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,103 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\Catalog\Presentation\Livewire\Forms;
|
||||
|
||||
use App\Modules\Catalog\Application\DTOs\WorkflowStepData;
|
||||
use App\Modules\Catalog\Application\DTOs\WorkflowTemplateData;
|
||||
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\Shared\Domain\Exceptions\DomainException;
|
||||
use Livewire\Form;
|
||||
|
||||
/**
|
||||
* Name, work type and steps of a workflow template. Each step has a `key`
|
||||
* that stays the same while steps are moved, for wire:key and element ids.
|
||||
*/
|
||||
class WorkflowTemplateForm extends Form
|
||||
{
|
||||
public string $name = '';
|
||||
|
||||
public string $work_type_id = '';
|
||||
|
||||
/**
|
||||
* @var list<array{key: int, title: string, work_type_id: string, description: string}>
|
||||
*/
|
||||
public array $steps = [];
|
||||
|
||||
public int $nextKey = 1;
|
||||
|
||||
public function addStep(string $title = '', string $workTypeId = '', string $description = ''): int
|
||||
{
|
||||
$key = $this->nextKey++;
|
||||
$this->steps[] = ['key' => $key, 'title' => $title, 'work_type_id' => $workTypeId, 'description' => $description];
|
||||
|
||||
return $key;
|
||||
}
|
||||
|
||||
public function toData(): WorkflowTemplateData
|
||||
{
|
||||
$this->validate();
|
||||
|
||||
return new WorkflowTemplateData(
|
||||
$this->name,
|
||||
(int) $this->work_type_id,
|
||||
array_map(fn (array $step): WorkflowStepData => WorkflowStepData::fromArray($step), $this->steps),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows a broken business rule as an error on the field it concerns.
|
||||
*/
|
||||
public function showDomainError(DomainException $exception): void
|
||||
{
|
||||
[$field, $key] = match (true) {
|
||||
$exception instanceof InvalidCatalogName => ['name', 'catalog.errors.invalid_name'],
|
||||
$exception instanceof WorkflowTemplateNameTaken => ['name', 'catalog.workflows.errors.name_taken'],
|
||||
$exception instanceof CatalogItemNotFound => ['work_type_id', 'catalog.errors.work_type_unavailable'],
|
||||
$exception instanceof WorkflowTemplateNeedsSteps => ['steps', 'catalog.workflows.errors.steps_required'],
|
||||
$exception instanceof InvalidWorkflowStepTitle => ['steps.'.($exception->stepIndex ?? 0).'.title', 'catalog.workflows.errors.invalid_step_title'],
|
||||
$exception instanceof WorkflowStepWorkTypeNotAllowed => ['steps.'.$exception->stepIndex.'.work_type_id', 'catalog.workflows.errors.step_work_type_not_allowed'],
|
||||
default => throw $exception,
|
||||
};
|
||||
|
||||
$this->addError($field, __($key));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array<int, string>>
|
||||
*/
|
||||
protected function rules(): array
|
||||
{
|
||||
return [
|
||||
'name' => ['required', 'string', 'max:100'],
|
||||
'work_type_id' => ['required', 'integer'],
|
||||
'steps' => ['required', 'array', 'min:1'],
|
||||
'steps.*.title' => ['required', 'string', 'max:255'],
|
||||
'steps.*.work_type_id' => ['nullable', 'integer'],
|
||||
'steps.*.description' => ['nullable', 'string', 'max:5000'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function messages(): array
|
||||
{
|
||||
return [
|
||||
'name.required' => __('catalog.errors.name_required'),
|
||||
'name.max' => __('catalog.errors.invalid_name'),
|
||||
'work_type_id.required' => __('catalog.workflows.errors.work_type_required'),
|
||||
'work_type_id.integer' => __('catalog.errors.work_type_unavailable'),
|
||||
'steps.required' => __('catalog.workflows.errors.steps_required'),
|
||||
'steps.min' => __('catalog.workflows.errors.steps_required'),
|
||||
'steps.*.title.required' => __('catalog.workflows.errors.step_title_required'),
|
||||
'steps.*.title.max' => __('catalog.workflows.errors.invalid_step_title'),
|
||||
'steps.*.work_type_id.integer' => __('catalog.workflows.errors.step_work_type_not_allowed'),
|
||||
'steps.*.description.max' => __('catalog.workflows.errors.description_too_long'),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user