add logic, test

This commit is contained in:
Nazri
2018-05-30 16:33:11 +08:00
parent 7381252c57
commit cc3ea574f8
5 changed files with 97 additions and 31 deletions
+26 -13
View File
@@ -15,6 +15,13 @@ class BookingController extends Controller
public function store(Request $request)
{
//logic if booking is not belongs to user, prohibit them from accessing the api
$user = User::where("id", Auth::user()->id)->first();
if (!$user)
{
return response()->json(['message'=>'Access denied'],401);
}
$rates = Rate::all()->last();
$term = $request->input('term');
$rate = 1;
@@ -49,23 +56,31 @@ class BookingController extends Controller
}
//Calculation part
//$bookings = Booking::all();
$amount = $request->input("amount");
if ($amount >= 10000 && ($term == 'x2_cash' || $term = 'x2_cheque' || $term = 'x2_ba')) {
//logic : 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;
}
$gst = 0*($amount + $svcharge);
//initial calculation
$RMBinMYR = (($amount + $svcharge) / $rate);
//calculate gst, 0% after 1june 2018
$gst = 0*$RMBinMYR;
$bia = round(($amount + $svcharge) / $rate + $gst,2);
//gst = 0.00% -> (0*($amount + $svcharge))
//bia = bank in amount in MYR
//calculate Sales Tax, 10% of initial calculation
$sales_tax = 0.10*$RMBinMYR;
//calculate billing, 1.5% of initial calculation
$billing = 0.015*$RMBinMYR;
//bia = bank in amount in MYR
$bia = round($RMBinMYR + $gst + $sales_tax + $billing,2);
// return $bia;
$user = Auth::user();
$booking = new Booking();
$booking->account_name = $request->input('account_name');
@@ -97,12 +112,9 @@ class BookingController extends Controller
$booking->verification_status = $request->input('verification_status');
$booking->user()->associate($user);
//$booking->user_id = $request->input('user_id');
$booking->bia = $bia;
$booking->save();
// return false;
//$booking = Booking::create($request->all());
return response()->json($booking, 201);
@@ -136,7 +148,8 @@ class BookingController extends Controller
$post->book_id = $booking->id;
$post->transfer_amount = $request->input('transfer_amount');
$post->bankslip_url = $fileNameToStore;
$post->save();;
$post->save();
return response()->json(['message'=>'Success'],201);
}
@@ -167,13 +180,13 @@ class BookingController extends Controller
$post->amount = $request->input('amount');
$post->image_url = $fileNameToStore;
$post->save();
return response()->json(['message'=>'Success'],201);
}
public function update(Request $request, $book_id)
{
$book_id = Booking::find($book_id);
//$com_id->id = $request->input('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');