Management downloads a created billing material as a semicolon CSV with decimal commas and a UTF-8 BOM for Excel: one row per invoice line with the invoice's customer, billing unit, e-invoice details and reference, the job, the line and its net, VAT and gross amounts. Consumers' full personal identity codes are included only for those who may see them, the response is not cached, and cells Excel would read as formulas are escaped. The columns follow Fennoa's import format once a sample exists. Co-Authored-By: Claude Opus 5.5 <[email protected]>
151 lines
5.7 KiB
PHP
151 lines
5.7 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>{{ __('billing.index.export_label', ['number' => $export->id]) }}</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->id])">{{ __('billing.csv.download_short') }}</x-link>
|
|
@endif
|
|
@endinteract
|
|
</x-table>
|
|
@endif
|
|
</div>
|