- Dark theme page background is #5a5e60; text on it is lifted to zinc-200 / primary-100 and TallStackUI's dark labels, hints and checkbox labels are lightened so everything stays at 4.5:1. - Shared HexColor picks white or black text by the higher WCAG contrast; a native-dialog colour picker and a large work dialog component. - Customers get a header colour (customers.header_color), set on the customer page. - New job status Jatkuvat / Kausi (ongoing): open, never late, billed monthly like running jobs. - Kanban model: board columns and views, urgent threshold, per-user board preferences (density, column colours and sort), card positions, tasks of continuing jobs pinned to the board, MoveBoardCard and board queries with logged hours from TimeTracking. Co-Authored-By: Claude Opus 5.5 <[email protected]>
245 lines
9.4 KiB
PHP
245 lines
9.4 KiB
PHP
<?php
|
|
|
|
use App\Modules\Expenses\Application\Contracts\ExpenseJobs;
|
|
use App\Modules\Expenses\Application\Contracts\ExpenseQueries;
|
|
use App\Modules\Expenses\Application\DTOs\ExpenseJob;
|
|
use App\Modules\Expenses\Application\DTOs\ExpenseSummary;
|
|
use App\Modules\Expenses\Application\UseCases\RemoveExpense;
|
|
use App\Modules\Expenses\Domain\Exceptions\ExpenseLocked;
|
|
use App\Modules\Expenses\Domain\Exceptions\ExpenseNotFound;
|
|
use App\Modules\Expenses\Presentation\Livewire\Concerns\ShowsExpenses;
|
|
use Livewire\Attributes\Computed;
|
|
use Livewire\Attributes\Locked;
|
|
use Livewire\Component;
|
|
|
|
/**
|
|
* The expenses of one customer job. Amounts of others' expenses are shown
|
|
* only with the expenses permission; everyone sees their own.
|
|
*/
|
|
new class extends Component
|
|
{
|
|
use ShowsExpenses;
|
|
|
|
#[Locked]
|
|
public int $jobId;
|
|
|
|
#[Locked]
|
|
public ?int $removalExpenseId = null;
|
|
|
|
public string $statusMessage = '';
|
|
|
|
public function mount(ExpenseJobs $jobs, int $job): void
|
|
{
|
|
$this->authorize('expenses.record');
|
|
$this->authorize('jobs.view-job', $job);
|
|
|
|
abort_if($jobs->find($job) === null, 404);
|
|
|
|
$this->jobId = $job;
|
|
}
|
|
|
|
#[Computed]
|
|
public function job(): ExpenseJob
|
|
{
|
|
return app(ExpenseJobs::class)->find($this->jobId) ?? abort(404);
|
|
}
|
|
|
|
/**
|
|
* @return list<ExpenseSummary>
|
|
*/
|
|
#[Computed]
|
|
public function expenses(): array
|
|
{
|
|
return app(ExpenseQueries::class)->forJob($this->jobId);
|
|
}
|
|
|
|
#[Computed]
|
|
public function canSeeTotals(): bool
|
|
{
|
|
return auth()->user()?->can('money.expenses') ?? false;
|
|
}
|
|
|
|
/**
|
|
* @return array{cost: int, billed: int}
|
|
*/
|
|
#[Computed]
|
|
public function totals(): array
|
|
{
|
|
return [
|
|
'cost' => array_sum(array_map(fn (ExpenseSummary $expense): int => $expense->costCents, $this->expenses)),
|
|
'billed' => array_sum(array_map(fn (ExpenseSummary $expense): int => $expense->billedAmountCents ?? 0, $this->expenses)),
|
|
];
|
|
}
|
|
|
|
public function confirmRemoval(int $expenseId): void
|
|
{
|
|
$expense = $this->expense($expenseId);
|
|
|
|
if ($expense === null || ! $this->canChange($expense)) {
|
|
return;
|
|
}
|
|
|
|
$this->removalExpenseId = $expenseId;
|
|
|
|
$this->js("document.getElementById('remove-expense-dialog').showModal()");
|
|
}
|
|
|
|
public function removeExpense(RemoveExpense $removeExpense): void
|
|
{
|
|
$expense = $this->expense((int) $this->removalExpenseId);
|
|
|
|
if ($expense !== null) {
|
|
$this->authorize('expenses.change', [$expense->userId, $expense->recordedBy]);
|
|
|
|
try {
|
|
$removeExpense->execute($expense->id);
|
|
$this->statusMessage = __('expenses.removed', ['expense' => $this->summaryText($expense)]);
|
|
} catch (ExpenseLocked) {
|
|
$this->statusMessage = __('expenses.errors.locked');
|
|
} catch (ExpenseNotFound) {
|
|
$this->statusMessage = __('expenses.errors.not_found');
|
|
}
|
|
}
|
|
|
|
$this->reset('removalExpenseId');
|
|
unset($this->expenses, $this->totals);
|
|
|
|
$this->js("document.getElementById('remove-expense-dialog').close(); document.getElementById('expenses-heading').focus()");
|
|
}
|
|
|
|
/**
|
|
* @return list<array{index: string, label: string, sortable: bool, align?: string}>
|
|
*/
|
|
public function headers(): array
|
|
{
|
|
return [
|
|
['index' => 'spentOn', 'label' => __('expenses.fields.spent_on'), 'sortable' => false],
|
|
['index' => 'what', 'label' => __('expenses.fields.what'), 'sortable' => false],
|
|
['index' => 'user', 'label' => __('expenses.fields.user'), 'sortable' => false],
|
|
['index' => 'cost', 'label' => __('expenses.fields.cost_column'), 'sortable' => false, 'align' => 'right'],
|
|
['index' => 'billed', 'label' => __('expenses.fields.billed_column'), 'sortable' => false, 'align' => 'right'],
|
|
['index' => 'actions', 'label' => __('expenses.actions'), 'sortable' => false],
|
|
];
|
|
}
|
|
|
|
public function render(): mixed
|
|
{
|
|
return $this->view()->title(__('expenses.job_page.title', ['job' => $this->job->label()]));
|
|
}
|
|
|
|
private function expense(int $expenseId): ?ExpenseSummary
|
|
{
|
|
return collect($this->expenses)->firstWhere('id', $expenseId);
|
|
}
|
|
};
|
|
?>
|
|
|
|
@php($job = $this->job)
|
|
|
|
<div class="mx-auto max-w-5xl space-y-6 p-4 sm:p-6">
|
|
<div class="space-y-2">
|
|
<x-page-title icon="receipt-refund">{{ __('expenses.job_page.title', ['job' => $job->label()]) }}</x-page-title>
|
|
<x-link :href="route('jobs.show', $job->id)" navigate class="text-sm">{{ __('expenses.job_page.back_to_job') }}</x-link>
|
|
</div>
|
|
|
|
<p role="status" aria-live="polite" class="min-h-5 text-sm">{{ $statusMessage }}</p>
|
|
|
|
@if (session('status'))
|
|
<x-alert role="status" color="green" light icon="check-circle" :text="session('status')" />
|
|
@endif
|
|
|
|
@if ($job->isLocked)
|
|
<p class="flex items-start gap-2 rounded-lg border border-zinc-300 p-3 text-sm dark:border-zinc-600">
|
|
<x-icon name="lock-closed" class="size-5 shrink-0" aria-hidden="true" />
|
|
{{ __('expenses.locked') }}
|
|
</p>
|
|
@else
|
|
<x-button :href="route('expenses.create', $job->id)" wire:navigate icon="plus" :text="__('expenses.add')" />
|
|
@endif
|
|
|
|
<section aria-labelledby="expenses-heading" class="space-y-3">
|
|
<h2 id="expenses-heading" tabindex="-1" class="text-xl font-semibold focus:outline-none">{{ __('expenses.job_page.list') }}</h2>
|
|
|
|
@unless ($this->canSeeTotals)
|
|
<p class="text-sm text-zinc-600 dark:text-zinc-200">{{ __('expenses.amounts_hidden_help') }}</p>
|
|
@endunless
|
|
|
|
@if ($this->expenses === [])
|
|
<x-empty-state icon="receipt-refund">{{ __('expenses.none') }}</x-empty-state>
|
|
@else
|
|
<x-table :headers="$this->headers()" :rows="$this->expenses">
|
|
@interact('column_spentOn', $expense)
|
|
<span class="whitespace-nowrap">{{ $this->dayLabel($expense->spentOn) }}</span>
|
|
@endinteract
|
|
|
|
@interact('column_what', $expense)
|
|
<span class="block font-medium break-words whitespace-normal">{{ $this->summaryText($expense) }}</span>
|
|
<span class="block text-xs text-zinc-600 dark:text-zinc-200">
|
|
{{ __('expenses.categories.'.$expense->category->value) }}, {{ __('expenses.payers.'.$expense->paidBy->value) }}
|
|
</span>
|
|
@endinteract
|
|
|
|
@interact('column_user', $expense)
|
|
{{ $expense->userName }}
|
|
@endinteract
|
|
|
|
@interact('column_cost', $expense)
|
|
<span class="whitespace-nowrap">{{ $this->amount($expense, $expense->costCents) }}</span>
|
|
@endinteract
|
|
|
|
@interact('column_billed', $expense)
|
|
<span class="whitespace-nowrap">{{ $this->amount($expense, $expense->billedAmountCents) }}</span>
|
|
@endinteract
|
|
|
|
@interact('column_actions', $expense)
|
|
@if ($this->canChange($expense))
|
|
<div class="flex flex-wrap gap-2">
|
|
<x-button
|
|
:href="route('expenses.edit', $expense->id)"
|
|
wire:navigate
|
|
subtle
|
|
color="black"
|
|
sm
|
|
icon="pencil"
|
|
:text="__('expenses.edit')"
|
|
:aria-label="__('expenses.edit_named', ['expense' => $this->summaryText($expense), 'day' => $this->dayLabel($expense->spentOn)])"
|
|
/>
|
|
<x-button
|
|
wire:click="confirmRemoval({{ $expense->id }})"
|
|
subtle
|
|
color="black"
|
|
sm
|
|
icon="trash"
|
|
:text="__('expenses.remove')"
|
|
:aria-label="__('expenses.remove_named', ['expense' => $this->summaryText($expense), 'day' => $this->dayLabel($expense->spentOn)])"
|
|
/>
|
|
</div>
|
|
@endif
|
|
@endinteract
|
|
</x-table>
|
|
|
|
@if ($this->canSeeTotals)
|
|
<dl class="grid gap-x-6 gap-y-1 text-sm sm:grid-cols-[max-content_1fr]">
|
|
<dt class="font-medium">{{ __('expenses.totals.cost') }}</dt>
|
|
<dd>{{ $this->money($this->totals['cost']) }}</dd>
|
|
<dt class="font-medium">{{ __('expenses.totals.billed') }}</dt>
|
|
<dd>{{ $this->money($this->totals['billed']) }}</dd>
|
|
</dl>
|
|
@endif
|
|
@endif
|
|
</section>
|
|
|
|
<x-confirm-dialog id="remove-expense-dialog" :title="__('expenses.removal_title')">
|
|
<p>
|
|
@php($removal = collect($this->expenses)->firstWhere('id', $removalExpenseId))
|
|
@if ($removal !== null)
|
|
{{ __('expenses.remove_question', ['expense' => $this->summaryText($removal), 'day' => $this->dayLabel($removal->spentOn)]) }}
|
|
@endif
|
|
</p>
|
|
|
|
<x-slot:actions>
|
|
<x-button wire:click="removeExpense" color="red" icon="trash" :text="__('expenses.remove')" />
|
|
</x-slot:actions>
|
|
</x-confirm-dialog>
|
|
</div>
|