Add catalog module for service units, services and work types

Phase 1, item 3: the hierarchy customer jobs, tasks and time entries
will refer to.

- New Catalog module: service unit > optional service > work type.
  Names are unique per level (case-insensitive); items are never
  deleted, only deactivated, and foreign keys restrict deletes.
- Pohjatiedot page (/catalog, admins and management): add, rename,
  reorder with move up/down buttons (keyboard-friendly, focus kept and
  announced) and an "in use" checkbox per row. Work types can move to
  another service of the same unit.
- A migration inserts the starting catalog from the specification when
  the tables are empty, so every installation has it.
- CatalogQueries gives other modules the active service units and the
  work types of chosen units plus the shared ones.
- Spec and CLAUDE.md updated.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-11-23 18:27:58 +02:00
co-authored by Claude Opus 5.5
parent e0b8f4970f
commit 51b2d4a252
62 changed files with 3196 additions and 7 deletions
@@ -0,0 +1,74 @@
<?php
namespace App\Modules\Catalog\Presentation\Livewire\Forms;
use App\Modules\Catalog\Domain\Exceptions\CatalogNameTaken;
use App\Modules\Catalog\Domain\Exceptions\InvalidCatalogName;
use App\Modules\Catalog\Domain\Exceptions\ServiceNotInUnit;
use App\Modules\Catalog\Domain\Exceptions\SharedUnitHasNoServices;
use App\Modules\Shared\Domain\Exceptions\DomainException;
use Livewire\Form;
/**
* Name (and for work types, service) of a service unit, service or work type.
*/
class CatalogItemForm extends Form
{
public string $name = '';
/**
* Only for work types: '' means directly under the service unit.
*/
public string $service_id = '';
public function validatedName(): string
{
$this->validate();
return $this->name;
}
public function serviceId(): ?int
{
return $this->service_id === '' ? null : (int) $this->service_id;
}
/**
* Shows a broken business rule as an error on the field it concerns.
*/
public function showDomainError(DomainException $exception): void
{
[$field, $key] = match ($exception::class) {
InvalidCatalogName::class => ['name', 'catalog.errors.invalid_name'],
CatalogNameTaken::class => ['name', 'catalog.errors.name_taken'],
ServiceNotInUnit::class => ['service_id', 'catalog.errors.service_not_in_unit'],
SharedUnitHasNoServices::class => ['name', 'catalog.errors.shared_unit_has_no_services'],
default => throw $exception,
};
$this->addError($field, __($key));
}
/**
* @return array<string, array<int, string>>
*/
protected function rules(): array
{
return [
'name' => ['required', 'string', 'max:100'],
'service_id' => ['nullable', 'integer'],
];
}
/**
* @return array<string, string>
*/
protected function messages(): array
{
return [
'name.required' => __('catalog.errors.name_required'),
'name.max' => __('catalog.errors.invalid_name'),
'service_id.integer' => __('catalog.errors.service_not_in_unit'),
];
}
}