Management builds the monthly billing material (laskuaineisto) as a draft: done jobs are added as invoices of their own, combined when the customer, billing unit and reference allow it, and their billable hours are set per work type. Creating the material checks the jobs again, marks the approved hours and billable expenses billed, forms invoice lines with price and VAT snapshots and moves the jobs to "Lasku luotu". Fixed price jobs bill their quoted amount once. Billed hours keep their approval and billed expenses can no longer change. The Fennoa export and monthly fee lines come later. Co-Authored-By: Claude Opus 5.5 <[email protected]>
144 lines
5.2 KiB
PHP
144 lines
5.2 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'],
|
|
];
|
|
}
|
|
|
|
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
|
|
</x-table>
|
|
@endif
|
|
</div>
|