authorize('expenses.use'); $this->month = $this->monthStart($this->month)?->format('Y-m') ?? $clock->today()->format('Y-m'); } /** * @return list */ #[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 */ 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; } }; ?>
{{ __('expenses.mine.title') }}

{{ __(auth()->user()?->can('expenses.record') ? 'expenses.mine.help' : 'expenses.mine.help_subcontractor') }}

{{ $this->monthLabel() }}

@if ($this->expenses === []) {{ __('expenses.none') }} @else @interact('column_spentOn', $expense) {{ $this->dayLabel($expense->spentOn) }} @endinteract @interact('column_job', $expense) @can('expenses.record') {{ $expense->job->label() }} @else {{ $expense->job->label() }} @endcan @if ($expense->job->isLocked) @endif @endinteract @interact('column_what', $expense) {{ $this->summaryText($expense) }} {{ __('expenses.categories.'.$expense->category->value) }}, {{ __('expenses.payers.'.$expense->paidBy->value) }} @endinteract @interact('column_cost', $expense) {{ $this->amount($expense, $expense->costCents) }} @endinteract @interact('column_actions', $expense) @if ($this->canChange($expense)) @endif @endinteract

{{ __('expenses.mine.total', ['total' => $this->money($this->total)]) }}

@endif