@php
$sym = config('pos.company.currency_symbol');
$billable = $split ?? $order;
$lines = ($split ? $split->items : $order->items)->where('status', '!=', 'void');
$happySaved = $lines->sum(fn ($i) => $i->original_price ? ((float) $i->original_price - (float) $i->unit_price) * $i->quantity : 0);
$documentType = $documentType ?? ((! $split && (bool) ($order->proforma ?? false)) ? 'bill' : 'receipt');
$isBill = $documentType === 'bill';
$globalReceipt = [
'show_logo' => \App\Models\Setting::get('receipt', 'show_logo', true),
'show_business_name' => \App\Models\Setting::get('receipt', 'show_business_name', true),
'show_landmark' => \App\Models\Setting::get('receipt', 'show_landmark', true),
'landmark' => \App\Models\Setting::get('receipt', 'landmark', ''),
'show_customer_details' => \App\Models\Setting::get('receipt', 'show_customer_details', true),
'show_business_contacts' => \App\Models\Setting::get('receipt', 'show_business_contacts', true),
'show_phone' => \App\Models\Setting::get('receipt', 'show_phone', true),
'show_alternative_phone' => \App\Models\Setting::get('receipt', 'show_alternative_phone', false),
'show_email' => \App\Models\Setting::get('receipt', 'show_email', false),
'show_website' => \App\Models\Setting::get('receipt', 'show_website', false),
'show_kra_pin' => \App\Models\Setting::get('receipt', 'show_kra_pin', true),
'show_order_details' => \App\Models\Setting::get('receipt', 'show_order_details', true),
'header_text' => \App\Models\Setting::get('receipt', 'header_text', ''),
'footer_text' => \App\Models\Setting::get('receipt', 'footer_text', 'Thank you for dining with us!'),
];
$receiptBranch = !empty($order->branch_id) ? \App\Models\Branch::find($order->branch_id) : null;
$branchReceipt = (array) ($receiptBranch?->receipt_settings ?? []);
$receipt = array_merge($globalReceipt, array_intersect_key($branchReceipt, $globalReceipt));
if (array_key_exists('landmark', $branchReceipt)) $receipt['landmark'] = $branchReceipt['landmark'];
$receiptBusinessName = $branchReceipt['business_name'] ?? $receiptBranch?->name ?? \App\Models\Setting::get('general', 'company_name', config('pos.company.name'));
$receiptBusinessAddress = $branchReceipt['address'] ?? $receiptBranch?->address ?? config('pos.company.address');
$receiptBusinessPhone = $branchReceipt['phone'] ?? $receiptBranch?->phone ?? \App\Models\Setting::get('general', 'business_phone', config('pos.company.phone', ''));
$receiptAlternativePhone = $branchReceipt['alternative_phone'] ?? \App\Models\Setting::get('general', 'alternative_phone', '');
$receiptEmail = $branchReceipt['email'] ?? \App\Models\Setting::get('general', 'business_email', '');
$receiptWebsite = $branchReceipt['website'] ?? \App\Models\Setting::get('general', 'business_website', '');
$receiptKraPin = $branchReceipt['kra_pin'] ?? \App\Models\Setting::get('general', 'company_pin', config('pos.company.kra_pin', ''));
$receiptTill = $branchReceipt['till_number'] ?? \App\Models\Setting::get('general', 'till_number', config('pos.company.till_number'));
$receiptPaybill = $branchReceipt['paybill_number'] ?? \App\Models\Setting::get('general', 'paybill_number', config('pos.company.paybill_number'));
$receiptLogoPath = $branchReceipt['logo_path'] ?? \App\Models\Setting::get('general', 'logo_path', config('pos.company.logo_path'));
// Normalize legacy paths to the path relative to storage/app/public.
$logoRelativePath = ltrim((string) $receiptLogoPath, '/');
foreach (['storage/app/public/', 'public/storage/', 'storage/'] as $prefix) {
if (str_starts_with($logoRelativePath, $prefix)) {
$logoRelativePath = substr($logoRelativePath, strlen($prefix));
break;
}
}
$logoUrl = $logoRelativePath !== '' ? asset('storage/' . $logoRelativePath) : null;
$customerPayment = ($split ? $split->payments : $order->payments)->first(fn ($payment) => $payment->customer);
$receiptCustomer = $customerPayment?->customer;
@endphp
@if ($receipt['show_logo'] && $receiptLogoPath)

