mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange.git
synced 2026-08-19 04:14:04 +00:00
add logic, test
This commit is contained in:
@@ -15,6 +15,13 @@ class BookingController extends Controller
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
//logic if booking is not belongs to user, prohibit them from accessing the api
|
||||
$user = User::where("id", Auth::user()->id)->first();
|
||||
if (!$user)
|
||||
{
|
||||
return response()->json(['message'=>'Access denied'],401);
|
||||
}
|
||||
|
||||
$rates = Rate::all()->last();
|
||||
$term = $request->input('term');
|
||||
$rate = 1;
|
||||
@@ -49,23 +56,31 @@ class BookingController extends Controller
|
||||
}
|
||||
|
||||
//Calculation part
|
||||
//$bookings = Booking::all();
|
||||
$amount = $request->input("amount");
|
||||
if ($amount >= 10000 && ($term == 'x2_cash' || $term = 'x2_cheque' || $term = 'x2_ba')) {
|
||||
|
||||
//logic : if amount higher than 10,000, no service charge. if amount lower than 10,000, 20.00 service charge
|
||||
if ($amount >= 10000 && ($term == 'x2_cash' || $term = 'x2_cheque' || $term = 'x2_ba')) {
|
||||
$svcharge = 0;
|
||||
}
|
||||
else {
|
||||
$svcharge = 20.00;
|
||||
}
|
||||
|
||||
$gst = 0*($amount + $svcharge);
|
||||
//initial calculation
|
||||
$RMBinMYR = (($amount + $svcharge) / $rate);
|
||||
|
||||
//calculate gst, 0% after 1june 2018
|
||||
$gst = 0*$RMBinMYR;
|
||||
|
||||
$bia = round(($amount + $svcharge) / $rate + $gst,2);
|
||||
//gst = 0.00% -> (0*($amount + $svcharge))
|
||||
//bia = bank in amount in MYR
|
||||
//calculate Sales Tax, 10% of initial calculation
|
||||
$sales_tax = 0.10*$RMBinMYR;
|
||||
|
||||
//calculate billing, 1.5% of initial calculation
|
||||
$billing = 0.015*$RMBinMYR;
|
||||
|
||||
//bia = bank in amount in MYR
|
||||
$bia = round($RMBinMYR + $gst + $sales_tax + $billing,2);
|
||||
|
||||
// return $bia;
|
||||
$user = Auth::user();
|
||||
$booking = new Booking();
|
||||
$booking->account_name = $request->input('account_name');
|
||||
@@ -97,12 +112,9 @@ class BookingController extends Controller
|
||||
$booking->verification_status = $request->input('verification_status');
|
||||
|
||||
$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);
|
||||
|
||||
|
||||
@@ -136,7 +148,8 @@ class BookingController extends Controller
|
||||
$post->book_id = $booking->id;
|
||||
$post->transfer_amount = $request->input('transfer_amount');
|
||||
$post->bankslip_url = $fileNameToStore;
|
||||
$post->save();;
|
||||
$post->save();
|
||||
return response()->json(['message'=>'Success'],201);
|
||||
|
||||
|
||||
}
|
||||
@@ -167,13 +180,13 @@ class BookingController extends Controller
|
||||
$post->amount = $request->input('amount');
|
||||
$post->image_url = $fileNameToStore;
|
||||
$post->save();
|
||||
return response()->json(['message'=>'Success'],201);
|
||||
}
|
||||
|
||||
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');
|
||||
|
||||
@@ -19,7 +19,6 @@ class CreateUserBankSlipsTable extends Migration
|
||||
$table->string('bankslip_url')->nullable();
|
||||
$table->double('transfer_amount')->nullable();
|
||||
$table->string('cust_marking')->nullable();
|
||||
$table->boolean('is_approve')->nullable();
|
||||
|
||||
$table->integer('book_id')->unsigned();
|
||||
$table->foreign('book_id')->references('id')->on('bookings');
|
||||
|
||||
@@ -14,7 +14,7 @@ class UpdateUploadBookingBankslip extends Migration
|
||||
public function up()
|
||||
{
|
||||
Schema::table('user_bank_slips', function (Blueprint $table) {
|
||||
$table->boolean('is_approve')->default('false');
|
||||
$table->boolean('is_approve')->default('0');
|
||||
});
|
||||
}
|
||||
/**
|
||||
|
||||
@@ -20,6 +20,9 @@
|
||||
<filter>
|
||||
<whitelist processUncoveredFilesFromWhitelist="true">
|
||||
<directory suffix=".php">./app</directory>
|
||||
<exclude>
|
||||
<file>./app/Http/routes.php</file>
|
||||
</exclude>
|
||||
</whitelist>
|
||||
</filter>
|
||||
<php>
|
||||
@@ -31,5 +34,6 @@
|
||||
<env name="MAIL_DRIVER" value="array"/>
|
||||
<env name="DB_CONNECTION" value="sqlite"/>
|
||||
<env name="DB_DATABASE" value=":memory:"/>
|
||||
<ini name="display_errors" value="true"/>
|
||||
</php>
|
||||
</phpunit>
|
||||
|
||||
+66
-16
@@ -38,28 +38,78 @@ class BookingTest extends TestCase
|
||||
'swift_code' => '123wert',
|
||||
'cnap' => '2131rew',
|
||||
'term' => 'x2_cash',
|
||||
'amount' => '14000'
|
||||
'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(200);
|
||||
$response->assertStatus(201);
|
||||
}
|
||||
|
||||
public function testImageUpload()
|
||||
{
|
||||
Storage::fake('bankslip_url');
|
||||
|
||||
$response = $this->json('POST', '/api/upload-bs', [
|
||||
public function testuploadbankslip()
|
||||
{
|
||||
Storage::fake('bankslip_url');
|
||||
|
||||
$response = $this->json('POST', '/api/booking/1/upload-user-bankslip', [
|
||||
'bankslip_url' => UploadedFile::fake()->image('comp.jpg'),
|
||||
'bank_slip_type' => '',
|
||||
'transfer_amount' => '1000',
|
||||
'book_id' => '1',
|
||||
'cust_marking' => '12345',
|
||||
'is_approve' => '1',
|
||||
'transfer_amount' => '12345'
|
||||
]);
|
||||
dd($response->getContent());
|
||||
$response->assertStatus(201);
|
||||
}
|
||||
|
||||
]);
|
||||
//var_dump($response);
|
||||
dd($response->getContent());
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
public function testuploadPO()
|
||||
{
|
||||
Storage::fake('image_url');
|
||||
|
||||
$response = $this->json('POST', '/api/booking/1/upload-po', [
|
||||
'image_url' => UploadedFile::fake()->image('comp.jpg'),
|
||||
'amount' => '12345'
|
||||
]);
|
||||
dd($response->getContent());
|
||||
$response->assertStatus(201);
|
||||
}
|
||||
|
||||
|
||||
// function upload_bankslip_test()
|
||||
// {
|
||||
// Storage::fake('public');
|
||||
//
|
||||
// $this->json('post', '/api/booking/1/upload-user-bankslip', [
|
||||
// 'bankslip_url' => $file = UploadedFile::fake()->image('random.jpg'),
|
||||
// 'transfer_amount' => '12345',
|
||||
// ]);
|
||||
//
|
||||
// $this->assertEquals('file/' . $file->hashName(), Upload::latest()->first()->file);
|
||||
//
|
||||
// Storage::disk('public')->assertExists('file/' . $file->hashName());
|
||||
//
|
||||
// }
|
||||
//
|
||||
// function upload_po_test()
|
||||
// {
|
||||
// Storage::fake('public');
|
||||
//
|
||||
// $this->json('post', '/api/booking/1/upload-po', [
|
||||
// 'image_url' => $file = UploadedFile::fake()->image('random.jpg'),
|
||||
// 'amount' => '12345',
|
||||
// ]);
|
||||
//
|
||||
// $this->assertEquals('file/' . $file->hashName(), Upload::latest()->first()->file);
|
||||
//
|
||||
// Storage::disk('public')->assertExists('file/' . $file->hashName());
|
||||
//
|
||||
// }
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user