@php $errorBag = $errors ?? new \Illuminate\Support\ViewErrorBag(); $errors = $errorBag; $documentType = $type === 'invoice' ? 'Invoice' : 'Quotation'; $statusOptions = $type === 'invoice' ? ['draft' => 'Draft', 'sent' => 'Sent', 'paid' => 'Paid'] : ['draft' => 'Draft', 'sent' => 'Sent']; if ($type === 'invoice' && ! auth()->user()?->can('mark-invoices-paid')) { if (($document->status ?? null) === 'paid') { $statusOptions = ['paid' => 'Paid']; } else { unset($statusOptions['paid']); } } $dateFieldTwo = $type === 'invoice' ? 'due_date' : 'valid_until'; $dateFieldTwoLabel = $type === 'invoice' ? 'Due date' : 'Valid until'; $items = old('items', isset($document) && $document->items ? $document->items->map(fn ($item) => $item->only(['description', 'quantity', 'unit_price']))->all() : [['description' => '', 'quantity' => 1, 'unit_price' => 0]]); $submitLabel = $submitLabel ?? 'Save'; $notesLabel = $type === 'invoice' ? 'Notes' : 'Notes'; $fieldClass = function (string $field, string $baseClass) use ($errorBag): string { return $errorBag->has($field) ? $baseClass.' '.$baseClass.'-invalid' : $baseClass; }; $hasItemErrors = $errorBag->has('items') || collect($errorBag->keys())->contains(fn ($key) => str_starts_with($key, 'items.')); $initialSubtotal = collect($items)->sum(fn ($item) => (float) ($item['quantity'] ?? 0) * (float) ($item['unit_price'] ?? 0)); $initialTaxRate = (float) old('tax_rate', $document->tax_rate ?? 15); $initialTax = $initialSubtotal * ($initialTaxRate / 100); $initialGrandTotal = $initialSubtotal + $initialTax; @endphp @csrf
@if ($errorBag->any()) @endif
01

Client & status

Select client and status.

@error('client_id')

{{ $message }}

@enderror

Links to client records.

@error('status')

{{ $message }}

@enderror

Choose the current status.

02

Dates & settings

Set dates. VAT uses Company Settings.

@error('issue_date')

{{ $message }}

@enderror
@error($dateFieldTwo)

{{ $message }}

@enderror
@error('tax_rate')

{{ $message }}

@enderror
03

Notes

Add short client notes.

@error('notes')

{{ $message }}

@enderror

Shown on the client document.

04

Line items

Add products or services.

Description Qty Price Total
@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

Keep line items clear.

Use one row per item.

@if ($hasItemErrors)
One or more line items need attention. Review the highlighted fields below.
@endif @error('items')

{{ $message }}

@enderror
@if (! file_exists(public_path('build/manifest.json'))) @include('components.documents.builder-script') @endif