diff --git a/app/Http/Controllers/BookingSupplierController.php b/app/Http/Controllers/BookingSupplierController.php index 94f87f37..607daf6b 100644 --- a/app/Http/Controllers/BookingSupplierController.php +++ b/app/Http/Controllers/BookingSupplierController.php @@ -31,7 +31,6 @@ class BookingSupplierController extends Controller public function show($id) { $booking = Booking::where('id', $id)->first(); - $tax_rate = SettingTaxRate::latest()->first()->tax_rate; $bankin_amount = round($booking->amount / $booking->rate, 2); if (!$booking){ @@ -75,10 +74,6 @@ class BookingSupplierController extends Controller $supplier_booking->payment_for = $booking->payment_for; $supplier_booking->order_no = $booking->order_no; $supplier_booking->payment_method = $payment_method; - $supplier_booking->tax_rate = $tax_rate; - $supplier_booking->rate = $booking->rate; - $supplier_booking->bankin_amount = $bankin_amount; - return response()->json($supplier_booking ,200); } @@ -92,19 +87,34 @@ class BookingSupplierController extends Controller $booking_id = $request->input("booking_id"); //$rate = $request->input('rate'); $rebate = $request->input('rebate'); - - // Calculation - $amountInRMB = $transfer_amount * $rate; - $billing = 0.015 * $transfer_amount; - $sales_tax = 0.0 * $transfer_amount; - $gst = 0 * $transfer_amount; // do we still need this ? - $customerBankInAmount = round($transfer_amount + $gst + $sales_tax + $billing,2); - $rmbBankAmount = round($customerBankInAmount + $rebate, 2); - - $user = Auth::user(); $supplier = SettingSupplier::find($supplier_id); $booking = Booking::find($booking_id); + + + // Calculation (backup) + // $amountInRMB = $transfer_amount * $rate; + // $billing = 0.015 * $transfer_amount; + // $sales_tax = 0.0 * $transfer_amount; + // $gst = 0 * $transfer_amount; // do we still need this ? + // $customerBankInAmount = round($transfer_amount + $gst + $sales_tax + $billing,2); + // $rmbBankAmount = round($customerBankInAmount + $rebate, 2); + + // Update: changes in 1.1 according to new supplier booking report + $transfer_amount = $booking->amount; + $rate = $booking->rate; + + $amount_in_myr = round($transfer_amount / $rate, 2); + $amountInRMB = $transfer_amount; + $tax_rate = SettingTaxRate::latest()->first()->tax_rate; + $sales_tax = round($tax_rate * $amount_in_myr - $amount_in_myr, 2); + $amount_after_tax = round($amount_in_myr * $tax_rate,2); + //$billing = 0.015 * $transfer_amount; + // + //$gst = 0 * $transfer_amount; // do we still need this ? + //$customerBankInAmount = round($transfer_amount + $gst + $sales_tax + $billing,2); + //$rmbBankAmount = round($customerBankInAmount + $rebate, 2); + // update existing booking supplier if exist $bookingsupplier = SupplierBooking::where('booking_id', $booking_id)->first(); @@ -113,14 +123,18 @@ class BookingSupplierController extends Controller } $bookingsupplier->supplier_id = $supplier->id; - $bookingsupplier->payment_method = $request->input('payment_method'); - $bookingsupplier->transfer_amount = $transfer_amount; + $bookingsupplier->amountInRMB = $amountInRMB; // TODO : rename to underscore + $bookingsupplier->amount_in_myr = $amount_in_myr; + $bookingsupplier->tax_rate = $tax_rate; + $bookingsupplier->amount_after_tax = $amount_after_tax; $bookingsupplier->rate = $rate; - $bookingsupplier->billing_amount = $billing; - $bookingsupplier->salestax_amount = $sales_tax; - $bookingsupplier->rebate = $rebate; - $bookingsupplier->amountInRMB = $amountInRMB; - $bookingsupplier->rmbBankAmount = $rmbBankAmount; + $bookingsupplier->rebate = $rebate; + $bookingsupplier->salestax_amount = $sales_tax; + //$bookingsupplier->payment_method = $request->input('payment_method'); // TODO : remove from db + //$bookingsupplier->transfer_amount = $transfer_amount; // TODO : remove from db + //$bookingsupplier->billing_amount = $billing; // TODO : remove from db + + //$bookingsupplier->rmbBankAmount = $rmbBankAmount; // TODO : remove from db $bookingsupplier->booking_id = $booking->id; $bookingsupplier->save(); @@ -134,43 +148,6 @@ class BookingSupplierController extends Controller return response()->json($bookingsupplier, 201); } - - public function update(Request $request, $id) - { - $bookingsupplier = SupplierBooking::find($id); - $bookingsupplier->payment_method = $request->input('payment_method'); - $bookingsupplier->transfer_amount = $request->input('transfer_amount'); - $bookingsupplier->rate = $request->input('rate'); - $bookingsupplier->rebate = $request->input('rebate'); - // calculation - $amountInRMB = $amount * $rate; - $billing = 0.015 * $amount; - $sales_tax = 0.10 * $amount; - $gst = 0 * $amount; - $customerBankInAmount = round($amount + $gst + $sales_tax + $billing,2); - $rmbBankAmount = $customerBankInAmount + $rebate; - - // save amount in rmb - $bookingsupplier->amountInRMB = $amountInRMB; - // save rmb bank amount - $bookingsupplier->rmbBankAmount = $rmbBankAmount; - $bookingsupplier->save(); - - /* For multiple booking */ - // $supplierbookingitems = $request->input("supplierbookingitem"); - // foreach ($bookings as $booking) - // { - // $update_supplierbookingitem = SupplierBookingItem::where('supplierbooking_id', $id)->first(); - // $update_supplierbookingitem->china_bankslip_url = $booking['china_bankslip_url']; - // $update_supplierbookingitem->bank_in_amount = $booking['bank_in_amount']; - // $update_supplierbookingitem->date = $booking['date']; - // $update_supplierbookingitem->details = $booking['details']; - // $update_supplierbookingitem->save(); - // } - return response()->json(['book_id'=>$book_id],201); - } - - public function report(Request $request, $id) { $supplier_booking = Booking::firstOrFail($id)->supplierBooking()->firstOrFail(); diff --git a/database/migrations/2018_07_26_094305_add_fields_into_supplier_bookings_table.php b/database/migrations/2018_07_26_094305_add_fields_into_supplier_bookings_table.php new file mode 100644 index 00000000..c7320caa --- /dev/null +++ b/database/migrations/2018_07_26_094305_add_fields_into_supplier_bookings_table.php @@ -0,0 +1,32 @@ +string('amount_in_myr')->nullable(); + $table->string('tax_rate')->nullable(); + $table->string('amount_after_tax')->nullable(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + // + } +} diff --git a/resources/assets/js/pages/admin/booking/supplierReport.vue b/resources/assets/js/pages/admin/booking/supplierReport.vue index 8020048b..5c8d655e 100644 --- a/resources/assets/js/pages/admin/booking/supplierReport.vue +++ b/resources/assets/js/pages/admin/booking/supplierReport.vue @@ -480,13 +480,17 @@ ctx.fillText("MYR/RM :", column1X, rowHeight[9] - 5); ctx.fillText("MYR", column2X, rowHeight[9] - 5); ctx.font = "bold 14px Arial"; - ctx.fillText(binding.value.transfer_amount, column3X, rowHeight[9] - 5); + ctx.fillText(binding.value.amount_in_myr, column3X, rowHeight[9] - 5); ctx.font = "13px Arial"; //// Row 8 ctx.fillText("* RATE :", column1X, rowHeight[10] - 5); ctx.fillText(binding.value.rate, column3X, rowHeight[10] - 5); //// Row 9 - // Empty + ctx.fillText("REBATE :", column1X, rowHeight[11] - 5); + ctx.fillText("MYR", column2X, rowHeight[11] - 5); + ctx.font = "14px Arial"; + ctx.fillText(binding.value.rebate, column3X, rowHeight[11] - 5); + ctx.font = "13px Arial"; //// Row 10 ctx.font = "bold 14px Arial"; ctx.fillText("CNY", column2X, rowHeight[12] - 5); @@ -506,14 +510,14 @@ //// Row 11 ctx.fillText("MYR/RM :", column1X, rowHeight[14] - 5); ctx.fillText("MYR", column2X, rowHeight[14] - 5); - ctx.fillText(binding.value.bankin_amount, column3X, rowHeight[14] - 5); + ctx.fillText(binding.value.amount_in_myr, column3X, rowHeight[14] - 5); //// Row 12 // ctx.fillText("Billing(1.0%) :", column1X, rowHeight[15] - 5); // ctx.fillText("MYR", column2X, rowHeight[15] - 5); // ctx.fillText(binding.value.billing_amount, column3X, rowHeight[15] - 5); //// Row 13 - ctx.fillText("+ TAX "+ binding.value.tax_rate + ":", column1X, rowHeight[16] - 5); + ctx.fillText("+ TAX "+ (Math.round((binding.value.tax_rate * 100 - 100) * 100) / 100) + "% :", column1X, rowHeight[16] - 5); // TODO : Change to percentage ctx.fillText("MYR", column2X, rowHeight[16] - 5); ctx.fillText(binding.value.salestax_amount, column3X, rowHeight[16] - 5); // //// Row 14 @@ -522,10 +526,10 @@ // ctx.fillText("289.84", column3X, rowHeight[17] - 15); //// Row 15 ctx.font = "bold 14px Arial"; - ctx.fillText("Customer Bank In Amount :", column1X, rowHeight[18] - 5); + ctx.fillText("Bank In Amount :", column1X, rowHeight[18] - 5); ctx.fillStyle = "#0070D5"; ctx.fillText("MYR", column2X, rowHeight[18] - 5); - ctx.fillText(binding.value.amountInRMB, column3X, rowHeight[18] - 5); + ctx.fillText(binding.value.amount_after_tax, column3X, rowHeight[18] - 5); ctx.fillStyle = "#000000"; ctx.font = "13px Arial"; //line @@ -543,16 +547,16 @@ ctx.lineTo(column3X + 20, rowHeight[18] - 2); ctx.stroke(); //// Row 16 - ctx.fillText("Rebate :", column1X, rowHeight[19] - 25); - ctx.fillText("CNY", column2X, rowHeight[19] - 25); - ctx.fillText("224.68", column3X, rowHeight[19] - 25); + // ctx.fillText("Rebate :", column1X, rowHeight[19] - 25); + // ctx.fillText("CNY", column2X, rowHeight[19] - 25); + // ctx.fillText("224.68", column3X, rowHeight[19] - 25); //// Row 16 ctx.font = "bold 14px Arial"; ctx.fillText("Bank In to Account Below :", column1X, rowHeight[20] - 5); ctx.font = "bold italic 15px Arial"; ctx.fillStyle = "#0070D5"; ctx.fillText("CNY", column2X, rowHeight[20] - 5); - ctx.fillText("7692.17", column3X - 20, rowHeight[20] - 5); + ctx.fillText(binding.value.amountInRMB, column3X - 20, rowHeight[20] - 5); ctx.fillStyle = "#000000"; ctx.font = "13px Arial"; //// Row 17