@php $logoPath = public_path($company['company_logo']); if (file_exists($logoPath)) { $base64Image = base64_encode(file_get_contents($logoPath)); } else { $base64Image = null; } @endphp @if ($base64Image) Logo @endif @php $host = parse_url(config('app.url'), PHP_URL_HOST); $host = preg_replace('/^www\./', '', $host); @endphp

{{ $company['email'] }}

{{ $host }}



@if ($company['company_gst_no']) GST: {{ $company['company_gst_no'] }} @endif
@if ($sale->is_return)

CREDIT NOTE

@elseif (!empty($sale->tax_amount) && $sale->tax_amount > 0)

TAX INVOICE

@else

PROFORMA INVOICE

@endif

{{ $company['name'] ?? '' }}

{{ $company['address'] ?? '' }}

Call: {{ $company['phone_number'] ?? '' }}

Bill To

Name: {{ $sale->customer->name ?? '-' }}
Phone: {{ $sale->customer->phone ?? '-' }}
Address: {{ $sale->customer->address ?? '' }}
{{ $sale->customer->city ?? '' }} {{ $sale->customer->country ?? '' }}

Details

Date: {{ \Carbon\Carbon::parse($sale->date ?? $sale->created_at)->format('d-m-Y') }}
Invoice No: {{ $sale->reference_code }}
Status: @if ($sale->status == 1) Completed @elseif($sale->status == 2) Pending @else Cancelled @endif
Payment Method: @if ($sale->payment_type == 1) CASH @elseif ($sale->payment_type == 3) BANK @elseif ($sale->payment_type == 5) CASH & BANK @else PENDING @endif
Payment Status: @if ($sale->payment_status == 1) Paid @elseif ($sale->payment_status == 2) Unpaid @else Partial @endif
Received Amt:{{ $company['company_currency'] }}{{ number_format($sale->received_amount, 2) }}

@php // Prepare data for pagination (chunking) $productsPerPage = 10; $itemsCollection = collect($sale->saleItems ?? []); $chunks = $itemsCollection->chunk($productsPerPage); $totalTaxAmount = $sale->tax_amount ?? 0; $totalDiscount = $sale->discount ?? 0; $totalShipping = $sale->shipping ?? 0; $roundOff = $sale->round_off ?? 0; $grandTotal = $sale->grand_total ?? 0; // ✅ SUBTRACT round off if exists if ($roundOff != 0) { $grandTotal = $grandTotal - $roundOff; } $paidAmount = $sale->paid_amount ?? 0; $cashAmount = $sale->cash_amount ?? 0; $bankAmount = $sale->bank_amount ?? 0; $discountPercentage = $sale->discount_percentage ?? 0; $taxRate = $sale->tax_rate ?? 0; $receivedAmount = $sale->received_amount ?? 0; // ✅ Change return calculation uses adjusted grand total $changeReturn = $receivedAmount - $grandTotal; @endphp @foreach ($chunks as $chunkIndex => $productChunk)
@foreach ($productChunk as $index => $item) @php // Now $index is an integer (0, 1, 2...) because $productChunk is an array of items, not attributes $globalIndex = $chunkIndex * $productsPerPage + $index; // Access nested product data $prod = $item['product'] ?? []; $name = $prod['name'] ?? 'Unknown Product'; $code = $prod['product_code'] ?? ''; $price = $item['net_unit_price'] ?? 0; $qty = $item['quantity'] ?? 0; // Tax Calculation from Item $taxPercent = $item['tax_value'] ?? 0; $taxAmt = $item['tax_amount'] ?? 0; $subTotal = $item['sub_total'] ?? $price * $qty; $lineTotal = $subTotal + $taxAmt; @endphp @endforeach
# Product Description Price Qty Subtotal Total
{{ $globalIndex + 1 }} {{ $name }}
@if (!empty($item['size'])) Size: {{ $item['size'] }} @endif
{{ $company['company_currency'] }}{{ number_format($price, 2) }} {{ $qty }} {{ $company['company_currency'] }}{{ number_format($subTotal, 2) }} {{ $company['company_currency'] }}{{ number_format($lineTotal, 2) }}
@if ($chunkIndex < $chunks->count() - 1)
@endif @endforeach