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,18 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Fakes;
|
||||
|
||||
use App\Modules\Customers\Application\Contracts\CustomerReferences;
|
||||
|
||||
class FakeCustomerReferences implements CustomerReferences
|
||||
{
|
||||
/**
|
||||
* @var list<int>
|
||||
*/
|
||||
public array $referencedIds = [];
|
||||
|
||||
public function refersTo(int $customerId): bool
|
||||
{
|
||||
return in_array($customerId, $this->referencedIds, true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Fakes;
|
||||
|
||||
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;
|
||||
|
||||
class FakeWorkflowTemplateQueries implements WorkflowTemplateQueries
|
||||
{
|
||||
/** @var array<int, WorkflowTemplateDetails> */
|
||||
public array $templates = [];
|
||||
|
||||
/**
|
||||
* @param list<array{0: string, 1?: int|null}> $steps Title and the step's own work type.
|
||||
*/
|
||||
public function addTemplate(int $id, string $name, int $workTypeId, int $serviceUnitId, array $steps, bool $active = true): void
|
||||
{
|
||||
$this->templates[$id] = new WorkflowTemplateDetails(
|
||||
$id,
|
||||
$name,
|
||||
$workTypeId,
|
||||
'työtehtävä '.$workTypeId,
|
||||
$serviceUnitId,
|
||||
$active,
|
||||
array_map(fn (array $step): WorkflowStepSummary => new WorkflowStepSummary(
|
||||
$step[0],
|
||||
null,
|
||||
$step[1] ?? null,
|
||||
$step[1] ?? $workTypeId,
|
||||
'työtehtävä '.($step[1] ?? $workTypeId),
|
||||
), $steps),
|
||||
);
|
||||
}
|
||||
|
||||
public function all(): array
|
||||
{
|
||||
return array_values(array_map(fn (WorkflowTemplateDetails $template): WorkflowTemplateSummary => new WorkflowTemplateSummary(
|
||||
$template->id,
|
||||
$template->name,
|
||||
$template->workTypeId,
|
||||
$template->workTypeName,
|
||||
$template->serviceUnitId,
|
||||
'yksikkö '.$template->serviceUnitId,
|
||||
$template->isActive,
|
||||
count($template->steps),
|
||||
), $this->templates));
|
||||
}
|
||||
|
||||
public function find(int $id): ?WorkflowTemplateDetails
|
||||
{
|
||||
return $this->templates[$id] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unit 9 plays the shared unit.
|
||||
*/
|
||||
public function activeFor(array $serviceUnitIds): array
|
||||
{
|
||||
return array_values(array_filter(
|
||||
$this->templates,
|
||||
fn (WorkflowTemplateDetails $template): bool => $template->isActive
|
||||
&& (in_array($template->serviceUnitId, $serviceUnitIds, true) || $template->serviceUnitId === 9),
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -43,4 +43,15 @@ class InMemoryBillingUnitRepository implements BillingUnitRepository
|
||||
{
|
||||
unset($this->billingUnits[$billingUnit->id()]);
|
||||
}
|
||||
|
||||
public function existsForCustomer(int $customerId): bool
|
||||
{
|
||||
foreach ($this->billingUnits as $billingUnit) {
|
||||
if ($billingUnit->customerId() === $customerId) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,4 +43,15 @@ class InMemoryCustomerContactRepository implements CustomerContactRepository
|
||||
{
|
||||
unset($this->contacts[$contact->id()]);
|
||||
}
|
||||
|
||||
public function existsForCustomer(int $customerId): bool
|
||||
{
|
||||
foreach ($this->contacts as $contact) {
|
||||
if ($contact->customerId() === $customerId) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,11 @@ class InMemoryCustomerRepository implements CustomerRepository
|
||||
return clone $stored;
|
||||
}
|
||||
|
||||
public function delete(Customer $customer): void
|
||||
{
|
||||
unset($this->customers[$customer->id()]);
|
||||
}
|
||||
|
||||
public function isPersonalIdentityCodeTaken(PersonalIdentityCode $code, ?int $exceptCustomerId = null): bool
|
||||
{
|
||||
foreach ($this->customers as $id => $customer) {
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Fakes;
|
||||
|
||||
use App\Modules\Shared\Application\Contracts\HolidayOverrides;
|
||||
use App\Modules\Shared\Application\DTOs\HolidayOverride;
|
||||
|
||||
class InMemoryHolidayOverrides implements HolidayOverrides
|
||||
{
|
||||
/** @var array<string, HolidayOverride> */
|
||||
public array $overrides = [];
|
||||
|
||||
public function between(string $from, string $to): array
|
||||
{
|
||||
ksort($this->overrides);
|
||||
|
||||
return array_values(array_filter($this->overrides, fn (HolidayOverride $override): bool => $override->date >= $from && $override->date <= $to));
|
||||
}
|
||||
|
||||
public function find(string $date): ?HolidayOverride
|
||||
{
|
||||
return $this->overrides[$date] ?? null;
|
||||
}
|
||||
|
||||
public function save(HolidayOverride $override): void
|
||||
{
|
||||
$this->overrides[$override->date] = $override;
|
||||
}
|
||||
|
||||
public function delete(string $date): void
|
||||
{
|
||||
unset($this->overrides[$date]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Fakes;
|
||||
|
||||
use App\Modules\Jobs\Domain\Contracts\TaskBookingRepository;
|
||||
use App\Modules\Jobs\Domain\Enums\TaskStatus;
|
||||
|
||||
class InMemoryTaskBookingRepository implements TaskBookingRepository
|
||||
{
|
||||
/** @var array<int, array<int, array<string, int>>> task id => user id => day => minutes */
|
||||
public array $bookings = [];
|
||||
|
||||
public function __construct(private InMemoryTaskRepository $tasks) {}
|
||||
|
||||
public function replaceFor(int $taskId, int $userId, array $minutesByDay): void
|
||||
{
|
||||
$this->bookings[$taskId][$userId] = array_filter($minutesByDay, fn (int $minutes): bool => $minutes > 0);
|
||||
}
|
||||
|
||||
public function deleteForTask(int $taskId, array $keepUserIds = []): void
|
||||
{
|
||||
foreach (array_keys($this->bookings[$taskId] ?? []) as $userId) {
|
||||
if (! in_array($userId, $keepUserIds, true)) {
|
||||
unset($this->bookings[$taskId][$userId]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function otherOpenMinutes(int $userId, string $from, string $to, int $exceptTaskId): array
|
||||
{
|
||||
$minutes = [];
|
||||
|
||||
foreach ($this->bookings as $taskId => $users) {
|
||||
if ($taskId === $exceptTaskId || ($this->tasks->tasks[$taskId] ?? null)?->status() === TaskStatus::Done) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($users[$userId] ?? [] as $day => $booked) {
|
||||
if ($day >= $from && $day <= $to) {
|
||||
$minutes[$day] = ($minutes[$day] ?? 0) + $booked;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ksort($minutes);
|
||||
|
||||
return $minutes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, int>
|
||||
*/
|
||||
public function of(int $taskId, int $userId): array
|
||||
{
|
||||
$days = $this->bookings[$taskId][$userId] ?? [];
|
||||
ksort($days);
|
||||
|
||||
return $days;
|
||||
}
|
||||
}
|
||||
@@ -44,6 +44,8 @@ class InMemoryTaskRepository implements TaskRepository
|
||||
$task->estimatedHours(),
|
||||
$task->assigneeUserIds(),
|
||||
$task->createdBy(),
|
||||
$task->plannedFrom(),
|
||||
$task->plannedTo(),
|
||||
);
|
||||
|
||||
return clone $this->tasks[$id];
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Fakes;
|
||||
|
||||
use App\Modules\Catalog\Domain\Contracts\WorkflowTemplateRepository;
|
||||
use App\Modules\Catalog\Domain\Entities\WorkflowTemplate;
|
||||
|
||||
class InMemoryWorkflowTemplateRepository implements WorkflowTemplateRepository
|
||||
{
|
||||
/** @var array<int, WorkflowTemplate> */
|
||||
public array $items = [];
|
||||
|
||||
private int $nextId = 1;
|
||||
|
||||
public function findById(int $id): ?WorkflowTemplate
|
||||
{
|
||||
return isset($this->items[$id]) ? clone $this->items[$id] : null;
|
||||
}
|
||||
|
||||
public function save(WorkflowTemplate $template): WorkflowTemplate
|
||||
{
|
||||
$id = $template->id() ?? $this->nextId++;
|
||||
$this->items[$id] = WorkflowTemplate::reconstitute($id, $template->workTypeId(), $template->name(), $template->isActive(), $template->steps());
|
||||
|
||||
return clone $this->items[$id];
|
||||
}
|
||||
|
||||
public function isNameTaken(int $workTypeId, string $name, ?int $exceptId = null): bool
|
||||
{
|
||||
foreach ($this->items as $id => $template) {
|
||||
if ($id !== $exceptId && $template->workTypeId() === $workTypeId && mb_strtolower($template->name()->value) === mb_strtolower($name)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user