mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange.git
synced 2026-08-19 20:34:08 +00:00
97062480d5
update routes with booking id pramas fixed not found routes fixed count down with real data moved bookings routes into autenticated route
323 lines
11 KiB
PHP
323 lines
11 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\PurchaseOrder;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use App\Booking;
|
|
use App\Rate;
|
|
use App\UserBankSlip;
|
|
use App\User;
|
|
use Auth;
|
|
use Validator;
|
|
use DateTime;
|
|
|
|
class BookingController extends Controller
|
|
{
|
|
|
|
public function show($id)
|
|
{
|
|
$booking = Booking::where('user_id',Auth::user()->id)->where('id', $id)->first();
|
|
|
|
$date1 = new DateTime($booking->created_at);
|
|
$date2 = new DateTime();
|
|
$difference_in_seconds = ($date1->format('U') + 60) - ($date2->format('U'));
|
|
|
|
|
|
|
|
$booking->timeout = $difference_in_seconds;
|
|
|
|
if (!$booking){
|
|
return response()->json(['success'=>false, 'message'=>'not found'], 404);
|
|
}
|
|
return $booking;
|
|
}
|
|
|
|
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
|
|
|
|
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;
|
|
}
|
|
|
|
// initial rmb to myr amount
|
|
$RMBinMYR = (($amount + $svcharge) / $rate);
|
|
|
|
// TODO : Should be remove this ?
|
|
// gst 0%
|
|
$gst = 0 * $RMBinMYR;
|
|
|
|
// Sales tax : 10 %
|
|
$sales_tax = 0.10 * $RMBinMYR;
|
|
|
|
// Billing fees : 1.5%
|
|
$billing = 0.015 * $RMBinMYR;
|
|
|
|
// Bank in amount
|
|
$bia = round($RMBinMYR + $gst + $sales_tax + $billing, 2);
|
|
|
|
|
|
$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-;
|
|
$booking->user()->associate($user);
|
|
$booking->save();
|
|
|
|
// 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');
|
|
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);
|
|
}
|
|
|
|
public function uploadbankslip(Request $request, $id)
|
|
{
|
|
$booking = Booking::where('user_id',Auth::user()->id)->where('id',$id)->first();
|
|
|
|
/* Validation*/
|
|
if (!$booking)
|
|
{
|
|
return response()->json(['message'=>'Access denied'], 200);
|
|
}
|
|
|
|
$validator = Validator::make($request->all(), [
|
|
'bankslip_url' => 'image|mimes:jpg,jpeg,bmp,png'
|
|
]);
|
|
|
|
if($validator->fails())
|
|
{
|
|
return response()->json(['message'=>'Incorrect format'],200);
|
|
}
|
|
|
|
if(!$bankslip_file = $request->file('bankslip_url'))
|
|
{
|
|
return response()->json(['message' => 'No file detected'], 400);
|
|
}
|
|
/* End Validation */
|
|
|
|
$filename = $bankslip_file->getClientOriginalName();
|
|
$ext = $bankslip_file->getClientOriginalExtension();
|
|
$input['bankslip_url'] = $filename;
|
|
|
|
$unique_name = 'bank_slip_' . md5($filename. time());
|
|
$unique_image_url = $unique_name. '.' .$ext;
|
|
Storage::putFileAs(
|
|
'bankslip_url',/*folder name*/ $bankslip_file, $unique_image_url
|
|
);
|
|
|
|
// why ?
|
|
$booking->cust_marking = $request->input('cust_marking');
|
|
$booking->bank_slip_type = $request->input('bank_slip_type');
|
|
|
|
$user_bankslip = new UserBankSlip;
|
|
$user_bankslip->book_id = $booking->id;
|
|
$user_bankslip->bankslip_url = $unique_image_url;
|
|
$user_bankslip->transfer_amount = $request->input('transfer_amount');
|
|
$user_bankslip->save();
|
|
|
|
return response()->json(['message'=>"Success"],200);
|
|
}
|
|
|
|
public function uploadPurchaseOrder(Request $request, $id)
|
|
{
|
|
$booking = Booking::where('user_id',Auth::user()->id)->where('id',$id)->first();
|
|
|
|
/* Validation */
|
|
if (!$booking)
|
|
{
|
|
return response()->json(['message'=>'Access denied'], 200);
|
|
}
|
|
|
|
$validator = Validator::make($request->all(), [
|
|
'image_url' => 'image|mimes:jpg,jpeg,bmp,png'
|
|
]);
|
|
|
|
if($validator->fails())
|
|
{
|
|
return response()->json(['message'=>'Incorrect format'],200);
|
|
}
|
|
|
|
if(!$user_input_file = $request->file('image_url'))
|
|
{
|
|
return response()->json(['message' => 'No file detected'], 400);
|
|
}
|
|
/* End Validation */
|
|
|
|
$filename = $user_input_file->getClientOriginalName();
|
|
$ext = $user_input_file->getClientOriginalExtension();
|
|
|
|
$input['image_url'] = $filename;
|
|
$unique_name = 'purchase_order_' . md5($filename. time());
|
|
$unique_image_url = $unique_name. '.' .$ext;
|
|
Storage::putFileAs(
|
|
'image_url',/*folder name*/ $user_input_file, $unique_image_url
|
|
);
|
|
|
|
$user_po = new PurchaseOrder;
|
|
$user_po->image_url = $unique_image_url;
|
|
$user_po->book_id = $booking->id;
|
|
$user_po->amount = $request->input('amount');
|
|
$user_po->save();
|
|
|
|
return response()->json(['message'=>'Success'],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);
|
|
}
|
|
|
|
public function cancel(Request $request, $book_id)
|
|
{
|
|
if (!$booking = Booking::where('user_id',Auth::user()->id)->where('id',$book_id)->first())
|
|
{
|
|
return response()->json(['message'=>'Access denied'], 200);
|
|
}
|
|
|
|
$booking->is_cancel = true;
|
|
$booking->save();
|
|
|
|
return response()->json(['message'=>'Success'],200);
|
|
}
|
|
|
|
public function calculation(Request $request){
|
|
$amount = $request->input('amount');
|
|
$term = $request->input('term');
|
|
$china_beneficiary = $request->input('china_beneficiary');
|
|
$rates = Rate::orderby('updated_at','desc')->first();
|
|
|
|
// 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([
|
|
'date' => date('Y-m-d'),
|
|
'marking' => $marking,
|
|
'amount' => $amount,
|
|
'payment_method' => $payment_method,
|
|
'service_charge' => $svcharge,
|
|
'rate' => $rate,
|
|
'bankin_amount' => $bankin_amount,
|
|
'china_beneficary' => $china_beneficiary
|
|
], 200);
|
|
}
|
|
} |