Rebuild the Kanban board after the prototype, with the job editor and quick intake dialog
- 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]>
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
<?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\Jobs\Application\Contracts\CustomerJobQueries;
|
||||
use App\Modules\Jobs\Application\DTOs\CustomerJobDetails;
|
||||
use App\Modules\Jobs\Application\DTOs\JobChangeEntry;
|
||||
use App\Modules\Shared\Domain\ValueObjects\Money;
|
||||
use App\Modules\Users\Application\Contracts\UserAccountQueries;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Livewire\Attributes\Computed;
|
||||
|
||||
/**
|
||||
* A job's change history as text, shared by the job page and the board's
|
||||
* job editor. Quote and monthly fee changes are shown only to those who may
|
||||
* see quotes (spec 5.7). The page has `$jobId` and a computed `job`.
|
||||
*
|
||||
* @property-read CustomerJobDetails $job
|
||||
* @property-read list<JobChangeEntry> $changes
|
||||
*/
|
||||
trait DescribesJobHistory
|
||||
{
|
||||
/**
|
||||
* @return list<JobChangeEntry>
|
||||
*/
|
||||
#[Computed]
|
||||
public function changes(): array
|
||||
{
|
||||
$changes = app(CustomerJobQueries::class)->changes($this->jobId);
|
||||
|
||||
return Gate::allows('money.quotes')
|
||||
? $changes
|
||||
: array_values(array_filter($changes, fn (JobChangeEntry $change): bool => ! in_array($change->field, ['quoted_amount', 'monthly_fee'], true)));
|
||||
}
|
||||
|
||||
public function formatDate(?string $date): string
|
||||
{
|
||||
return $date === null ? __('jobs.not_set') : CarbonImmutable::parse($date)->format('j.n.Y');
|
||||
}
|
||||
|
||||
/**
|
||||
* A history value as text: names for ids, labels for enum keys,
|
||||
* Finnish dates and amounts.
|
||||
*/
|
||||
public function historyValue(string $field, ?string $value): string
|
||||
{
|
||||
if ($value === null || $value === '') {
|
||||
return __('jobs.not_set');
|
||||
}
|
||||
|
||||
$ids = array_map('intval', explode(',', $value));
|
||||
$named = fn (array $names): string => implode(', ', array_map(
|
||||
fn (int $id): string => $names[$id] ?? __('jobs.history.unknown', ['id' => $id]),
|
||||
$ids,
|
||||
));
|
||||
|
||||
return match ($field) {
|
||||
'starts_on', 'due_on', 'planned_from', 'planned_to' => $this->formatDate($value),
|
||||
'quoted_amount', 'monthly_fee' => Money::fromCents((int) $value)->format(),
|
||||
'kind' => __('jobs.kinds.'.$value),
|
||||
'status' => __('jobs.statuses.'.$value),
|
||||
'priority' => __('jobs.priorities.'.$value),
|
||||
'payment_basis' => __('jobs.payment_bases.'.$value),
|
||||
'customer' => $named(app(CustomerQueries::class)->namesByIds($ids)),
|
||||
'service_units' => $named(app(CatalogQueries::class)->serviceUnitNames($ids)),
|
||||
'responsible_user', 'contact_user', 'biller_user', 'members' => $named(app(UserAccountQueries::class)->namesByIds($ids)),
|
||||
'customer_contact' => app(CustomerQueries::class)->findContact($this->job->customer->id, $ids[0])->name ?? __('jobs.history.unknown', ['id' => $ids[0]]),
|
||||
'billing_unit' => app(CustomerQueries::class)->findBillingUnit($this->job->customer->id, $ids[0])->name ?? __('jobs.history.unknown', ['id' => $ids[0]]),
|
||||
default => $value,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
<?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 = '';
|
||||
}
|
||||
}
|
||||
@@ -14,8 +14,9 @@ use Illuminate\Validation\Rule;
|
||||
use Livewire\Form;
|
||||
|
||||
/**
|
||||
* Quick job intake on a phone: only what is needed to open a job (spec 6).
|
||||
* Everything else gets the defaults and is filled in later.
|
||||
* Quick job intake on a phone and in the board's dialog: only what is
|
||||
* needed to open a job (docs/ui-kanban-board.md 6). Everything else gets
|
||||
* the defaults and is filled in later.
|
||||
*/
|
||||
class QuickJobForm extends Form
|
||||
{
|
||||
@@ -31,6 +32,27 @@ class QuickJobForm extends Form
|
||||
|
||||
public string $status = JobStatus::Tentative->value;
|
||||
|
||||
public string $priority = Priority::Normal->value;
|
||||
|
||||
public string $customer_contact_id = '';
|
||||
|
||||
/** The intake has a new contact person of the customer to add. */
|
||||
public bool $adding_contact = false;
|
||||
|
||||
public string $new_contact_name = '';
|
||||
|
||||
public string $new_contact_phone = '';
|
||||
|
||||
/**
|
||||
* The statuses a job can start in at intake.
|
||||
*
|
||||
* @return list<JobStatus>
|
||||
*/
|
||||
public static function startStatuses(): array
|
||||
{
|
||||
return [JobStatus::Prospect, JobStatus::Tentative, JobStatus::QuoteRequest, JobStatus::Order, JobStatus::InProduction];
|
||||
}
|
||||
|
||||
public function toData(): CustomerJobData
|
||||
{
|
||||
$this->validate();
|
||||
@@ -42,8 +64,9 @@ class QuickJobForm extends Form
|
||||
responsibleUserId: (int) $this->responsible_user_id,
|
||||
kind: JobKind::OneOff->value,
|
||||
status: $this->status,
|
||||
priority: Priority::Normal->value,
|
||||
priority: $this->priority,
|
||||
description: trim($this->description) === '' ? null : $this->description,
|
||||
customerContactId: $this->customer_contact_id === '' ? null : (int) $this->customer_contact_id,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -52,7 +75,7 @@ class QuickJobForm extends Form
|
||||
*/
|
||||
public function clearForNextJob(): void
|
||||
{
|
||||
$this->reset('customer_id', 'name', 'description', 'service_unit_id');
|
||||
$this->reset('customer_id', 'name', 'description', 'service_unit_id', 'priority', 'customer_contact_id', 'adding_contact', 'new_contact_name', 'new_contact_phone');
|
||||
$this->resetErrorBag();
|
||||
}
|
||||
|
||||
@@ -83,7 +106,11 @@ class QuickJobForm extends Form
|
||||
'description' => ['nullable', 'string', 'max:2000'],
|
||||
'service_unit_id' => ['required', 'integer'],
|
||||
'responsible_user_id' => ['required', 'integer'],
|
||||
'status' => ['required', Rule::in([JobStatus::Tentative->value, JobStatus::Prospect->value])],
|
||||
'status' => ['required', Rule::in(array_map(fn (JobStatus $status): string => $status->value, self::startStatuses()))],
|
||||
'priority' => ['required', Rule::enum(Priority::class)],
|
||||
'customer_contact_id' => ['nullable', 'integer'],
|
||||
'new_contact_name' => [$this->adding_contact ? 'required' : 'nullable', 'string', 'max:255'],
|
||||
'new_contact_phone' => ['nullable', 'string', 'max:50'],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -100,6 +127,10 @@ class QuickJobForm extends Form
|
||||
'service_unit_id.required' => __('jobs.quick.service_unit_required'),
|
||||
'responsible_user_id.required' => __('jobs.errors.responsible_required'),
|
||||
'status.in' => __('jobs.errors.status_not_allowed'),
|
||||
'priority.*' => __('jobs.errors.status_not_allowed'),
|
||||
'new_contact_name.required' => __('jobs.quick.contact_name_required'),
|
||||
'new_contact_name.max' => __('jobs.errors.too_long', ['max' => 255]),
|
||||
'new_contact_phone.max' => __('jobs.errors.too_long', ['max' => 50]),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -13,6 +13,7 @@ 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;
|
||||
@@ -29,7 +30,9 @@ use Livewire\Component;
|
||||
*/
|
||||
new class extends Component
|
||||
{
|
||||
use PicksCustomer;
|
||||
use EditsJobDetails, PicksCustomer {
|
||||
EditsJobDetails::customerChosen insteadof PicksCustomer;
|
||||
}
|
||||
|
||||
#[Locked]
|
||||
public ?int $jobId = null;
|
||||
@@ -69,132 +72,6 @@ new class extends Component
|
||||
$this->form->fillFromDetails($details);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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()");
|
||||
}
|
||||
|
||||
public function save(CreateCustomerJob $createJob, UpdateCustomerJob $updateJob, CustomerJobQueries $jobQueries): void
|
||||
{
|
||||
$this->authorize('jobs.manage');
|
||||
@@ -239,36 +116,6 @@ new class extends Component
|
||||
{
|
||||
return $this->view()->title($this->heading());
|
||||
}
|
||||
|
||||
private 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 = '';
|
||||
}
|
||||
};
|
||||
?>
|
||||
|
||||
|
||||
@@ -0,0 +1,927 @@
|
||||
<?php
|
||||
|
||||
use App\Modules\Catalog\Application\Contracts\WorkflowTemplateQueries;
|
||||
use App\Modules\Catalog\Application\DTOs\WorkflowTemplateDetails;
|
||||
use App\Modules\Jobs\Application\Contracts\CustomerJobQueries;
|
||||
use App\Modules\Jobs\Application\Contracts\LoggedJobHours;
|
||||
use App\Modules\Jobs\Application\Contracts\TaskQueries;
|
||||
use App\Modules\Jobs\Application\DTOs\CustomerJobDetails;
|
||||
use App\Modules\Jobs\Application\DTOs\TaskData;
|
||||
use App\Modules\Jobs\Application\DTOs\TaskSummary;
|
||||
use App\Modules\Jobs\Application\UseCases\AddTask;
|
||||
use App\Modules\Jobs\Application\UseCases\AddTasksFromWorkflowTemplate;
|
||||
use App\Modules\Jobs\Application\UseCases\ChangeJobPriority;
|
||||
use App\Modules\Jobs\Application\UseCases\ChangeJobStatus;
|
||||
use App\Modules\Jobs\Application\UseCases\ChangeTaskStatus;
|
||||
use App\Modules\Jobs\Application\UseCases\PinTaskToBoard;
|
||||
use App\Modules\Jobs\Application\UseCases\UpdateCustomerJob;
|
||||
use App\Modules\Jobs\Application\UseCases\UpdateTask;
|
||||
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\Enums\TaskStatus;
|
||||
use App\Modules\Jobs\Domain\Exceptions\CustomerJobNotFound;
|
||||
use App\Modules\Jobs\Domain\Exceptions\TaskNotFound;
|
||||
use App\Modules\Jobs\Presentation\Livewire\Concerns\DescribesJobHistory;
|
||||
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\Shared\Domain\ValueObjects\HexColor;
|
||||
use App\Modules\Users\Domain\Enums\Role;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Livewire\Attributes\Computed;
|
||||
use Livewire\Attributes\Locked;
|
||||
use Livewire\Attributes\On;
|
||||
use Livewire\Component;
|
||||
|
||||
/**
|
||||
* The board's full job editor (docs/ui-kanban-board.md 5): a two-column
|
||||
* work area in a dialog where every detail of a job can be seen and changed
|
||||
* without leaving the board. Status and priority change at once, task rows
|
||||
* save as they change, and "Tallenna ja sulje" saves the job's details.
|
||||
* Without jobs.manage the editor only shows the job and lets tasks be
|
||||
* marked done.
|
||||
*/
|
||||
new class extends Component
|
||||
{
|
||||
use DescribesJobHistory;
|
||||
use EditsJobDetails, PicksCustomer {
|
||||
EditsJobDetails::customerChosen insteadof PicksCustomer;
|
||||
}
|
||||
|
||||
public const string DIALOG = 'job-editor-dialog';
|
||||
|
||||
#[Locked]
|
||||
public ?int $jobId = null;
|
||||
|
||||
#[Locked]
|
||||
public ?string $storedStatus = null;
|
||||
|
||||
public JobForm $form;
|
||||
|
||||
public string $newTag = '';
|
||||
|
||||
public string $newTaskTitle = '';
|
||||
|
||||
public string $newTaskAssignee = '';
|
||||
|
||||
public bool $newTaskPin = false;
|
||||
|
||||
public string $templateId = '';
|
||||
|
||||
#[On('open-job-editor')]
|
||||
public function open(int $jobId): void
|
||||
{
|
||||
$this->authorize('jobs.view-job', [$jobId]);
|
||||
|
||||
$details = app(CustomerJobQueries::class)->findDetails($jobId);
|
||||
|
||||
if ($details === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->resetErrorBag();
|
||||
$this->reset('newTag', 'newTaskTitle', 'newTaskPin', 'templateId', 'statusMessage', 'customerSearch');
|
||||
$this->jobId = $details->id;
|
||||
$this->loadDetails($details);
|
||||
$this->newTaskAssignee = (string) $details->responsible->id;
|
||||
unset($this->job, $this->tasks, $this->changes, $this->contacts, $this->billingUnits, $this->statusOptions);
|
||||
|
||||
$this->js("document.getElementById('".self::DIALOG."').showModal(); document.getElementById('job-editor-name')?.focus()");
|
||||
}
|
||||
|
||||
#[Computed]
|
||||
public function job(): ?CustomerJobDetails
|
||||
{
|
||||
return $this->jobId === null ? null : app(CustomerJobQueries::class)->findDetails($this->jobId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<TaskSummary>
|
||||
*/
|
||||
#[Computed]
|
||||
public function tasks(): array
|
||||
{
|
||||
return $this->jobId === null ? [] : app(TaskQueries::class)->tasksOf($this->jobId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<WorkflowTemplateDetails>
|
||||
*/
|
||||
#[Computed]
|
||||
public function templates(): array
|
||||
{
|
||||
$job = $this->job;
|
||||
|
||||
return $job === null ? [] : app(WorkflowTemplateQueries::class)->activeFor(array_map(fn ($unit): int => $unit->id, $job->serviceUnits));
|
||||
}
|
||||
|
||||
/**
|
||||
* Pinned state of the job's tasks: TaskSummary does not carry it.
|
||||
*
|
||||
* @return array<int, bool>
|
||||
*/
|
||||
#[Computed]
|
||||
public function pinnedTasks(): array
|
||||
{
|
||||
return $this->jobId === null ? [] : app(TaskQueries::class)->pinnedTaskIds($this->jobId);
|
||||
}
|
||||
|
||||
public function canEdit(): bool
|
||||
{
|
||||
return Gate::allows('jobs.manage');
|
||||
}
|
||||
|
||||
public function loggedHours(): string
|
||||
{
|
||||
$quarters = $this->jobId === null ? 0 : (app(LoggedJobHours::class)->quartersByJobs([$this->jobId])[$this->jobId] ?? 0);
|
||||
|
||||
return str_replace('.', ',', rtrim(rtrim(number_format($quarters / 4, 2, '.', ''), '0'), '.'));
|
||||
}
|
||||
|
||||
public function changeStatus(string $value, ChangeJobStatus $changeStatus): void
|
||||
{
|
||||
$this->authorize('jobs.manage');
|
||||
|
||||
$status = JobStatus::tryFrom($value);
|
||||
$job = $this->job;
|
||||
|
||||
if ($status === null || $job === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($status->value !== $this->storedStatus && ! $this->maySetStatus($status)) {
|
||||
$this->addError('form.status', __('jobs.errors.status_not_allowed'));
|
||||
$this->form->status = (string) $this->storedStatus;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$changeStatus->execute($job->id, $status, (int) auth()->id());
|
||||
} catch (CustomerJobNotFound) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->resetErrorBag('form.status');
|
||||
$this->storedStatus = $status->value;
|
||||
$this->form->status = $status->value;
|
||||
unset($this->job, $this->changes, $this->statusOptions);
|
||||
$this->statusMessage = __('jobs.editor.status_changed', ['number' => $job->number, 'status' => __('jobs.statuses.'.$status->value)]);
|
||||
$this->dispatch('job-saved');
|
||||
}
|
||||
|
||||
public function unlock(ChangeJobStatus $changeStatus): void
|
||||
{
|
||||
$this->authorize('jobs.unlock');
|
||||
|
||||
$this->changeStatus(JobStatus::InProduction->value, $changeStatus);
|
||||
}
|
||||
|
||||
public function changePriority(string $value, ChangeJobPriority $changePriority): void
|
||||
{
|
||||
$this->authorize('jobs.manage');
|
||||
|
||||
$priority = Priority::tryFrom($value);
|
||||
$job = $this->job;
|
||||
|
||||
if ($priority === null || $job === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$changePriority->execute($job->id, $priority, (int) auth()->id());
|
||||
|
||||
$this->form->priority = $priority->value;
|
||||
unset($this->job, $this->changes);
|
||||
$this->statusMessage = __('jobs.editor.priority_changed', ['number' => $job->number, 'priority' => __('jobs.priorities.'.$priority->value)]);
|
||||
$this->dispatch('job-saved');
|
||||
}
|
||||
|
||||
public function setTaskDone(int $taskId, bool $done, ChangeTaskStatus $changeStatus): void
|
||||
{
|
||||
$this->authorize('jobs.update-task-status', [$this->jobId]);
|
||||
|
||||
$task = $this->findTask($taskId);
|
||||
|
||||
if ($task === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$changeStatus->execute((int) $this->jobId, $taskId, $done ? TaskStatus::Done : TaskStatus::InProgress);
|
||||
} catch (TaskNotFound) {
|
||||
return;
|
||||
}
|
||||
|
||||
unset($this->tasks);
|
||||
$this->statusMessage = __($done ? 'jobs.board.task_done' : 'jobs.board.task_reopened', ['task' => $task->title]);
|
||||
$this->dispatch('job-saved');
|
||||
}
|
||||
|
||||
/**
|
||||
* One field of a task row changed: title, status, assignee or due date.
|
||||
*/
|
||||
public function updateTaskField(int $taskId, string $field, string $value, UpdateTask $updateTask): void
|
||||
{
|
||||
$this->authorize('jobs.manage-tasks', [$this->jobId]);
|
||||
|
||||
$task = $this->findTask($taskId);
|
||||
|
||||
if ($task === null || ! in_array($field, ['title', 'status', 'assignee', 'due_on'], true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$data = new TaskData(
|
||||
title: $field === 'title' ? $value : $task->title,
|
||||
workTypeId: $task->workType->id,
|
||||
status: $field === 'status' ? $value : $task->status->value,
|
||||
description: $task->description,
|
||||
dueOn: $field === 'due_on' ? ($value === '' ? null : $value) : $task->dueOn,
|
||||
estimatedHours: $task->estimatedHours,
|
||||
assigneeUserId: $field === 'assignee' ? ($value === '' ? null : (int) $value) : $task->assignee?->id,
|
||||
memberUserIds: array_map(fn ($member): int => $member->id, $task->members),
|
||||
plannedFrom: $task->plannedFrom,
|
||||
plannedTo: $task->plannedTo,
|
||||
);
|
||||
|
||||
try {
|
||||
$updateTask->execute((int) $this->jobId, $taskId, $data, (int) auth()->id());
|
||||
} catch (DomainException) {
|
||||
$this->addError('tasks.'.$taskId, __('jobs.board.not_moved'));
|
||||
unset($this->tasks);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->resetErrorBag('tasks.'.$taskId);
|
||||
unset($this->tasks);
|
||||
$this->statusMessage = __('jobs.editor.task_saved', ['task' => $data->title]);
|
||||
$this->dispatch('job-saved');
|
||||
}
|
||||
|
||||
public function pinTask(int $taskId, bool $pinned, PinTaskToBoard $pin): void
|
||||
{
|
||||
$this->authorize('jobs.manage-tasks', [$this->jobId]);
|
||||
|
||||
$task = $this->findTask($taskId);
|
||||
|
||||
try {
|
||||
$pin->execute((int) $this->jobId, $taskId, $pinned);
|
||||
} catch (DomainException) {
|
||||
return;
|
||||
}
|
||||
|
||||
unset($this->pinnedTasks);
|
||||
$this->statusMessage = __($pinned ? 'jobs.board.task_pinned' : 'jobs.board.task_unpinned', ['task' => $task->title ?? '']);
|
||||
$this->dispatch('job-saved');
|
||||
}
|
||||
|
||||
public function addTask(AddTask $addTask, PinTaskToBoard $pin): void
|
||||
{
|
||||
$this->authorize('jobs.manage-tasks', [$this->jobId]);
|
||||
|
||||
$title = trim($this->newTaskTitle);
|
||||
$workTypeId = $this->firstWorkTypeId();
|
||||
|
||||
if ($title === '') {
|
||||
$this->addError('newTaskTitle', __('jobs.board.task_title_required'));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($workTypeId === null) {
|
||||
$this->addError('newTaskTitle', __('jobs.board.no_work_type'));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$taskId = $addTask->execute((int) $this->jobId, new TaskData(
|
||||
$title,
|
||||
$workTypeId,
|
||||
TaskStatus::Waiting->value,
|
||||
assigneeUserId: $this->newTaskAssignee === '' ? null : (int) $this->newTaskAssignee,
|
||||
), (int) auth()->id());
|
||||
|
||||
if ($this->newTaskPin && $this->job?->status === JobStatus::Ongoing) {
|
||||
$pin->execute((int) $this->jobId, $taskId, true);
|
||||
}
|
||||
} catch (DomainException) {
|
||||
$this->addError('newTaskTitle', __('jobs.board.not_moved'));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->reset('newTaskTitle', 'newTaskPin');
|
||||
unset($this->tasks, $this->pinnedTasks);
|
||||
$this->statusMessage = __('jobs.editor.task_added', ['task' => $title]);
|
||||
$this->dispatch('job-saved');
|
||||
$this->js("document.getElementById('job-editor-new-task')?.focus()");
|
||||
}
|
||||
|
||||
public function applyTemplate(AddTasksFromWorkflowTemplate $addFromTemplate): void
|
||||
{
|
||||
$this->authorize('jobs.manage-tasks', [$this->jobId]);
|
||||
|
||||
if ($this->templateId === '') {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$result = $addFromTemplate->execute((int) $this->jobId, (int) $this->templateId, (int) auth()->id(), [], true);
|
||||
} catch (DomainException) {
|
||||
$this->addError('templateId', __('jobs.board.not_moved'));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->templateId = '';
|
||||
unset($this->tasks);
|
||||
$count = $result->added;
|
||||
$this->statusMessage = trans_choice('jobs.editor.template_added', $count, ['count' => $count]);
|
||||
$this->dispatch('job-saved');
|
||||
}
|
||||
|
||||
public function save(UpdateCustomerJob $updateJob): void
|
||||
{
|
||||
$this->authorize('jobs.manage');
|
||||
|
||||
$job = $this->job;
|
||||
|
||||
if ($job === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Status and priority are saved by their own controls in the header.
|
||||
$this->form->status = $job->status->value;
|
||||
$this->form->priority = $job->priority->value;
|
||||
|
||||
try {
|
||||
$updateJob->execute($job->id, $this->form->toData(), (int) auth()->id());
|
||||
} catch (CustomerJobNotFound) {
|
||||
return;
|
||||
} catch (DomainException $exception) {
|
||||
$this->form->showDomainError($exception);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->dispatch('job-saved');
|
||||
$this->js("document.getElementById('".self::DIALOG."').close()");
|
||||
$this->statusMessage = __('jobs.editor.saved', ['number' => $job->number]);
|
||||
$this->dispatch('job-editor-saved', message: $this->statusMessage);
|
||||
}
|
||||
|
||||
public function render(): mixed
|
||||
{
|
||||
return $this->view();
|
||||
}
|
||||
|
||||
private function loadDetails(CustomerJobDetails $details): void
|
||||
{
|
||||
$this->storedStatus = $details->status->value;
|
||||
$this->customerName = $details->customer->name;
|
||||
$this->form->reset();
|
||||
$this->form->fillFromDetails($details);
|
||||
}
|
||||
|
||||
private function findTask(int $taskId): ?TaskSummary
|
||||
{
|
||||
foreach ($this->tasks as $task) {
|
||||
if ($task->id === $taskId) {
|
||||
return $task;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function firstWorkTypeId(): ?int
|
||||
{
|
||||
$job = $this->job;
|
||||
|
||||
if ($job === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$unitIds = array_map(fn ($unit): int => $unit->id, $job->serviceUnits);
|
||||
$shared = null;
|
||||
|
||||
foreach (app(\App\Modules\Catalog\Application\Contracts\CatalogQueries::class)->activeWorkTypesFor($unitIds) as $node) {
|
||||
$workTypes = [...$node->workTypes, ...array_merge([], ...array_map(fn ($service): array => $service->workTypes, $node->services))];
|
||||
$first = $workTypes[0]->id ?? null;
|
||||
|
||||
if ($first === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (in_array($node->serviceUnit->id, $unitIds, true)) {
|
||||
return $first;
|
||||
}
|
||||
|
||||
$shared ??= $first;
|
||||
}
|
||||
|
||||
return $shared;
|
||||
}
|
||||
};
|
||||
?>
|
||||
|
||||
@php
|
||||
$job = $this->job;
|
||||
$canEdit = $this->canEdit();
|
||||
$staff = collect($this->users)->reject(fn ($user) => $user->role === Role::Subcontractor);
|
||||
$headerColor = new HexColor($job?->customer->id !== null ? (app(\App\Modules\Customers\Application\Contracts\CustomerQueries::class)->headerColorsByIds([$job->customer->id])[$job->customer->id] ?? '#23476a') : '#23476a');
|
||||
$fieldClass = 'w-full rounded-lg border border-neutral-400 bg-white px-2.5 py-1.5 text-xs text-neutral-900 focus-visible:outline-2 focus-visible:outline-primary-600 dark:border-[#6b7079] dark:bg-[#24262a] dark:text-white dark:focus-visible:outline-primary-300';
|
||||
$labelClass = 'mb-1 block text-[11px] font-semibold text-neutral-800 dark:text-neutral-100';
|
||||
$boxClass = 'space-y-2.5 rounded-xl border border-neutral-200 bg-neutral-100 p-3.5 dark:border-[#36393f] dark:bg-[#18191b]';
|
||||
$boxHeading = 'text-[10px] font-extrabold tracking-wider text-neutral-700 uppercase dark:text-neutral-200';
|
||||
@endphp
|
||||
|
||||
<div>
|
||||
<x-work-dialog id="job-editor-dialog" width="max-w-5xl">
|
||||
<x-slot:header>
|
||||
<div
|
||||
style="background-color: {{ $headerColor->value }}; color: {{ $headerColor->textColor() }}"
|
||||
class="flex shrink-0 flex-wrap items-center justify-between gap-3 rounded-t-2xl border-b border-black/15 px-5 py-3"
|
||||
>
|
||||
<div class="flex min-w-0 flex-1 flex-wrap items-center gap-2.5">
|
||||
<span class="shrink-0 rounded bg-black/25 px-2 py-0.5 text-xs font-extrabold tracking-wider text-white uppercase">{{ $job?->number }}</span>
|
||||
<h2 id="job-editor-dialog-title" class="min-w-0 truncate text-sm font-extrabold">
|
||||
<span class="sr-only">{{ __('jobs.editor.heading', ['number' => $job?->number]) }}: </span>{{ $job?->customer->name }}
|
||||
</h2>
|
||||
@if ($job !== null && Gate::allows('customers.use'))
|
||||
<button
|
||||
type="button"
|
||||
x-on:click="$dispatch('color-picker:open', {{ Js::from([
|
||||
'id' => 'colour-picker',
|
||||
'title' => __('jobs.board.customer_color_title', ['customer' => $job->customer->name]),
|
||||
'color' => $headerColor->value,
|
||||
'method' => 'setCustomerColor',
|
||||
'args' => [$job->customer->id],
|
||||
'resettable' => true,
|
||||
]) }})"
|
||||
aria-label="{{ __('jobs.editor.color_label', ['customer' => $job->customer->name]) }}"
|
||||
class="inline-flex min-h-6 items-center gap-1 rounded bg-black/20 px-2 text-[11px] font-semibold transition hover:bg-black/30 focus-visible:outline-2 focus-visible:outline-current"
|
||||
>
|
||||
<x-icon name="swatch" class="size-3.5" aria-hidden="true" />
|
||||
<span>{{ __('jobs.editor.color') }}</span>
|
||||
</button>
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<div class="flex shrink-0 flex-wrap items-center gap-2">
|
||||
@if ($job !== null)
|
||||
<div class="flex items-center gap-1 rounded-lg bg-black/20 px-2 py-1">
|
||||
<label for="job-editor-status" class="text-[11px] font-bold">{{ __('jobs.editor.status') }}:</label>
|
||||
<select
|
||||
id="job-editor-status"
|
||||
wire:model="form.status"
|
||||
wire:change="changeStatus($event.target.value)"
|
||||
@disabled(! $canEdit)
|
||||
class="rounded border-0 bg-transparent py-0 pr-7 pl-1 text-xs font-extrabold focus-visible:outline-2 focus-visible:outline-current"
|
||||
>
|
||||
@foreach ($this->statusOptions as $status)
|
||||
<option value="{{ $status->value }}" class="bg-white text-neutral-900 dark:bg-[#282a2e] dark:text-white">{{ __('jobs.statuses.'.$status->value) }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
<div class="flex items-center gap-1 rounded-lg bg-black/20 px-2 py-1">
|
||||
<label for="job-editor-priority" class="text-[11px] font-bold">{{ __('jobs.editor.priority') }}:</label>
|
||||
<select
|
||||
id="job-editor-priority"
|
||||
wire:model="form.priority"
|
||||
wire:change="changePriority($event.target.value)"
|
||||
@disabled(! $canEdit)
|
||||
class="rounded border-0 bg-transparent py-0 pr-7 pl-1 text-xs font-extrabold focus-visible:outline-2 focus-visible:outline-current"
|
||||
>
|
||||
@foreach (Priority::cases() as $priority)
|
||||
<option value="{{ $priority->value }}" class="bg-white text-neutral-900 dark:bg-[#282a2e] dark:text-white">{{ __('jobs.priorities.'.$priority->value) }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
@endif
|
||||
<button
|
||||
type="button"
|
||||
x-on:click="$el.closest('dialog').close()"
|
||||
aria-label="{{ __('jobs.editor.close') }}"
|
||||
class="inline-flex size-8 items-center justify-center rounded-lg bg-black/20 transition hover:bg-black/35 focus-visible:outline-2 focus-visible:outline-current"
|
||||
>
|
||||
<x-icon name="x-mark" class="size-4" aria-hidden="true" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</x-slot:header>
|
||||
|
||||
@if ($job !== null)
|
||||
@error('form.status')
|
||||
<p role="alert" class="border-b border-red-300 bg-red-50 px-5 py-2 text-xs font-semibold text-red-800 dark:border-red-800 dark:bg-red-950 dark:text-red-100">{{ $message }}</p>
|
||||
@enderror
|
||||
|
||||
@if (in_array($job->status, [JobStatus::Done, JobStatus::Invoiced, JobStatus::Billed], true))
|
||||
<div role="status" class="flex flex-wrap items-center justify-between gap-2 border-b border-amber-300 bg-amber-100 px-5 py-2 text-xs font-semibold text-amber-950 dark:border-amber-800 dark:bg-amber-950/90 dark:text-amber-100">
|
||||
<span class="inline-flex items-center gap-1.5"><x-icon name="lock-closed" class="size-4" aria-hidden="true" />{{ __('jobs.editor.locked') }}</span>
|
||||
@can('jobs.unlock')
|
||||
<button type="button" wire:click="unlock" class="min-h-6 rounded bg-amber-800 px-2.5 text-[11px] font-bold text-white hover:bg-amber-900 focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-amber-900 dark:focus-visible:outline-amber-200">{{ __('jobs.editor.unlock') }}</button>
|
||||
@endcan
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<p role="status" aria-live="polite" class="min-h-4 px-5 pt-2 text-xs font-medium">{{ $statusMessage }}</p>
|
||||
@unless ($canEdit)
|
||||
<p class="px-5 text-xs">{{ __('jobs.editor.read_only') }}</p>
|
||||
@endunless
|
||||
|
||||
<div class="grid grid-cols-1 gap-5 p-5 lg:grid-cols-12">
|
||||
{{-- Left: content, tasks and records --}}
|
||||
<div class="space-y-5 lg:col-span-8">
|
||||
<fieldset @disabled(! $canEdit) class="space-y-3">
|
||||
<div>
|
||||
<label for="job-editor-name" class="{{ $labelClass }}">{{ __('jobs.fields.name') }}</label>
|
||||
<input id="job-editor-name" type="text" wire:model="form.name" maxlength="255" autocomplete="off" class="w-full rounded-xl border border-neutral-300 bg-neutral-100/70 px-3 py-2 text-base font-extrabold text-neutral-900 focus-visible:outline-2 focus-visible:outline-primary-600 dark:border-[#4b5058] dark:bg-[#18191b] dark:text-white dark:focus-visible:outline-primary-300" />
|
||||
@error('form.name') <p class="mt-1 text-xs font-semibold text-red-700 dark:text-red-200">{{ $message }}</p> @enderror
|
||||
</div>
|
||||
<div class="grid grid-cols-1 gap-3 md:grid-cols-2">
|
||||
<div>
|
||||
<label for="job-editor-description" class="{{ $labelClass }}">{{ __('jobs.fields.description') }}</label>
|
||||
<textarea id="job-editor-description" rows="3" wire:model="form.description" class="{{ $fieldClass }} bg-neutral-50 p-2.5 dark:bg-[#18191b]"></textarea>
|
||||
</div>
|
||||
<div>
|
||||
<label for="job-editor-instructions" class="{{ $labelClass }}">{{ __('jobs.fields.instructions') }}</label>
|
||||
<textarea id="job-editor-instructions" rows="3" wire:model="form.instructions" class="{{ $fieldClass }} bg-amber-50/40 p-2.5 dark:bg-[#1e1d19]"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
<section aria-labelledby="job-editor-links-heading" class="{{ $boxClass }} bg-neutral-50">
|
||||
<div class="flex items-center justify-between">
|
||||
<h3 id="job-editor-links-heading" class="{{ $boxHeading }}">{{ __('jobs.editor.links') }}</h3>
|
||||
@if ($canEdit)
|
||||
<button type="button" id="add-link" wire:click="addLink" class="min-h-6 text-xs font-bold text-primary-700 hover:underline focus-visible:outline-2 focus-visible:outline-primary-600 dark:text-primary-100 dark:focus-visible:outline-primary-300">+ {{ __('jobs.links.add') }}</button>
|
||||
@endif
|
||||
</div>
|
||||
@if ($form->links === [])
|
||||
<p class="text-[11px]">{{ __('jobs.links.none') }}</p>
|
||||
@endif
|
||||
<ul class="space-y-1.5">
|
||||
@foreach ($form->links as $index => $link)
|
||||
<li wire:key="editor-link-{{ $index }}" class="grid grid-cols-1 gap-2 rounded-lg border border-neutral-200 bg-white p-2 sm:grid-cols-12 dark:border-[#36393f] dark:bg-[#25272b]">
|
||||
@if ($canEdit)
|
||||
<div class="sm:col-span-5">
|
||||
<label for="link-title-{{ $index }}" class="sr-only">{{ __('jobs.links.title') }}</label>
|
||||
<input id="link-title-{{ $index }}" wire:model="form.links.{{ $index }}.title" placeholder="{{ __('jobs.links.title') }}" class="{{ $fieldClass }}" />
|
||||
</div>
|
||||
<div class="sm:col-span-5">
|
||||
<label for="link-url-{{ $index }}" class="sr-only">{{ __('jobs.links.url') }}</label>
|
||||
<input id="link-url-{{ $index }}" type="url" wire:model="form.links.{{ $index }}.url" placeholder="https://…" class="{{ $fieldClass }}" />
|
||||
</div>
|
||||
<button type="button" wire:click="removeLink({{ $index }})" aria-label="{{ __('jobs.links.remove', ['number' => $index + 1]) }}" class="min-h-6 rounded text-xs font-bold text-red-700 hover:underline focus-visible:outline-2 focus-visible:outline-primary-600 sm:col-span-2 dark:text-red-200 dark:focus-visible:outline-primary-300">✕</button>
|
||||
@else
|
||||
<a href="{{ $link['url'] }}" target="_blank" rel="noopener" class="font-semibold text-primary-700 hover:underline sm:col-span-12 dark:text-primary-100">{{ $link['title'] }} <span class="sr-only">({{ __('layout.opens_in_new_window') }})</span></a>
|
||||
@endif
|
||||
</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
@error('form.links') <p class="text-xs font-semibold text-red-700 dark:text-red-200">{{ $message }}</p> @enderror
|
||||
</section>
|
||||
|
||||
{{-- Tasks --}}
|
||||
<section aria-labelledby="job-editor-tasks-heading" class="{{ $boxClass }} bg-neutral-50">
|
||||
<div class="flex flex-wrap items-center justify-between gap-2">
|
||||
<div>
|
||||
<h3 id="job-editor-tasks-heading" class="{{ $boxHeading }}">{{ $job->status === JobStatus::Ongoing ? __('jobs.editor.tasks_ongoing') : __('jobs.editor.tasks') }}</h3>
|
||||
<p class="text-[11px]">{{ $job->status === JobStatus::Ongoing ? __('jobs.editor.tasks_hint_ongoing') : __('jobs.editor.tasks_hint') }}</p>
|
||||
</div>
|
||||
@if (Gate::allows('jobs.manage-tasks', [$job->id]) && $this->templates !== [] && $job->status->allowsTasks())
|
||||
<form wire:submit="applyTemplate" class="flex items-center gap-1.5">
|
||||
<label for="job-editor-template" class="sr-only">{{ __('jobs.editor.template') }}</label>
|
||||
<select id="job-editor-template" wire:model="templateId" class="{{ $fieldClass }} w-auto py-1 text-[11px]">
|
||||
<option value="">{{ __('jobs.editor.template_choose') }}</option>
|
||||
@foreach ($this->templates as $template)
|
||||
<option value="{{ $template->id }}">{{ $template->name }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
<button type="submit" class="min-h-6 rounded-lg bg-indigo-700 px-2.5 text-[11px] font-bold text-white hover:bg-indigo-800 focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-primary-600 dark:focus-visible:outline-primary-300">{{ __('jobs.editor.template_apply') }}</button>
|
||||
</form>
|
||||
@endif
|
||||
</div>
|
||||
|
||||
@if ($this->tasks === [])
|
||||
<p class="text-[11px]">{{ __('jobs.editor.no_tasks') }}</p>
|
||||
@endif
|
||||
|
||||
<ul class="space-y-2">
|
||||
@foreach ($this->tasks as $task)
|
||||
@php($canManageTask = Gate::allows('jobs.manage-tasks', [$job->id]))
|
||||
<li wire:key="editor-task-{{ $task->id }}" x-data="{ checklist: false }" class="space-y-2 rounded-xl border border-neutral-200 bg-white p-2.5 text-xs dark:border-[#36393f] dark:bg-[#25272b]">
|
||||
<div class="flex flex-wrap items-center justify-between gap-2">
|
||||
<div class="flex min-w-0 flex-1 items-center gap-2">
|
||||
<input
|
||||
type="checkbox"
|
||||
id="editor-task-done-{{ $task->id }}"
|
||||
@checked($task->status === TaskStatus::Done)
|
||||
@disabled(! Gate::allows('jobs.update-task-status', [$job->id]))
|
||||
wire:change="setTaskDone({{ $task->id }}, $event.target.checked)"
|
||||
aria-label="{{ __('jobs.editor.task_done', ['task' => $task->title]) }}"
|
||||
class="size-4 rounded border-neutral-500 text-emerald-700 dark:border-neutral-400 dark:bg-[#16171a]"
|
||||
/>
|
||||
@if ($canManageTask)
|
||||
<label for="editor-task-title-{{ $task->id }}" class="sr-only">{{ __('jobs.editor.task_title') }}</label>
|
||||
<input
|
||||
id="editor-task-title-{{ $task->id }}"
|
||||
type="text"
|
||||
value="{{ $task->title }}"
|
||||
maxlength="255"
|
||||
wire:change="updateTaskField({{ $task->id }}, 'title', $event.target.value)"
|
||||
class="min-w-0 flex-1 rounded border border-transparent bg-transparent px-1 py-0.5 font-bold text-neutral-900 hover:border-neutral-300 focus-visible:outline-2 focus-visible:outline-primary-600 dark:text-white dark:hover:border-[#4b5058] dark:focus-visible:outline-primary-300"
|
||||
/>
|
||||
@else
|
||||
<span class="font-bold">{{ $task->title }}</span>
|
||||
@endif
|
||||
</div>
|
||||
|
||||
@if ($canManageTask)
|
||||
<div class="flex flex-wrap items-center gap-1.5">
|
||||
<label for="editor-task-status-{{ $task->id }}" class="sr-only">{{ __('jobs.editor.task_status', ['task' => $task->title]) }}</label>
|
||||
<select id="editor-task-status-{{ $task->id }}" wire:change="updateTaskField({{ $task->id }}, 'status', $event.target.value)" class="{{ $fieldClass }} w-auto py-0.5 text-[11px]">
|
||||
@foreach (TaskStatus::cases() as $taskStatus)
|
||||
<option value="{{ $taskStatus->value }}" @selected($taskStatus === $task->status)>{{ __('jobs.tasks.statuses.'.$taskStatus->value) }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
<label for="editor-task-assignee-{{ $task->id }}" class="sr-only">{{ __('jobs.editor.task_assignee', ['task' => $task->title]) }}</label>
|
||||
<select id="editor-task-assignee-{{ $task->id }}" wire:change="updateTaskField({{ $task->id }}, 'assignee', $event.target.value)" class="{{ $fieldClass }} w-auto py-0.5 text-[11px]">
|
||||
<option value="">{{ __('jobs.editor.no_assignee') }}</option>
|
||||
@foreach ($this->users as $user)
|
||||
<option value="{{ $user->id }}" @selected($user->id === $task->assignee?->id)>{{ $user->name }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
<label for="editor-task-due-{{ $task->id }}" class="sr-only">{{ __('jobs.editor.task_due', ['task' => $task->title]) }}</label>
|
||||
<input id="editor-task-due-{{ $task->id }}" type="date" value="{{ $task->dueOn }}" wire:change="updateTaskField({{ $task->id }}, 'due_on', $event.target.value)" class="{{ $fieldClass }} w-auto py-0.5 text-[11px]" />
|
||||
@if ($job->status === JobStatus::Ongoing)
|
||||
@php($pinned = $this->pinnedTasks[$task->id] ?? false)
|
||||
<button
|
||||
type="button"
|
||||
wire:click="pinTask({{ $task->id }}, {{ $pinned ? 'false' : 'true' }})"
|
||||
aria-label="{{ $pinned ? __('jobs.board.unpin_label', ['task' => $task->title]) : __('jobs.board.pin_label', ['task' => $task->title]) }}"
|
||||
@class(['min-h-6 rounded px-2.5 text-[11px] font-bold text-white transition focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-primary-600 dark:focus-visible:outline-primary-300', 'bg-amber-700 hover:bg-amber-800' => $pinned, 'bg-indigo-600 hover:bg-indigo-700' => ! $pinned])
|
||||
>{{ $pinned ? __('jobs.board.unpin') : __('jobs.board.pin') }}</button>
|
||||
@endif
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
@error('tasks.'.$task->id) <p class="text-xs font-semibold text-red-700 dark:text-red-200">{{ $message }}</p> @enderror
|
||||
|
||||
<div class="pl-6">
|
||||
<button
|
||||
type="button"
|
||||
x-on:click="checklist = ! checklist"
|
||||
x-bind:aria-expanded="checklist.toString()"
|
||||
aria-controls="editor-checklist-{{ $task->id }}"
|
||||
class="inline-flex min-h-6 items-center gap-1 rounded text-[11px] font-semibold text-indigo-800 hover:underline focus-visible:outline-2 focus-visible:outline-primary-600 dark:text-indigo-100 dark:focus-visible:outline-primary-300"
|
||||
>
|
||||
<x-icon name="chevron-right" class="size-3 transition" x-bind:class="checklist && 'rotate-90'" aria-hidden="true" />
|
||||
{{ __('jobs.editor.checklist') }}
|
||||
</button>
|
||||
<div id="editor-checklist-{{ $task->id }}" x-show="checklist" x-cloak class="pt-1">
|
||||
<livewire:jobs::task-checklist :job-id="$job->id" :task-id="$task->id" :task-title="$task->title" :wire:key="'editor-checklist-'.$task->id" />
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
|
||||
@if (Gate::allows('jobs.manage-tasks', [$job->id]) && $job->status->allowsTasks())
|
||||
<form wire:submit="addTask" class="space-y-2 border-t border-neutral-200 pt-2 dark:border-[#36393f]">
|
||||
<div class="flex flex-wrap gap-2">
|
||||
<label for="job-editor-new-task" class="sr-only">{{ __('jobs.editor.new_task') }}</label>
|
||||
<input id="job-editor-new-task" type="text" wire:model="newTaskTitle" maxlength="255" placeholder="{{ __('jobs.editor.new_task_placeholder') }}" class="{{ $fieldClass }} min-w-[200px] flex-1 placeholder:text-neutral-600 dark:placeholder:text-neutral-300" />
|
||||
<label for="job-editor-new-task-assignee" class="sr-only">{{ __('jobs.editor.new_task_assignee') }}</label>
|
||||
<select id="job-editor-new-task-assignee" wire:model="newTaskAssignee" class="{{ $fieldClass }} w-auto">
|
||||
<option value="">{{ __('jobs.editor.no_assignee') }}</option>
|
||||
@foreach ($this->users as $user)
|
||||
<option value="{{ $user->id }}">{{ $user->name }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
<button type="submit" class="min-h-6 rounded-lg bg-primary-600 px-3.5 text-xs font-bold text-white hover:bg-primary-700 focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-primary-600 dark:focus-visible:outline-primary-300">+ {{ __('jobs.editor.add_task') }}</button>
|
||||
</div>
|
||||
@error('newTaskTitle') <p class="text-xs font-semibold text-red-700 dark:text-red-200">{{ $message }}</p> @enderror
|
||||
@if ($job->status === JobStatus::Ongoing)
|
||||
<label class="flex cursor-pointer items-center gap-2 text-xs">
|
||||
<input type="checkbox" wire:model="newTaskPin" class="size-4 rounded border-neutral-500 text-indigo-600 dark:border-neutral-400 dark:bg-[#16171a]" />
|
||||
<span>{{ __('jobs.editor.pin_new') }}</span>
|
||||
</label>
|
||||
@endif
|
||||
</form>
|
||||
@endif
|
||||
</section>
|
||||
|
||||
{{-- Records: hours, expenses, history --}}
|
||||
<div class="rounded-xl border border-neutral-200 bg-neutral-50 p-3.5 dark:border-[#36393f] dark:bg-[#1b1c1f]">
|
||||
<x-tabs
|
||||
id="job-editor-tabs-{{ $job->id }}"
|
||||
wire:key="job-editor-tabs-{{ $job->id }}"
|
||||
:label="__('jobs.editor.tabs_label')"
|
||||
:tabs="[
|
||||
'hours' => __('jobs.editor.tab_hours', ['hours' => $this->loggedHours()]),
|
||||
'expenses' => __('jobs.editor.tab_expenses'),
|
||||
'history' => __('jobs.editor.tab_history', ['count' => count($this->changes)]),
|
||||
]"
|
||||
>
|
||||
<x-tabs.panel tabs-id="job-editor-tabs-{{ $job->id }}" name="hours">
|
||||
<livewire:time::job-quick-hours :job-id="$job->id" :wire:key="'editor-hours-'.$job->id" />
|
||||
</x-tabs.panel>
|
||||
<x-tabs.panel tabs-id="job-editor-tabs-{{ $job->id }}" name="expenses">
|
||||
<livewire:expenses::job-quick-expense :job-id="$job->id" :wire:key="'editor-expenses-'.$job->id" />
|
||||
</x-tabs.panel>
|
||||
<x-tabs.panel tabs-id="job-editor-tabs-{{ $job->id }}" name="history">
|
||||
@if ($this->changes === [])
|
||||
<p class="text-xs">{{ __('jobs.history.empty') }}</p>
|
||||
@else
|
||||
<ol class="max-h-48 space-y-1.5 overflow-y-auto text-[11px]" tabindex="0" aria-label="{{ __('jobs.sections.history') }}">
|
||||
@foreach ($this->changes as $change)
|
||||
<li class="flex flex-wrap items-center justify-between gap-2 border-b border-neutral-200 py-1 dark:border-[#2e3137]">
|
||||
<span>
|
||||
<strong>{{ $change->userName }}</strong>:
|
||||
@if ($change->field === 'created')
|
||||
{{ __('jobs.history.created', ['user' => $change->userName, 'number' => $change->newValue]) }}
|
||||
@else
|
||||
{{ __('jobs.history.changed', [
|
||||
'field' => __('jobs.fields.'.$change->field),
|
||||
'old' => $this->historyValue($change->field, $change->oldValue),
|
||||
'new' => $this->historyValue($change->field, $change->newValue),
|
||||
]) }}
|
||||
@endif
|
||||
</span>
|
||||
<span class="shrink-0">{{ CarbonImmutable::parse($change->changedAt)->format('j.n.Y H.i') }}</span>
|
||||
</li>
|
||||
@endforeach
|
||||
</ol>
|
||||
@endif
|
||||
</x-tabs.panel>
|
||||
</x-tabs>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{-- Right: metadata, schedule, team and money --}}
|
||||
<fieldset @disabled(! $canEdit) class="space-y-4 text-xs lg:col-span-4">
|
||||
<legend class="sr-only">{{ __('jobs.sections.basics') }}</legend>
|
||||
|
||||
<section aria-labelledby="job-editor-customer-heading" class="{{ $boxClass }}">
|
||||
<h3 id="job-editor-customer-heading" class="{{ $boxHeading }}">{{ __('jobs.editor.customer_section') }}</h3>
|
||||
<x-jobs.customer-picker :customer-id="$form->customer_id" :customer-name="$customerName" :search="$customerSearch" :results="$this->customerResults" />
|
||||
<div>
|
||||
<label for="job-editor-contact" class="{{ $labelClass }}">{{ __('jobs.fields.customer_contact') }}</label>
|
||||
<select id="job-editor-contact" wire:model="form.customer_contact_id" class="{{ $fieldClass }}">
|
||||
<option value="">{{ __('jobs.fields.none_selected') }}</option>
|
||||
@foreach ($this->contacts as $contact)
|
||||
<option wire:key="editor-contact-{{ $contact->id }}" value="{{ $contact->id }}">{{ $contact->name }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label for="job-editor-billing-unit" class="{{ $labelClass }}">{{ __('jobs.fields.billing_unit') }}</label>
|
||||
<select id="job-editor-billing-unit" wire:model="form.billing_unit_id" class="{{ $fieldClass }}">
|
||||
<option value="">{{ __('jobs.fields.none_selected') }}</option>
|
||||
@foreach ($this->billingUnits as $unit)
|
||||
<option wire:key="editor-billing-unit-{{ $unit->id }}" value="{{ $unit->id }}">{{ $unit->name }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section aria-labelledby="job-editor-team-heading" class="{{ $boxClass }}">
|
||||
<h3 id="job-editor-team-heading" class="{{ $boxHeading }}">{{ __('jobs.editor.team_section') }}</h3>
|
||||
@foreach (['responsible_user_id' => 'responsible_user', 'contact_user_id' => 'contact_user', 'biller_user_id' => 'biller_user'] as $field => $label)
|
||||
<div>
|
||||
<label for="job-editor-{{ $field }}" class="{{ $labelClass }}">{{ __('jobs.fields.'.$label) }}</label>
|
||||
<select id="job-editor-{{ $field }}" wire:model="form.{{ $field }}" class="{{ $fieldClass }}">
|
||||
@if ($field !== 'responsible_user_id')
|
||||
<option value="">{{ __('jobs.fields.none_selected') }}</option>
|
||||
@endif
|
||||
@foreach ($staff as $user)
|
||||
<option value="{{ $user->id }}">{{ $user->name }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
@error('form.'.$field) <p class="mt-1 text-xs font-semibold text-red-700 dark:text-red-200">{{ $message }}</p> @enderror
|
||||
</div>
|
||||
@endforeach
|
||||
<x-checkbox-group
|
||||
:legend="__('jobs.fields.members')"
|
||||
model="form.member_user_ids"
|
||||
:options="collect($this->users)->map(fn ($user) => ['value' => $user->id, 'label' => $user->name, 'note' => $user->role === Role::Subcontractor ? __('users.roles.subcontractor') : null])->all()"
|
||||
/>
|
||||
</section>
|
||||
|
||||
<section aria-labelledby="job-editor-units-heading" class="{{ $boxClass }}">
|
||||
<h3 id="job-editor-units-heading" class="{{ $boxHeading }}">{{ __('jobs.editor.units_section') }}</h3>
|
||||
<x-checkbox-group :legend="__('jobs.fields.service_units')" model="form.service_unit_ids" :options="$this->serviceUnitOptions" />
|
||||
<div class="space-y-1.5">
|
||||
<p id="editor-tags-label" class="{{ $labelClass }}">{{ __('jobs.fields.tags') }}</p>
|
||||
@if ($form->tags !== [])
|
||||
<ul aria-labelledby="editor-tags-label" class="flex flex-wrap gap-1">
|
||||
@foreach ($form->tags as $index => $tag)
|
||||
<li wire:key="editor-tag-{{ $tag }}" class="inline-flex items-center gap-1 rounded-full border border-indigo-300 bg-indigo-100 px-2 py-0.5 text-[11px] font-bold text-indigo-900 dark:border-indigo-700 dark:bg-indigo-950 dark:text-indigo-100">
|
||||
{{ $tag }}
|
||||
@if ($canEdit)
|
||||
<button type="button" wire:click="removeTag({{ $index }})" aria-label="{{ __('jobs.tags.remove', ['tag' => $tag]) }}" class="inline-flex size-5 items-center justify-center rounded-full hover:bg-indigo-200 focus-visible:outline-2 focus-visible:outline-primary-600 dark:hover:bg-indigo-900 dark:focus-visible:outline-primary-300">×</button>
|
||||
@endif
|
||||
</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
@endif
|
||||
@if ($canEdit)
|
||||
<div class="flex gap-1">
|
||||
<label for="new-tag" class="sr-only">{{ __('jobs.tags.new') }}</label>
|
||||
<input id="new-tag" type="text" list="editor-tag-suggestions" wire:model.live.debounce.300ms="newTag" wire:keydown.enter.prevent="addTag" autocomplete="off" placeholder="{{ __('jobs.tags.new') }}" class="{{ $fieldClass }} placeholder:text-neutral-600 dark:placeholder:text-neutral-300" />
|
||||
<datalist id="editor-tag-suggestions">
|
||||
@foreach ($this->tagSuggestions as $suggestion)
|
||||
<option value="{{ $suggestion }}"></option>
|
||||
@endforeach
|
||||
</datalist>
|
||||
<button type="button" wire:click="addTag" class="min-h-6 rounded-lg bg-neutral-700 px-2 text-[11px] font-bold text-white hover:bg-neutral-800 focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-primary-600 dark:focus-visible:outline-primary-300">{{ __('jobs.tags.add') }}</button>
|
||||
</div>
|
||||
@error('newTag') <p class="text-xs font-semibold text-red-700 dark:text-red-200">{{ $message }}</p> @enderror
|
||||
@endif
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section aria-labelledby="job-editor-schedule-heading" class="{{ $boxClass }}">
|
||||
<h3 id="job-editor-schedule-heading" class="{{ $boxHeading }}">{{ __('jobs.editor.schedule_section') }}</h3>
|
||||
<div>
|
||||
<label for="job-editor-kind" class="{{ $labelClass }}">{{ __('jobs.fields.kind') }}</label>
|
||||
<select id="job-editor-kind" wire:model="form.kind" class="{{ $fieldClass }}">
|
||||
@foreach (JobKind::cases() as $kind)
|
||||
<option value="{{ $kind->value }}">{{ __('jobs.kinds.'.$kind->value) }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
<div class="grid grid-cols-2 gap-2">
|
||||
@foreach (['starts_on', 'due_on', 'planned_from', 'planned_to'] as $field)
|
||||
<div>
|
||||
<label for="job-editor-{{ $field }}" class="{{ $labelClass }}">{{ __('jobs.fields.'.$field) }}</label>
|
||||
<input id="job-editor-{{ $field }}" type="date" wire:model="form.{{ $field }}" class="{{ $fieldClass }}" />
|
||||
@error('form.'.$field) <p class="mt-1 text-xs font-semibold text-red-700 dark:text-red-200">{{ $message }}</p> @enderror
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
<div>
|
||||
<label for="job-editor-estimated-hours" class="{{ $labelClass }}">{{ __('jobs.fields.estimated_hours') }}</label>
|
||||
<input id="job-editor-estimated-hours" type="number" step="0.25" min="0" inputmode="decimal" wire:model="form.estimated_hours" class="{{ $fieldClass }}" />
|
||||
@error('form.estimated_hours') <p class="mt-1 text-xs font-semibold text-red-700 dark:text-red-200">{{ $message }}</p> @enderror
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section aria-labelledby="job-editor-money-heading" class="{{ $boxClass }}">
|
||||
<h3 id="job-editor-money-heading" class="{{ $boxHeading }}">{{ __('jobs.editor.money_section') }}</h3>
|
||||
<div>
|
||||
<label for="job-editor-payment-basis" class="{{ $labelClass }}">{{ __('jobs.fields.payment_basis') }}</label>
|
||||
<select id="job-editor-payment-basis" wire:model.live="form.payment_basis" class="{{ $fieldClass }}">
|
||||
<option value="">{{ __('jobs.fields.no_payment_basis') }}</option>
|
||||
@foreach (PaymentBasis::cases() as $basis)
|
||||
<option value="{{ $basis->value }}">{{ __('jobs.payment_bases.'.$basis->value) }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
@can('money.quotes')
|
||||
<div class="grid grid-cols-2 gap-2">
|
||||
<div>
|
||||
<label for="job-editor-quoted" class="{{ $labelClass }}">{{ __('jobs.fields.quoted_amount_input') }}</label>
|
||||
<input id="job-editor-quoted" inputmode="decimal" autocomplete="off" wire:model="form.quoted_amount" class="{{ $fieldClass }}" />
|
||||
@error('form.quoted_amount') <p class="mt-1 text-xs font-semibold text-red-700 dark:text-red-200">{{ $message }}</p> @enderror
|
||||
</div>
|
||||
@if ($form->payment_basis === 'monthly_fee')
|
||||
<div>
|
||||
<label for="job-editor-monthly-fee" class="{{ $labelClass }}">{{ __('jobs.fields.monthly_fee_input') }}</label>
|
||||
<input id="job-editor-monthly-fee" inputmode="decimal" autocomplete="off" wire:model="form.monthly_fee" class="{{ $fieldClass }}" />
|
||||
@error('form.monthly_fee') <p class="mt-1 text-xs font-semibold text-red-700 dark:text-red-200">{{ $message }}</p> @enderror
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
@else
|
||||
<p class="rounded bg-neutral-200/70 p-2 text-[11px] dark:bg-[#24262a]">{{ __('jobs.editor.money_hidden') }}</p>
|
||||
@endcan
|
||||
<div>
|
||||
<label for="job-editor-reference" class="{{ $labelClass }}">{{ __('jobs.fields.customer_reference') }}</label>
|
||||
<input id="job-editor-reference" autocomplete="off" wire:model="form.customer_reference" class="{{ $fieldClass }}" />
|
||||
</div>
|
||||
</section>
|
||||
</fieldset>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<x-slot:footer>
|
||||
<span class="text-[11px]">{{ __('jobs.editor.footer') }}</span>
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
@if ($job !== null)
|
||||
<x-link :href="route('jobs.show', $job->id)" navigate class="text-xs">{{ __('jobs.editor.open_page') }}</x-link>
|
||||
@endif
|
||||
@if ($job !== null && $canEdit)
|
||||
<x-button wire:click="save" sm :text="__('jobs.editor.save')" />
|
||||
@endif
|
||||
</div>
|
||||
</x-slot:footer>
|
||||
</x-work-dialog>
|
||||
</div>
|
||||
@@ -2,9 +2,13 @@
|
||||
|
||||
use App\Modules\Catalog\Application\Contracts\CatalogQueries;
|
||||
use App\Modules\Catalog\Application\DTOs\ServiceUnitSummary;
|
||||
use App\Modules\Customers\Application\Contracts\CustomerQueries;
|
||||
use App\Modules\Customers\Application\DTOs\ContactData;
|
||||
use App\Modules\Customers\Application\DTOs\ContactSummary;
|
||||
use App\Modules\Customers\Application\UseCases\AddContact;
|
||||
use App\Modules\Jobs\Application\Contracts\CustomerJobQueries;
|
||||
use App\Modules\Jobs\Application\UseCases\CreateCustomerJob;
|
||||
use App\Modules\Jobs\Domain\Enums\JobStatus;
|
||||
use App\Modules\Jobs\Domain\Enums\Priority;
|
||||
use App\Modules\Jobs\Presentation\Livewire\Concerns\PicksCustomer;
|
||||
use App\Modules\Jobs\Presentation\Livewire\Forms\QuickJobForm;
|
||||
use App\Modules\Shared\Domain\Exceptions\DomainException;
|
||||
@@ -16,16 +20,25 @@ use Livewire\Attributes\Locked;
|
||||
use Livewire\Component;
|
||||
|
||||
/**
|
||||
* Quick job intake (pikavastaanotto), made for phones: customer, name,
|
||||
* short description, service unit and responsible person. The page stays
|
||||
* open for the next job and links to the one just created.
|
||||
* Quick job intake (pikavastaanotto, docs/ui-kanban-board.md 6), made for
|
||||
* phones and also opened as a dialog on the Kanban board: customer and its
|
||||
* contact person (with a quick add), name, short description, service
|
||||
* unit, responsible person, initial status and priority. The page stays
|
||||
* open for the next job and links to the one just created; the dialog
|
||||
* closes and the board shows the new card.
|
||||
*/
|
||||
new class extends Component
|
||||
{
|
||||
use PicksCustomer;
|
||||
|
||||
public const string DIALOG = 'quick-intake-dialog';
|
||||
|
||||
public QuickJobForm $form;
|
||||
|
||||
/** Embedded in the board's dialog instead of being the page. */
|
||||
#[Locked]
|
||||
public bool $inDialog = false;
|
||||
|
||||
/**
|
||||
* The job created last on this page, shown with links to it.
|
||||
*/
|
||||
@@ -38,10 +51,11 @@ new class extends Component
|
||||
#[Locked]
|
||||
public string $createdNumber = '';
|
||||
|
||||
public function mount(): void
|
||||
public function mount(bool $inDialog = false): void
|
||||
{
|
||||
$this->authorize('jobs.manage');
|
||||
|
||||
$this->inDialog = $inDialog;
|
||||
$this->form->responsible_user_id = (string) auth()->id();
|
||||
}
|
||||
|
||||
@@ -68,10 +82,40 @@ new class extends Component
|
||||
));
|
||||
}
|
||||
|
||||
public function save(CreateCustomerJob $createJob, CustomerJobQueries $jobQueries): void
|
||||
/**
|
||||
* @return list<ContactSummary>
|
||||
*/
|
||||
#[Computed]
|
||||
public function contacts(): array
|
||||
{
|
||||
return $this->form->customer_id === '' ? [] : app(CustomerQueries::class)->contactsOf((int) $this->form->customer_id);
|
||||
}
|
||||
|
||||
public function save(CreateCustomerJob $createJob, CustomerJobQueries $jobQueries, AddContact $addContact): void
|
||||
{
|
||||
$this->authorize('jobs.manage');
|
||||
|
||||
$this->form->validate();
|
||||
|
||||
if ($this->form->adding_contact && trim($this->form->new_contact_name) !== '') {
|
||||
$this->authorize('customers.use');
|
||||
|
||||
try {
|
||||
$contactId = $addContact->execute((int) $this->form->customer_id, new ContactData(
|
||||
name: trim($this->form->new_contact_name),
|
||||
phone: trim($this->form->new_contact_phone) === '' ? null : trim($this->form->new_contact_phone),
|
||||
));
|
||||
} catch (DomainException) {
|
||||
$this->addError('form.new_contact_name', __('jobs.quick.contact_name_required'));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->form->customer_contact_id = (string) $contactId;
|
||||
$this->form->adding_contact = false;
|
||||
unset($this->contacts);
|
||||
}
|
||||
|
||||
$data = $this->form->toData();
|
||||
|
||||
try {
|
||||
@@ -90,6 +134,15 @@ new class extends Component
|
||||
$this->customerName = '';
|
||||
$this->customerSearch = '';
|
||||
$this->statusMessage = '';
|
||||
unset($this->contacts);
|
||||
|
||||
if ($this->inDialog) {
|
||||
$this->dispatch('quick-job-created', status: $data->status);
|
||||
$this->dispatch('job-editor-saved', message: $this->createdMessage);
|
||||
$this->js("document.getElementById('".self::DIALOG."').close()");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->js("document.getElementById('quick-created')?.focus()");
|
||||
}
|
||||
@@ -98,33 +151,44 @@ new class extends Component
|
||||
{
|
||||
return $this->view()->title(__('jobs.quick.title'));
|
||||
}
|
||||
|
||||
/**
|
||||
* A contact person of another customer no longer fits.
|
||||
*/
|
||||
protected function customerChosen(?int $customerId): void
|
||||
{
|
||||
$this->form->customer_contact_id = '';
|
||||
unset($this->contacts);
|
||||
}
|
||||
};
|
||||
?>
|
||||
|
||||
<div class="mx-auto max-w-lg space-y-6 p-4 sm:p-6">
|
||||
<div class="space-y-1">
|
||||
<x-page-title icon="bolt">{{ __('jobs.quick.title') }}</x-page-title>
|
||||
<p class="text-sm text-zinc-600 dark:text-zinc-200">{{ __('jobs.quick.intro') }}</p>
|
||||
</div>
|
||||
<div @class(['mx-auto max-w-lg space-y-6 p-4 sm:p-6' => ! $inDialog])>
|
||||
@unless ($inDialog)
|
||||
<div class="space-y-1">
|
||||
<x-page-title icon="bolt">{{ __('jobs.quick.title') }}</x-page-title>
|
||||
<p class="text-sm text-zinc-600 dark:text-zinc-200">{{ __('jobs.quick.intro') }}</p>
|
||||
</div>
|
||||
|
||||
<div id="quick-created" tabindex="-1" role="status" aria-live="polite" class="focus:outline-none">
|
||||
@if ($createdJobId !== null)
|
||||
<div class="space-y-2 rounded-lg border border-green-700 bg-green-50 p-4 text-sm text-green-900 dark:border-green-500 dark:bg-green-950 dark:text-green-100">
|
||||
<p class="flex items-start gap-2 font-medium">
|
||||
<x-icon name="check-circle" class="size-5 shrink-0" aria-hidden="true" />
|
||||
{{ $createdMessage }}
|
||||
</p>
|
||||
<p class="flex flex-wrap gap-x-4 gap-y-1">
|
||||
<x-link :href="route('jobs.show', $createdJobId)" navigate>{{ __('jobs.quick.open', ['number' => $createdNumber]) }}</x-link>
|
||||
<x-link :href="route('jobs.edit', $createdJobId)" navigate>{{ __('jobs.quick.complete') }}</x-link>
|
||||
</p>
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
<div id="quick-created" tabindex="-1" role="status" aria-live="polite" class="focus:outline-none">
|
||||
@if ($createdJobId !== null)
|
||||
<div class="space-y-2 rounded-lg border border-green-700 bg-green-50 p-4 text-sm text-green-900 dark:border-green-500 dark:bg-green-950 dark:text-green-100">
|
||||
<p class="flex items-start gap-2 font-medium">
|
||||
<x-icon name="check-circle" class="size-5 shrink-0" aria-hidden="true" />
|
||||
{{ $createdMessage }}
|
||||
</p>
|
||||
<p class="flex flex-wrap gap-x-4 gap-y-1">
|
||||
<x-link :href="route('jobs.show', $createdJobId)" navigate>{{ __('jobs.quick.open', ['number' => $createdNumber]) }}</x-link>
|
||||
<x-link :href="route('jobs.edit', $createdJobId)" navigate>{{ __('jobs.quick.complete') }}</x-link>
|
||||
</p>
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
@endunless
|
||||
|
||||
<p role="status" aria-live="polite" class="text-sm">{{ $statusMessage }}</p>
|
||||
<p role="status" aria-live="polite" @class(['text-sm', 'px-5 pt-3' => $inDialog])>{{ $statusMessage }}</p>
|
||||
|
||||
<form wire:submit="save" class="card space-y-6" novalidate>
|
||||
<form wire:submit="save" @class(['card space-y-6' => ! $inDialog, 'space-y-4 px-5 pb-5' => $inDialog]) novalidate>
|
||||
<x-jobs.customer-picker
|
||||
:customer-id="$form->customer_id"
|
||||
:customer-name="$customerName"
|
||||
@@ -132,34 +196,83 @@ new class extends Component
|
||||
:results="$this->customerResults"
|
||||
/>
|
||||
|
||||
<x-input wire:model="form.name" :label="__('jobs.fields.name')" autocomplete="off" required />
|
||||
<div class="space-y-2">
|
||||
<div class="flex flex-wrap items-end justify-between gap-2">
|
||||
<div class="min-w-0 flex-1">
|
||||
<x-select.native
|
||||
id="{{ $inDialog ? 'dialog-' : '' }}quick-contact"
|
||||
wire:model="form.customer_contact_id"
|
||||
:label="__('jobs.quick.contact')"
|
||||
:aria-label="__('jobs.quick.contact')"
|
||||
:disabled="$form->customer_id === ''"
|
||||
:hint="$form->customer_id === '' ? __('jobs.customer_picker.choose_customer_first') : null"
|
||||
>
|
||||
<option value="">{{ __('jobs.fields.none_selected') }}</option>
|
||||
@foreach ($this->contacts as $contact)
|
||||
<option wire:key="quick-contact-{{ $contact->id }}" value="{{ $contact->id }}">{{ $contact->name }}</option>
|
||||
@endforeach
|
||||
</x-select.native>
|
||||
</div>
|
||||
@if ($form->customer_id !== '')
|
||||
<x-button
|
||||
wire:click="$toggle('form.adding_contact')"
|
||||
subtle
|
||||
color="black"
|
||||
sm
|
||||
:text="__('jobs.quick.add_contact')"
|
||||
:aria-label="__('jobs.quick.add_contact_label')"
|
||||
x-bind:aria-expanded="$wire.form.adding_contact.toString()"
|
||||
/>
|
||||
@endif
|
||||
</div>
|
||||
@if ($form->adding_contact && $form->customer_id !== '')
|
||||
<div class="grid gap-3 rounded-lg border border-indigo-400 bg-indigo-50/40 p-3 sm:grid-cols-2 dark:border-indigo-500 dark:bg-[#1e2026]">
|
||||
<x-input id="{{ $inDialog ? 'dialog-' : '' }}quick-contact-name" wire:model="form.new_contact_name" :label="__('jobs.quick.contact_name')" autocomplete="off" required />
|
||||
<x-input id="{{ $inDialog ? 'dialog-' : '' }}quick-contact-phone" wire:model="form.new_contact_phone" type="tel" :label="__('jobs.quick.contact_phone')" autocomplete="off" />
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<x-textarea wire:model="form.description" :label="__('jobs.quick.description')" rows="3" />
|
||||
<x-input id="{{ $inDialog ? 'dialog-' : '' }}quick-name" wire:model="form.name" :label="__('jobs.fields.name')" autocomplete="off" required />
|
||||
|
||||
{{-- TallStackUI's native select does not tie its label to the control, so aria-label names it. --}}
|
||||
<x-select.native wire:model="form.service_unit_id" :label="__('jobs.quick.service_unit')" :aria-label="__('jobs.quick.service_unit')" required>
|
||||
<option value="">{{ __('jobs.fields.none_selected') }}</option>
|
||||
@foreach ($this->serviceUnits as $unit)
|
||||
<option value="{{ $unit->id }}">{{ $unit->name }}</option>
|
||||
@endforeach
|
||||
</x-select.native>
|
||||
<x-textarea id="{{ $inDialog ? 'dialog-' : '' }}quick-description" wire:model="form.description" :label="__('jobs.quick.description')" rows="3" />
|
||||
|
||||
<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 ($this->staff as $user)
|
||||
<option value="{{ $user->id }}">{{ $user->name }}</option>
|
||||
@endforeach
|
||||
</x-select.native>
|
||||
<div class="grid gap-4 sm:grid-cols-2">
|
||||
{{-- TallStackUI's native select does not tie its label to the control, so aria-label names it. --}}
|
||||
<x-select.native id="{{ $inDialog ? 'dialog-' : '' }}quick-service-unit" wire:model="form.service_unit_id" :label="__('jobs.quick.service_unit')" :aria-label="__('jobs.quick.service_unit')" required>
|
||||
<option value="">{{ __('jobs.fields.none_selected') }}</option>
|
||||
@foreach ($this->serviceUnits as $unit)
|
||||
<option value="{{ $unit->id }}">{{ $unit->name }}</option>
|
||||
@endforeach
|
||||
</x-select.native>
|
||||
|
||||
<x-radio.group
|
||||
wire:model="form.status"
|
||||
:label="__('jobs.fields.status')"
|
||||
:options="[
|
||||
['label' => __('jobs.statuses.'.JobStatus::Tentative->value), 'value' => JobStatus::Tentative->value],
|
||||
['label' => __('jobs.statuses.'.JobStatus::Prospect->value), 'value' => JobStatus::Prospect->value],
|
||||
]"
|
||||
/>
|
||||
<x-select.native id="{{ $inDialog ? 'dialog-' : '' }}quick-responsible" 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 ($this->staff as $user)
|
||||
<option value="{{ $user->id }}">{{ $user->name }}</option>
|
||||
@endforeach
|
||||
</x-select.native>
|
||||
|
||||
<x-button submit lg class="w-full" :text="__('jobs.quick.save')" />
|
||||
<x-select.native id="{{ $inDialog ? 'dialog-' : '' }}quick-status" wire:model="form.status" :label="__('jobs.quick.start_status')" :aria-label="__('jobs.quick.start_status')">
|
||||
@foreach (QuickJobForm::startStatuses() as $status)
|
||||
<option value="{{ $status->value }}">{{ __('jobs.statuses.'.$status->value) }}</option>
|
||||
@endforeach
|
||||
</x-select.native>
|
||||
|
||||
<x-select.native id="{{ $inDialog ? 'dialog-' : '' }}quick-priority" 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>
|
||||
</div>
|
||||
|
||||
@if ($inDialog)
|
||||
<div class="flex justify-end gap-2 border-t border-neutral-200 pt-3 dark:border-[#36393f]">
|
||||
<x-button subtle color="black" :text="__('layout.cancel')" x-on:click="$el.closest('dialog').close()" />
|
||||
<x-button submit :text="__('jobs.quick.save')" />
|
||||
</div>
|
||||
@else
|
||||
<x-button submit lg class="w-full" :text="__('jobs.quick.save')" />
|
||||
@endif
|
||||
</form>
|
||||
</div>
|
||||
|
||||
@@ -19,6 +19,7 @@ use App\Modules\Shared\Domain\ValueObjects\Money;
|
||||
use Livewire\Attributes\Computed;
|
||||
use Livewire\Attributes\Locked;
|
||||
use Livewire\Attributes\On;
|
||||
use App\Modules\Jobs\Presentation\Livewire\Concerns\DescribesJobHistory;
|
||||
use Livewire\Component;
|
||||
|
||||
/**
|
||||
@@ -26,6 +27,8 @@ use Livewire\Component;
|
||||
*/
|
||||
new class extends Component
|
||||
{
|
||||
use DescribesJobHistory;
|
||||
|
||||
#[Locked]
|
||||
public int $jobId;
|
||||
|
||||
@@ -57,20 +60,6 @@ new class extends Component
|
||||
return app(CustomerJobQueries::class)->findDetails($this->jobId) ?? abort(404);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<JobChangeEntry>
|
||||
*/
|
||||
#[Computed]
|
||||
public function changes(): array
|
||||
{
|
||||
$changes = app(CustomerJobQueries::class)->changes($this->jobId);
|
||||
|
||||
// Changes of the quoted amount are shown only to those who may see quotes (spec 5.7).
|
||||
return Gate::allows('money.quotes')
|
||||
? $changes
|
||||
: array_values(array_filter($changes, fn (JobChangeEntry $change): bool => ! in_array($change->field, ['quoted_amount', 'monthly_fee'], true)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<TaskSummary>
|
||||
*/
|
||||
@@ -159,43 +148,6 @@ new class extends Component
|
||||
$this->js("document.getElementById('remove-task-dialog').close(); document.getElementById('tasks-heading').focus()");
|
||||
}
|
||||
|
||||
public function formatDate(?string $date): string
|
||||
{
|
||||
return $date === null ? __('jobs.not_set') : CarbonImmutable::parse($date)->format('j.n.Y');
|
||||
}
|
||||
|
||||
/**
|
||||
* A history value as text: names for ids, labels for enum keys,
|
||||
* Finnish dates.
|
||||
*/
|
||||
public function historyValue(string $field, ?string $value): string
|
||||
{
|
||||
if ($value === null || $value === '') {
|
||||
return __('jobs.not_set');
|
||||
}
|
||||
|
||||
$ids = array_map('intval', explode(',', $value));
|
||||
$named = fn (array $names): string => implode(', ', array_map(
|
||||
fn (int $id): string => $names[$id] ?? __('jobs.history.unknown', ['id' => $id]),
|
||||
$ids,
|
||||
));
|
||||
|
||||
return match ($field) {
|
||||
'starts_on', 'due_on', 'planned_from', 'planned_to' => $this->formatDate($value),
|
||||
'quoted_amount', 'monthly_fee' => Money::fromCents((int) $value)->format(),
|
||||
'kind' => __('jobs.kinds.'.$value),
|
||||
'status' => __('jobs.statuses.'.$value),
|
||||
'priority' => __('jobs.priorities.'.$value),
|
||||
'payment_basis' => __('jobs.payment_bases.'.$value),
|
||||
'customer' => $named(app(CustomerQueries::class)->namesByIds($ids)),
|
||||
'service_units' => $named(app(CatalogQueries::class)->serviceUnitNames($ids)),
|
||||
'responsible_user', 'contact_user', 'biller_user', 'members' => $named(app(UserAccountQueries::class)->namesByIds($ids)),
|
||||
'customer_contact' => app(CustomerQueries::class)->findContact($this->job->customer->id, $ids[0])->name ?? __('jobs.history.unknown', ['id' => $ids[0]]),
|
||||
'billing_unit' => app(CustomerQueries::class)->findBillingUnit($this->job->customer->id, $ids[0])->name ?? __('jobs.history.unknown', ['id' => $ids[0]]),
|
||||
default => $value,
|
||||
};
|
||||
}
|
||||
|
||||
public function render(): mixed
|
||||
{
|
||||
return $this->view()->title($this->job->number.' '.$this->job->name);
|
||||
|
||||
Reference in New Issue
Block a user