- Toolbar: whose board (own, a person, a service line, all), pipeline views (daily, sales, full), urgent and late filters with a live count, normal and compact density, and the quick intake button. - Columns side by side with horizontal scrolling on desktop, stacked on phones; each user's own column colours and order, the urgent column's threshold menu, and the continuing jobs column. - Cards in customer colours: job cards with their tasks checked off inside the card (the status select is gone), continuing job cards with the next period, PIN and quick add, and pinned task cards. Dragging moves and orders cards; the keyboard opens the job editor from the card title. - Job editor dialog: every job detail, tasks with checklists and templates, quick hours (TimeTracking) and expenses (Expenses), history. - The quick intake form also adds a contact person, initial status and priority, and opens as a dialog on the board. Co-Authored-By: Claude Opus 5.5 <[email protected]>
391 lines
18 KiB
PHP
391 lines
18 KiB
PHP
<?php
|
|
|
|
use App\Modules\Catalog\Application\Contracts\CatalogQueries;
|
|
use App\Modules\Customers\Application\Contracts\CustomerQueries;
|
|
use App\Modules\Customers\Application\DTOs\BillingUnitSummary;
|
|
use App\Modules\Customers\Application\DTOs\ContactSummary;
|
|
use App\Modules\Jobs\Application\Contracts\CustomerJobQueries;
|
|
use App\Modules\Jobs\Application\DTOs\CustomerJobDetails;
|
|
use App\Modules\Jobs\Application\UseCases\CreateCustomerJob;
|
|
use App\Modules\Jobs\Application\UseCases\UpdateCustomerJob;
|
|
use App\Modules\Jobs\Domain\Enums\JobKind;
|
|
use App\Modules\Jobs\Domain\Enums\JobStatus;
|
|
use App\Modules\Jobs\Domain\Enums\PaymentBasis;
|
|
use App\Modules\Jobs\Domain\Enums\Priority;
|
|
use App\Modules\Jobs\Domain\Exceptions\CustomerJobNotFound;
|
|
use App\Modules\Jobs\Presentation\Livewire\Concerns\EditsJobDetails;
|
|
use App\Modules\Jobs\Presentation\Livewire\Concerns\PicksCustomer;
|
|
use App\Modules\Jobs\Presentation\Livewire\Forms\JobForm;
|
|
use App\Modules\Shared\Domain\Exceptions\DomainException;
|
|
use App\Modules\Users\Application\Contracts\UserAccountQueries;
|
|
use App\Modules\Users\Application\DTOs\UserOption;
|
|
use App\Modules\Users\Domain\Enums\Role;
|
|
use Illuminate\Support\Facades\Gate;
|
|
use Livewire\Attributes\Computed;
|
|
use Livewire\Attributes\Locked;
|
|
use Livewire\Component;
|
|
|
|
/**
|
|
* Create page (no {job}) and edit page (with {job}) of a customer job.
|
|
*/
|
|
new class extends Component
|
|
{
|
|
use EditsJobDetails, PicksCustomer {
|
|
EditsJobDetails::customerChosen insteadof PicksCustomer;
|
|
}
|
|
|
|
#[Locked]
|
|
public ?int $jobId = null;
|
|
|
|
#[Locked]
|
|
public string $jobNumber = '';
|
|
|
|
/**
|
|
* The status stored before this edit: always offered, even when the
|
|
* user could not set it themselves.
|
|
*/
|
|
#[Locked]
|
|
public ?string $storedStatus = null;
|
|
|
|
public JobForm $form;
|
|
|
|
public string $newTag = '';
|
|
|
|
public function mount(CustomerJobQueries $jobQueries, ?int $job = null): void
|
|
{
|
|
$this->authorize('jobs.manage');
|
|
|
|
if ($job === null) {
|
|
$this->form->responsible_user_id = (string) auth()->id();
|
|
|
|
return;
|
|
}
|
|
|
|
$details = $jobQueries->findDetails($job);
|
|
|
|
abort_if($details === null, 404);
|
|
|
|
$this->jobId = $details->id;
|
|
$this->jobNumber = $details->number;
|
|
$this->customerName = $details->customer->name;
|
|
$this->storedStatus = $details->status->value;
|
|
$this->form->fillFromDetails($details);
|
|
}
|
|
|
|
public function save(CreateCustomerJob $createJob, UpdateCustomerJob $updateJob, CustomerJobQueries $jobQueries): void
|
|
{
|
|
$this->authorize('jobs.manage');
|
|
|
|
$status = JobStatus::tryFrom($this->form->status);
|
|
|
|
if ($status !== null && $status->value !== $this->storedStatus && ! $this->maySetStatus($status)) {
|
|
$this->addError('form.status', __('jobs.errors.status_not_allowed'));
|
|
|
|
return;
|
|
}
|
|
|
|
$data = $this->form->toData();
|
|
|
|
try {
|
|
if ($this->jobId === null) {
|
|
$jobId = $createJob->execute($data, (int) auth()->id());
|
|
$number = $jobQueries->findDetails($jobId)->number ?? '';
|
|
session()->flash('status', __('jobs.created', ['number' => $number, 'name' => trim($data->name)]));
|
|
} else {
|
|
$updateJob->execute($this->jobId, $data, (int) auth()->id());
|
|
$jobId = $this->jobId;
|
|
session()->flash('status', __('jobs.updated', ['number' => $this->jobNumber]));
|
|
}
|
|
} catch (CustomerJobNotFound) {
|
|
abort(404);
|
|
} catch (DomainException $exception) {
|
|
$this->form->showDomainError($exception);
|
|
|
|
return;
|
|
}
|
|
|
|
$this->redirectRoute('jobs.show', $jobId, navigate: true);
|
|
}
|
|
|
|
public function heading(): string
|
|
{
|
|
return $this->jobId === null ? __('jobs.create_title') : __('jobs.edit_title').' '.$this->jobNumber;
|
|
}
|
|
|
|
public function render(): mixed
|
|
{
|
|
return $this->view()->title($this->heading());
|
|
}
|
|
};
|
|
?>
|
|
|
|
@php
|
|
$userOptions = collect($this->users)->map(fn ($user) => [
|
|
'value' => $user->id,
|
|
'label' => $user->name,
|
|
'note' => $user->role === Role::Subcontractor ? __('users.roles.subcontractor') : null,
|
|
])->all();
|
|
$staffOptions = collect($this->users)->reject(fn ($user) => $user->role === Role::Subcontractor);
|
|
@endphp
|
|
|
|
<div class="mx-auto max-w-3xl space-y-6 p-4 sm:p-6">
|
|
<x-page-title icon="briefcase">{{ $this->heading() }}</x-page-title>
|
|
|
|
<p role="status" aria-live="polite" class="text-sm">{{ $statusMessage }}</p>
|
|
|
|
<form wire:submit="save" class="card space-y-8" novalidate>
|
|
<fieldset class="space-y-6">
|
|
<legend class="text-lg font-semibold">{{ __('jobs.sections.basics') }}</legend>
|
|
|
|
<x-input wire:model="form.name" :label="__('jobs.fields.name')" autocomplete="off" required />
|
|
|
|
<x-jobs.customer-picker
|
|
:customer-id="$form->customer_id"
|
|
:customer-name="$customerName"
|
|
:search="$customerSearch"
|
|
:results="$this->customerResults"
|
|
/>
|
|
|
|
<x-textarea wire:model="form.description" :label="__('jobs.fields.description')" resize-auto />
|
|
|
|
<x-checkbox-group
|
|
:legend="__('jobs.fields.service_units')"
|
|
model="form.service_unit_ids"
|
|
:options="$this->serviceUnitOptions"
|
|
/>
|
|
</fieldset>
|
|
|
|
<fieldset class="space-y-6">
|
|
<legend class="text-lg font-semibold">{{ __('jobs.sections.schedule') }}</legend>
|
|
|
|
<div class="grid gap-6 sm:grid-cols-2">
|
|
<x-input wire:model="form.starts_on" type="date" :label="__('jobs.fields.starts_on')" />
|
|
<x-input wire:model="form.due_on" type="date" :label="__('jobs.fields.due_on')" />
|
|
<x-input wire:model="form.planned_from" type="date" :label="__('jobs.fields.planned_from')" />
|
|
<x-input wire:model="form.planned_to" type="date" :label="__('jobs.fields.planned_to')" />
|
|
</div>
|
|
</fieldset>
|
|
|
|
<fieldset class="space-y-6">
|
|
<legend class="text-lg font-semibold">{{ __('jobs.sections.classification') }}</legend>
|
|
|
|
<div class="grid gap-6 sm:grid-cols-2">
|
|
{{-- TallStackUI's native select does not tie its label to the control, so aria-label names it. --}}
|
|
<x-select.native wire:model="form.status" :label="__('jobs.fields.status')" :aria-label="__('jobs.fields.status')">
|
|
@foreach ($this->statusOptions as $status)
|
|
<option value="{{ $status->value }}">{{ __('jobs.statuses.'.$status->value) }}</option>
|
|
@endforeach
|
|
</x-select.native>
|
|
|
|
<x-select.native wire:model="form.priority" :label="__('jobs.fields.priority')" :aria-label="__('jobs.fields.priority')">
|
|
@foreach (Priority::cases() as $priority)
|
|
<option value="{{ $priority->value }}">{{ __('jobs.priorities.'.$priority->value) }}</option>
|
|
@endforeach
|
|
</x-select.native>
|
|
|
|
<x-select.native wire:model="form.kind" :label="__('jobs.fields.kind')" :aria-label="__('jobs.fields.kind')">
|
|
@foreach (JobKind::cases() as $kind)
|
|
<option value="{{ $kind->value }}">{{ __('jobs.kinds.'.$kind->value) }}</option>
|
|
@endforeach
|
|
</x-select.native>
|
|
|
|
<x-select.native wire:model.live="form.payment_basis" :label="__('jobs.fields.payment_basis')" :aria-label="__('jobs.fields.payment_basis')">
|
|
<option value="">{{ __('jobs.fields.no_payment_basis') }}</option>
|
|
@foreach (PaymentBasis::cases() as $basis)
|
|
<option value="{{ $basis->value }}">{{ __('jobs.payment_bases.'.$basis->value) }}</option>
|
|
@endforeach
|
|
</x-select.native>
|
|
|
|
<x-input
|
|
wire:model="form.estimated_hours"
|
|
type="number"
|
|
step="0.25"
|
|
min="0"
|
|
inputmode="decimal"
|
|
:label="__('jobs.fields.estimated_hours')"
|
|
:hint="__('jobs.fields.estimated_hours_description')"
|
|
/>
|
|
|
|
@can('money.quotes')
|
|
<x-input
|
|
wire:model="form.quoted_amount"
|
|
inputmode="decimal"
|
|
autocomplete="off"
|
|
:label="__('jobs.fields.quoted_amount_input')"
|
|
:hint="__('jobs.fields.quoted_amount_description')"
|
|
/>
|
|
|
|
@if ($form->payment_basis === 'monthly_fee')
|
|
<x-input
|
|
wire:model="form.monthly_fee"
|
|
inputmode="decimal"
|
|
autocomplete="off"
|
|
:label="__('jobs.fields.monthly_fee_input')"
|
|
:hint="__('jobs.fields.monthly_fee_description')"
|
|
/>
|
|
@endif
|
|
@endcan
|
|
</div>
|
|
</fieldset>
|
|
|
|
<fieldset class="space-y-6">
|
|
<legend class="text-lg font-semibold">{{ __('jobs.sections.members') }}</legend>
|
|
|
|
<div class="grid gap-6 sm:grid-cols-2">
|
|
<x-select.native wire:model="form.responsible_user_id" :label="__('jobs.fields.responsible_user')" :aria-label="__('jobs.fields.responsible_user')" required>
|
|
<option value="">{{ __('jobs.fields.none_selected') }}</option>
|
|
@foreach ($staffOptions as $user)
|
|
<option value="{{ $user->id }}">{{ $user->name }}</option>
|
|
@endforeach
|
|
</x-select.native>
|
|
|
|
<x-select.native wire:model="form.contact_user_id" :label="__('jobs.fields.contact_user')" :aria-label="__('jobs.fields.contact_user')" :hint="__('jobs.fields.contact_user_description')">
|
|
<option value="">{{ __('jobs.fields.none_selected') }}</option>
|
|
@foreach ($staffOptions as $user)
|
|
<option value="{{ $user->id }}">{{ $user->name }}</option>
|
|
@endforeach
|
|
</x-select.native>
|
|
|
|
<x-select.native wire:model="form.biller_user_id" :label="__('jobs.fields.biller_user')" :aria-label="__('jobs.fields.biller_user')" :hint="__('jobs.fields.biller_user_description')">
|
|
<option value="">{{ __('jobs.fields.none_selected') }}</option>
|
|
@foreach ($staffOptions as $user)
|
|
<option value="{{ $user->id }}">{{ $user->name }}</option>
|
|
@endforeach
|
|
</x-select.native>
|
|
|
|
<x-select.native
|
|
wire:model="form.customer_contact_id"
|
|
:label="__('jobs.fields.customer_contact')"
|
|
:aria-label="__('jobs.fields.customer_contact')"
|
|
:hint="$form->customer_id === '' ? __('jobs.customer_picker.choose_customer_first') : null"
|
|
:disabled="$form->customer_id === ''"
|
|
>
|
|
<option value="">{{ __('jobs.fields.none_selected') }}</option>
|
|
@foreach ($this->contacts as $contact)
|
|
<option wire:key="contact-{{ $contact->id }}" value="{{ $contact->id }}">{{ $contact->name }}</option>
|
|
@endforeach
|
|
</x-select.native>
|
|
|
|
<x-select.native
|
|
wire:model="form.billing_unit_id"
|
|
:label="__('jobs.fields.billing_unit')"
|
|
:aria-label="__('jobs.fields.billing_unit')"
|
|
:hint="$form->customer_id === '' ? __('jobs.customer_picker.choose_customer_first') : null"
|
|
:disabled="$form->customer_id === ''"
|
|
>
|
|
<option value="">{{ __('jobs.fields.none_selected') }}</option>
|
|
@foreach ($this->billingUnits as $billingUnit)
|
|
<option wire:key="billing-unit-{{ $billingUnit->id }}" value="{{ $billingUnit->id }}">{{ $billingUnit->name }}</option>
|
|
@endforeach
|
|
</x-select.native>
|
|
</div>
|
|
|
|
<x-checkbox-group
|
|
:legend="__('jobs.fields.members')"
|
|
:hint="__('jobs.fields.members_description')"
|
|
model="form.member_user_ids"
|
|
:options="$userOptions"
|
|
/>
|
|
</fieldset>
|
|
|
|
<fieldset class="space-y-6">
|
|
<legend class="text-lg font-semibold">{{ __('jobs.sections.extra') }}</legend>
|
|
|
|
<x-input wire:model="form.customer_reference" :label="__('jobs.fields.customer_reference')" autocomplete="off" />
|
|
|
|
{{-- Tags: free text with suggestions from earlier tags, added one at a time. --}}
|
|
<div class="space-y-3">
|
|
<div class="flex flex-wrap items-end gap-3">
|
|
<div class="min-w-0 flex-1">
|
|
<x-input
|
|
id="new-tag"
|
|
wire:model.live.debounce.300ms="newTag"
|
|
wire:keydown.enter.prevent="addTag"
|
|
list="tag-suggestions"
|
|
:label="__('jobs.tags.new')"
|
|
:hint="__('jobs.tags.new_description')"
|
|
autocomplete="off"
|
|
/>
|
|
<datalist id="tag-suggestions">
|
|
@foreach ($this->tagSuggestions as $suggestion)
|
|
<option value="{{ $suggestion }}"></option>
|
|
@endforeach
|
|
</datalist>
|
|
</div>
|
|
<x-button wire:click="addTag" subtle color="black" icon="plus" :text="__('jobs.tags.add')" />
|
|
</div>
|
|
|
|
<p id="tags-label" class="text-sm font-semibold text-gray-700 dark:text-dark-300">{{ __('jobs.fields.tags') }}</p>
|
|
@if ($form->tags === [])
|
|
<p class="text-sm text-zinc-600 dark:text-zinc-200">{{ __('jobs.tags.none') }}</p>
|
|
@else
|
|
<ul aria-labelledby="tags-label" class="flex flex-wrap gap-2">
|
|
@foreach ($form->tags as $index => $tag)
|
|
<li wire:key="tag-{{ $tag }}" class="inline-flex items-center gap-1 rounded-full border border-zinc-300 py-1 pr-1 pl-3 text-sm dark:border-zinc-600">
|
|
{{ $tag }}
|
|
<x-button.circle
|
|
wire:click="removeTag({{ $index }})"
|
|
subtle
|
|
color="black"
|
|
xs
|
|
icon="x-mark"
|
|
:aria-label="__('jobs.tags.remove', ['tag' => $tag])"
|
|
/>
|
|
</li>
|
|
@endforeach
|
|
</ul>
|
|
@endif
|
|
@error('form.tags')
|
|
<p class="text-sm text-red-700 dark:text-red-400">{{ $message }}</p>
|
|
@enderror
|
|
</div>
|
|
|
|
{{-- Links: title and address per row. --}}
|
|
<div class="space-y-3">
|
|
<p class="text-sm font-semibold text-gray-700 dark:text-dark-300">{{ __('jobs.fields.links') }}</p>
|
|
|
|
@if ($form->links === [])
|
|
<p class="text-sm text-zinc-600 dark:text-zinc-200">{{ __('jobs.links.none') }}</p>
|
|
@endif
|
|
|
|
@foreach ($form->links as $index => $link)
|
|
<fieldset wire:key="link-{{ $index }}" class="space-y-3 rounded-lg border border-zinc-200 p-3 dark:border-zinc-700">
|
|
<legend class="px-1 text-sm font-medium">{{ __('jobs.links.link_number', ['number' => $index + 1]) }}</legend>
|
|
<div class="grid gap-3 sm:grid-cols-2">
|
|
<x-input id="link-title-{{ $index }}" wire:model="form.links.{{ $index }}.title" :label="__('jobs.links.title')" autocomplete="off" />
|
|
<x-input id="link-url-{{ $index }}" wire:model="form.links.{{ $index }}.url" type="url" :label="__('jobs.links.url')" :hint="__('jobs.links.url_description')" autocomplete="off" />
|
|
</div>
|
|
<x-button
|
|
wire:click="removeLink({{ $index }})"
|
|
subtle
|
|
color="black"
|
|
sm
|
|
icon="trash"
|
|
:text="__('jobs.links.remove', ['number' => $index + 1])"
|
|
/>
|
|
</fieldset>
|
|
@endforeach
|
|
|
|
<x-button id="add-link" wire:click="addLink" subtle color="black" sm icon="plus" :text="__('jobs.links.add')" />
|
|
|
|
@error('form.links')
|
|
<p class="text-sm text-red-700 dark:text-red-400">{{ $message }}</p>
|
|
@enderror
|
|
</div>
|
|
|
|
<x-textarea wire:model="form.instructions" :label="__('jobs.fields.instructions')" :hint="__('jobs.fields.instructions_description')" resize-auto />
|
|
</fieldset>
|
|
|
|
<div class="flex flex-wrap gap-3">
|
|
<x-button submit :text="__('jobs.save')" />
|
|
<x-button
|
|
:href="$jobId === null ? route('jobs.index') : route('jobs.show', $jobId)"
|
|
wire:navigate
|
|
subtle
|
|
color="black"
|
|
:text="__('jobs.cancel')"
|
|
/>
|
|
</div>
|
|
</form>
|
|
</div>
|