@php
$errorBag = $errors ?? new \Illuminate\Support\ViewErrorBag();
$items = old('items', $recurringInvoice->items?->map(fn ($item) => $item->only(['description', 'quantity', 'unit_price']))->all() ?: [['description' => '', 'quantity' => 1, 'unit_price' => 0]]);
$fieldClass = fn (string $field, string $baseClass): string => $errorBag->has($field) ? $baseClass.' '.$baseClass.'-invalid' : $baseClass;
$initialSubtotal = collect($items)->sum(fn ($item) => (float) ($item['quantity'] ?? 0) * (float) ($item['unit_price'] ?? 0));
$initialTaxRate = (float) old('tax_rate', $recurringInvoice->tax_rate ?? 15);
$initialTax = $initialSubtotal * ($initialTaxRate / 100);
$initialGrandTotal = $initialSubtotal + $initialTax;
$hasItemErrors = $errorBag->has('items') || collect($errorBag->keys())->contains(fn ($key) => str_starts_with($key, 'items.'));
@endphp
@csrf
@if (($method ?? null) === 'PUT')
@method('PUT')
@endif
@if ($errorBag->any())
Please correct the highlighted fields.
Complete the recurring invoice setup.
@endif
@error('client_id')
{{ $message }}
@enderror
@error('title')
{{ $message }}
@enderror
@error('frequency')
{{ $message }}
@enderror
@error('generation_mode')
{{ $message }}
@enderror
Track only creates an open invoice for manual payment recording without emailing the client.
@error('start_date')
{{ $message }}
@enderror
@error('next_run_date')
{{ $message }}
@enderror
@error('end_date')
{{ $message }}
@enderror
@error('due_days')
{{ $message }}
@enderror
@error('tax_rate'){{ $message }}
@enderror
@error('notes'){{ $message }}
@enderror
DescriptionQtyPriceTotal
@foreach ($items as $index => $item)
@php
$descriptionKey = "items.$index.description";
$quantityKey = "items.$index.quantity";
$priceKey = "items.$index.unit_price";
$lineTotal = (float) ($item['quantity'] ?? 0) * (float) ($item['unit_price'] ?? 0);
@endphp
Description
@error($descriptionKey)
{{ $message }}
@enderror
Qty
@error($quantityKey)
{{ $message }}
@enderror
Price
@error($priceKey)
{{ $message }}
@enderror
Total
R {{ number_format($lineTotal, 2) }}
@endforeach
@if ($hasItemErrors)Review the highlighted line items.
@endif
@error('items'){{ $message }}
@enderror
@if (! file_exists(public_path('build/manifest.json')))
@include('components.documents.builder-script')
@endif