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,222 @@
|
||||
<?php
|
||||
|
||||
use App\Modules\Shared\Application\DTOs\Holiday;
|
||||
use App\Modules\Shared\Application\UseCases\HolidayCalendar;
|
||||
use App\Modules\Shared\Domain\Exceptions\HolidayAlreadyExists;
|
||||
use App\Modules\Shared\Domain\Exceptions\InvalidHolidayName;
|
||||
use App\Modules\Shared\Domain\Exceptions\NotAHoliday;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Livewire\Attributes\Computed;
|
||||
use Livewire\Attributes\Locked;
|
||||
use Livewire\Attributes\Url;
|
||||
use Livewire\Component;
|
||||
|
||||
/**
|
||||
* Holidays (Arkipyhät): the Finnish public holidays of a year, calculated
|
||||
* automatically, which the admin can take out of use, and the company's
|
||||
* own days off. The task calendar shows them like weekends.
|
||||
*/
|
||||
new class extends Component
|
||||
{
|
||||
#[Url(except: 0)]
|
||||
public int $year = 0;
|
||||
|
||||
public string $date = '';
|
||||
|
||||
public string $name = '';
|
||||
|
||||
#[Locked]
|
||||
public string $statusMessage = '';
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
$this->authorize('settings.manage');
|
||||
|
||||
if ($this->year < 2000 || $this->year > 2100) {
|
||||
$this->year = (int) now()->format('Y');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<array{date: string, day: string, name: string, kind: string, active: bool, company: bool}>
|
||||
*/
|
||||
#[Computed]
|
||||
public function holidays(): array
|
||||
{
|
||||
return array_map(fn (Holiday $holiday): array => [
|
||||
'date' => $holiday->date,
|
||||
'day' => $this->formatDay($holiday->date),
|
||||
'name' => $this->holidayName($holiday),
|
||||
'kind' => __($holiday->isCompanyDay() ? 'holidays.kinds.company' : 'holidays.kinds.public'),
|
||||
'active' => $holiday->active,
|
||||
'company' => $holiday->isCompanyDay(),
|
||||
], app(HolidayCalendar::class)->between($this->year.'-01-01', $this->year.'-12-31'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<array{index: string, label: string, sortable: bool}>
|
||||
*/
|
||||
public function headers(): array
|
||||
{
|
||||
return [
|
||||
['index' => 'day', 'label' => __('holidays.columns.date'), 'sortable' => false],
|
||||
['index' => 'name', 'label' => __('holidays.columns.name'), 'sortable' => false],
|
||||
['index' => 'kind', 'label' => __('holidays.columns.kind'), 'sortable' => false],
|
||||
['index' => 'state', 'label' => __('holidays.columns.state'), 'sortable' => false],
|
||||
['index' => 'actions', 'label' => __('holidays.columns.actions'), 'sortable' => false],
|
||||
];
|
||||
}
|
||||
|
||||
public function changeYear(int $step): void
|
||||
{
|
||||
$this->authorize('settings.manage');
|
||||
|
||||
$this->year = max(2000, min(2100, $this->year + ($step < 0 ? -1 : 1)));
|
||||
$this->statusMessage = __('holidays.showing_year', ['year' => $this->year]);
|
||||
unset($this->holidays);
|
||||
}
|
||||
|
||||
public function disable(string $date, HolidayCalendar $calendar): void
|
||||
{
|
||||
$this->change($date, fn () => $calendar->disable($date), 'holidays.disabled');
|
||||
}
|
||||
|
||||
public function enable(string $date, HolidayCalendar $calendar): void
|
||||
{
|
||||
$this->change($date, fn () => $calendar->enable($date), 'holidays.enabled');
|
||||
}
|
||||
|
||||
public function remove(string $date, HolidayCalendar $calendar): void
|
||||
{
|
||||
$this->change($date, fn () => $calendar->removeCompanyDay($date), 'holidays.removed');
|
||||
}
|
||||
|
||||
public function add(HolidayCalendar $calendar): void
|
||||
{
|
||||
$this->authorize('settings.manage');
|
||||
$this->statusMessage = '';
|
||||
|
||||
$this->validate([
|
||||
'date' => ['required', 'date_format:Y-m-d', 'after_or_equal:2000-01-01', 'before_or_equal:2100-12-31'],
|
||||
'name' => ['required', 'string', 'max:100'],
|
||||
], [
|
||||
'date.*' => __('holidays.errors.date'),
|
||||
'name.*' => __('holidays.errors.name'),
|
||||
]);
|
||||
|
||||
try {
|
||||
$calendar->addCompanyDay($this->date, $this->name);
|
||||
} catch (InvalidHolidayName) {
|
||||
$this->addError('name', __('holidays.errors.name'));
|
||||
|
||||
return;
|
||||
} catch (HolidayAlreadyExists) {
|
||||
$this->addError('date', __('holidays.errors.exists'));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->statusMessage = __('holidays.added', ['day' => $this->formatDay($this->date), 'name' => trim($this->name)]);
|
||||
$this->year = (int) substr($this->date, 0, 4);
|
||||
$this->reset('date', 'name');
|
||||
unset($this->holidays);
|
||||
}
|
||||
|
||||
public function render(): mixed
|
||||
{
|
||||
return $this->view()->title(__('holidays.title'));
|
||||
}
|
||||
|
||||
private function change(string $date, \Closure $action, string $messageKey): void
|
||||
{
|
||||
$this->authorize('settings.manage');
|
||||
|
||||
$holiday = collect($this->holidays)->firstWhere('date', $date);
|
||||
|
||||
try {
|
||||
$action();
|
||||
} catch (NotAHoliday|\InvalidArgumentException) {
|
||||
$this->statusMessage = __('holidays.not_changed');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
unset($this->holidays);
|
||||
$this->statusMessage = __($messageKey, ['day' => $this->formatDay($date), 'name' => $holiday['name'] ?? '']);
|
||||
}
|
||||
|
||||
private function holidayName(Holiday $holiday): string
|
||||
{
|
||||
return $holiday->key === null ? (string) $holiday->name : __('holidays.names.'.$holiday->key);
|
||||
}
|
||||
|
||||
private function formatDay(string $date): string
|
||||
{
|
||||
$day = CarbonImmutable::createFromFormat('!Y-m-d', $date);
|
||||
|
||||
return ! $day instanceof CarbonImmutable ? $date :__('holidays.weekdays.'.$day->dayOfWeekIso).' '.$day->format('j.n.Y');
|
||||
}
|
||||
};
|
||||
?>
|
||||
|
||||
<div class="mx-auto max-w-4xl space-y-6 p-4 sm:p-6">
|
||||
<div class="space-y-1">
|
||||
<h1 class="text-2xl font-semibold">{{ __('holidays.title') }}</h1>
|
||||
<p class="text-sm text-zinc-600 dark:text-zinc-300">{{ __('holidays.intro') }}</p>
|
||||
<p class="text-sm"><x-link :href="route('settings.company')" navigate>{{ __('company.title') }}</x-link></p>
|
||||
</div>
|
||||
|
||||
<p role="status" aria-live="polite" class="min-h-5 text-sm font-medium">{{ $statusMessage }}</p>
|
||||
|
||||
<section aria-labelledby="holidays-year-heading" class="space-y-4">
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
<x-button subtle color="black" icon="chevron-left" wire:click="changeYear(-1)" :text="__('holidays.previous_year')" />
|
||||
<h2 id="holidays-year-heading" class="text-lg font-semibold">{{ __('holidays.year_heading', ['year' => $year]) }}</h2>
|
||||
<x-button subtle color="black" icon="chevron-right" position="right" wire:click="changeYear(1)" :text="__('holidays.next_year')" />
|
||||
</div>
|
||||
|
||||
<x-table :headers="$this->headers()" :rows="$this->holidays">
|
||||
@interact('column_day', $holiday)
|
||||
<span class="whitespace-nowrap">{{ $holiday['day'] }}</span>
|
||||
@endinteract
|
||||
|
||||
@interact('column_name', $holiday)
|
||||
<span class="break-words">{{ $holiday['name'] }}</span>
|
||||
@endinteract
|
||||
|
||||
@interact('column_kind', $holiday)
|
||||
{{ $holiday['kind'] }}
|
||||
@endinteract
|
||||
|
||||
@interact('column_state', $holiday)
|
||||
@if ($holiday['active'])
|
||||
<span class="inline-flex items-center gap-1"><x-icon name="check" class="size-4" aria-hidden="true" />{{ __('holidays.in_use') }}</span>
|
||||
@else
|
||||
<span class="inline-flex items-center gap-1"><x-icon name="x-mark" class="size-4" aria-hidden="true" />{{ __('holidays.not_in_use') }}</span>
|
||||
@endif
|
||||
@endinteract
|
||||
|
||||
@interact('column_actions', $holiday)
|
||||
@if ($holiday['company'])
|
||||
<x-button sm subtle color="black" wire:click="remove('{{ $holiday['date'] }}')" :text="__('holidays.remove')" :aria-label="__('holidays.remove_named', ['name' => $holiday['name'], 'day' => $holiday['day']])" />
|
||||
@elseif ($holiday['active'])
|
||||
<x-button sm subtle color="black" wire:click="disable('{{ $holiday['date'] }}')" :text="__('holidays.disable')" :aria-label="__('holidays.disable_named', ['name' => $holiday['name'], 'day' => $holiday['day']])" />
|
||||
@else
|
||||
<x-button sm subtle color="black" wire:click="enable('{{ $holiday['date'] }}')" :text="__('holidays.enable')" :aria-label="__('holidays.enable_named', ['name' => $holiday['name'], 'day' => $holiday['day']])" />
|
||||
@endif
|
||||
@endinteract
|
||||
</x-table>
|
||||
</section>
|
||||
|
||||
<section aria-labelledby="holidays-add-heading" class="space-y-4">
|
||||
<h2 id="holidays-add-heading" class="text-lg font-semibold">{{ __('holidays.add_heading') }}</h2>
|
||||
|
||||
<form wire:submit="add" class="grid gap-4 sm:grid-cols-[12rem_1fr_auto] sm:items-start" novalidate>
|
||||
<x-input wire:model="date" type="date" :label="__('holidays.fields.date')" required />
|
||||
<x-input wire:model="name" :label="__('holidays.fields.name')" :hint="__('holidays.fields.name_hint')" autocomplete="off" required />
|
||||
<div class="sm:pt-6">
|
||||
<x-button submit :text="__('holidays.add')" />
|
||||
</div>
|
||||
</form>
|
||||
</section>
|
||||
</div>
|
||||
@@ -7,4 +7,5 @@ Route::middleware(['web', 'auth', 'can:settings.manage'])
|
||||
->name('settings.')
|
||||
->group(function () {
|
||||
Route::livewire('/company', 'shared::company')->name('company');
|
||||
Route::livewire('/holidays', 'shared::holidays')->name('holidays');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user