Merge branches 'vapor/development' and 'vapor/production' of https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal into vapor/development

This commit is contained in:
edmondlang
2025-02-17 17:44:20 +08:00
2 changed files with 82 additions and 69 deletions
@@ -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());
+72 -69
View File
@@ -647,81 +647,84 @@ Route::get('/container/billing/{month}/{year}', function($month, $year){
echo '<h3>'.$container->reference.' ('.$container->loading_date->format('d-m-Y').')</h3>';
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 '<br>';
if(!$invoice) {
echo '<p style="color: red"><a href="'.route('order.show', $order->reference).'" target="_blank">'.$packingList->reference .'</a> Warning: no billing</p>';
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 '<span style="color: '.(($invoice->amount - $payments->sum('amount')) < 0.01 ? 'green' : 'red').'"><p style="color: red"><a href="'.route('order.show', $order->reference).'" target="_blank">'.$packingList->reference .'</a> | 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().')').'</span>';
echo '<br><br>';
} 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 '<br>';
if(!$invoice) {
echo '<p style="color: red"><a href="'.route('order.show', $order->reference).'" target="_blank">'.$packingList->reference .'</a> Warning: no billing</p>';
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 '<span style="color: '.(($invoice->amount - $payments->sum('amount')) < 0.01 ? 'green' : 'red').'"><p style="color: red"><a href="'.route('order.show', $order->reference).'" target="_blank">'.$packingList->reference .'</a> | 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().')').'</span>';
echo '<br><br>';
}
echo '<h4>Container Invoices: '.$containerBilled.'/'.$containerTotalBillable.'</h4>';