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:
@@ -13,7 +13,7 @@ use DateInterval;
|
||||
use DateTimeImmutable;
|
||||
|
||||
/**
|
||||
* Books a saved task's estimate from each assignee's days with the
|
||||
* Books a saved task's estimate from its assignee's days with the
|
||||
* TaskScheduler, using the holidays in use and the daily maximum
|
||||
* (setting `jobs.daily_capacity_hours`, 8 h by default). When the days
|
||||
* are full, the task's planned end moves later.
|
||||
@@ -41,8 +41,8 @@ final class TaskPlanner
|
||||
}
|
||||
|
||||
/**
|
||||
* Rebooks the task's assignees and, if their days were full, moves the
|
||||
* task's planned end later. The task must be saved (have an id);
|
||||
* Rebooks the task's assignee (members get no bookings) and, if their
|
||||
* days were full, moves the task's planned end later. The task must be saved (have an id);
|
||||
* save it again afterwards.
|
||||
*
|
||||
* @return bool Whether the planned end moved later.
|
||||
@@ -59,33 +59,27 @@ final class TaskPlanner
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->bookings->deleteForTask($taskId, $task->assigneeUserIds());
|
||||
$userId = $task->assigneeUserId();
|
||||
$this->bookings->deleteForTask($taskId, $userId === null ? [] : [$userId]);
|
||||
|
||||
$minutes = (int) round(($task->estimatedHours()->value ?? 0) * 60);
|
||||
$lookahead = $to->add(new DateInterval('P'.self::LOOKAHEAD_DAYS.'D'))->format('Y-m-d');
|
||||
$holidays = $this->holidays->activeDatesBetween($from->format('Y-m-d'), $lookahead);
|
||||
$capacity = $this->capacityMinutes();
|
||||
$end = $to;
|
||||
|
||||
foreach ($task->assigneeUserIds() as $userId) {
|
||||
$schedule = TaskScheduler::schedule(
|
||||
$from,
|
||||
$to,
|
||||
$minutes,
|
||||
$this->bookings->otherOpenMinutes($userId, $from->format('Y-m-d'), $lookahead, $taskId),
|
||||
$capacity,
|
||||
$holidays,
|
||||
);
|
||||
|
||||
$this->bookings->replaceFor($taskId, $userId, $schedule->minutesByDay);
|
||||
|
||||
if ($schedule->end > $end) {
|
||||
$end = $schedule->end;
|
||||
}
|
||||
if ($userId === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($end > $to) {
|
||||
$task->schedule($from, $end);
|
||||
$lookahead = $to->add(new DateInterval('P'.self::LOOKAHEAD_DAYS.'D'))->format('Y-m-d');
|
||||
$schedule = TaskScheduler::schedule(
|
||||
$from,
|
||||
$to,
|
||||
self::minutesOf($task),
|
||||
$this->bookings->otherOpenMinutes($userId, $from->format('Y-m-d'), $lookahead, $taskId),
|
||||
$this->capacityMinutes(),
|
||||
$this->holidays->activeDatesBetween($from->format('Y-m-d'), $lookahead),
|
||||
);
|
||||
|
||||
$this->bookings->replaceFor($taskId, $userId, $schedule->minutesByDay);
|
||||
|
||||
if ($schedule->end > $to) {
|
||||
$task->schedule($from, $schedule->end);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -93,14 +87,69 @@ final class TaskPlanner
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedules a saved task to end on its due date: the estimate is booked
|
||||
* from the assignee's free time on the due date and the working days
|
||||
* before it, not before the earliest day (today); what does not fit
|
||||
* goes after the due date. Without an assignee nothing is booked and the
|
||||
* task starts as many working days before as the estimate needs. Save
|
||||
* the task afterwards.
|
||||
*
|
||||
* @return bool Whether the task ends after its due date.
|
||||
*/
|
||||
public function planBackwards(Task $task, DateTimeImmutable $earliest): bool
|
||||
{
|
||||
$taskId = (int) $task->id();
|
||||
$due = $task->dueOn();
|
||||
|
||||
if ($due === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$userId = $task->assigneeUserId();
|
||||
$minutes = self::minutesOf($task);
|
||||
$start = min($due, $earliest)->sub(new DateInterval('P'.self::LOOKAHEAD_DAYS.'D'))->format('Y-m-d');
|
||||
$lookahead = max($due, $earliest)->add(new DateInterval('P'.self::LOOKAHEAD_DAYS.'D'))->format('Y-m-d');
|
||||
$holidays = $this->holidays->activeDatesBetween($start, $lookahead);
|
||||
|
||||
$this->bookings->deleteForTask($taskId);
|
||||
|
||||
if ($userId === null) {
|
||||
$task->schedule(TaskScheduler::defaultStart($due, $minutes, $this->capacityMinutes(), $holidays, $earliest), $due);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$schedule = TaskScheduler::scheduleBackwards(
|
||||
$due,
|
||||
$minutes,
|
||||
$this->bookings->otherOpenMinutes($userId, $start, $lookahead, $taskId),
|
||||
$this->capacityMinutes(),
|
||||
$holidays,
|
||||
$earliest,
|
||||
);
|
||||
|
||||
$this->bookings->replaceFor($taskId, $userId, $schedule->minutesByDay);
|
||||
|
||||
$firstDay = array_key_first($schedule->minutesByDay);
|
||||
$task->schedule($firstDay === null ? $due : new DateTimeImmutable($firstDay), $schedule->end);
|
||||
|
||||
return $schedule->extended;
|
||||
}
|
||||
|
||||
/**
|
||||
* The end of a task placed on a day without an end (TaskScheduler::defaultEnd).
|
||||
*/
|
||||
public function defaultEnd(DateTimeImmutable $from, Task $task): DateTimeImmutable
|
||||
{
|
||||
$minutes = (int) round(($task->estimatedHours()->value ?? 0) * 60);
|
||||
$minutes = self::minutesOf($task);
|
||||
$lookahead = $from->add(new DateInterval('P'.self::LOOKAHEAD_DAYS.'D'))->format('Y-m-d');
|
||||
|
||||
return TaskScheduler::defaultEnd($from, $minutes, $this->capacityMinutes(), $this->holidays->activeDatesBetween($from->format('Y-m-d'), $lookahead));
|
||||
}
|
||||
|
||||
private static function minutesOf(Task $task): int
|
||||
{
|
||||
return (int) round(($task->estimatedHours()->value ?? 0) * 60);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user