Files
petriandClaude Sonnet 5.5 7d7b72989d Add an editable menu name and reserve billing material numbers on creation
- Company details get an optional "Valikon nimi", shown at the left of the
  main menu; it falls back to the application name when empty.
- A billing material gets its running number (billing_exports.number) only
  when it is created, so discarded drafts leave no gaps. Drafts have no
  number; existing created materials are numbered by the migration, and the
  CSV file name uses the number.
- TaskAssigneeMigrationTest rolls back from its own migration onward instead
  of assuming it is the last one.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-11-24 19:41:57 +02:00

151 lines
5.8 KiB
PHP

<?php
use App\Modules\Billing\Application\Contracts\BillingQueries;
use App\Modules\Billing\Application\DTOs\ExportSummary;
use App\Modules\Billing\Application\UseCases\OpenBillingDraft;
use App\Modules\Billing\Domain\Enums\ExportStatus;
use App\Modules\Billing\Domain\Exceptions\DraftAlreadyOpen;
use App\Modules\Billing\Presentation\Livewire\Concerns\FormatsBilling;
use Livewire\Attributes\Computed;
use Livewire\Attributes\Locked;
use Livewire\Component;
/**
* Billing materials (laskuaineistot), newest first, and the way to start
* a new draft or continue the open one. Management only.
*/
new class extends Component
{
use FormatsBilling;
#[Locked]
public string $statusMessage = '';
public function mount(): void
{
$this->authorize('billing.manage');
$this->statusMessage = (string) session('billing-status', '');
}
/**
* @return list<ExportSummary>
*/
#[Computed]
public function exports(): array
{
return app(BillingQueries::class)->exports();
}
#[Computed]
public function openDraft(): ?ExportSummary
{
foreach ($this->exports as $export) {
if ($export->status === ExportStatus::Draft) {
return $export;
}
}
return null;
}
public function openDraftNow(OpenBillingDraft $openBillingDraft): void
{
$this->authorize('billing.manage');
try {
$id = $openBillingDraft->execute((int) auth()->id());
$this->redirectRoute('billing.export', ['export' => $id], navigate: true);
} catch (DraftAlreadyOpen) {
$this->statusMessage = __('billing.errors.draft_open');
unset($this->exports, $this->openDraft);
}
}
/**
* @return list<array{index: string, label: string, sortable: bool, align?: string}>
*/
public function headers(): array
{
return [
['index' => 'number', 'label' => __('billing.index.columns.number'), 'sortable' => false],
['index' => 'status', 'label' => __('billing.index.columns.status'), 'sortable' => false],
['index' => 'created', 'label' => __('billing.index.columns.created'), 'sortable' => false],
['index' => 'finalized', 'label' => __('billing.index.columns.finalized'), 'sortable' => false],
['index' => 'invoices', 'label' => __('billing.index.columns.invoices'), 'sortable' => false, 'align' => 'right'],
['index' => 'jobs', 'label' => __('billing.index.columns.jobs'), 'sortable' => false, 'align' => 'right'],
['index' => 'net', 'label' => __('billing.index.columns.net'), 'sortable' => false, 'align' => 'right'],
['index' => 'file', 'label' => __('billing.index.columns.file'), 'sortable' => false],
];
}
public function render(): mixed
{
return $this->view()->title(__('billing.index.title'));
}
};
?>
<div class="mx-auto max-w-6xl space-y-6 p-4 sm:p-6">
<div class="space-y-2">
<h1 class="text-2xl font-semibold">{{ __('billing.index.title') }}</h1>
<p class="max-w-3xl text-sm">{{ __('billing.index.intro') }}</p>
</div>
<p>
@if ($this->openDraft !== null)
<x-button :href="route('billing.export', $this->openDraft->id)" wire:navigate icon="pencil-square" :text="__('billing.index.continue')" />
@else
<x-button wire:click="openDraftNow" icon="plus" :text="__('billing.index.new')" />
@endif
</p>
<p role="status" aria-live="polite" class="text-sm font-medium">{{ $statusMessage }}</p>
@if ($this->exports === [])
<p class="text-sm">{{ __('billing.index.none') }}</p>
@else
<x-table :headers="$this->headers()" :rows="$this->exports">
@interact('column_number', $export)
<x-link :href="route('billing.export', $export->id)" navigate>{{ $export->number === null ? __('billing.index.draft_label') : __('billing.index.export_label', ['number' => $export->number]) }}</x-link>
@endinteract
@interact('column_status', $export)
<span class="inline-flex items-center gap-1">
<x-icon :name="$export->status->value === 'draft' ? 'pencil-square' : 'lock-closed'" class="size-4" aria-hidden="true" />
{{ __('billing.statuses.'.$export->status->value) }}
</span>
@endinteract
@interact('column_created', $export)
<span class="whitespace-nowrap">{{ $this->timeLabel($export->createdAt) }}</span>
<span class="block text-xs">{{ $export->createdByName }}</span>
@endinteract
@interact('column_finalized', $export)
@if ($export->finalizedAt !== null)
<span class="whitespace-nowrap">{{ $this->timeLabel($export->finalizedAt) }}</span>
<span class="block text-xs">{{ $export->finalizedByName }}</span>
@endif
@endinteract
@interact('column_invoices', $export)
{{ $export->invoiceCount }}
@endinteract
@interact('column_jobs', $export)
{{ $export->jobCount }}
@endinteract
@interact('column_net', $export)
<span class="whitespace-nowrap">{{ $export->netCents === null ? '' : $this->money($export->netCents) }}</span>
@endinteract
@interact('column_file', $export)
@if ($export->status->value === 'created')
<x-link :href="route('billing.csv', $export->id)" icon="arrow-down-tray" :aria-label="__('billing.csv.download_named', ['number' => $export->number])">{{ __('billing.csv.download_short') }}</x-link>
@endif
@endinteract
</x-table>
@endif
</div>