From f17bfea25051db481a45d5c9a2939db5315898dc Mon Sep 17 00:00:00 2001 From: edmondlang Date: Thu, 5 May 2022 21:05:45 +0800 Subject: [PATCH 1/2] fix generate invoice api and database seeder for segment constant --- .../CreateShippingInvoiceTransactionLogic.php | 78 ++++---- .../seeders/SegmentConstantsTableSeeder.php | 170 ++++++++---------- .../elements/PackingListComponent.vue | 2 +- 3 files changed, 109 insertions(+), 141 deletions(-) diff --git a/app/Classes/Modules/Transactions/ControllersLogic/CreateShippingInvoiceTransactionLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/CreateShippingInvoiceTransactionLogic.php index a66e4137..1db3cbd8 100644 --- a/app/Classes/Modules/Transactions/ControllersLogic/CreateShippingInvoiceTransactionLogic.php +++ b/app/Classes/Modules/Transactions/ControllersLogic/CreateShippingInvoiceTransactionLogic.php @@ -21,10 +21,12 @@ use App\Classes\ValueObjects\Constants\PaymentMethodType; use App\Classes\ValueObjects\Constants\ApprovalStatus; use App\Classes\ValueObjects\Constants\DocumentType; use App\Classes\ValueObjects\Constants\PackageType; +use App\Classes\ValueObjects\Constants\SegmentConstants; use App\Classes\ValueObjects\Constants\TransactionDetailType; use App\Models\Document; use App\Models\Transaction; +use Carbon\Carbon; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Illuminate\Support\Facades\Storage; @@ -98,57 +100,35 @@ class CreateShippingInvoiceTransactionLogic extends AbstractControllerLogic return ($package->width / 100) * ($package->height / 100) *($package->length / 100) * ($package->quantity); }); - $order = $packing_list->owner()->first(); + $order = $packing_list->owner; $address = $order->addresses()->first(); - $base_price_constant = $this->fetchesSegmentConstant->execute(['id' => 1]); - $warehouse_rate_constant = $this->fetchesSegmentConstant->execute(['id' => 2]); - $state_rate_constant = $this->fetchesSegmentConstant->execute(['id' => 3]); - $center_postcode_constant = $this->fetchesSegmentConstant->execute(['id' => 4]); - $outstation_postcode_constant = $this->fetchesSegmentConstant->execute(['id' => 5]); + $base_price_constant = $this->fetchesSegmentConstant->execute(['segment_id' => 1, 'reference' => SegmentConstants::BASE_PRICE]); + $warehouse_rate_constant = $this->fetchesSegmentConstant->execute(['segment_id' => 1, 'reference' => SegmentConstants::WAREHOUSE_RATE]); + $state_rate_constant = $this->fetchesSegmentConstant->execute(['segment_id' => 1, 'reference' => SegmentConstants::STATE_RATE]); + $center_postcode_constant = $this->fetchesSegmentConstant->execute(['segment_id' => 1, 'reference' => SegmentConstants::CENTER_POSTCODE]); + $outstation_postcode_constant = $this->fetchesSegmentConstant->execute(['segment_id' => 1, 'reference' => SegmentConstants::OUTSTATION_POSTCODE]); $base_price = 0; $warehouse_rate = 0; $state_rate = 0; - $state_select = []; - $with_out = false; + $state_select = ''; - if ($base_price_constant) { - $base_price = $base_price_constant->value->price; - } + $base_price = $this->getConstantByKey($base_price_constant, date('Y-m-d')); + dd($base_price); - if ($warehouse_rate_constant) { - $package_warehouse = $order->OrderRoles()->where('role_id', '=', OrderRoleTypes::ORIGIN_WAREHOUSE)->first()->appointee->reference; - foreach ($warehouse_rate_constant->value->config as $key_warehouse => $row_warehouse) { - if ($row_warehouse->warehouse_name == $package_warehouse) { - $warehouse_rate = $row_warehouse->rate; - } - } - } + $warehouseId = $order->orderRoles()->where('role_id', OrderRoleTypes::ORIGIN_WAREHOUSE)->first()->company_module_id; + $warehouse_rate = $this->getConstantByKey($warehouse_rate_constant, $warehouseId)->amount; - if ($state_rate_constant) { - foreach ($state_rate_constant->value->config as $key_state => $row_state) { - if ($row_state->status_id == $address->state_id) { - $state_select = $row_state; - } - } - } + $stateId = $address->state_id; + $state_rate_constant = $this->getConstantByKey($state_rate_constant, $stateId); - if ($outstation_postcode_constant) { - foreach ($outstation_postcode_constant->value as $key_out => $row_out) { - - if($row_out == $address->postcode) { - $with_out = true; - } - } - } - - if (!empty($state_select)) { - $state_rate = $state_select->rate; - if ($with_out) { - $state_rate = $state_select->rate + $state_select->outstation_rate; - } - } + // get $state_rate + $postcode = $address->postcode; + $this->checkPostcodeExistInConstant($center_postcode_constant, $postcode) === true ? $state_select = 'center' : '' ; + $this->checkPostcodeExistInConstant($outstation_postcode_constant, $postcode) === true ? $state_select = 'outstation' : '' ; + $state_rate_constant = (array)$state_rate_constant; + $state_rate = $state_rate_constant[$state_select]; $price_cbm = $base_price + $warehouse_rate + $state_rate; $total_cbm = $price_cbm * ($cbm + $over_weight_cbm); @@ -213,4 +193,20 @@ class CreateShippingInvoiceTransactionLogic extends AbstractControllerLogic return $this->response([]); } + + function getConstantByKey($segmentConstantObject, $key) { + if ($segmentConstantObject) { + $base_rate = (array) $segmentConstantObject->value; + $base_rate = array_key_exists($key, $base_rate) === true ? $base_rate[$key] : 0; + return $base_rate; + } + } + + function checkPostcodeExistInConstant($segmentConstantObject, $postcode) { + if ($segmentConstantObject) { + $segmentConstantObject = $segmentConstantObject->value; + return in_array($postcode, $segmentConstantObject); + } + } + } diff --git a/database/seeders/SegmentConstantsTableSeeder.php b/database/seeders/SegmentConstantsTableSeeder.php index 2fc68bf0..c46fc8b6 100644 --- a/database/seeders/SegmentConstantsTableSeeder.php +++ b/database/seeders/SegmentConstantsTableSeeder.php @@ -19,8 +19,8 @@ class SegmentConstantsTableSeeder extends Seeder 'segment_id' => 1, 'reference' => SegmentConstants::BASE_PRICE, 'value' => json_encode([ - 'id'=> 1, - 'price' => 500, + '2022-05-01'=> '0.00', + '2022-05-02'=> '0.00', ]), ], [ @@ -28,21 +28,12 @@ class SegmentConstantsTableSeeder extends Seeder 'segment_id' => 1, 'reference' => SegmentConstants::WAREHOUSE_RATE, 'value' => json_encode([ - 'id'=> 1, - 'config' => [ - [ - 'warehouse_name' => WarehouseReferences::VT_GUANG_ZHOU, - 'rate' => 10 - ], - [ - 'warehouse_name' => WarehouseReferences::YD_GUANG_ZHOU, - 'rate' => 10 - ], - [ - 'warehouse_name' => WarehouseReferences::VT_YIWU, - 'rate' => 10 - ], - ] + '7' =>[ + 'amount' => '0.00', + ], + '6' =>[ + 'amount' => '0.00', + ], ]), ], [ @@ -50,88 +41,69 @@ class SegmentConstantsTableSeeder extends Seeder 'segment_id' => 1, 'reference' => SegmentConstants::STATE_RATE, 'value' => json_encode([ - 'id'=> 1, - 'config' => [ - [ - 'status_id' => 1, - 'rate' => 10, - 'outstation_rate' => 2 - ], - [ - 'status_id' => 2, - 'rate' => 10, - 'outstation_rate' => 2 - ], - [ - 'status_id' => 3, - 'rate' => 10, - 'outstation_rate' => 2 - ], - [ - 'status_id' => 4, - 'rate' => 10, - 'outstation_rate' => 2 - ], - [ - 'status_id' => 5, - 'rate' => 10, - 'outstation_rate' => 2 - ], - [ - 'status_id' => 6, - 'rate' => 10, - 'outstation_rate' => 2 - ], - [ - 'status_id' => 7, - 'rate' => 10, - 'outstation_rate' => 2 - ], - [ - 'status_id' => 8, - 'rate' => 10, - 'outstation_rate' => 2 - ], - [ - 'status_id' => 9, - 'rate' => 10, - 'outstation_rate' => 2 - ], - [ - 'status_id' => 10, - 'rate' => 10, - 'outstation_rate' => 2 - ], - [ - 'status_id' => 11, - 'rate' => 10, - 'outstation_rate' => 2 - ], - [ - 'status_id' => 12, - 'rate' => 10, - 'outstation_rate' => 2 - ], - [ - 'status_id' => 13, - 'rate' => 20, - 'outstation_rate' => 2 - ], - [ - 'status_id' => 14, - 'rate' => 20, - 'outstation_rate' => 2 - ], - [ - 'status_id' => 15, - 'rate' => 10, - 'outstation_rate' => 2 - ], - [ - 'status_id' => 16, - 'rate' => 10, - 'outstation_rate' => 2 - ] + '1' =>[ + 'center' => '10.00', + 'outstation' => '2.00' + ], + '2' =>[ + 'center' => '10.00', + 'outstation' => '2.00' + ], + '3' =>[ + 'center' => '10.00', + 'outstation' => '2.00' + ], + '4' =>[ + 'center' => '10.00', + 'outstation' => '2.00' + ], + '5' =>[ + 'center' => '10.00', + 'outstation' => '2.00' + ], + '6' =>[ + 'center' => '10.00', + 'outstation' => '2.00' + ], + '7' =>[ + 'center' => '10.00', + 'outstation' => '2.00' + ], + '8' =>[ + 'center' => '10.00', + 'outstation' => '2.00' + ], + '9' =>[ + 'center' => '10.00', + 'outstation' => '2.00' + ], + '10' =>[ + 'center' => '10.00', + 'outstation' => '2.00' + ], + '11' =>[ + 'center' => '10.00', + 'outstation' => '2.00' + ], + '12' =>[ + 'center' => '10.00', + 'outstation' => '2.00' + ], + '13' =>[ + 'center' => '10.00', + 'outstation' => '2.00' + ], + '14' =>[ + 'center' => '10.00', + 'outstation' => '2.00' + ], + '15' =>[ + 'center' => '10.00', + 'outstation' => '2.00' + ], + '16' =>[ + 'center' => '10.00', + 'outstation' => '2.00' ] ]), ], diff --git a/resources/assets/vue/components/containers/elements/PackingListComponent.vue b/resources/assets/vue/components/containers/elements/PackingListComponent.vue index c5c19608..e35bd710 100644 --- a/resources/assets/vue/components/containers/elements/PackingListComponent.vue +++ b/resources/assets/vue/components/containers/elements/PackingListComponent.vue @@ -40,7 +40,7 @@
Unclaimed
-
+
Generate Invoice
From 5e1626e6a43cda3cb2c34a926a7cb69f2c74e211 Mon Sep 17 00:00:00 2001 From: edmondlang Date: Sat, 7 May 2022 16:28:11 +0800 Subject: [PATCH 2/2] add soft delete in segemtns model --- app/Models/SegmentCompany.php | 3 +++ app/Models/SegmentConstant.php | 2 ++ 2 files changed, 5 insertions(+) diff --git a/app/Models/SegmentCompany.php b/app/Models/SegmentCompany.php index 660057fc..3f5d37d5 100644 --- a/app/Models/SegmentCompany.php +++ b/app/Models/SegmentCompany.php @@ -1,8 +1,11 @@