mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange.git
synced 2026-08-19 20:34:08 +00:00
144 lines
4.7 KiB
PHP
144 lines
4.7 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 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();
|
|
|
|
if (!$booking){
|
|
return response()->json(['message' => 'Booking not found'], 404);
|
|
}
|
|
|
|
$supplier_booking = $booking->supplierBooking()->first();
|
|
$dt = new \DateTime($supplier_booking->created_at);
|
|
$supplier_booking->date = $dt->format('j F Y');
|
|
|
|
|
|
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.10 * $transfer_amount;
|
|
$gst = 0 * $transfer_amount; // do we still need this ?
|
|
$customerBankInAmount = round($transfer_amount + $gst + $sales_tax + $billing,2);
|
|
$rmbBankAmount = $customerBankInAmount + $rebate;
|
|
|
|
$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);
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|