mirror of
https://gitlab.com/omair-personal/exchange.git
synced 2026-08-19 12:34:13 +00:00
145 lines
5.0 KiB
PHP
145 lines
5.0 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);
|
|
}
|
|
|
|
// Only for single booking
|
|
// TODO : Multiple booking
|
|
public function store(Request $request, $id)
|
|
{
|
|
$payment_amount = $request->input("payment_amount");
|
|
$rate = $request->input("rate");
|
|
$rebate = $request->input("rebate");
|
|
$supplier_id = $request->input("supplier_id");
|
|
|
|
// Calculation
|
|
$amountInRMB = $payment_amount * $rate;
|
|
$billing = 0.015 * $payment_amount;
|
|
$sales_tax = 0.10 * $payment_amount;
|
|
$gst = 0 * $payment_amount; // do we still need this ?
|
|
$customerBankInAmount = round($payment_amount + $gst + $sales_tax + $billing,2);
|
|
$rmbBankAmount = $customerBankInAmount + $rebate;
|
|
|
|
$user = Auth::user();
|
|
$supplier = SettingSupplier::find($supplier_id);
|
|
$booking = Booking::find($id);
|
|
|
|
$bookingsupplier = new BookingSupplier();
|
|
$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->booking()->associate($booking);
|
|
$bookingsupplier->save();
|
|
|
|
// update booking status
|
|
$booking->status = 4;
|
|
$booking->admin_status = 3;
|
|
$booking->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 report(Request $request, $id)
|
|
{
|
|
$supplier_booking = Booking::firstOrFail($id)->supplierBooking()->firstOrFail();
|
|
|
|
return response()->json($supplier_booking ,200);
|
|
}
|
|
|
|
|
|
}
|