- Dark indigo header and tinted page background; the mobile main menu gets its own row, in the same order as the keyboard reaches it. - Page titles with an icon chip (x-page-title, x-page, x-page-header) and card sections (x-panel, the card utility); x-table styled as a card with an indigo header row in AppServiceProvider::styleTables(). - Job and task statuses, late work, unapproved hours and stock states as badges with icon and text (x-status-badge, x-jobs.status, x-jobs.task-status), never colour alone. - Empty lists as x-empty-state; dashboard quick link tiles, week hour bars and trend arrows; Kanban columns and task cards edged by status; calendar today column and bar accents; quick sale, reports and machine console restyled; signed-out pages show the app name. - Focus rings use the primary colour in both themes (white in the header). - Document the components in CLAUDE.md; test the status badges. Co-Authored-By: Claude Opus 5.5 <[email protected]>
171 lines
6.8 KiB
PHP
171 lines
6.8 KiB
PHP
<?php
|
|
|
|
use App\Modules\Expenses\Application\Contracts\ExpenseQueries;
|
|
use App\Modules\Expenses\Application\DTOs\ExpenseSummary;
|
|
use App\Modules\Expenses\Presentation\Livewire\Concerns\ShowsExpenses;
|
|
use App\Modules\Users\Application\Contracts\Clock;
|
|
use Carbon\CarbonImmutable;
|
|
use Livewire\Attributes\Computed;
|
|
use Livewire\Attributes\Locked;
|
|
use Livewire\Attributes\Url;
|
|
use Livewire\Component;
|
|
|
|
/**
|
|
* The signed-in user's own expenses month by month, with their amounts.
|
|
* Subcontractors see the expenses management recorded for them.
|
|
*/
|
|
new class extends Component
|
|
{
|
|
use ShowsExpenses;
|
|
|
|
/**
|
|
* The month shown (Y-m). Read from the URL on mount and then changed
|
|
* only by showMonth(), so the browser cannot set it.
|
|
*/
|
|
#[Locked]
|
|
#[Url(as: 'kuukausi', except: '')]
|
|
public string $month = '';
|
|
|
|
public function mount(Clock $clock): void
|
|
{
|
|
$this->authorize('expenses.use');
|
|
|
|
$this->month = $this->monthStart($this->month)?->format('Y-m') ?? $clock->today()->format('Y-m');
|
|
}
|
|
|
|
/**
|
|
* @return list<ExpenseSummary>
|
|
*/
|
|
#[Computed]
|
|
public function expenses(): array
|
|
{
|
|
return app(ExpenseQueries::class)->forUserInMonth((int) auth()->id(), $this->month);
|
|
}
|
|
|
|
#[Computed]
|
|
public function total(): int
|
|
{
|
|
return array_sum(array_map(fn (ExpenseSummary $expense): int => $expense->costCents, $this->expenses));
|
|
}
|
|
|
|
public function showMonth(string $which, Clock $clock): void
|
|
{
|
|
$current = $this->monthStart($this->month) ?? CarbonImmutable::instance($clock->today());
|
|
|
|
$this->month = match ($which) {
|
|
'previous' => $current->subMonthNoOverflow()->format('Y-m'),
|
|
'next' => $current->addMonthNoOverflow()->format('Y-m'),
|
|
default => $clock->today()->format('Y-m'),
|
|
};
|
|
|
|
unset($this->expenses, $this->total);
|
|
}
|
|
|
|
public function monthLabel(): string
|
|
{
|
|
$date = $this->monthStart($this->month);
|
|
|
|
return $date === null ? $this->month : __('expenses.months')[$date->month - 1].' '.$date->year;
|
|
}
|
|
|
|
/**
|
|
* @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' => 'job', 'label' => __('expenses.fields.job'), 'sortable' => false],
|
|
['index' => 'what', 'label' => __('expenses.fields.what'), 'sortable' => false],
|
|
['index' => 'cost', 'label' => __('expenses.fields.cost_column'), 'sortable' => false, 'align' => 'right'],
|
|
['index' => 'actions', 'label' => __('expenses.actions'), 'sortable' => false],
|
|
];
|
|
}
|
|
|
|
public function render(): mixed
|
|
{
|
|
return $this->view()->title(__('expenses.mine.title'));
|
|
}
|
|
|
|
/**
|
|
* The first day of a Y-m month, or null when the value is not one.
|
|
*/
|
|
private function monthStart(string $month): ?CarbonImmutable
|
|
{
|
|
return preg_match('/^\d{4}-(0[1-9]|1[0-2])$/', $month) === 1
|
|
? CarbonImmutable::createFromFormat('!Y-m', $month)
|
|
: null;
|
|
}
|
|
};
|
|
?>
|
|
|
|
<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.mine.title') }}</x-page-title>
|
|
<p class="text-sm text-zinc-600 dark:text-zinc-300">
|
|
{{ __(auth()->user()?->can('expenses.record') ? 'expenses.mine.help' : 'expenses.mine.help_subcontractor') }}
|
|
</p>
|
|
</div>
|
|
|
|
<nav aria-label="{{ __('expenses.mine.month_navigation') }}" class="flex flex-wrap items-center gap-2">
|
|
<x-button wire:click="showMonth('previous')" subtle color="black" sm icon="chevron-left" :text="__('expenses.mine.previous')" />
|
|
<x-button wire:click="showMonth('current')" subtle color="black" sm :text="__('expenses.mine.current')" />
|
|
<x-button wire:click="showMonth('next')" subtle color="black" sm icon="chevron-right" position="right" :text="__('expenses.mine.next')" />
|
|
</nav>
|
|
|
|
<section aria-labelledby="month-heading" class="space-y-3">
|
|
<h2 id="month-heading" class="text-xl font-semibold" aria-live="polite">{{ $this->monthLabel() }}</h2>
|
|
|
|
@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_job', $expense)
|
|
@can('expenses.record')
|
|
<x-link :href="route('expenses.job', $expense->job->id)" navigate class="whitespace-normal">{{ $expense->job->label() }}</x-link>
|
|
@else
|
|
<span class="whitespace-normal">{{ $expense->job->label() }}</span>
|
|
@endcan
|
|
@if ($expense->job->isLocked)
|
|
<span class="mt-1 flex items-center gap-1 text-xs">
|
|
<x-icon name="lock-closed" class="size-4" aria-hidden="true" /> {{ __('expenses.locked_short') }}
|
|
</span>
|
|
@endif
|
|
@endinteract
|
|
|
|
@interact('column_what', $expense)
|
|
<span class="block break-words whitespace-normal">{{ $this->summaryText($expense) }}</span>
|
|
<span class="block text-xs text-zinc-600 dark:text-zinc-300">
|
|
{{ __('expenses.categories.'.$expense->category->value) }}, {{ __('expenses.payers.'.$expense->paidBy->value) }}
|
|
</span>
|
|
@endinteract
|
|
|
|
@interact('column_cost', $expense)
|
|
<span class="whitespace-nowrap">{{ $this->amount($expense, $expense->costCents) }}</span>
|
|
@endinteract
|
|
|
|
@interact('column_actions', $expense)
|
|
@if ($this->canChange($expense))
|
|
<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)])"
|
|
/>
|
|
@endif
|
|
@endinteract
|
|
</x-table>
|
|
|
|
<p class="text-sm font-medium">{{ __('expenses.mine.total', ['total' => $this->money($this->total)]) }}</p>
|
|
@endif
|
|
</section>
|
|
</div>
|