Files
Toiminnanohjaus/app/Modules/Billing/Presentation/Livewire/⚡job-months.blade.php
petriandClaude Sonnet 5.5 bc3dbf16a4 Show a monthly fee job's billed periods on a page of its own
The new billing::job-months page lists the months that created billing
materials have billed for a monthly fee job, with links to the materials
and the total, and the months still to bill up to the current month,
counted the same way as a new material counts them. The job page links
to it next to the payment basis for those who manage billing.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-11-25 15:56:15 +02:00

158 lines
6.5 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
use App\Modules\Billing\Application\DTOs\MonthlyBillingView;
use App\Modules\Billing\Application\Services\MonthlyBillingViews;
use App\Modules\Billing\Domain\ValueObjects\BillingMonths;
use App\Modules\Billing\Presentation\Livewire\Concerns\FormatsBilling;
use Livewire\Attributes\Computed;
use Livewire\Attributes\Locked;
use Livewire\Component;
/**
* The billing periods of a monthly fee job (spec 5.5): the months billed
* on created billing materials, with links to them, and the months from
* the job's start up to the current month that are still to bill.
* Management only.
*/
new class extends Component
{
use FormatsBilling;
#[Locked]
public int $jobId = 0;
public function mount(int $job): void
{
$this->authorize('billing.manage');
$this->jobId = $job;
if (app(MonthlyBillingViews::class)->forJob($job) === null) {
abort(404);
}
}
#[Computed]
public function billing(): MonthlyBillingView
{
return app(MonthlyBillingViews::class)->forJob($this->jobId) ?? abort(404);
}
public function monthLabel(string $month): string
{
return BillingMonths::label($month);
}
public function dayLabel(string $date): string
{
return (new DateTimeImmutable($date))->format('j.n.Y');
}
public function heading(): string
{
return __('billing.job_months.title', ['job' => $this->billing->job->number.' '.$this->billing->job->name]);
}
/**
* @return list<array{index: string, label: string, sortable: bool, align?: string}>
*/
public function headers(): array
{
return [
['index' => 'month', 'label' => __('billing.job_months.columns.month'), 'sortable' => false],
['index' => 'export', 'label' => __('billing.job_months.columns.export'), 'sortable' => false],
['index' => 'finalized', 'label' => __('billing.job_months.columns.finalized'), 'sortable' => false],
['index' => 'net', 'label' => __('billing.job_months.columns.net'), 'sortable' => false, 'align' => 'right'],
];
}
public function render(): mixed
{
return $this->view()->title($this->heading());
}
};
?>
@php($billing = $this->billing)
@php($job = $billing->job)
<div class="mx-auto max-w-4xl space-y-6 p-4 sm:p-6">
<div class="space-y-2">
<p><x-link :href="route('jobs.show', $job->id)" navigate>{{ __('billing.job_months.back') }}</x-link></p>
<h1 class="text-2xl font-semibold">{{ $this->heading() }}</h1>
<p class="max-w-3xl text-sm">{{ __('billing.job_months.intro') }}</p>
</div>
<section aria-labelledby="summary-heading" class="space-y-2">
<h2 id="summary-heading" class="sr-only">{{ __('billing.job_months.summary') }}</h2>
<dl class="grid grid-cols-1 gap-x-6 gap-y-1 text-sm sm:grid-cols-[auto_1fr]">
<dt class="font-medium">{{ __('billing.job_months.customer') }}</dt>
<dd>{{ $job->customerName }}</dd>
<dt class="font-medium">{{ __('billing.job_months.monthly_fee') }}</dt>
<dd>{{ $job->monthlyFeeCents === null ? __('billing.job_months.no_fee') : $this->money($job->monthlyFeeCents).' '.__('billing.job_months.vat_excluded') }}</dd>
<dt class="font-medium">{{ __('billing.job_months.starts') }}</dt>
<dd>{{ $job->billingStartsOn === '' ? '–' : $this->monthLabel(substr($job->billingStartsOn, 0, 7)) }}</dd>
<dt class="font-medium">{{ __('billing.job_months.ends') }}</dt>
<dd>{{ $billing->billingEndsOn === null ? __('billing.job_months.no_end') : $this->dayLabel($billing->billingEndsOn) }}</dd>
<dt class="font-medium">{{ __('billing.job_months.billing_unit') }}</dt>
<dd>{{ $job->billingUnitName ?? __('billing.invoices.no_billing_unit') }}</dd>
</dl>
@if (! $job->inBillableStatus)
<p class="flex items-center gap-1 text-sm font-medium">
<x-icon name="information-circle" class="size-5 shrink-0" aria-hidden="true" />
{{ __('billing.job_months.not_running') }}
</p>
@endif
</section>
<section aria-labelledby="billed-heading" class="space-y-3">
<h2 id="billed-heading" class="text-xl font-semibold">{{ __('billing.job_months.billed_title', ['count' => count($billing->billed)]) }}</h2>
@if ($billing->billed === [])
<p class="text-sm">{{ __('billing.job_months.none_billed') }}</p>
@else
<x-table :headers="$this->headers()" :rows="$billing->billed">
@interact('column_month', $month)
<span class="whitespace-nowrap">{{ $this->monthLabel($month->month) }}</span>
@endinteract
@interact('column_export', $month)
<x-link :href="route('billing.export', $month->exportId)" navigate>{{ __('billing.index.export_label', ['number' => $month->exportNumber]) }}</x-link>
@endinteract
@interact('column_finalized', $month)
<span class="whitespace-nowrap">{{ $month->finalizedAt === null ? '' : $this->timeLabel($month->finalizedAt) }}</span>
@endinteract
@interact('column_net', $month)
<span class="whitespace-nowrap">{{ $this->money($month->netCents) }}</span>
@endinteract
</x-table>
<p class="text-sm font-medium">{{ __('billing.job_months.billed_total', ['net' => $this->money($billing->billedNetCents())]) }}</p>
@endif
</section>
<section aria-labelledby="unbilled-heading" class="space-y-3">
<h2 id="unbilled-heading" class="text-xl font-semibold">{{ __('billing.job_months.unbilled_title', ['month' => $this->monthLabel($billing->currentMonth)]) }}</h2>
@if ($billing->unbilled === [])
<p class="flex items-center gap-1 text-sm">
<x-icon name="check-circle" class="size-5 shrink-0" aria-hidden="true" />
{{ __('billing.job_months.none_unbilled') }}
</p>
@else
<ul class="flex flex-wrap gap-2" aria-label="{{ __('billing.job_months.unbilled_list') }}">
@foreach ($billing->unbilled as $month)
<li class="rounded-md border border-zinc-300 px-3 py-1 text-sm dark:border-zinc-600">{{ $this->monthLabel($month) }}</li>
@endforeach
</ul>
<p class="text-sm">{{ __('billing.job_months.unbilled_help') }}</p>
@endif
</section>
</div>