transports()->first(); $currentSchedule = $transport ? $transport->schedules()->where('status', '!=', ApprovalStatus::EXPIRED)->first() : null; $scheduleHistory = $transport ? $transport->schedules()->where('status', ApprovalStatus::EXPIRED)->get() : null; $status = 'Loaded'; if($currentSchedule) { if(Carbon::parse($currentSchedule->etd) >= Carbon::today()){ $status = 'Shipping'; } if(Carbon::parse($currentSchedule->eta) >= Carbon::today()){ $status = 'Arrived?'; } if($transport->drop_date){ $status = 'Pending deliveries'; if(!$container->packinglists()->whereDoesntHave('transports')->get()){ $status = 'Complete'; } } } return [ $container->reference, $container->loading_date, $currentSchedule ? $currentSchedule->etd : null, $currentSchedule ? $currentSchedule->eta : null, $scheduleHistory ? count($scheduleHistory) : 0, $transport ? $transport->drop_date : null, $status, $container->packages()->sum('quantity'), $container->packages()->sum(DB::raw('(width/100) * (height/100) * (length/100) * quantity')), ]; } /** * @return string */ public function title(): string { return 'Containers'; } }