@endif
@if ($receipt['show_business_name']){{ $receiptBusinessName }}
@endif
@if ($receipt['show_business_contacts'])
@if ($receiptBusinessAddress){{ $receiptBusinessAddress }}
@endif
@if ($receipt['show_landmark'] && $receipt['landmark']){{ $receipt['landmark'] }}
@endif
@if ($receipt['show_phone'] && $receiptBusinessPhone)
{{ $receiptBusinessPhone }}
@endif
@if ($receipt['show_alternative_phone'] && $receiptAlternativePhone)
Alt: {{ $receiptAlternativePhone }}
@endif
@if ($receipt['show_email'] && $receiptEmail)
{{ $receiptEmail }}
@endif
@if ($receipt['show_website'] && $receiptWebsite)
{{ $receiptWebsite }}
@endif
@if ($receipt['show_kra_pin'] && $receiptKraPin)
KRA PIN: {{ $receiptKraPin }}
@endif
@if ($receiptTill || $receiptPaybill)
@if ($receiptTill) Till: {{ $receiptTill }} @endif @if ($receiptTill && $receiptPaybill) · @endif @if ($receiptPaybill) Paybill: {{ $receiptPaybill }} @endif
@endif
@endif
@if (trim((string) $receipt['header_text']) !== ''){{ $receipt['header_text'] }}
@endif
@if ($isBill)
BILL
@endif
@if ($receipt['show_order_details'])
Order: {{ $order->order_number }}
@if ($split){{ $split->label }}
@endif
{{ $order->table->name ?? $order->sale_type->label() }}
Waiter: {{ $order->waiter->name ?? '-' }}@if ($order->cashier) · Cashier: {{ $order->cashier->name }}@endif
@endif
{{ now(config('pos.company.timezone', 'Africa/Nairobi'))->format('d M Y, H:i') }}
@if ($receipt['show_customer_details'] && $receiptCustomer)
Customer: {{ $receiptCustomer->name }}
@if ($receiptCustomer->phone)Phone: {{ $receiptCustomer->phone }}
@endif
@if ($receiptCustomer->kra_pin)KRA PIN: {{ $receiptCustomer->kra_pin }}
@endif
@endif
@forelse ($lines as $item)
| {{ $item->quantity }}x {{ $item->product->name }}@if ($item->discount_percent > 0) (-{{ rtrim(rtrim(number_format($item->discount_percent, 2), '0'), '.') }}%)@endif |
{{ number_format($item->line_total, 2) }} |
@empty
| No items |
@endforelse
| Subtotal | {{ number_format($billable->subtotal, 2) }} |
@if ($happySaved > 0)
| Happy hour saved you | {{ number_format($happySaved, 2) }} |
@endif
| Discount | -{{ number_format($billable->discount_total, 2) }} |
@if (! $split)
| Service charge | {{ number_format($order->service_charge_total, 2) }} |
@endif
| VAT | {{ number_format($billable->tax_total, 2) }} |
| Levy | {{ number_format($billable->levy_total, 2) }} |
| TOTAL | {{ $sym }} {{ number_format($billable->grand_total, 2) }} |
@if ($isBill)
Please settle with the cashier.
@else
@php
$creditPayment = ($split ? $split->payments : $order->payments)->first(fn ($payment) => ($payment->paymentMethod->type ?? null) === 'credit' || strtolower((string) $payment->method) === 'credit');
@endphp
@if ($creditPayment)
DUE
@if ($creditPayment->customer)
Customer: {{ $creditPayment->customer->name }}
@endif
@endif
Payments
@forelse (($split ? $split->payments : $order->payments) as $payment)
{{ $payment->paymentMethod->name ?? $payment->method }}
{{ number_format($payment->amount, 2) }}
@if ($payment->reference_number)
Ref: {{ $payment->reference_number }}
@endif
@empty
No payment recorded yet
@endforelse
@if (trim((string) $receipt['footer_text']) !== ''){{ $receipt['footer_text'] }}
@endif
@endif