Task calendar (/jobs/calendar) replaces per-unit task Kanban columns (K34): a two-week Gantt of tasks per person. Bars move, resize and change person by dragging or through a keyboard dialog. Each task's estimate is booked evenly over working days into task_bookings, and what exceeds the daily maximum (jobs.daily_capacity_hours, 8 h) moves to the next working day. Tasks get planned_from/planned_to on the form. Holidays (/settings/holidays): Finnish public holidays calculated per year, which the admin can take out of use, plus company days off. Also includes the earlier uncommitted work: workflow templates with adding tasks from a template, and removing customers no module refers to. Co-Authored-By: Claude Opus 5.5 <[email protected]>
61 lines
1.7 KiB
PHP
61 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace Tests\Fakes;
|
|
|
|
use App\Modules\Jobs\Domain\Contracts\TaskBookingRepository;
|
|
use App\Modules\Jobs\Domain\Enums\TaskStatus;
|
|
|
|
class InMemoryTaskBookingRepository implements TaskBookingRepository
|
|
{
|
|
/** @var array<int, array<int, array<string, int>>> task id => user id => day => minutes */
|
|
public array $bookings = [];
|
|
|
|
public function __construct(private InMemoryTaskRepository $tasks) {}
|
|
|
|
public function replaceFor(int $taskId, int $userId, array $minutesByDay): void
|
|
{
|
|
$this->bookings[$taskId][$userId] = array_filter($minutesByDay, fn (int $minutes): bool => $minutes > 0);
|
|
}
|
|
|
|
public function deleteForTask(int $taskId, array $keepUserIds = []): void
|
|
{
|
|
foreach (array_keys($this->bookings[$taskId] ?? []) as $userId) {
|
|
if (! in_array($userId, $keepUserIds, true)) {
|
|
unset($this->bookings[$taskId][$userId]);
|
|
}
|
|
}
|
|
}
|
|
|
|
public function otherOpenMinutes(int $userId, string $from, string $to, int $exceptTaskId): array
|
|
{
|
|
$minutes = [];
|
|
|
|
foreach ($this->bookings as $taskId => $users) {
|
|
if ($taskId === $exceptTaskId || ($this->tasks->tasks[$taskId] ?? null)?->status() === TaskStatus::Done) {
|
|
continue;
|
|
}
|
|
|
|
foreach ($users[$userId] ?? [] as $day => $booked) {
|
|
if ($day >= $from && $day <= $to) {
|
|
$minutes[$day] = ($minutes[$day] ?? 0) + $booked;
|
|
}
|
|
}
|
|
}
|
|
|
|
ksort($minutes);
|
|
|
|
return $minutes;
|
|
}
|
|
|
|
/**
|
|
* @return array<string, int>
|
|
*/
|
|
public function of(int $taskId, int $userId): array
|
|
{
|
|
$days = $this->bookings[$taskId][$userId] ?? [];
|
|
ksort($days);
|
|
|
|
return $days;
|
|
}
|
|
}
|