mirror of
https://gitlab.com/omair-personal/exchange.git
synced 2026-08-19 12:34:13 +00:00
179 lines
6.2 KiB
PHP
179 lines
6.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Booking;
|
|
use App\Rate;
|
|
use App\User;
|
|
use Auth;
|
|
use Illuminate\Http\Request;
|
|
|
|
class BookingController extends Controller
|
|
{
|
|
public function store(Request $request)
|
|
{
|
|
$rates = Rate::all()->last();
|
|
$term = $request->input('term');
|
|
$rate = 1; // default
|
|
switch ($term) {
|
|
case "x1_cash":
|
|
$rate = $rates->x1_cash;
|
|
break;
|
|
case "x1_cheque":
|
|
$rate = $rates->x1_cheque;
|
|
break;
|
|
case "x1_ba":
|
|
$rate = $rates->x1_ba;
|
|
break;
|
|
case "x2_cash":
|
|
$rate = $rates->x2_cash;
|
|
break;
|
|
case "x2_cheque":
|
|
$rate = $rates->x2_cheque;
|
|
break;
|
|
case "x2_ba":
|
|
$rate = $rates->x2_ba;
|
|
break;
|
|
default:
|
|
return response()->json([
|
|
'success' => false,
|
|
'message' => 'Invalid input',
|
|
], 422);
|
|
break;
|
|
}
|
|
|
|
// Calculation
|
|
|
|
// Service charge
|
|
$amount = $request->input("amount");
|
|
if ($amount >= 10000 && ($term == 'x2_cash' || $term = 'x2_cheque' || $term = 'x2_ba')) {
|
|
$svcharge = 0;
|
|
} else {
|
|
$svcharge = 20.00;
|
|
}
|
|
|
|
// Total bankin ammount
|
|
//gst = 0.00% -> (0*($amount + $svcharge))
|
|
$bia = round(($amount + $svcharge) / $rate + (0 * ($amount + $svcharge)), 2);
|
|
|
|
// New booking
|
|
// TODO : different method for USD and RMB
|
|
$booking = new Booking();
|
|
$booking->account_name = $request->input('account_name');
|
|
$booking->account_num = $request->input('account_num');
|
|
$booking->bank_name = $request->input('bank_name');
|
|
$booking->bank_branch = $request->input('bank_branch');
|
|
$booking->company_name = $request->input('company_name');
|
|
$booking->company_address = $request->input('company_address');
|
|
$booking->bank_address = $request->input('bank_address');
|
|
$booking->swift_code = $request->input('swift_code');
|
|
$booking->cnap = $request->input('cnap');
|
|
$booking->term = $request->input('term');
|
|
$booking->amount = $request->input('amount');
|
|
$booking->rate_id = $rate;
|
|
|
|
$booking->rmb_book_amount = $request->input('rmb_book_amount');
|
|
$booking->rmb_book_pay_method = $request->input('rmb_book_pay_method');
|
|
$booking->rmb_book_account_name = $request->input('rmb_book_account_name');
|
|
$booking->rmb_book_acc_no = $request->input('rmb_book_acc_no');
|
|
$booking->rmb_book_bank_branch = $request->input('rmb_book_bank_branch');
|
|
|
|
$booking->usd_book_amount = $request->input('usd_book_amount');
|
|
$booking->usd_book_pay_method = $request->input('usd_book_pay_method');
|
|
$booking->usd_book_company_name = $request->input('usd_book_company_name');
|
|
$booking->usd_book_company_address = $request->input('usd_book_company_address');
|
|
$booking->usd_book_swift_code = $request->input('usd_book_swift_code');
|
|
$booking->usd_book_cnap = $request->input('usd_book_cnap');
|
|
$booking->usd_book_bank_branch = $request->input('usd_book_bank_branch');
|
|
$booking->verification_status = $request->input('verification_status');
|
|
$booking->user()->associate(Auth::user());
|
|
$booking->bia = $bia;
|
|
$booking->save();
|
|
|
|
return response()->json($booking, 201);
|
|
}
|
|
|
|
public function update(Request $request, $book_id)
|
|
{
|
|
$booking = Booking::where('user_id', Auth::user())->where('id', $book_id)->firstOrFail();
|
|
$booking->account_name = $request->input('account_name');
|
|
$booking->account_num = $request->input('account_num');
|
|
$booking->bank_name = $request->input('bank_name');
|
|
$booking->bank_branch = $request->input('bank_branch');
|
|
$booking->company_name = $request->input('company_name');
|
|
$booking->company_address = $request->input('company_address');
|
|
$booking->bank_address = $request->input('bank_address');
|
|
$booking->swift_code = $request->input('swift_code');
|
|
$booking->cnap = $request->input('cnap');
|
|
$booking->save();
|
|
return response()->json(['book_id' => $book_id], 200);
|
|
}
|
|
|
|
public function delete(Booking $book_id)
|
|
{
|
|
$booking = Booking::where('user_id', Auth::user())->where('id', $book_id)->firstOrFail();
|
|
$booking->delete($book_id);
|
|
return response()->json($book_id, 204);
|
|
}
|
|
|
|
// TODO : cancel booking feature
|
|
|
|
public function calculation(Request $request){
|
|
$amount = $request->input('amount');
|
|
$term = $request->input('term');
|
|
$rates = Rate::all()->last();
|
|
|
|
// TODO : get marking
|
|
$marking = "123X";
|
|
|
|
switch ($term) {
|
|
case "x1_cash":
|
|
$rate = $rates->x1_cash;
|
|
$payment_method = "cash";
|
|
break;
|
|
case "x1_cheque":
|
|
$rate = $rates->x1_cheque;
|
|
$payment_method = "Cheque";
|
|
break;
|
|
case "x1_ba":
|
|
$rate = $rates->x1_ba;
|
|
$payment_method = "BA";
|
|
break;
|
|
case "x2_cash":
|
|
$rate = $rates->x2_cash;
|
|
$payment_method = "Cash";
|
|
break;
|
|
case "x2_cheque":
|
|
$rate = $rates->x2_cheque;
|
|
$payment_method = "Cheque";
|
|
break;
|
|
case "x2_ba":
|
|
$rate = $rates->x2_ba;
|
|
$payment_method = "BA";
|
|
break;
|
|
default:
|
|
return response()->json([
|
|
'success' => false,
|
|
'message' => 'Invalid input',
|
|
], 422);
|
|
break;
|
|
}
|
|
|
|
if ($amount >= 10000 && ($term == 'x2_cash' || $term = 'x2_cheque' || $term = 'x2_ba')) {
|
|
$svcharge = 0;
|
|
} else {
|
|
$svcharge = 20.00;
|
|
}
|
|
|
|
$bankin_amount = round(($amount + $svcharge) / $rate + (0 * ($amount + $svcharge)), 2);
|
|
|
|
return response()->json([
|
|
'customer_marking' => $marking,
|
|
'payment_method' => $payment_method,
|
|
'service_charge' => $svcharge,
|
|
'rate' => $rate,
|
|
'bankin_amount' => $bankin_amount
|
|
], 200);
|
|
}
|
|
}
|