diff --git a/routes/web.php b/routes/web.php index 3679b98e..5daa2957 100644 --- a/routes/web.php +++ b/routes/web.php @@ -256,29 +256,20 @@ Route::get('/container/{reference}/refresh/', function (string $reference){ $container = Container::where('reference', $reference)->first(); $supplier = in_array($container->owner_id, [3, 4]) ? 'VT' : 'YD'; + $arrivalDates = \App\Models\PackingList::whereIn('reference', $container->packingLists->pluck('reference'))->where('type', \App\Classes\ValueObjects\Constants\PackingListType::WAREHOUSE_RECEIVE_LIST)->get()->map(function($packingList){ + return $packingList->transports()->first()->drop_date; + })->sortBy(function($date){ + return $date; + }); + + $startDate = $arrivalDates->first()->subDay()->format('d-m-Y'); + $endDate = $arrivalDates->last()->addDay()->format('d-m-Y'); + if($supplier === 'VT'){ - $arrivalDates = \App\Models\PackingList::whereIn('reference', $container->packingLists->pluck('reference'))->where('type', \App\Classes\ValueObjects\Constants\PackingListType::WAREHOUSE_RECEIVE_LIST)->get()->map(function($packingList){ - return $packingList->transports()->first()->drop_date; - })->sortBy(function($date){ - return $date; - }); - - $startDate = $arrivalDates->first()->subDay()->format('d-m-Y'); - $endDate = $arrivalDates->last()->addDay()->format('d-m-Y'); - - (App()->make(\App\Classes\Modules\PackingLists\Processors\FetchLoadedContainersFromVTPortalProcessor::class))->execute($startDate, $endDate); + return (App()->make(\App\Classes\Modules\PackingLists\Processors\FetchLoadedContainersFromVTPortalProcessor::class))->execute($startDate, $endDate); } if($supplier === 'YD'){ - $arrivalDates = \App\Models\PackingList::whereIn('reference', $container->packingLists->pluck('reference'))->where('type', \App\Classes\ValueObjects\Constants\PackingListType::WAREHOUSE_RECEIVE_LIST)->get()->map(function($packingList){ - return $packingList->transports()->first()->drop_date; - })->sortBy(function($date){ - return $date; - }); - - $startDate = $arrivalDates->first()->subDay()->format('d-m-Y'); - $endDate = $arrivalDates->last()->addDay()->format('d-m-Y'); - return redirect(route('yd.refresh').'?start_date='.$startDate.'&end_date='.$endDate); }