@extends('admin.layouts.dashboard') @section('title', 'Invoice ' . $invoice->invoice_number) @push('head') @include('admin.invoices._invoice-form-styles') @endpush @section('content')
{{-- Action bar --}}

Invoice {{ $invoice->invoice_number }}

Download PDF Edit @if($invoice->job_detail_id) Back @else Back @endif
@if(session('success'))
{{ session('success') }}
@endif @if(session('error'))
{{ session('error') }}
@endif @php function numberToWordsShow($number) { $ones = ['','One','Two','Three','Four','Five','Six','Seven','Eight','Nine','Ten', 'Eleven','Twelve','Thirteen','Fourteen','Fifteen','Sixteen','Seventeen','Eighteen','Nineteen']; $tens = ['','','Twenty','Thirty','Forty','Fifty','Sixty','Seventy','Eighty','Ninety']; if ($number == 0) return 'Zero'; $words = ''; $num = (int) $number; if ($num >= 1000) { $words .= numberToWordsShow((int)floor($num/1000)) . ' Thousand '; $num %= 1000; } if ($num >= 100) { $words .= $ones[(int)floor($num/100)] . ' Hundred '; $num %= 100; } if ($num >= 20) { $words .= $tens[(int)floor($num/10)] . ' '; $num %= 10; } if ($num > 0) { $words .= $ones[$num] . ' '; } return trim($words); } // Calculations $taxType = $invoice->tax_type ?? 'exclusive'; $overallDiscount = (float)($invoice->discount_amount ?? 0); $totals = \App\Models\Invoice::computeTotals($invoice->line_items, $taxType, $overallDiscount); $itemsSubtotal = $totals['itemsSubtotal']; $lineDiscountTotal = $totals['lineDiscountTotal']; $gstAmount = $totals['gstAmount']; $pstAmount = $totals['pstAmount']; $gstLabel = \App\Models\Invoice::taxSummaryLabel('GST', $totals['gstRateTotal'] ?? 0); $pstLabel = \App\Models\Invoice::taxSummaryLabel('HST/PST', $totals['pstRateTotal'] ?? 0); $totalExact = $totals['totalExact']; $totalRounded = $totals['totalRounded']; $roundedOff = $totals['roundedOff']; $showLineDiscount = $setting->usesLineItemDiscount(); $rawNum = $invoice->invoice_number; $numOnly = ltrim(preg_replace('/^INV-0*/i', '', $rawNum), '0') ?: '0'; $displayNum = '#' . $numOnly; // Due date fallback $dueDate = $invoice->due_date ? $invoice->due_date->format('M d, Y') : $invoice->invoice_date->copy()->addDays(30)->format('M d, Y'); @endphp {{-- ══════════════════════════════════════════════════════════ Invoice paper ══════════════════════════════════════════════════════════ --}}
{{-- ── HEADER ROW: Logo | INVOICE | #num + Original Copy ── --}}
@if($setting->logo_path) {{ $setting->business_name }} @else {{ $setting->business_name }} @endif INVOICE
{{ $displayNum }}
Original Copy
{{-- ── INFO ROW: FROM (left) | Amount Due + Dates (right) ── --}}
{{ $setting->business_name }}
{{ $setting->address }}
@if($setting->phone) Phone: {{ $setting->phone }}
@endif @if($setting->email) Email: {{ $setting->email }}
@endif @if($setting->website) Website: {{ $setting->website }}
@endif @include('admin.invoices.partials._tax-registration-lines', ['invoiceGstNumber' => $invoice->gst_number ?? null])
{{-- Amount Due banner --}}
Amount Due: ${{ number_format($totalRounded, 2) }}
{{-- Issue / Due dates --}}
@if($invoice->payment_terms) @endif
Invoice No: {{ $invoice->invoice_number }}
Terms: {{ \App\Models\Invoice::paymentTermsOptions()[$invoice->payment_terms] ?? $invoice->payment_terms }}
Issue Date: {{ $invoice->invoice_date->format('d - M - Y') }}
Due Date: {{ $dueDate }}
{{-- ── BILL TO ── --}}
Bill To
{{ $invoice->customer_name }}
@if($invoice->customer_phone)
{{ $invoice->customer_phone }}
@endif @if($invoice->customer_email) @endif @if($invoice->customer_address)
{{ $invoice->customer_address }}
@endif @if($invoice->customer_country)
{{ $invoice->customer_country }}
@endif
{{-- ── ITEMS TABLE ── --}}
@if($showLineDiscount) @endif @if($taxType === 'exclusive') @endif @foreach($invoice->line_items as $i => $item) @php $li = \App\Models\Invoice::computeLineItem($item, $taxType); $itemDesc = $invoice->lineItemDescriptionForDisplay($item, $loop->first); $linkedItems = $loop->first ? $invoice->linkedItemsLabel() : null; $qtyDisplay = $li['qty'] % 1 == 0 ? (int)$li['qty'] : $li['qty']; $gstRateShow = $li['gstRate'] > 0 || ($li['gstRate'] + $li['pstRate'] === 0.0 && ($item['tax_rate'] ?? 0) > 0) ? ($li['gstRate'] + $li['pstRate'] === 0.0 ? ($item['tax_rate'] ?? 0) : $li['gstRate']) : 0; @endphp @if($showLineDiscount) @endif @if($taxType === 'exclusive') @endif @endforeach @if($showLineDiscount && $lineDiscountTotal > 0) @endif @if($overallDiscount > 0) @endif @if($taxType !== 'inclusive' && $gstAmount > 0) @endif @if($taxType !== 'inclusive' && $pstAmount > 0) @endif
# Item & Description Unit Qty PriceDisc%GST HST/PSTAmount
{{ $i + 1 }}
#{{ $i + 1 }} Item
Unit {{ $item['unit'] ?? '—' }}
{{ $item['description'] }}
@if($itemDesc || $linkedItems)
@if($itemDesc){!! nl2br(e($itemDesc)) !!}@endif @if($linkedItems) @if($itemDesc)
@endif Item(s): {{ $linkedItems }} @endif
@endif
{{ $item['unit'] ?? '—' }} {{ $qtyDisplay }} ${{ number_format($li['displayRate'], 2) }} @if($li['discPct'] > 0) {{ number_format($li['discPct'], 0) }}% @else — @endif @if($li['gstRate'] > 0 || ($li['gstRate'] + $li['pstRate'] === 0.0 && ($item['tax_rate'] ?? 0) > 0)) ${{ number_format($li['gstAmt'], 2) }}
{{ number_format($gstRateShow, 0) }}% @else — @endif
{{ $gstRateShow > 0 ? number_format($gstRateShow, 0) . '%' : '—' }}
@if($li['pstRate'] > 0) ${{ number_format($li['pstAmt'], 2) }}
{{ number_format($li['pstRate'], 0) }}% @else — @endif
{{ $li['pstRate'] > 0 ? number_format($li['pstRate'], 0) . '%' : '—' }}
{{ ($showLineDiscount && $li['discAmt'] > 0) ? 'Disc -$' . number_format($li['discAmt'], 2) : '' }} {{ ($taxType !== 'inclusive' && $li['gstAmt'] > 0) ? 'GST +$' . number_format($li['gstAmt'], 2) : '' }} {{ ($taxType !== 'inclusive' && $li['pstAmt'] > 0) ? 'HST +$' . number_format($li['pstAmt'], 2) : '' }} ${{ number_format($li['rowAmt'], 2) }}
Subtotal ${{ number_format($itemsSubtotal, 2) }}
Discount -${{ number_format($lineDiscountTotal, 2) }}
Overall Discount{{ $invoice->discount_type === 'percent' ? ' ('.$invoice->discount_value.'%)' : '' }} -${{ number_format($overallDiscount, 2) }}
{{ $gstLabel }} ${{ number_format($gstAmount, 2) }}
{{ $pstLabel }} ${{ number_format($pstAmount, 2) }}
Rounded Off {{ ($roundedOff >= 0 ? '+' : '') . '$' . number_format($roundedOff, 2) }}
TOTAL ${{ number_format($totalRounded, 2) }}
{{-- ── BOTTOM ROW: Terms (left) | Summary (right) ── --}} {{-- Left: Terms & Conditions + Payment info --}} {{-- Right: Summary table (desktop) --}}
{{-- /card-body --}}
{{-- /card --}}
@endsection