Merge branch 'master' of gitlab.com:CIEFWorldwideSdnBhd/exchange into feature/booking-pagination

This commit is contained in:
Mohd Arief
2018-06-29 12:09:44 +08:00
33 changed files with 12258 additions and 874 deletions
+77 -28
View File
@@ -19,11 +19,12 @@ class BookingController extends Controller
{
public function index(){
$user = Auth::user();
$user = Auth::user();
$bookings = Booking::select('id', 'created_at', 'status', 'rate', 'term', 'amount', 'bia', 'verification_status')
->where('user_id', $user->id)
->get();
->where('user_id', $user->id)
->paginate(10);
// reformat to fit frontend structure
foreach ($bookings as $booking) {
// set timeout
@@ -40,7 +41,7 @@ class BookingController extends Controller
// TODO : transfer_amount change name to bia
$booking->transfer_amount = $booking->bia;
$booking->track_status = "(". $booking->status ."/6)";
$booking->track_status = "(". $booking->status ."/7)";
switch ($booking->status) {
case 1:
$status_desc = "Order in progress";
@@ -60,6 +61,9 @@ class BookingController extends Controller
case 6:
$status_desc = "Processing invoice";
break;
case 7:
$status_desc = "Order Completed";
break;
default:
$status_desc = "";
}
@@ -91,30 +95,30 @@ class BookingController extends Controller
// TODO : transfer_amount change name to bia
$booking->transfer_amount = $booking->bia;
$booking->track_status = "(". $booking->admin_status ."/7)";
$booking->track_status = "(". $booking->admin_status ."/8)";
switch ($booking->admin_status) {
case 0:
$status_desc = "Waiting user to upload bankin slip";
break;
case 1:
$status_desc = "Waiting for verification";
$status_desc = "Waiting customer upload bank slip";
break;
case 2:
$status_desc = "Bookg with supplier";
$status_desc = "Verify user bank slip";
break;
case 3:
$status_desc = "Supplier booking report. Please confirm with your booking.";
$status_desc = "Generate supplier booking report";
break;
case 4:
$status_desc = "Please update supplier booking status.";
$status_desc = "Supplier booking report. Please confirm with your booking.";
break;
case 5:
$status_desc = "Upload China Bankslip";
$status_desc = "Please, upload China Bankslip";
break;
case 6:
$status_desc = "Customer has uploaded the invoice, please upload purchase order";
$status_desc = "Waiting customer to upload purchase order";
break;
case 7:
$status_desc = "Customer has uploaded purchase order, please upload invoice";
break;
case 8:
$status_desc = "Booking Completed";
break;
default:
@@ -419,24 +423,26 @@ class BookingController extends Controller
$user_po = new PurchaseOrder;
$user_po->image_path = $upload_path;
$user_po->book_id = $booking->id;
$user_po->booking_id = $booking->id;
$user_po->save();
$booking->status = 6;
$booking->admin_status = 7;
$booking->save();
return response()->json(['message'=>'Success'],200);
}
public function confirmPurchaseOrder($id){
$booking = Booking::where('user_id',Auth::user()->id)->where('id',$id)->first();
$booking->status = 6;
$booking->save();
return response()->json(['message'=>'Success'],200);
}
public function showPurchaseOrder($id){
$booking = Booking::where('id',$id)->first();
$user_po = $booking->purchaseOrder()->first();
return response()->json(['po_path'=> $user_po],200);
if($user_po){
return response()->json(['user_po_path'=> $user_po->image_path ],200);
}
return response()->json(['message'=> 'waiting customer to upload their po'],400);
}
public function delete(Booking $book_id)
@@ -588,7 +594,7 @@ class BookingController extends Controller
//upload
public function uploadInvoice(Request $request, $id)
{
$booking = Booking::where('user_id',Auth::user()->id)->where('id',$id)->first();
$booking = Booking::where('id',$id)->first();
/* Validation */
if (!$booking)
@@ -614,7 +620,7 @@ class BookingController extends Controller
return response()->json(['message'=>'Image too large, upload files up to 3 MB'], 400);
}
if(!$input_file = $request->file('invoice_path'))
if(!$input_file = $request->file('file'))
{
return response()->json(['message'=>'No file detected'], 400);
}
@@ -623,20 +629,63 @@ class BookingController extends Controller
$filename = $input_file->getClientOriginalName();
$ext = $input_file->getClientOriginalExtension();
$input['invoice_path'] = $filename;
$unique_name = 'invoice' . md5($filename. time());
$unique_file_url = $unique_name. '.' .$ext;
$upload_path = Storage::disk('public')->putFileAs(
'invoice',/*folder name*/ $input_file, $unique_file_url, 'public'
'invoice', $input_file, $unique_file_url, 'public'
);
$invoice = new Invoice;
$invoice->invoice_path = $upload_path;
$invoice->amount = $request->input('amount');
// TODO : amount
$invoice->amount = 0;
$invoice->booking_id = $booking->id;
$invoice->save();
return response()->json(['message'=>"Success"],200);
}
public function confirmSupplier(Request $request, $id)
{
$booking = Booking::where('id', $id)->firstOrFail();
$booking->status = 4; // processing transfer
$booking->admin_status = 5; // upload china bankslip
if($booking->save()){
return response()->json(['message'=>"Success"],200);
}
}
public function confirmPurchaseOrder($id){
$booking = Booking::where('user_id',Auth::user()->id)->where('id',$id)->first();
$purchase_order = $booking->purchaseOrder()->first();
if(!$purchase_order){
return response()->json(["message"=> "Please upload your purchase order"],400);
}
$booking->status = 6;
$booking->save();
return response()->json(['message'=>'Success'],200);
}
public function confirmInvoice(Request $request, $id)
{
$booking = Booking::where('id', $id)->firstOrFail();
$invoice = $booking->invoice()->first();
if(!$invoice){
return response()->json(["message"=> "Please upload your invoice"],400);
}
$booking->status = 7; // completed
$booking->admin_status = 7; // completed
if($booking->save()){
return response()->json(['message'=>"Success"],200);
}
}
}