mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange.git
synced 2026-08-22 13:54:17 +00:00
Merge branch 'master' of gitlab.com:CIEFWorldwideSdnBhd/exchange into fix/booking-integration
# Conflicts: # app/Http/Controllers/BookingController.php
This commit is contained in:
@@ -17,7 +17,7 @@ class BookingController extends Controller
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$rates = Rate::all()->last();
|
||||
$rates = Rate::orderby('updated_at','desc')->first();
|
||||
$term = $request->input('term');
|
||||
$rate = 1; // default
|
||||
switch ($term) {
|
||||
@@ -129,7 +129,7 @@ class BookingController extends Controller
|
||||
public function uploadbankslip(Request $request, $id)
|
||||
{
|
||||
$booking = Booking::where('user_id',Auth::user()->id)->where('id',$id)->first();
|
||||
|
||||
|
||||
/* Validation*/
|
||||
if (!$booking)
|
||||
{
|
||||
@@ -175,7 +175,7 @@ class BookingController extends Controller
|
||||
|
||||
public function uploadPurchaseOrder(Request $request, $id)
|
||||
{
|
||||
$booking = Booking::where('user_id',Auth::user()->id)->where('id',$id)->first();
|
||||
$booking = Booking::where('user_id',Auth::user()->id)->where('id',$id)->first();
|
||||
|
||||
/* Validation */
|
||||
if (!$booking)
|
||||
@@ -198,13 +198,12 @@ class BookingController extends Controller
|
||||
}
|
||||
/* End Validation */
|
||||
|
||||
|
||||
$filename = $user_input_file->getClientOriginalName();
|
||||
$ext = $user_input_file->getClientOriginalExtension();
|
||||
|
||||
$input['image_url'] = $filename;
|
||||
$unique_name = 'purchase_order_' . md5($filename. time());
|
||||
$unique_image_url = $unique_name. '.' .$ext;
|
||||
$unique_image_url = $unique_name. '.' .$ext;
|
||||
Storage::putFileAs(
|
||||
'image_url',/*folder name*/ $user_input_file, $unique_image_url
|
||||
);
|
||||
@@ -217,74 +216,86 @@ class BookingController extends Controller
|
||||
|
||||
return response()->json(['message'=>'Success'],200);
|
||||
}
|
||||
|
||||
public function delete(Booking $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 booking feature
|
||||
|
||||
public function cancel(Request $request, $book_id)
|
||||
{
|
||||
if (!$booking = Booking::where('user_id',Auth::user()->id)->where('id',$book_id)->first())
|
||||
{
|
||||
return response()->json(['message'=>'Access denied'], 200);
|
||||
}
|
||||
|
||||
$booking->is_cancel = true;
|
||||
$booking->save();
|
||||
|
||||
return response()->json(['message'=>'Success'],200);
|
||||
}
|
||||
|
||||
public function calculation(Request $request){
|
||||
$amount = $request->input('amount');
|
||||
$term = $request->input('term');
|
||||
$china_beneficiary = $request->input('china_beneficiary');
|
||||
$rates = Rate::all()->last();
|
||||
|
||||
// TODO : get marking
|
||||
$marking = "123X";
|
||||
|
||||
switch ($term) {
|
||||
case "x1_cash":
|
||||
$rate = $rates->x1_cash;
|
||||
$payment_method = "cash";
|
||||
break;
|
||||
case "x1_cheque":
|
||||
$rate = $rates->x1_cheque;
|
||||
$payment_method = "Cheque";
|
||||
break;
|
||||
case "x1_ba":
|
||||
$rate = $rates->x1_ba;
|
||||
$payment_method = "BA";
|
||||
break;
|
||||
case "x2_cash":
|
||||
$rate = $rates->x2_cash;
|
||||
$payment_method = "Cash";
|
||||
break;
|
||||
case "x2_cheque":
|
||||
$rate = $rates->x2_cheque;
|
||||
$payment_method = "Cheque";
|
||||
break;
|
||||
case "x2_ba":
|
||||
$rate = $rates->x2_ba;
|
||||
$payment_method = "BA";
|
||||
break;
|
||||
default:
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Invalid input',
|
||||
], 422);
|
||||
break;
|
||||
}
|
||||
|
||||
if ($amount >= 10000 && ($term == 'x2_cash' || $term = 'x2_cheque' || $term = 'x2_ba')) {
|
||||
$svcharge = 0;
|
||||
} else {
|
||||
$svcharge = 20.00;
|
||||
}
|
||||
|
||||
$bankin_amount = round(($amount + $svcharge) / $rate + (0 * ($amount + $svcharge)), 2);
|
||||
|
||||
return response()->json([
|
||||
'date' => date('Y-m-d'),
|
||||
'marking' => $marking,
|
||||
'amount' => $amount,
|
||||
'payment_method' => $payment_method,
|
||||
'service_charge' => $svcharge,
|
||||
'rate' => $rate,
|
||||
'bankin_amount' => $bankin_amount,
|
||||
'china_beneficary' => $china_beneficiary
|
||||
], 200);
|
||||
}
|
||||
$amount = $request->input('amount');
|
||||
$term = $request->input('term');
|
||||
$china_beneficiary = $request->input('china_beneficiary');
|
||||
$rates = Rate::all()->last();
|
||||
|
||||
// TODO : get marking
|
||||
$marking = "123X";
|
||||
|
||||
switch ($term) {
|
||||
case "x1_cash":
|
||||
$rate = $rates->x1_cash;
|
||||
$payment_method = "cash";
|
||||
break;
|
||||
case "x1_cheque":
|
||||
$rate = $rates->x1_cheque;
|
||||
$payment_method = "Cheque";
|
||||
break;
|
||||
case "x1_ba":
|
||||
$rate = $rates->x1_ba;
|
||||
$payment_method = "BA";
|
||||
break;
|
||||
case "x2_cash":
|
||||
$rate = $rates->x2_cash;
|
||||
$payment_method = "Cash";
|
||||
break;
|
||||
case "x2_cheque":
|
||||
$rate = $rates->x2_cheque;
|
||||
$payment_method = "Cheque";
|
||||
break;
|
||||
case "x2_ba":
|
||||
$rate = $rates->x2_ba;
|
||||
$payment_method = "BA";
|
||||
break;
|
||||
default:
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Invalid input',
|
||||
], 422);
|
||||
break;
|
||||
}
|
||||
|
||||
if ($amount >= 10000 && ($term == 'x2_cash' || $term = 'x2_cheque' || $term = 'x2_ba')) {
|
||||
$svcharge = 0;
|
||||
} else {
|
||||
$svcharge = 20.00;
|
||||
}
|
||||
|
||||
$bankin_amount = round(($amount + $svcharge) / $rate + (0 * ($amount + $svcharge)), 2);
|
||||
|
||||
return response()->json([
|
||||
'date' => date('Y-m-d'),
|
||||
'marking' => $marking,
|
||||
'amount' => $amount,
|
||||
'payment_method' => $payment_method,
|
||||
'service_charge' => $svcharge,
|
||||
'rate' => $rate,
|
||||
'bankin_amount' => $bankin_amount,
|
||||
'china_beneficary' => $china_beneficiary
|
||||
], 200);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
use Faker\Generator as Faker;
|
||||
|
||||
$factory->define(App\Booking::class, function (Faker $faker) {
|
||||
$rate_id = App\Rate::pluck('id')->toArray();
|
||||
$user_id = App\User::pluck('id')->toArray();
|
||||
|
||||
return [
|
||||
'account_name' => $faker->name,
|
||||
'account_num' => $faker->unique()->randomDigit,
|
||||
'bank_name' => $faker->name,
|
||||
'bank_branch' => $faker->unique()->address,
|
||||
'company_name' => $faker->name,
|
||||
'company_address' => $faker->unique()->address,
|
||||
'bank_address' => $faker->unique()->address,
|
||||
'swift_code' => $faker->unique()->randomDigit,
|
||||
'cnap' => $faker->randomDigit,
|
||||
'term' => str_random(10),
|
||||
'amount'=> $faker->randomDigit,
|
||||
|
||||
'rate_id' => $faker->randomElement($rate_id),
|
||||
'user_id' => $faker->randomElement($user_id),
|
||||
|
||||
'rmb_book_amount' => $faker->randomDigit,
|
||||
'rmb_book_pay_method' => str_random(10),
|
||||
'rmb_book_account_name' => $faker->name,
|
||||
'rmb_book_acc_no' => $faker->randomDigit,
|
||||
'rmb_book_bank_branch' => $faker->unique()->address,
|
||||
|
||||
'usd_book_amount' => $faker->randomDigit,
|
||||
'usd_book_pay_method'=> str_random(10),
|
||||
'usd_book_company_name'=> $faker->name,
|
||||
'usd_book_company_address' => $faker->unique()->address,
|
||||
'usd_book_swift_code'=> $faker->unique()->randomDigit,
|
||||
'usd_book_cnap' => $faker->randomDigit,
|
||||
'usd_book_bank_branch' => $faker->unique()->address,
|
||||
|
||||
];
|
||||
});
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AddCancelBookingTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('bookings', function (Blueprint $table) {
|
||||
$table->boolean('is_cancel')->default('0');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
if (Schema::hasColumn('bookings', 'is_cancel')) {
|
||||
Schema::table('bookings', function (Blueprint $table) {
|
||||
// $table->dropColumn('is_cancel');
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -82,5 +82,6 @@ Route::delete('setting-supplier/{supplier}', 'SettingSupplierController@delete')
|
||||
|
||||
Route::post('upload-china-bankslip', 'ChinaBankSlipController@store');
|
||||
|
||||
Route::post('booking/{book_id}/cancel', 'BookingController@cancel');
|
||||
Route::post('booking/{id}/upload-user-bankslip', 'BookingController@uploadbankslip');
|
||||
Route::post('booking/{id}/upload-po', 'BookingController@uploadPurchaseOrder');
|
||||
|
||||
@@ -18,77 +18,90 @@ use App\Booking;
|
||||
class BookingTest extends TestCase
|
||||
{
|
||||
protected $user;
|
||||
protected $booking;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
Artisan::call('db:seed');
|
||||
$this->user = factory(User::class)->create();
|
||||
$this->booking = factory(Booking::class)->create([
|
||||
'user_id' => $this->user->id
|
||||
]);
|
||||
}
|
||||
|
||||
public function testPost()
|
||||
{
|
||||
$response =
|
||||
$this->actingAs($this->user)
|
||||
->postJson('/api/booking/', [
|
||||
'account_name' => 'johnny',
|
||||
'account_num' => '1234567',
|
||||
'bank_name' => 'myabnak',
|
||||
'bank_branch' => 'banking',
|
||||
'company_name' => 'besaras',
|
||||
'company_address' => 'californina',
|
||||
'bank_address' => 'cyber',
|
||||
'swift_code' => '123wert',
|
||||
'cnap' => '2131rew',
|
||||
'term' => 'x2_cash',
|
||||
'amount' => '14000',
|
||||
'rmb_book_amount' => '2131',
|
||||
'rmb_book_pay_method' => '2131rea',
|
||||
'rmb_book_account_name' => '2131rew',
|
||||
'rmb_book_acc_no' => '2131',
|
||||
'rmb_book_bank_branch' => '2131rew',
|
||||
'usd_book_amount' => '2131',
|
||||
'usd_book_pay_method' => '2131rew',
|
||||
'usd_book_company_name' => '2131rew',
|
||||
'usd_book_company_address' => '2131rew',
|
||||
'usd_book_swift_code' => '2131rew',
|
||||
'usd_book_cnap' => '2131rew',
|
||||
'usd_book_bank_branch' => '2131rew',
|
||||
'verification_status' => '1'
|
||||
]);
|
||||
$response->assertStatus(201);
|
||||
->postJson('/api/booking/', [
|
||||
'account_name' => 'johnny',
|
||||
'account_num' => '1234567',
|
||||
'bank_name' => 'myabnak',
|
||||
'bank_branch' => 'banking',
|
||||
'company_name' => 'besaras',
|
||||
'company_address' => 'californina',
|
||||
'bank_address' => 'cyber',
|
||||
'swift_code' => '123wert',
|
||||
'cnap' => '2131rew',
|
||||
'term' => 'x2_cash',
|
||||
'amount' => '14000',
|
||||
'rmb_book_amount' => '2131',
|
||||
'rmb_book_pay_method' => '2131rea',
|
||||
'rmb_book_account_name' => '2131rew',
|
||||
'rmb_book_acc_no' => '2131',
|
||||
'rmb_book_bank_branch' => '2131rew',
|
||||
'usd_book_amount' => '2131',
|
||||
'usd_book_pay_method' => '2131rew',
|
||||
'usd_book_company_name' => '2131rew',
|
||||
'usd_book_company_address' => '2131rew',
|
||||
'usd_book_swift_code' => '2131rew',
|
||||
'usd_book_cnap' => '2131rew',
|
||||
'usd_book_bank_branch' => '2131rew',
|
||||
'verification_status' => '1'
|
||||
])
|
||||
->assertStatus(201);
|
||||
}
|
||||
|
||||
public function testuploadbankslip()
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
Storage::fake('bankslip_url');
|
||||
$bankslip_url = UploadedFile::fake()->image('comp.jpg');
|
||||
|
||||
if(!file_exists($bankslip_url)){
|
||||
$response->assertStatus(400);
|
||||
}
|
||||
|
||||
$response = $this->json('POST', '/api/booking/1/upload-user-bankslip', [
|
||||
'bankslip_url' => $bankslip_url,
|
||||
'transfer_amount' => '9000'
|
||||
]);
|
||||
$response->assertStatus(200);
|
||||
$this->actingAs($this->user)
|
||||
->json('POST', '/api/booking/' . $this->booking->id . '/upload-user-bankslip', [
|
||||
'bankslip_url' => $bankslip_url,
|
||||
'transfer_amount' => '9000'
|
||||
])
|
||||
->assertSuccessful();
|
||||
}
|
||||
|
||||
public function testuploadPO()
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
Storage::fake('image_url');
|
||||
$image_url = UploadedFile::fake()->image('comp.jpg');
|
||||
|
||||
if(!file_exists($image_url)){
|
||||
$response->assertStatus(400);
|
||||
}
|
||||
|
||||
$response = $this->json('POST', '/api/booking/1/upload-po', [
|
||||
'image_url' => UploadedFile::fake()->image('comp.jpg'),
|
||||
'amount' => '12345'
|
||||
]);
|
||||
$response->assertStatus(200);
|
||||
|
||||
$this->actingAs($this->user)
|
||||
->json('POST', '/api/booking/' . $this->booking->id . '/upload-po', [
|
||||
'image_url' => UploadedFile::fake()->image('comp.jpg'),
|
||||
'amount' => '12345'
|
||||
])
|
||||
->assertSuccessful();
|
||||
|
||||
}
|
||||
|
||||
public function testCancel()
|
||||
{
|
||||
$this->actingAs($this->user)
|
||||
->json('POST','/api/booking/' . $this->booking->id . '/cancel', [])
|
||||
->assertSuccessful();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user