mirror of
https://gitlab.com/omair-personal/exchange.git
synced 2026-08-19 12:34:13 +00:00
fix conflit with master
This commit is contained in:
@@ -17,135 +17,179 @@ use DateTime;
|
||||
class BookingController extends Controller
|
||||
{
|
||||
|
||||
public function show($id)
|
||||
{
|
||||
$booking = Booking::where('user_id',Auth::user()->id)->where('id', $id)->first();
|
||||
public function index(){
|
||||
$bookings = Booking::select('id', 'created_at', 'status', 'rate', 'amount', 'bia', 'verification_status')
|
||||
->where('user_id',Auth::user()->id)
|
||||
->get();
|
||||
|
||||
// reformat to fit frontend structure
|
||||
foreach ($bookings as $booking) {
|
||||
// set timeout
|
||||
$date1 = new DateTime($booking->created_at);
|
||||
$date2 = new DateTime();
|
||||
$difference_in_seconds = ($date1->format('U') + 600) - ($date2->format('U'));
|
||||
$booking->timeout = $difference_in_seconds;
|
||||
|
||||
$date1 = new DateTime($booking->created_at);
|
||||
$date2 = new DateTime();
|
||||
$difference_in_seconds = ($date1->format('U') + 600) - ($date2->format('U'));
|
||||
// TODO : you can make it better
|
||||
if($difference_in_seconds < 0 ){
|
||||
$booking->timeout = 0;
|
||||
}
|
||||
|
||||
|
||||
// TODO : transfer_amount change name to bia
|
||||
$booking->transfer_amount = $booking->bia;
|
||||
|
||||
$booking->track_status = "(". $booking->status ."/6)";
|
||||
|
||||
$booking->timeout = $difference_in_seconds;
|
||||
switch ($booking->status) {
|
||||
case 1:
|
||||
$booking->status_desc = "Order in progress";
|
||||
case 2:
|
||||
$booking->status_desc = "Waiting for payment";
|
||||
case 3:
|
||||
$booking->status_desc = "Waiting verification";
|
||||
case 4:
|
||||
$booking->status_desc = "Processing transfer";
|
||||
case 5:
|
||||
$booking->status_desc = "Transfer Complete, please upload your PO";
|
||||
case 6:
|
||||
$booking->status_desc = "Processing invoice";
|
||||
default:
|
||||
$booking->status_desc = "";
|
||||
}
|
||||
}
|
||||
|
||||
if (!$booking){
|
||||
return response()->json(['success'=>false, 'message'=>'not found'], 404);
|
||||
}
|
||||
return $booking;
|
||||
}
|
||||
return $bookings;
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$rates = Rate::orderby('updated_at','desc')->first();
|
||||
$term = $request->input('term');
|
||||
$amount = $request->input("amount");
|
||||
$user = Auth::user();
|
||||
$rate = 1; // default rate to 1
|
||||
public function show($id)
|
||||
{
|
||||
$booking = Booking::where('user_id',Auth::user()->id)->where('id', $id)->first();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
// Service charge (RMB) : if amount higher than 10,000, no service charge. if amount lower than 10,000, 20.00 service charge
|
||||
if ($amount >= 10000 && ($term == 'x2_cash' || $term = 'x2_cheque' || $term = 'x2_ba')) {
|
||||
$svcharge = 0;
|
||||
} else {
|
||||
$svcharge = 20.00;
|
||||
}
|
||||
$date1 = new DateTime($booking->created_at);
|
||||
$date2 = new DateTime();
|
||||
$difference_in_seconds = ($date1->format('U') + 600) - ($date2->format('U'));
|
||||
|
||||
// initial rmb to myr amount
|
||||
$RMBinMYR = (($amount + $svcharge) / $rate);
|
||||
$booking->timeout = $difference_in_seconds;
|
||||
|
||||
// TODO : Should be remove this ?
|
||||
// gst 0%
|
||||
$gst = 0 * $RMBinMYR;
|
||||
if (!$booking){
|
||||
return response()->json(['success'=>false, 'message'=>'not found'], 404);
|
||||
}
|
||||
return $booking;
|
||||
}
|
||||
|
||||
// Sales tax : 10 %
|
||||
$sales_tax = 0.10 * $RMBinMYR;
|
||||
public function store(Request $request)
|
||||
{
|
||||
$rates = Rate::orderby('updated_at','desc')->first();
|
||||
$term = $request->input('term');
|
||||
$amount = $request->input("amount");
|
||||
$user = Auth::user();
|
||||
$rate = 1; // default rate to 1
|
||||
|
||||
// Billing fees : 1.5%
|
||||
$billing = 0.015 * $RMBinMYR;
|
||||
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;
|
||||
}
|
||||
|
||||
// Service charge (RMB) : if amount higher than 10,000, no service charge. if amount lower than 10,000, 20.00 service charge
|
||||
if ($amount >= 10000 && ($term == 'x2_cash' || $term = 'x2_cheque' || $term = 'x2_ba')) {
|
||||
$svcharge = 0;
|
||||
} else {
|
||||
$svcharge = 20.00;
|
||||
}
|
||||
|
||||
// Bank in amount
|
||||
$bia = round($RMBinMYR + $gst + $sales_tax + $billing, 2);
|
||||
// initial rmb to myr amount
|
||||
$RMBinMYR = (($amount + $svcharge) / $rate);
|
||||
|
||||
$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->amount = $request->input('amount');
|
||||
$booking->term = $term;
|
||||
$booking->rate_id = $rates->id;
|
||||
$booking->rmb_book_amount = $request->input('amount');
|
||||
$booking->bia = $bia;
|
||||
// $booking->user_id = $user->id;
|
||||
$booking->user()->associate($user);
|
||||
|
||||
// TODO : Should be remove this ?
|
||||
// gst 0%
|
||||
$gst = 0 * $RMBinMYR;
|
||||
|
||||
// The test failed due to ->save() before filling up the information at below
|
||||
// Sales tax : 10 %
|
||||
$sales_tax = 0.10 * $RMBinMYR;
|
||||
|
||||
// TODO : handle RMB, MYR and USD (we can use exchange type: USDtoMYR, RMBtoMYR vise versa to switch case)
|
||||
// $booking->rmb_book_pay_method = $request->input('payment_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->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');
|
||||
// Billing fees : 1.5%
|
||||
$billing = 0.015 * $RMBinMYR;
|
||||
|
||||
// $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->save();
|
||||
return response()->json($booking, 201);
|
||||
}
|
||||
// Bank in amount
|
||||
$bia = round($RMBinMYR + $gst + $sales_tax + $billing, 2);
|
||||
|
||||
public function update(Request $request, $book_id)
|
||||
{
|
||||
$book_id = Booking::find($book_id);
|
||||
$book_id->account_name = $request->input('account_name');
|
||||
$book_id->account_num = $request->input('account_num');
|
||||
$book_id->bank_name = $request->input('bank_name');
|
||||
$book_id->bank_branch = $request->input('bank_branch');
|
||||
$book_id->company_name = $request->input('company_name');
|
||||
$book_id->company_address = $request->input('company_address');
|
||||
$book_id->bank_address = $request->input('bank_address');
|
||||
$book_id->swift_code = $request->input('swift_code');
|
||||
$book_id->cnap = $request->input('cnap');
|
||||
$book_id->save();
|
||||
$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->amount = $request->input('amount');
|
||||
$booking->term = $term;
|
||||
$booking->rate_id = $rates->id;
|
||||
$booking->rate = $rate;
|
||||
$booking->rmb_book_amount = $request->input('amount');
|
||||
$booking->status = 2;
|
||||
$booking->bia = $bia;
|
||||
// $booking->user_id = $user->id;
|
||||
$booking->user()->associate($user);
|
||||
|
||||
|
||||
// The test failed due to ->save() before filling up the information at below
|
||||
|
||||
// TODO : handle RMB, MYR and USD (we can use exchange type: USDtoMYR, RMBtoMYR vise versa to switch case)
|
||||
// $booking->rmb_book_pay_method = $request->input('payment_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->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->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->save();
|
||||
return response()->json($booking, 201);
|
||||
}
|
||||
|
||||
public function update(Request $request, $book_id)
|
||||
{
|
||||
$book_id = Booking::find($book_id);
|
||||
$book_id->account_name = $request->input('account_name');
|
||||
$book_id->account_num = $request->input('account_num');
|
||||
$book_id->bank_name = $request->input('bank_name');
|
||||
$book_id->bank_branch = $request->input('bank_branch');
|
||||
$book_id->company_name = $request->input('company_name');
|
||||
$book_id->company_address = $request->input('company_address');
|
||||
$book_id->bank_address = $request->input('bank_address');
|
||||
$book_id->swift_code = $request->input('swift_code');
|
||||
$book_id->cnap = $request->input('cnap');
|
||||
$book_id->save();
|
||||
|
||||
return response()->json(['book_id'=>$book_id],200);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user