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:
@@ -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')),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user