@php $customerOptions = $customers->mapWithKeys(fn ($customer) => [$customer->id => $customer->name.' - '.($customer->email ?: $customer->phone ?: 'No contact')])->all(); $serviceOptions = $services->mapWithKeys(fn ($service) => [$service->id => $service->name.' ('.($currentBusiness?->currency ?? 'USD').' '.number_format((float) $service->price, 2).')'])->all(); $appointmentOptions = $appointments->mapWithKeys(fn ($appointment) => [ $appointment->id => trim(($appointment->booking_number ?: 'Appointment').' - '.($appointment->customer?->name ?? 'Customer').' - '.($appointment->service?->name ?? 'Service')), ])->all(); $oldItems = old('items'); if (is_array($oldItems) && count($oldItems) > 0) { $formItems = collect($oldItems); } elseif ($invoice->exists && $invoice->items->isNotEmpty()) { $formItems = $invoice->items->map(fn ($item) => [ 'service_id' => $item->service_id, 'description' => $item->description, 'quantity' => $item->quantity, 'unit_price' => $item->unit_price, 'tax_rate' => $item->tax_rate, ]); } else { $firstService = $services->first(); $formItems = collect([ [ 'service_id' => $firstService?->id, 'description' => $firstService?->name ?? 'Service appointment', 'quantity' => 1, 'unit_price' => $firstService?->price ?? 0, 'tax_rate' => 0, ], ]); } while ($formItems->count() < 4) { $formItems->push(['service_id' => null, 'description' => null, 'quantity' => null, 'unit_price' => null, 'tax_rate' => 0]); } $statusValue = old('status', $invoice->status_value ?: 'draft'); @endphp
@csrf @if ($formMethod !== 'POST') @method($formMethod) @endif @if ($errors->any())

Please fix the highlighted invoice fields.

@endif
@foreach (['Service', 'Description', 'Qty', 'Price', 'Tax %', 'Line Total'] as $heading) @endforeach @foreach ($formItems as $index => $item) @php $quantity = old("items.$index.quantity", $item['quantity'] ?? null); $unitPrice = old("items.$index.unit_price", $item['unit_price'] ?? null); $lineTotal = (float) $quantity * (float) $unitPrice; @endphp @endforeach
{{ $heading }}
{{ ($invoice->currency ?: ($currentBusiness?->currency ?? 'USD')).' '.number_format($lineTotal, 2) }}

Blank rows are ignored. Dynamic add/remove controls can be wired later when the invoice editor JavaScript is expanded.

Cancel {{ $submitLabel }}