@php $adminProfile = \App\Models\Admin::find(session('admin_id')); $shopName = $adminProfile && $adminProfile->shop_name ? $adminProfile->display_shop_name : ($adminProfile->name ?? 'Mandi Management'); $showReceiptLogo = (bool) ($adminProfile->show_pos_receipt_logo ?? false); $shopLogo = null; $invoiceStatus = strtolower((string) ($invoice->status ?? 'unpaid')); $invoiceStatusLabel = match ($invoiceStatus) { 'paid' => __('Paid'), 'partial' => __('Partial'), 'unpaid' => __('Unpaid'), 'received' => __('Received'), default => ucfirst($invoiceStatus), }; $customerName = $invoice->customer?->display_name ?: __('Walk-in Customer'); $adminName = $adminProfile?->name ?: __('Admin'); $exchangeReturnItems = collect($invoice->exchange_return_items ?? []) ->filter(fn ($item) => is_array($item)) ->values(); if ($showReceiptLogo && $adminProfile && $adminProfile->pos_receipt_logo) { $logoPath = storage_path('app/public/' . $adminProfile->pos_receipt_logo); if (file_exists($logoPath)) { $logoMime = mime_content_type($logoPath) ?: 'image/png'; $shopLogo = 'data:' . $logoMime . ';base64,' . base64_encode(file_get_contents($logoPath)); } } @endphp
@php $otherChargesTotal = (float) ($invoice->other_charges_total ?? 0); $visibleCharges = $invoice->charges->filter(fn ($charge) => (float) ($charge->amount ?? 0) > 0)->values(); $visibleOtherChargesTotal = (float) $visibleCharges->sum(fn ($charge) => (float) ($charge->amount ?? 0)); $itemDiscountTotal = (float) $invoice->items->sum(fn ($item) => (float) ($item->item_discount ?? 0)); $invoiceDiscount = (float) ($invoice->discount ?? 0); $totalDiscount = $itemDiscountTotal + $invoiceDiscount; $exchangeCreditAmount = max((float) ($invoice->exchange_credit_amount ?? 0), 0); $exchangeCashPaidAmount = max((float) ($invoice->exchange_cash_paid_amount ?? 0), 0); // Current Total = naya products ka amount (exchange credit alag line pe dikhega) $currentInvoiceTotal = max((float) $invoice->subtotal - $totalDiscount + $visibleOtherChargesTotal, 0); $netPayable = max((float) $invoice->total - $exchangeCreditAmount, 0); $paidAmount = max((float) $invoice->paid_amount, 0); $dueAdjustedAmount = max((float) ($invoice->due_adjusted_amount ?? 0), 0); $customerDueBeforeCheckout = max((float) ($invoice->customer_due_before ?? 0), 0); $storedChangeAmount = max((float) ($invoice->change_amount ?? 0), 0); $displayPaidAmount = $exchangeReturnItems->isNotEmpty() ? $exchangeCashPaidAmount : ($paidAmount + $storedChangeAmount + $dueAdjustedAmount); $cashOverage = $exchangeReturnItems->isNotEmpty() ? max($exchangeCashPaidAmount - $netPayable, 0) : max($displayPaidAmount - $netPayable, 0); $exchangeOverage = $exchangeReturnItems->isNotEmpty() ? max($exchangeCreditAmount - (float) $invoice->total, 0) : 0; // Prefer saved change_amount from checkout; fall back only for older invoices. $changeAmount = $storedChangeAmount > 0 ? $storedChangeAmount : max($exchangeOverage + $cashOverage - $dueAdjustedAmount, 0); $remainingDue = $exchangeReturnItems->isNotEmpty() ? max($netPayable - $exchangeCashPaidAmount, 0) : max($netPayable - $paidAmount, 0); $customerDueAfterCheckout = max($customerDueBeforeCheckout + $remainingDue - $dueAdjustedAmount, 0); $netPayableDisplay = $customerDueAfterCheckout; @endphp
@if ($shopLogo)
@endif

{{ $shopName }}

