Replace the demo home page with a dashboard

Everyone sees their open tasks on an agenda, their open jobs, this
week's hours and quick links. Admin and management also get a lazily
loaded management panel: things to do, the month so far against the
previous month, jobs and late work, and everyone's workload.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
2026-11-25 09:20:02 +02:00
co-authored by Claude Sonnet 5.5
parent d4251d00d7
commit 487a7d34ba
46 changed files with 2032 additions and 62 deletions
@@ -0,0 +1,38 @@
<?php
declare(strict_types=1);
namespace App\Modules\Dashboard\Application\Contracts;
/**
* What the management panel needs from Billing, Sales, Users and the
* holiday calendar. Days are Y-m-d.
*/
interface DashboardAdmin
{
/**
* The billing material draft being prepared, if there is one.
*/
public function openDraftId(): ?int;
/**
* Days before the day with quick sales whose cash day is not closed.
*
* @return list<string>
*/
public function unclosedCashDaysBefore(string $day): array;
/**
* Active users who do the work, subcontractors left out, by name.
*
* @return array<int, string>
*/
public function staff(): array;
/**
* Public holidays in use and company days off between the days.
*
* @return list<string>
*/
public function holidaysBetween(string $from, string $to): array;
}
@@ -0,0 +1,24 @@
<?php
declare(strict_types=1);
namespace App\Modules\Dashboard\Application\Contracts;
use App\Modules\Dashboard\Application\DTOs\PeriodFigures;
/**
* Key figures from the Reports module.
*/
interface DashboardFigures
{
/**
* Figures of the days from the first to the last (Y-m-d).
*/
public function between(string $from, string $to): PeriodFigures;
/**
* The value (VAT 0, cents) of the hours not billed yet, worked on or
* before the day.
*/
public function unbilledValueCents(string $day): int;
}
@@ -0,0 +1,26 @@
<?php
declare(strict_types=1);
namespace App\Modules\Dashboard\Application\Contracts;
use App\Modules\Dashboard\Application\DTOs\PendingApproval;
use App\Modules\Dashboard\Application\DTOs\WeekHours;
/**
* Recorded hours, from the TimeTracking module.
*/
interface DashboardTime
{
/**
* The user's hours in the week starting on the Monday (Y-m-d).
*/
public function week(int $userId, string $monday): WeekHours;
/**
* Everyone's hours waiting for approval, by person (by name).
*
* @return list<PendingApproval>
*/
public function pendingApprovals(): array;
}
@@ -0,0 +1,52 @@
<?php
declare(strict_types=1);
namespace App\Modules\Dashboard\Application\Contracts;
use App\Modules\Dashboard\Application\DTOs\WorkJob;
use App\Modules\Dashboard\Application\DTOs\WorkTask;
/**
* Jobs, tasks and their bookings, from the Jobs module. Days are Y-m-d;
* lateness is decided by the Dashboard, so isLate is false here.
*/
interface DashboardWork
{
/**
* @return list<WorkTask>
*/
public function openTasksOf(int $userId): array;
/**
* @return list<WorkJob>
*/
public function openJobsOf(int $userId): array;
/**
* @return array<string, int> Kanban status key => jobs.
*/
public function jobCountsByStatus(): array;
public function overdueJobCount(string $today): int;
public function overdueTaskCount(string $today): int;
/**
* @return list<WorkTask>
*/
public function oldestOverdueTasks(string $today, int $limit): array;
/**
* The daily maximum a person's tasks may book, in minutes.
*/
public function dailyCapacityMinutes(): int;
/**
* Minutes the open tasks book per person in the days.
*
* @param list<int> $userIds
* @return array<int, int>
*/
public function bookedMinutes(array $userIds, string $from, string $to): array;
}
@@ -0,0 +1,46 @@
<?php
declare(strict_types=1);
namespace App\Modules\Dashboard\Application\DTOs;
/**
* The management panel of the home page on a day:
*
* - to do: hours waiting for approval by person, done jobs waiting for
* billing, the open billing draft, unclosed cash days and the value of
* unbilled hours;
* - this month so far against the same days of the previous month;
* - the jobs by status, late jobs and late tasks (the oldest of them);
* - everyone's workload this week and next (Mondays given).
*/
final readonly class ManagementOverview
{
/**
* @param list<PendingApproval> $pendingApprovals
* @param list<string> $unclosedCashDays
* @param array<string, int> $jobCounts
* @param list<WorkTask> $oldestOverdueTasks
* @param list<PersonLoad> $workloads
*/
public function __construct(
public array $pendingApprovals,
public int $doneJobCount,
public ?int $draftExportId,
public array $unclosedCashDays,
public int $unbilledValueCents,
public string $monthFrom,
public string $monthTo,
public string $previousFrom,
public string $previousTo,
public PeriodFigures $month,
public PeriodFigures $previousMonth,
public array $jobCounts,
public int $overdueJobCount,
public int $overdueTaskCount,
public array $oldestOverdueTasks,
public string $thisMonday,
public string $nextMonday,
public array $workloads,
) {}
}
@@ -0,0 +1,18 @@
<?php
declare(strict_types=1);
namespace App\Modules\Dashboard\Application\DTOs;
/**
* A person's hours waiting for approval, in quarter hours, over some weeks.
*/
final readonly class PendingApproval
{
public function __construct(
public int $userId,
public string $name,
public int $quarters,
public int $weekCount,
) {}
}
@@ -0,0 +1,22 @@
<?php
declare(strict_types=1);
namespace App\Modules\Dashboard\Application\DTOs;
/**
* Key figures of a period: hours on customers' and internal jobs (quarter
* hours), billed by the created billing materials of its months (work and
* expenses, VAT 0), the margin (null without an internal hourly cost) and
* quick sales (with VAT). Cents.
*/
final readonly class PeriodFigures
{
public function __construct(
public int $customerQuarters,
public int $internalQuarters,
public int $billedCents,
public ?int $marginCents,
public int $salesCents,
) {}
}
@@ -0,0 +1,20 @@
<?php
declare(strict_types=1);
namespace App\Modules\Dashboard\Application\DTOs;
use App\Modules\Dashboard\Domain\ValueObjects\Workload;
/**
* A person's workload this week and next week.
*/
final readonly class PersonLoad
{
public function __construct(
public int $userId,
public string $name,
public Workload $thisWeek,
public Workload $nextWeek,
) {}
}
@@ -0,0 +1,34 @@
<?php
declare(strict_types=1);
namespace App\Modules\Dashboard\Application\DTOs;
/**
* What the home page shows everyone: their open tasks on an agenda (late,
* today or tomorrow, later this week, and how many later), their first
* open jobs and how many there are, and their hours this week.
*/
final readonly class PersonalOverview
{
/**
* @param list<WorkTask> $overdue
* @param list<WorkTask> $soon
* @param list<WorkTask> $thisWeek
* @param list<WorkJob> $jobs
*/
public function __construct(
public array $overdue,
public array $soon,
public array $thisWeek,
public int $laterCount,
public array $jobs,
public int $jobCount,
public WeekHours $week,
) {}
public function hasTasks(): bool
{
return $this->overdue !== [] || $this->soon !== [] || $this->thisWeek !== [] || $this->laterCount > 0;
}
}
@@ -0,0 +1,22 @@
<?php
declare(strict_types=1);
namespace App\Modules\Dashboard\Application\DTOs;
/**
* A user's hours in a week, in quarter hours: each day (Y-m-d, Monday to
* Sunday), the total and those waiting for approval.
*/
final readonly class WeekHours
{
/**
* @param array<string, int> $days
*/
public function __construct(
public string $monday,
public array $days,
public int $totalQuarters,
public int $unapprovedQuarters,
) {}
}
@@ -0,0 +1,28 @@
<?php
declare(strict_types=1);
namespace App\Modules\Dashboard\Application\DTOs;
/**
* An open customer job on the home page. Status and priority are the Jobs
* module's keys; the due date is Y-m-d.
*/
final readonly class WorkJob
{
public function __construct(
public int $id,
public string $number,
public string $name,
public string $customerName,
public string $status,
public string $priority,
public ?string $dueOn,
public bool $isLate = false,
) {}
public function late(): self
{
return new self($this->id, $this->number, $this->name, $this->customerName, $this->status, $this->priority, $this->dueOn, true);
}
}
@@ -0,0 +1,31 @@
<?php
declare(strict_types=1);
namespace App\Modules\Dashboard\Application\DTOs;
/**
* An open task on the home page. The status is the Jobs module's task
* status key; days are Y-m-d.
*/
final readonly class WorkTask
{
public function __construct(
public int $taskId,
public int $jobId,
public string $jobNumber,
public string $jobName,
public string $title,
public string $status,
public ?string $dueOn,
public ?string $plannedFrom,
public ?string $plannedTo,
public ?string $assigneeName,
public bool $isLate = false,
) {}
public function late(): self
{
return new self($this->taskId, $this->jobId, $this->jobNumber, $this->jobName, $this->title, $this->status, $this->dueOn, $this->plannedFrom, $this->plannedTo, $this->assigneeName, true);
}
}
@@ -0,0 +1,98 @@
<?php
declare(strict_types=1);
namespace App\Modules\Dashboard\Application\UseCases;
use App\Modules\Dashboard\Application\Contracts\DashboardAdmin;
use App\Modules\Dashboard\Application\Contracts\DashboardFigures;
use App\Modules\Dashboard\Application\Contracts\DashboardTime;
use App\Modules\Dashboard\Application\Contracts\DashboardWork;
use App\Modules\Dashboard\Application\DTOs\ManagementOverview;
use App\Modules\Dashboard\Application\DTOs\PersonLoad;
use App\Modules\Dashboard\Application\DTOs\WorkTask;
use App\Modules\Dashboard\Domain\ValueObjects\Workload;
use DateTimeImmutable;
/**
* The management panel of the home page for admin and management on a day.
* The month so far is compared with the same days of the previous month
* (to its end when it is shorter).
*/
final readonly class ManagementOverviewQuery
{
public const int OVERDUE_TASK_LIMIT = 5;
public function __construct(
private DashboardWork $work,
private DashboardTime $time,
private DashboardAdmin $admin,
private DashboardFigures $figures,
) {}
public function execute(DateTimeImmutable $today): ManagementOverview
{
$day = $today->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<PersonLoad>
*/
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;
}
}
@@ -0,0 +1,55 @@
<?php
declare(strict_types=1);
namespace App\Modules\Dashboard\Application\UseCases;
use App\Modules\Dashboard\Application\Contracts\DashboardTime;
use App\Modules\Dashboard\Application\Contracts\DashboardWork;
use App\Modules\Dashboard\Application\DTOs\PersonalOverview;
use App\Modules\Dashboard\Application\DTOs\WorkJob;
use App\Modules\Dashboard\Domain\Enums\AgendaBucket;
use DateTimeImmutable;
/**
* The user's own part of the home page on a day: open tasks they are the
* assignee or a member of, their open jobs (5.6) and this week's hours.
*/
final readonly class PersonalOverviewQuery
{
public const int JOB_LIMIT = 10;
public function __construct(
private DashboardWork $work,
private DashboardTime $time,
) {}
public function execute(int $userId, DateTimeImmutable $today): PersonalOverview
{
$day = $today->format('Y-m-d');
$tomorrow = $today->modify('+1 day')->format('Y-m-d');
$monday = $today->modify('monday this week');
$sunday = $monday->modify('+6 days')->format('Y-m-d');
$buckets = ['overdue' => [], 'soon' => [], 'this_week' => [], 'later' => []];
foreach ($this->work->openTasksOf($userId) as $task) {
$bucket = AgendaBucket::of($task->dueOn, $task->plannedFrom, $day, $tomorrow, $sunday);
$buckets[$bucket->value][] = $bucket === AgendaBucket::Overdue ? $task->late() : $task;
}
$jobs = array_map(
fn (WorkJob $job): WorkJob => $job->dueOn !== null && $job->dueOn < $day ? $job->late() : $job,
$this->work->openJobsOf($userId),
);
return new PersonalOverview(
$buckets['overdue'],
$buckets['soon'],
$buckets['this_week'],
count($buckets['later']),
array_slice($jobs, 0, self::JOB_LIMIT),
count($jobs),
$this->time->week($userId, $monday->format('Y-m-d')),
);
}
}