diff --git a/app/Booking.php b/app/Booking.php index 6daa1d89..beae4a40 100644 --- a/app/Booking.php +++ b/app/Booking.php @@ -47,5 +47,11 @@ class Booking extends Model public function purchaseOrder(){ return $this->hasOne(PurchaseOrder::class); } + + public function invoice(){ + return $this->hasOne(Invoice::class); + } + + } diff --git a/app/Http/Controllers/BookingController.php b/app/Http/Controllers/BookingController.php index 022a8c95..30a650a5 100644 --- a/app/Http/Controllers/BookingController.php +++ b/app/Http/Controllers/BookingController.php @@ -423,19 +423,6 @@ class BookingController extends Controller 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 showPurchaseOrder($id){ $booking = Booking::where('id',$id)->first(); @@ -657,8 +644,38 @@ class BookingController extends Controller 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; // processing transfer + $booking->admin_status = 6; // upload china bankslip - + if($booking->save()){ + return response()->json(['message'=>"Success"],200); + } } } diff --git a/app/Invoice.php b/app/Invoice.php index 570dc72b..5150b1e4 100644 --- a/app/Invoice.php +++ b/app/Invoice.php @@ -7,4 +7,8 @@ use Illuminate\Database\Eloquent\Model; class Invoice extends Model { protected $fillable = ['invoice_url','amount','booking_id']; + + public function booking(){ + return $this->hasOne('App\Booking'); + } } diff --git a/resources/assets/js/pages/admin/booking/uploadInvoice.vue b/resources/assets/js/pages/admin/booking/uploadInvoice.vue index 5ccd8559..7e2d0d89 100644 --- a/resources/assets/js/pages/admin/booking/uploadInvoice.vue +++ b/resources/assets/js/pages/admin/booking/uploadInvoice.vue @@ -5,7 +5,7 @@


-
+

Upload Invoice

@@ -173,42 +173,24 @@
- - - -
-
- + - +
Upload Invoice
-
- Submit + Submit
@@ -357,50 +339,32 @@ }, methods: { - uploadPo(formName) { - this.loading_btn = true - - this.$refs[formName].validate((valid) => { - if (valid) { - let newChinaSlip = { - date: this.chinaSlipForm.date, - actual_transfer_amount: this.chinaSlipForm.actual_transfer_amount, - details: this.chinaSlipForm.details, - } - - axios.patch('/api/booking/' + this.booking_id + '/update-china-bankslip', newChinaSlip) - .then((response) => { - this.$message({ - showClose: true, - message: 'Your bankinslip has been submitted, please wait admin to approve.', - type: 'success', - duration: 5000 - }) - - console.log(response) - this.$router.push({ - name: 'home' - }) - }) - .catch((error) => { - this.loading = false - this.$message({ - showClose: true, - message: 'Please upload your bankin slip first.', - type: 'warning', - duration: 10000 - }) - console.log(error) - this.loading_btn = false - }) - - } else { - this.loading_btn = false - } + confirmInvoice () { + this.loading_btn = true + axios + .post('/api/booking/' + this.$route.params.id + '/confirm-invoice') + .then((response) => { + console.log(response) + this.$message({ + showClose: true, + message: 'Your invoice has been uploaded. Order completed !', + type: 'success', + duration: 5000 + }) + this.$router.push({ + name: 'home' + }) + this.loading_btn = false + }).catch((error) => { + this.$message({ + showClose: true, + message: 'Please upload invoice', + type: 'error', + duration: 30000 + }) + this.loading_btn = false }) - - - }, + }, handleRemove(file, fileList) { console.log(file, fileList); }, diff --git a/routes/api.php b/routes/api.php index 9f6089fc..be6caa34 100644 --- a/routes/api.php +++ b/routes/api.php @@ -63,7 +63,6 @@ Route::group(['middleware' => 'guest:api'], function () { Route::group(['middleware' => ['role:admin']], function() { Route::get('admin/booking/', 'BookingController@adminIndex'); Route::get('admin/booking/{id}', 'BookingController@adminShow'); - Route::post('booking/{id}/upload-invoice', 'BookingController@uploadInvoice'); Route::post('update-rate', 'RateController@store'); Route::put('update-rate/{rate}', 'RateController@update'); @@ -104,8 +103,9 @@ Route::group(['middleware' => ['role:admin']], function() { Route::post('/booking/{id}/upload-china-bankslip','ChinaBankSlipController@store'); Route::patch('/booking/{id}/update-china-bankslip','ChinaBankSlipController@update'); - Route::get('/booking/{id}/po', 'BookingController@showPurchaseOrder'); + Route::post('booking/{id}/upload-invoice', 'BookingController@uploadInvoice'); + Route::post('booking/{id}/confirm-invoice', 'BookingController@confirmInvoice'); });