{{-- Shared receipt layout for POS and Sales print (MRP tier) --}}
@php
// Resolve language suffix
$lang = $lang ?? 0; // 0=en,1=si,2=ta
// Normalize $lang because settings can store it as string (e.g. '0', 'english', 'sinhala')
if (!is_int($lang)) {
if (is_numeric($lang)) {
$lang = (int) $lang;
} else {
$key = strtolower(trim((string) $lang));
if (in_array($key, ['sinhala', 'si'], true)) {
$lang = 1;
} elseif (in_array($key, ['tamil', 'ta'], true)) {
$lang = 2;
} else {
$lang = 0;
}
}
}
$langSuffix = $lang == 1 ? '_si' : ($lang == 2 ? '_ta' : '_en');
$format = strtolower($format ?? request('format', 'pos'));
$isA4 = $format === 'a4';
$paperSetting = $paperSetting
?? (request('paper_mm') ?? request('paper_width_mm') ?? request('paper_width')
?? ($receiptSettings['paper_width_mm'] ?? $receiptSettings['receipt_paper_width'] ?? ($location->paper_width ?? $location->receipt_width ?? 80)));
$paperSetting = is_numeric($paperSetting) ? (float) $paperSetting : 80;
$isWideFormat = in_array($format, ['wide', 'letter', 'legal'], true);
$isAnyAFormat = strpos($format, 'a') === 0; // Treat A3/A4/A5 etc. as wide
$isWide = ($paperSetting >= 150) || $isAnyAFormat || $isWideFormat;
$returnTotal = $returnTotal ?? 0;
@endphp
{{-- Logo --}}
@if(($receiptSettings['receipt_show_logo'] ?? 1) && $location && $location->logo)
@endif
{{-- Business Name --}}
@if($receiptSettings['receipt_show_title'] ?? 1)
{{ $receiptSettings['business_name'] ?? config('app.name', 'POS System') }}
@endif
{{-- Business Address --}}
@if($receiptSettings['receipt_show_address'] ?? 1)
{{ $receiptSettings['business_address'] ?? config('app.address', 'Store Address') }}
@endif
{{-- Business Phone --}}
@if($receiptSettings['receipt_show_phone'] ?? 1)
{{ $receiptSettings['business_phone'] ?? config('app.phone', 'Tel: 0000000000') }}
@endif
{{-- Business Email --}}
@if($receiptSettings['receipt_show_email'] ?? 1)
{{ $receiptSettings['business_email'] ?? '' }}
@endif
@if($invoice->returns && $invoice->returns->count() > 0)
{{ $receiptSettings['receipt_text_returns_recorded' . $langSuffix] ?? 'Returns recorded' }}
Net after returns: {{ number_format(($invoice->total ?? 0) - ($returnTotal ?? 0), 2) }}
@endif
{{-- Invoice Info --}}
@if($receiptSettings['receipt_show_invoice'] ?? 1)
| {{ $receiptSettings['receipt_text_invoice' . $langSuffix] ?? 'Invoice' }} |
{{ $invoice->invoice_number }} |
@endif
@if($receiptSettings['receipt_show_date'] ?? 1)
| {{ $receiptSettings['receipt_text_date' . $langSuffix] ?? 'Date' }} |
{{ $invoice->posted_at ? $invoice->posted_at->format('Y-m-d h:i A') : now()->format('Y-m-d h:i A') }} |
@endif
@if($invoice->customer && ($receiptSettings['receipt_show_customer'] ?? 1))
| {{ $receiptSettings['receipt_text_customer' . $langSuffix] ?? 'Customer' }} |
{{ $invoice->customer->name }} |
@if($invoice->customer->pin && ($receiptSettings['receipt_show_customer_pin'] ?? 0))
| {{ $receiptSettings['receipt_text_customer_pin' . $langSuffix] ?? 'ID' }} |
{{ $invoice->customer->pin }} |
@endif
@endif
@if($receiptSettings['receipt_show_cashier'] ?? 1)
| {{ $receiptSettings['receipt_text_cashier' . $langSuffix] ?? 'Cashier' }} |
{{ $invoice->user->name ?? '-' }} |
@endif
| {{ $receiptSettings['receipt_text_qty' . $langSuffix] ?? 'Qty' }} |
{{ $receiptSettings['receipt_text_mrp' . $langSuffix] ?? 'MRP' }} |
{{ $receiptSettings['receipt_text_amount' . $langSuffix] ?? 'Amount' }} |
@php
$mrpTotal = 0; // Sum of MRP * qty (gross)
$netSubtotal = 0; // Sum of sale price * qty (net before bill discount)
$itemDiscountTotal = 0; // Sum of savings from MRP
@endphp
@foreach($invoice->items as $item)
@php
$product = $item->product;
$isOtherItem = empty($item->product_id) && !empty($item->other_item_name);
if ($isOtherItem) {
$productName = $item->other_item_name ?? 'Other Item';
$mrp = $item->price ?? 0;
} else {
$productName = ($lang ?? 0) === 0
? ($product->name ?? 'Product')
: (!empty($product->name_local) ? $product->name_local : ($product->name ?? 'Product'));
$mrp = $product->default_price ?? $product->price_sale ?? 0;
}
$itemTotal = $item->qty * $item->price;
$itemSaving = max($mrp - $item->price, 0) * $item->qty;
$mrpTotal += $mrp * $item->qty;
$netSubtotal += $itemTotal;
$itemDiscountTotal += $itemSaving;
@endphp
|
@if(($receiptSettings['receipt_show_barcode'] ?? 1) && !$isOtherItem)
@php
$code = trim((string)($product->barcode ?? ''));
if ($code === '') { $code = trim((string)($product->sku ?? '')); }
@endphp
@if($code !== '')
{{ $code }}
@endif
@endif
{{ $productName }}
|
@php
$unitName = '';
$uid = (int)($product->unit_id ?? 0);
if ($uid > 0 && isset($unitCodesById) && is_array($unitCodesById) && isset($unitCodesById[$uid])) {
$unitName = trim((string)$unitCodesById[$uid]);
} elseif (isset($product->unit)) {
$unitName = trim((string)$product->unit);
}
@endphp
| {{ number_format($item->qty, 2) }}@if(($receiptSettings['receipt_show_unit'] ?? 1) && $unitName !== ''){{ $unitName }}@endif |
{{ number_format($mrp, 2) }} |
{{ number_format($itemTotal, 2) }} |
|
@endforeach
@php
$billDiscount = $invoice->discount ?? 0;
$invoiceAmount = $netSubtotal - $billDiscount; // net amount after bill discount
$paidCash = $invoice->paid_cash ?? 0;
$paidCard = $invoice->paid_pos ?? 0;
$paidCredit = $invoice->paid_credit ?? 0; // UNPAID portion (credit)
$paidAmount = $paidCash + $paidCard; // Only actual cash + card payments
$balance = $invoiceAmount - $paidAmount; // POSITIVE = owes, NEGATIVE = change
$totalSaving = $itemDiscountTotal + $billDiscount;
@endphp
@if($receiptSettings['receipt_show_discounts'] ?? 1)
@if($itemDiscountTotal > 0 || $billDiscount > 0)
| {{ $receiptSettings['receipt_text_received_discounts' . $langSuffix] ?? 'Received Discounts' }} |
@endif
@if($itemDiscountTotal > 0 && ($receiptSettings['receipt_show_item_discount'] ?? 1))
| {{ $receiptSettings['receipt_text_item_discount' . $langSuffix] ?? 'Item Discount' }} |
({{ number_format($itemDiscountTotal, 2) }}) |
@endif
@if($billDiscount > 0)
| {{ $receiptSettings['receipt_text_bill_discount' . $langSuffix] ?? 'Bill Discount' }} |
({{ number_format($billDiscount, 2) }}) |
@endif
@endif
@if($receiptSettings['receipt_show_invoice_amount'] ?? 1)
| {{ $receiptSettings['receipt_text_invoice_amount' . $langSuffix] ?? 'Invoice Amount' }} |
{{ number_format($invoiceAmount, 2) }} |
@endif
| {{ $receiptSettings['receipt_text_payment_details' . $langSuffix] ?? 'Payment Details' }} |
@if($paidCash > 0)
| {{ $receiptSettings['receipt_text_cash' . $langSuffix] ?? 'Cash' }} |
{{ number_format($paidCash, 2) }} |
@endif
@if($paidCard > 0)
| {{ $receiptSettings['receipt_text_card' . $langSuffix] ?? 'Card/POS' }} |
{{ number_format($paidCard, 2) }} |
@endif
@if($paidCredit > 0)
| {{ $receiptSettings['receipt_text_credit' . $langSuffix] ?? 'Credit' }} |
{{ number_format($paidCredit, 2) }} |
@endif
| {{ $receiptSettings['receipt_text_paid_amount' . $langSuffix] ?? 'Paid Amount' }} |
{{ number_format($paidAmount, 2) }} |
| {{ $balance < 0 ? ($receiptSettings['receipt_text_change' . $langSuffix] ?? 'Change') : ($receiptSettings['receipt_text_balance_due' . $langSuffix] ?? 'Balance Due') }} |
{{ number_format(abs($balance), 2) }} |
@if(($receiptSettings['receipt_show_your_saving'] ?? 1) && $totalSaving > 0)
{{ $receiptSettings['receipt_text_your_saving' . $langSuffix] ?? 'Your Saving' }}
{{ number_format($totalSaving, 2) }}
@endif
@php
$priorDue = max($invoice->previous_balance ?? 0, 0);
$totalDue = max($invoice->current_balance ?? 0, 0);
$hasCreditOnThisInvoice = ($paidCredit ?? 0) > 0.009;
$shouldShowDue = ($receiptSettings['receipt_show_due_summary' . $langSuffix] ?? ($receiptSettings['receipt_show_due_summary'] ?? 1))
&& ($priorDue > 0.009 || $totalDue > 0.009 || $hasCreditOnThisInvoice);
@endphp
@if($shouldShowDue)
{{ $receiptSettings['receipt_text_due_summary' . $langSuffix] ?? 'Due Summary' }}
{{ $receiptSettings['receipt_text_previous_due' . $langSuffix] ?? 'Previous Due' }}
{{ number_format($priorDue, 2) }}
|
{{ $receiptSettings['receipt_text_total_due' . $langSuffix] ?? 'Total Due' }}
{{ number_format($totalDue, 2) }}
|
@endif
{{ $receiptSettings['receipt_text_sold_items' . $langSuffix] ?? 'Sold Items' }}: {{ number_format($invoice->items->count()) }}
@if($invoice->returns && $invoice->returns->count() > 0)
@php
$returnRows = $invoice->returns;
$returnLineTotal = 0;
@endphp
{{ $receiptSettings['receipt_text_return_details' . $langSuffix] ?? 'Return Details' }}
| {{ $receiptSettings['receipt_text_item' . $langSuffix] ?? 'Item' }} |
{{ $receiptSettings['receipt_text_qty' . $langSuffix] ?? 'Qty' }} |
{{ $receiptSettings['receipt_text_price' . $langSuffix] ?? 'Price' }} |
{{ $receiptSettings['receipt_text_amount' . $langSuffix] ?? 'Amount' }} |
@foreach($returnRows as $ret)
@php
$retQty = (float) ($ret->qty ?? 0);
$retPrice = (float) ($ret->price ?? 0);
$retAmount = $retQty * $retPrice;
$returnLineTotal += $retAmount;
$retProduct = $ret->product;
$retProductName = ($lang ?? 0) === 0
? ($retProduct->name ?? 'Item')
: (!empty($retProduct->name_local) ? $retProduct->name_local : ($retProduct->name ?? 'Item'));
@endphp
|
{{ $retProductName }}
|
@if(($receiptSettings['receipt_show_barcode'] ?? 1) && !empty($retProduct?->barcode))
| {{ $retProduct->barcode }} |
@endif
|
{{ number_format($retQty, 2) }} |
{{ number_format($retPrice, 2) }} |
{{ number_format($retAmount, 2) }} |
@if(!empty($ret->reason))
| {{ $receiptSettings['receipt_text_reason' . $langSuffix] ?? 'Reason' }}: {{ $ret->reason }} |
@endif
|
@endforeach
| {{ $receiptSettings['receipt_text_return_total' . $langSuffix] ?? 'Return Total' }} |
{{ number_format($returnLineTotal, 2) }} |
@endif
{{ $receiptSettings['receipt_footer_text' . $langSuffix] ?? 'Thank you! Come again.' }}
Powered by Yashan.dev
thisurababi@gmail.com
+94 76 12 48 041 | +94 78 91 31 950