format('Y-m-d'); $monthFrom = $today->format('Y-m-01'); $previousStart = $today->modify('first day of previous month'); $previousFrom = $previousStart->format('Y-m-d'); $previousTo = $previousStart->format('Y-m-').sprintf('%02d', min((int) $today->format('j'), (int) $previousStart->format('t'))); $jobCounts = $this->work->jobCountsByStatus(); $thisMonday = $today->modify('monday this week'); $nextMonday = $thisMonday->modify('+7 days'); return new ManagementOverview( $this->time->pendingApprovals(), $jobCounts['done'] ?? 0, $this->admin->openDraftId(), $this->admin->unclosedCashDaysBefore($day), $this->figures->unbilledValueCents($day), $monthFrom, $day, $previousFrom, $previousTo, $this->figures->between($monthFrom, $day), $this->figures->between($previousFrom, $previousTo), $jobCounts, $this->work->overdueJobCount($day), $this->work->overdueTaskCount($day), array_map(fn (WorkTask $task): WorkTask => $task->late(), $this->work->oldestOverdueTasks($day, self::OVERDUE_TASK_LIMIT)), $thisMonday->format('Y-m-d'), $nextMonday->format('Y-m-d'), $this->workloads($thisMonday, $nextMonday), ); } /** * @return list */ private function workloads(DateTimeImmutable $thisMonday, DateTimeImmutable $nextMonday): array { $staff = $this->admin->staff(); $daily = $this->work->dailyCapacityMinutes(); $weeks = []; foreach ([$thisMonday, $nextMonday] as $monday) { $from = $monday->format('Y-m-d'); $to = $monday->modify('+6 days')->format('Y-m-d'); $weeks[] = [ 'booked' => $this->work->bookedMinutes(array_keys($staff), $from, $to), 'days' => Workload::workingDays($from, $to, $this->admin->holidaysBetween($from, $to)), ]; } $result = []; foreach ($staff as $userId => $name) { $result[] = new PersonLoad( $userId, $name, Workload::of($weeks[0]['booked'][$userId] ?? 0, $daily, $weeks[0]['days']), Workload::of($weeks[1]['booked'][$userId] ?? 0, $daily, $weeks[1]['days']), ); } return $result; } }