mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange.git
synced 2026-08-19 12:24:09 +00:00
4e0f1dbe0a
added exception if userbankslip not save show error added tax rate to supplier booking added order number and payment for to booking seeder
186 lines
6.1 KiB
PHP
186 lines
6.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Auth;
|
|
use App\SupplierBooking;
|
|
use App\Booking;
|
|
use App\Rate;
|
|
use App\User;
|
|
use App\UserBankSlip;
|
|
use App\SettingBeneficiary;
|
|
use App\SupplierBookingItem;
|
|
use App\SettingSupplier;
|
|
use App\SettingTaxRate;
|
|
use Illuminate\Http\Request;
|
|
|
|
class BookingSupplierController extends Controller
|
|
{
|
|
|
|
public function index()
|
|
{
|
|
$bookingsupplier = SupplierBooking::all();
|
|
|
|
$response = [
|
|
'supplier-booking' => $bookingsupplier
|
|
];
|
|
|
|
return response()->json($response, 200);
|
|
}
|
|
|
|
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){
|
|
return response()->json(['message' => 'Booking not found'], 404);
|
|
}
|
|
|
|
switch ($booking->term) {
|
|
case "x1_cash":
|
|
$payment_method = "CASH";
|
|
break;
|
|
case "x1_cheque":
|
|
|
|
$payment_method = "CHEQUE";
|
|
break;
|
|
case "x1_ba":
|
|
|
|
$payment_method = "BA";
|
|
break;
|
|
case "x2_cash":
|
|
|
|
$payment_method = "CASH";
|
|
break;
|
|
case "x2_cheque":
|
|
$payment_method = "CHEQUE";
|
|
break;
|
|
case "x2_ba":
|
|
$payment_method = "BA";
|
|
break;
|
|
default:
|
|
return response()->json([
|
|
'success' => false,
|
|
'message' => 'Invalid input',
|
|
], 422);
|
|
break;
|
|
}
|
|
|
|
$supplier_booking = $booking->supplierBooking()->first();
|
|
$dt = new \DateTime($supplier_booking->created_at);
|
|
$supplier_booking->date = $dt->format('j F Y');
|
|
$supplier_booking->marking = $booking->user->marking;
|
|
$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);
|
|
}
|
|
|
|
// Only for single booking
|
|
// TODO : Multiple booking
|
|
public function store(Request $request)
|
|
{
|
|
$transfer_amount = $request->input("transfer_amount");
|
|
$supplier_id = $request->input("supplier_id");
|
|
$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);
|
|
|
|
// update existing booking supplier if exist
|
|
$bookingsupplier = SupplierBooking::where('booking_id', $booking_id)->first();
|
|
|
|
if (!$bookingsupplier){
|
|
$bookingsupplier = new SupplierBooking();
|
|
|
|
}
|
|
|
|
$bookingsupplier->supplier_id = $supplier->id;
|
|
$bookingsupplier->payment_method = $request->input('payment_method');
|
|
$bookingsupplier->transfer_amount = $transfer_amount;
|
|
$bookingsupplier->rate = $rate;
|
|
$bookingsupplier->billing_amount = $billing;
|
|
$bookingsupplier->salestax_amount = $sales_tax;
|
|
$bookingsupplier->rebate = $rebate;
|
|
$bookingsupplier->amountInRMB = $amountInRMB;
|
|
$bookingsupplier->rmbBankAmount = $rmbBankAmount;
|
|
$bookingsupplier->booking_id = $booking->id;
|
|
$bookingsupplier->save();
|
|
|
|
// update booking status
|
|
$booking->status = 4;
|
|
$booking->admin_status = 4;
|
|
$booking->save();
|
|
|
|
|
|
|
|
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();
|
|
|
|
return response()->json($supplier_booking ,200);
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|