mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange.git
synced 2026-08-19 12:24:09 +00:00
165 lines
5.3 KiB
PHP
165 lines
5.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\BookingSupplier;
|
|
use App\Booking;
|
|
use App\Rate;
|
|
use App\User;
|
|
use App\UserBankSlip;
|
|
use Illuminate\Http\Request;
|
|
|
|
class BookingSupplierController extends Controller
|
|
{
|
|
|
|
public function index()
|
|
{
|
|
$bookingsupplier = BookingSupplier::all();
|
|
|
|
$response = [
|
|
'supplier-booking' => $bookingsupplier
|
|
];
|
|
return response()->json($response, 200);
|
|
}
|
|
|
|
// function show($id)
|
|
public function show($id)
|
|
{
|
|
$bookingsupplier = BookingSupplier::has('supplier-booking')->findOrFail($id);
|
|
|
|
$response = [
|
|
'supplier-booking' => $booking
|
|
];
|
|
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 = $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;
|
|
|
|
$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
|
|
foreach ($bookingsupplier as $booking)
|
|
{
|
|
$manybooking = new Booking(array(
|
|
'book_id' => $booking->id,
|
|
'term' => $booking['term'],
|
|
'amount' => $booking['amount'],
|
|
'account_name' => $booking['account_name'],
|
|
'account_num' => $booking['account_num'],
|
|
'bank_name' => $booking['bank_name'],
|
|
'bank_branch' => $booking['account_name'],
|
|
'company_name' => $booking['company_name'],
|
|
'company_address' => $booking['company_address'],
|
|
'bank_address' => $booking['bank_address'],
|
|
'swift_code' => $booking['swift_code'],
|
|
'cnap' => $booking['cnap'],
|
|
'verification_status' => $booking['verification_status'],
|
|
'rmb_book_amount' => $booking['rmb_book_amount'],
|
|
'rmb_book_pay_method' => $booking['rmb_book_pay_method'],
|
|
'rmb_book_account_name' => $booking['rmb_book_account_name'],
|
|
'rmb_book_bank_name' => $booking['rmb_book_bank_name'],
|
|
'rmb_book_acc_no' => $booking['rmb_book_acc_no'],
|
|
'rmb_book_bank_branch' => $booking['rmb_book_bank_branch'],
|
|
));
|
|
|
|
$manybooking->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();
|
|
|
|
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);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|