Phase 1, item 4. New Jobs module: - Customer jobs with the spec's fields except money (phase 2): yearly running numbers (2026-0001) from a locked counter row, service units, schedule, kind, status, priority, payment basis, estimated hours, PO reference, instructions, members (responsible, contact person, customer contact, biller, billing unit, other members), tags shared across jobs, and links. - Every change is recorded field by field and shown on the job page with names and Finnish dates. - References to other modules are checked through their query contracts: contact and billing unit must be the customer's own; service units and users must be in use unless already on the job. - Job list with search, filters and "my jobs" on by default; job form with an accessible customer search and quick add; job page. - Access: subcontractors see only jobs they are members of, read only; billing statuses for management and the job's biller; archiving for management. Related changes: - Customers: one internal customer (created by a migration) for internal work; contacts and billing units used by a job cannot be removed. - Users and Catalog: batch name lookups and active user options with roles for other modules. - <x-checkbox-group> component; spec and CLAUDE.md updated. Co-Authored-By: Claude Opus 5.5 <[email protected]>
191 lines
7.1 KiB
PHP
191 lines
7.1 KiB
PHP
<?php
|
||
|
||
use App\Modules\Catalog\Application\Contracts\CatalogQueries;
|
||
use App\Modules\Jobs\Application\Contracts\CustomerJobQueries;
|
||
use App\Modules\Jobs\Application\DTOs\CustomerJobSummary;
|
||
use App\Modules\Jobs\Application\DTOs\JobListFilter;
|
||
use App\Modules\Jobs\Domain\Enums\JobStatus;
|
||
use App\Modules\Jobs\Domain\Enums\Priority;
|
||
use App\Modules\Users\Domain\Enums\Role;
|
||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||
use Livewire\Attributes\Computed;
|
||
use Livewire\Attributes\Url;
|
||
use Livewire\Component;
|
||
use Livewire\WithPagination;
|
||
|
||
/**
|
||
* The customer job list: search, filters and "my jobs" on by default.
|
||
*/
|
||
new class extends Component
|
||
{
|
||
use WithPagination;
|
||
|
||
#[Url(as: 'q', except: '')]
|
||
public string $search = '';
|
||
|
||
#[Url(except: '')]
|
||
public string $status = '';
|
||
|
||
#[Url(except: '')]
|
||
public string $priority = '';
|
||
|
||
#[Url(as: 'unit', except: '')]
|
||
public string $serviceUnit = '';
|
||
|
||
#[Url(except: true)]
|
||
public bool $mine = true;
|
||
|
||
#[Url(except: false)]
|
||
public bool $archived = false;
|
||
|
||
public function mount(): void
|
||
{
|
||
$this->authorize('jobs.view');
|
||
}
|
||
|
||
public function updated(string $property): void
|
||
{
|
||
if (in_array($property, ['search', 'status', 'priority', 'serviceUnit', 'mine', 'archived'], true)) {
|
||
$this->resetPage();
|
||
}
|
||
}
|
||
|
||
public function isSubcontractor(): bool
|
||
{
|
||
return auth()->user()?->role === Role::Subcontractor;
|
||
}
|
||
|
||
/**
|
||
* @return LengthAwarePaginator<int, CustomerJobSummary>
|
||
*/
|
||
#[Computed]
|
||
public function jobs(): LengthAwarePaginator
|
||
{
|
||
$userId = (int) auth()->id();
|
||
|
||
return app(CustomerJobQueries::class)->paginate(new JobListFilter(
|
||
search: $this->search,
|
||
status: JobStatus::tryFrom($this->status)?->value,
|
||
priority: Priority::tryFrom($this->priority)?->value,
|
||
serviceUnitId: $this->serviceUnit === '' ? null : (int) $this->serviceUnit,
|
||
mineForUserId: $this->mine && ! $this->isSubcontractor() ? $userId : null,
|
||
onlyMemberUserId: $this->isSubcontractor() ? $userId : null,
|
||
includeArchived: $this->archived,
|
||
));
|
||
}
|
||
|
||
/**
|
||
* @return list<array{index: string, label: string, sortable: bool}>
|
||
*/
|
||
public function headers(): array
|
||
{
|
||
return [
|
||
['index' => 'number', 'label' => __('jobs.fields.number'), 'sortable' => false],
|
||
['index' => 'name', 'label' => __('jobs.fields.name'), 'sortable' => false],
|
||
['index' => 'customerName', 'label' => __('jobs.fields.customer'), 'sortable' => false],
|
||
['index' => 'status', 'label' => __('jobs.fields.status'), 'sortable' => false],
|
||
['index' => 'priority', 'label' => __('jobs.fields.priority'), 'sortable' => false],
|
||
['index' => 'dueOn', 'label' => __('jobs.fields.due_on'), 'sortable' => false],
|
||
['index' => 'responsibleName', 'label' => __('jobs.fields.responsible_user'), 'sortable' => false],
|
||
];
|
||
}
|
||
|
||
public function render(): mixed
|
||
{
|
||
return $this->view()->title(__('jobs.title'));
|
||
}
|
||
};
|
||
?>
|
||
|
||
<div class="mx-auto max-w-7xl space-y-6 p-4 sm:p-6">
|
||
<div class="flex flex-wrap items-center justify-between gap-4">
|
||
<h1 class="text-2xl font-semibold">{{ __('jobs.title') }}</h1>
|
||
|
||
@can('jobs.manage')
|
||
<x-button :href="route('jobs.create')" wire:navigate icon="plus" :text="__('jobs.new')" />
|
||
@endcan
|
||
</div>
|
||
|
||
@if (session('status'))
|
||
<x-alert role="status" color="green" light icon="check-circle" :text="session('status')" />
|
||
@endif
|
||
|
||
@if ($this->isSubcontractor())
|
||
<p class="text-sm text-zinc-600 dark:text-zinc-300">{{ __('jobs.list.subcontractor_note') }}</p>
|
||
@endif
|
||
|
||
<div class="grid gap-4 md:grid-cols-2 xl:grid-cols-4">
|
||
<div class="md:col-span-2 xl:col-span-4">
|
||
<x-input
|
||
wire:model.live.debounce.300ms="search"
|
||
type="search"
|
||
icon="magnifying-glass"
|
||
:label="__('jobs.list.search')"
|
||
:hint="__('jobs.list.search_description')"
|
||
/>
|
||
</div>
|
||
|
||
{{-- TallStackUI's native select does not tie its label to the control, so aria-label names it. --}}
|
||
<x-select.native wire:model.live="status" :label="__('jobs.fields.status')" :aria-label="__('jobs.fields.status')">
|
||
<option value="">{{ __('jobs.list.all_statuses') }}</option>
|
||
@foreach (JobStatus::cases() as $option)
|
||
<option value="{{ $option->value }}">{{ __('jobs.statuses.'.$option->value) }}</option>
|
||
@endforeach
|
||
</x-select.native>
|
||
|
||
<x-select.native wire:model.live="priority" :label="__('jobs.fields.priority')" :aria-label="__('jobs.fields.priority')">
|
||
<option value="">{{ __('jobs.list.all_priorities') }}</option>
|
||
@foreach (Priority::cases() as $option)
|
||
<option value="{{ $option->value }}">{{ __('jobs.priorities.'.$option->value) }}</option>
|
||
@endforeach
|
||
</x-select.native>
|
||
|
||
<x-select.native wire:model.live="serviceUnit" :label="__('jobs.fields.service_units')" :aria-label="__('jobs.fields.service_units')">
|
||
<option value="">{{ __('jobs.list.all_service_units') }}</option>
|
||
@foreach (app(CatalogQueries::class)->activeServiceUnits() as $unit)
|
||
<option value="{{ $unit->id }}">{{ $unit->name }}</option>
|
||
@endforeach
|
||
</x-select.native>
|
||
|
||
<div class="space-y-2">
|
||
@unless ($this->isSubcontractor())
|
||
<x-checkbox id="only-mine" wire:model.live="mine" :label="__('jobs.list.only_mine')" />
|
||
@endunless
|
||
<x-checkbox id="include-archived" wire:model.live="archived" :label="__('jobs.list.include_archived')" />
|
||
</div>
|
||
</div>
|
||
|
||
<p role="status" aria-live="polite" aria-atomic="true" class="text-sm text-zinc-600 dark:text-zinc-300">
|
||
{{ trans_choice('jobs.list.result_count', $this->jobs->total(), ['count' => $this->jobs->total()]) }}
|
||
@if ($mine && ! $this->isSubcontractor())
|
||
– {{ __('jobs.list.only_mine_description') }}
|
||
@endif
|
||
</p>
|
||
|
||
@if ($this->jobs->total() === 0)
|
||
<p class="text-sm text-zinc-600 dark:text-zinc-300">{{ __('jobs.list.empty') }}</p>
|
||
@else
|
||
<x-table :headers="$this->headers()" :rows="$this->jobs" paginate>
|
||
@interact('column_number', $job)
|
||
<span class="whitespace-nowrap">{{ $job->number }}</span>
|
||
@endinteract
|
||
|
||
@interact('column_name', $job)
|
||
<x-link :href="route('jobs.show', $job->id)" navigate class="font-medium">{{ $job->name }}</x-link>
|
||
@endinteract
|
||
|
||
@interact('column_status', $job)
|
||
{{ __('jobs.statuses.'.$job->status->value) }}
|
||
@endinteract
|
||
|
||
@interact('column_priority', $job)
|
||
<x-jobs.priority :priority="$job->priority" />
|
||
@endinteract
|
||
|
||
@interact('column_dueOn', $job)
|
||
<x-jobs.due-date :date="$job->dueOn" :status="$job->status" />
|
||
@endinteract
|
||
</x-table>
|
||
@endif
|
||
</div>
|