Add monthly fee billing lines to the billing material

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]>
This commit is contained in:
2026-11-24 13:23:46 +02:00
co-authored by Claude Opus 5.5
parent 97bd23bed5
commit 5f9423a3c3
49 changed files with 799 additions and 82 deletions
@@ -14,6 +14,7 @@ use App\Modules\Jobs\Domain\Exceptions\InvalidEstimatedHours;
use App\Modules\Jobs\Domain\Exceptions\InvalidJobLink;
use App\Modules\Jobs\Domain\Exceptions\InvalidJobName;
use App\Modules\Jobs\Domain\Exceptions\InvalidJobReference;
use App\Modules\Jobs\Domain\Exceptions\InvalidMonthlyFee;
use App\Modules\Jobs\Domain\Exceptions\InvalidTag;
use App\Modules\Jobs\Domain\Exceptions\PlanEndsBeforeStart;
use App\Modules\Jobs\Domain\Exceptions\ServiceUnitRequired;
@@ -62,6 +63,8 @@ class JobForm extends Form
*/
public string $quoted_amount = '';
public string $monthly_fee = '';
public string $customer_reference = '';
public string $instructions = '';
@@ -101,6 +104,7 @@ class JobForm extends Form
$this->payment_basis = $job->paymentBasis->value ?? '';
$this->estimated_hours = $job->estimatedHours ?? '';
$this->quoted_amount = $job->quotedAmountCents === null || ! Gate::allows('money.quotes') ? '' : Money::fromCents($job->quotedAmountCents)->inputValue();
$this->monthly_fee = $job->monthlyFeeCents === null || ! Gate::allows('money.quotes') ? '' : Money::fromCents($job->monthlyFeeCents)->inputValue();
$this->customer_reference = $job->customerReference ?? '';
$this->instructions = $job->instructions ?? '';
$this->responsible_user_id = (string) $job->responsible->id;
@@ -146,6 +150,7 @@ class JobForm extends Form
links: array_values(array_filter($this->links, fn (array $link): bool => trim($link['title']) !== '' || trim($link['url']) !== '')),
quotedAmount: $text($this->quoted_amount),
setsQuotedAmount: Gate::allows('money.quotes'),
monthlyFee: $this->payment_basis === PaymentBasis::MonthlyFee->value ? $text($this->monthly_fee) : null,
);
}
@@ -161,6 +166,7 @@ class JobForm extends Form
$exception instanceof PlanEndsBeforeStart => ['planned_to', 'jobs.errors.plan_ends_before_start'],
$exception instanceof InvalidEstimatedHours => ['estimated_hours', 'jobs.errors.invalid_hours'],
$exception instanceof InvalidMoneyAmount => ['quoted_amount', 'jobs.errors.invalid_amount'],
$exception instanceof InvalidMonthlyFee => ['monthly_fee', 'jobs.errors.invalid_amount'],
$exception instanceof InvalidTag => ['tags', 'jobs.errors.invalid_tag'],
$exception instanceof InvalidJobLink => ['links', 'jobs.errors.invalid_link'],
$exception instanceof InvalidJobReference => [self::referenceField($exception->field), 'jobs.errors.invalid_reference'],
@@ -201,6 +207,7 @@ class JobForm extends Form
'payment_basis' => ['nullable', Rule::enum(PaymentBasis::class)],
'estimated_hours' => ['nullable', 'numeric', 'min:0', 'max:99999'],
'quoted_amount' => ['nullable', 'string', 'max:20'],
'monthly_fee' => ['nullable', 'string', 'max:20'],
'customer_reference' => ['nullable', 'string', 'max:255'],
'instructions' => ['nullable', 'string', 'max:10000'],
'responsible_user_id' => ['required', 'integer'],
@@ -240,6 +247,7 @@ class JobForm extends Form
'estimated_hours.min' => __('jobs.errors.invalid_hours'),
'estimated_hours.max' => __('jobs.errors.invalid_hours'),
'quoted_amount.max' => __('jobs.errors.invalid_amount'),
'monthly_fee.max' => __('jobs.errors.invalid_amount'),
'customer_reference.max' => __('jobs.errors.too_long', ['max' => 255]),
'instructions.max' => __('jobs.errors.too_long', ['max' => 10000]),
'responsible_user_id.required' => __('jobs.errors.responsible_required'),
@@ -342,7 +342,7 @@ new class extends Component
@endforeach
</x-select.native>
<x-select.native wire:model="form.payment_basis" :label="__('jobs.fields.payment_basis')" :aria-label="__('jobs.fields.payment_basis')">
<x-select.native wire:model.live="form.payment_basis" :label="__('jobs.fields.payment_basis')" :aria-label="__('jobs.fields.payment_basis')">
<option value="">{{ __('jobs.fields.no_payment_basis') }}</option>
@foreach (PaymentBasis::cases() as $basis)
<option value="{{ $basis->value }}">{{ __('jobs.payment_bases.'.$basis->value) }}</option>
@@ -367,6 +367,16 @@ new class extends Component
:label="__('jobs.fields.quoted_amount_input')"
:hint="__('jobs.fields.quoted_amount_description')"
/>
@if ($form->payment_basis === 'monthly_fee')
<x-input
wire:model="form.monthly_fee"
inputmode="decimal"
autocomplete="off"
:label="__('jobs.fields.monthly_fee_input')"
:hint="__('jobs.fields.monthly_fee_description')"
/>
@endif
@endcan
</div>
</fieldset>
@@ -67,7 +67,7 @@ new class extends Component
// Changes of the quoted amount are shown only to those who may see quotes (spec 5.7).
return Gate::allows('money.quotes')
? $changes
: array_values(array_filter($changes, fn (JobChangeEntry $change): bool => $change->field !== 'quoted_amount'));
: array_values(array_filter($changes, fn (JobChangeEntry $change): bool => ! in_array($change->field, ['quoted_amount', 'monthly_fee'], true)));
}
/**
@@ -171,7 +171,7 @@ new class extends Component
return match ($field) {
'starts_on', 'due_on', 'planned_from', 'planned_to' => $this->formatDate($value),
'quoted_amount' => Money::fromCents((int) $value)->format(),
'quoted_amount', 'monthly_fee' => Money::fromCents((int) $value)->format(),
'kind' => __('jobs.kinds.'.$value),
'status' => __('jobs.statuses.'.$value),
'priority' => __('jobs.priorities.'.$value),
@@ -245,6 +245,11 @@ new class extends Component
@can('money.quotes')
<dt class="font-medium">{{ __('jobs.fields.quoted_amount') }}</dt>
<dd>{{ $job->quotedAmountCents === null ? __('jobs.not_set') : Money::fromCents($job->quotedAmountCents)->format().' '.__('jobs.vat_excluded') }}</dd>
@if ($job->paymentBasis?->value === 'monthly_fee' || $job->monthlyFeeCents !== null)
<dt class="font-medium">{{ __('jobs.fields.monthly_fee') }}</dt>
<dd>{{ $job->monthlyFeeCents === null ? __('jobs.not_set') : Money::fromCents($job->monthlyFeeCents)->format().' '.__('jobs.vat_excluded') }}</dd>
@endif
@endcan
<dt class="font-medium">{{ __('jobs.fields.customer_reference') }}</dt>