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:
2026-11-30 06:33:28 +02:00
co-authored by Claude Opus 5.5
parent f4b58f6b1d
commit 6332ff0fa9
35 changed files with 3556 additions and 494 deletions
@@ -0,0 +1,133 @@
<?php
use App\Modules\Expenses\Application\Contracts\ExpenseJobs;
use App\Modules\Expenses\Application\Contracts\ExpenseQueries;
use App\Modules\Expenses\Application\DTOs\ExpenseData;
use App\Modules\Expenses\Application\DTOs\ExpenseSummary;
use App\Modules\Expenses\Application\UseCases\RecordExpense;
use App\Modules\Expenses\Domain\Enums\ExpenseCategory;
use App\Modules\Expenses\Domain\Enums\ExpensePayer;
use App\Modules\Expenses\Domain\Exceptions\ExpenseJobNotFound;
use App\Modules\Expenses\Domain\Exceptions\ExpenseLocked;
use App\Modules\Expenses\Presentation\Livewire\Concerns\ShowsExpenses;
use App\Modules\Shared\Domain\Exceptions\DomainException;
use App\Modules\Users\Application\Contracts\Clock;
use Illuminate\Support\Facades\Gate;
use Livewire\Attributes\Computed;
use Livewire\Attributes\Locked;
use Livewire\Component;
/**
* Quick expenses of a job in the board's job editor: a description and an
* amount without VAT, paid by the company, dated today. The list shows
* amounts only to those who may see them; the full form is on the job's
* expense page.
*/
new class extends Component
{
use ShowsExpenses;
#[Locked]
public int $jobId;
public string $description = '';
public string $cost = '';
public string $statusMessage = '';
public function mount(int $jobId): void
{
$this->authorize('expenses.use');
$this->jobId = $jobId;
}
/**
* @return list<ExpenseSummary>
*/
#[Computed]
public function expenses(): array
{
return app(ExpenseQueries::class)->forJob($this->jobId);
}
public function isLocked(): bool
{
return app(ExpenseJobs::class)->find($this->jobId)?->isLocked ?? true;
}
public function save(RecordExpense $record, Clock $clock): void
{
$this->authorize('expenses.record');
if (trim($this->description) === '') {
$this->addError('description', __('expenses.errors.description_required'));
return;
}
try {
$record->execute($this->jobId, new ExpenseData(
userId: (int) auth()->id(),
category: ExpenseCategory::Materials,
paidBy: ExpensePayer::Company,
spentOn: $clock->today()->format('Y-m-d'),
description: trim($this->description),
cost: $this->cost,
), (int) auth()->id());
} catch (ExpenseLocked) {
$this->addError('cost', __('expenses.quick.locked'));
return;
} catch (ExpenseJobNotFound) {
abort(404);
} catch (DomainException) {
$this->addError('cost', __('expenses.errors.invalid_amount'));
return;
}
$this->statusMessage = __('expenses.quick.added', ['description' => trim($this->description)]);
$this->reset('description', 'cost');
unset($this->expenses);
}
};
?>
<div class="space-y-2.5 text-xs">
@if (Gate::allows('expenses.record') && ! $this->isLocked())
<form wire:submit="save" class="grid gap-3 sm:grid-cols-12 sm:items-start">
<div class="sm:col-span-6">
<x-input id="quick-expense-description-{{ $jobId }}" wire:model="description" maxlength="255" :label="__('expenses.quick.description')" :placeholder="__('expenses.quick.description_placeholder')" autocomplete="off" />
</div>
<div class="sm:col-span-3">
<x-input id="quick-expense-cost-{{ $jobId }}" wire:model="cost" inputmode="decimal" :label="__('expenses.quick.amount')" placeholder="0,00" autocomplete="off" />
</div>
<div class="sm:col-span-3 sm:pt-6">
<x-button submit sm class="w-full" :text="__('expenses.quick.add')" />
</div>
</form>
@elseif ($this->isLocked())
<p class="font-semibold">{{ __('expenses.quick.locked') }}</p>
@endif
<p role="status" aria-live="polite" class="min-h-4 font-medium">{{ $statusMessage }}</p>
@if ($this->expenses === [])
<p>{{ __('expenses.quick.none') }}</p>
@else
<ul class="space-y-1">
@foreach ($this->expenses as $expense)
<li wire:key="quick-expense-{{ $expense->id }}" class="flex justify-between gap-2 rounded border border-neutral-200 bg-white px-2.5 py-1.5 dark:border-[#36393f] dark:bg-[#25272b]">
<span class="min-w-0 break-words">{{ $this->summaryText($expense) }}</span>
<span class="shrink-0 font-bold">{{ $this->amount($expense, $expense->costCents) }}</span>
</li>
@endforeach
</ul>
@endif
@can('expenses.record')
<x-link :href="route('expenses.job', $jobId)" navigate class="text-xs">{{ __('expenses.quick.all') }}</x-link>
@endcan
</div>
@@ -16,6 +16,13 @@ interface TaskQueries
*/ */
public function tasksOf(int $jobId): array; public function tasksOf(int $jobId): array;
/**
* Which of the job's tasks are pinned to the Kanban board, by task id.
*
* @return array<int, bool>
*/
public function pinnedTaskIds(int $jobId): array;
/** /**
* Null when the task does not exist or belongs to another job. * Null when the task does not exist or belongs to another job.
*/ */
@@ -36,6 +36,16 @@ class EloquentTaskQueries implements TaskQueries
return $this->summaries($models); return $this->summaries($models);
} }
public function pinnedTaskIds(int $jobId): array
{
return TaskModel::query()
->where('customer_job_id', $jobId)
->where('is_pinned_to_board', true)
->pluck('id')
->mapWithKeys(fn ($id): array => [(int) $id => true])
->all();
}
public function findTask(int $jobId, int $taskId): ?TaskSummary public function findTask(int $jobId, int $taskId): ?TaskSummary
{ {
$model = TaskModel::query()->where('customer_job_id', $jobId)->find($taskId); $model = TaskModel::query()->where('customer_job_id', $jobId)->find($taskId);
@@ -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; use Livewire\Form;
/** /**
* Quick job intake on a phone: only what is needed to open a job (spec 6). * Quick job intake on a phone and in the board's dialog: only what is
* Everything else gets the defaults and is filled in later. * 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 class QuickJobForm extends Form
{ {
@@ -31,6 +32,27 @@ class QuickJobForm extends Form
public string $status = JobStatus::Tentative->value; 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 public function toData(): CustomerJobData
{ {
$this->validate(); $this->validate();
@@ -42,8 +64,9 @@ class QuickJobForm extends Form
responsibleUserId: (int) $this->responsible_user_id, responsibleUserId: (int) $this->responsible_user_id,
kind: JobKind::OneOff->value, kind: JobKind::OneOff->value,
status: $this->status, status: $this->status,
priority: Priority::Normal->value, priority: $this->priority,
description: trim($this->description) === '' ? null : $this->description, 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 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(); $this->resetErrorBag();
} }
@@ -83,7 +106,11 @@ class QuickJobForm extends Form
'description' => ['nullable', 'string', 'max:2000'], 'description' => ['nullable', 'string', 'max:2000'],
'service_unit_id' => ['required', 'integer'], 'service_unit_id' => ['required', 'integer'],
'responsible_user_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'), 'service_unit_id.required' => __('jobs.quick.service_unit_required'),
'responsible_user_id.required' => __('jobs.errors.responsible_required'), 'responsible_user_id.required' => __('jobs.errors.responsible_required'),
'status.in' => __('jobs.errors.status_not_allowed'), '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\PaymentBasis;
use App\Modules\Jobs\Domain\Enums\Priority; use App\Modules\Jobs\Domain\Enums\Priority;
use App\Modules\Jobs\Domain\Exceptions\CustomerJobNotFound; 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\Concerns\PicksCustomer;
use App\Modules\Jobs\Presentation\Livewire\Forms\JobForm; use App\Modules\Jobs\Presentation\Livewire\Forms\JobForm;
use App\Modules\Shared\Domain\Exceptions\DomainException; use App\Modules\Shared\Domain\Exceptions\DomainException;
@@ -29,7 +30,9 @@ use Livewire\Component;
*/ */
new class extends Component new class extends Component
{ {
use PicksCustomer; use EditsJobDetails, PicksCustomer {
EditsJobDetails::customerChosen insteadof PicksCustomer;
}
#[Locked] #[Locked]
public ?int $jobId = null; public ?int $jobId = null;
@@ -69,132 +72,6 @@ new class extends Component
$this->form->fillFromDetails($details); $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 public function save(CreateCustomerJob $createJob, UpdateCustomerJob $updateJob, CustomerJobQueries $jobQueries): void
{ {
$this->authorize('jobs.manage'); $this->authorize('jobs.manage');
@@ -239,36 +116,6 @@ new class extends Component
{ {
return $this->view()->title($this->heading()); 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\Contracts\CatalogQueries;
use App\Modules\Catalog\Application\DTOs\ServiceUnitSummary; 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\Contracts\CustomerJobQueries;
use App\Modules\Jobs\Application\UseCases\CreateCustomerJob; 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\Concerns\PicksCustomer;
use App\Modules\Jobs\Presentation\Livewire\Forms\QuickJobForm; use App\Modules\Jobs\Presentation\Livewire\Forms\QuickJobForm;
use App\Modules\Shared\Domain\Exceptions\DomainException; use App\Modules\Shared\Domain\Exceptions\DomainException;
@@ -16,16 +20,25 @@ use Livewire\Attributes\Locked;
use Livewire\Component; use Livewire\Component;
/** /**
* Quick job intake (pikavastaanotto), made for phones: customer, name, * Quick job intake (pikavastaanotto, docs/ui-kanban-board.md 6), made for
* short description, service unit and responsible person. The page stays * phones and also opened as a dialog on the Kanban board: customer and its
* open for the next job and links to the one just created. * 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 new class extends Component
{ {
use PicksCustomer; use PicksCustomer;
public const string DIALOG = 'quick-intake-dialog';
public QuickJobForm $form; 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. * The job created last on this page, shown with links to it.
*/ */
@@ -38,10 +51,11 @@ new class extends Component
#[Locked] #[Locked]
public string $createdNumber = ''; public string $createdNumber = '';
public function mount(): void public function mount(bool $inDialog = false): void
{ {
$this->authorize('jobs.manage'); $this->authorize('jobs.manage');
$this->inDialog = $inDialog;
$this->form->responsible_user_id = (string) auth()->id(); $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->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(); $data = $this->form->toData();
try { try {
@@ -90,6 +134,15 @@ new class extends Component
$this->customerName = ''; $this->customerName = '';
$this->customerSearch = ''; $this->customerSearch = '';
$this->statusMessage = ''; $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()"); $this->js("document.getElementById('quick-created')?.focus()");
} }
@@ -98,33 +151,44 @@ new class extends Component
{ {
return $this->view()->title(__('jobs.quick.title')); 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(['mx-auto max-w-lg space-y-6 p-4 sm:p-6' => ! $inDialog])>
<div class="space-y-1"> @unless ($inDialog)
<x-page-title icon="bolt">{{ __('jobs.quick.title') }}</x-page-title> <div class="space-y-1">
<p class="text-sm text-zinc-600 dark:text-zinc-200">{{ __('jobs.quick.intro') }}</p> <x-page-title icon="bolt">{{ __('jobs.quick.title') }}</x-page-title>
</div> <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"> <div id="quick-created" tabindex="-1" role="status" aria-live="polite" class="focus:outline-none">
@if ($createdJobId !== null) @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"> <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"> <p class="flex items-start gap-2 font-medium">
<x-icon name="check-circle" class="size-5 shrink-0" aria-hidden="true" /> <x-icon name="check-circle" class="size-5 shrink-0" aria-hidden="true" />
{{ $createdMessage }} {{ $createdMessage }}
</p> </p>
<p class="flex flex-wrap gap-x-4 gap-y-1"> <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.show', $createdJobId)" navigate>{{ __('jobs.quick.open', ['number' => $createdNumber]) }}</x-link>
<x-link :href="route('jobs.edit', $createdJobId)" navigate>{{ __('jobs.quick.complete') }}</x-link> <x-link :href="route('jobs.edit', $createdJobId)" navigate>{{ __('jobs.quick.complete') }}</x-link>
</p> </p>
</div> </div>
@endif @endif
</div> </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 <x-jobs.customer-picker
:customer-id="$form->customer_id" :customer-id="$form->customer_id"
:customer-name="$customerName" :customer-name="$customerName"
@@ -132,34 +196,83 @@ new class extends Component
:results="$this->customerResults" :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-textarea id="{{ $inDialog ? 'dialog-' : '' }}quick-description" wire:model="form.description" :label="__('jobs.quick.description')" rows="3" />
<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-select.native wire:model="form.responsible_user_id" :label="__('jobs.fields.responsible_user')" :aria-label="__('jobs.fields.responsible_user')" required> <div class="grid gap-4 sm:grid-cols-2">
<option value="">{{ __('jobs.fields.none_selected') }}</option> {{-- TallStackUI's native select does not tie its label to the control, so aria-label names it. --}}
@foreach ($this->staff as $user) <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="{{ $user->id }}">{{ $user->name }}</option> <option value="">{{ __('jobs.fields.none_selected') }}</option>
@endforeach @foreach ($this->serviceUnits as $unit)
</x-select.native> <option value="{{ $unit->id }}">{{ $unit->name }}</option>
@endforeach
</x-select.native>
<x-radio.group <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>
wire:model="form.status" <option value="">{{ __('jobs.fields.none_selected') }}</option>
:label="__('jobs.fields.status')" @foreach ($this->staff as $user)
:options="[ <option value="{{ $user->id }}">{{ $user->name }}</option>
['label' => __('jobs.statuses.'.JobStatus::Tentative->value), 'value' => JobStatus::Tentative->value], @endforeach
['label' => __('jobs.statuses.'.JobStatus::Prospect->value), 'value' => JobStatus::Prospect->value], </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> </form>
</div> </div>
@@ -19,6 +19,7 @@ use App\Modules\Shared\Domain\ValueObjects\Money;
use Livewire\Attributes\Computed; use Livewire\Attributes\Computed;
use Livewire\Attributes\Locked; use Livewire\Attributes\Locked;
use Livewire\Attributes\On; use Livewire\Attributes\On;
use App\Modules\Jobs\Presentation\Livewire\Concerns\DescribesJobHistory;
use Livewire\Component; use Livewire\Component;
/** /**
@@ -26,6 +27,8 @@ use Livewire\Component;
*/ */
new class extends Component new class extends Component
{ {
use DescribesJobHistory;
#[Locked] #[Locked]
public int $jobId; public int $jobId;
@@ -57,20 +60,6 @@ new class extends Component
return app(CustomerJobQueries::class)->findDetails($this->jobId) ?? abort(404); 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> * @return list<TaskSummary>
*/ */
@@ -159,43 +148,6 @@ new class extends Component
$this->js("document.getElementById('remove-task-dialog').close(); document.getElementById('tasks-heading').focus()"); $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 public function render(): mixed
{ {
return $this->view()->title($this->job->number.' '.$this->job->name); return $this->view()->title($this->job->number.' '.$this->job->name);
@@ -0,0 +1,39 @@
<?php
namespace App\Modules\Jobs\Presentation\Support;
use App\Modules\Jobs\Application\DTOs\BoardCard;
use Carbon\CarbonImmutable;
/**
* Finnish short formats on Kanban cards: "16.12." and "1,5".
*/
final class BoardFormat
{
public static function shortDate(?string $date): string
{
return $date === null ? '–' : CarbonImmutable::parse($date)->format('j.n.');
}
public static function hours(float|string|null $hours): string
{
if ($hours === null || $hours === '') {
return '0';
}
$text = rtrim(rtrim(number_format((float) $hours, 2, '.', ''), '0'), '.');
return str_replace('.', ',', $text === '' ? '0' : $text);
}
/**
* "1,5/4 h": recorded against estimated hours.
*/
public static function cardHours(BoardCard $card): string
{
return __('jobs.board.hours', [
'logged' => self::hours($card->loggedHours()),
'estimated' => self::hours($card->estimatedHours),
]);
}
}
@@ -0,0 +1,143 @@
<?php
use App\Modules\Jobs\Application\Contracts\CustomerJobQueries;
use App\Modules\Jobs\Application\Contracts\TaskQueries;
use App\Modules\Jobs\Application\DTOs\TaskSummary;
use App\Modules\Jobs\Domain\Enums\TaskStatus;
use App\Modules\Shared\Domain\Exceptions\DomainException;
use App\Modules\TimeTracking\Application\Contracts\TimeEntryQueries;
use App\Modules\TimeTracking\Application\UseCases\AddTaskHours;
use App\Modules\TimeTracking\Domain\Exceptions\DailyHoursExceeded;
use App\Modules\TimeTracking\Domain\Exceptions\InvalidWorkedHours;
use App\Modules\TimeTracking\Domain\Exceptions\TimeApproved;
use App\Modules\TimeTracking\Domain\Exceptions\TimeLocked;
use App\Modules\Users\Application\Contracts\Clock;
use Illuminate\Support\Facades\Gate;
use Livewire\Attributes\Computed;
use Livewire\Attributes\Locked;
use Livewire\Component;
/**
* Quick hours on a job for today, in the board's job editor: a task of the
* job, hours in quarter hours and a description.
*/
new class extends Component
{
#[Locked]
public int $jobId;
public string $taskId = '';
public string $hours = '';
public string $note = '';
public string $statusMessage = '';
public function mount(int $jobId): void
{
$this->authorize('time.use');
$this->jobId = $jobId;
$this->taskId = (string) ($this->tasks[0]->id ?? '');
}
/**
* @return list<TaskSummary>
*/
#[Computed]
public function tasks(): array
{
return array_values(array_filter(
app(TaskQueries::class)->tasksOf($this->jobId),
fn (TaskSummary $task): bool => $task->status !== TaskStatus::Done,
));
}
public function isLocked(): bool
{
return app(CustomerJobQueries::class)->findDetails($this->jobId)?->status->locksTime() ?? true;
}
public function loggedHours(): string
{
$quarters = app(TimeEntryQueries::class)->quartersByJobs([$this->jobId])[$this->jobId] ?? 0;
return str_replace('.', ',', rtrim(rtrim(number_format($quarters / 4, 2, '.', ''), '0'), '.'));
}
public function estimatedHours(): string
{
$estimate = app(CustomerJobQueries::class)->findDetails($this->jobId)?->estimatedHours;
return $estimate === null ? '0' : str_replace('.', ',', rtrim(rtrim($estimate, '0'), '.'));
}
public function save(AddTaskHours $addHours, Clock $clock): void
{
$this->authorize('time.book', $this->jobId);
$task = collect($this->tasks)->first(fn (TaskSummary $task): bool => (string) $task->id === $this->taskId);
if ($task === null) {
$this->addError('taskId', __('time.quick_hours.no_tasks'));
return;
}
try {
$saved = $addHours->execute((int) auth()->id(), $task->id, $clock->today()->format('Y-m-d'), $this->hours, trim($this->note) === '' ? null : trim($this->note));
} catch (InvalidWorkedHours) {
$this->addError('hours', __('time.errors.invalid_hours'));
return;
} catch (DailyHoursExceeded) {
$this->addError('hours', __('time.errors.day_full'));
return;
} catch (TimeLocked|TimeApproved) {
$this->addError('hours', __('time.quick_hours.locked'));
return;
} catch (DomainException) {
$this->addError('hours', __('time.quick_hours.not_allowed'));
return;
}
$this->reset('hours', 'note');
$this->statusMessage = __('time.quick_hours.added', ['hours' => $saved, 'task' => $task->title]);
$this->dispatch('job-saved');
}
};
?>
<div class="space-y-2.5 text-xs">
@if ($this->isLocked())
<p class="font-semibold">{{ __('time.quick_hours.locked') }}</p>
@elseif ($this->tasks === [])
<p>{{ __('time.quick_hours.no_tasks') }}</p>
@elseif (Gate::allows('time.book', $jobId))
<form wire:submit="save" class="grid gap-3 sm:grid-cols-12 sm:items-start">
<div class="sm:col-span-4">
<x-select.native id="quick-hours-task-{{ $jobId }}" wire:model="taskId" :label="__('time.quick_hours.task')" :aria-label="__('time.quick_hours.task')">
@foreach ($this->tasks as $task)
<option value="{{ $task->id }}">{{ $task->title }}</option>
@endforeach
</x-select.native>
</div>
<div class="sm:col-span-2">
<x-input id="quick-hours-hours-{{ $jobId }}" wire:model="hours" inputmode="decimal" :label="__('time.quick_hours.hours')" placeholder="1,5" autocomplete="off" />
</div>
<div class="sm:col-span-4">
<x-input id="quick-hours-note-{{ $jobId }}" wire:model="note" maxlength="2000" :label="__('time.quick_hours.note')" :placeholder="__('time.quick_hours.note_placeholder')" autocomplete="off" />
</div>
<div class="sm:col-span-2 sm:pt-6">
<x-button submit sm class="w-full" :text="__('time.quick_hours.add')" />
</div>
</form>
@endif
<p role="status" aria-live="polite" class="min-h-4 font-medium">{{ $statusMessage }}</p>
<p>{{ __('time.quick_hours.total', ['logged' => $this->loggedHours(), 'estimated' => $this->estimatedHours()]) }}</p>
</div>
+11
View File
@@ -110,4 +110,15 @@ return [
'invalid_markup' => 'Enter the markup as a percentage, e.g. 15 (at most two decimals).', 'invalid_markup' => 'Enter the markup as a percentage, e.g. 15 (at most two decimals).',
'text_too_long' => 'The text may be at most 255 characters.', 'text_too_long' => 'The text may be at most 255 characters.',
], ],
'quick' => [
'description' => 'Expense',
'description_placeholder' => 'E.g. print media',
'amount' => 'Amount (€, VAT 0)',
'add' => 'Add expense',
'added' => 'Expense :description added.',
'hidden' => 'Hidden (money permission)',
'none' => 'The job has no expenses.',
'all' => 'All expenses of the job',
'locked' => 'The job\'s expenses are locked.',
],
]; ];
+60
View File
@@ -307,6 +307,58 @@ return [
'density_saved' => 'Card density: :density.', 'density_saved' => 'Card density: :density.',
], ],
'editor' => [
'heading' => 'Customer job :number',
'close' => 'Close the card',
'color' => 'Colour',
'color_label' => 'Change the colour of customer :customer',
'status' => 'Status',
'priority' => 'Priority',
'locked' => 'The job is marked done – its hours and expenses are locked for billing.',
'unlock' => 'Open the lock (management)',
'read_only' => 'You can mark tasks done, but not change the job\'s details.',
'links' => 'File links (Drive, Dropbox, materials)',
'tasks' => 'Tasks of the customer job',
'tasks_ongoing' => 'Periods and tasks of the continuing job',
'tasks_hint' => 'Manage work steps, assignees, due dates and checklists.',
'tasks_hint_ongoing' => 'Mark done or lift a flexible task into the pipeline (PIN).',
'no_tasks' => 'The job has no tasks yet.',
'task_done' => 'Done: :task',
'task_title' => 'Task name',
'task_status' => 'Status of task :task',
'task_assignee' => 'Assignee of task :task',
'task_due' => 'Due date of task :task',
'no_assignee' => 'No assignee',
'checklist' => 'Checklist',
'template' => 'Workflow template',
'template_choose' => '+ Add from a workflow template…',
'template_apply' => 'Create',
'template_added' => '{0} No tasks were added from the template.|{1} :count task was added from the template.|[2,*] :count tasks were added from the template.',
'new_task' => 'Name of the new task',
'new_task_placeholder' => 'Add a new task to this customer job…',
'new_task_assignee' => 'Assignee of the new task',
'add_task' => 'Add',
'pin_new' => 'Lift the new task into the pipeline as a card of its own (PIN)',
'task_added' => 'Task :task added.',
'task_saved' => 'Task :task saved.',
'tabs_label' => 'Records',
'tab_hours' => 'Time entries (:hours h)',
'tab_expenses' => 'Expenses',
'tab_history' => 'Change history (:count)',
'customer_section' => 'Customer and billing unit',
'team_section' => 'Own team and members',
'units_section' => 'Service units and tags',
'schedule_section' => 'Schedule and kind',
'money_section' => 'Billing and money',
'money_hidden' => 'Quote and billing amounts are hidden from your role (2.3 Visibility of amounts).',
'footer' => 'Changes are saved to the customer job and recorded in its change history.',
'save' => 'Save and close',
'open_page' => 'Open the job page',
'saved' => 'Changes to customer job :number saved.',
'status_changed' => 'Status of job :number: :status.',
'priority_changed' => 'Priority of job :number: :priority.',
],
'calendar' => [ 'calendar' => [
'title' => 'Task calendar', 'title' => 'Task calendar',
'intro' => 'Tasks by assignee according to their schedule. Move a task by dragging its bar, change its length by dragging the bar\'s edge, or open the bar as a button to change the schedule, assignee and status in a form.', 'intro' => 'Tasks by assignee according to their schedule. Move a task by dragging its bar, change its length by dragging the bar\'s edge, or open the bar as a button to change the schedule, assignee and status in a form.',
@@ -383,6 +435,14 @@ return [
'open' => 'Open job :number', 'open' => 'Open job :number',
'complete' => 'Complete details', 'complete' => 'Complete details',
'link' => 'Quick intake', 'link' => 'Quick intake',
'dialog_title' => 'New job / Quick intake',
'contact' => 'Customer contact person',
'add_contact' => '+ Quick add new',
'add_contact_label' => 'Quick add a new contact person',
'contact_name' => 'Name of the new contact person',
'contact_phone' => 'Phone',
'contact_name_required' => 'Enter the name of the new contact person.',
'start_status' => 'Initial status',
], ],
'list' => [ 'list' => [
+12
View File
@@ -103,4 +103,16 @@ return [
'open_week_of' => 'Open week: :name, :week', 'open_week_of' => 'Open week: :name, :week',
'approver_value' => ':name, :date', 'approver_value' => ':name, :date',
], ],
'quick_hours' => [
'task' => 'Task',
'hours' => 'Hours today',
'note' => 'Description',
'note_placeholder' => 'E.g. layout and proofs',
'add' => 'Record hours',
'added' => ':hours h recorded on task :task for today.',
'total' => 'Recorded in all: :logged h / estimate: :estimated h.',
'locked' => 'The job\'s hours are locked, so no hours can be recorded.',
'no_tasks' => 'The job has no open tasks to record hours on.',
'not_allowed' => 'You cannot record hours on this job.',
],
]; ];
+11
View File
@@ -110,4 +110,15 @@ return [
'invalid_markup' => 'Anna kate prosentteina, esim. 15 (enintään kaksi desimaalia).', 'invalid_markup' => 'Anna kate prosentteina, esim. 15 (enintään kaksi desimaalia).',
'text_too_long' => 'Teksti voi olla enintään 255 merkkiä.', 'text_too_long' => 'Teksti voi olla enintään 255 merkkiä.',
], ],
'quick' => [
'description' => 'Kulu',
'description_placeholder' => 'Esim. tulostusmedia',
'amount' => 'Summa (€, ALV 0)',
'add' => 'Lisää kulu',
'added' => 'Kulu :description lisätty.',
'hidden' => 'Piilotettu (rahaoikeus)',
'none' => 'Työllä ei ole kuluja.',
'all' => 'Kaikki työn kulut',
'locked' => 'Työn kulut on lukittu.',
],
]; ];
+60
View File
@@ -307,6 +307,58 @@ return [
'density_saved' => 'Korttien tiheys: :density.', 'density_saved' => 'Korttien tiheys: :density.',
], ],
'editor' => [
'heading' => 'Asiakastyö :number',
'close' => 'Sulje kortti',
'color' => 'Väri',
'color_label' => 'Vaihda asiakkaan :customer väri',
'status' => 'Tila',
'priority' => 'Prioriteetti',
'locked' => 'Työ on merkitty valmiiksi – tunnit ja kulut on lukittu laskutusta varten.',
'unlock' => 'Avaa lukitus (johto)',
'read_only' => 'Voit kuitata tehtäviä, mutta et muuttaa työn tietoja.',
'links' => 'Tiedostolinkit (Drive, Dropbox, aineistot)',
'tasks' => 'Asiakastyön tehtävät',
'tasks_ongoing' => 'Jatkuvan työn jaksot ja tehtävät',
'tasks_hint' => 'Hallitse työvaiheita, tekijöitä, määräpäiviä ja tarkistuslistoja.',
'tasks_hint_ongoing' => 'Kuittaa valmiiksi tai nosta joustava tehtävä työputkeen (PIN).',
'no_tasks' => 'Työllä ei ole vielä tehtäviä.',
'task_done' => 'Valmis: :task',
'task_title' => 'Tehtävän nimi',
'task_status' => 'Tehtävän :task tila',
'task_assignee' => 'Tehtävän :task tekijä',
'task_due' => 'Tehtävän :task määräpäivä',
'no_assignee' => 'Ei tekijää',
'checklist' => 'Tarkistuslista',
'template' => 'Työnkulkupohja',
'template_choose' => '+ Lisää työnkulkupohjasta…',
'template_apply' => 'Luo',
'template_added' => '{0} Pohjasta ei lisätty tehtäviä.|{1} Pohjasta lisättiin :count tehtävä.|[2,*] Pohjasta lisättiin :count tehtävää.',
'new_task' => 'Uuden tehtävän nimi',
'new_task_placeholder' => 'Lisää uusi tehtävä tälle asiakastyölle…',
'new_task_assignee' => 'Uuden tehtävän tekijä',
'add_task' => 'Lisää',
'pin_new' => 'Nosta uusi tehtävä samalla työputkeen omana korttinaan (PIN)',
'task_added' => 'Tehtävä :task lisätty.',
'task_saved' => 'Tehtävä :task tallennettu.',
'tabs_label' => 'Kirjaukset',
'tab_hours' => 'Tuntikirjaukset (:hours h)',
'tab_expenses' => 'Kulut',
'tab_history' => 'Muutoshistoria (:count)',
'customer_section' => 'Asiakas ja laskutusyksikkö',
'team_section' => 'Oma tiimi ja jäsenet',
'units_section' => 'Palveluyksiköt ja tagit',
'schedule_section' => 'Aikataulu ja laji',
'money_section' => 'Laskutus ja raha',
'money_hidden' => 'Tarjous- ja laskutussummat on piilotettu käyttäjäroolilta (2.3 Rahamäärien näkyvyys).',
'footer' => 'Muutokset tallentuvat asiakastyölle ja kirjautuvat muutoshistoriaan.',
'save' => 'Tallenna ja sulje',
'open_page' => 'Avaa työsivu',
'saved' => 'Asiakastyön :number muutokset tallennettu.',
'status_changed' => 'Työn :number tila: :status.',
'priority_changed' => 'Työn :number prioriteetti: :priority.',
],
'calendar' => [ 'calendar' => [
'title' => 'Tehtäväkalenteri', 'title' => 'Tehtäväkalenteri',
'intro' => 'Tehtävät tekijöittäin aikataulun mukaan. Siirrä tehtävää vetämällä palkkia, muuta kestoa vetämällä palkin reunasta tai avaa palkki painikkeena, jolloin aikataulun, tekijän ja tilan voi muuttaa lomakkeella.', 'intro' => 'Tehtävät tekijöittäin aikataulun mukaan. Siirrä tehtävää vetämällä palkkia, muuta kestoa vetämällä palkin reunasta tai avaa palkki painikkeena, jolloin aikataulun, tekijän ja tilan voi muuttaa lomakkeella.',
@@ -383,6 +435,14 @@ return [
'open' => 'Avaa työ :number', 'open' => 'Avaa työ :number',
'complete' => 'Täydennä tietoja', 'complete' => 'Täydennä tietoja',
'link' => 'Pikavastaanotto', 'link' => 'Pikavastaanotto',
'dialog_title' => 'Uusi työ / Pikavastaanotto',
'contact' => 'Asiakkaan kontaktihenkilö',
'add_contact' => '+ Pikalisää uusi',
'add_contact_label' => 'Pikalisää uusi kontaktihenkilö',
'contact_name' => 'Uuden kontaktihenkilön nimi',
'contact_phone' => 'Puhelin',
'contact_name_required' => 'Anna uuden kontaktihenkilön nimi.',
'start_status' => 'Alkutila',
], ],
'list' => [ 'list' => [
+12
View File
@@ -103,4 +103,16 @@ return [
'open_week_of' => 'Avaa viikko: :name, :week', 'open_week_of' => 'Avaa viikko: :name, :week',
'approver_value' => ':name, :date', 'approver_value' => ':name, :date',
], ],
'quick_hours' => [
'task' => 'Tehtävä',
'hours' => 'Tunnit tänään',
'note' => 'Selite',
'note_placeholder' => 'Esim. taitto ja vedostus',
'add' => 'Kirjaa tunnit',
'added' => ':hours h kirjattu tehtävälle :task tälle päivälle.',
'total' => 'Yhteensä kirjattu: :logged h / arvio: :estimated h.',
'locked' => 'Työn tunnit on lukittu, joten tunteja ei voi kirjata.',
'no_tasks' => 'Työllä ei ole avoimia tehtäviä, joille kirjata tunteja.',
'not_allowed' => 'Et voi kirjata tunteja tälle työlle.',
],
]; ];
+26
View File
@@ -72,3 +72,29 @@ html {
@utility card { @utility card {
@apply rounded-xl border border-zinc-200 bg-white p-4 shadow-sm sm:p-5 dark:border-zinc-700 dark:bg-zinc-900; @apply rounded-xl border border-zinc-200 bg-white p-4 shadow-sm sm:p-5 dark:border-zinc-700 dark:bg-zinc-900;
} }
/* The Kanban board's horizontal scrollbar (docs/kanban-prototyyppi.html). */
.kanban-scroll::-webkit-scrollbar {
height: 10px;
width: 8px;
}
.kanban-scroll::-webkit-scrollbar-track {
background: rgb(0 0 0 / 0.18);
border-radius: 9999px;
}
.kanban-scroll::-webkit-scrollbar-thumb {
background: rgb(255 255 255 / 0.4);
border-radius: 9999px;
}
/* The card being dragged on the board, and the drop place. */
[wire\:sort\:item].sortable-ghost {
opacity: 0.45;
}
[wire\:sort\:item].sortable-ghost > article {
outline: 3px solid var(--color-indigo-400);
outline-offset: 1px;
}
@@ -0,0 +1,47 @@
{{--
The customer-coloured top bar of a job card: the drag handle
(wire:sort:handle) and a click target that opens the job editor. The
keyboard opens the job from the title button below; the palette button
changes the customer's colour for every card and the time sheet.
--}}
@props(['card', 'canMove' => false, 'canColor' => false])
@php
$color = new \App\Modules\Shared\Domain\ValueObjects\HexColor($card->customerHeaderColor ?? '#23476a');
$light = $color->isLight();
@endphp
<div
@if ($canMove) wire:sort:handle @endif
wire:click="openJob({{ $card->jobId }})"
title="{{ __('jobs.board.drag_hint') }}"
style="background-color: {{ $color->value }}; color: {{ $color->textColor() }}"
@class(['flex items-center justify-between gap-1 px-2 py-1 select-none', 'cursor-grab active:cursor-grabbing' => $canMove, 'cursor-pointer' => ! $canMove])
>
<div class="flex min-w-0 items-center gap-1">
@if ($canMove)
<x-icon name="ellipsis-vertical" class="size-3 shrink-0 opacity-80" aria-hidden="true" />
@endif
<span class="truncate text-[11px] font-extrabold tracking-tight">{{ $card->customerName }}</span>
</div>
<div class="flex shrink-0 items-center gap-1">
<span @class(['rounded px-1.5 text-[10px] font-bold', 'bg-black/10' => $light, 'bg-white/20' => ! $light])>{{ $card->number }}</span>
@if ($canColor)
<button
type="button"
x-on:click.stop="$dispatch('color-picker:open', {{ Js::from([
'id' => 'colour-picker',
'title' => __('jobs.board.customer_color_title', ['customer' => $card->customerName]),
'color' => $color->value,
'method' => 'setCustomerColor',
'args' => [$card->customerId],
'resettable' => $card->customerHeaderColor !== null,
]) }})"
aria-label="{{ __('jobs.board.customer_color_button', ['customer' => $card->customerName]) }}"
class="inline-flex size-6 items-center justify-center rounded hover:bg-black/15 focus-visible:outline-2 focus-visible:outline-current dark:hover:bg-white/15"
>
<x-icon name="swatch" class="size-3.5" aria-hidden="true" />
</button>
@endif
</div>
</div>
@@ -0,0 +1,99 @@
{{--
A customer job card (docs/ui-kanban-board.md 4.1): customer bar, title
that opens the job editor, responsible person, service unit, priority,
due date, hours and the job's tasks, which open inside the card and can
be marked done. Compact cards have three rows.
--}}
@props(['card', 'compact' => false, 'canMove' => false, 'canColor' => false, 'canCheck' => false])
@use('App\Modules\Jobs\Presentation\Support\BoardFormat')
@php
$total = count($card->tasks);
$done = $card->doneTaskCount();
@endphp
<article
aria-labelledby="card-{{ $card->key() }}-title"
x-data="{ expanded: false }"
class="overflow-hidden rounded-xl border border-neutral-300 bg-white shadow-sm transition dark:border-[#36393f] dark:bg-[#282a2e]"
>
<x-jobs.board.card-header :card="$card" :can-move="$canMove" :can-color="$canColor" />
<div @class(['space-y-1.5 p-1.5' => $compact, 'space-y-2 p-2.5' => ! $compact])>
<h3 class="m-0" id="card-{{ $card->key() }}-title">
<button
type="button"
id="card-{{ $card->key() }}-open"
wire:click="openJob({{ $card->jobId }})"
title="{{ $card->title }}"
class="block w-full truncate rounded text-left text-[13px] font-bold text-neutral-900 hover:underline focus-visible:outline-2 focus-visible:outline-primary-600 dark:text-white dark:focus-visible:outline-primary-300"
><span class="sr-only">{{ $card->number }} </span>{{ $card->title }}</button>
</h3>
@if ($compact)
<div class="flex items-center justify-between gap-1 text-[10px]">
<div class="flex min-w-0 items-center gap-1">
<x-jobs.board.person :initials="$card->responsibleInitials()" :name="$card->responsibleFirstName()" />
<x-jobs.board.priority-badge :priority="$card->priority" />
</div>
@if ($total > 0)
<button
type="button"
x-on:click="expanded = ! expanded"
x-bind:aria-expanded="expanded.toString()"
aria-controls="tasks-{{ $card->key() }}"
aria-label="{{ __('jobs.board.tasks_compact', ['done' => $done, 'total' => $total]) }}"
class="inline-flex min-h-6 shrink-0 items-center gap-0.5 rounded bg-neutral-100 px-1.5 text-[10px] font-bold text-neutral-800 transition hover:bg-neutral-200 focus-visible:outline-2 focus-visible:outline-primary-600 dark:bg-[#1e2023] dark:text-neutral-100 dark:hover:bg-[#32353b] dark:focus-visible:outline-primary-300"
>
{{ $done }}/{{ $total }}
<x-icon name="chevron-down" class="size-3 transition" x-bind:class="expanded && 'rotate-180'" aria-hidden="true" />
</button>
@endif
</div>
@else
<div class="flex items-center justify-between gap-1 text-[10px]">
<x-jobs.board.person :initials="$card->responsibleInitials()" :name="$card->responsibleFirstName()" />
<div class="flex min-w-0 items-center gap-1">
@if ($card->serviceUnitName !== null)
<span class="truncate rounded bg-neutral-100 px-1.5 py-0.5 font-medium text-neutral-700 dark:bg-[#1e2023] dark:text-neutral-200" title="{{ $card->serviceUnitName }}">{{ $card->serviceUnitName }}</span>
@endif
<x-jobs.board.priority-badge :priority="$card->priority" />
</div>
</div>
<p class="flex flex-wrap items-center gap-1.5 text-[10px] text-neutral-700 dark:text-neutral-200">
@if ($card->isLate)
<span class="inline-flex items-center gap-0.5 font-bold text-red-700 dark:text-red-200">
<x-icon name="exclamation-triangle" class="size-3" aria-hidden="true" />{{ __('jobs.board.late', ['date' => BoardFormat::shortDate($card->dueOn)]) }}
</span>
@else
<span class="font-medium">{{ __('jobs.board.due', ['date' => BoardFormat::shortDate($card->dueOn)]) }}</span>
@endif
<span aria-hidden="true">•</span>
<span>{{ BoardFormat::cardHours($card) }}</span>
</p>
@if ($total > 0)
<div class="border-t border-neutral-200 pt-1 dark:border-[#36393f]">
<button
type="button"
x-on:click="expanded = ! expanded"
x-bind:aria-expanded="expanded.toString()"
aria-controls="tasks-{{ $card->key() }}"
class="flex min-h-6 w-full items-center justify-between rounded px-1.5 text-[11px] font-semibold text-neutral-800 transition hover:bg-neutral-100 focus-visible:outline-2 focus-visible:outline-primary-600 dark:text-neutral-100 dark:hover:bg-[#32353b] dark:focus-visible:outline-primary-300"
>
<span>{{ __('jobs.board.tasks_toggle', ['done' => $done, 'total' => $total]) }}</span>
<x-icon name="chevron-down" class="size-3.5 transition" x-bind:class="expanded && 'rotate-180'" aria-hidden="true" />
</button>
</div>
@endif
@endif
@if ($total > 0)
<div id="tasks-{{ $card->key() }}" x-show="expanded" x-cloak @class(['border-t border-neutral-200 pt-1 dark:border-[#36393f]' => $compact, 'mt-1.5' => ! $compact])>
<x-jobs.board.task-list :card="$card" :can-check="$canCheck" :compact="$compact" />
</div>
@endif
</div>
</article>
@@ -0,0 +1,59 @@
{{--
A small header button that opens a list of choices (menuitemradio):
the urgent threshold and a column's order. Escape and a click outside
close it; focus returns to the button.
Props: `label` (the button's name), `heading`, `options` (value => text),
`current` (value), `method` and `args` (the Livewire call, with the
chosen value last), `active` (highlights the button).
--}}
@props(['id', 'label', 'heading', 'options', 'current', 'method', 'args' => [], 'active' => false])
<div class="relative" x-data="{ open: false }" x-on:keydown.escape.stop="if (open) { open = false; $refs.button.focus(); }" x-on:click.outside="open = false">
<button
type="button"
x-ref="button"
x-on:click="open = ! open; if (open) { $nextTick(() => $refs.menu.querySelector('[aria-checked=true]')?.focus()) }"
x-bind:aria-expanded="open.toString()"
aria-haspopup="menu"
aria-controls="{{ $id }}"
aria-label="{{ $label }}"
title="{{ $label }}"
@class([
'inline-flex size-6 items-center justify-center rounded transition focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-current',
'bg-black/20 ring-1 ring-current/40 dark:bg-white/25' => $active,
'hover:bg-black/15 dark:hover:bg-white/15' => ! $active,
])
>
{{ $slot }}
</button>
<div
id="{{ $id }}"
x-ref="menu"
x-show="open"
x-cloak
role="menu"
aria-label="{{ $heading }}"
class="absolute top-8 right-0 z-50 w-56 space-y-0.5 rounded-xl border border-neutral-300 bg-white p-1.5 text-neutral-900 shadow-2xl dark:border-[#3e4249] dark:bg-[#282a2e] dark:text-neutral-100"
>
<div class="px-2 py-1 text-[10px] font-bold tracking-wider text-neutral-600 uppercase dark:text-neutral-300" aria-hidden="true">{{ $heading }}</div>
@foreach ($options as $value => $text)
<button
type="button"
role="menuitemradio"
aria-checked="{{ $value === $current ? 'true' : 'false' }}"
wire:click="{{ $method }}({{ collect([...$args, $value])->map(fn ($arg) => Js::from($arg))->join(', ') }})"
x-on:click="open = false; $refs.button.focus()"
x-on:keydown.arrow-down.prevent="$el.nextElementSibling?.focus()"
x-on:keydown.arrow-up.prevent="$el.previousElementSibling?.matches('button') && $el.previousElementSibling.focus()"
class="flex w-full items-center justify-between rounded-lg px-2.5 py-1.5 text-left text-xs font-medium transition hover:bg-neutral-100 focus-visible:outline-2 focus-visible:outline-primary-600 dark:hover:bg-[#34373d] dark:focus-visible:outline-primary-300"
>
<span>{{ $text }}</span>
@if ($value === $current)
<x-icon name="check" class="size-4 text-primary-700 dark:text-primary-200" aria-hidden="true" />
@endif
</button>
@endforeach
</div>
</div>
@@ -0,0 +1,105 @@
{{--
A continuing / season job card (docs/ui-kanban-board.md 4.2): the next
open task with a one-click "mark done", lifting tasks into the pipeline
(PIN), and all periods and tasks with a quick add.
--}}
@props(['card', 'compact' => false, 'canMove' => false, 'canColor' => false, 'canCheck' => false, 'canManage' => false])
@php
$total = count($card->tasks);
$done = $card->doneTaskCount();
$next = $card->nextOpenTask();
@endphp
<article
aria-labelledby="card-{{ $card->key() }}-title"
x-data="{ expanded: false }"
class="overflow-hidden rounded-xl border border-neutral-300 bg-white shadow-sm dark:border-[#36393f] dark:bg-[#282a2e]"
>
<x-jobs.board.card-header :card="$card" :can-move="$canMove" :can-color="$canColor" />
<div @class(['space-y-1.5 p-1.5' => $compact, 'space-y-2 p-2.5' => ! $compact])>
<h3 class="m-0" id="card-{{ $card->key() }}-title">
<button
type="button"
id="card-{{ $card->key() }}-open"
wire:click="openJob({{ $card->jobId }})"
title="{{ $card->title }}"
class="block w-full truncate rounded text-left text-[13px] font-bold text-neutral-900 hover:underline focus-visible:outline-2 focus-visible:outline-primary-600 dark:text-white dark:focus-visible:outline-primary-300"
><span class="sr-only">{{ $card->number }} </span>{{ $card->title }}</button>
</h3>
<div class="flex items-center justify-between gap-1 text-[10px]">
<div class="flex min-w-0 items-center gap-1">
<x-jobs.board.person :initials="$card->responsibleInitials()" :name="$card->responsibleFirstName()" />
<span class="truncate rounded bg-purple-100 px-1.5 py-0.5 font-bold text-purple-900 dark:bg-purple-950/90 dark:text-purple-100">{{ __('jobs.board.periods', ['done' => $done, 'total' => $total]) }}</span>
</div>
@if ($compact)
<button
type="button"
x-on:click="expanded = ! expanded"
x-bind:aria-expanded="expanded.toString()"
aria-controls="tasks-{{ $card->key() }}"
aria-label="{{ __('jobs.board.all_periods', ['done' => $done, 'total' => $total]) }}"
class="inline-flex min-h-6 shrink-0 items-center gap-0.5 rounded bg-neutral-100 px-1.5 text-[10px] font-bold text-neutral-800 transition hover:bg-neutral-200 focus-visible:outline-2 focus-visible:outline-primary-600 dark:bg-[#1e2023] dark:text-neutral-100 dark:hover:bg-[#32353b] dark:focus-visible:outline-primary-300"
>
{{ $done }}/{{ $total }}
<x-icon name="chevron-down" class="size-3 transition" x-bind:class="expanded && 'rotate-180'" aria-hidden="true" />
</button>
@endif
</div>
@if (! $compact && $next !== null)
<div class="space-y-1.5 rounded-lg border border-neutral-200 bg-neutral-100 p-2 dark:border-[#36393f] dark:bg-[#1e2023]">
<p class="text-[10px] font-bold tracking-wider text-neutral-700 uppercase dark:text-neutral-200">{{ __('jobs.board.next_up') }}</p>
<p class="text-xs leading-snug font-semibold text-neutral-900 dark:text-neutral-100">{{ $next->title }}</p>
<div class="flex flex-wrap items-center gap-1.5 pt-0.5">
@if ($canCheck)
<button
type="button"
wire:click="setTaskDone({{ $card->jobId }}, {{ $next->id }}, true)"
aria-label="{{ __('jobs.board.mark_done_label', ['task' => $next->title]) }}"
class="inline-flex min-h-6 items-center gap-1 rounded bg-emerald-700 px-2 text-[10px] font-bold text-white transition hover:bg-emerald-800 focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-primary-600 dark:focus-visible:outline-primary-300"
>{{ __('jobs.board.mark_done') }} <x-icon name="check" class="size-3" aria-hidden="true" /></button>
@endif
@if ($canManage)
<button
type="button"
wire:click="pinTask({{ $card->jobId }}, {{ $next->id }}, {{ $next->pinnedToBoard ? 'false' : 'true' }})"
aria-label="{{ $next->pinnedToBoard ? __('jobs.board.unpin_label', ['task' => $next->title]) : __('jobs.board.pin_label', ['task' => $next->title]) }}"
@class([
'inline-flex min-h-6 items-center gap-1 rounded px-2 text-[10px] 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' => $next->pinnedToBoard,
'bg-indigo-600 hover:bg-indigo-700' => ! $next->pinnedToBoard,
])
>
{{ $next->pinnedToBoard ? __('jobs.board.unpin') : __('jobs.board.pin') }}
@unless ($next->pinnedToBoard)
<x-icon name="arrow-up-right" class="size-3" aria-hidden="true" />
@endunless
</button>
@endif
</div>
</div>
@endif
@unless ($compact)
<div class="border-t border-neutral-200 pt-1 dark:border-[#36393f]">
<button
type="button"
x-on:click="expanded = ! expanded"
x-bind:aria-expanded="expanded.toString()"
aria-controls="tasks-{{ $card->key() }}"
class="flex min-h-6 w-full items-center justify-between rounded px-1.5 text-[11px] font-semibold text-neutral-800 transition hover:bg-neutral-100 focus-visible:outline-2 focus-visible:outline-primary-600 dark:text-neutral-100 dark:hover:bg-[#32353b] dark:focus-visible:outline-primary-300"
>
<span>{{ __('jobs.board.all_periods', ['done' => $done, 'total' => $total]) }}</span>
<x-icon name="chevron-down" class="size-3.5 transition" x-bind:class="expanded && 'rotate-180'" aria-hidden="true" />
</button>
</div>
@endunless
<div id="tasks-{{ $card->key() }}" x-show="expanded" x-cloak class="space-y-1.5 border-t border-neutral-200 pt-1 dark:border-[#36393f]">
<x-jobs.board.task-list :card="$card" :can-check="$canCheck" :can-manage="$canManage" ongoing :compact="$compact" />
</div>
</div>
</article>
@@ -0,0 +1,7 @@
{{-- A person on a Kanban card: initials in a ball and the first name. --}}
@props(['initials', 'name' => null])
<span {{ $attributes->class('inline-flex shrink-0 items-center gap-1 rounded bg-neutral-100 px-1.5 py-0.5 font-semibold text-neutral-800 dark:bg-[#1e2023] dark:text-neutral-100') }}>
<span class="flex size-4 items-center justify-center rounded-full bg-primary-600 text-[9px] font-bold text-white" aria-hidden="true">{{ $initials }}</span>
<span>{{ $name ?? '–' }}</span>
</span>
@@ -0,0 +1,22 @@
{{--
A Kanban card's priority badge: the text carries the meaning, the
colour only supports it; "Heti" also gets the striped dot.
--}}
@props(['priority'])
@php
$classes = match ($priority->value) {
'immediate' => 'bg-orange-100 text-red-950 border-orange-400 dark:bg-orange-950 dark:text-orange-100 dark:border-orange-700',
'urgent' => 'bg-red-100 text-red-900 border-red-300 dark:bg-red-950 dark:text-red-100 dark:border-red-800',
'first' => 'bg-amber-100 text-amber-950 border-amber-300 dark:bg-amber-950 dark:text-amber-100 dark:border-amber-800',
'waiting' => 'bg-blue-100 text-blue-900 border-blue-300 dark:bg-blue-950 dark:text-blue-100 dark:border-blue-800',
default => 'bg-emerald-100 text-emerald-900 border-emerald-300 dark:bg-emerald-950 dark:text-emerald-100 dark:border-emerald-800',
};
@endphp
<span {{ $attributes->class(['inline-flex shrink-0 items-center gap-1 rounded border px-1.5 py-0.5 text-[10px] font-bold', $classes]) }}>
@if ($priority->value === 'immediate')
<span class="size-2 rounded-full bg-[repeating-linear-gradient(-45deg,#dc2626_0_5px,#ea580c_5px_10px)]" aria-hidden="true"></span>
@endif
{{ __('jobs.priorities.'.$priority->value) }}
</span>
@@ -0,0 +1,69 @@
{{--
A task of a continuing job lifted into the pipeline (docs/ui-kanban-board.md
4.3): dashed border, indigo bar with "Vapauta", link to the parent job.
Its column follows the task's status.
--}}
@props(['card', 'compact' => false, 'canMove' => false, 'canManage' => false])
@use('App\Modules\Jobs\Presentation\Support\BoardFormat')
<article
aria-labelledby="card-{{ $card->key() }}-title"
class="overflow-hidden rounded-xl border-2 border-dashed border-indigo-400 bg-white shadow-md dark:border-indigo-400/80 dark:bg-[#282a2e]"
>
<div
@if ($canMove) wire:sort:handle @endif
wire:click="openJob({{ $card->jobId }})"
title="{{ __('jobs.board.drag_hint') }}"
@class(['flex items-center justify-between gap-1.5 bg-indigo-700 px-2.5 py-1 text-white select-none', 'cursor-grab active:cursor-grabbing' => $canMove, 'cursor-pointer' => ! $canMove])
>
<div class="flex min-w-0 items-center gap-1 text-[10px] font-extrabold tracking-wide uppercase">
@if ($canMove)
<x-icon name="ellipsis-vertical" class="size-3 shrink-0 opacity-80" aria-hidden="true" />
@endif
<x-icon name="map-pin" class="size-3 shrink-0" aria-hidden="true" />
<span class="truncate">{{ __('jobs.board.task_card') }}</span>
</div>
@if ($canManage)
<button
type="button"
wire:click.stop="pinTask({{ $card->jobId }}, {{ $card->taskId }}, false)"
aria-label="{{ __('jobs.board.unpin_label', ['task' => $card->title]) }}"
class="inline-flex min-h-6 shrink-0 items-center rounded bg-white/20 px-1.5 text-[10px] font-bold transition hover:bg-white/30 focus-visible:outline-2 focus-visible:outline-white"
>{{ __('jobs.board.release') }}</button>
@endif
</div>
<div @class(['space-y-1 p-1.5' => $compact, 'space-y-2 p-2.5' => ! $compact])>
<p class="truncate text-[10px] font-semibold text-indigo-800 dark:text-indigo-200" title="{{ $card->customerName }} • {{ $card->jobName }}">
<x-icon name="link" class="inline size-3" aria-hidden="true" /> {{ $card->customerName }} • {{ $card->jobName }}
</p>
<h3 class="m-0" id="card-{{ $card->key() }}-title">
<button
type="button"
id="card-{{ $card->key() }}-open"
wire:click="openJob({{ $card->jobId }})"
title="{{ $card->title }}"
class="block w-full truncate rounded text-left text-[13px] font-bold text-neutral-900 hover:underline focus-visible:outline-2 focus-visible:outline-primary-600 dark:text-white dark:focus-visible:outline-primary-300"
>{{ $card->title }}</button>
</h3>
<div class="flex items-center justify-between gap-1 text-[10px]">
<x-jobs.board.person :initials="$card->responsibleInitials()" :name="$card->responsibleFirstName()" />
<div class="flex items-center gap-1">
<x-jobs.board.priority-badge :priority="$card->priority" />
@if ($compact)
<span class="font-semibold text-neutral-700 dark:text-neutral-200">{{ BoardFormat::shortDate($card->dueOn) }}</span>
@endif
</div>
</div>
@unless ($compact)
<p class="border-t border-neutral-200 pt-1.5 text-[10px] font-medium text-neutral-700 dark:border-[#36393f] dark:text-neutral-200">
{{ BoardFormat::shortDate($card->dueOn) }} • {{ BoardFormat::cardHours($card) }}
</p>
@endunless
</div>
</article>
@@ -0,0 +1,83 @@
{{--
A card's tasks inside the card: each with a checkbox that marks it done
(or open again). On a continuing job's card each task can also be lifted
into the pipeline as a card of its own (PIN), and new tasks are added
straight from the card.
--}}
@props(['card', 'canCheck' => false, 'canManage' => false, 'ongoing' => false, 'compact' => false])
<ul @class(['space-y-1', 'space-y-1.5' => $ongoing && ! $compact])>
@foreach ($card->tasks as $task)
<li wire:key="board-task-{{ $task->id }}" @class([
'rounded border border-neutral-200 bg-neutral-50 text-[11px] dark:border-[#32353b] dark:bg-[#1b1c1f]',
'flex items-center justify-between gap-1.5 px-2 py-1' => ! $ongoing,
'space-y-1 p-1.5' => $ongoing,
])>
<label class="flex min-w-0 flex-1 cursor-pointer items-center gap-1.5">
<input
type="checkbox"
@checked($task->isDone())
@disabled(! $canCheck)
wire:change="setTaskDone({{ $card->jobId }}, {{ $task->id }}, $event.target.checked)"
class="size-4 shrink-0 rounded border-neutral-500 text-emerald-700 focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-primary-600 dark:border-neutral-400 dark:bg-[#16171a] dark:focus-visible:outline-primary-300"
/>
<span @class([
$ongoing ? 'leading-tight' : 'truncate',
'text-neutral-600 line-through dark:text-neutral-300' => $task->isDone(),
'font-medium text-neutral-800 dark:text-neutral-100' => ! $task->isDone(),
]) @if (! $ongoing) title="{{ $task->title }}" @endif>{{ $task->title }}</span>
</label>
@if ($ongoing)
<div class="flex items-center justify-between gap-1 pl-5">
@if ($canManage)
<button
type="button"
wire:click="pinTask({{ $card->jobId }}, {{ $task->id }}, {{ $task->pinnedToBoard ? 'false' : 'true' }})"
aria-label="{{ $task->pinnedToBoard ? __('jobs.board.unpin_label', ['task' => $task->title]) : __('jobs.board.pin_label', ['task' => $task->title]) }}"
@class([
'inline-flex min-h-6 items-center gap-1 rounded border px-2 text-[10px] font-bold transition hover:opacity-90 focus-visible:outline-2 focus-visible:outline-primary-600 dark:focus-visible:outline-primary-300',
'border-amber-500/60 bg-amber-100 text-amber-900 dark:bg-amber-600/20 dark:text-amber-100' => $task->pinnedToBoard,
'border-indigo-500/60 bg-indigo-100 text-indigo-900 dark:bg-indigo-600/20 dark:text-indigo-100' => ! $task->pinnedToBoard,
])
>
<x-icon name="map-pin" class="size-3" aria-hidden="true" />
{{ $task->pinnedToBoard ? __('jobs.board.unpin') : __('jobs.board.pin') }}
</button>
@endif
@if ($task->assigneeFirstName() !== null)
<span class="text-[10px] font-semibold text-neutral-600 dark:text-neutral-200">{{ $task->assigneeFirstName() }}</span>
@endif
</div>
@elseif ($task->assigneeFirstName() !== null)
<span class="shrink-0 text-[10px] font-semibold text-neutral-600 dark:text-neutral-200">{{ $task->assigneeFirstName() }}</span>
@endif
</li>
@endforeach
</ul>
@if ($ongoing && $canManage)
<form wire:submit="addTask({{ $card->jobId }})" class="space-y-1 border-t border-neutral-200 pt-1 dark:border-[#32353b]">
<div class="flex gap-1">
<label for="new-task-{{ $card->jobId }}" class="sr-only">{{ __('jobs.board.new_task_label', ['job' => $card->number.' '.$card->title]) }}</label>
<input
id="new-task-{{ $card->jobId }}"
type="text"
wire:model="newTaskTitles.{{ $card->jobId }}"
maxlength="255"
placeholder="+ {{ __('jobs.board.new_task') }}…"
class="min-w-0 flex-1 rounded border border-neutral-400 bg-white px-2 py-1 text-[11px] text-neutral-900 placeholder:text-neutral-600 dark:border-[#6b7079] dark:bg-[#16171a] dark:text-white dark:placeholder:text-neutral-300"
/>
<button type="submit" class="min-h-6 shrink-0 rounded bg-primary-600 px-2 text-[11px] 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.board.add_task') }}
</button>
</div>
@error('newTaskTitles.'.$card->jobId)
<p class="text-[11px] font-semibold text-red-700 dark:text-red-200">{{ $message }}</p>
@enderror
<label class="flex cursor-pointer items-center gap-1.5 text-[10px] text-neutral-700 select-none dark:text-neutral-200">
<input type="checkbox" wire:model="newTaskPins.{{ $card->jobId }}" class="size-4 rounded border-neutral-500 text-indigo-600 dark:border-neutral-400 dark:bg-[#16171a]" />
<span>{{ __('jobs.board.pin_new') }}</span>
</label>
</form>
@endif
+48 -10
View File
@@ -134,24 +134,62 @@ it('has no accessibility issues on the Kanban board and no sideways scrolling on
'mobile, dark' => ['mobile', 'dark'], 'mobile, dark' => ['mobile', 'dark'],
]); ]);
it('moves a card to another column with the keyboard', function () { it('moves a card to another column with the keyboard through the job editor', function () {
$select = '#job-status-'.$this->job->id;
visit(route('jobs.board')) visit(route('jobs.board'))
->assertScript('document.querySelector("#column-tentative").textContent.includes("Messuvideo")', true) ->assertScript('document.querySelector("#column-quotes").textContent.includes("Messuvideo")', true)
->select($select, 'order') ->click('#card-job-'.$this->job->id.'-open')
->assertSee('Työ '.$this->job->number.' Messuvideo siirretty tilaan Tilaus.') ->assertScript('document.getElementById("job-editor-dialog").open', true)
->assertScript('document.querySelector("#column-order").textContent.includes("Messuvideo")', true) ->assertScript('document.activeElement.id', 'job-editor-name')
->assertScript('document.activeElement.id', 'job-status-'.$this->job->id) ->assertNoAccessibilityIssues(level: 2)
->assertNoAccessibilityIssues(level: 2); ->select('#job-editor-status', 'order')
->assertSee('Työn '.$this->job->number.' tila: Tilaus.')
->keys('#job-editor-status', 'Escape')
->assertScript('document.getElementById("job-editor-dialog").open', false)
->assertScript('document.querySelector("#column-order").textContent.includes("Messuvideo")', true);
expect($this->job->fresh()->status->value)->toBe('order'); expect($this->job->fresh()->status->value)->toBe('order');
}); });
it('has no accessibility issues in the job editor and the quick intake dialog', function (string $device, string $colorScheme) {
TaskModel::factory()->create(['customer_job_id' => $this->job->id, 'title' => 'Kuvauspäivä']);
$visit = visit(route('jobs.board'));
$visit = $device === 'mobile' ? $visit->on()->mobile() : $visit->on()->desktop();
$visit = $colorScheme === 'dark' ? $visit->inDarkMode() : $visit->inLightMode();
$visit->click('#card-job-'.$this->job->id.'-open')
->assertScript('document.getElementById("job-editor-dialog").open', true)
->assertSee('Kuvauspäivä')
->assertNoJavaScriptErrors()
->assertNoAccessibilityIssues(level: 2)
->keys('#job-editor-name', 'Escape')
->click('Uusi työ / Pikavastaanotto')
->assertScript('document.getElementById("quick-intake-dialog").open', true)
->assertNoAccessibilityIssues(level: 2);
})->with([
'desktop, light' => ['desktop', 'light'],
'desktop, dark' => ['desktop', 'dark'],
'mobile, light' => ['mobile', 'light'],
'mobile, dark' => ['mobile', 'dark'],
]);
it('marks a task done from the task panel of a card', function () {
$this->job->update(['status' => 'in_production']);
$task = TaskModel::factory()->create(['customer_job_id' => $this->job->id, 'title' => 'Leikkaus', 'status' => 'in_progress']);
visit(route('jobs.board'))
->click('[aria-controls="tasks-job-'.$this->job->id.'"]')
->click('#tasks-job-'.$this->job->id.' input[type=checkbox]')
->assertSee('Tehtävä Leikkaus kuitattu valmiiksi.')
->assertNoAccessibilityIssues(level: 2);
expect($task->fresh()->status->value)->toBe('done');
});
it('moves a card by dragging it to another column', function () { it('moves a card by dragging it to another column', function () {
visit(route('jobs.board')) visit(route('jobs.board'))
->on()->desktop() ->on()->desktop()
->drag('[wire\:sort\:item="'.$this->job->id.'"]', '#column-order ul') ->drag('[wire\:sort\:item="job-'.$this->job->id.'"] [wire\:sort\:handle]', '#column-order ul')
->assertSee('siirretty tilaan Tilaus.'); ->assertSee('siirretty tilaan Tilaus.');
expect($this->job->fresh()->status->value)->toBe('order'); expect($this->job->fresh()->status->value)->toBe('order');
+5
View File
@@ -21,6 +21,11 @@ class FakeTaskQueries implements TaskQueries
$this->tasks[$taskId] = new BookableTask($taskId, $jobId, '2026-0001', 'Kampanja', 'Tehtävä '.$taskId, $workTypeId, 'graafinen työ', $jobStatus, TaskStatus::Waiting); $this->tasks[$taskId] = new BookableTask($taskId, $jobId, '2026-0001', 'Kampanja', 'Tehtävä '.$taskId, $workTypeId, 'graafinen työ', $jobStatus, TaskStatus::Waiting);
} }
public function pinnedTaskIds(int $jobId): array
{
return [];
}
public function tasksOf(int $jobId): array public function tasksOf(int $jobId): array
{ {
return []; return [];
+195 -19
View File
@@ -1,7 +1,11 @@
<?php <?php
use App\Models\User; use App\Models\User;
use App\Modules\Customers\Infrastructure\Persistence\Eloquent\CustomerModel;
use App\Modules\Jobs\Domain\Enums\BoardColumn;
use App\Modules\Jobs\Domain\Enums\BoardDensity;
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\CustomerJobModel; use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\CustomerJobModel;
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\TaskModel;
use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use Livewire\Livewire; use Livewire\Livewire;
@@ -13,68 +17,237 @@ beforeEach(function () {
$this->actingAs($this->employee); $this->actingAs($this->employee);
}); });
it('shows the Kanban columns in order with my jobs, without archived ones', function () { /**
CustomerJobModel::factory()->create(['name' => 'Tilattu työ', 'status' => 'order', 'responsible_user_id' => $this->employee->id]); * @return array<string, list<string>> card keys by column
*/
function boardColumnKeys(mixed $board): array
{
return array_map(fn (array $cards): array => array_map(fn ($card): string => $card->key(), $cards), $board->instance()->columns);
}
it('shows the daily pipeline columns in order with my jobs, without archived ones and the quick-sale job', function () {
$mine = CustomerJobModel::factory()->create(['name' => 'Tilattu työ', 'status' => 'order', 'responsible_user_id' => $this->employee->id]);
CustomerJobModel::factory()->create(['name' => 'Arkistoitu työ', 'status' => 'archived', 'responsible_user_id' => $this->employee->id]); CustomerJobModel::factory()->create(['name' => 'Arkistoitu työ', 'status' => 'archived', 'responsible_user_id' => $this->employee->id]);
CustomerJobModel::factory()->create(['name' => 'Pikamyynnit', 'status' => 'in_production', 'responsible_user_id' => $this->employee->id, 'quick_sale_year' => 2026]);
CustomerJobModel::factory()->create(['name' => 'Muiden työ', 'status' => 'order']); CustomerJobModel::factory()->create(['name' => 'Muiden työ', 'status' => 'order']);
$board = Livewire::test('jobs::board') $board = Livewire::test('jobs::board')
->assertSee('Tilattu työ') ->assertSee('Tilattu työ')
->assertDontSee('Arkistoitu työ') ->assertDontSee('Arkistoitu työ')
->assertDontSee('Pikamyynnit')
->assertDontSee('Muiden työ') ->assertDontSee('Muiden työ')
->assertSeeInOrder(['Prospekti', 'Alustava', 'Tarjouspyyntö', 'Tilaus', 'Tuotannossa', 'Keskeytetty', 'Valmis', 'Lasku luotu', 'Laskutettu', 'Jatkuvat / Kausi']) ->assertSeeInOrder(['Tarjoukset', 'Jonossa', 'Työn alla', 'Työn alla • Kiire', 'Odottaa asiakasta', 'Valmis • Laskuta', 'Jatkuvat &amp; Kausi'], false)
->set('mine', false) ->assertDontSeeHtml('id="job-status-');
->assertSee('Muiden työ');
expect(array_keys($board->instance()->board))->not->toContain('archived') expect(array_keys($board->instance()->columns))->toBe(['quotes', 'order', 'in_production', 'in_production_urgent', 'on_hold', 'done', 'ongoing'])
->and(array_map(fn ($job) => $job->name, $board->instance()->board['order']))->toContain('Tilattu työ', 'Muiden työ'); ->and(boardColumnKeys($board)['order'])->toBe(['job-'.$mine->id]);
$board->set('board', 'all')->assertSee('Muiden työ');
$this->get(route('jobs.board'))->assertOk()->assertSee('Kanban'); $this->get(route('jobs.board'))->assertOk()->assertSee('Kanban');
}); });
it('moves a job with the select or by dropping it, and records the change', function () { it('shows the sales and full pipelines with their own columns', function () {
$board = Livewire::test('jobs::board')->call('setView', 'sales');
expect(array_keys($board->instance()->columns))->toBe(['prospect', 'tentative', 'quote_request']);
$board->call('setView', 'full');
expect(array_keys($board->instance()->columns))->toContain('invoiced', 'billed', 'ongoing')->not->toContain('quotes');
});
it('filters by person, service line, urgency and lateness', function () {
$colleague = User::factory()->create(['name' => 'Anna Korhonen']);
$urgent = CustomerJobModel::factory()->create(['name' => 'Kiiretyö', 'status' => 'in_production', 'priority' => 'urgent', 'responsible_user_id' => $colleague->id]);
$late = CustomerJobModel::factory()->create(['name' => 'Myöhässä oleva', 'status' => 'order', 'due_on' => now()->subDays(3), 'responsible_user_id' => $colleague->id]);
$board = Livewire::test('jobs::board')
->assertSee('Henkilö: Anna Korhonen')
->set('board', 'person-'.$colleague->id)
->assertSee('Kiiretyö')
->assertSee('Myöhässä oleva')
->toggle('onlyUrgent')
->assertSee('Kiiretyö')
->assertDontSee('Myöhässä oleva')
->assertSee('Näytetään 1 kortti');
$board->toggle('onlyUrgent')->toggle('onlyLate')
->assertSee('Myöhässä oleva')
->assertDontSee('Kiiretyö');
expect($urgent->id)->not->toBe($late->id);
});
it('moves a job to another column by dropping it, and records the change', function () {
$job = CustomerJobModel::factory()->create(['name' => 'Messuvideo', 'status' => 'tentative', 'responsible_user_id' => $this->employee->id]); $job = CustomerJobModel::factory()->create(['name' => 'Messuvideo', 'status' => 'tentative', 'responsible_user_id' => $this->employee->id]);
Livewire::test('jobs::board') Livewire::test('jobs::board')
->call('moveJob', $job->id, 'order') ->call('moveDropped', 'job-'.$job->id, 0, 'order')
->assertSee('Työ '.$job->number.' Messuvideo siirretty tilaan Tilaus.') ->assertSee('Työ '.$job->number.' Messuvideo siirretty tilaan Tilaus.')
->call('moveDropped', (string) $job->id, 0, 'in_production') ->call('moveDropped', 'job-'.$job->id, 0, 'in_production')
->assertSee('siirretty tilaan Tuotannossa.'); ->assertSee('siirretty tilaan Tuotannossa.');
expect($job->fresh()->status->value)->toBe('in_production') expect($job->fresh()->status->value)->toBe('in_production')
->and(DB::table('customer_job_changes')->where('customer_job_id', $job->id)->where('field', 'status')->count())->toBe(2); ->and(DB::table('customer_job_changes')->where('customer_job_id', $job->id)->where('field', 'status')->count())->toBe(2);
}); });
it('raises the priority when a job is dropped into the urgent column, by the user\'s threshold', function () {
$job = CustomerJobModel::factory()->create(['name' => 'Juliste', 'status' => 'in_production', 'priority' => 'normal', 'responsible_user_id' => $this->employee->id]);
$board = Livewire::test('jobs::board')
->call('setUrgentThreshold', 'first')
->call('moveDropped', 'job-'.$job->id, 0, 'in_production_urgent')
->assertSee('siirretty Kiire-listaan (prioriteetti nostettu: Ensin)');
expect($job->fresh()->priority->value)->toBe('first')
->and(boardColumnKeys($board)['in_production_urgent'])->toBe(['job-'.$job->id]);
$board->call('moveDropped', 'job-'.$job->id, 0, 'in_production');
expect($job->fresh()->priority->value)->toBe('normal');
});
it('stores the drop order inside a column and switches a due-date column to own order', function () {
$first = CustomerJobModel::factory()->create(['status' => 'order', 'due_on' => now()->addDays(2), 'responsible_user_id' => $this->employee->id]);
$second = CustomerJobModel::factory()->create(['status' => 'order', 'due_on' => now()->addDay(), 'responsible_user_id' => $this->employee->id]);
$board = Livewire::test('jobs::board')->call('setColumnSort', 'order', 'due_date');
expect(boardColumnKeys($board)['order'])->toBe(['job-'.$second->id, 'job-'.$first->id]);
$board->call('moveDropped', 'job-'.$second->id, 1, 'order')
->assertSee('järjestys: oma järjestys');
expect(boardColumnKeys($board)['order'])->toBe(['job-'.$first->id, 'job-'.$second->id])
->and(DB::table('job_board_preferences')->where('user_id', $this->employee->id)->value('column_sorts'))->toBe('{"order":"manual"}');
});
it('lets only management and the biller move a job to a billing status', function () { it('lets only management and the biller move a job to a billing status', function () {
$job = CustomerJobModel::factory()->create(['status' => 'done', 'responsible_user_id' => $this->employee->id]); $job = CustomerJobModel::factory()->create(['status' => 'done', 'responsible_user_id' => $this->employee->id]);
Livewire::test('jobs::board') Livewire::test('jobs::board')
->call('moveJob', $job->id, 'invoiced') ->call('setView', 'full')
->call('moveDropped', 'job-'.$job->id, 0, 'invoiced')
->assertSee('voi asettaa vain johto tai työn laskuttaja'); ->assertSee('voi asettaa vain johto tai työn laskuttaja');
expect($job->fresh()->status->value)->toBe('done'); expect($job->fresh()->status->value)->toBe('done');
$job->update(['biller_user_id' => $this->employee->id]); $job->update(['biller_user_id' => $this->employee->id]);
Livewire::test('jobs::board')->call('moveJob', $job->id, 'invoiced'); Livewire::test('jobs::board')->call('setView', 'full')->call('moveDropped', 'job-'.$job->id, 0, 'invoiced');
expect($job->fresh()->status->value)->toBe('invoiced'); expect($job->fresh()->status->value)->toBe('invoiced');
}); });
it('ignores unknown statuses, archiving and jobs not on the board', function () { it('keeps continuing jobs in their own column', function () {
$ongoing = CustomerJobModel::factory()->create(['name' => 'Futsal LIVE', 'status' => 'ongoing', 'responsible_user_id' => $this->employee->id]);
$order = CustomerJobModel::factory()->create(['status' => 'order', 'responsible_user_id' => $this->employee->id]);
$board = Livewire::test('jobs::board')
->call('moveDropped', 'job-'.$ongoing->id, 0, 'in_production')
->assertSee('Korttia ei voi siirtää listaan Työn alla.')
->call('moveDropped', 'job-'.$order->id, 0, 'ongoing')
->assertSee('Korttia ei voi siirtää listaan Jatkuvat &amp; Kausi.', false);
expect($ongoing->fresh()->status->value)->toBe('ongoing')
->and($order->fresh()->status->value)->toBe('order')
->and(boardColumnKeys($board)['ongoing'])->toBe(['job-'.$ongoing->id]);
});
it('ignores unknown columns and cards not on the board', function () {
$job = CustomerJobModel::factory()->create(['status' => 'order', 'responsible_user_id' => $this->employee->id]); $job = CustomerJobModel::factory()->create(['status' => 'order', 'responsible_user_id' => $this->employee->id]);
$other = CustomerJobModel::factory()->create(['status' => 'order']); $other = CustomerJobModel::factory()->create(['status' => 'order']);
Livewire::test('jobs::board') Livewire::test('jobs::board')
->call('moveJob', $job->id, 'nonsense') ->call('moveDropped', 'job-'.$job->id, 0, 'nonsense')
->assertSee('Työtä ei siirretty.') ->assertSee('Työtä ei siirretty.')
->call('moveJob', $job->id, 'archived') ->call('moveDropped', 'job-'.$job->id, 0, 'archived')
->call('moveJob', $other->id, 'done') ->call('moveDropped', 'job-'.$job->id, 0, 'invoiced')
->call('moveJob', 999, 'done'); ->call('moveDropped', 'job-'.$other->id, 0, 'done')
->call('moveDropped', 'job-999', 0, 'done');
expect($job->fresh()->status->value)->toBe('order') expect($job->fresh()->status->value)->toBe('order')
->and($other->fresh()->status->value)->toBe('order'); ->and($other->fresh()->status->value)->toBe('order');
}); });
it('shows a subcontractor only their cards, without moving', function () { it('marks a task done from the card and opens it again', function () {
$job = CustomerJobModel::factory()->create(['status' => 'in_production', 'responsible_user_id' => $this->employee->id]);
$task = TaskModel::factory()->create(['customer_job_id' => $job->id, 'title' => 'Vedos asiakkaalle', 'status' => 'in_progress']);
$board = Livewire::test('jobs::board')
->assertSee('Tehtävät (0/1)')
->call('setTaskDone', $job->id, $task->id, true)
->assertSee('Tehtävä Vedos asiakkaalle kuitattu valmiiksi.')
->assertSee('Tehtävät (1/1)');
expect($task->fresh()->status->value)->toBe('done');
$board->call('setTaskDone', $job->id, $task->id, false);
expect($task->fresh()->status->value)->toBe('in_progress');
});
it('lifts a continuing job\'s task into the pipeline and releases it', function () {
$job = CustomerJobModel::factory()->create(['name' => 'Somemarkkinointi', 'status' => 'ongoing', 'responsible_user_id' => $this->employee->id]);
$task = TaskModel::factory()->create(['customer_job_id' => $job->id, 'title' => 'Joulukampanja', 'status' => 'waiting']);
$board = Livewire::test('jobs::board')
->assertSee('Seuraava vuorossa:')
->call('pinTask', $job->id, $task->id, true)
->assertSee('Tehtävä Joulukampanja nostettu työputkeen.')
->assertSee('Tehtävä • PIN');
expect(boardColumnKeys($board)['order'])->toBe(['task-'.$task->id]);
$board->call('moveDropped', 'task-'.$task->id, 0, 'in_production');
expect($task->fresh()->status->value)->toBe('in_progress');
$board->call('pinTask', $job->id, $task->id, false);
expect((bool) $task->fresh()->is_pinned_to_board)->toBeFalse();
});
it('adds a task to a continuing job straight from its card', function () {
$job = CustomerJobModel::factory()->create(['status' => 'ongoing', 'responsible_user_id' => $this->employee->id]);
$unitId = DB::table('customer_job_service_unit')->where('customer_job_id', $job->id)->value('service_unit_id');
Livewire::test('jobs::board')
->call('addTask', $job->id)
->assertSee('Anna tehtävän nimi.')
->set('newTaskTitles.'.$job->id, 'Ottelu 12.12.')
->set('newTaskPins.'.$job->id, true)
->call('addTask', $job->id)
->assertSee('Tehtävä Ottelu 12.12. lisätty');
$task = TaskModel::query()->where('customer_job_id', $job->id)->sole();
expect($task->title)->toBe('Ottelu 12.12.')
->and((bool) $task->is_pinned_to_board)->toBeTrue()
->and($task->assignee_user_id)->toBe($this->employee->id)
->and($unitId)->not->toBeNull();
});
it('keeps each user\'s column colours and density their own and saves the customer colour for everyone', function () {
$customer = CustomerModel::factory()->create(['name' => 'Ässä KP Oy']);
CustomerJobModel::factory()->create(['customer_id' => $customer->id, 'status' => 'order', 'responsible_user_id' => $this->employee->id]);
$board = Livewire::test('jobs::board')
->call('setColumnColor', 'order', '#B91C1C')
->assertSee('Listan Jonossa otsikkoväri tallennettu.')
->call('setDensity', 'compact')
->call('setCustomerColor', $customer->id, '#991b1b')
->assertSee('Asiakkaan Ässä KP Oy väri tallennettu.')
->assertSeeHtml('background-color: #991b1b; color: #ffffff')
->call('setColumnColor', 'order', 'javascript:alert(1)')
->assertSee('Väri ei kelpaa.');
expect($board->instance()->columnStyle(BoardColumn::Order)['header'])->toBe('#b91c1c')
->and($board->instance()->preferences->density)->toBe(BoardDensity::Compact);
expect($customer->fresh()->header_color)->toBe('#991b1b');
$this->actingAs(User::factory()->create());
$otherBoard = Livewire::test('jobs::board');
expect($otherBoard->instance()->columnStyle(BoardColumn::Order)['header'])->toBe('#23476a')
->and($otherBoard->instance()->preferences->density)->toBe(BoardDensity::Normal);
$this->actingAs($this->employee);
Livewire::test('jobs::board')->call('setColumnColor', 'order', null)->assertSee('palautettu oletukseksi');
});
it('shows a subcontractor only their cards, without moving or changing colours', function () {
$subcontractor = User::factory()->subcontractor()->create(); $subcontractor = User::factory()->subcontractor()->create();
$theirs = CustomerJobModel::factory()->withMembers([$subcontractor->id])->create(['name' => 'Alihankintatyö', 'status' => 'order']); $theirs = CustomerJobModel::factory()->withMembers([$subcontractor->id])->create(['name' => 'Alihankintatyö', 'status' => 'order']);
CustomerJobModel::factory()->create(['name' => 'Muu työ', 'status' => 'order']); CustomerJobModel::factory()->create(['name' => 'Muu työ', 'status' => 'order']);
@@ -85,8 +258,11 @@ it('shows a subcontractor only their cards, without moving', function () {
->assertSee('Alihankintatyö') ->assertSee('Alihankintatyö')
->assertDontSee('Muu työ') ->assertDontSee('Muu työ')
->assertDontSeeHtml('wire:sort=') ->assertDontSeeHtml('wire:sort=')
->call('moveJob', $theirs->id, 'done') ->assertDontSeeHtml('id="board-select"')
->call('moveDropped', 'job-'.$theirs->id, 0, 'done')
->assertForbidden(); ->assertForbidden();
Livewire::test('jobs::board')->call('setCustomerColor', $theirs->customer_id, '#000000')->assertForbidden();
expect($theirs->fresh()->status->value)->toBe('order'); expect($theirs->fresh()->status->value)->toBe('order');
}); });
@@ -0,0 +1,128 @@
<?php
use App\Models\User;
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\CustomerJobModel;
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\TaskModel;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Livewire\Livewire;
uses(RefreshDatabase::class);
beforeEach(function () {
$this->employee = User::factory()->create();
$this->actingAs($this->employee);
$this->job = CustomerJobModel::factory()->create(['name' => 'Kylkiteippaukset', 'status' => 'order', 'responsible_user_id' => $this->employee->id]);
});
it('opens a job from the board and saves its details without leaving the board', function () {
Livewire::test('jobs::board')
->call('openJob', $this->job->id)
->assertDispatched('open-job-editor', jobId: $this->job->id);
Livewire::test('jobs::job-editor')
->dispatch('open-job-editor', jobId: $this->job->id)
->assertSet('form.name', 'Kylkiteippaukset')
->assertSee($this->job->number)
->set('form.name', 'Pakettiauton kylkiteippaukset')
->set('form.instructions', 'Asiakkaan logo vektorina')
->call('save')
->assertHasNoErrors()
->assertDispatched('job-saved')
->assertDispatched('job-editor-saved');
expect($this->job->fresh()->name)->toBe('Pakettiauton kylkiteippaukset')
->and($this->job->fresh()->instructions)->toBe('Asiakkaan logo vektorina');
});
it('changes the status and priority at once and records them', function () {
Livewire::test('jobs::job-editor')
->dispatch('open-job-editor', jobId: $this->job->id)
->call('changeStatus', 'in_production')
->assertSee('tila: Tuotannossa')
->call('changePriority', 'urgent')
->assertSee('prioriteetti: Kiire');
expect($this->job->fresh()->status->value)->toBe('in_production')
->and($this->job->fresh()->priority->value)->toBe('urgent')
->and(DB::table('customer_job_changes')->where('customer_job_id', $this->job->id)->whereIn('field', ['status', 'priority'])->count())->toBe(2);
});
it('keeps an employee from billing statuses and from opening the lock', function () {
$this->job->update(['status' => 'done']);
Livewire::test('jobs::job-editor')
->dispatch('open-job-editor', jobId: $this->job->id)
->assertSee('tunnit ja kulut on lukittu')
->assertDontSee('Avaa lukitus (johto)')
->call('changeStatus', 'invoiced')
->assertHasErrors('form.status')
->call('changeStatus', 'in_production')
->assertHasErrors('form.status');
expect($this->job->fresh()->status->value)->toBe('done');
$this->actingAs(User::factory()->management()->create());
Livewire::test('jobs::job-editor')
->dispatch('open-job-editor', jobId: $this->job->id)
->call('unlock');
expect($this->job->fresh()->status->value)->toBe('in_production');
});
it('edits, adds and marks tasks done in the editor', function () {
$task = TaskModel::factory()->create(['customer_job_id' => $this->job->id, 'title' => 'Vedos', 'status' => 'waiting']);
$editor = Livewire::test('jobs::job-editor')
->dispatch('open-job-editor', jobId: $this->job->id)
->call('updateTaskField', $task->id, 'title', 'Vedos asiakkaalle')
->call('updateTaskField', $task->id, 'due_on', '2026-12-16')
->call('setTaskDone', $task->id, true)
->set('newTaskTitle', 'Asennus')
->call('addTask')
->assertHasNoErrors()
->assertSee('Tehtävä Asennus lisätty.');
expect($task->fresh()->title)->toBe('Vedos asiakkaalle')
->and($task->fresh()->due_on?->format('Y-m-d'))->toBe('2026-12-16')
->and($task->fresh()->status->value)->toBe('done')
->and(TaskModel::query()->where('customer_job_id', $this->job->id)->where('title', 'Asennus')->value('assignee_user_id'))->toBe($this->employee->id);
$editor->call('updateTaskField', $task->id, 'nonsense', 'x');
expect($task->fresh()->title)->toBe('Vedos asiakkaalle');
});
it('hides quote amounts without the quotes permission', function () {
$this->job->update(['quoted_amount_cents' => 123400]);
Livewire::test('jobs::job-editor')
->dispatch('open-job-editor', jobId: $this->job->id)
->assertSee('Tarjous- ja laskutussummat on piilotettu')
->assertDontSeeHtml('id="job-editor-quoted"');
$this->actingAs(User::factory()->management()->create());
Livewire::test('jobs::job-editor')
->dispatch('open-job-editor', jobId: $this->job->id)
->assertSeeHtml('id="job-editor-quoted"');
});
it('lets a subcontractor only look at their own job and tick its tasks', function () {
$subcontractor = User::factory()->subcontractor()->create();
$theirs = CustomerJobModel::factory()->withMembers([$subcontractor->id])->create(['status' => 'in_production']);
$task = TaskModel::factory()->create(['customer_job_id' => $theirs->id, 'status' => 'in_progress']);
$this->actingAs($subcontractor);
Livewire::test('jobs::job-editor')
->dispatch('open-job-editor', jobId: $this->job->id)
->assertForbidden();
Livewire::test('jobs::job-editor')
->dispatch('open-job-editor', jobId: $theirs->id)
->assertSee('Voit kuitata tehtäviä')
->call('setTaskDone', $task->id, true)
->call('save')
->assertForbidden();
expect($task->fresh()->status->value)->toBe('done');
});
@@ -78,17 +78,17 @@ it('shows the quoted amount to an employee with the quotes permission', function
it('records when a job is done and clears it when management opens the lock', function () { it('records when a job is done and clears it when management opens the lock', function () {
$this->actingAs(User::factory()->management()->create()); $this->actingAs(User::factory()->management()->create());
Livewire::test('jobs::board')->set('mine', false)->call('moveJob', $this->job->id, 'done'); Livewire::test('jobs::board')->set('board', 'all')->call('setView', 'full')->call('moveDropped', 'job-'.$this->job->id, 0, 'done');
$completedAt = $this->job->refresh()->completed_at; $completedAt = $this->job->refresh()->completed_at;
expect($completedAt)->not->toBeNull(); expect($completedAt)->not->toBeNull();
Livewire::test('jobs::board')->set('mine', false)->call('moveJob', $this->job->id, 'invoiced'); Livewire::test('jobs::board')->set('board', 'all')->call('setView', 'full')->call('moveDropped', 'job-'.$this->job->id, 0, 'invoiced');
expect($this->job->refresh()->completed_at?->equalTo($completedAt))->toBeTrue(); expect($this->job->refresh()->completed_at?->equalTo($completedAt))->toBeTrue();
$this->get(route('jobs.show', $this->job->id))->assertSee('Valmistunut'); $this->get(route('jobs.show', $this->job->id))->assertSee('Valmistunut');
Livewire::test('jobs::board')->set('mine', false)->call('moveJob', $this->job->id, 'in_production'); Livewire::test('jobs::board')->set('board', 'all')->call('setView', 'full')->call('moveDropped', 'job-'.$this->job->id, 0, 'in_production');
expect($this->job->refresh()->completed_at)->toBeNull(); expect($this->job->refresh()->completed_at)->toBeNull();
}); });
@@ -88,3 +88,40 @@ it('keeps subcontractors out and shows the menu link only to those who may open
$this->get(route('jobs.quick'))->assertForbidden(); $this->get(route('jobs.quick'))->assertForbidden();
$this->get(route('jobs.index'))->assertDontSee('Pikavastaanotto'); $this->get(route('jobs.index'))->assertDontSee('Pikavastaanotto');
}); });
it('opens a job from the board\'s dialog with a new contact person, status and priority', function () {
Livewire::test('jobs::quick', ['inDialog' => true])
->call('selectCustomer', $this->customer->id)
->set('form.adding_contact', true)
->set('form.name', 'Pakettiauton kylkiteippaukset')
->set('form.service_unit_id', (string) $this->unit->id)
->call('save')
->assertHasErrors('form.new_contact_name')
->set('form.new_contact_name', 'Ville Virtanen')
->set('form.new_contact_phone', '040 123 4567')
->set('form.status', 'in_production')
->set('form.priority', 'urgent')
->call('save')
->assertHasNoErrors()
->assertDispatched('quick-job-created', status: 'in_production')
->assertDispatched('job-editor-saved');
$job = CustomerJobModel::query()->sole();
$contactId = DB::table('customer_contacts')->where('customer_id', $this->customer->id)->where('name', 'Ville Virtanen')->value('id');
expect($job->status->value)->toBe('in_production')
->and($job->priority->value)->toBe('urgent')
->and($job->customer_contact_id)->toBe($contactId);
});
it('refuses initial statuses past production', function () {
Livewire::test('jobs::quick')
->call('selectCustomer', $this->customer->id)
->set('form.name', 'Valmis jo')
->set('form.service_unit_id', (string) $this->unit->id)
->set('form.status', 'done')
->call('save')
->assertHasErrors('form.status');
expect(CustomerJobModel::query()->count())->toBe(0);
});
@@ -110,15 +110,15 @@ it('lets only management move a done job back, which opens its lock', function (
$this->actingAs($this->employee); $this->actingAs($this->employee);
Livewire::test('jobs::board') Livewire::test('jobs::board')
->set('mine', false) ->set('board', 'all')->call('setView', 'full')
->call('moveJob', $job->id, 'in_production') ->call('moveDropped', 'job-'.$job->id, 0, 'in_production')
->assertSet('statusMessage', fn (string $message) => str_contains($message, 'lukituksen voi avata vain johto')); ->assertSet('statusMessage', fn (string $message) => str_contains($message, 'lukituksen voi avata vain johto'));
expect($job->refresh()->status)->toBe(JobStatus::Done); expect($job->refresh()->status)->toBe(JobStatus::Done);
$this->actingAs(User::factory()->management()->create()); $this->actingAs(User::factory()->management()->create());
Livewire::test('jobs::board')->set('mine', false)->call('moveJob', $job->id, 'in_production'); Livewire::test('jobs::board')->set('board', 'all')->call('setView', 'full')->call('moveDropped', 'job-'.$job->id, 0, 'in_production');
expect($job->refresh()->status)->toBe(JobStatus::InProduction); expect($job->refresh()->status)->toBe(JobStatus::InProduction);