updated supplier calculation with latest format

This commit is contained in:
Jack Goh
2018-07-26 10:56:28 +08:00
parent 293dfd6cd2
commit 45e8ce8620
3 changed files with 82 additions and 69 deletions
@@ -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();