Give tasks one assignee and members, and schedule template tasks to due dates

- A task now has one optional assignee (tasks.assignee_user_id), whose
  calendar row it is on and whose days its estimate books, and members
  (task_members) who see it among their own jobs and in the weekly sheet
  but get no bookings. A migration moves existing assignees over: the one
  with most booked time becomes the assignee, the others members.
- Adding tasks from a workflow template asks for each step's assignee and,
  by default, schedules tasks with a due date to end on it, booking the
  estimate backwards from the due date (not before today); what does not
  fit runs past the due date and is reported as late.
- The task calendar leaves quick sale tasks out of the unscheduled list,
  shows a bar's job details in a popover on hover and focus, and shows the
  day load on its own grid line.
- The template table stacks its cells on narrow screens to reflow at 320 px.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-11-24 19:01:11 +02:00
co-authored by Claude Opus 5.5
parent b4f2f1cfaa
commit 18598cc08e
45 changed files with 1133 additions and 248 deletions
@@ -7,6 +7,8 @@ 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\DTOs\TemplateTasksResult;
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;
@@ -19,11 +21,14 @@ 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;
use App\Modules\Users\Application\Contracts\Clock;
/**
* 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
* order: waiting, with the step's work type and the due date, estimate and
* assignee entered for it (without an entry, the adder is the assignee).
* When asked, a task with a due date is scheduled to end on it, booked
* backwards from the due date (TaskPlanner::planBackwards). The tasks are
* copies, so later changes to the template do not touch them.
*/
final class AddTasksFromWorkflowTemplate
@@ -33,32 +38,39 @@ final class AddTasksFromWorkflowTemplate
private TaskRepository $tasks,
private WorkflowTemplateQueries $templates,
private TaskReferenceChecker $references,
private TaskPlanner $planner,
private Clock $clock,
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.
* @param list<TemplateTaskSchedule> $schedules In step order; a missing one leaves the task without a due date and estimate, assigned to the adder.
* @param bool $scheduleToDueDates Whether tasks with a due date are scheduled to end on it.
*
* @throws CustomerJobNotFound
* @throws InvalidEstimatedHours
* @throws TasksNotAllowedYet
* @throws WorkflowTemplateNotAvailable
* @throws InvalidTaskReference when a step's work type is not available for the job
* @throws InvalidTaskReference when a step's work type is not available for the job, or the assignee is not active
*/
public function execute(int $jobId, int $templateId, int $actorUserId, array $schedules = []): int
public function execute(int $jobId, int $templateId, int $actorUserId, array $schedules = [], bool $scheduleToDueDates = false): TemplateTasksResult
{
$dueDates = array_map(fn (TemplateTaskSchedule $schedule) => TaskInput::date($schedule->dueOn), $schedules);
$estimates = array_map(fn (TemplateTaskSchedule $schedule) => TaskInput::hours($schedule->estimatedHours), $schedules);
$assignees = array_map(fn (TemplateTaskSchedule $schedule): ?int => $schedule->assigneeUserId, $schedules);
return $this->transactions->run(function () use ($jobId, $templateId, $actorUserId, $dueDates, $estimates): int {
return $this->transactions->run(function () use ($jobId, $templateId, $actorUserId, $dueDates, $estimates, $assignees, $scheduleToDueDates): TemplateTasksResult {
$job = $this->jobs->findById($jobId) ?? throw new CustomerJobNotFound($jobId);
$template = $this->availableTemplate($templateId, $job->details()->serviceUnitIds);
$today = $this->clock->today();
$scheduled = 0;
$late = 0;
foreach ($template->steps as $index => $step) {
$this->references->check($job, $step->effectiveWorkTypeId, [$actorUserId]);
$assigneeUserId = array_key_exists($index, $assignees) ? $assignees[$index] : $actorUserId;
$this->references->check($job, $step->effectiveWorkTypeId, $assigneeUserId);
$this->tasks->save(Task::create(
$task = $this->tasks->save(Task::create(
$jobId,
$job->details()->status,
$step->effectiveWorkTypeId,
@@ -67,12 +79,19 @@ final class AddTasksFromWorkflowTemplate
TaskStatus::Waiting,
$dueDates[$index] ?? null,
$estimates[$index] ?? null,
[$actorUserId],
$assigneeUserId,
[],
$actorUserId,
));
if ($scheduleToDueDates && $task->dueOn() !== null) {
$late += $this->planner->planBackwards($task, $today) ? 1 : 0;
$scheduled++;
$this->tasks->save($task);
}
}
return count($template->steps);
return new TemplateTasksResult(count($template->steps), $scheduled, $late);
});
}