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,14 +13,16 @@ use App\Modules\Jobs\Domain\ValueObjects\TaskTitle;
|
||||
use DateTimeImmutable;
|
||||
|
||||
/**
|
||||
* A task (tehtävä) of a customer job: one step of the work, done by its
|
||||
* assignees under one work type. Time entries are recorded on tasks.
|
||||
* Its planned schedule (planned from–to) places it in the task calendar.
|
||||
* A task (tehtävä) of a customer job: one step of the work under one work
|
||||
* type. Its assignee (tekijä) does it: the planned schedule (planned
|
||||
* from–to) places it on the assignee's row of the task calendar and books
|
||||
* the estimate from their days. Members (jäsenet) see the task among their
|
||||
* own but get no bookings. Time entries are recorded on tasks.
|
||||
*/
|
||||
final class Task
|
||||
{
|
||||
/**
|
||||
* @param list<int> $assigneeUserIds
|
||||
* @param list<int> $memberUserIds
|
||||
*/
|
||||
private function __construct(
|
||||
private ?int $id,
|
||||
@@ -31,17 +33,18 @@ final class Task
|
||||
private TaskStatus $status,
|
||||
private ?DateTimeImmutable $dueOn,
|
||||
private ?EstimatedHours $estimatedHours,
|
||||
private array $assigneeUserIds,
|
||||
private ?int $assigneeUserId,
|
||||
private array $memberUserIds,
|
||||
private int $createdBy,
|
||||
private ?DateTimeImmutable $plannedFrom = null,
|
||||
private ?DateTimeImmutable $plannedTo = null,
|
||||
) {
|
||||
$this->assigneeUserIds = self::normaliseIds($assigneeUserIds);
|
||||
$this->memberUserIds = self::members($memberUserIds, $assigneeUserId);
|
||||
self::checkPlan($plannedFrom, $plannedTo);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<int> $assigneeUserIds
|
||||
* @param list<int> $memberUserIds
|
||||
*
|
||||
* @throws TasksNotAllowedYet
|
||||
* @throws PlanEndsBeforeStart
|
||||
@@ -55,7 +58,8 @@ final class Task
|
||||
TaskStatus $status,
|
||||
?DateTimeImmutable $dueOn,
|
||||
?EstimatedHours $estimatedHours,
|
||||
array $assigneeUserIds,
|
||||
?int $assigneeUserId,
|
||||
array $memberUserIds,
|
||||
int $createdBy,
|
||||
?DateTimeImmutable $plannedFrom = null,
|
||||
?DateTimeImmutable $plannedTo = null,
|
||||
@@ -64,11 +68,11 @@ final class Task
|
||||
throw new TasksNotAllowedYet;
|
||||
}
|
||||
|
||||
return new self(null, $jobId, $workTypeId, $title, self::text($description), $status, $dueOn, $estimatedHours, $assigneeUserIds, $createdBy, ...self::plan($plannedFrom, $plannedTo));
|
||||
return new self(null, $jobId, $workTypeId, $title, self::text($description), $status, $dueOn, $estimatedHours, $assigneeUserId, $memberUserIds, $createdBy, ...self::plan($plannedFrom, $plannedTo));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<int> $assigneeUserIds
|
||||
* @param list<int> $memberUserIds
|
||||
*/
|
||||
public static function reconstitute(
|
||||
int $id,
|
||||
@@ -79,16 +83,17 @@ final class Task
|
||||
TaskStatus $status,
|
||||
?DateTimeImmutable $dueOn,
|
||||
?EstimatedHours $estimatedHours,
|
||||
array $assigneeUserIds,
|
||||
?int $assigneeUserId,
|
||||
array $memberUserIds,
|
||||
int $createdBy,
|
||||
?DateTimeImmutable $plannedFrom = null,
|
||||
?DateTimeImmutable $plannedTo = null,
|
||||
): self {
|
||||
return new self($id, $jobId, $workTypeId, $title, $description, $status, $dueOn, $estimatedHours, $assigneeUserIds, $createdBy, $plannedFrom, $plannedTo);
|
||||
return new self($id, $jobId, $workTypeId, $title, $description, $status, $dueOn, $estimatedHours, $assigneeUserId, $memberUserIds, $createdBy, $plannedFrom, $plannedTo);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<int> $assigneeUserIds
|
||||
* @param list<int> $memberUserIds
|
||||
*/
|
||||
public function changeDetails(
|
||||
int $workTypeId,
|
||||
@@ -97,7 +102,8 @@ final class Task
|
||||
TaskStatus $status,
|
||||
?DateTimeImmutable $dueOn,
|
||||
?EstimatedHours $estimatedHours,
|
||||
array $assigneeUserIds,
|
||||
?int $assigneeUserId,
|
||||
array $memberUserIds,
|
||||
): void {
|
||||
$this->workTypeId = $workTypeId;
|
||||
$this->title = $title;
|
||||
@@ -105,7 +111,8 @@ final class Task
|
||||
$this->status = $status;
|
||||
$this->dueOn = $dueOn;
|
||||
$this->estimatedHours = $estimatedHours;
|
||||
$this->assigneeUserIds = self::normaliseIds($assigneeUserIds);
|
||||
$this->assigneeUserId = $assigneeUserId;
|
||||
$this->memberUserIds = self::members($memberUserIds, $assigneeUserId);
|
||||
}
|
||||
|
||||
public function changeStatus(TaskStatus $status): void
|
||||
@@ -125,11 +132,13 @@ final class Task
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<int> $assigneeUserIds
|
||||
* Makes the user the assignee (null: no assignee). A member who becomes
|
||||
* the assignee is no longer a member; the earlier assignee is dropped.
|
||||
*/
|
||||
public function changeAssignees(array $assigneeUserIds): void
|
||||
public function assignTo(?int $userId): void
|
||||
{
|
||||
$this->assigneeUserIds = self::normaliseIds($assigneeUserIds);
|
||||
$this->assigneeUserId = $userId;
|
||||
$this->memberUserIds = self::members($this->memberUserIds, $userId);
|
||||
}
|
||||
|
||||
public function id(): ?int
|
||||
@@ -187,12 +196,17 @@ final class Task
|
||||
return $this->plannedFrom !== null;
|
||||
}
|
||||
|
||||
public function assigneeUserId(): ?int
|
||||
{
|
||||
return $this->assigneeUserId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<int>
|
||||
*/
|
||||
public function assigneeUserIds(): array
|
||||
public function memberUserIds(): array
|
||||
{
|
||||
return $this->assigneeUserIds;
|
||||
return $this->memberUserIds;
|
||||
}
|
||||
|
||||
public function createdBy(): int
|
||||
@@ -201,12 +215,14 @@ final class Task
|
||||
}
|
||||
|
||||
/**
|
||||
* The members sorted, without duplicates and without the assignee.
|
||||
*
|
||||
* @param list<int> $ids
|
||||
* @return list<int>
|
||||
*/
|
||||
private static function normaliseIds(array $ids): array
|
||||
private static function members(array $ids, ?int $assigneeUserId): array
|
||||
{
|
||||
$ids = array_values(array_unique($ids));
|
||||
$ids = array_values(array_unique(array_filter($ids, fn (int $id): bool => $id !== $assigneeUserId)));
|
||||
sort($ids);
|
||||
|
||||
return $ids;
|
||||
|
||||
@@ -9,7 +9,7 @@ use DateInterval;
|
||||
use DateTimeImmutable;
|
||||
|
||||
/**
|
||||
* Books a task's estimated time from an assignee's days (spec 18.3).
|
||||
* Books a task's estimated time from its assignee's days (spec 18.3).
|
||||
*
|
||||
* The estimate is split evenly over the working days of the planned
|
||||
* period (not Saturdays, Sundays or holidays); a period of only such days
|
||||
@@ -65,10 +65,36 @@ final class TaskScheduler
|
||||
}
|
||||
}
|
||||
|
||||
$day = $to;
|
||||
return self::finish($booked, self::bookAfter($to, $carry, $otherMinutes, $capacityMinutes, $holidaySet), $to);
|
||||
}
|
||||
|
||||
for ($extra = 0; $carry > 0 && $extra < self::MAX_EXTRA_DAYS; $extra++) {
|
||||
$day = $day->add(new DateInterval('P1D'));
|
||||
/**
|
||||
* Books a task's estimated time backwards from its due date: first the
|
||||
* assignee's free time on the due date, then on the working days before
|
||||
* it, but not before the earliest day (today). What does not fit goes to
|
||||
* the working days after the due date, which makes the task end late.
|
||||
*
|
||||
* @param array<string, int> $otherMinutes Y-m-d => minutes booked by the assignee's other open tasks.
|
||||
* @param list<string> $holidays Y-m-d dates of the holidays in use.
|
||||
*/
|
||||
public static function scheduleBackwards(
|
||||
DateTimeImmutable $due,
|
||||
int $minutes,
|
||||
array $otherMinutes,
|
||||
int $capacityMinutes,
|
||||
array $holidays,
|
||||
DateTimeImmutable $earliest,
|
||||
): TaskSchedule {
|
||||
if ($minutes <= 0) {
|
||||
return new TaskSchedule([], $due, false);
|
||||
}
|
||||
|
||||
$holidaySet = array_flip($holidays);
|
||||
$booked = [];
|
||||
$carry = $minutes;
|
||||
$first = $earliest->format('Y-m-d');
|
||||
|
||||
for ($day = $due, $back = 0; $carry > 0 && $day->format('Y-m-d') >= $first && $back < self::MAX_EXTRA_DAYS; $day = $day->sub(new DateInterval('P1D')), $back++) {
|
||||
$date = $day->format('Y-m-d');
|
||||
|
||||
if (! self::isWorkingDay($date, $holidaySet)) {
|
||||
@@ -83,16 +109,41 @@ final class TaskScheduler
|
||||
}
|
||||
}
|
||||
|
||||
if ($carry > 0) {
|
||||
$date = $day->format('Y-m-d');
|
||||
$booked[$date] = ($booked[$date] ?? 0) + $carry;
|
||||
// A due date before the earliest day: the rest starts on the earliest day.
|
||||
$after = $due->format('Y-m-d') >= $first ? $due : $earliest->sub(new DateInterval('P1D'));
|
||||
|
||||
return self::finish($booked, self::bookAfter($after, $carry, $otherMinutes, $capacityMinutes, $holidaySet), $due);
|
||||
}
|
||||
|
||||
/**
|
||||
* The start of a task that ends on a day: as many working days before
|
||||
* it as the estimate needs at the daily maximum, but not before the
|
||||
* earliest day unless the end is; without an estimate, the day itself.
|
||||
*
|
||||
* @param list<string> $holidays
|
||||
*/
|
||||
public static function defaultStart(DateTimeImmutable $to, int $minutes, int $capacityMinutes, array $holidays, DateTimeImmutable $earliest): DateTimeImmutable
|
||||
{
|
||||
$first = $earliest->format('Y-m-d');
|
||||
|
||||
if ($minutes <= 0 || $capacityMinutes <= 0 || $to->format('Y-m-d') <= $first) {
|
||||
return $to;
|
||||
}
|
||||
|
||||
ksort($booked);
|
||||
$lastDay = array_key_last($booked);
|
||||
$end = $lastDay !== null && $lastDay > $to->format('Y-m-d') ? new DateTimeImmutable($lastDay) : $to;
|
||||
$needed = (int) ceil($minutes / $capacityMinutes);
|
||||
$holidaySet = array_flip($holidays);
|
||||
$day = $to;
|
||||
$counted = self::isWorkingDay($to->format('Y-m-d'), $holidaySet) ? 1 : 0;
|
||||
|
||||
return new TaskSchedule($booked, $end, $end > $to);
|
||||
while ($counted < $needed && $day->format('Y-m-d') > $first) {
|
||||
$day = $day->sub(new DateInterval('P1D'));
|
||||
|
||||
if (self::isWorkingDay($day->format('Y-m-d'), $holidaySet)) {
|
||||
$counted++;
|
||||
}
|
||||
}
|
||||
|
||||
return $day;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -168,6 +219,59 @@ final class TaskScheduler
|
||||
return $shares;
|
||||
}
|
||||
|
||||
/**
|
||||
* Books the carried minutes on the working days after the day; what
|
||||
* finds no free time within MAX_EXTRA_DAYS goes on the last day tried.
|
||||
*
|
||||
* @param array<string, int> $otherMinutes
|
||||
* @param array<string, int> $holidaySet
|
||||
* @return array<string, int> Y-m-d => minutes.
|
||||
*/
|
||||
private static function bookAfter(DateTimeImmutable $day, int $carry, array $otherMinutes, int $capacityMinutes, array $holidaySet): array
|
||||
{
|
||||
$booked = [];
|
||||
|
||||
for ($extra = 0; $carry > 0 && $extra < self::MAX_EXTRA_DAYS; $extra++) {
|
||||
$day = $day->add(new DateInterval('P1D'));
|
||||
$date = $day->format('Y-m-d');
|
||||
|
||||
if (! self::isWorkingDay($date, $holidaySet)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$booking = min($carry, self::free($date, $otherMinutes, $capacityMinutes));
|
||||
$carry -= $booking;
|
||||
|
||||
if ($booking > 0) {
|
||||
$booked[$date] = $booking;
|
||||
}
|
||||
}
|
||||
|
||||
if ($carry > 0) {
|
||||
$date = $day->format('Y-m-d');
|
||||
$booked[$date] = ($booked[$date] ?? 0) + $carry;
|
||||
}
|
||||
|
||||
return $booked;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, int> $booked
|
||||
* @param array<string, int> $overflow Bookings after the planned end.
|
||||
*/
|
||||
private static function finish(array $booked, array $overflow, DateTimeImmutable $to): TaskSchedule
|
||||
{
|
||||
foreach ($overflow as $date => $minutes) {
|
||||
$booked[$date] = ($booked[$date] ?? 0) + $minutes;
|
||||
}
|
||||
|
||||
ksort($booked);
|
||||
$lastDay = array_key_last($booked);
|
||||
$end = $lastDay !== null && $lastDay > $to->format('Y-m-d') ? new DateTimeImmutable($lastDay) : $to;
|
||||
|
||||
return new TaskSchedule($booked, $end, $end > $to);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, int> $otherMinutes
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user