From b7f258f6a9162448a31506b37c5602e56985c3b3 Mon Sep 17 00:00:00 2001 From: Jack Goh Date: Wed, 27 Jun 2018 10:30:01 +0800 Subject: [PATCH] refactor BookingsupplierController fix booking supplier model updated fields for bookg supplier frontend --- app/Booking.php | 5 +- app/BookingSupplier.php | 5 +- app/Http/Controllers/BookingController.php | 2 +- .../Controllers/BookingSupplierController.php | 23 ++- .../pages/admin/booking/supplierBooking.vue | 146 +++++++++--------- 5 files changed, 91 insertions(+), 90 deletions(-) diff --git a/app/Booking.php b/app/Booking.php index b03276d9..fec84e1c 100644 --- a/app/Booking.php +++ b/app/Booking.php @@ -28,11 +28,14 @@ class Booking extends Model public $timestamps = true; - public function user(){ return $this->belongsTo('app\User'); } + public function bookingSupplier(){ + return $this->belongsTo('app\BookingSupplier '); + } + public function userBankSlip(){ return $this->hasOne(UserBankSlip::class); } diff --git a/app/BookingSupplier.php b/app/BookingSupplier.php index aed75bc1..dbf1de39 100644 --- a/app/BookingSupplier.php +++ b/app/BookingSupplier.php @@ -15,12 +15,11 @@ class BookingSupplier extends Model return $this->belongsTo('app\User'); } - public function bookingSupplier() - { + public function booking(){ return $this->hasOne('App\Booking'); } - public function supplierbookingitem() + public function supplierBookingTtem() { return $this->hasMany('App\SupplierBookingItem'); } diff --git a/app/Http/Controllers/BookingController.php b/app/Http/Controllers/BookingController.php index f190aefb..f893d614 100644 --- a/app/Http/Controllers/BookingController.php +++ b/app/Http/Controllers/BookingController.php @@ -164,9 +164,9 @@ class BookingController extends Controller public function store(Request $request) { - $rates = Rate::orderby('updated_at','desc')->first(); $term = $request->input('term'); $amount = $request->input("amount"); // in RMB + $rates = Rate::orderby('updated_at','desc')->first(); $creditLimit = SettingCredit::orderby('updated_at','desc')->first(); if (!$creditLimit){ diff --git a/app/Http/Controllers/BookingSupplierController.php b/app/Http/Controllers/BookingSupplierController.php index 0193e12c..9e3640ed 100644 --- a/app/Http/Controllers/BookingSupplierController.php +++ b/app/Http/Controllers/BookingSupplierController.php @@ -36,37 +36,44 @@ class BookingSupplierController extends Controller return response()->json($response, 200); } + // Only for single booking + // TODO : Multiple booking public function store(Request $request, $id) { - //Calculation part - //single booking supplier $payment_amount = $request->input("payment_amount"); $rate = $request->input("rate"); $rebate = $request->input("rebate"); - + $supplier_id = $request->input("supplier_id"); + + // Calculation $amountInRMB = $payment_amount * $rate; $billing = 0.015 * $payment_amount; $sales_tax = 0.10 * $payment_amount; - $gst = 0 * $payment_amount; + $gst = 0 * $payment_amount; // do we still need this ? $customerBankInAmount = round($payment_amount + $gst + $sales_tax + $billing,2); $rmbBankAmount = $customerBankInAmount + $rebate; $user = Auth::user(); + $supplier = SettingSupplier::find($supplier_id); + $booking = Booking::find($id); + $bookingsupplier = new BookingSupplier(); - - $supplier = SettingSupplier::find($id); $bookingsupplier->supplier_id = $supplier->id; - $bookingsupplier->payment_method = $request->input('payment_method'); $bookingsupplier->payment_amount = $request->input('payment_amount'); $bookingsupplier->rate = $request->input('rate'); $bookingsupplier->rebate = $request->input('rebate'); - $bookingsupplier->user()->associate($user); $bookingsupplier->amountInRMB = $amountInRMB; $bookingsupplier->rmbBankAmount = $rmbBankAmount; + $bookingsupplier->booking()->associate($booking); $bookingsupplier->save(); + // update booking status + $booking->status = 4; + $booking->admin_status = 3; + $booking->save(); + //// one bookingsupplier has many booking // $bookings = $request->input("booking"); // foreach ($bookings as $booking) diff --git a/resources/assets/js/pages/admin/booking/supplierBooking.vue b/resources/assets/js/pages/admin/booking/supplierBooking.vue index 095440a9..f393a329 100644 --- a/resources/assets/js/pages/admin/booking/supplierBooking.vue +++ b/resources/assets/js/pages/admin/booking/supplierBooking.vue @@ -19,7 +19,7 @@
- +
@@ -147,7 +147,9 @@
@@ -199,41 +201,32 @@ - -
- - - - - - - - - - - - - - - - - - - Generate Report - -
-
+ +
- - + + + + + + + + + + + + + + + + + + Generate Report + +
+
-
@@ -256,7 +249,7 @@ return { status: 3, loading_btn: false, - booking_details:{ + booking_details: { id: null, amount: null, bia: null, @@ -264,7 +257,7 @@ }, supplier: null, supplier_options: null, - supplierBookingForm:{ + supplierBookingForm: { supplier: null, amount: null, rate: null, @@ -276,62 +269,62 @@ required: true, message: 'Please input amount', trigger: 'change' - } ], - amount: [{ + }], + rebate: [{ required: true, message: 'Please input bank name', trigger: 'change' - } ], + }], rate: [{ required: true, message: 'Please input account name', trigger: 'change' }], - transfer_amount: [{ + payment_amount: [{ required: true, message: 'Please input branch', trigger: 'change' }] - }, + }, } }, - beforeCreate () { - const loading = this.$loading({ - lock: true, - text: 'Please wait..', - spinner: 'el-icon-loading', - background: 'rgba(0, 0, 0, 0.7)' - }) - - axios - .get('/api/admin/booking/' + this.$route.params.id) - .then((response) => { - loading.close() - this.booking_details = response.data - }).catch((error) => { - console.log(error) - loading.close() - this.$router.push({ - name: 'notfound' - }) + beforeCreate() { + const loading = this.$loading({ + lock: true, + text: 'Please wait..', + spinner: 'el-icon-loading', + background: 'rgba(0, 0, 0, 0.7)' }) - axios - .get('/api/setting-supplier/') - .then((response) => { - loading.close() - this.supplier_options = response.data - }).catch((error) => { - loading.close() - console.log(error) - this.$router.push({ - name: 'notfound' + axios + .get('/api/admin/booking/' + this.$route.params.id) + .then((response) => { + loading.close() + this.booking_details = response.data + }).catch((error) => { + console.log(error) + loading.close() + this.$router.push({ + name: 'notfound' + }) }) - }) - - }, + + axios + .get('/api/setting-supplier/') + .then((response) => { + loading.close() + this.supplier_options = response.data + }).catch((error) => { + loading.close() + console.log(error) + this.$router.push({ + name: 'notfound' + }) + }) + + }, methods: { - generateReport (formName) { + generateReport(formName) { this.loading_btn = true this.$refs[formName].validate((valid) => { @@ -360,9 +353,8 @@ // this.loading = false // console.log(error) // }) - - } - else{ + + } else { this.loading_btn = false } })
-
MYR {{ booking_details.bia }}
+
+ MYR {{ booking_details.bia }} +