Add tasks to customer jobs
Phase 1, item 7, in the Jobs module (tasks are part of a job, and my jobs needs their assignees): - Tasks with name, work type, assignees, status (waiting, in progress, in review, done), due date, estimated hours and description. - Tasks can be added once the job is a quote request or later, not to an archived job. The work type must belong to the job's service units or the shared ones and be in use; assignees must be active. What a task already has stays allowed after being taken out of use. - Job page: a Tehtävät section with a status select per task (announced, focus kept), edit links and delete with a confirmation dialog. Task form with work types grouped by unit and service. - Access: adding, changing and removing for everyone but subcontractors; subcontractors may change task statuses on jobs they are attached to. - Task assignees now count in my jobs (list, Kanban, job access). - Spec and CLAUDE.md updated. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -0,0 +1,177 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\Jobs\Domain\Entities;
|
||||
|
||||
use App\Modules\Jobs\Domain\Enums\JobStatus;
|
||||
use App\Modules\Jobs\Domain\Enums\TaskStatus;
|
||||
use App\Modules\Jobs\Domain\Exceptions\TasksNotAllowedYet;
|
||||
use App\Modules\Jobs\Domain\ValueObjects\EstimatedHours;
|
||||
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.
|
||||
*/
|
||||
final class Task
|
||||
{
|
||||
/**
|
||||
* @param list<int> $assigneeUserIds
|
||||
*/
|
||||
private function __construct(
|
||||
private ?int $id,
|
||||
private int $jobId,
|
||||
private int $workTypeId,
|
||||
private TaskTitle $title,
|
||||
private ?string $description,
|
||||
private TaskStatus $status,
|
||||
private ?DateTimeImmutable $dueOn,
|
||||
private ?EstimatedHours $estimatedHours,
|
||||
private array $assigneeUserIds,
|
||||
private int $createdBy,
|
||||
) {
|
||||
$this->assigneeUserIds = self::normaliseIds($assigneeUserIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<int> $assigneeUserIds
|
||||
*
|
||||
* @throws TasksNotAllowedYet
|
||||
*/
|
||||
public static function create(
|
||||
int $jobId,
|
||||
JobStatus $jobStatus,
|
||||
int $workTypeId,
|
||||
TaskTitle $title,
|
||||
?string $description,
|
||||
TaskStatus $status,
|
||||
?DateTimeImmutable $dueOn,
|
||||
?EstimatedHours $estimatedHours,
|
||||
array $assigneeUserIds,
|
||||
int $createdBy,
|
||||
): self {
|
||||
if (! $jobStatus->allowsTasks()) {
|
||||
throw new TasksNotAllowedYet;
|
||||
}
|
||||
|
||||
return new self(null, $jobId, $workTypeId, $title, self::text($description), $status, $dueOn, $estimatedHours, $assigneeUserIds, $createdBy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<int> $assigneeUserIds
|
||||
*/
|
||||
public static function reconstitute(
|
||||
int $id,
|
||||
int $jobId,
|
||||
int $workTypeId,
|
||||
TaskTitle $title,
|
||||
?string $description,
|
||||
TaskStatus $status,
|
||||
?DateTimeImmutable $dueOn,
|
||||
?EstimatedHours $estimatedHours,
|
||||
array $assigneeUserIds,
|
||||
int $createdBy,
|
||||
): self {
|
||||
return new self($id, $jobId, $workTypeId, $title, $description, $status, $dueOn, $estimatedHours, $assigneeUserIds, $createdBy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<int> $assigneeUserIds
|
||||
*/
|
||||
public function changeDetails(
|
||||
int $workTypeId,
|
||||
TaskTitle $title,
|
||||
?string $description,
|
||||
TaskStatus $status,
|
||||
?DateTimeImmutable $dueOn,
|
||||
?EstimatedHours $estimatedHours,
|
||||
array $assigneeUserIds,
|
||||
): void {
|
||||
$this->workTypeId = $workTypeId;
|
||||
$this->title = $title;
|
||||
$this->description = self::text($description);
|
||||
$this->status = $status;
|
||||
$this->dueOn = $dueOn;
|
||||
$this->estimatedHours = $estimatedHours;
|
||||
$this->assigneeUserIds = self::normaliseIds($assigneeUserIds);
|
||||
}
|
||||
|
||||
public function changeStatus(TaskStatus $status): void
|
||||
{
|
||||
$this->status = $status;
|
||||
}
|
||||
|
||||
public function id(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function jobId(): int
|
||||
{
|
||||
return $this->jobId;
|
||||
}
|
||||
|
||||
public function workTypeId(): int
|
||||
{
|
||||
return $this->workTypeId;
|
||||
}
|
||||
|
||||
public function title(): TaskTitle
|
||||
{
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
public function description(): ?string
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
public function status(): TaskStatus
|
||||
{
|
||||
return $this->status;
|
||||
}
|
||||
|
||||
public function dueOn(): ?DateTimeImmutable
|
||||
{
|
||||
return $this->dueOn;
|
||||
}
|
||||
|
||||
public function estimatedHours(): ?EstimatedHours
|
||||
{
|
||||
return $this->estimatedHours;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<int>
|
||||
*/
|
||||
public function assigneeUserIds(): array
|
||||
{
|
||||
return $this->assigneeUserIds;
|
||||
}
|
||||
|
||||
public function createdBy(): int
|
||||
{
|
||||
return $this->createdBy;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<int> $ids
|
||||
* @return list<int>
|
||||
*/
|
||||
private static function normaliseIds(array $ids): array
|
||||
{
|
||||
$ids = array_values(array_unique($ids));
|
||||
sort($ids);
|
||||
|
||||
return $ids;
|
||||
}
|
||||
|
||||
private static function text(?string $value): ?string
|
||||
{
|
||||
$value = $value === null ? '' : trim($value);
|
||||
|
||||
return $value === '' ? null : $value;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user