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:
+128
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\Catalog\Infrastructure\Persistence\Repositories;
|
||||
|
||||
use App\Modules\Catalog\Application\Contracts\WorkflowTemplateQueries;
|
||||
use App\Modules\Catalog\Application\DTOs\WorkflowStepSummary;
|
||||
use App\Modules\Catalog\Application\DTOs\WorkflowTemplateDetails;
|
||||
use App\Modules\Catalog\Application\DTOs\WorkflowTemplateSummary;
|
||||
use App\Modules\Catalog\Infrastructure\Persistence\Eloquent\WorkflowTemplateModel;
|
||||
use App\Modules\Catalog\Infrastructure\Persistence\Eloquent\WorkflowTemplateStepModel;
|
||||
use App\Modules\Catalog\Infrastructure\Persistence\Eloquent\WorkTypeModel;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
|
||||
class EloquentWorkflowTemplateQueries implements WorkflowTemplateQueries
|
||||
{
|
||||
public function all(): array
|
||||
{
|
||||
return $this->ordered()
|
||||
->withCount('steps')
|
||||
->get()
|
||||
->map(fn (WorkflowTemplateModel $model): WorkflowTemplateSummary => new WorkflowTemplateSummary(
|
||||
$model->id,
|
||||
$model->name,
|
||||
$model->work_type_id,
|
||||
(string) $model->getAttribute('work_type_name'),
|
||||
(int) $model->getAttribute('service_unit_id'),
|
||||
(string) $model->getAttribute('service_unit_name'),
|
||||
$model->is_active,
|
||||
(int) $model->getAttribute('steps_count'),
|
||||
))
|
||||
->values()
|
||||
->all();
|
||||
}
|
||||
|
||||
public function find(int $id): ?WorkflowTemplateDetails
|
||||
{
|
||||
$models = $this->ordered()->whereKey($id)->get();
|
||||
|
||||
return $this->toDetails($models)[0] ?? null;
|
||||
}
|
||||
|
||||
public function activeFor(array $serviceUnitIds): array
|
||||
{
|
||||
$models = $this->ordered()
|
||||
->where('workflow_templates.is_active', true)
|
||||
->where('work_types.is_active', true)
|
||||
->where('service_units.is_active', true)
|
||||
->where(fn (Builder $query) => $query->whereNull('services.id')->orWhere('services.is_active', true))
|
||||
->where(fn (Builder $query) => $query
|
||||
->whereIn('service_units.id', $serviceUnitIds)
|
||||
->orWhere('service_units.is_shared', true))
|
||||
->get();
|
||||
|
||||
return $this->toDetails($models);
|
||||
}
|
||||
|
||||
/**
|
||||
* Templates with their work type and unit, in catalog order: units (the
|
||||
* shared one last), services, work types under no service last, then by name.
|
||||
*
|
||||
* @return Builder<WorkflowTemplateModel>
|
||||
*/
|
||||
private function ordered(): Builder
|
||||
{
|
||||
return WorkflowTemplateModel::query()
|
||||
->join('work_types', 'work_types.id', '=', 'workflow_templates.work_type_id')
|
||||
->join('service_units', 'service_units.id', '=', 'work_types.service_unit_id')
|
||||
->leftJoin('services', 'services.id', '=', 'work_types.service_id')
|
||||
->select('workflow_templates.*')
|
||||
->addSelect([
|
||||
'work_types.name as work_type_name',
|
||||
'service_units.id as service_unit_id',
|
||||
'service_units.name as service_unit_name',
|
||||
])
|
||||
->orderBy('service_units.is_shared')
|
||||
->orderBy('service_units.sort_order')
|
||||
->orderByRaw('services.sort_order IS NULL')
|
||||
->orderBy('services.sort_order')
|
||||
->orderBy('work_types.sort_order')
|
||||
->orderBy('workflow_templates.name')
|
||||
->orderBy('workflow_templates.id');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection<int, WorkflowTemplateModel> $models
|
||||
* @return list<WorkflowTemplateDetails>
|
||||
*/
|
||||
private function toDetails(Collection $models): array
|
||||
{
|
||||
if ($models->isEmpty()) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$steps = WorkflowTemplateStepModel::query()
|
||||
->whereIn('workflow_template_id', $models->pluck('id'))
|
||||
->orderBy('sort_order')
|
||||
->get()
|
||||
->groupBy('workflow_template_id');
|
||||
|
||||
$workTypeNames = WorkTypeModel::query()
|
||||
->whereIn('id', $steps->flatten(1)->pluck('work_type_id')->filter()->unique())
|
||||
->pluck('name', 'id');
|
||||
|
||||
return $models->map(function (WorkflowTemplateModel $model) use ($steps, $workTypeNames): WorkflowTemplateDetails {
|
||||
$workTypeName = (string) $model->getAttribute('work_type_name');
|
||||
|
||||
return new WorkflowTemplateDetails(
|
||||
$model->id,
|
||||
$model->name,
|
||||
$model->work_type_id,
|
||||
$workTypeName,
|
||||
(int) $model->getAttribute('service_unit_id'),
|
||||
$model->is_active,
|
||||
($steps->get($model->id) ?? collect())
|
||||
->map(fn (WorkflowTemplateStepModel $step): WorkflowStepSummary => new WorkflowStepSummary(
|
||||
$step->title,
|
||||
$step->description,
|
||||
$step->work_type_id,
|
||||
$step->work_type_id ?? $model->work_type_id,
|
||||
$step->work_type_id === null ? $workTypeName : (string) $workTypeNames->get($step->work_type_id),
|
||||
))
|
||||
->values()
|
||||
->all(),
|
||||
);
|
||||
})->values()->all();
|
||||
}
|
||||
}
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\Catalog\Infrastructure\Persistence\Repositories;
|
||||
|
||||
use App\Modules\Catalog\Domain\Contracts\WorkflowTemplateRepository;
|
||||
use App\Modules\Catalog\Domain\Entities\WorkflowTemplate;
|
||||
use App\Modules\Catalog\Domain\ValueObjects\CatalogName;
|
||||
use App\Modules\Catalog\Domain\ValueObjects\WorkflowStep;
|
||||
use App\Modules\Catalog\Domain\ValueObjects\WorkflowStepTitle;
|
||||
use App\Modules\Catalog\Infrastructure\Persistence\Eloquent\WorkflowTemplateModel;
|
||||
use App\Modules\Catalog\Infrastructure\Persistence\Eloquent\WorkflowTemplateStepModel;
|
||||
|
||||
class EloquentWorkflowTemplateRepository implements WorkflowTemplateRepository
|
||||
{
|
||||
public function findById(int $id): ?WorkflowTemplate
|
||||
{
|
||||
$model = WorkflowTemplateModel::query()->with('steps')->find($id);
|
||||
|
||||
return $model === null ? null : $this->toEntity($model);
|
||||
}
|
||||
|
||||
public function save(WorkflowTemplate $template): WorkflowTemplate
|
||||
{
|
||||
$model = $template->id() === null ? new WorkflowTemplateModel : WorkflowTemplateModel::query()->findOrFail($template->id());
|
||||
|
||||
$model->fill([
|
||||
'work_type_id' => $template->workTypeId(),
|
||||
'name' => $template->name()->value,
|
||||
'is_active' => $template->isActive(),
|
||||
])->save();
|
||||
|
||||
// Steps have no identity of their own: the saved list replaces the old one.
|
||||
WorkflowTemplateStepModel::query()->where('workflow_template_id', $model->id)->delete();
|
||||
|
||||
foreach ($template->steps() as $index => $step) {
|
||||
WorkflowTemplateStepModel::query()->create([
|
||||
'workflow_template_id' => $model->id,
|
||||
'work_type_id' => $step->workTypeId,
|
||||
'title' => $step->title->value,
|
||||
'description' => $step->description,
|
||||
'sort_order' => $index + 1,
|
||||
]);
|
||||
}
|
||||
|
||||
return $this->toEntity($model->load('steps'));
|
||||
}
|
||||
|
||||
public function isNameTaken(int $workTypeId, string $name, ?int $exceptId = null): bool
|
||||
{
|
||||
return WorkflowTemplateModel::query()
|
||||
->where('work_type_id', $workTypeId)
|
||||
->whereRaw('LOWER(name) = ?', [mb_strtolower($name)])
|
||||
->when($exceptId !== null, fn ($query) => $query->whereKeyNot($exceptId))
|
||||
->exists();
|
||||
}
|
||||
|
||||
private function toEntity(WorkflowTemplateModel $model): WorkflowTemplate
|
||||
{
|
||||
return WorkflowTemplate::reconstitute(
|
||||
$model->id,
|
||||
$model->work_type_id,
|
||||
new CatalogName($model->name),
|
||||
$model->is_active,
|
||||
$model->steps
|
||||
->map(fn (WorkflowTemplateStepModel $step): WorkflowStep => new WorkflowStep(
|
||||
new WorkflowStepTitle($step->title),
|
||||
$step->description,
|
||||
$step->work_type_id,
|
||||
))
|
||||
->values()
|
||||
->all(),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user