Files
petriandClaude Sonnet 5.5 487a7d34ba 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]>
2026-11-25 09:20:02 +02:00

56 lines
1.5 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Modules\Dashboard\Domain\ValueObjects;
/**
* A person's booked work in a week against what they can do in it: the
* daily maximum on each working day (weekends, public holidays and company
* days off excluded). Minutes.
*/
final readonly class Workload
{
public function __construct(
public int $bookedMinutes,
public int $capacityMinutes,
) {}
public static function of(int $bookedMinutes, int $dailyCapacityMinutes, int $workingDays): self
{
return new self($bookedMinutes, $dailyCapacityMinutes * $workingDays);
}
/**
* Booked work as a share of the capacity, null without working days.
*/
public function ratio(): ?float
{
return $this->capacityMinutes === 0 ? null : $this->bookedMinutes / $this->capacityMinutes;
}
public function isOverloaded(): bool
{
return $this->bookedMinutes > $this->capacityMinutes;
}
/**
* Weekdays (Monday to Friday) between the days (Y-m-d, both included)
* that are not among the holidays.
*
* @param list<string> $holidays
*/
public static function workingDays(string $from, string $to, array $holidays): int
{
$days = 0;
for ($day = new \DateTimeImmutable($from); $day->format('Y-m-d') <= $to; $day = $day->modify('+1 day')) {
if ((int) $day->format('N') <= 5 && ! in_array($day->format('Y-m-d'), $holidays, true)) {
$days++;
}
}
return $days;
}
}