Fill the task calendar's working days in order instead of evenly

A task's estimate now takes each working day of its planned period up to
the assignee's free capacity before the next day gets anything, so 9 h
is booked as 7.5 h + 1.5 h rather than 4.5 h + 4.5 h. What does not fit
in the period still moves past its end and makes the task end later.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
2026-11-25 12:10:43 +02:00
co-authored by Claude Sonnet 5.5
parent ede7043765
commit eb9346d31c
6 changed files with 23 additions and 45 deletions
@@ -55,7 +55,7 @@ it('moves a task to another person by dropping it and books their days', functio
expect($task->refresh()->planned_from?->format('Y-m-d'))->toBe('2026-12-28')
->and($task->planned_to?->format('Y-m-d'))->toBe('2026-12-29')
->and($task->assignee_user_id)->toBe($this->other->id)
->and(DB::table('task_bookings')->where('task_id', $task->id)->orderBy('day')->pluck('minutes', 'day')->all())->toBe(['2026-12-28' => 360, '2026-12-29' => 360]);
->and(DB::table('task_bookings')->where('task_id', $task->id)->orderBy('day')->pluck('minutes', 'day')->all())->toBe(['2026-12-28' => 450, '2026-12-29' => 270]);
});
it('continues a task on the next working day when the day is full', function () {
@@ -156,11 +156,11 @@ it('does not remove a task with time entries', function () {
->and(JobStatus::OnHold->locksTime())->toBeFalse();
});
it('books a scheduled task evenly from the working days of its period', function () {
it('books a scheduled task by filling the working days of its period in order', function () {
$taskId = $this->addTask->execute($this->jobId, new TaskData('Taitto', 11, 'waiting', estimatedHours: '12', assigneeUserId: 10, plannedFrom: '2026-12-04', plannedTo: '2026-12-07'), 10);
$oneDayId = $this->addTask->execute($this->jobId, new TaskData('Palaveri', 91, 'waiting', assigneeUserId: 10, plannedFrom: '2026-12-08'), 10);
expect($this->bookings->of($taskId, 10))->toBe(['2026-12-04' => 360, '2026-12-07' => 360])
expect($this->bookings->of($taskId, 10))->toBe(['2026-12-04' => 480, '2026-12-07' => 240])
->and($this->tasks->findForJob($this->jobId, $oneDayId)?->plannedTo()?->format('Y-m-d'))->toBe('2026-12-08')
->and($this->bookings->of($oneDayId, 10))->toBe([]);
});
@@ -7,11 +7,11 @@ function scheduleDay(string $date): DateTimeImmutable
return new DateTimeImmutable($date);
}
it('splits the estimate evenly over the working days of the period', function () {
it('fills the working days of the period in order', function () {
// Fri 4.12.2026 – Tue 8.12.2026; the weekend in between gets nothing.
$schedule = TaskScheduler::schedule(scheduleDay('2026-12-04'), scheduleDay('2026-12-08'), 600, [], 480, []);
expect($schedule->minutesByDay)->toBe(['2026-12-04' => 210, '2026-12-07' => 195, '2026-12-08' => 195])
expect($schedule->minutesByDay)->toBe(['2026-12-04' => 480, '2026-12-07' => 120])
->and($schedule->end->format('Y-m-d'))->toBe('2026-12-08')
->and($schedule->extended)->toBeFalse();
});
@@ -21,7 +21,7 @@ it('skips holidays and uses weekend days when the period has nothing else', func
$weekend = TaskScheduler::schedule(scheduleDay('2026-12-05'), scheduleDay('2026-12-06'), 300, [], 480, []);
expect($overHolidays->minutesByDay)->toBe(['2026-12-28' => 240])
->and($weekend->minutesByDay)->toBe(['2026-12-05' => 150, '2026-12-06' => 150]);
->and($weekend->minutesByDay)->toBe(['2026-12-05' => 300]);
});
it('moves what does not fit to the next working days and ends later', function () {