From e3bc918bd8d753e3e9df6a427308502b2251afc2 Mon Sep 17 00:00:00 2001 From: edmondlang Date: Fri, 14 Feb 2025 00:30:53 +0800 Subject: [PATCH 1/2] add new segment - No Extra Centimeter Charged --- .../PackingLists/Processors/CreatePackageProcessor.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/Classes/Modules/PackingLists/Processors/CreatePackageProcessor.php b/app/Classes/Modules/PackingLists/Processors/CreatePackageProcessor.php index 477f7da7..06d97528 100644 --- a/app/Classes/Modules/PackingLists/Processors/CreatePackageProcessor.php +++ b/app/Classes/Modules/PackingLists/Processors/CreatePackageProcessor.php @@ -9,6 +9,8 @@ use App\Classes\Modules\PackingLists\Standards\Rules\Packages\CanCreatePackage; use App\Classes\ValueObjects\Constants\WarehouseReferences; use App\Models\Order; use App\Models\PackingList; +use App\Models\Segment; +use Illuminate\Support\Facades\Log; class CreatePackageProcessor { @@ -53,6 +55,14 @@ class CreatePackageProcessor if($replica->owner->owner instanceof Order){ $modificationValue = in_array( $replica->owner->owner->companyModule->id, WarehouseReferences::REPLICA_WHITE_LIST) ? 0 : 1; + + // if customer in segment 'No Extra Centimeter Charged' + $segmentId = Segment::where('name', 'No Extra Centimeter Charged')->first()->id; + $companySegments = $replica->owner->owner->companyModule->connections()->first()->segments->pluck('id')->toArray(); + if (in_array($segmentId, $companySegments)) { + $modificationValue = 0; + Log::info('No Extra Centimeter Charged segment working'); + } } $packageObject = new PackageObject($object->getType(), $object->getDescription(), $object->getWidth() + $modificationValue, $object->getHeight() + $modificationValue, $object->getLength() + $modificationValue, $object->getWeight(), $object->getQuantity(), $object->getStatus()); From a3b08a7c113728378022f114880d4d944da61ff6 Mon Sep 17 00:00:00 2001 From: edmondlang Date: Mon, 17 Feb 2025 17:43:52 +0800 Subject: [PATCH 2/2] fix bug error web "/container/billing/{month}/{year}" --- routes/web.php | 141 +++++++++++++++++++++++++------------------------ 1 file changed, 72 insertions(+), 69 deletions(-) diff --git a/routes/web.php b/routes/web.php index fd53346f..6cf3bfb7 100644 --- a/routes/web.php +++ b/routes/web.php @@ -646,81 +646,84 @@ Route::get('/container/billing/{month}/{year}', function($month, $year){ echo '

'.$container->reference.' ('.$container->loading_date->format('d-m-Y').')

'; foreach ($packingLists as $packingList) { - $invoice = $packingList->transactions() - ->where('type', TransactionType::SHIPPING_INVOICE)->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]) - ->first(); + try { + $invoice = $packingList->transactions() + ->where('type', TransactionType::SHIPPING_INVOICE)->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]) + ->first(); - $warehouseList = PackingList::where('reference', $packingList->reference)->where('type', 1)->first(); - if($warehouseList){ - $packing_list_drop_date = $warehouseList->transports->first()->drop_date; - } else { - echo '<------------- can\'t find arrival date -------------->'; - } - - $order = $packingList->owner; - $address = $order->addresses()->where('status', ApprovalStatus::APPROVED)->first(); - $warehouseId = $order->orderRoles()->where('role_id', OrderRoleTypes::ORIGIN_WAREHOUSE)->first()->company_module_id; - - $cbm = round($packingList->packages->where('type', '!=', PackageType::OVER_WEIGHT)->sum(function($package) { - return ($package->width / 100) * ($package->height / 100) *($package->length / 100) * ($package->quantity); - }), 2); - - $over_weight_cbm = round($packingList->packages->where('type', PackageType::OVER_WEIGHT)->sum(function($package) { - return ($package->width / 100) * ($package->height / 100) *($package->length / 100) * ($package->quantity); - }), 2); - $price = $basePrice; - - if($warehouseId === 2358){ - $price += $yiwuCost; - if($packing_list_drop_date >= Carbon::parse('19-9-2022')){ - $price += $yiwuDiscount; + $warehouseList = PackingList::where('reference', $packingList->reference)->where('type', 1)->first(); + if($warehouseList){ + $packing_list_drop_date = $warehouseList->transports->first()->drop_date; + } else { + echo '<------------- can\'t find arrival date -------------->'; } - } else { - if($cbm >= 2 && in_array($address->state_id, [4, 15])){ - $price += $bigParcelDiscount; + + $order = $packingList->owner; + $address = $order->addresses()->where('status', ApprovalStatus::APPROVED)->first(); + $warehouseId = $order->orderRoles()->where('role_id', OrderRoleTypes::ORIGIN_WAREHOUSE)->first()->company_module_id; + + $cbm = round($packingList->packages->where('type', '!=', PackageType::OVER_WEIGHT)->sum(function($package) { + return ($package->width / 100) * ($package->height / 100) *($package->length / 100) * ($package->quantity); + }), 2); + + $over_weight_cbm = round($packingList->packages->where('type', PackageType::OVER_WEIGHT)->sum(function($package) { + return ($package->width / 100) * ($package->height / 100) *($package->length / 100) * ($package->quantity); + }), 2); + $price = $basePrice; + + if($warehouseId === 2358){ + $price += $yiwuCost; + if($packing_list_drop_date >= Carbon::parse('19-9-2022')){ + $price += $yiwuDiscount; + } + } else { + if($cbm >= 2 && in_array($address->state_id, [4, 15])){ + $price += $bigParcelDiscount; + } + if($packing_list_drop_date >= Carbon::parse('19-9-2022')){ + $price += $discount; + } } - if($packing_list_drop_date >= Carbon::parse('19-9-2022')){ - $price += $discount; + + if(in_array($address->state_id,$outstationStates)) { + $price += 50; } + + $cbm = max($cbm, 0.3); + $cost = $price * ($cbm + $over_weight_cbm); + + $containerCost += $cost; + + if(in_array($address->state_id, [13, 14])) { + echo 'East Malaysia - '; + } + echo 'estimated cost: [QTY: '.($cbm + $over_weight_cbm).' | Unit Price: '.$price.' | Total: '.$cost.']'; + echo '
'; + + if(!$invoice) { + echo '

'.$packingList->reference .' Warning: no billing

'; + continue; + } + + $payments = $invoice->transactions() + ->where('type', TransactionType::PAYMENT)->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]) + ->get(); + + $billed += 1; + $containerBilled += 1; + + $totalBilled += $invoice->amount; + $containerTotalBilled += $invoice->amount; + + $totalPaid += $payments->sum('amount'); + $containerTotalPaid += $payments->sum('amount'); + + echo '

'.$packingList->reference .' | Amount: '.$invoice->amount.' | Paid: '.$payments->sum('amount').' | Invoice Date: '.$invoice->created_at->format('d-m-Y'). (($invoice->amount - $payments->sum('amount')) < 0.01 ? '' : '('.$invoice->created_at->diffForHumans().')').''; + echo '

'; + } catch (Exception $e){ + echo "<------------- Error processing packing list {$packingList->reference}: " . $e->getMessage() . " -------------->"; } - - if(in_array($address->state_id,$outstationStates)) { - $price += 50; - } - - $cbm = max($cbm, 0.3); - $cost = $price * ($cbm + $over_weight_cbm); - - $containerCost += $cost; - - if(in_array($address->state_id, [13, 14])) { - echo 'East Malaysia - '; - } - echo 'estimated cost: [QTY: '.($cbm + $over_weight_cbm).' | Unit Price: '.$price.' | Total: '.$cost.']'; - echo '
'; - - if(!$invoice) { - echo '

'.$packingList->reference .' Warning: no billing

'; - continue; - } - - $payments = $invoice->transactions() - ->where('type', TransactionType::PAYMENT)->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]) - ->get(); - - $billed += 1; - $containerBilled += 1; - - $totalBilled += $invoice->amount; - $containerTotalBilled += $invoice->amount; - - $totalPaid += $payments->sum('amount'); - $containerTotalPaid += $payments->sum('amount'); - - echo '

'.$packingList->reference .' | Amount: '.$invoice->amount.' | Paid: '.$payments->sum('amount').' | Invoice Date: '.$invoice->created_at->format('d-m-Y'). (($invoice->amount - $payments->sum('amount')) < 0.01 ? '' : '('.$invoice->created_at->diffForHumans().')').''; - echo '

'; - } echo '

Container Invoices: '.$containerBilled.'/'.$containerTotalBillable.'

';