@php $awaitingCount = $sectionsWithLines->flatMap(fn ($s) => $s['lines'])->where('customer_approval', 'awaiting')->count(); $approvedCount = $sectionsWithLines->flatMap(fn ($s) => $s['lines'])->where('customer_approval', 'approved')->count(); $rejectedCount = $sectionsWithLines->flatMap(fn ($s) => $s['lines'])->where('customer_approval', 'rejected')->count(); @endphp {{-- ── Job card summary strip ──────────────────────────────────────────────── --}}
Final Invoice
{{ $jobCard->displayName() }}
{{ $jobCard->vehicleDescription() }} @if($jobCard->vehicle_registration) {{ $jobCard->vehicle_registration }} @endif
Customer
{{ $jobCard->customer_email }}
@if($jobCard->invoice_sent_at)
Invoice sent {{ $jobCard->invoice_sent_at->format('d M Y H:i') }}
@else
Not yet sent to customer
@endif
{{ $awaitingCount }}
Awaiting
{{ $approvedCount }}
Approved
@if($rejectedCount > 0)
{{ $rejectedCount }}
Rejected
@endif
{{-- ── Awaiting notice ──────────────────────────────────────────────────────── --}} @if($awaitingCount > 0)
{{ $awaitingCount }} line{{ $awaitingCount !== 1 ? 's' : '' }} awaiting customer approval. Use Send Invoice to Customer above to notify the customer to review and approve.
@endif {{-- ── Sections ─────────────────────────────────────────────────────────────── --}} @foreach($sectionsWithLines as $item) @php $section = $item['section']; $lines = $item['lines']; $statusColors = [ 'open' => 'bg-gray-100 text-gray-600', 'pending_approval' => 'bg-amber-100 text-amber-700', 'approved' => 'bg-blue-100 text-blue-700', 'paid' => 'bg-green-100 text-green-700', ]; $statusColor = $statusColors[$section->status] ?? 'bg-gray-100 text-gray-600'; $statusLabel = \App\Domain\Workshop\Models\JobCardSection::STATUSES[$section->status] ?? $section->status; @endphp
{{-- Section header --}}
{{ $section->name }} {{ $statusLabel }} @if($section->assignedTo) {{ $section->assignedTo->name }} @endif
{{-- Lines table --}} @if($lines->isEmpty())
No invoice lines yet for this section.
Import labour hours from the button above, or add parts/consumable lines.
@else @foreach($lines as $i => $line) @php $rowBg = $i % 2 === 0 ? '' : 'bg-gray-50'; $typeColors = [ 'labour' => 'bg-green-50 text-green-700', 'parts' => 'bg-blue-50 text-blue-700', 'consumables' => 'bg-amber-50 text-amber-700', ]; $typeColor = $typeColors[$line->type] ?? 'bg-gray-100 text-gray-600'; $approvalColors = [ 'awaiting' => 'bg-amber-50 text-amber-700', 'approved' => 'bg-green-50 text-green-700', 'rejected' => 'bg-red-50 text-red-600', ]; $approvalColor = $approvalColors[$line->customer_approval] ?? 'bg-gray-100 text-gray-600'; $approvalLabel = ['awaiting'=>'Awaiting','approved'=>'Approved','rejected'=>'Rejected'][$line->customer_approval] ?? $line->customer_approval; @endphp @endforeach
Description Type Supplier Qty / Hours Cost excl Markup Unit excl Total incl Approval
{{ $line->description }} @if($line->mechanic_name)
{{ $line->mechanic_name }}
@endif
{{ \App\Domain\Workshop\Models\JobCardInvoiceLine::TYPES[$line->type] ?? $line->type }} {{ $line->supplier ?: '—' }} {{ $line->type === 'labour' ? number_format($line->actual_hours, 1) . 'h' : number_format($line->quantity, $line->quantity == intval($line->quantity) ? 0 : 2) }} {{ $line->cost_price_excl_vat !== null ? 'R '.number_format($line->cost_price_excl_vat, 2) : '—' }} {{ $line->markup_pct !== null ? number_format($line->markup_pct * 100, 0).'%' : '—' }} R {{ number_format($line->unit_price_excl_vat, 2) }} R {{ number_format($line->total_incl_vat, 2) }} {{ $approvalLabel }}
Section subtotal excl. VAT R {{ number_format($item['subtotal_excl'], 2) }}
VAT (15%) R {{ number_format($item['vat'], 2) }}
Section Total incl. VAT R {{ number_format($item['total_incl'], 2) }}
@endif
@endforeach {{-- ── Grand total ──────────────────────────────────────────────────────────── --}} @if($grandTotal > 0)
Grand Total
{{ $totalLines }} line{{ $totalLines !== 1 ? 's' : '' }} across {{ $sectionsWithLines->count() }} section{{ $sectionsWithLines->count() !== 1 ? 's' : '' }}
Excl. VAT
R {{ number_format($grandExcl, 2) }}
VAT 15%
R {{ number_format($grandVat, 2) }}
R {{ number_format($grandTotal, 2) }}
Total incl. VAT
@endif