@php // Safe data extraction with defaults $store = $data['store'] ?? [ 'name' => config('app.name', 'Kenyan Supermarket'), 'address' => config('app.address', 'Nairobi CBD'), 'phone' => config('app.phone', '0700 000 000'), 'pin' => config('app.pin', 'P051234567N'), 'vat_number' => config('app.vat_number', 'VAT001234567'), ]; $customer = $data['customer'] ?? null; $items = $data['items'] ?? []; $totals = $data['totals'] ?? []; $payment = $data['payment'] ?? []; $vatInfo = $data['vat_info'] ?? []; $notes = $data['notes'] ?? []; // Safe customer data $customerName = $customer['name'] ?? null; $customerPhone = $customer['phone'] ?? null; $customerEmail = $customer['email'] ?? null; $customerPin = $customer['pin'] ?? null; $customerVatNumber = $customer['vat_number'] ?? null; $customerVatStatus = $customer['vat_status'] ?? 'vatable'; // Safe totals $subtotal = $totals['subtotal'] ?? 0; $discount = $totals['discount'] ?? 0; $vatAmount = $totals['vat_amount'] ?? 0; $grandTotal = $totals['grand_total'] ?? 0; $taxableAmount = $totals['taxable_amount'] ?? 0; $nonTaxableAmount = $totals['non_taxable_amount'] ?? 0; $exemptedAmount = $totals['exempted_amount'] ?? 0; $zeroRatedAmount = $totals['zero_rated_amount'] ?? 0; // Safe payment data $paymentMethod = $payment['method'] ?? 'cash'; $amountPaid = $payment['amount_paid'] ?? $grandTotal; $cashReceived = $payment['cash_received'] ?? null; $change = $payment['change'] ?? null; $transactionId = $payment['transaction_id'] ?? null; $mpesaDetails = $payment['mpesa_details'] ?? null; // Safe vat info $isVatApplicable = $vatInfo['is_vat_applicable'] ?? true; $isZeroRated = $vatInfo['is_zero_rated'] ?? false; $isExempted = $vatInfo['is_exempted'] ?? false; $vatBreakdown = $vatInfo['breakdown'] ?? []; // Default notes if none provided if (empty($notes)) { $notes = [ 'Thank you for your business!', 'Keep this receipt for warranty claims', 'VAT Invoice - Valid for Tax Purposes', 'Items sold are not returnable unless defective', 'Please check goods before leaving the counter', 'Valid for 7 days from date of purchase' ]; } @endphp
{{ strtoupper($store['name']) }}
{{ $store['address'] ?? '' }}
Tel: {{ $store['phone'] ?? '' }}
@if(!empty($store['pin']))
PIN: {{ $store['pin'] }}
@endif @if(!empty($store['vat_number']))
VAT: {{ $store['vat_number'] }}
@endif
Invoice No: {{ $data['invoice_no'] ?? '' }}
Receipt No: {{ $data['receipt_no'] ?? '' }}
Date: {{ $data['date'] ?? '' }} {{ $data['time'] ?? '' }}
Cashier: {{ $data['cashier'] ?? 'Cashier' }}
{{-- Customer Information --}} @if($customerName)
Customer: {{ $customerName }}
@endif @if($customerPhone)
Phone: {{ $customerPhone }}
@endif @if($customerVatNumber)
VAT No: {{ $customerVatNumber }}
@endif @if($customerVatStatus && in_array($customerVatStatus, ['exempted', 'zero_rated']))
VAT Status: {{ $customerVatStatus === 'exempted' ? 'VAT Exempted' : ($customerVatStatus === 'zero_rated' ? 'Zero-Rated' : 'VATable') }}
@endif @if(!$customerName)
Customer: Walk-in Customer
@endif
ITEMS
ITEM
QTY
PRICE
TOTAL
@if(count($items) > 0) @foreach($items as $item) @php $itemName = $item['name'] ?? 'Item'; $itemQty = $item['quantity'] ?? $item['qty'] ?? 1; $itemPrice = $item['unit_price'] ?? $item['price'] ?? 0; $itemTotal = $item['total'] ?? ($itemPrice * $itemQty); $itemTaxRate = $item['tax_rate'] ?? 0; $itemTaxAmount = $item['tax_amount'] ?? 0; $isVatable = $item['is_vatable'] ?? ($itemTaxRate > 0); @endphp
{{ $itemName }}
{{ $itemQty }}
KES {{ number_format($itemPrice, 2) }}
KES {{ number_format($itemTotal, 2) }}
@if($isVatable && $itemTaxRate > 0 && $itemTaxAmount > 0)
VAT {{ $itemTaxRate }}% KES {{ number_format($itemTaxAmount, 2) }}
@endif @endforeach @else
No items
0.00
@endif
TOTALS
Subtotal: KES {{ number_format($subtotal, 2) }}
@if($discount > 0)
Discount: -KES {{ number_format($discount, 2) }}
@endif @if(count($vatBreakdown) > 0) @foreach($vatBreakdown as $vat)
VAT {{ $vat['rate'] ?? 16 }}%: KES {{ number_format($vat['amount'] ?? 0, 2) }}
@endforeach @elseif($vatAmount > 0)
VAT: KES {{ number_format($vatAmount, 2) }}
@endif @if($taxableAmount > 0)
Taxable Amount: KES {{ number_format($taxableAmount, 2) }}
@endif @if($nonTaxableAmount > 0)
Non-taxable: KES {{ number_format($nonTaxableAmount, 2) }}
@endif @if($exemptedAmount > 0)
Exempted: KES {{ number_format($exemptedAmount, 2) }}
@endif @if($zeroRatedAmount > 0)
Zero-rated: KES {{ number_format($zeroRatedAmount, 2) }}
@endif
TOTAL: KES {{ number_format($grandTotal, 2) }}
PAYMENT
{{ strtoupper($paymentMethod) }}
Amount Paid: KES {{ number_format($amountPaid, 2) }}
@if($paymentMethod === 'cash' && $cashReceived)
Cash Received: KES {{ number_format($cashReceived, 2) }}
@endif @if($paymentMethod === 'cash' && $change > 0)
Change: KES {{ number_format($change, 2) }}
@endif @if($paymentMethod === 'mpesa' && $mpesaDetails)
Phone: {{ $mpesaDetails['phone'] ?? '' }}
Transaction ID: {{ $mpesaDetails['transaction_id'] ?? '' }}
@endif @if($transactionId)
Transaction ID: {{ $transactionId }}
@endif
@if($isExempted || $isZeroRated || !$isVatApplicable)
VAT INFORMATION
@if($isExempted)
VAT EXEMPTED CUSTOMER
No VAT Applied
@elseif($isZeroRated)
ZERO-RATED CUSTOMER
0% VAT Rate Applied
@elseif(!$isVatApplicable)
NO VAT APPLICABLE
VAT Not Applied
@endif
@endif
@if($data['invoice_no'] ?? false)
Receipt No: {{ $data['invoice_no'] }}
@endif