fix discussion 2

This commit is contained in:
Nazri Hamzah
2018-06-20 12:15:33 +08:00
parent 8fa4f15818
commit 32bf2f4375
@@ -3,6 +3,9 @@
namespace App\Http\Controllers;
use App\BookingSupplier;
use App\Booking;
use App\Rate;
use App\User;
use App\UserBankSlip;
use Illuminate\Http\Request;
@@ -11,10 +14,10 @@ class BookingSupplierController extends Controller
public function index()
{
$booking = BookingSupplier::all();
$bookingsupplier = BookingSupplier::all();
$response = [
'supplier-booking' => $booking
'supplier-booking' => $bookingsupplier
];
return response()->json($response, 200);
}
@@ -22,7 +25,7 @@ class BookingSupplierController extends Controller
// function show($id)
public function show($id)
{
$booking = BookingSupplier::has('supplier-booking')->findOrFail($id);
$bookingsupplier = BookingSupplier::has('supplier-booking')->findOrFail($id);
$response = [
'supplier-booking' => $booking
@@ -52,7 +55,7 @@ class BookingSupplierController extends Controller
{
//Calculation part
//single booking supplier
$amount = $request->input("payment_amount");
$payment_amount = $request->input("payment_amount");
$rate = $request->input("rate");
$rebate = $request->input("rebate");
@@ -64,22 +67,51 @@ class BookingSupplierController extends Controller
$rmbBankAmount = $customerBankInAmount + $rebate;
$user = Auth::user();
$booking = new BookingSupplier();
$bookingsupplier = new BookingSupplier();
$supplier = SettingSupplier::find($id);
$booking->supplier_id = $supplier->id;
$bookingsupplier->supplier_id = $supplier->id;
$booking->payment_method = $request->input('payment_method');
$booking->payment_amount = $request->input('payment_amount');
$booking->rate = $request->input('rate');
$booking->rebate = $request->input('rebate');
$bookingsupplier->payment_method = $request->input('payment_method');
$bookingsupplier->payment_amount = $request->input('payment_amount');
$bookingsupplier->rate = $request->input('rate');
$bookingsupplier->rebate = $request->input('rebate');
$booking->user()->associate($user);
$booking->amountInRMB = $amountInRMB;
$booking->rmbBankAmount = $rmbBankAmount;
$booking->save();
$bookingsupplier->user()->associate($user);
$bookingsupplier->amountInRMB = $amountInRMB;
$bookingsupplier->rmbBankAmount = $rmbBankAmount;
return response()->json($booking, 201);
$bookingsupplier->save();
//one bookingsupplier has many booking
foreach ($bookingsupplier as $booking)
{
$manybooking = new Booking(array(
'book_id' => $booking->id,
'term' => $booking['term'],
'amount' => $booking['amount'],
'account_name' => $booking['account_name'],
'account_num' => $booking['account_num'],
'bank_name' => $booking['bank_name'],
'bank_branch' => $booking['account_name'],
'company_name' => $booking['company_name'],
'company_address' => $booking['company_address'],
'bank_address' => $booking['bank_address'],
'swift_code' => $booking['swift_code'],
'cnap' => $booking['cnap'],
'verification_status' => $booking['verification_status'],
'rmb_book_amount' => $booking['rmb_book_amount'],
'rmb_book_pay_method' => $booking['rmb_book_pay_method'],
'rmb_book_account_name' => $booking['rmb_book_account_name'],
'rmb_book_bank_name' => $booking['rmb_book_bank_name'],
'rmb_book_acc_no' => $booking['rmb_book_acc_no'],
'rmb_book_bank_branch' => $booking['rmb_book_bank_branch'],
));
$manybooking->save();
}
return response()->json($bookingsupplier, 201);
}
@@ -87,11 +119,11 @@ class BookingSupplierController extends Controller
public function update(Request $request, $id)
{
$booking = BookingSupplier::find($id);
$booking->payment_method = $request->input('payment_method');
$booking->payment_amount = $request->input('payment_amount');
$booking->rate = $request->input('rate');
$booking->rebate = $request->input('rebate');
$bookingsupplier = BookingSupplier::find($id);
$bookingsupplier->payment_method = $request->input('payment_method');
$bookingsupplier->payment_amount = $request->input('payment_amount');
$bookingsupplier->rate = $request->input('rate');
$bookingsupplier->rebate = $request->input('rebate');
// calculation
$amountInRMB = $amount * $rate;
$billing = 0.015 * $amount;
@@ -101,10 +133,10 @@ class BookingSupplierController extends Controller
$rmbBankAmount = $customerBankInAmount + $rebate;
// save amount in rmb
$booking->amountInRMB = $amountInRMB;
$bookingsupplier->amountInRMB = $amountInRMB;
// save rmb bank amount
$booking->rmbBankAmount = $rmbBankAmount;
$booking->save();
$bookingsupplier->rmbBankAmount = $rmbBankAmount;
$bookingsupplier->save();
return response()->json(['book_id'=>$book_id],201);
}
@@ -116,8 +148,8 @@ class BookingSupplierController extends Controller
public function supplierbookingreport(Request $request, $id)
{
$booking = Booking::where("admin_id", Auth::user()->id)->where('id', $id)->first();
if (!$booking)
$bookingsupplier = BookingSupplier::where("admin_id", Auth::user()->id)->where('id', $id)->first();
if (!$bookingsupplier)
{
return response()->json(['message'=>'Access denied'], 200);
}