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:
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Modules\Catalog\Infrastructure\Persistence\Eloquent\ServiceModel;
|
||||
use App\Modules\Catalog\Infrastructure\Persistence\Eloquent\ServiceUnitModel;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends Factory<ServiceModel>
|
||||
*/
|
||||
class ServiceFactory extends Factory
|
||||
{
|
||||
protected $model = ServiceModel::class;
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'service_unit_id' => ServiceUnitModel::factory(),
|
||||
'name' => fake()->unique()->words(2, true),
|
||||
'is_active' => true,
|
||||
'sort_order' => fake()->unique()->numberBetween(100, 100000),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Modules\Catalog\Infrastructure\Persistence\Eloquent\ServiceUnitModel;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends Factory<ServiceUnitModel>
|
||||
*/
|
||||
class ServiceUnitFactory extends Factory
|
||||
{
|
||||
protected $model = ServiceUnitModel::class;
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'name' => fake()->unique()->words(2, true),
|
||||
'is_shared' => false,
|
||||
'is_active' => true,
|
||||
'sort_order' => fake()->unique()->numberBetween(100, 100000),
|
||||
];
|
||||
}
|
||||
|
||||
public function inactive(): static
|
||||
{
|
||||
return $this->state(fn (): array => ['is_active' => false]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Modules\Catalog\Infrastructure\Persistence\Eloquent\ServiceUnitModel;
|
||||
use App\Modules\Catalog\Infrastructure\Persistence\Eloquent\WorkTypeModel;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends Factory<WorkTypeModel>
|
||||
*/
|
||||
class WorkTypeFactory extends Factory
|
||||
{
|
||||
protected $model = WorkTypeModel::class;
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'service_unit_id' => ServiceUnitModel::factory(),
|
||||
'service_id' => null,
|
||||
'name' => fake()->unique()->words(2, true),
|
||||
'is_active' => true,
|
||||
'sort_order' => fake()->unique()->numberBetween(100, 100000),
|
||||
];
|
||||
}
|
||||
|
||||
public function inactive(): static
|
||||
{
|
||||
return $this->state(fn (): array => ['is_active' => false]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Service units > services > work types. Rows are never deleted, only
|
||||
* deactivated, so the foreign keys restrict deletes.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('service_units', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name', 100);
|
||||
$table->boolean('is_shared')->default(false);
|
||||
$table->boolean('is_active')->default(true);
|
||||
$table->unsignedInteger('sort_order');
|
||||
$table->timestamps();
|
||||
|
||||
$table->index('sort_order');
|
||||
});
|
||||
|
||||
Schema::create('services', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('service_unit_id')->constrained()->restrictOnDelete();
|
||||
$table->string('name', 100);
|
||||
$table->boolean('is_active')->default(true);
|
||||
$table->unsignedInteger('sort_order');
|
||||
$table->timestamps();
|
||||
|
||||
$table->index(['service_unit_id', 'sort_order']);
|
||||
});
|
||||
|
||||
Schema::create('work_types', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('service_unit_id')->constrained()->restrictOnDelete();
|
||||
$table->foreignId('service_id')->nullable()->constrained()->restrictOnDelete();
|
||||
$table->string('name', 100);
|
||||
$table->boolean('is_active')->default(true);
|
||||
$table->unsignedInteger('sort_order');
|
||||
$table->timestamps();
|
||||
|
||||
$table->index(['service_unit_id', 'service_id', 'sort_order']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('work_types');
|
||||
Schema::dropIfExists('services');
|
||||
Schema::dropIfExists('service_units');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* The starting catalog from the specification (chapter 11.1), so every
|
||||
* installation has it without a separate seed command. Units with
|
||||
* services list them as 'service' => [work types]; others list work
|
||||
* types directly. The last unit is the shared one.
|
||||
*
|
||||
* @var array<string, array<int|string, string|list<string>>>
|
||||
*/
|
||||
private const array CATALOG = [
|
||||
'Mediatuotanto' => [
|
||||
'Videotuotanto' => ['videokuvaus', 'kuvausassistentti', 'editointi', 'animointi', '3D-mallinnus'],
|
||||
'Valokuvaus' => ['kuvaus', 'editointi'],
|
||||
'Äänituotanto' => ['äänitys', 'editointi'],
|
||||
],
|
||||
'Markkinointi' => ['graafinen työ', 'julkaisutyö', 'kampanjatyö'],
|
||||
'Painotuotanto' => ['painotyö', 'asennus'],
|
||||
'Ylläpitopalvelut' => ['asennustyö', 'päivitystyö'],
|
||||
'Verkkosivut' => ['ohjelmointityö'],
|
||||
'Ohjelmistot' => ['ohjelmointityö', 'ohjelmointityö vaativa', 'pelimoottoritoteutukset'],
|
||||
'Kuluttajapalvelut' => ['valokuvaus', 'tulosteet', 'passikuvat', 'digitointi'],
|
||||
'Kaikille yhteiset' => ['suunnittelu', 'tuotanto', 'projektin johtaminen', 'konsultointi', 'koulutus'],
|
||||
];
|
||||
|
||||
private const string SHARED_UNIT = 'Kaikille yhteiset';
|
||||
|
||||
public function up(): void
|
||||
{
|
||||
if (DB::table('service_units')->exists()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$now = now();
|
||||
$unitOrder = 0;
|
||||
|
||||
foreach (self::CATALOG as $unitName => $children) {
|
||||
$unitId = DB::table('service_units')->insertGetId([
|
||||
'name' => $unitName,
|
||||
'is_shared' => $unitName === self::SHARED_UNIT,
|
||||
'is_active' => true,
|
||||
'sort_order' => ++$unitOrder,
|
||||
'created_at' => $now,
|
||||
'updated_at' => $now,
|
||||
]);
|
||||
|
||||
$serviceOrder = 0;
|
||||
$workTypeOrder = 0;
|
||||
|
||||
foreach ($children as $key => $child) {
|
||||
if (is_array($child)) {
|
||||
$serviceId = DB::table('services')->insertGetId([
|
||||
'service_unit_id' => $unitId,
|
||||
'name' => $key,
|
||||
'is_active' => true,
|
||||
'sort_order' => ++$serviceOrder,
|
||||
'created_at' => $now,
|
||||
'updated_at' => $now,
|
||||
]);
|
||||
|
||||
foreach (array_values($child) as $index => $workType) {
|
||||
$this->insertWorkType($unitId, $serviceId, $workType, $index + 1, $now);
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->insertWorkType($unitId, null, $child, ++$workTypeOrder, $now);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The starting data is not removed: it may already be referenced.
|
||||
*/
|
||||
public function down(): void {}
|
||||
|
||||
private function insertWorkType(int $unitId, ?int $serviceId, string $name, int $sortOrder, mixed $now): void
|
||||
{
|
||||
DB::table('work_types')->insert([
|
||||
'service_unit_id' => $unitId,
|
||||
'service_id' => $serviceId,
|
||||
'name' => $name,
|
||||
'is_active' => true,
|
||||
'sort_order' => $sortOrder,
|
||||
'created_at' => $now,
|
||||
'updated_at' => $now,
|
||||
]);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user