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 */ #[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 */ 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)
{{ __('expenses.job_page.title', ['job' => $job->label()]) }} {{ __('expenses.job_page.back_to_job') }}

{{ $statusMessage }}

@if (session('status')) @endif @if ($job->isLocked)

@else @endif

{{ __('expenses.job_page.list') }}

@unless ($this->canSeeTotals)

{{ __('expenses.amounts_hidden_help') }}

@endunless @if ($this->expenses === []) {{ __('expenses.none') }} @else @interact('column_spentOn', $expense) {{ $this->dayLabel($expense->spentOn) }} @endinteract @interact('column_what', $expense) {{ $this->summaryText($expense) }} {{ __('expenses.categories.'.$expense->category->value) }}, {{ __('expenses.payers.'.$expense->paidBy->value) }} @endinteract @interact('column_user', $expense) {{ $expense->userName }} @endinteract @interact('column_cost', $expense) {{ $this->amount($expense, $expense->costCents) }} @endinteract @interact('column_billed', $expense) {{ $this->amount($expense, $expense->billedAmountCents) }} @endinteract @interact('column_actions', $expense) @if ($this->canChange($expense))
@endif @endinteract
@if ($this->canSeeTotals)
{{ __('expenses.totals.cost') }}
{{ $this->money($this->totals['cost']) }}
{{ __('expenses.totals.billed') }}
{{ $this->money($this->totals['billed']) }}
@endif @endif

@php($removal = collect($this->expenses)->firstWhere('id', $removalExpenseId)) @if ($removal !== null) {{ __('expenses.remove_question', ['expense' => $this->summaryText($removal), 'day' => $this->dayLabel($removal->spentOn)]) }} @endif