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:
@@ -3,6 +3,7 @@
|
||||
use App\Modules\Jobs\Application\DTOs\CustomerJobData;
|
||||
use App\Modules\Jobs\Application\DTOs\TemplateTaskSchedule;
|
||||
use App\Modules\Jobs\Application\Services\JobDetailsFactory;
|
||||
use App\Modules\Jobs\Application\Services\TaskPlanner;
|
||||
use App\Modules\Jobs\Application\Services\TaskReferenceChecker;
|
||||
use App\Modules\Jobs\Application\UseCases\AddTasksFromWorkflowTemplate;
|
||||
use App\Modules\Jobs\Application\UseCases\CreateCustomerJob;
|
||||
@@ -12,13 +13,17 @@ 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\Shared\Application\UseCases\HolidayCalendar;
|
||||
use Tests\Fakes\FakeCatalogQueries;
|
||||
use Tests\Fakes\FakeClock;
|
||||
use Tests\Fakes\FakeCustomerQueries;
|
||||
use Tests\Fakes\FakeSettings;
|
||||
use Tests\Fakes\FakeTransactionManager;
|
||||
use Tests\Fakes\FakeUserAccountQueries;
|
||||
use Tests\Fakes\FakeWorkflowTemplateQueries;
|
||||
use Tests\Fakes\InMemoryCustomerJobRepository;
|
||||
use Tests\Fakes\InMemoryHolidayOverrides;
|
||||
use Tests\Fakes\InMemoryTaskBookingRepository;
|
||||
use Tests\Fakes\InMemoryTaskRepository;
|
||||
|
||||
beforeEach(function () {
|
||||
@@ -39,6 +44,8 @@ beforeEach(function () {
|
||||
$catalog->addWorkType(21, 2, 'painotyö');
|
||||
$catalog->addWorkType(91, 9, 'suunnittelu');
|
||||
$users->addUser(10, 'Eero');
|
||||
$users->addUser(11, 'Aino');
|
||||
$users->addUser(12, 'Pois', active: false);
|
||||
|
||||
$createJob = new CreateCustomerJob($this->jobs, $this->jobs, new JobDetailsFactory($customers, $catalog, $users), $transactions, new FakeClock(new DateTimeImmutable('2026-05-01')));
|
||||
$this->jobId = $createJob->execute(new CustomerJobData('Video', 1, [1], 10, 'one_off', 'quote_request', 'normal'), 10);
|
||||
@@ -49,18 +56,20 @@ beforeEach(function () {
|
||||
$this->templates->addTemplate(3, 'Vanha', 11, 1, [['Kuvaus']], active: false);
|
||||
$this->templates->addTemplate(4, 'Rikki', 11, 1, [['Painatus', 21]]);
|
||||
|
||||
$this->addTasks = new AddTasksFromWorkflowTemplate($this->jobs, $this->tasks, $this->templates, new TaskReferenceChecker($catalog, $users), $transactions);
|
||||
$this->bookings = new InMemoryTaskBookingRepository($this->tasks);
|
||||
$planner = new TaskPlanner($this->bookings, new HolidayCalendar(new InMemoryHolidayOverrides), new FakeSettings);
|
||||
$this->addTasks = new AddTasksFromWorkflowTemplate($this->jobs, $this->tasks, $this->templates, new TaskReferenceChecker($catalog, $users), $planner, new FakeClock(new DateTimeImmutable('2026-05-01')), $transactions);
|
||||
});
|
||||
|
||||
it('adds a waiting task per step in order, with the step work type and the adder as assignee', function () {
|
||||
expect($this->addTasks->execute($this->jobId, 1, 10))->toBe(3);
|
||||
expect($this->addTasks->execute($this->jobId, 1, 10)->added)->toBe(3);
|
||||
|
||||
$tasks = array_values($this->tasks->tasks);
|
||||
|
||||
expect(array_map(fn (Task $task): array => [$task->title()->value, $task->workTypeId(), $task->status(), $task->assigneeUserIds()], $tasks))->toBe([
|
||||
['Suunnittelu', 91, TaskStatus::Waiting, [10]],
|
||||
['Kuvaus', 11, TaskStatus::Waiting, [10]],
|
||||
['Editointi', 12, TaskStatus::Waiting, [10]],
|
||||
expect(array_map(fn (Task $task): array => [$task->title()->value, $task->workTypeId(), $task->status(), $task->assigneeUserId(), $task->isScheduled()], $tasks))->toBe([
|
||||
['Suunnittelu', 91, TaskStatus::Waiting, 10, false],
|
||||
['Kuvaus', 11, TaskStatus::Waiting, 10, false],
|
||||
['Editointi', 12, TaskStatus::Waiting, 10, false],
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -94,3 +103,71 @@ it('gives each task the due date and estimate entered for its step', function ()
|
||||
it('rejects an estimate that is not a number', function () {
|
||||
$this->addTasks->execute($this->jobId, 1, 10, [new TemplateTaskSchedule(null, 'paljon')]);
|
||||
})->throws(InvalidEstimatedHours::class);
|
||||
|
||||
/**
|
||||
* @param array<int, Task> $tasks
|
||||
* @return list<array{0: ?string, 1: ?string}>
|
||||
*/
|
||||
function plannedPeriods(array $tasks): array
|
||||
{
|
||||
return array_map(fn (Task $task): array => [$task->plannedFrom()?->format('Y-m-d'), $task->plannedTo()?->format('Y-m-d')], array_values($tasks));
|
||||
}
|
||||
|
||||
it('gives each task the assignee chosen for its step', function () {
|
||||
$this->addTasks->execute($this->jobId, 1, 10, [
|
||||
new TemplateTaskSchedule(null, null, 11),
|
||||
new TemplateTaskSchedule(null, null, null),
|
||||
new TemplateTaskSchedule(null, null, 10),
|
||||
]);
|
||||
|
||||
expect(array_map(fn (Task $task): ?int => $task->assigneeUserId(), array_values($this->tasks->tasks)))->toBe([11, null, 10]);
|
||||
});
|
||||
|
||||
it('rejects an inactive assignee', function () {
|
||||
try {
|
||||
$this->addTasks->execute($this->jobId, 1, 10, [new TemplateTaskSchedule(null, null, 12)]);
|
||||
$this->fail('No exception');
|
||||
} catch (InvalidTaskReference $exception) {
|
||||
expect($exception->field)->toBe('assignee');
|
||||
}
|
||||
});
|
||||
|
||||
it('schedules tasks to end on their due dates, booking backwards from the due date past full days', function () {
|
||||
$result = $this->addTasks->execute($this->jobId, 1, 10, [
|
||||
new TemplateTaskSchedule('2026-05-12', '12', 10),
|
||||
new TemplateTaskSchedule('2026-05-12', '6', 10),
|
||||
new TemplateTaskSchedule(null, '2', 10),
|
||||
], scheduleToDueDates: true);
|
||||
|
||||
[$first, $second] = array_keys($this->tasks->tasks);
|
||||
|
||||
expect([$result->added, $result->scheduled, $result->late])->toBe([3, 2, 0])
|
||||
->and(plannedPeriods($this->tasks->tasks))->toBe([['2026-05-11', '2026-05-12'], ['2026-05-08', '2026-05-12'], [null, null]])
|
||||
->and($this->bookings->of($first, 10))->toBe(['2026-05-11' => 240, '2026-05-12' => 480])
|
||||
->and($this->bookings->of($second, 10))->toBe(['2026-05-08' => 120, '2026-05-11' => 240]);
|
||||
});
|
||||
|
||||
it('does not schedule before today and lets the rest run past the due date', function () {
|
||||
$result = $this->addTasks->execute($this->jobId, 1, 10, [new TemplateTaskSchedule('2026-05-04', '20', 10)], scheduleToDueDates: true);
|
||||
$taskId = array_key_first($this->tasks->tasks);
|
||||
|
||||
// Today, 1.5., is May Day, so only Monday 4.5. is free before the due date.
|
||||
expect([$result->scheduled, $result->late])->toBe([1, 1])
|
||||
->and(plannedPeriods([$this->tasks->tasks[$taskId]]))->toBe([['2026-05-04', '2026-05-06']])
|
||||
->and($this->bookings->of($taskId, 10))->toBe(['2026-05-04' => 480, '2026-05-05' => 480, '2026-05-06' => 240]);
|
||||
});
|
||||
|
||||
it('gives a task without an assignee the working days its estimate needs before the due date, without bookings', function () {
|
||||
$this->addTasks->execute($this->jobId, 1, 10, [new TemplateTaskSchedule('2026-05-12', '12', null)], scheduleToDueDates: true);
|
||||
$taskId = array_key_first($this->tasks->tasks);
|
||||
|
||||
expect(plannedPeriods([$this->tasks->tasks[$taskId]]))->toBe([['2026-05-11', '2026-05-12']])
|
||||
->and($this->bookings->bookings[$taskId] ?? [])->toBe([]);
|
||||
});
|
||||
|
||||
it('leaves the tasks unscheduled when scheduling to due dates is off', function () {
|
||||
$result = $this->addTasks->execute($this->jobId, 1, 10, [new TemplateTaskSchedule('2026-05-12', '12', 10)]);
|
||||
|
||||
expect($result->scheduled)->toBe(0)
|
||||
->and(plannedPeriods($this->tasks->tasks)[0])->toBe([null, null]);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user