mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange.git
synced 2026-08-19 12:24:09 +00:00
Merge branch 'master' of gitlab.com:CIEFWorldwideSdnBhd/exchange into fix/bug
# Conflicts: # app/Http/Controllers/BookingController.php # resources/assets/js/pages/home.vue
This commit is contained in:
@@ -13,6 +13,7 @@ use App\Invoice;
|
||||
use App\SettingCredit;
|
||||
use App\SettingTaxRate;
|
||||
use App\SettingBillingCharge;
|
||||
use App\Notification;
|
||||
use Auth;
|
||||
use Validator;
|
||||
use DateTime;
|
||||
@@ -80,7 +81,7 @@ class BookingController extends Controller
|
||||
$user = Auth::user();
|
||||
$bookings = Booking::select('user_id', 'id', 'created_at', 'admin_status', 'rate', 'term', 'amount', 'bia', 'verification_status')
|
||||
->orderby('updated_at','desc')
|
||||
->get();
|
||||
->paginate(10);
|
||||
|
||||
// reformat to fit frontend structure
|
||||
foreach ($bookings as $booking) {
|
||||
@@ -248,7 +249,9 @@ class BookingController extends Controller
|
||||
$term = $request->input('term');
|
||||
$amount = $request->input("amount"); // in RMB
|
||||
$rates = Rate::orderby('updated_at','desc')->first();
|
||||
$creditLimit = SettingCredit::orderby('updated_at','desc')->first();
|
||||
$creditLimit = SettingCredit::orderby('updated_at','desc')->first();
|
||||
$taxrate = SettingTaxRate::latest()->first()->tax_rate;
|
||||
$billingChargeRate = SettingBillingCharge::latest()->first()->billing_charge_rate;
|
||||
|
||||
if (!$creditLimit){
|
||||
return response()->json("Credit limit not set, please contact admin", 405);
|
||||
@@ -290,27 +293,31 @@ class BookingController extends Controller
|
||||
}
|
||||
|
||||
// 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')) {
|
||||
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);
|
||||
|
||||
$subtotal = round(($amount + $svcharge) / $rate,2);
|
||||
|
||||
// TODO : refactor
|
||||
if ($taxrate !=0){
|
||||
$taxAmount = round($subtotal * $taxrate - $subtotal,2);
|
||||
}
|
||||
else{
|
||||
$taxAmount = 0;
|
||||
}
|
||||
|
||||
if ($billingChargeRate !=0){
|
||||
$billingChargeAmount = round(($amount + $svcharge) * $billingChargeRate - ($amount + $svcharge), 2);
|
||||
}
|
||||
else{
|
||||
$billingChargeAmount = 0;
|
||||
}
|
||||
|
||||
$billingChargeAmount = round((($amount / $rate) * $billingChargeRate) - ($amount / $rate), 2);
|
||||
$bankin_amount = round($subtotal + $taxAmount + $billingChargeAmount , 2);
|
||||
|
||||
$booking = new Booking();
|
||||
$booking->account_name = $request->input('account_name');
|
||||
@@ -323,9 +330,9 @@ class BookingController extends Controller
|
||||
$booking->term = $term;
|
||||
$booking->rate_id = $rates->id;
|
||||
$booking->rate = $rate;
|
||||
$booking->rmb_book_amount = $request->input('amount');
|
||||
$booking->rmb_book_amount = $request->input('amount'); // BIG TODO : amount change variable name to rmb_book_amount
|
||||
$booking->status = 2;
|
||||
$booking->bia = $bia;
|
||||
$booking->bia = $bankin_amount; // BID TODO : change bia viariable name
|
||||
// $booking->user_id = $user->id;
|
||||
$booking->user()->associate($user);
|
||||
|
||||
@@ -456,9 +463,16 @@ class BookingController extends Controller
|
||||
$booking->admin_status = 2;
|
||||
$booking->save();
|
||||
|
||||
// Add notification message to admin
|
||||
$adminNotification = new Notification;
|
||||
$adminNotification->detail = "A bankslip is uploaded for booking " . $booking->id;
|
||||
$adminNotification->link = "/booking/" . $booking->id . "/verification";
|
||||
$adminNotification->user_id = User::withRole('admin')->first()->id;
|
||||
$adminNotification->save();
|
||||
|
||||
$user_bankslip->transfer_amount = $request->input('transfer_amount');
|
||||
$user_bankslip->save();
|
||||
return response()->json(["message"=> "Success"],200);
|
||||
return response()->json($adminNotification,200);
|
||||
}
|
||||
|
||||
public function uploadPurchaseOrder(Request $request, $id)
|
||||
@@ -570,7 +584,6 @@ class BookingController extends Controller
|
||||
if($amount > $creditLimit->rmb_credit_limit){
|
||||
return response()->json(["message" => "Exceed credit limit, please contact our sales team for larger quantitiy"], 400);
|
||||
}
|
||||
|
||||
|
||||
switch ($term) {
|
||||
case "x1_cash":
|
||||
@@ -604,16 +617,31 @@ class BookingController extends Controller
|
||||
], 422);
|
||||
break;
|
||||
}
|
||||
|
||||
if (($amount >= 10000) && ($term == 'x2_cash' || $term == 'x2_cheque' || $term == 'x2_ba')) {
|
||||
|
||||
if ($amount >= 10000 && ($term == 'x2_cash' || $term == 'x2_cheque' || $term == 'x2_ba')) {
|
||||
$svcharge = 0;
|
||||
} else {
|
||||
$svcharge = 20.00;
|
||||
}
|
||||
|
||||
$subtotal = round($amount + $svcharge / $rate,2);
|
||||
$taxAmount = round($subtotal * $taxrate,2);
|
||||
$billingChargeAmount = round(($amount + $svcharge) * $billingChargeRate, 2);
|
||||
$subtotal = round(($amount + $svcharge) / $rate,2);
|
||||
|
||||
// TODO : refactor
|
||||
if ($taxrate !=0){
|
||||
$taxAmount = round($subtotal * $taxrate - $subtotal,2);
|
||||
}
|
||||
else{
|
||||
$taxAmount = 0;
|
||||
}
|
||||
|
||||
if ($billingChargeRate !=0){
|
||||
$billingChargeAmount = round(($amount + $svcharge) * $billingChargeRate - ($amount + $svcharge), 2);
|
||||
}
|
||||
else{
|
||||
$billingChargeAmount = 0;
|
||||
}
|
||||
|
||||
$billingChargeAmount = round((($amount / $rate) * $billingChargeRate) - ($amount / $rate), 2);
|
||||
$bankin_amount = round($subtotal + $taxAmount + $billingChargeAmount , 2);
|
||||
|
||||
return response()->json([
|
||||
@@ -630,6 +658,8 @@ class BookingController extends Controller
|
||||
'taxAmount' => $taxAmount,
|
||||
'billingChargeAmount' => $billingChargeAmount,
|
||||
'bankin_amount' => $bankin_amount,
|
||||
'acc_name' => $request->input('acc_name'),
|
||||
'acc_no' => $request->input('acc_no')
|
||||
], 200);
|
||||
}
|
||||
|
||||
@@ -660,11 +690,26 @@ class BookingController extends Controller
|
||||
|
||||
// update booking status
|
||||
$booking->status = 4;
|
||||
if($booking->term !== "x1_ba" || $booking->term !== "x2_cheque")
|
||||
if($booking->term !== "x1_ba" || $booking->term !== "x2_cheque"){
|
||||
$booking->admin_status = 3;
|
||||
else
|
||||
// Add notification message to user
|
||||
$userNotification = new Notification;
|
||||
$userNotification->detail = "Your bankslip for booking " . $booking->id . " is approved.";
|
||||
$userNotification->link = "/booking/" . $booking->id . "/transfer";
|
||||
$userNotification->user_id = $booking->user_id;
|
||||
$userNotification->save();
|
||||
}
|
||||
else{
|
||||
$booking->admin_status = 5;
|
||||
// Add notification message to user
|
||||
$userNotification = new Notification;
|
||||
$userNotification->detail = "Your bankslip for booking " . $booking->id . " is approved.";
|
||||
$userNotification->link = "/booking/" . $booking->id . "/supplier";
|
||||
$userNotification->user_id = $booking->user_id;
|
||||
$userNotification->save();
|
||||
}
|
||||
$booking->save();
|
||||
|
||||
|
||||
return response()->json(['message'=>'Success'],200);
|
||||
}
|
||||
@@ -760,6 +805,11 @@ class BookingController extends Controller
|
||||
$booking->admin_status = 5; // upload china bankslip
|
||||
|
||||
if($booking->save()){
|
||||
$userNotification = new Notification;
|
||||
$userNotification->detail = "Supplier booking report for booking " . $booking->id . " is completed.";
|
||||
$userNotification->link = "/booking/" . $booking->id . "/transfer";
|
||||
$userNotification->user_id = $booking->user_id;
|
||||
$userNotification->save();
|
||||
return response()->json(['message'=>"Success"],200);
|
||||
}
|
||||
}
|
||||
@@ -768,16 +818,21 @@ class BookingController extends Controller
|
||||
$booking = Booking::where('user_id',Auth::user()->id)->where('id',$id)->first();
|
||||
|
||||
$purchase_order = $booking->purchaseOrder()->first();
|
||||
return($purchase_order);
|
||||
|
||||
if(!$purchase_order){
|
||||
return response()->json(["message"=> "Please upload your purchase order"],400);
|
||||
}
|
||||
|
||||
$booking->status = 6; // wait invoice
|
||||
$booking->admin_status = 6; // upload invoice
|
||||
$booking->save();
|
||||
return response()->json(['message'=>'Success'],200);
|
||||
|
||||
$adminNotification = new Notification;
|
||||
$adminNotification->detail = "Purchase Order for booking " . $booking->id . " is uploaded.";
|
||||
$adminNotification->link = "/booking/" . $booking->id . "/upload-invoice";
|
||||
$adminNotification->user_id = User::withRole('admin')->first()->id;
|
||||
$adminNotification->save();
|
||||
|
||||
return response()->json($purchase_order,200);
|
||||
}
|
||||
|
||||
public function confirmInvoice(Request $request, $id)
|
||||
@@ -794,6 +849,11 @@ class BookingController extends Controller
|
||||
$booking->admin_status = 7; // completed
|
||||
|
||||
if($booking->save()){
|
||||
$adminNotification = new Notification;
|
||||
$adminNotification->detail = "Invoice for booking " . $booking->id . " is uploaded.";
|
||||
$adminNotification->link = "/booking/" . $booking->id . "/complete";
|
||||
$adminNotification->user_id = $booking->user_id;
|
||||
$adminNotification->save();
|
||||
return response()->json(['message'=>"Success"],200);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user