supplier booking

This commit is contained in:
Nazri Hamzah
2018-06-19 17:26:37 +08:00
parent 6e54771ca2
commit a5633b7754
12 changed files with 185 additions and 14 deletions
+7
View File
@@ -9,8 +9,15 @@ class Booking extends Model
// protected $guarded = [];
protected $fillable = ['term', 'amount', 'rate_id', 'user_id', 'account_name', 'account_num', 'bank_name', 'bank_branch', 'company_name', 'company_address', 'bank_address', 'swift_code', 'cnap' ,'verification_status'];
public $timestamps = true;
public function user(){
return $this->belongsTo('app\User');
}
// has one userbankslip
public function uploadbankslip()
{
return $this->hasOne('app\UserBankSlip');
}
}
+17
View File
@@ -0,0 +1,17 @@
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class BookingSupplier extends Model
{
// protected $guarded = [];
protected $fillable = ['rate','rebate','payment_amount','payment_method'];
public $timestamps = true;
public function user()
{
return $this->belongsTo('app\User');
}
}
+12 -12
View File
@@ -117,14 +117,14 @@ class BookingController extends Controller
public function uploadbankslip(Request $request, $id)
{
$user_bankslip = Booking::where("user_id", Auth::user()->id)->first();
if (!$user_bankslip)
$booking = Booking::where("user_id", Auth::user()->id)->first();
if (!$booking)
{
return response()->json(['message'=>'Access denied'], 200);
}
$validator = Validator::make($request->all(), [
'bankslip_url' => 'image|mimes:jpg,jpeg,bmp,png'
'bankslip_file' => 'image|mimes:jpg,jpeg,bmp,png'
]);
if($validator->fails())
@@ -132,19 +132,19 @@ class BookingController extends Controller
return response()->json(['message'=>'Incorrect format'],200);
}
if($file = $request->file('bankslip_url'))
if($file = $request->file('bankslip_file'))
{
$bankslip_url = $request->file('bankslip_url');
$filename = $bankslip_url->getClientOriginalName();
$bankslip_file = $request->file('bankslip_file');
$filename = $bankslip_file->getClientOriginalName();
$unique_name = 'bank_slip_' . md5($filename. time());
$file = $request->file('bankslip_url');
$file = $request->file('bankslip_file');
$ext = $file->getClientOriginalExtension();
$input['bankslip_url'] = $filename;
$input['bankslip_file'] = $filename;
Storage::putFileAs(
'bankslip_url',/*folder name*/ $file, $unique_name. '.' .$ext
'bankslip_file',/*folder name*/ $file, $unique_name. '.' .$ext
);
$user_bankslip->bankslip_url = $unique_name. '.' .$ext; //update database
$user_bankslip->bankslip_file = $unique_name. '.' .$ext; //update database
} //end if
else {
return response()->json(['message' => 'No file detected'], 400);
@@ -167,8 +167,8 @@ class BookingController extends Controller
public function uploadPurchaseOrder(Request $request, $id)
{
$user_po = Booking::where("user_id", Auth::user()->id)->first();
if (!$user_po)
$booking = Booking::where("user_id", Auth::user()->id)->first();
if (!$booking)
{
return response()->json(['message'=>'Access denied'], 200);
}
@@ -0,0 +1,132 @@
<?php
namespace App\Http\Controllers;
use App\BookingSupplier;
use App\UserBankSlip;
use Illuminate\Http\Request;
class BookingSupplierController extends Controller
{
public function index()
{
$booking = BookingSupplier::all();
$response = [
'supplier-booking' => $booking
];
return response()->json($response, 200);
}
// function show($id)
public function show($id)
{
$booking = BookingSupplier::has('supplier-booking')->findOrFail($id);
$response = [
'supplier-booking' => $booking
];
return response()->json($response, 200);
}
//single booking detail : one customer bank slip
public function viewCustomerBookingDetail (Request $request, $id )
{
// display all booking that is already uploaded user bankin slip
// TODO: admin can access only
// get current booking
$booking = Booking::where("admin_id", Auth::user()->id)->where('id', $id)->first();
if (!$booking)
{
return response()->json(['message'=>'Access denied'], 200);
}
return response()->json($booking, 200);
}
public function store(Request $request, $id)
{
//Calculation part
//single booking supplier
$amount = $request->input("payment_amount");
$rate = $request->input("rate");
$rebate = $request->input("rebate");
$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;
$user = Auth::user();
$booking = new BookingSupplier();
$supplier = SettingSupplier::find($id);
$booking->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');
$booking->user()->associate($user);
$booking->amountInRMB = $amountInRMB;
$booking->rmbBankAmount = $rmbBankAmount;
$booking->save();
return response()->json($booking, 201);
}
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');
// 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
$booking->amountInRMB = $amountInRMB;
// save rmb bank amount
$booking->rmbBankAmount = $rmbBankAmount;
$booking->save();
return response()->json(['book_id'=>$book_id],201);
}
public function destroy(BookingSupplier $id)
{
$id->delete($id);
}
public function supplierbookingreport(Request $request, $id)
{
$booking = Booking::where("admin_id", Auth::user()->id)->where('id', $id)->first();
if (!$booking)
{
return response()->json(['message'=>'Access denied'], 200);
}
}
}
+7
View File
@@ -7,4 +7,11 @@ use Illuminate\Database\Eloquent\Model;
class UserBankSlip extends Model
{
protected $fillable = ['bank_slip_type','bankslip_url','transfer_amount','book_id','cust_marking'];
// belongs to booking
public function uploadbankslip(){
return $this->belongsTo('app\Booking');
}
}
Executable → Regular
View File
Executable → Regular
View File

Before

Width:  |  Height:  |  Size: 78 KiB

After

Width:  |  Height:  |  Size: 78 KiB

Executable → Regular
View File
Executable → Regular
View File
Executable → Regular
View File
Executable → Regular
View File
+10 -2
View File
@@ -80,6 +80,14 @@ Route::put('setting-supplier/{supplier}', 'SettingSupplierController@update');
Route::delete('setting-supplier/{supplier}', 'SettingSupplierController@delete');
Route::post('upload-china-bankslip', 'ChinaBankSlipController@store');
//customer booking
Route::post('booking/{id}/upload-user-bankslip', 'BookingController@uploadbankslip');
Route::post('booking/{id}/upload-po', 'BookingController@uploadPurchaseOrder');
Route::post('booking/{id}/upload-po', 'BookingController@uploadPurchaseOrder');
//supplier booking
Route::get('supplier-booking', 'BookingSupplierController@index');
Route::get('supplier-booking/{id}', 'BookingSupplierController@show');
Route::get('supplier-booking/{id}', 'BookingSupplierController@viewCustomerBookingDetail');
Route::post('supplier-booking', 'BookingSupplierController@store');
Route::put('supplier-booking/{id}', 'BookingSupplierController@update');
Route::delete('supplier-booking/{id}', 'BookingSupplierController@destroy');