mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-19 04:24:12 +00:00
Laravel Vapor - Enhancement to prevent customer from underpay when a transaction also invoice storage invoices
This commit is contained in:
@@ -22,6 +22,7 @@ use App\Models\GroupTransaction;
|
||||
use App\Http\Resources\WalletTransactionResource;
|
||||
use App\Models\Wallet;
|
||||
use App\Classes\Modules\Transactions\Processors\ReleaseGoodsToCustomerProcessor;
|
||||
use App\Classes\Modules\Transactions\Processors\CheckStorageInvoiceTransactionProcessor;
|
||||
|
||||
|
||||
class CreateGroupsLogic extends AbstractControllerLogic
|
||||
@@ -60,6 +61,8 @@ class CreateGroupsLogic extends AbstractControllerLogic
|
||||
/** @var ReleaseGoodsToCustomerProcessor */
|
||||
private $releaseGoodsToCustomerProcessor;
|
||||
|
||||
/** @var CheckStorageInvoiceTransactionProcessor */
|
||||
private $checkStorageInvoiceTransactionProcessor;
|
||||
|
||||
public function __construct(
|
||||
FetchesTransaction $fetchesTransaction,
|
||||
@@ -68,7 +71,8 @@ class CreateGroupsLogic extends AbstractControllerLogic
|
||||
CreateWalletTopUpTransactionProcessor $createWalletTopUpTransactionProcessor,
|
||||
CreatePaymentTransactionProcessor $createPaymentTransactionProcessor,
|
||||
CreatesGroup $createsGroup,
|
||||
ReleaseGoodsToCustomerProcessor $releaseGoodsToCustomerProcessor
|
||||
ReleaseGoodsToCustomerProcessor $releaseGoodsToCustomerProcessor,
|
||||
CheckStorageInvoiceTransactionProcessor $checkStorageInvoiceTransactionProcessor
|
||||
)
|
||||
{
|
||||
$this->fetchesTransaction = $fetchesTransaction;
|
||||
@@ -78,6 +82,7 @@ class CreateGroupsLogic extends AbstractControllerLogic
|
||||
$this->createPaymentTransactionProcessor = $createPaymentTransactionProcessor;
|
||||
$this->createsGroup = $createsGroup;
|
||||
$this->releaseGoodsToCustomerProcessor = $releaseGoodsToCustomerProcessor;
|
||||
$this->checkStorageInvoiceTransactionProcessor = $checkStorageInvoiceTransactionProcessor;
|
||||
}
|
||||
|
||||
public function logic(Request $request) : JsonResponse
|
||||
@@ -87,6 +92,52 @@ class CreateGroupsLogic extends AbstractControllerLogic
|
||||
// todo-new: check why is this not working
|
||||
// $invoices = $this->fetchesTransaction->execute(['id_in' => $invoice_ids]);
|
||||
$invoices = Transaction::whereIn('id', $invoice_ids)->get();
|
||||
$typeOneInvoices = $invoices->filter(function ($invoice) {
|
||||
return $invoice->type == 1;
|
||||
});
|
||||
|
||||
// Check amount to be paid by customer 1
|
||||
$amount = $request->input('amount');
|
||||
if($typeOneInvoices)
|
||||
{
|
||||
foreach ($typeOneInvoices as $invoice) {
|
||||
$storages = $this->checkStorageInvoiceTransactionProcessor->executeShippingTransaction($invoice);
|
||||
$invoice['storages'] = $storages;
|
||||
}
|
||||
|
||||
$totalAmount = $typeOneInvoices->reduce(function ($total, $transaction) {
|
||||
$topLevelAmount = $transaction->amount ?? 0;
|
||||
$storagesAmount = collect($transaction['storages'] ?? [])->reduce(function ($sum, $storage) {
|
||||
$storageInvoiceAmount = $storage['storageInvoice']['amount'] ?? 0;
|
||||
return $sum + $storageInvoiceAmount;
|
||||
}, 0);
|
||||
return $total + $topLevelAmount + $storagesAmount;
|
||||
|
||||
}, 0);
|
||||
$diff = abs($amount - $totalAmount);
|
||||
if($diff > 0.01){
|
||||
$response = ['message' => 'Some information has been updated, please reload the page to proceed. [ref: 001]'];
|
||||
return $this->response(['data' => $response]);
|
||||
}
|
||||
}
|
||||
|
||||
// Check amount to be paid by customer 2
|
||||
$totalAmount = 0;
|
||||
$proceed = false;
|
||||
foreach ($invoices as $invoice) {
|
||||
$totalAmount += $invoice->amount;
|
||||
}
|
||||
if(abs($totalAmount - $amount ) > 0.01){
|
||||
$proceed = true;
|
||||
}
|
||||
|
||||
if($proceed){
|
||||
// $response = ['message' => 'Total: '.$totalAmount. ', submitted amount: '.$request->input('amount').', proceed: true'];
|
||||
$response = ['message' => 'Some information has been updated, please reload the page to proceed. [ref: 002]'];
|
||||
return $this->response(['data' => $response]);
|
||||
}
|
||||
|
||||
|
||||
$isInvoicesApprove = $this->checkIfInvoicesAreApprove($invoices);
|
||||
if(!$isInvoicesApprove){
|
||||
$response = ['message' => 'One of the transactions might be suspended; please check if there are any disputes in progress.'];
|
||||
@@ -95,7 +146,6 @@ class CreateGroupsLogic extends AbstractControllerLogic
|
||||
else{
|
||||
$paymentMethodStr = $request->input('payment_method');
|
||||
$paymentMethod = PaymentMethodType::PAYMENT_METHODS[$paymentMethodStr];
|
||||
$amount = $request->input('amount');
|
||||
$bankCode = $request->input('bank_code');
|
||||
$result = $this->processInvoices($invoices, $paymentMethodStr, $amount, $bankCode);
|
||||
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Classes\Modules\Transactions\ControllersLogic;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Transactions\Services\FetchesTransaction;
|
||||
use App\Classes\Modules\Transactions\Services\GeneratesTransactionBillNumber;
|
||||
use App\Classes\Modules\Companies\Services\FetchesCompanyModule;
|
||||
use App\Classes\Modules\Transactions\Processors\CreatePaymentTransactionProcessor;
|
||||
use App\Classes\Modules\Groups\Services\CreatesGroup;
|
||||
use App\Models\Transaction;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Classes\Modules\Wallets\Processors\CreateWalletTopUpTransactionProcessor;
|
||||
use App\Classes\Modules\Transactions\Processors\ReleaseGoodsToCustomerProcessor;
|
||||
use App\Classes\Modules\Transactions\Processors\CheckStorageInvoiceTransactionProcessor;
|
||||
use App\Http\Resources\TransactionVerifyResource;
|
||||
|
||||
class VerifyTransactionsLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Verify Transactions',
|
||||
'message' => 'You have successfully verified submitted transactions'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CheckStorageInvoiceTransactionProcessor */
|
||||
private $checkStorageInvoiceTransactionProcessor;
|
||||
|
||||
|
||||
public function __construct(
|
||||
CheckStorageInvoiceTransactionProcessor $checkStorageInvoiceTransactionProcessor
|
||||
)
|
||||
{
|
||||
$this->checkStorageInvoiceTransactionProcessor = $checkStorageInvoiceTransactionProcessor;
|
||||
}
|
||||
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$invoice_ids = json_decode($request->route('transaction_ids'));
|
||||
$invoices = Transaction::whereIn('id', $invoice_ids)->get();
|
||||
|
||||
$result = $this->processInvoices($invoices);
|
||||
return $this->collectionResponse(TransactionVerifyResource::collection($result));
|
||||
|
||||
}
|
||||
|
||||
private function processInvoices($invoices){
|
||||
foreach ($invoices as $invoice) {
|
||||
$storages = $this->checkStorageInvoiceTransactionProcessor->executeShippingTransaction($invoice);
|
||||
$invoice['storages'] = $storages;
|
||||
}
|
||||
return $invoices;
|
||||
}
|
||||
}
|
||||
+14
@@ -155,6 +155,20 @@ class CheckStorageInvoiceTransactionProcessor
|
||||
return $results;
|
||||
}
|
||||
|
||||
public function executeShippingTransaction(Transaction $shippingInvoice){
|
||||
LogHelper::channel('storage_invoices')->info('shippingInvoice: '.json_encode($shippingInvoice));
|
||||
$results = [];
|
||||
$packingList = $shippingInvoice->owner;
|
||||
$order = $packingList->owner;
|
||||
$eta = $this->getEtaFromPackingList($packingList);
|
||||
$result = $this->processSingleTransactionOfTypeShippingInvoice($shippingInvoice, $packingList, $order->company_module_id, $eta);
|
||||
|
||||
if($result){
|
||||
$results[] = $result;
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
|
||||
private function getArrivalDateAtChinaWarehoue($packingList){
|
||||
if($packingList->type === PackingListType::SHIPPING_PACKING_LIST){
|
||||
$receive_packing_list = PackingList::where('reference', $packingList->reference)->where('type', PackingListType::WAREHOUSE_RECEIVE_LIST)->first();
|
||||
|
||||
@@ -12,7 +12,7 @@ class CreateGroupsController
|
||||
{
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param CreatePurchaseOrderTransactionLogic $logic
|
||||
* @param CreateGroupsLogic $logic
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function create(Request $request, CreateGroupsLogic $logic) : JsonResponse {
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Http\Controllers\Transactions;
|
||||
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Classes\Modules\Transactions\ControllersLogic\VerifyTransactionsLogic;
|
||||
|
||||
|
||||
class VerifyTransactionsController
|
||||
{
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param VerifyTransactionsLogic $logic
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function verify(Request $request, VerifyTransactionsLogic $logic) : JsonResponse {
|
||||
return $logic->execute($request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class TransactionVerifyResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
// 'id' => $this->id,
|
||||
'amount' => (double) $this->amount,
|
||||
'storages' => $this->storages ? $this->storages : null,
|
||||
];
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -22,7 +22,7 @@ export default {
|
||||
}
|
||||
|
||||
successNotification ? this.$store.dispatch('createNotification', {title: response.title, message: response.message, type: 'success'}): null;
|
||||
this.successHandler(response)
|
||||
this.successHandler(response, section)
|
||||
|
||||
|
||||
});
|
||||
|
||||
@@ -15,6 +15,8 @@ Route::group(['prefix' => 'transactions', 'namespace' => 'Transactions', 'as' =>
|
||||
|
||||
Route::get('wallet/list', 'ListWalletTransactionsController@list')->name('wallet.list');
|
||||
|
||||
Route::get('/verify/{transaction_ids}', 'VerifyTransactionsController@verify')->name('verify.transactions');
|
||||
|
||||
Route::group(['prefix' => 'payment', 'as' => 'payment.'], function () {
|
||||
Route::post('/create', 'CreatePaymentTransactionController@create')->name('create');
|
||||
Route::post('/upload-verification-document/{transaction_id}', 'UploadPaymentVerificationDocumentController@upload')->name('verification.create');
|
||||
|
||||
Reference in New Issue
Block a user