mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange.git
synced 2026-08-21 21:34:16 +00:00
updated only booking belongs to user can update or delete the booking
phpfmt booking controller removed example test moved booking test to feature
This commit is contained in:
@@ -2,193 +2,118 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Booking;
|
||||
use App\Rate;
|
||||
use App\User;
|
||||
use Auth;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class BookingController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
//public function index()
|
||||
//{
|
||||
// return response()->json(['success' => true, 'message'=> "You have successfully logged out."]);
|
||||
//}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
//public function create()
|
||||
//{
|
||||
// return response()->json(['success' => true, 'message'=> "Success"]);
|
||||
//}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$rates = Rate::all()->last();
|
||||
$term = $request->input('term');
|
||||
$rate = 1;
|
||||
|
||||
switch($term){
|
||||
$rate = 1; // default
|
||||
switch ($term) {
|
||||
case "x1_cash":
|
||||
$rate = $rates->x1_cash;
|
||||
$rate = $rates->x1_cash;
|
||||
break;
|
||||
case "x1_cheque":
|
||||
$rate = $rates->x1_cheque;
|
||||
$rate = $rates->x1_cheque;
|
||||
break;
|
||||
case "x1_ba":
|
||||
$rate = $rates->x1_ba;
|
||||
break;
|
||||
case "x2_cash":
|
||||
$rate = $rates->x2_cash;
|
||||
$rate = $rates->x2_cash;
|
||||
break;
|
||||
case "x2_cheque":
|
||||
$rate = $rates->x2_cheque;
|
||||
$rate = $rates->x2_cheque;
|
||||
break;
|
||||
case "x2_ba":
|
||||
$rate = $rates->x2_ba;
|
||||
break;
|
||||
default:
|
||||
|
||||
//$rate = "no";
|
||||
return Response::json(array(
|
||||
'code' => 422,
|
||||
'message' => 'Invalid input'
|
||||
return Response::json(array(
|
||||
'success' => false,
|
||||
'message' => 'Invalid input',
|
||||
), 422);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
//Calculation part
|
||||
// $bookings = Booking::all();
|
||||
// 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;
|
||||
}
|
||||
else {
|
||||
$svcharge = 20.00;
|
||||
}
|
||||
|
||||
$bia = round(($amount + $svcharge) / $rate + (0*($amount + $svcharge)), 2);
|
||||
// Total bankin ammount
|
||||
//gst = 0.00% -> (0*($amount + $svcharge))
|
||||
//bia = bank in amount in MYR
|
||||
$bia = round(($amount + $svcharge) / $rate + (0 * ($amount + $svcharge)), 2);
|
||||
|
||||
// return $bia;
|
||||
$user = Auth::user();
|
||||
$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;
|
||||
// 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->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->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();
|
||||
|
||||
$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);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
//public function show($id)
|
||||
//{
|
||||
// $booking = Booking::find($id);
|
||||
// return view('booking.index');
|
||||
//}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
//public function edit($id)
|
||||
//{
|
||||
//
|
||||
//}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
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');
|
||||
$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);
|
||||
|
||||
|
||||
|
||||
{
|
||||
$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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function delete(Booking $book_id)
|
||||
{
|
||||
$book_id->delete($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 function
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user