Add the task calendar, holidays, workflow templates and customer removal
Task calendar (/jobs/calendar) replaces per-unit task Kanban columns (K34): a two-week Gantt of tasks per person. Bars move, resize and change person by dragging or through a keyboard dialog. Each task's estimate is booked evenly over working days into task_bookings, and what exceeds the daily maximum (jobs.daily_capacity_hours, 8 h) moves to the next working day. Tasks get planned_from/planned_to on the form. Holidays (/settings/holidays): Finnish public holidays calculated per year, which the admin can take out of use, plus company days off. Also includes the earlier uncommitted work: workflow templates with adding tasks from a template, and removing customers no module refers to. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\Catalog\Application\Contracts;
|
||||
|
||||
use App\Modules\Catalog\Application\DTOs\WorkflowTemplateDetails;
|
||||
use App\Modules\Catalog\Application\DTOs\WorkflowTemplateSummary;
|
||||
|
||||
/**
|
||||
* Read side of workflow templates (työnkulkupohjat). Customer jobs use it
|
||||
* to make tasks from a template.
|
||||
*/
|
||||
interface WorkflowTemplateQueries
|
||||
{
|
||||
/**
|
||||
* All templates, active or not, in the order of their work types in the
|
||||
* catalog (the shared unit last) and by name.
|
||||
*
|
||||
* @return list<WorkflowTemplateSummary>
|
||||
*/
|
||||
public function all(): array;
|
||||
|
||||
public function find(int $id): ?WorkflowTemplateDetails;
|
||||
|
||||
/**
|
||||
* Active templates whose work type is in use in the given service units
|
||||
* or in the shared unit, in catalog order and by name.
|
||||
*
|
||||
* @param list<int> $serviceUnitIds
|
||||
* @return list<WorkflowTemplateDetails>
|
||||
*/
|
||||
public function activeFor(array $serviceUnitIds): array;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\Catalog\Application\DTOs;
|
||||
|
||||
/**
|
||||
* A step of a workflow template as entered. A null work type means the template's own.
|
||||
*/
|
||||
final readonly class WorkflowStepData
|
||||
{
|
||||
public function __construct(
|
||||
public string $title,
|
||||
public ?string $description = null,
|
||||
public ?int $workTypeId = null,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @param array{title?: string, description?: string|null, work_type_id?: int|string|null} $input
|
||||
*/
|
||||
public static function fromArray(array $input): self
|
||||
{
|
||||
$workTypeId = $input['work_type_id'] ?? null;
|
||||
|
||||
return new self(
|
||||
(string) ($input['title'] ?? ''),
|
||||
$input['description'] ?? null,
|
||||
$workTypeId === null || $workTypeId === '' ? null : (int) $workTypeId,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\Catalog\Application\DTOs;
|
||||
|
||||
/**
|
||||
* A step of a workflow template. $workTypeId is the step's own work type
|
||||
* (null: the template's), $effectiveWorkTypeId the one its task gets.
|
||||
*/
|
||||
final readonly class WorkflowStepSummary
|
||||
{
|
||||
public function __construct(
|
||||
public string $title,
|
||||
public ?string $description,
|
||||
public ?int $workTypeId,
|
||||
public int $effectiveWorkTypeId,
|
||||
public string $workTypeName,
|
||||
) {}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\Catalog\Application\DTOs;
|
||||
|
||||
/**
|
||||
* A workflow template as entered on its form.
|
||||
*/
|
||||
final readonly class WorkflowTemplateData
|
||||
{
|
||||
/**
|
||||
* @param list<WorkflowStepData> $steps
|
||||
*/
|
||||
public function __construct(
|
||||
public string $name,
|
||||
public int $workTypeId,
|
||||
public array $steps,
|
||||
) {}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\Catalog\Application\DTOs;
|
||||
|
||||
/**
|
||||
* A workflow template with its steps in order.
|
||||
*/
|
||||
final readonly class WorkflowTemplateDetails
|
||||
{
|
||||
/**
|
||||
* @param list<WorkflowStepSummary> $steps
|
||||
*/
|
||||
public function __construct(
|
||||
public int $id,
|
||||
public string $name,
|
||||
public int $workTypeId,
|
||||
public string $workTypeName,
|
||||
public int $serviceUnitId,
|
||||
public bool $isActive,
|
||||
public array $steps,
|
||||
) {}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\Catalog\Application\DTOs;
|
||||
|
||||
/**
|
||||
* A workflow template on the template list.
|
||||
*/
|
||||
final readonly class WorkflowTemplateSummary
|
||||
{
|
||||
public function __construct(
|
||||
public int $id,
|
||||
public string $name,
|
||||
public int $workTypeId,
|
||||
public string $workTypeName,
|
||||
public int $serviceUnitId,
|
||||
public string $serviceUnitName,
|
||||
public bool $isActive,
|
||||
public int $stepCount,
|
||||
) {}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\Catalog\Application\Services;
|
||||
|
||||
use App\Modules\Catalog\Application\DTOs\WorkflowStepData;
|
||||
use App\Modules\Catalog\Domain\Contracts\ServiceUnitRepository;
|
||||
use App\Modules\Catalog\Domain\Contracts\WorkTypeRepository;
|
||||
use App\Modules\Catalog\Domain\Entities\WorkType;
|
||||
use App\Modules\Catalog\Domain\Exceptions\InvalidWorkflowStepTitle;
|
||||
use App\Modules\Catalog\Domain\Exceptions\WorkflowStepWorkTypeNotAllowed;
|
||||
use App\Modules\Catalog\Domain\ValueObjects\WorkflowStep;
|
||||
use App\Modules\Catalog\Domain\ValueObjects\WorkflowStepTitle;
|
||||
|
||||
/**
|
||||
* Builds the steps of a workflow template from input and checks their own work types.
|
||||
*/
|
||||
final class WorkflowStepBuilder
|
||||
{
|
||||
public function __construct(
|
||||
private WorkTypeRepository $workTypes,
|
||||
private ServiceUnitRepository $serviceUnits,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @param list<WorkflowStepData> $input
|
||||
* @return list<WorkflowStep>
|
||||
*
|
||||
* @throws InvalidWorkflowStepTitle with the index of the step
|
||||
*/
|
||||
public function build(array $input): array
|
||||
{
|
||||
$steps = [];
|
||||
|
||||
foreach ($input as $index => $step) {
|
||||
try {
|
||||
$title = new WorkflowStepTitle($step->title);
|
||||
} catch (InvalidWorkflowStepTitle) {
|
||||
throw new InvalidWorkflowStepTitle($index);
|
||||
}
|
||||
|
||||
$steps[] = new WorkflowStep($title, $step->description, $step->workTypeId);
|
||||
}
|
||||
|
||||
return $steps;
|
||||
}
|
||||
|
||||
/**
|
||||
* A step's own work type must be in use and belong to the template work
|
||||
* type's unit or to the shared unit. A work type the template already
|
||||
* uses stays allowed after it is taken out of use.
|
||||
*
|
||||
* @param list<WorkflowStep> $steps
|
||||
* @param list<WorkflowStep> $currentSteps
|
||||
*
|
||||
* @throws WorkflowStepWorkTypeNotAllowed
|
||||
*/
|
||||
public function checkWorkTypes(WorkType $templateWorkType, array $steps, array $currentSteps = []): void
|
||||
{
|
||||
$currentIds = array_map(fn (WorkflowStep $step): ?int => $step->workTypeId, $currentSteps);
|
||||
|
||||
foreach ($steps as $index => $step) {
|
||||
if ($step->workTypeId === null || $step->workTypeId === $templateWorkType->id()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$workType = $this->workTypes->findById($step->workTypeId);
|
||||
|
||||
if ($workType === null
|
||||
|| (! $workType->isActive() && ! in_array($workType->id(), $currentIds, true))
|
||||
|| ! $this->sameOrSharedUnit($templateWorkType, $workType)) {
|
||||
throw new WorkflowStepWorkTypeNotAllowed($index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function sameOrSharedUnit(WorkType $templateWorkType, WorkType $workType): bool
|
||||
{
|
||||
return $workType->serviceUnitId() === $templateWorkType->serviceUnitId()
|
||||
|| ($this->serviceUnits->findById($workType->serviceUnitId())?->isShared() ?? false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\Catalog\Application\UseCases;
|
||||
|
||||
use App\Modules\Catalog\Application\DTOs\WorkflowTemplateData;
|
||||
use App\Modules\Catalog\Application\Services\WorkflowStepBuilder;
|
||||
use App\Modules\Catalog\Domain\Contracts\WorkflowTemplateRepository;
|
||||
use App\Modules\Catalog\Domain\Contracts\WorkTypeRepository;
|
||||
use App\Modules\Catalog\Domain\Entities\WorkflowTemplate;
|
||||
use App\Modules\Catalog\Domain\Enums\CatalogLevel;
|
||||
use App\Modules\Catalog\Domain\Exceptions\CatalogItemNotFound;
|
||||
use App\Modules\Catalog\Domain\Exceptions\InvalidCatalogName;
|
||||
use App\Modules\Catalog\Domain\Exceptions\InvalidWorkflowStepTitle;
|
||||
use App\Modules\Catalog\Domain\Exceptions\WorkflowStepWorkTypeNotAllowed;
|
||||
use App\Modules\Catalog\Domain\Exceptions\WorkflowTemplateNameTaken;
|
||||
use App\Modules\Catalog\Domain\Exceptions\WorkflowTemplateNeedsSteps;
|
||||
use App\Modules\Catalog\Domain\ValueObjects\CatalogName;
|
||||
use App\Modules\Shared\Application\Contracts\TransactionManager;
|
||||
|
||||
/**
|
||||
* Adds a workflow template to an active work type and returns its id.
|
||||
*/
|
||||
final class AddWorkflowTemplate
|
||||
{
|
||||
public function __construct(
|
||||
private WorkflowTemplateRepository $templates,
|
||||
private WorkTypeRepository $workTypes,
|
||||
private WorkflowStepBuilder $stepBuilder,
|
||||
private TransactionManager $transactions,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @throws CatalogItemNotFound when the work type is missing or not in use
|
||||
* @throws InvalidCatalogName
|
||||
* @throws InvalidWorkflowStepTitle
|
||||
* @throws WorkflowStepWorkTypeNotAllowed
|
||||
* @throws WorkflowTemplateNameTaken
|
||||
* @throws WorkflowTemplateNeedsSteps
|
||||
*/
|
||||
public function execute(WorkflowTemplateData $data): int
|
||||
{
|
||||
$name = new CatalogName($data->name);
|
||||
$steps = $this->stepBuilder->build($data->steps);
|
||||
$template = WorkflowTemplate::create($data->workTypeId, $name, $steps);
|
||||
|
||||
return $this->transactions->run(function () use ($data, $name, $steps, $template): int {
|
||||
$workType = $this->workTypes->findById($data->workTypeId);
|
||||
|
||||
if ($workType === null || ! $workType->isActive()) {
|
||||
throw new CatalogItemNotFound(CatalogLevel::WorkType, $data->workTypeId);
|
||||
}
|
||||
|
||||
if ($this->templates->isNameTaken($data->workTypeId, $name->value)) {
|
||||
throw new WorkflowTemplateNameTaken;
|
||||
}
|
||||
|
||||
$this->stepBuilder->checkWorkTypes($workType, $steps);
|
||||
|
||||
return (int) $this->templates->save($template)->id();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\Catalog\Application\UseCases;
|
||||
|
||||
use App\Modules\Catalog\Domain\Contracts\WorkflowTemplateRepository;
|
||||
use App\Modules\Catalog\Domain\Exceptions\WorkflowTemplateNotFound;
|
||||
use App\Modules\Shared\Application\Contracts\TransactionManager;
|
||||
|
||||
/**
|
||||
* Takes a workflow template out of use or back into use. A template out of
|
||||
* use is not offered on customer jobs.
|
||||
*/
|
||||
final class SetWorkflowTemplateActive
|
||||
{
|
||||
public function __construct(
|
||||
private WorkflowTemplateRepository $templates,
|
||||
private TransactionManager $transactions,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @throws WorkflowTemplateNotFound
|
||||
*/
|
||||
public function execute(int $templateId, bool $active): void
|
||||
{
|
||||
$this->transactions->run(function () use ($templateId, $active): void {
|
||||
$template = $this->templates->findById($templateId) ?? throw new WorkflowTemplateNotFound($templateId);
|
||||
|
||||
$active ? $template->activate() : $template->deactivate();
|
||||
$this->templates->save($template);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\Catalog\Application\UseCases;
|
||||
|
||||
use App\Modules\Catalog\Application\DTOs\WorkflowTemplateData;
|
||||
use App\Modules\Catalog\Application\Services\WorkflowStepBuilder;
|
||||
use App\Modules\Catalog\Domain\Contracts\WorkflowTemplateRepository;
|
||||
use App\Modules\Catalog\Domain\Contracts\WorkTypeRepository;
|
||||
use App\Modules\Catalog\Domain\Enums\CatalogLevel;
|
||||
use App\Modules\Catalog\Domain\Exceptions\CatalogItemNotFound;
|
||||
use App\Modules\Catalog\Domain\Exceptions\InvalidCatalogName;
|
||||
use App\Modules\Catalog\Domain\Exceptions\InvalidWorkflowStepTitle;
|
||||
use App\Modules\Catalog\Domain\Exceptions\WorkflowStepWorkTypeNotAllowed;
|
||||
use App\Modules\Catalog\Domain\Exceptions\WorkflowTemplateNameTaken;
|
||||
use App\Modules\Catalog\Domain\Exceptions\WorkflowTemplateNeedsSteps;
|
||||
use App\Modules\Catalog\Domain\Exceptions\WorkflowTemplateNotFound;
|
||||
use App\Modules\Catalog\Domain\ValueObjects\CatalogName;
|
||||
use App\Modules\Shared\Application\Contracts\TransactionManager;
|
||||
|
||||
/**
|
||||
* Saves a workflow template's name, work type and steps. Tasks already made
|
||||
* from the template do not change.
|
||||
*/
|
||||
final class UpdateWorkflowTemplate
|
||||
{
|
||||
public function __construct(
|
||||
private WorkflowTemplateRepository $templates,
|
||||
private WorkTypeRepository $workTypes,
|
||||
private WorkflowStepBuilder $stepBuilder,
|
||||
private TransactionManager $transactions,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @throws CatalogItemNotFound when a new work type is missing or not in use
|
||||
* @throws InvalidCatalogName
|
||||
* @throws InvalidWorkflowStepTitle
|
||||
* @throws WorkflowStepWorkTypeNotAllowed
|
||||
* @throws WorkflowTemplateNameTaken
|
||||
* @throws WorkflowTemplateNeedsSteps
|
||||
* @throws WorkflowTemplateNotFound
|
||||
*/
|
||||
public function execute(int $templateId, WorkflowTemplateData $data): void
|
||||
{
|
||||
$name = new CatalogName($data->name);
|
||||
$steps = $this->stepBuilder->build($data->steps);
|
||||
|
||||
$this->transactions->run(function () use ($templateId, $data, $name, $steps): void {
|
||||
$template = $this->templates->findById($templateId) ?? throw new WorkflowTemplateNotFound($templateId);
|
||||
$workType = $this->workTypes->findById($data->workTypeId);
|
||||
$workTypeChanged = $data->workTypeId !== $template->workTypeId();
|
||||
|
||||
if ($workType === null || ($workTypeChanged && ! $workType->isActive())) {
|
||||
throw new CatalogItemNotFound(CatalogLevel::WorkType, $data->workTypeId);
|
||||
}
|
||||
|
||||
if ($this->templates->isNameTaken($data->workTypeId, $name->value, $templateId)) {
|
||||
throw new WorkflowTemplateNameTaken;
|
||||
}
|
||||
|
||||
$this->stepBuilder->checkWorkTypes($workType, $steps, $template->steps());
|
||||
|
||||
$template->change($data->workTypeId, $name, $steps);
|
||||
$this->templates->save($template);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user