Jobs billed by a fixed monthly fee get a monthly fee field, kept behind the quotes permission like the quoted amount. A billing material now has a billing month: a new draft adds every monthly fee job with something to bill, each on an invoice of its own, and bills one line for every unbilled month from the job's start up to the billing month (or its end or completion), so skipped months are caught up and no month is billed twice. Their expenses are billed alongside, their hours are covered by the fee and marked billed, and the job keeps running. Co-Authored-By: Claude Opus 5.5 <[email protected]>
673 lines
37 KiB
PHP
673 lines
37 KiB
PHP
<?php
|
|
|
|
use App\Modules\Billing\Application\DTOs\ExportView;
|
|
use App\Modules\Billing\Application\DTOs\InvoiceJobView;
|
|
use App\Modules\Billing\Application\Services\ExportViews;
|
|
use App\Modules\Billing\Application\UseCases\AddJobToDraft;
|
|
use App\Modules\Billing\Application\UseCases\DiscardDraft;
|
|
use App\Modules\Billing\Application\UseCases\FinalizeBillingExport;
|
|
use App\Modules\Billing\Application\UseCases\MoveJobToInvoice;
|
|
use App\Modules\Billing\Application\UseCases\RemoveJobFromDraft;
|
|
use App\Modules\Billing\Application\UseCases\SeparateJob;
|
|
use App\Modules\Billing\Application\UseCases\SetBillableHours;
|
|
use App\Modules\Billing\Application\UseCases\SetBillingPeriod;
|
|
use App\Modules\Billing\Domain\Enums\BillingMode;
|
|
use App\Modules\Billing\Domain\Enums\LineKind;
|
|
use App\Modules\Billing\Domain\Exceptions\BillingExportNotFound;
|
|
use App\Modules\Billing\Domain\Exceptions\ExportEmpty;
|
|
use App\Modules\Billing\Domain\Exceptions\ExportNotDraft;
|
|
use App\Modules\Billing\Domain\Exceptions\InvalidBillableHours;
|
|
use App\Modules\Billing\Domain\Exceptions\InvalidBillingPeriod;
|
|
use App\Modules\Billing\Domain\ValueObjects\BillingMonths;
|
|
use App\Modules\Billing\Domain\Exceptions\InvoicesCannotMerge;
|
|
use App\Modules\Billing\Domain\Exceptions\JobAlreadyInDraft;
|
|
use App\Modules\Billing\Domain\Exceptions\JobNotBillable;
|
|
use App\Modules\Billing\Domain\Exceptions\JobNotInDraft;
|
|
use App\Modules\Billing\Domain\ValueObjects\InvoiceLine;
|
|
use App\Modules\Billing\Presentation\Livewire\Concerns\FormatsBilling;
|
|
use Livewire\Attributes\Computed;
|
|
use Livewire\Attributes\Locked;
|
|
use Livewire\Component;
|
|
|
|
/**
|
|
* A billing material (laskuaineisto). As a draft: its invoices with the
|
|
* jobs' approved hours, management's billable hours and the expenses,
|
|
* the done jobs that may be added, combining jobs on invoices, and
|
|
* creating the material. Once created: its invoices and lines, read only.
|
|
*/
|
|
new class extends Component
|
|
{
|
|
use FormatsBilling;
|
|
|
|
#[Locked]
|
|
public int $exportId = 0;
|
|
|
|
#[Locked]
|
|
public string $statusMessage = '';
|
|
|
|
#[Locked]
|
|
public string $errorMessage = '';
|
|
|
|
/**
|
|
* The invoice chosen in each job's "move to invoice" select, keyed by job id.
|
|
*
|
|
* @var array<int|string, string>
|
|
*/
|
|
public array $moveTargets = [];
|
|
|
|
public function mount(int $export): void
|
|
{
|
|
$this->authorize('billing.manage');
|
|
$this->exportId = $export;
|
|
|
|
if (app(ExportViews::class)->of($export) === null) {
|
|
abort(404);
|
|
}
|
|
}
|
|
|
|
#[Computed]
|
|
public function export(): ExportView
|
|
{
|
|
return app(ExportViews::class)->of($this->exportId) ?? abort(404);
|
|
}
|
|
|
|
public function add(int $jobId, AddJobToDraft $addJobToDraft): void
|
|
{
|
|
$label = $this->availableLabel($jobId);
|
|
$this->attempt(fn () => $addJobToDraft->execute($this->exportId, $jobId), __('billing.available.added', ['job' => $label]), $label);
|
|
}
|
|
|
|
public function remove(int $jobId, RemoveJobFromDraft $removeJobFromDraft): void
|
|
{
|
|
$label = $this->jobLabel($jobId);
|
|
$this->attempt(fn () => $removeJobFromDraft->execute($this->exportId, $jobId), __('billing.jobs.removed', ['job' => $label]), $label);
|
|
}
|
|
|
|
public function move(int $jobId, MoveJobToInvoice $moveJobToInvoice): void
|
|
{
|
|
$label = $this->jobLabel($jobId);
|
|
$target = (int) ($this->moveTargets[$jobId] ?? 0);
|
|
|
|
if ($target === 0) {
|
|
return;
|
|
}
|
|
|
|
$this->attempt(fn () => $moveJobToInvoice->execute($this->exportId, $jobId, $target), __('billing.jobs.moved', ['job' => $label]), $label);
|
|
unset($this->moveTargets[$jobId]);
|
|
}
|
|
|
|
public function separate(int $jobId, SeparateJob $separateJob): void
|
|
{
|
|
$label = $this->jobLabel($jobId);
|
|
$this->attempt(fn () => $separateJob->execute($this->exportId, $jobId), __('billing.jobs.separated', ['job' => $label]), $label);
|
|
}
|
|
|
|
public function saveHours(int $jobId, int $workTypeId, string $value, SetBillableHours $setBillableHours): void
|
|
{
|
|
$this->authorize('billing.manage');
|
|
$field = 'hours.'.$jobId.'.'.$workTypeId;
|
|
$this->resetErrorBag($field);
|
|
$label = $this->jobLabel($jobId);
|
|
$workType = $this->workTypeName($jobId, $workTypeId);
|
|
|
|
try {
|
|
$setBillableHours->execute($this->exportId, $jobId, $workTypeId, mb_substr($value, 0, 20));
|
|
$this->statusMessage = __('billing.jobs.hours_saved', ['job' => $label, 'work_type' => $workType]);
|
|
$this->errorMessage = '';
|
|
} catch (InvalidBillableHours) {
|
|
$this->addError($field, __('billing.errors.hours'));
|
|
} catch (ExportNotDraft|BillingExportNotFound|JobNotInDraft $exception) {
|
|
$this->errorMessage = $this->errorText($exception, $label);
|
|
}
|
|
|
|
unset($this->export);
|
|
}
|
|
|
|
public function savePeriod(string $value, SetBillingPeriod $setBillingPeriod): void
|
|
{
|
|
$this->authorize('billing.manage');
|
|
$this->resetErrorBag('period');
|
|
$this->statusMessage = '';
|
|
$this->errorMessage = '';
|
|
|
|
try {
|
|
$setBillingPeriod->execute($this->exportId, mb_substr(trim($value), 0, 7));
|
|
unset($this->export);
|
|
$this->statusMessage = __('billing.export.period_saved', ['month' => BillingMonths::label($this->export->period)]);
|
|
} catch (InvalidBillingPeriod) {
|
|
$this->addError('period', __('billing.errors.period'));
|
|
} catch (ExportNotDraft|BillingExportNotFound $exception) {
|
|
$this->errorMessage = $this->errorText($exception, '');
|
|
}
|
|
|
|
unset($this->export);
|
|
}
|
|
|
|
public function confirmFinalize(): void
|
|
{
|
|
$this->authorize('billing.manage');
|
|
$this->js("document.getElementById('finalize-dialog').showModal()");
|
|
}
|
|
|
|
public function finalize(FinalizeBillingExport $finalizeBillingExport): void
|
|
{
|
|
$this->authorize('billing.manage');
|
|
$this->statusMessage = '';
|
|
$this->errorMessage = '';
|
|
|
|
try {
|
|
$invoices = $finalizeBillingExport->execute($this->exportId, (int) auth()->id());
|
|
$this->statusMessage = __('billing.export.finalized', ['invoices' => $invoices]);
|
|
} catch (ExportNotDraft|BillingExportNotFound|ExportEmpty|JobNotBillable $exception) {
|
|
$this->errorMessage = $this->errorText($exception, $exception instanceof JobNotBillable ? $this->jobLabel($exception->jobId) : '');
|
|
}
|
|
|
|
unset($this->export);
|
|
$this->js("document.getElementById('finalize-dialog').close(); document.getElementById('billing-status').focus()");
|
|
}
|
|
|
|
public function confirmDiscard(): void
|
|
{
|
|
$this->authorize('billing.manage');
|
|
$this->js("document.getElementById('discard-dialog').showModal()");
|
|
}
|
|
|
|
public function discard(DiscardDraft $discardDraft): void
|
|
{
|
|
$this->authorize('billing.manage');
|
|
|
|
try {
|
|
$discardDraft->execute($this->exportId);
|
|
session()->flash('billing-status', __('billing.export.discarded'));
|
|
$this->redirectRoute('billing.index', navigate: true);
|
|
} catch (ExportNotDraft|BillingExportNotFound $exception) {
|
|
$this->errorMessage = $this->errorText($exception, '');
|
|
unset($this->export);
|
|
$this->js("document.getElementById('discard-dialog').close(); document.getElementById('billing-error').focus()");
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @return list<InvoiceLine>
|
|
*/
|
|
public function linesOfKind(InvoiceJobView $job, LineKind $kind): array
|
|
{
|
|
return array_values(array_filter($job->lines, fn (InvoiceLine $line): bool => $line->kind === $kind));
|
|
}
|
|
|
|
/**
|
|
* @return list<array{index: string, label: string, sortable: bool, align?: string}>
|
|
*/
|
|
public function availableHeaders(): array
|
|
{
|
|
return [
|
|
['index' => 'job', 'label' => __('billing.available.columns.job'), 'sortable' => false],
|
|
['index' => 'customer', 'label' => __('billing.available.columns.customer'), 'sortable' => false],
|
|
['index' => 'mode', 'label' => __('billing.available.columns.mode'), 'sortable' => false],
|
|
['index' => 'hours', 'label' => __('billing.available.columns.hours'), 'sortable' => false, 'align' => 'right'],
|
|
['index' => 'expenses', 'label' => __('billing.available.columns.expenses'), 'sortable' => false, 'align' => 'right'],
|
|
['index' => 'actions', 'label' => __('billing.available.columns.actions'), 'sortable' => false],
|
|
];
|
|
}
|
|
|
|
public function render(): mixed
|
|
{
|
|
return $this->view()->title(__('billing.export.title', ['number' => $this->exportId]));
|
|
}
|
|
|
|
/**
|
|
* Runs a change of the draft and reports it in the status or error area.
|
|
*/
|
|
private function attempt(callable $change, string $success, string $jobLabel): void
|
|
{
|
|
$this->authorize('billing.manage');
|
|
$this->statusMessage = '';
|
|
$this->errorMessage = '';
|
|
|
|
try {
|
|
$change();
|
|
$this->statusMessage = $success;
|
|
} catch (BillingExportNotFound|ExportNotDraft|JobAlreadyInDraft|JobNotInDraft|JobNotBillable|InvoicesCannotMerge $exception) {
|
|
$this->errorMessage = $this->errorText($exception, $jobLabel);
|
|
}
|
|
|
|
unset($this->export);
|
|
}
|
|
|
|
private function errorText(\Throwable $exception, string $jobLabel): string
|
|
{
|
|
return match (true) {
|
|
$exception instanceof JobNotBillable => __('billing.errors.not_billable', ['job' => $jobLabel, 'reason' => $this->reasonText($exception->reason, $this->missingRates($exception->jobId))]),
|
|
$exception instanceof InvoicesCannotMerge => __('billing.merge_refusals.'.$exception->refusal->value),
|
|
$exception instanceof ExportNotDraft => __('billing.errors.not_draft'),
|
|
$exception instanceof ExportEmpty => __('billing.errors.empty'),
|
|
$exception instanceof JobAlreadyInDraft => __('billing.errors.already_in_draft'),
|
|
$exception instanceof JobNotInDraft => __('billing.errors.not_in_draft'),
|
|
default => __('billing.errors.not_found'),
|
|
};
|
|
}
|
|
|
|
/**
|
|
* @return list<string>
|
|
*/
|
|
private function missingRates(int $jobId): array
|
|
{
|
|
foreach ($this->export->availableJobs as $available) {
|
|
if ($available->job->id === $jobId) {
|
|
return $available->missingRateNames;
|
|
}
|
|
}
|
|
|
|
return $this->findJob($jobId)->missingRateNames ?? [];
|
|
}
|
|
|
|
private function availableLabel(int $jobId): string
|
|
{
|
|
foreach ($this->export->availableJobs as $available) {
|
|
if ($available->job->id === $jobId) {
|
|
return $available->job->label();
|
|
}
|
|
}
|
|
|
|
return (string) $jobId;
|
|
}
|
|
|
|
private function jobLabel(int $jobId): string
|
|
{
|
|
return $this->findJob($jobId)?->label() ?? $this->availableLabel($jobId);
|
|
}
|
|
|
|
private function workTypeName(int $jobId, int $workTypeId): string
|
|
{
|
|
foreach ($this->findJob($jobId)->hours ?? [] as $row) {
|
|
if ($row->workTypeId === $workTypeId) {
|
|
return $row->name;
|
|
}
|
|
}
|
|
|
|
return '';
|
|
}
|
|
|
|
private function findJob(int $jobId): ?InvoiceJobView
|
|
{
|
|
foreach ($this->export->invoices as $invoice) {
|
|
foreach ($invoice->jobs as $job) {
|
|
if ($job->jobId === $jobId) {
|
|
return $job;
|
|
}
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
};
|
|
?>
|
|
|
|
<div class="mx-auto max-w-6xl space-y-6 p-4 sm:p-6">
|
|
@php($export = $this->export)
|
|
|
|
<div class="space-y-2">
|
|
<p><x-link :href="route('billing.index')" navigate>{{ __('billing.export.back') }}</x-link></p>
|
|
<h1 class="text-2xl font-semibold">{{ __('billing.export.title', ['number' => $export->id]) }}</h1>
|
|
<p class="flex items-center gap-2 text-sm">
|
|
@if ($export->isDraft())
|
|
<x-icon name="pencil-square" class="size-5 shrink-0" aria-hidden="true" />
|
|
{{ __('billing.export.draft_info', ['name' => $export->createdByName, 'at' => $this->timeLabel($export->createdAt)]) }}
|
|
@else
|
|
<x-icon name="lock-closed" class="size-5 shrink-0" aria-hidden="true" />
|
|
{{ __('billing.export.created_info', ['name' => (string) $export->finalizedByName, 'at' => $this->timeLabel($export->finalizedAt ?? $export->createdAt)]) }}
|
|
@endif
|
|
</p>
|
|
<p class="text-sm font-medium">
|
|
{{ __('billing.export.summary', ['invoices' => count($export->invoices), 'jobs' => $export->jobCount(), 'net' => $this->money($export->totals->netCents)]) }}
|
|
</p>
|
|
</div>
|
|
|
|
<p id="billing-status" tabindex="-1" role="status" aria-live="polite" class="text-sm font-medium focus:outline-none">{{ $statusMessage }}</p>
|
|
<p id="billing-error" tabindex="-1" role="alert" class="text-sm font-medium text-red-700 focus:outline-none dark:text-red-400">{{ $errorMessage }}</p>
|
|
|
|
@if ($export->isDraft())
|
|
<div class="max-w-xs space-y-1">
|
|
<label for="billing-period" class="block text-sm font-semibold">{{ __('billing.export.period') }}</label>
|
|
<input
|
|
id="billing-period"
|
|
type="month"
|
|
value="{{ $export->period }}"
|
|
wire:change="savePeriod($event.target.value)"
|
|
aria-describedby="billing-period-help @error('period') billing-period-error @enderror"
|
|
@error('period') aria-invalid="true" @enderror
|
|
class="w-full rounded-md border border-zinc-400 bg-white px-2 py-1.5 text-zinc-900 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-700 aria-invalid:border-red-700 dark:border-zinc-500 dark:bg-zinc-900 dark:text-zinc-100 dark:aria-invalid:border-red-400 dark:[color-scheme:dark]"
|
|
/>
|
|
<p id="billing-period-help" class="text-xs text-zinc-600 dark:text-zinc-300">{{ __('billing.export.period_help') }}</p>
|
|
@error('period')
|
|
<p id="billing-period-error" class="text-xs text-red-700 dark:text-red-400">{{ $message }}</p>
|
|
@enderror
|
|
</div>
|
|
|
|
@if ($export->hasProblems())
|
|
<p class="flex items-start gap-2 rounded-lg border border-amber-700 p-4 text-sm dark:border-amber-400">
|
|
<x-icon name="exclamation-triangle" class="size-5 shrink-0" aria-hidden="true" />
|
|
{{ __('billing.export.problems') }}
|
|
</p>
|
|
@endif
|
|
|
|
<div class="flex flex-wrap gap-3">
|
|
@if ($export->invoices !== [])
|
|
<x-button wire:click="confirmFinalize" icon="lock-closed" :text="__('billing.export.finalize')" />
|
|
@endif
|
|
<x-button wire:click="confirmDiscard" subtle color="black" icon="trash" :text="__('billing.export.discard')" />
|
|
</div>
|
|
@endif
|
|
|
|
<section aria-labelledby="invoices-heading" class="space-y-6">
|
|
<h2 id="invoices-heading" class="text-xl font-semibold">{{ __('billing.invoices.title') }}</h2>
|
|
|
|
@if ($export->invoices === [])
|
|
<p class="text-sm">{{ __('billing.invoices.none') }}</p>
|
|
@endif
|
|
|
|
@foreach ($export->invoices as $invoiceNumber => $invoice)
|
|
<section wire:key="invoice-{{ $invoice->key }}" aria-labelledby="invoice-{{ $invoice->key }}-heading" class="space-y-4 rounded-lg border border-zinc-300 p-4 dark:border-zinc-600">
|
|
<div class="space-y-1">
|
|
<h3 id="invoice-{{ $invoice->key }}-heading" class="text-lg font-semibold">{{ __('billing.invoices.heading', ['number' => $invoiceNumber + 1, 'customer' => $invoice->customerName]) }}</h3>
|
|
<dl class="grid gap-x-4 gap-y-1 text-sm sm:grid-cols-[auto_1fr]">
|
|
<dt class="font-medium">{{ __('billing.invoices.billing_unit') }}</dt>
|
|
<dd>{{ $invoice->billingUnitName ?? __('billing.invoices.no_billing_unit') }}</dd>
|
|
<dt class="font-medium">{{ __('billing.invoices.reference') }}</dt>
|
|
<dd>{{ $invoice->reference ?? __('billing.invoices.no_reference') }}</dd>
|
|
</dl>
|
|
</div>
|
|
|
|
@foreach ($invoice->jobs as $job)
|
|
<article wire:key="job-{{ $job->jobId }}" aria-labelledby="job-{{ $job->jobId }}-heading" class="space-y-3 border-t border-zinc-200 pt-3 dark:border-zinc-700">
|
|
<h4 id="job-{{ $job->jobId }}-heading" class="font-semibold">
|
|
<x-link :href="route('jobs.show', $job->jobId)" navigate>{{ $job->label() }}</x-link>
|
|
</h4>
|
|
<p class="text-sm">{{ __('billing.jobs.mode', ['mode' => $this->modeLabel($job->mode)]) }}</p>
|
|
|
|
@if ($job->problem !== null)
|
|
<p class="flex items-start gap-2 text-sm font-medium text-red-700 dark:text-red-400">
|
|
<x-icon name="x-circle" class="size-5 shrink-0" aria-hidden="true" />
|
|
{{ $this->reasonText($job->problem, $job->missingRateNames) }}
|
|
</p>
|
|
@endif
|
|
|
|
@if ($export->isDraft() && $job->unapprovedQuarters > 0 && $job->mode !== BillingMode::MonthlyFee)
|
|
<p class="flex items-start gap-2 text-sm">
|
|
<x-icon name="exclamation-triangle" class="size-5 shrink-0" aria-hidden="true" />
|
|
<span>
|
|
{{ __('billing.jobs.unapproved', ['hours' => $this->hours($job->unapprovedQuarters)]) }}
|
|
<x-link :href="route('time.approvals')" navigate underline>{{ __('billing.jobs.approvals_link') }}</x-link>
|
|
</span>
|
|
</p>
|
|
@endif
|
|
|
|
@if ($export->isDraft())
|
|
@if ($job->mode === BillingMode::MonthlyFee)
|
|
@php($months = $this->linesOfKind($job, LineKind::MonthlyFee))
|
|
@if ($months === [])
|
|
<p class="text-sm">{{ __('billing.jobs.no_months') }}</p>
|
|
@else
|
|
<table class="w-full text-sm">
|
|
<caption class="mb-1 text-left font-medium">{{ __('billing.jobs.months_caption', ['job' => $job->label()]) }}</caption>
|
|
<thead>
|
|
<tr class="border-b border-zinc-300 text-left dark:border-zinc-600">
|
|
<th scope="col" class="py-2 pr-3">{{ __('billing.jobs.month') }}</th>
|
|
<th scope="col" class="py-2 text-right">{{ __('billing.jobs.amount') }}</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody class="divide-y divide-zinc-200 dark:divide-zinc-700">
|
|
@foreach ($months as $line)
|
|
<tr wire:key="month-{{ $job->jobId }}-{{ $line->period }}">
|
|
<td class="py-2 pr-3">{{ BillingMonths::label((string) $line->period) }}</td>
|
|
<td class="py-2 text-right whitespace-nowrap">{{ $this->money($line->netCents) }}</td>
|
|
</tr>
|
|
@endforeach
|
|
</tbody>
|
|
</table>
|
|
@endif
|
|
@php($approved = array_sum(array_map(fn ($row) => $row->approvedQuarters, $job->hours)))
|
|
@if ($approved > 0)
|
|
<p class="text-sm">{{ __('billing.jobs.monthly_hours', ['hours' => $this->hours($approved)]) }}</p>
|
|
@endif
|
|
@elseif ($job->mode === BillingMode::FixedPrice)
|
|
@php($fixed = $this->linesOfKind($job, LineKind::FixedPrice))
|
|
<p class="text-sm">
|
|
{{ $fixed === [] ? __('billing.jobs.fixed_price_billed') : __('billing.jobs.fixed_price', ['amount' => $this->money($fixed[0]->netCents)]) }}
|
|
</p>
|
|
@php($approved = array_sum(array_map(fn ($row) => $row->approvedQuarters, $job->hours)))
|
|
@if ($approved > 0)
|
|
<p class="text-sm">{{ __('billing.jobs.fixed_hours', ['hours' => $this->hours($approved)]) }}</p>
|
|
@endif
|
|
@elseif ($job->hours === [])
|
|
<p class="text-sm">{{ __('billing.jobs.no_hours') }}</p>
|
|
@else
|
|
<div class="overflow-x-auto">
|
|
<table class="w-full text-sm">
|
|
<caption class="sr-only">{{ __('billing.jobs.hours_caption', ['job' => $job->label()]) }}</caption>
|
|
<thead>
|
|
<tr class="border-b border-zinc-300 text-left dark:border-zinc-600">
|
|
<th scope="col" class="py-2 pr-3">{{ __('billing.jobs.work_type') }}</th>
|
|
<th scope="col" class="py-2 pr-3 text-right">{{ __('billing.jobs.approved_hours') }}</th>
|
|
<th scope="col" class="py-2 pr-3">{{ __('billing.jobs.billable_hours') }}</th>
|
|
<th scope="col" class="py-2 pr-3 text-right">{{ __('billing.jobs.rate') }}</th>
|
|
<th scope="col" class="py-2 text-right">{{ __('billing.jobs.net') }}</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody class="divide-y divide-zinc-200 dark:divide-zinc-700">
|
|
@foreach ($job->hours as $row)
|
|
@php($fieldId = 'hours-'.$job->jobId.'-'.$row->workTypeId)
|
|
<tr wire:key="{{ $fieldId }}">
|
|
<th scope="row" class="py-2 pr-3 text-left font-normal">{{ $row->name }}</th>
|
|
<td class="py-2 pr-3 text-right">{{ $this->hours($row->approvedQuarters) }}</td>
|
|
<td class="py-2 pr-3">
|
|
<input
|
|
id="{{ $fieldId }}"
|
|
type="text"
|
|
inputmode="decimal"
|
|
autocomplete="off"
|
|
value="{{ $this->hours($row->billableQuarters) }}"
|
|
wire:change="saveHours({{ $job->jobId }}, {{ $row->workTypeId }}, $event.target.value)"
|
|
aria-label="{{ __('billing.jobs.billable_label', ['work_type' => $row->name]) }}"
|
|
aria-describedby="hours-help-{{ $job->jobId }}"
|
|
@error('hours.'.$job->jobId.'.'.$row->workTypeId) aria-invalid="true" aria-errormessage="{{ $fieldId }}-error" @enderror
|
|
class="w-20 rounded-md border border-zinc-400 bg-white px-2 py-1.5 text-right text-zinc-900 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-700 aria-invalid:border-red-700 dark:border-zinc-500 dark:bg-zinc-900 dark:text-zinc-100 dark:aria-invalid:border-red-400"
|
|
/>
|
|
@if ($row->isAdjusted)
|
|
<span class="ml-1 text-xs">({{ __('billing.jobs.adjusted') }})</span>
|
|
@endif
|
|
@error('hours.'.$job->jobId.'.'.$row->workTypeId)
|
|
<span id="{{ $fieldId }}-error" class="mt-1 block text-xs text-red-700 dark:text-red-400">{{ $message }}</span>
|
|
@enderror
|
|
</td>
|
|
<td class="py-2 pr-3 text-right whitespace-nowrap">{{ $row->rateCents === null ? __('billing.jobs.no_rate') : $this->money($row->rateCents) }}</td>
|
|
<td class="py-2 text-right whitespace-nowrap">{{ $this->money($row->netCents) }}</td>
|
|
</tr>
|
|
@endforeach
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<p id="hours-help-{{ $job->jobId }}" class="text-xs text-zinc-600 dark:text-zinc-300">{{ __('billing.jobs.billable_help') }}</p>
|
|
@endif
|
|
|
|
@php($expenseLines = $this->linesOfKind($job, LineKind::Expense))
|
|
@if ($expenseLines !== [])
|
|
<table class="w-full text-sm">
|
|
<caption class="mb-1 text-left font-medium">{{ __('billing.jobs.expenses_caption', ['job' => $job->label()]) }}</caption>
|
|
<thead>
|
|
<tr class="border-b border-zinc-300 text-left dark:border-zinc-600">
|
|
<th scope="col" class="py-2 pr-3">{{ __('billing.jobs.expense') }}</th>
|
|
<th scope="col" class="py-2 text-right">{{ __('billing.jobs.amount') }}</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody class="divide-y divide-zinc-200 dark:divide-zinc-700">
|
|
@foreach ($expenseLines as $line)
|
|
<tr wire:key="expense-{{ $line->expenseId }}">
|
|
<td class="py-2 pr-3">{{ $line->description }}</td>
|
|
<td class="py-2 text-right whitespace-nowrap">{{ $this->money($line->netCents) }}</td>
|
|
</tr>
|
|
@endforeach
|
|
</tbody>
|
|
</table>
|
|
@endif
|
|
|
|
<div class="flex flex-wrap items-end gap-3">
|
|
@if (($invoice->mergeTargets[$job->jobId] ?? []) !== [])
|
|
<div class="w-full max-w-xs">
|
|
{{-- TallStackUI's native select does not tie its label to the control, so aria-label names it. --}}
|
|
<x-select.native
|
|
wire:model="moveTargets.{{ $job->jobId }}"
|
|
:label="__('billing.jobs.move_label', ['job' => $job->number])"
|
|
:aria-label="__('billing.jobs.move_label', ['job' => $job->number])"
|
|
>
|
|
<option value="">{{ __('billing.jobs.move_placeholder') }}</option>
|
|
@foreach ($invoice->mergeTargets[$job->jobId] as $target)
|
|
<option value="{{ $target->invoiceKey }}">{{ $target->label }}</option>
|
|
@endforeach
|
|
</x-select.native>
|
|
</div>
|
|
<x-button wire:click="move({{ $job->jobId }})" subtle color="black" sm icon="arrows-right-left" :text="__('billing.jobs.move')" :aria-label="__('billing.jobs.move_named', ['job' => $job->label()])" />
|
|
@endif
|
|
|
|
@if (count($invoice->jobs) > 1)
|
|
<x-button wire:click="separate({{ $job->jobId }})" subtle color="black" sm icon="document-duplicate" :text="__('billing.jobs.separate')" :aria-label="__('billing.jobs.separate_named', ['job' => $job->label()])" />
|
|
@endif
|
|
|
|
<x-button wire:click="remove({{ $job->jobId }})" subtle color="black" sm icon="minus-circle" :text="__('billing.jobs.remove')" :aria-label="__('billing.jobs.remove_named', ['job' => $job->label()])" />
|
|
</div>
|
|
@else
|
|
<div class="overflow-x-auto">
|
|
<table class="w-full text-sm">
|
|
<caption class="sr-only">{{ __('billing.lines.caption', ['job' => $job->label()]) }}</caption>
|
|
<thead>
|
|
<tr class="border-b border-zinc-300 text-left dark:border-zinc-600">
|
|
<th scope="col" class="py-2 pr-3">{{ __('billing.lines.description') }}</th>
|
|
<th scope="col" class="py-2 pr-3 text-right">{{ __('billing.lines.recorded') }}</th>
|
|
<th scope="col" class="py-2 pr-3 text-right">{{ __('billing.lines.quantity') }}</th>
|
|
<th scope="col" class="py-2 pr-3 text-right">{{ __('billing.lines.unit_price') }}</th>
|
|
<th scope="col" class="py-2 text-right">{{ __('billing.lines.net') }}</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody class="divide-y divide-zinc-200 dark:divide-zinc-700">
|
|
@foreach ($job->lines as $index => $line)
|
|
<tr wire:key="line-{{ $job->jobId }}-{{ $index }}">
|
|
<td class="py-2 pr-3">
|
|
<span class="block text-xs">{{ __('billing.kinds.'.$line->kind->value) }}</span>
|
|
{{ $line->description }}
|
|
</td>
|
|
<td class="py-2 pr-3 text-right">{{ $line->recordedQuarters === null ? '' : $this->hours($line->recordedQuarters) }}</td>
|
|
<td class="py-2 pr-3 text-right">{{ $line->quantityQuarters === null ? '' : $this->hours($line->quantityQuarters) }}</td>
|
|
<td class="py-2 pr-3 text-right whitespace-nowrap">{{ $this->money($line->unitPriceCents) }}</td>
|
|
<td class="py-2 text-right whitespace-nowrap">{{ $this->money($line->netCents) }}</td>
|
|
</tr>
|
|
@endforeach
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
@endif
|
|
</article>
|
|
@endforeach
|
|
|
|
<table class="ml-auto w-full max-w-sm text-sm">
|
|
<caption class="mb-1 text-left font-semibold">{{ __('billing.invoices.totals') }}</caption>
|
|
<tbody class="divide-y divide-zinc-200 dark:divide-zinc-700">
|
|
<tr>
|
|
<th scope="row" class="py-1 text-left font-normal">{{ __('billing.invoices.net') }}</th>
|
|
<td class="py-1 text-right whitespace-nowrap">{{ $this->money($invoice->totals->netCents) }}</td>
|
|
</tr>
|
|
@foreach ($invoice->totals->byVatRate as $basisPoints => $amounts)
|
|
<tr wire:key="invoice-{{ $invoice->key }}-vat-{{ $basisPoints }}">
|
|
<th scope="row" class="py-1 text-left font-normal">{{ __('billing.invoices.vat', ['rate' => $this->vatRate($basisPoints)]) }}</th>
|
|
<td class="py-1 text-right whitespace-nowrap">{{ $this->money($amounts['vat']) }}</td>
|
|
</tr>
|
|
@endforeach
|
|
<tr>
|
|
<th scope="row" class="py-1 text-left font-semibold">{{ __('billing.invoices.gross') }}</th>
|
|
<td class="py-1 text-right font-semibold whitespace-nowrap">{{ $this->money($invoice->totals->grossCents()) }}</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</section>
|
|
@endforeach
|
|
|
|
@if (count($export->invoices) > 1)
|
|
<table class="ml-auto w-full max-w-sm text-sm">
|
|
<caption class="mb-1 text-left font-semibold">{{ __('billing.invoices.export_totals') }}</caption>
|
|
<tbody class="divide-y divide-zinc-200 dark:divide-zinc-700">
|
|
<tr>
|
|
<th scope="row" class="py-1 text-left font-normal">{{ __('billing.invoices.net') }}</th>
|
|
<td class="py-1 text-right whitespace-nowrap">{{ $this->money($export->totals->netCents) }}</td>
|
|
</tr>
|
|
<tr>
|
|
<th scope="row" class="py-1 text-left font-semibold">{{ __('billing.invoices.gross') }}</th>
|
|
<td class="py-1 text-right font-semibold whitespace-nowrap">{{ $this->money($export->totals->grossCents()) }}</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
@endif
|
|
</section>
|
|
|
|
@if ($export->isDraft())
|
|
<section aria-labelledby="available-heading" class="space-y-3">
|
|
<h2 id="available-heading" class="text-xl font-semibold">{{ __('billing.available.title') }}</h2>
|
|
<p class="text-sm">{{ __('billing.available.intro') }}</p>
|
|
|
|
@if ($export->availableJobs === [])
|
|
<p class="text-sm">{{ __('billing.available.none') }}</p>
|
|
@else
|
|
<x-table :headers="$this->availableHeaders()" :rows="$export->availableJobs">
|
|
@interact('column_job', $available)
|
|
<x-link :href="route('jobs.show', $available->job->id)" navigate>{{ $available->job->label() }}</x-link>
|
|
@endinteract
|
|
|
|
@interact('column_customer', $available)
|
|
<span class="whitespace-normal">{{ $available->job->customerName }}</span>
|
|
@endinteract
|
|
|
|
@interact('column_mode', $available)
|
|
{{ $this->modeLabel($available->job->mode) }}
|
|
@endinteract
|
|
|
|
@interact('column_hours', $available)
|
|
{{ $this->hours($available->approvedQuarters) }}
|
|
@if ($available->unapprovedQuarters > 0)
|
|
<span class="block text-xs">{{ __('billing.available.unapproved', ['hours' => $this->hours($available->unapprovedQuarters)]) }}</span>
|
|
@endif
|
|
@endinteract
|
|
|
|
@interact('column_expenses', $available)
|
|
{{ $available->expenseCount }}
|
|
@endinteract
|
|
|
|
@interact('column_actions', $available)
|
|
@if ($available->reason === null)
|
|
<x-button wire:click="add({{ $available->job->id }})" sm icon="plus" :text="__('billing.available.add')" :aria-label="__('billing.available.add_named', ['job' => $available->job->label()])" />
|
|
@else
|
|
<span class="flex items-start gap-1 whitespace-normal text-sm">
|
|
<x-icon name="x-circle" class="size-4 shrink-0" aria-hidden="true" />
|
|
{{ $this->reasonText($available->reason, $available->missingRateNames) }}
|
|
</span>
|
|
@endif
|
|
@endinteract
|
|
</x-table>
|
|
@endif
|
|
</section>
|
|
|
|
<x-confirm-dialog id="finalize-dialog" :title="__('billing.export.finalize_title')">
|
|
<p>{{ __('billing.export.finalize_text', ['invoices' => count($export->invoices), 'net' => $this->money($export->totals->netCents)]) }}</p>
|
|
|
|
<x-slot:actions>
|
|
<x-button wire:click="finalize" :text="__('billing.export.finalize')" />
|
|
</x-slot:actions>
|
|
</x-confirm-dialog>
|
|
|
|
<x-confirm-dialog id="discard-dialog" :title="__('billing.export.discard_title')">
|
|
<p>{{ __('billing.export.discard_text') }}</p>
|
|
|
|
<x-slot:actions>
|
|
<x-button wire:click="discard" color="red" :text="__('billing.export.discard')" />
|
|
</x-slot:actions>
|
|
</x-confirm-dialog>
|
|
@endif
|
|
</div>
|