- 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]>
188 lines
5.8 KiB
PHP
188 lines
5.8 KiB
PHP
<?php
|
|
|
|
namespace App\Modules\Jobs\Presentation\Livewire\Concerns;
|
|
|
|
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\Domain\Enums\JobStatus;
|
|
use App\Modules\Jobs\Presentation\Livewire\Forms\JobForm;
|
|
use App\Modules\Users\Application\Contracts\UserAccountQueries;
|
|
use App\Modules\Users\Application\DTOs\UserOption;
|
|
use Illuminate\Support\Facades\Gate;
|
|
use Livewire\Attributes\Computed;
|
|
|
|
/**
|
|
* The choices and list editing of a job's details, shared by the job form
|
|
* page and the board's job editor: service units, people, the customer's
|
|
* contacts and billing units, the statuses this user may set, tags and
|
|
* links. The page has a JobForm `$form`, `$jobId`, `$storedStatus`,
|
|
* `$newTag` and (from PicksCustomer) `$statusMessage`.
|
|
*
|
|
* @property JobForm $form
|
|
* @property-read list<UserOption> $users
|
|
* @property-read list<ContactSummary> $contacts
|
|
* @property-read list<BillingUnitSummary> $billingUnits
|
|
* @property-read list<JobStatus> $statusOptions
|
|
*/
|
|
trait EditsJobDetails
|
|
{
|
|
/**
|
|
* @return list<array{value: int, label: string}>
|
|
*/
|
|
#[Computed]
|
|
public function serviceUnitOptions(): array
|
|
{
|
|
$catalog = app(CatalogQueries::class);
|
|
$options = [];
|
|
|
|
foreach ($catalog->activeServiceUnits() as $unit) {
|
|
$options[$unit->id] = ['value' => $unit->id, 'label' => $unit->name];
|
|
}
|
|
|
|
// Units already on the job stay visible after being taken out of use.
|
|
foreach ($this->form->service_unit_ids as $id) {
|
|
if (! isset($options[(int) $id]) && ($unit = $catalog->findServiceUnit((int) $id)) !== null) {
|
|
$options[$unit->id] = ['value' => $unit->id, 'label' => $unit->name, 'note' => __('catalog.inactive')];
|
|
}
|
|
}
|
|
|
|
return array_values($options);
|
|
}
|
|
|
|
/**
|
|
* @return list<UserOption>
|
|
*/
|
|
#[Computed]
|
|
public function users(): array
|
|
{
|
|
return app(UserAccountQueries::class)->activeUserOptions();
|
|
}
|
|
|
|
/**
|
|
* @return list<ContactSummary>
|
|
*/
|
|
#[Computed]
|
|
public function contacts(): array
|
|
{
|
|
return $this->form->customer_id === '' ? [] : app(CustomerQueries::class)->contactsOf((int) $this->form->customer_id);
|
|
}
|
|
|
|
/**
|
|
* @return list<BillingUnitSummary>
|
|
*/
|
|
#[Computed]
|
|
public function billingUnits(): array
|
|
{
|
|
return $this->form->customer_id === '' ? [] : app(CustomerQueries::class)->billingUnitsOf((int) $this->form->customer_id);
|
|
}
|
|
|
|
/**
|
|
* Statuses this user may choose: billing statuses for management and the
|
|
* job's biller, archived for management, and always the stored one.
|
|
*
|
|
* @return list<JobStatus>
|
|
*/
|
|
#[Computed]
|
|
public function statusOptions(): array
|
|
{
|
|
return array_values(array_filter(
|
|
JobStatus::cases(),
|
|
fn (JobStatus $status): bool => $status->value === $this->storedStatus || $this->maySetStatus($status),
|
|
));
|
|
}
|
|
|
|
/**
|
|
* @return list<string>
|
|
*/
|
|
#[Computed]
|
|
public function tagSuggestions(): array
|
|
{
|
|
return array_values(array_diff(app(CustomerJobQueries::class)->tagSuggestions($this->newTag), $this->form->tags));
|
|
}
|
|
|
|
public function addTag(): void
|
|
{
|
|
$tag = trim(preg_replace('/\s+/u', ' ', $this->newTag) ?? '');
|
|
|
|
if ($tag === '' || mb_strlen($tag) > 50) {
|
|
$this->addError('newTag', __('jobs.errors.invalid_tag'));
|
|
|
|
return;
|
|
}
|
|
|
|
$taken = array_map('mb_strtolower', $this->form->tags);
|
|
|
|
if (! in_array(mb_strtolower($tag), $taken, true)) {
|
|
$this->form->tags[] = $tag;
|
|
}
|
|
|
|
$this->newTag = '';
|
|
$this->resetErrorBag('newTag');
|
|
$this->statusMessage = __('jobs.tags.added', ['tag' => $tag]);
|
|
}
|
|
|
|
public function removeTag(int $index): void
|
|
{
|
|
$tag = $this->form->tags[$index] ?? null;
|
|
|
|
if ($tag === null) {
|
|
return;
|
|
}
|
|
|
|
unset($this->form->tags[$index]);
|
|
$this->form->tags = array_values($this->form->tags);
|
|
$this->statusMessage = __('jobs.tags.removed', ['tag' => $tag]);
|
|
|
|
$this->js("document.getElementById('new-tag')?.focus()");
|
|
}
|
|
|
|
public function addLink(): void
|
|
{
|
|
$this->form->links[] = ['title' => '', 'url' => ''];
|
|
$index = count($this->form->links) - 1;
|
|
|
|
$this->js("document.getElementById('link-title-{$index}')?.focus()");
|
|
}
|
|
|
|
public function removeLink(int $index): void
|
|
{
|
|
unset($this->form->links[$index]);
|
|
$this->form->links = array_values($this->form->links);
|
|
|
|
$this->js("document.getElementById('add-link')?.focus()");
|
|
}
|
|
|
|
protected function maySetStatus(JobStatus $status): bool
|
|
{
|
|
$stored = $this->storedStatus === null ? null : JobStatus::tryFrom($this->storedStatus);
|
|
|
|
if ($stored !== null && $stored->unlocksTo($status) && ! Gate::allows('jobs.unlock')) {
|
|
return false;
|
|
}
|
|
|
|
if ($status === JobStatus::Archived) {
|
|
return Gate::allows('jobs.archive');
|
|
}
|
|
|
|
if ($status->isBillingStatus()) {
|
|
$details = $this->jobId === null ? null : app(CustomerJobQueries::class)->findDetails($this->jobId);
|
|
|
|
return Gate::allows('jobs.set-billing-status', [$details?->biller?->id]);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* A contact or billing unit of another customer no longer fits.
|
|
*/
|
|
protected function customerChosen(?int $customerId): void
|
|
{
|
|
$this->form->customer_contact_id = '';
|
|
$this->form->billing_unit_id = '';
|
|
}
|
|
}
|