Add the task calendar, holidays, workflow templates and customer removal

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]>
This commit is contained in:
2026-11-24 18:13:11 +02:00
co-authored by Claude Opus 5.5
parent dfe4941f02
commit b4f2f1cfaa
134 changed files with 6930 additions and 45 deletions
@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace App\Modules\Jobs\Application\UseCases;
use App\Modules\Jobs\Application\DTOs\TaskData;
use App\Modules\Jobs\Application\Services\TaskPlanner;
use App\Modules\Jobs\Application\Services\TaskReferenceChecker;
use App\Modules\Jobs\Domain\Contracts\CustomerJobRepository;
use App\Modules\Jobs\Domain\Contracts\TaskRepository;
@@ -12,6 +13,7 @@ use App\Modules\Jobs\Domain\Entities\Task;
use App\Modules\Jobs\Domain\Enums\TaskStatus;
use App\Modules\Jobs\Domain\Exceptions\CustomerJobNotFound;
use App\Modules\Jobs\Domain\Exceptions\InvalidTaskReference;
use App\Modules\Jobs\Domain\Exceptions\PlanEndsBeforeStart;
use App\Modules\Jobs\Domain\Exceptions\TasksNotAllowedYet;
use App\Modules\Jobs\Domain\ValueObjects\TaskTitle;
use App\Modules\Shared\Application\Contracts\TransactionManager;
@@ -22,6 +24,7 @@ final class AddTask
private CustomerJobRepository $jobs,
private TaskRepository $tasks,
private TaskReferenceChecker $references,
private TaskPlanner $planner,
private TransactionManager $transactions,
) {}
@@ -31,6 +34,7 @@ final class AddTask
* @throws CustomerJobNotFound
* @throws TasksNotAllowedYet
* @throws InvalidTaskReference
* @throws PlanEndsBeforeStart
*/
public function execute(int $jobId, TaskData $data, int $actorUserId): int
{
@@ -51,9 +55,17 @@ final class AddTask
TaskInput::hours($data->estimatedHours),
$data->assigneeUserIds,
$actorUserId,
TaskInput::date($data->plannedFrom),
TaskInput::date($data->plannedTo),
);
return (int) $this->tasks->save($task)->id();
$task = $this->tasks->save($task);
if ($task->isScheduled() && $this->planner->plan($task)) {
$task = $this->tasks->save($task);
}
return (int) $task->id();
});
}
}
@@ -0,0 +1,92 @@
<?php
declare(strict_types=1);
namespace App\Modules\Jobs\Application\UseCases;
use App\Modules\Catalog\Application\Contracts\WorkflowTemplateQueries;
use App\Modules\Catalog\Application\DTOs\WorkflowTemplateDetails;
use App\Modules\Jobs\Application\DTOs\TemplateTaskSchedule;
use App\Modules\Jobs\Application\Services\TaskReferenceChecker;
use App\Modules\Jobs\Domain\Contracts\CustomerJobRepository;
use App\Modules\Jobs\Domain\Contracts\TaskRepository;
use App\Modules\Jobs\Domain\Entities\Task;
use App\Modules\Jobs\Domain\Enums\TaskStatus;
use App\Modules\Jobs\Domain\Exceptions\CustomerJobNotFound;
use App\Modules\Jobs\Domain\Exceptions\InvalidEstimatedHours;
use App\Modules\Jobs\Domain\Exceptions\InvalidTaskReference;
use App\Modules\Jobs\Domain\Exceptions\TasksNotAllowedYet;
use App\Modules\Jobs\Domain\Exceptions\WorkflowTemplateNotAvailable;
use App\Modules\Jobs\Domain\ValueObjects\TaskTitle;
use App\Modules\Shared\Application\Contracts\TransactionManager;
/**
* Makes a task of every step of a workflow template, in the template's
* order: waiting, with the step's work type and the due date and estimate
* entered for it, assigned to the user who adds them. The tasks are
* copies, so later changes to the template do not touch them.
*/
final class AddTasksFromWorkflowTemplate
{
public function __construct(
private CustomerJobRepository $jobs,
private TaskRepository $tasks,
private WorkflowTemplateQueries $templates,
private TaskReferenceChecker $references,
private TransactionManager $transactions,
) {}
/**
* @param list<TemplateTaskSchedule> $schedules In step order; a missing one leaves the task without a due date and estimate.
* @return int How many tasks were added.
*
* @throws CustomerJobNotFound
* @throws InvalidEstimatedHours
* @throws TasksNotAllowedYet
* @throws WorkflowTemplateNotAvailable
* @throws InvalidTaskReference when a step's work type is not available for the job
*/
public function execute(int $jobId, int $templateId, int $actorUserId, array $schedules = []): int
{
$dueDates = array_map(fn (TemplateTaskSchedule $schedule) => TaskInput::date($schedule->dueOn), $schedules);
$estimates = array_map(fn (TemplateTaskSchedule $schedule) => TaskInput::hours($schedule->estimatedHours), $schedules);
return $this->transactions->run(function () use ($jobId, $templateId, $actorUserId, $dueDates, $estimates): int {
$job = $this->jobs->findById($jobId) ?? throw new CustomerJobNotFound($jobId);
$template = $this->availableTemplate($templateId, $job->details()->serviceUnitIds);
foreach ($template->steps as $index => $step) {
$this->references->check($job, $step->effectiveWorkTypeId, [$actorUserId]);
$this->tasks->save(Task::create(
$jobId,
$job->details()->status,
$step->effectiveWorkTypeId,
new TaskTitle($step->title),
$step->description,
TaskStatus::Waiting,
$dueDates[$index] ?? null,
$estimates[$index] ?? null,
[$actorUserId],
$actorUserId,
));
}
return count($template->steps);
});
}
/**
* @param list<int> $serviceUnitIds
*/
private function availableTemplate(int $templateId, array $serviceUnitIds): WorkflowTemplateDetails
{
foreach ($this->templates->activeFor($serviceUnitIds) as $template) {
if ($template->id === $templateId) {
return $template;
}
}
throw new WorkflowTemplateNotAvailable($templateId);
}
}
@@ -0,0 +1,35 @@
<?php
declare(strict_types=1);
namespace App\Modules\Jobs\Application\UseCases;
use App\Modules\Jobs\Application\Services\TaskPlanner;
use App\Modules\Jobs\Domain\Contracts\TaskRepository;
use App\Modules\Jobs\Domain\Exceptions\TaskNotFound;
use App\Modules\Shared\Application\Contracts\TransactionManager;
/**
* Takes a task out of the task calendar: no planned period, no bookings.
*/
final class ClearTaskSchedule
{
public function __construct(
private TaskRepository $tasks,
private TaskPlanner $planner,
private TransactionManager $transactions,
) {}
/**
* @throws TaskNotFound
*/
public function execute(int $jobId, int $taskId): void
{
$this->transactions->run(function () use ($jobId, $taskId): void {
$task = $this->tasks->findForJob($jobId, $taskId) ?? throw new TaskNotFound($jobId, $taskId);
$task->schedule(null, null);
$this->planner->plan($task);
$this->tasks->save($task);
});
}
}
@@ -0,0 +1,75 @@
<?php
declare(strict_types=1);
namespace App\Modules\Jobs\Application\UseCases;
use App\Modules\Jobs\Application\DTOs\ScheduleResult;
use App\Modules\Jobs\Application\Services\TaskPlanner;
use App\Modules\Jobs\Application\Services\TaskReferenceChecker;
use App\Modules\Jobs\Domain\Contracts\CustomerJobRepository;
use App\Modules\Jobs\Domain\Contracts\TaskRepository;
use App\Modules\Jobs\Domain\Exceptions\CustomerJobNotFound;
use App\Modules\Jobs\Domain\Exceptions\InvalidTaskReference;
use App\Modules\Jobs\Domain\Exceptions\PlanEndsBeforeStart;
use App\Modules\Jobs\Domain\Exceptions\TaskNotFound;
use App\Modules\Shared\Application\Contracts\TransactionManager;
/**
* Moves a task in the task calendar: a new planned period, and possibly
* from one person's row to another's (the person on the row it left is
* replaced as an assignee; null is the "no assignee" row). Without an
* end, the task lasts as many working days as its estimate needs.
*/
final class ScheduleTask
{
public function __construct(
private CustomerJobRepository $jobs,
private TaskRepository $tasks,
private TaskReferenceChecker $references,
private TaskPlanner $planner,
private TransactionManager $transactions,
) {}
/**
* @throws CustomerJobNotFound
* @throws TaskNotFound
* @throws InvalidTaskReference
* @throws PlanEndsBeforeStart
*/
public function execute(int $jobId, int $taskId, ?int $fromUserId, ?int $toUserId, string $plannedFrom, ?string $plannedTo): ScheduleResult
{
$from = TaskInput::date($plannedFrom) ?? throw new PlanEndsBeforeStart;
$to = TaskInput::date($plannedTo);
return $this->transactions->run(function () use ($jobId, $taskId, $fromUserId, $toUserId, $from, $to): ScheduleResult {
$job = $this->jobs->findById($jobId) ?? throw new CustomerJobNotFound($jobId);
$task = $this->tasks->findForJob($jobId, $taskId) ?? throw new TaskNotFound($jobId, $taskId);
$assignees = $task->assigneeUserIds();
if ($fromUserId !== $toUserId) {
$assignees = array_values(array_filter($assignees, fn (int $userId): bool => $userId !== $fromUserId));
if ($toUserId !== null) {
$assignees[] = $toUserId;
}
}
$this->references->check($job, $task->workTypeId(), $assignees, $task);
$task->changeAssignees($assignees);
$task->schedule($from, $to ?? $this->planner->defaultEnd($from, $task));
$task = $this->tasks->save($task);
$extended = $this->planner->plan($task);
$task = $this->tasks->save($task);
return new ScheduleResult(
(string) $task->plannedFrom()?->format('Y-m-d'),
(string) $task->plannedTo()?->format('Y-m-d'),
$extended,
);
});
}
}
@@ -5,12 +5,15 @@ declare(strict_types=1);
namespace App\Modules\Jobs\Application\UseCases;
use App\Modules\Jobs\Application\DTOs\TaskData;
use App\Modules\Jobs\Application\Services\TaskPlanner;
use App\Modules\Jobs\Application\Services\TaskReferenceChecker;
use App\Modules\Jobs\Domain\Contracts\CustomerJobRepository;
use App\Modules\Jobs\Domain\Contracts\TaskRepository;
use App\Modules\Jobs\Domain\Entities\Task;
use App\Modules\Jobs\Domain\Enums\TaskStatus;
use App\Modules\Jobs\Domain\Exceptions\CustomerJobNotFound;
use App\Modules\Jobs\Domain\Exceptions\InvalidTaskReference;
use App\Modules\Jobs\Domain\Exceptions\PlanEndsBeforeStart;
use App\Modules\Jobs\Domain\Exceptions\TaskNotFound;
use App\Modules\Jobs\Domain\ValueObjects\TaskTitle;
use App\Modules\Shared\Application\Contracts\TransactionManager;
@@ -21,6 +24,7 @@ final class UpdateTask
private CustomerJobRepository $jobs,
private TaskRepository $tasks,
private TaskReferenceChecker $references,
private TaskPlanner $planner,
private TransactionManager $transactions,
) {}
@@ -28,6 +32,7 @@ final class UpdateTask
* @throws CustomerJobNotFound
* @throws TaskNotFound
* @throws InvalidTaskReference
* @throws PlanEndsBeforeStart
*/
public function execute(int $jobId, int $taskId, TaskData $data): void
{
@@ -39,6 +44,8 @@ final class UpdateTask
$this->references->check($job, $data->workTypeId, $data->assigneeUserIds, $task);
$before = self::planningInput($task);
$task->changeDetails(
$data->workTypeId,
$title,
@@ -48,8 +55,28 @@ final class UpdateTask
TaskInput::hours($data->estimatedHours),
$data->assigneeUserIds,
);
$task->schedule(TaskInput::date($data->plannedFrom), TaskInput::date($data->plannedTo));
$this->tasks->save($task);
$task = $this->tasks->save($task);
// Rebook only when what the bookings depend on changed.
if (self::planningInput($task) !== $before) {
$this->planner->plan($task);
$this->tasks->save($task);
}
});
}
/**
* @return array{0: ?string, 1: ?string, 2: ?float, 3: list<int>}
*/
private static function planningInput(Task $task): array
{
return [
$task->plannedFrom()?->format('Y-m-d'),
$task->plannedTo()?->format('Y-m-d'),
$task->estimatedHours()?->value,
$task->assigneeUserIds(),
];
}
}