mirror of
https://gitlab.com/omair-personal/exchange.git
synced 2026-08-21 21:44:26 +00:00
fix conflit
This commit is contained in:
@@ -31,8 +31,7 @@ class BookingController extends Controller
|
||||
// set timeout
|
||||
$date1 = new DateTime($booking->created_at);
|
||||
$date2 = new DateTime();
|
||||
$time_in_seconds = SettingCredit::orderby('updated_at','desc')->first()->time_limit;
|
||||
$difference_in_seconds = ($date1->format('U') + $time_in_seconds) - ($date2->format('U'));
|
||||
$difference_in_seconds = ($date1->format('U') + 600) - ($date2->format('U'));
|
||||
$booking->timeout = $difference_in_seconds;
|
||||
|
||||
// TODO : you can make it better
|
||||
@@ -94,7 +93,7 @@ class BookingController extends Controller
|
||||
// TODO : transfer_amount change name to bia
|
||||
$booking->transfer_amount = $booking->bia;
|
||||
|
||||
$booking->track_status = "(". $booking->admin_status ."/6)";
|
||||
$booking->track_status = "(". $booking->admin_status ."/7)";
|
||||
switch ($booking->admin_status) {
|
||||
case 0:
|
||||
$status_desc = "Waiting user to upload bankin slip";
|
||||
@@ -112,10 +111,13 @@ class BookingController extends Controller
|
||||
$status_desc = "Please update supplier booking status.";
|
||||
break;
|
||||
case 5:
|
||||
$status_desc = "Customer has uploaded the invoice, please upload purchase order";
|
||||
$status_desc = "Upload China Bankslip";
|
||||
break;
|
||||
case 6:
|
||||
$status_desc = "Booking completed";
|
||||
$status_desc = "Customer has uploaded the invoice, please upload purchase order";
|
||||
break;
|
||||
case 7:
|
||||
$status_desc = "Booking Completed";
|
||||
break;
|
||||
default:
|
||||
$status_desc = "";
|
||||
@@ -148,7 +150,8 @@ class BookingController extends Controller
|
||||
public function adminShow($id)
|
||||
{
|
||||
$booking = Booking::where('id', $id)->first();
|
||||
return $booking->userBankSlip()->get();
|
||||
$user_bankslip_path = $booking->userBankSlip()->first()->bankslip_path;
|
||||
$booking->user_bankslip_path = Storage::url($user_bankslip_path);
|
||||
|
||||
if($booking){
|
||||
$date1 = new DateTime($booking->created_at);
|
||||
@@ -166,10 +169,15 @@ class BookingController extends Controller
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$rates = Rate::orderby('updated_at','desc')->first();
|
||||
$term = $request->input('term');
|
||||
$amount = $request->input("amount"); // in RMB
|
||||
$creditLimit = SettingCredit::orderby('updated_at','desc')->first();
|
||||
$rates = Rate::orderby('updated_at','desc')->first();
|
||||
$creditLimit = SettingCredit::orderby('updated_at','desc')->first();
|
||||
|
||||
if (!$creditLimit){
|
||||
return response()->json("Credit limit not set, please contact admin", 405);
|
||||
}
|
||||
|
||||
if($amount > $creditLimit->rmb_credit_limit){
|
||||
return response()->json("Exceed credit limit, need approved from admin", 401);
|
||||
}
|
||||
@@ -315,29 +323,33 @@ class BookingController extends Controller
|
||||
return response()->json(['message'=>'Image too large, upload files up to 3 MB'], 400);
|
||||
}
|
||||
|
||||
if(!$bankslip_file = $request->file('file'))
|
||||
if($bankslip_file = $request->file('file'))
|
||||
{
|
||||
/* End Validation */
|
||||
$filename = $bankslip_file->getClientOriginalName();
|
||||
$ext = $bankslip_file->getClientOriginalExtension();
|
||||
|
||||
|
||||
$unique_name = 'bank_slip_' . md5($filename. time()); // probably not a good idea
|
||||
$unique_image_path = $unique_name. '.' .$ext;
|
||||
|
||||
$upload_path = Storage::disk('public')->putFileAs(
|
||||
'user_bankslip', $bankslip_file, $unique_image_path
|
||||
);
|
||||
|
||||
$user_bankslip = new UserBankSlip;
|
||||
$user_bankslip->booking_id = $booking->id;
|
||||
$user_bankslip->bankslip_path = $upload_path;
|
||||
$user_bankslip->transfer_amount = $request->input('transfer_amount');
|
||||
$user_bankslip->save();
|
||||
|
||||
|
||||
return response()->json(['message'=>"Success"],200);
|
||||
}
|
||||
else {
|
||||
return response()->json(['message' => 'No file detected'], 400);
|
||||
}
|
||||
/* End Validation */
|
||||
$filename = $bankslip_file->getClientOriginalName();
|
||||
$ext = $bankslip_file->getClientOriginalExtension();
|
||||
$input['file'] = $filename;
|
||||
|
||||
$unique_name = 'bank_slip_' . md5($filename. time()); // probably not a good idea
|
||||
$unique_image_path = $unique_name. '.' .$ext;
|
||||
Storage::putFileAs(
|
||||
'user_bankslip', $bankslip_file, $unique_image_path
|
||||
);
|
||||
|
||||
$user_bankslip = new UserBankSlip;
|
||||
$user_bankslip->booking_id = $booking->id;
|
||||
$user_bankslip->bankslip_path = $unique_image_path;
|
||||
$user_bankslip->transfer_amount = $request->input('transfer_amount');
|
||||
$user_bankslip->save();
|
||||
|
||||
|
||||
return response()->json(['message'=>"Success"],200);
|
||||
|
||||
}
|
||||
|
||||
public function updateBankSlipAmount(Request $request, $id){
|
||||
@@ -346,7 +358,13 @@ class BookingController extends Controller
|
||||
|
||||
if(!$user_bankslip){
|
||||
return response()->json(["message"=> "not found"],400);
|
||||
}
|
||||
}
|
||||
|
||||
// update booking status
|
||||
$booking->status = 3;
|
||||
$booking->admin_status = 2;
|
||||
$booking->save();
|
||||
|
||||
$user_bankslip->transfer_amount = $request->input('transfer_amount');
|
||||
$user_bankslip->save();
|
||||
return response()->json(["message"=> "Success"],200);
|
||||
@@ -392,12 +410,12 @@ class BookingController extends Controller
|
||||
$input['file'] = $filename;
|
||||
$unique_name = 'purchase_order_' . md5($filename. time());
|
||||
$unique_image_path = $unique_name. '.' .$ext;
|
||||
Storage::putFileAs(
|
||||
'purchase_order',/*folder name*/ $user_input_file, $unique_image_path
|
||||
$upload_path = Storage::disk('public')->putFileAs(
|
||||
'purchase_order',/*folder name*/ $user_input_file, $unique_image_path, 'public'
|
||||
);
|
||||
|
||||
$user_po = new PurchaseOrder;
|
||||
$user_po->image_path = $unique_image_path;
|
||||
$user_po->image_path = $upload_path;
|
||||
$user_po->book_id = $booking->id;
|
||||
$user_po->save();
|
||||
|
||||
@@ -406,11 +424,18 @@ class BookingController extends Controller
|
||||
|
||||
public function confirmPurchaseOrder($id){
|
||||
$booking = Booking::where('user_id',Auth::user()->id)->where('id',$id)->first();
|
||||
$booking->status = 5;
|
||||
$booking->status = 6;
|
||||
$booking->save();
|
||||
return response()->json(['message'=>'Success'],200);
|
||||
}
|
||||
|
||||
public function showPurchaseOrder($id){
|
||||
$booking = Booking::where('id',$id)->first();
|
||||
$user_po = $booking->purchaseOrder()->first();
|
||||
|
||||
return response()->json(['po_path'=> $user_po],200);
|
||||
}
|
||||
|
||||
public function delete(Booking $book_id)
|
||||
{
|
||||
$booking = Booking::where('user_id', Auth::user())->where('id', $book_id)->firstOrFail();
|
||||
@@ -496,14 +521,16 @@ class BookingController extends Controller
|
||||
|
||||
public function approveBankSlip(Request $request, $book_id)
|
||||
{
|
||||
if (!$booking = Booking::where('user_id',Auth::user()->id)->where('id',$book_id)->first())
|
||||
$booking = Booking::where('id',$book_id)->first();
|
||||
|
||||
if (!$booking)
|
||||
{
|
||||
return response()->json(['message'=>'Access denied'], 200);
|
||||
return response()->json(['message'=>'Booking not found'], 400);
|
||||
}
|
||||
|
||||
if(!$userBankSlip = UserBankSlip::where('booking_id',$booking->id)->first())
|
||||
{
|
||||
return response()->json(['message'=>'Access denied'], 200);
|
||||
return response()->json(['message'=>'User bankslip not found'], 400);
|
||||
}
|
||||
|
||||
// Rejected bankslip cannot be approve again
|
||||
@@ -515,12 +542,19 @@ class BookingController extends Controller
|
||||
$userBankSlip->is_approve = 1;
|
||||
$userBankSlip->estimated_arrival_time = $request->input('estimated_arrival_time');
|
||||
$userBankSlip->save();
|
||||
|
||||
// update booking status
|
||||
$booking->status = 4;
|
||||
$booking->admin_status = 3;
|
||||
$booking->save();
|
||||
|
||||
return response()->json(['message'=>'Success'],200);
|
||||
}
|
||||
|
||||
public function rejectBankSlip(Request $request, $book_id)
|
||||
{
|
||||
if (!$booking = Booking::where('user_id',Auth::user()->id)->where('id',$book_id)->first())
|
||||
$booking = Booking::where('id',$book_id)->first();
|
||||
if (!$booking)
|
||||
{
|
||||
return response()->json(['message'=>'Access denied'], 200);
|
||||
}
|
||||
@@ -540,6 +574,12 @@ class BookingController extends Controller
|
||||
$userBankSlip->reject_reason = $request->reject_reason;
|
||||
$userBankSlip->save();
|
||||
|
||||
// TODO : reject user bankinslip
|
||||
// update booking status
|
||||
$booking->status = 0;
|
||||
$booking->admin_status = 0;
|
||||
$booking->save();
|
||||
|
||||
return response()->json(['message'=>'Success'],200);
|
||||
}
|
||||
//upload
|
||||
@@ -583,12 +623,12 @@ class BookingController extends Controller
|
||||
$input['invoice_path'] = $filename;
|
||||
$unique_name = 'invoice' . md5($filename. time());
|
||||
$unique_file_url = $unique_name. '.' .$ext;
|
||||
Storage::putFileAs(
|
||||
'invoice',/*folder name*/ $input_file, $unique_file_url
|
||||
$upload_path = Storage::disk('public')->putFileAs(
|
||||
'invoice',/*folder name*/ $input_file, $unique_file_url, 'public'
|
||||
);
|
||||
|
||||
$invoice = new Invoice;
|
||||
$invoice->invoice_path = $unique_file_url;
|
||||
$invoice->invoice_path = $upload_path;
|
||||
$invoice->amount = $request->input('amount');
|
||||
$invoice->booking_id = $booking->id;
|
||||
$invoice->save();
|
||||
|
||||
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Auth;
|
||||
use App\SupplierBooking;
|
||||
use App\Booking;
|
||||
use App\Rate;
|
||||
use App\User;
|
||||
use App\UserBankSlip;
|
||||
use App\SettingBeneficiary;
|
||||
use App\SupplierBookingItem;
|
||||
use App\SettingSupplier;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class BookingSupplierController extends Controller
|
||||
{
|
||||
|
||||
public function index()
|
||||
{
|
||||
$bookingsupplier = SupplierBooking::all();
|
||||
|
||||
$response = [
|
||||
'supplier-booking' => $bookingsupplier
|
||||
];
|
||||
|
||||
return response()->json($response, 200);
|
||||
}
|
||||
|
||||
public function show($id)
|
||||
{
|
||||
$bookingsupplier = SupplierBooking::has('supplier-booking')->findOrFail($id);
|
||||
|
||||
$response = [
|
||||
'supplier-booking' => $bookingsupplier
|
||||
];
|
||||
|
||||
return response()->json($response, 200);
|
||||
}
|
||||
|
||||
// Only for single booking
|
||||
// TODO : Multiple booking
|
||||
public function store(Request $request)
|
||||
{
|
||||
|
||||
$transfer_amount = $request->input("transfer_amount");
|
||||
$supplier_id = $request->input("supplier_id");
|
||||
$booking_id = $request->input("booking_id");
|
||||
$rate = $request->input('rate');
|
||||
$rebate = $request->input('rebate');
|
||||
|
||||
if ($supplierbooking = SupplierBooking::where('book_id', $booking_id)->first()){
|
||||
return response()->json(['success'=>false, 'message'=>'Bad request, please contact support'], 400);
|
||||
}
|
||||
|
||||
|
||||
// Calculation
|
||||
$amountInRMB = $transfer_amount * $rate;
|
||||
$billing = 0.015 * $transfer_amount;
|
||||
$sales_tax = 0.10 * $transfer_amount;
|
||||
$gst = 0 * $transfer_amount; // do we still need this ?
|
||||
$customerBankInAmount = round($transfer_amount + $gst + $sales_tax + $billing,2);
|
||||
$rmbBankAmount = $customerBankInAmount + $rebate;
|
||||
|
||||
$user = Auth::user();
|
||||
$supplier = SettingSupplier::find($supplier_id);
|
||||
$booking = Booking::find($booking_id);
|
||||
|
||||
$bookingsupplier = new SupplierBooking();
|
||||
$bookingsupplier->supplier_id = $supplier->id;
|
||||
$bookingsupplier->payment_method = $request->input('payment_method');
|
||||
$bookingsupplier->transfer_amount = $transfer_amount;
|
||||
$bookingsupplier->rate = $rate;
|
||||
$bookingsupplier->rebate = $rebate;
|
||||
$bookingsupplier->amountInRMB = $amountInRMB;
|
||||
$bookingsupplier->rmbBankAmount = $rmbBankAmount;
|
||||
$bookingsupplier->book_id = $booking->id;
|
||||
$bookingsupplier->save();
|
||||
|
||||
// update booking status
|
||||
$booking->status = 5;
|
||||
$booking->admin_status = 4;
|
||||
$booking->save();
|
||||
|
||||
// TODO : generate a jpg version of report and save the path
|
||||
|
||||
return response()->json($bookingsupplier, 201);
|
||||
}
|
||||
|
||||
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
$bookingsupplier = BSupplierBooking::find($id);
|
||||
$bookingsupplier->payment_method = $request->input('payment_method');
|
||||
$bookingsupplier->transfer_amount = $request->input('transfer_amount');
|
||||
$bookingsupplier->rate = $request->input('rate');
|
||||
$bookingsupplier->rebate = $request->input('rebate');
|
||||
// calculation
|
||||
$amountInRMB = $amount * $rate;
|
||||
$billing = 0.015 * $amount;
|
||||
$sales_tax = 0.10 * $amount;
|
||||
$gst = 0 * $amount;
|
||||
$customerBankInAmount = round($amount + $gst + $sales_tax + $billing,2);
|
||||
$rmbBankAmount = $customerBankInAmount + $rebate;
|
||||
|
||||
// save amount in rmb
|
||||
$bookingsupplier->amountInRMB = $amountInRMB;
|
||||
// save rmb bank amount
|
||||
$bookingsupplier->rmbBankAmount = $rmbBankAmount;
|
||||
$bookingsupplier->save();
|
||||
|
||||
// $supplierbookingitems = $request->input("supplierbookingitem");
|
||||
// foreach ($bookings as $booking)
|
||||
// {
|
||||
// $update_supplierbookingitem = SupplierBookingItem::where('supplierbooking_id', $id)->first();
|
||||
// $update_supplierbookingitem->china_bankslip_url = $booking['china_bankslip_url'];
|
||||
// $update_supplierbookingitem->bank_in_amount = $booking['bank_in_amount'];
|
||||
// $update_supplierbookingitem->date = $booking['date'];
|
||||
// $update_supplierbookingitem->details = $booking['details'];
|
||||
// $update_supplierbookingitem->save();
|
||||
// }
|
||||
return response()->json(['book_id'=>$book_id],201);
|
||||
}
|
||||
|
||||
|
||||
public function report(Request $request, $id)
|
||||
{
|
||||
$supplier_booking = Booking::firstOrFail($id)->supplierBooking()->firstOrFail();
|
||||
|
||||
return response()->json($supplier_booking ,200);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -3,118 +3,85 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\ChinaBankSlip;
|
||||
use App\Booking;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Validator;
|
||||
|
||||
class ChinaBankSlipController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
public function store(Request $request, $id)
|
||||
{
|
||||
$booking = Booking::where('id',$id)->firstOrFail();
|
||||
|
||||
// TODO : put this after check file exist
|
||||
// validate file format
|
||||
$validator = Validator::make($request->all(), [
|
||||
'file' => 'image|mimes:jpg,jpeg,bmp,png'
|
||||
]);
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
// Handle File Upload
|
||||
if($request->hasFile('china_bank_slips')){
|
||||
// Get filename with the extension
|
||||
$filenameWithExt = $request->file('china_bank_slips')->getClientOriginalName();
|
||||
// Get just filename
|
||||
$filename = pathinfo($filenameWithExt, PATHINFO_FILENAME);
|
||||
// Get just ext
|
||||
$extension = $request->file('china_bank_slips')->getClientOriginalExtension();
|
||||
// Filename to store
|
||||
$fileNameToStore= $filename.'_'.time().'.'.$extension;
|
||||
|
||||
// File size checking
|
||||
$validator = Validator::make($request->all(), [
|
||||
'china_bank_slips' => 'max:3072'
|
||||
]);
|
||||
|
||||
if($validator->fails())
|
||||
{
|
||||
return response()->json(['message'=>'Image too large, upload files up to 3 MB'], 400);
|
||||
}
|
||||
// Upload Image
|
||||
$path = $request->file('china_bank_slips')->storeAs('public/bankslip', $fileNameToStore);
|
||||
} else {
|
||||
$fileNameToStore = 'hello.jpg';
|
||||
if($validator->fails())
|
||||
{
|
||||
return response()->json(['message'=>'Incorrect format'],200);
|
||||
}
|
||||
// Create Post
|
||||
$post = new ChinaBankSlip;
|
||||
$post->actual_transfer_amount = $request->input('actual_transfer_amount');
|
||||
$post->date = $request->input('date');
|
||||
$post->details = $request->input('details');
|
||||
$post->china_bank_slip_path = $fileNameToStore;
|
||||
$post->save();
|
||||
return response()->json(['message'=>$post], 200);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param \App\ChinaBankSlip $chinaBankSlip
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show(ChinaBankSlip $chinaBankSlip)
|
||||
{
|
||||
//
|
||||
$validator = Validator::make($request->all(), [
|
||||
'china_bank_slips' => 'max:3072'
|
||||
]);
|
||||
|
||||
if($validator->fails())
|
||||
{
|
||||
return response()->json(['message'=>'Image too large, upload files up to 3 MB'], 400);
|
||||
}
|
||||
|
||||
|
||||
if($bankslip_file = $request->file('file')){
|
||||
|
||||
$filename = $bankslip_file->getClientOriginalName();
|
||||
$ext = $bankslip_file->getClientOriginalExtension();
|
||||
$unique_name = 'cnbank_slip_' . md5($filename. time()); // probably not a good idea
|
||||
$unique_image_path = $unique_name. '.' .$ext;
|
||||
|
||||
// Upload Image
|
||||
$upload_path = Storage::disk('public')->putFileAs(
|
||||
'china_bank_slip', $bankslip_file, $unique_image_path
|
||||
);
|
||||
|
||||
|
||||
} else {
|
||||
return response()->json(['message'=>'file not found'],200);
|
||||
}
|
||||
|
||||
$china_bankslip = new ChinaBankSlip;
|
||||
$china_bankslip->booking_id = $booking->id;
|
||||
$china_bankslip->china_bank_slip_path = $upload_path;
|
||||
$china_bankslip->save();
|
||||
|
||||
return response()->json(['message'=>'success'], 201);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\ChinaBankSlip $chinaBankSlip
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit(ChinaBankSlip $chinaBankSlip)
|
||||
{
|
||||
//
|
||||
public function update(Request $request, $id){
|
||||
$booking = Booking::where('id',$id)->first();
|
||||
$china_bankslip = $booking->chinaBankSlip()->first();
|
||||
|
||||
// TODO: first or fail
|
||||
if(!$china_bankslip){
|
||||
return response()->json(["message"=> "not found"],400);
|
||||
}
|
||||
|
||||
$china_bankslip->actual_transfer_amount = $request->input('actual_transfer_amount');
|
||||
$china_bankslip->date = $request->input('date');
|
||||
$china_bankslip->details = $request->input('details');
|
||||
$china_bankslip->save();
|
||||
|
||||
// update booking status
|
||||
$booking->status = 5;
|
||||
$booking->admin_status = 6;
|
||||
$booking->save();
|
||||
|
||||
return response()->json(["message"=> "Success"],200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \App\ChinaBankSlip $chinaBankSlip
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, ChinaBankSlip $chinaBankSlip)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\ChinaBankSlip $chinaBankSlip
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy(ChinaBankSlip $chinaBankSlip)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,13 @@ class SettingSupplierController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return SettingSupplier::all();
|
||||
$suppliers = SettingSupplier::all();
|
||||
|
||||
foreach ($suppliers as $supplier) {
|
||||
$supplier->value = $supplier->id;
|
||||
$supplier->label = $supplier->company_name;
|
||||
}
|
||||
return $suppliers;
|
||||
}
|
||||
|
||||
public function show(SettingSupplier $supplier)
|
||||
|
||||
Reference in New Issue
Block a user