mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange.git
synced 2026-08-19 12:24:09 +00:00
105b61eab3
updated chinabankslip error message to be more clear fixed supplier booking report loading button updated upload invoice frontend to show user po image
137 lines
4.5 KiB
PHP
137 lines
4.5 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)
|
|
{
|
|
$bookingsupplier = SupplierBooking::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)
|
|
{
|
|
|
|
$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');
|
|
|
|
if ($supplierbooking = SupplierBooking::where('book_id', $booking_id)->first()){
|
|
return response()->json(['success'=>false, 'message'=>'Bad request, please contact support'], 400);
|
|
}
|
|
|
|
|
|
// 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);
|
|
|
|
$bookingsupplier = new SupplierBooking();
|
|
$bookingsupplier->supplier_id = $supplier->id;
|
|
$bookingsupplier->payment_method = $request->input('payment_method');
|
|
$bookingsupplier->transfer_amount = $transfer_amount;
|
|
$bookingsupplier->rate = $rate;
|
|
$bookingsupplier->rebate = $rebate;
|
|
$bookingsupplier->amountInRMB = $amountInRMB;
|
|
$bookingsupplier->rmbBankAmount = $rmbBankAmount;
|
|
$bookingsupplier->book_id = $booking->id;
|
|
$bookingsupplier->save();
|
|
|
|
// update booking status
|
|
$booking->status = 4;
|
|
$booking->admin_status = 4;
|
|
$booking->save();
|
|
|
|
// TODO : generate a jpg version of report and save the path
|
|
|
|
return response()->json($bookingsupplier, 201);
|
|
}
|
|
|
|
|
|
public function update(Request $request, $id)
|
|
{
|
|
$bookingsupplier = BSupplierBooking::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();
|
|
|
|
// $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);
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|