From 200a9547300638377be190f222666a5f4ee7e86c Mon Sep 17 00:00:00 2001 From: omair saleh Date: Sun, 6 Mar 2022 12:21:51 +0800 Subject: [PATCH 1/2] fix active customer list --- routes/web.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/routes/web.php b/routes/web.php index 6f765b8a..497e61be 100644 --- a/routes/web.php +++ b/routes/web.php @@ -204,7 +204,7 @@ Route::get('/settings', function () { return view('pages.settings'); })->name('settings'); -Route::get('/customers/active/{active_start}/{active_end}/{inactive_start?}/{inactive_end?}', function ($active_start, $active_end, $inactive_start=null, $inactive_end=null) { +Route::get('/customers/active/{active_start}/{active_end}/{inactive_start?}/{inactive_end?}/{with_cbm?}', function ($active_start, $active_end, $inactive_start=null, $inactive_end=null, $with_cbm = false) { $activeCompanies = CompanyModule::where('type', \App\Classes\ValueObjects\Constants\BusinessType::IMPORTER)->whereHas('orderPackingLists', function($query) use($inactive_start, $inactive_end) { return $query->where('packing_lists.type', \App\Classes\ValueObjects\Constants\PackingListType::WAREHOUSE_RECEIVE_LIST)->whereHas('transports', function ($query) use ($inactive_start, $inactive_end) { return $query->where('drop_date', '>=', \Carbon\Carbon::parse($inactive_start))->where('drop_date', '<=', \Carbon\Carbon::parse($inactive_end)->addDay()); @@ -222,7 +222,20 @@ Route::get('/customers/active/{active_start}/{active_end}/{inactive_start?}/{ina $connection = $company->inviters()->withPivot('invitee_reference')->first(); $marking = $connection ? $connection->pivot->invitee_reference:''; - echo $key + 1 .'. '.$marking.'

'; + if($with_cbm){ + $totalCbm = $company->orderPackingLists()->where('packing_lists.type', \App\Classes\ValueObjects\Constants\PackingListType::SHIPPING_PACKING_LIST)->get()->map(function ($packingList) { + $replica = $packingList->packingLists()->where('type', \App\Classes\ValueObjects\Constants\PackingListType::SHIPPING_PACKING_LIST_REPLICA)->first(); + return $replica ? $replica : $packingList; + })->flatMap(function ($packingList) { + return $packingList->packages; + })->sum(function($package){ + return (( (float) $package->width / 100) * ( (float) $package->length / 100) * ( (float) $package->height / 100)) * $package->quantity; + }); + } + + $totalCbm = ($with_cbm ? '('. $totalCbm .')' : ''); + + echo $key + 1 .'. '.$marking.' '.$totalCbm.'

'; } }); \ No newline at end of file From b6834ac6f5277651049e400f730728bf08531475 Mon Sep 17 00:00:00 2001 From: omair saleh Date: Sun, 6 Mar 2022 12:33:49 +0800 Subject: [PATCH 2/2] fix active customer list --- routes/web.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/routes/web.php b/routes/web.php index 497e61be..3b2c90de 100644 --- a/routes/web.php +++ b/routes/web.php @@ -223,17 +223,15 @@ Route::get('/customers/active/{active_start}/{active_end}/{inactive_start?}/{ina $marking = $connection ? $connection->pivot->invitee_reference:''; if($with_cbm){ - $totalCbm = $company->orderPackingLists()->where('packing_lists.type', \App\Classes\ValueObjects\Constants\PackingListType::SHIPPING_PACKING_LIST)->get()->map(function ($packingList) { - $replica = $packingList->packingLists()->where('type', \App\Classes\ValueObjects\Constants\PackingListType::SHIPPING_PACKING_LIST_REPLICA)->first(); - return $replica ? $replica : $packingList; - })->flatMap(function ($packingList) { + $packingList = $company->orderPackingLists()->where('packing_lists.type', \App\Classes\ValueObjects\Constants\PackingListType::SHIPPING_PACKING_LIST)->get(); + $totalCbm = $packingList->flatMap(function ($packingList) { return $packingList->packages; })->sum(function($package){ return (( (float) $package->width / 100) * ( (float) $package->length / 100) * ( (float) $package->height / 100)) * $package->quantity; }); } - $totalCbm = ($with_cbm ? '('. $totalCbm .')' : ''); + $totalCbm = ($with_cbm ? '['. $packingList->count().'] ('. $totalCbm .')' : ''); echo $key + 1 .'. '.$marking.' '.$totalCbm.'

'; }