{{ $adminProfile?->display_address ?: 'N/A' }}
{{ __('Phone') }}: {{ $adminProfile->phone ?? 'N/A' }}
{{ __('Sales Receipt') }}
{{ __('Dated:') }} {{ $invoice->created_at->format('d/m/Y') }}
{{ __('Time:') }} {{ $invoice->created_at->format('h:i A') }}
{{ __('Inv #:') }} {{ $invoice->invoice_number }}
{{ __('Status:') }} {{ $invoiceStatusLabel }}
{{-- @if((float) ($invoice->cut_total ?? 0) > 0)
{{ __('Cut:') }} Rs. {{ number_format((float) $invoice->cut_total, 2) }}
@endif --}}
@if($adminProfile?->pos_receipt_show_customer_name ?? true)
{{ __('Customer:') }} {{ $customerName }}
@endif @if(($adminProfile?->pos_receipt_show_customer_email ?? false) && filled($invoice->customer?->email))
{{ __('Email:') }} {{ $invoice->customer->email }}
@endif @if(($adminProfile?->pos_receipt_show_customer_phone ?? false) && filled($invoice->customer?->phone))
{{ __('Phone:') }} {{ $invoice->customer->phone }}
@endif @if(($adminProfile?->pos_receipt_show_customer_address ?? false) && filled($invoice->customer?->address))
{{ __('Address:') }} {{ $invoice->customer->address }}
@endif
{{ __('Admin:') }} {{ $adminName }}
@if($exchangeReturnItems->isNotEmpty())
{{ __('Exchange Items') }}
@foreach ($exchangeReturnItems as $item) @endforeach
{{ __('Item Description') }} {{ __('Price') }} {{ __('Qty.') }} {{ __('Amount') }}
{{ $item['product_name'] ?? __('Return Item') }}
{{ __('Exchange') }}
{{ number_format((float) ($item['price'] ?? 0), 2) }} {{ number_format((float) ($item['qty'] ?? 0), 2) }} {{ number_format((float) ($item['total'] ?? 0), 2) }}
@endif @foreach ($invoice->items as $item) @endforeach
{{ __('Item Description') }} {{ __('Price') }} {{ __('Qty.') }} {{ __('Amount') }}
{{ $item->product?->display_name ?: $item->product_name }} @if($item->product?->unit)
{{ $item->product->unit->display_name }}
@endif
{{ number_format((float) $item->price, 2) }} {{ number_format((float) $item->qty, 2) }} {{ number_format((float) $item->total, 2) }}
{{ __('Total Items') }} {{ number_format($invoice->items->count(), 2) }}
{{--
{{ __('No. Of Qty.:') }} {{ number_format((float) $invoice->items->sum('qty'), 2) }}
--}} {{-- Exchange invoice pe Sub Total Amount Current Total ke sath confusion create karta hai --}} @if($exchangeReturnItems->isEmpty())
{{ __('Sub Total Amount:') }} Rs. {{ number_format((float) $invoice->subtotal, 2) }}
@endif
{{ __('Discount') }} Rs. {{ number_format($totalDiscount, 2) }}
@if($itemDiscountTotal > 0)
+ {{ __('Item Discount') }} Rs. {{ number_format($itemDiscountTotal, 2) }}
@endif @if($invoiceDiscount > 0)
+ {{ __('Invoice Discount') }} Rs. {{ number_format($invoiceDiscount, 2) }}
@endif @if($visibleCharges->count() > 0)
{{ __('Other Charges') }} Rs. {{ number_format($visibleOtherChargesTotal, 2) }}
@foreach($visibleCharges as $charge)
+ {{ $charge->name }} Rs. {{ number_format((float) $charge->amount, 2) }}
@endforeach @endif
{{ __('Current Total') }} Rs. {{ number_format($currentInvoiceTotal, 2) }}
@if($exchangeReturnItems->isNotEmpty())
{{ __('Exchange Credit') }} Rs. {{ number_format((float) ($invoice->exchange_credit_amount ?? 0), 2) }}
@endif @if($customerDueBeforeCheckout > 0)
{{ __('Previous Due') }} Rs. {{ number_format($customerDueBeforeCheckout, 2) }}
@endif
{{ __('Paid Amount') }} Rs. {{ number_format($displayPaidAmount, 2) }}
@if($dueAdjustedAmount > 0)
{{ __('Due Adjustment') }} Rs. {{ number_format($dueAdjustedAmount, 2) }}
@endif @if($changeAmount > 0)
{{ __('Change') }} Rs. {{ number_format($changeAmount, 2) }}
@endif @if($remainingDue > 0)
{{ __('This Invoice Balance') }} Rs. {{ number_format($remainingDue, 2) }}
@endif @if($customerDueBeforeCheckout > 0 || $dueAdjustedAmount > 0 || $remainingDue > 0)
{{ __('Due After Checkout') }} Rs. {{ number_format($customerDueAfterCheckout, 2) }}
@endif {{-- @if((float) ($invoice->cut_total ?? 0) > 0)
{{ __('Cut Amount') }} Rs. {{ number_format((float) $invoice->cut_total, 2) }}
@endif --}}
{{ __('Net Payable:') }} Rs. {{ number_format((float) $netPayableDisplay, 2) }}
{{--
AMOUNT IN FIGURES: Rs. {{ number_format((float) $netPayableDisplay, 2) }}
--}} @if (!empty($adminProfile->receipt_terms) && !empty($adminProfile->show_receipt_terms))
{{ $adminProfile->receipt_terms }}
@endif
* {{ __('Thanks for shopping with us') }} *
{{--
{{ __('Thanks for shopping with us') }}
--}}
Powered By Power Edge IT Services SMC PVT LTD