- 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]>
134 lines
4.7 KiB
PHP
134 lines
4.7 KiB
PHP
<?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>
|