From 2fccdf4f7e53d43498ec4ec0dbe97b401fa9c464 Mon Sep 17 00:00:00 2001 From: Dillon Ngo Date: Fri, 1 Nov 2024 10:05:16 +0800 Subject: [PATCH 1/3] Laravel Vapor - Enhancement to prevent customer from underpay when a transaction also invoice storage invoices --- ...heckStorageInvoiceTransactionProcessor.php | 67 +++++++++++-------- 1 file changed, 39 insertions(+), 28 deletions(-) diff --git a/app/Classes/Modules/Transactions/Processors/CheckStorageInvoiceTransactionProcessor.php b/app/Classes/Modules/Transactions/Processors/CheckStorageInvoiceTransactionProcessor.php index 80e6f0ce..93d80c14 100644 --- a/app/Classes/Modules/Transactions/Processors/CheckStorageInvoiceTransactionProcessor.php +++ b/app/Classes/Modules/Transactions/Processors/CheckStorageInvoiceTransactionProcessor.php @@ -128,28 +128,8 @@ class CheckStorageInvoiceTransactionProcessor $packingLists = $order->destinationWarehousePackages; foreach ($packingLists as $packingList){ - $arrivalDateAtChinaWarehouse = $this->getArrivalDateAtChinaWarehoue($packingList); - LogHelper::channel('storage_invoices')->info('arrivalDateAtChinaWarehouse: '.json_encode($arrivalDateAtChinaWarehouse)); - LogHelper::channel('storage_invoices')->info('destinationWarehousePackage: '.json_encode($packingList)); - $eta = $this->getEtaFromPackingList($packingList); - if($arrivalDateAtChinaWarehouse && $eta){ - $transactions = $packingList->transactions()->where('transactions.type', TransactionType::SHIPPING_INVOICE)->whereIn('transactions.status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])->get(); - // $transactions = $destinationWarehousePackage->transactions()->where('transactions.type', TransactionType::SHIPPING_INVOICE)->where('transactions.status', ApprovalStatus::APPROVED)->get(); - - /** @var Transaction $invoice_transaction */ - foreach ($transactions as $invoice_transaction){ - $result = null; - if(!$is_credit_term){ - $result = $this->processSingleTransactionOfTypeShippingInvoice($invoice_transaction, $packingList, $order->company_module_id, $eta); - } - else{ - $result = $this->isPaidOrWaivedStorageInvoiceExist($invoice_transaction, $packingList, $eta); - } - if($result){ - $results[] = $result; - } - } - } + $newResults = $this->getResults($packingList, $order, $is_credit_term); + $results = array_merge($results, $newResults); } return $results; @@ -158,13 +138,44 @@ class CheckStorageInvoiceTransactionProcessor 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); + $pL = $shippingInvoice->owner; + $order = $pL->owner; + $is_credit_term = $order->companyModule->inviters()->withPivot('is_credit_term')->first()->pivot->is_credit_term; + $packingLists = $order->destinationWarehousePackages; - if($result){ - $results[] = $result; + foreach ($packingLists as $packingList){ + if($packingList->id === $pL->id){ + $newResults = $this->getResults($packingList, $order, $is_credit_term); + $results = array_merge($results, $newResults); + } + } + + return $results; + } + + private function getResults($packingList, $order, $is_credit_term){ + $results = []; + $arrivalDateAtChinaWarehouse = $this->getArrivalDateAtChinaWarehoue($packingList); + LogHelper::channel('storage_invoices')->info('arrivalDateAtChinaWarehouse: '.json_encode($arrivalDateAtChinaWarehouse)); + LogHelper::channel('storage_invoices')->info('destinationWarehousePackage: '.json_encode($packingList)); + $eta = $this->getEtaFromPackingList($packingList); + if($arrivalDateAtChinaWarehouse && $eta){ + $transactions = $packingList->transactions()->where('transactions.type', TransactionType::SHIPPING_INVOICE)->whereIn('transactions.status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])->get(); + // $transactions = $destinationWarehousePackage->transactions()->where('transactions.type', TransactionType::SHIPPING_INVOICE)->where('transactions.status', ApprovalStatus::APPROVED)->get(); + + /** @var Transaction $invoice_transaction */ + foreach ($transactions as $invoice_transaction){ + $result = null; + if(!$is_credit_term){ + $result = $this->processSingleTransactionOfTypeShippingInvoice($invoice_transaction, $packingList, $order->company_module_id, $eta); + } + else{ + $result = $this->isPaidOrWaivedStorageInvoiceExist($invoice_transaction, $packingList, $eta); + } + if($result){ + $results[] = $result; + } + } } return $results; } From 4a6e5f71306a049744db0c21a717c1f0c8ee9fab Mon Sep 17 00:00:00 2001 From: edmondlang Date: Fri, 1 Nov 2024 17:27:55 +0800 Subject: [PATCH 2/3] fix bug create order add address extra fields --- .../ControllersLogic/CreateAddressLogic.php | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/app/Classes/Modules/Addresses/ControllersLogic/CreateAddressLogic.php b/app/Classes/Modules/Addresses/ControllersLogic/CreateAddressLogic.php index f019bab3..d0c59052 100644 --- a/app/Classes/Modules/Addresses/ControllersLogic/CreateAddressLogic.php +++ b/app/Classes/Modules/Addresses/ControllersLogic/CreateAddressLogic.php @@ -15,8 +15,10 @@ use App\Classes\Modules\Contacts\Processors\CreateContactProcessor; use App\Classes\Modules\Remarks\DataTransferObjects\RemarkObject; use App\Classes\Modules\Remarks\Processors\CreateRemarkProcessor; use App\Classes\ValueObjects\Constants\ApprovalStatus; +use App\Classes\ValueObjects\Constants\RemarkTypes; use App\Http\Resources\AddressResource; use App\Models\Address; +use Carbon\Carbon; use ErrorException; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; @@ -100,6 +102,24 @@ class CreateAddressLogic extends AbstractControllerLogic $this->createRemarkProcessor->execute($address, $remarkObject); } + if ($request->input('pickup_time_to') <= $request->input('pickup_time_from')) { + $pickupTimeFrom = Carbon::parse($request->input('pickup_time_from')); + $request->merge([ + 'pickup_time_to' => $pickupTimeFrom->addHour()->format('H:i') // Format to hh:mm + ]); + } + + $addressExtraFields = [ + 'property_type' => $request->input('property_type'), + 'receive_goods_working_hours' => $request->input('receive_goods_working_hours'), + 'receive_goods_after_hours' => $request->input('receive_goods_after_hours'), + 'receive_goods_on_saturday' => $request->input('receive_goods_on_saturday'), + ]; + + $address->addressExtraFields()->delete(); + $addressExtraFieldsObject = new RemarkObject(json_encode($addressExtraFields), Auth()->user()->id, RemarkTypes::ADDRESS_EXTRA_COLUMNS); + $remark = $this->createRemarkProcessor->execute($address, $addressExtraFieldsObject); + return $this->resourceResponse(new AddressResource($address)); } From 33a271a54cc8e58d92fe6e81a4d35bc1dce1b2b5 Mon Sep 17 00:00:00 2001 From: edmondlang Date: Mon, 4 Nov 2024 16:45:59 +0800 Subject: [PATCH 3/3] fix bug - /orders search component not working --- .../components/orders/sections/OrderSearchSectionComponent.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/assets/vue/components/orders/sections/OrderSearchSectionComponent.vue b/resources/assets/vue/components/orders/sections/OrderSearchSectionComponent.vue index f5a57205..cacd12dd 100644 --- a/resources/assets/vue/components/orders/sections/OrderSearchSectionComponent.vue +++ b/resources/assets/vue/components/orders/sections/OrderSearchSectionComponent.vue @@ -37,7 +37,7 @@ methods: { search() { this.$store.dispatch('toggleSection', {name: 'searchOrderSection', status: true}); - this.$store.dispatch('updateListQueue', {name: 'searchOrderListSection', filters: {reference_like:query, with_packing_lists: true}}); + this.$store.dispatch('updateListQueue', {name: 'searchOrderListSection', filters: {reference_like:this.query, with_packing_lists: true}}); } } }