mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange.git
synced 2026-08-19 12:24:09 +00:00
181 lines
6.4 KiB
PHP
181 lines
6.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\BookingSupplier;
|
|
use App\Booking;
|
|
use App\Rate;
|
|
use App\User;
|
|
use App\UserBankSlip;
|
|
use App\SettingBeneficiary;
|
|
use App\SupplierBookingItem;
|
|
use Illuminate\Http\Request;
|
|
|
|
class BookingSupplierController extends Controller
|
|
{
|
|
|
|
public function index()
|
|
{
|
|
$bookingsupplier = BookingSupplier::all();
|
|
|
|
$response = [
|
|
'supplier-booking' => $bookingsupplier
|
|
];
|
|
return response()->json($response, 200);
|
|
}
|
|
|
|
public function show($id)
|
|
{
|
|
$bookingsupplier = BookingSupplier::has('supplier-booking')->findOrFail($id);
|
|
|
|
$response = [
|
|
'supplier-booking' => $bookingsupplier
|
|
];
|
|
return response()->json($response, 200);
|
|
}
|
|
|
|
//single booking detail : one customer bank slip
|
|
public function viewCustomerBookingDetail (Request $request, $id )
|
|
{
|
|
// display all booking that is already uploaded user bankin slip
|
|
// TODO: admin can access only
|
|
// get current booking
|
|
|
|
// $booking = Booking::where("admin_id", Auth::user()->id)->where('id', $id)->first();
|
|
if (!$booking)
|
|
{
|
|
return response()->json(['message'=>'Access denied'], 200);
|
|
}
|
|
return response()->json($booking, 200);
|
|
|
|
}
|
|
|
|
|
|
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");
|
|
|
|
$amountInRMB = $payment_amount * $rate;
|
|
$billing = 0.015 * $payment_amount;
|
|
$sales_tax = 0.10 * $payment_amount;
|
|
$gst = 0 * $payment_amount;
|
|
$customerBankInAmount = round($payment_amount + $gst + $sales_tax + $billing,2);
|
|
$rmbBankAmount = $customerBankInAmount + $rebate;
|
|
|
|
$user = Auth::user();
|
|
$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->save();
|
|
|
|
//// one bookingsupplier has many booking
|
|
// $bookings = $request->input("booking");
|
|
// foreach ($bookings as $booking)
|
|
// {
|
|
// $bookingsupplierbooking = new Booking(array(
|
|
// 'book_id' => $booking->id,
|
|
// 'supplierbooking_id' => $supplier->id
|
|
// ));
|
|
// $bookingsupplierbooking->save();
|
|
|
|
// $new_supplierbooking = new SupplierBookingItem(array(
|
|
// 'book_id' => $booking->id,
|
|
// 'bank_in_amount'=>$booking['bank_in_amount'],
|
|
// 'date'=>$booking['date'],
|
|
// 'details'=>$booking['details'],
|
|
// 'supplierbooking_id' => $supplier->id
|
|
// ));
|
|
// $new_supplierbooking->save();
|
|
|
|
// }
|
|
return response()->json($bookingsupplier, 201);
|
|
}
|
|
|
|
|
|
public function update(Request $request, $id)
|
|
{
|
|
$bookingsupplier = BookingSupplier::find($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');
|
|
// 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();
|
|
|
|
// $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 destroy(BookingSupplier $id)
|
|
{
|
|
$id->delete($id);
|
|
}
|
|
|
|
public function supplierbookingreport(Request $request, $id)
|
|
{
|
|
$bookingsupplier = BookingSupplier::where("admin_id", Auth::user()->id)->where('id', $id)->first();
|
|
if (!$bookingsupplier)
|
|
{
|
|
return response()->json(['message'=>'Access denied'], 200);
|
|
}
|
|
|
|
// //get customer booking id, date,amount, rate, total, gst, rebate, bank in amount, beneficiary account number, bank slip.
|
|
// return BookingSupplier::find($id);
|
|
|
|
// //display report
|
|
// $bookingsupplier = BookingSupplier::with (['supplier_bookings' => function($query){
|
|
// $query -> select ('book_id','date','transfer_amount','rate','rebate', 'amountInRMB', 'rmbBankAmount');
|
|
// }])->get();
|
|
|
|
// //get uploaded customer booking bank slip
|
|
// $userbankslip = UserBankSlip::with (['user_bank_slips' => function($query){
|
|
// $query -> select ('book_id','bankslip_url');
|
|
// }])->get();
|
|
|
|
// //get active beneficiary account
|
|
// $beneficiary = SettingBeneficiary::with (['setting_beneficiaries' => function($query){
|
|
// $query -> select ('bank_name','acc_no');
|
|
// }])->get();
|
|
|
|
$supplier_booking = $booking->supplierBooking()->first();
|
|
$user_bankslip = $booking->userBankSlip()->first();
|
|
|
|
}
|
|
|
|
|
|
}
|