@php $branch = $addedInvoice->branch ?? null; $company = $branch->company ?? null; /* ---------- COMPANY / BRANCH ---------- */ $companyName = $settings->company_name ?? ($company->name ?? ''); $companyAddress = $settings->address ?? ($company->address ?? ''); $companyPhone = $settings->phone ?? ($company->phone ?? ''); $companyGstin = $settings->gst_no ?? ''; $bankName = $settings->bank_name ?? ''; $accountNo = $settings->account_no ?? ''; $ifscCode = $settings->ifsc_code ?? ''; /* ---------- CLIENT ---------- */ $clientName = $addedInvoice->client->user->name ?? ''; $clientCompany = $addedInvoice->client->company_name ?? ''; $clientAddress = $addedInvoice->client->address ?? (optional(optional($addedInvoice->order)->clientAddress)->address ?? (optional(optional($addedInvoice->client)->user)->location ?? '')); $clientGstin = $addedInvoice->client->gstin ?? ''; /* Legacy records store placeholders like "N/A" where a value was unknown. Nothing missing should print on a bill, so blank them out. */ $blank = function ($value) { $v = trim((string) $value); return in_array(strtoupper($v), ['N/A', 'NA', '-', 'NULL']) ? '' : $v; }; $clientName = $blank($clientName); $clientCompany = $blank($clientCompany); $clientAddress = $blank($clientAddress); $clientGstin = $blank($clientGstin); $billTo = trim(($clientCompany ?: $clientName) . ($clientAddress ? ', ' . $clientAddress : '')); /* ---------- INVOICE HEAD ---------- */ $invoiceNo = $addedInvoice->invoice_id ?? ''; $invoiceDate = !empty($addedInvoice->invoice_date) ? \Carbon\Carbon::parse($addedInvoice->invoice_date)->format('d-m-Y') : ''; /* ---------- NUMBER FORMATTER (drops trailing zeros, like the printed book) ---------- */ $num = function ($value, $decimals = 2) { $formatted = rtrim(rtrim(number_format((float) $value, $decimals, '.', ''), '0'), '.'); return $formatted === '' || $formatted === '-' ? '0' : $formatted; }; /* Money values carry the rupee symbol and always show 2 decimals (200 -> 200.00). Quantities and tax rates keep using $num, which trims trailing zeros. */ $money = function ($value, $decimals = 2) { return '₹' . number_format((float) $value, $decimals, '.', ''); }; /* ---------- LINE ITEMS + TAX BUCKETS ---------- */ $items = $addedInvoice->invoiceItems ?? collect(); $itemCount = count($items); $rows = []; $subTotal = 0; $totalTax = 0; $sgst = ['rate' => 0, 'amount' => 0]; $cgst = ['rate' => 0, 'amount' => 0]; $igst = ['rate' => 0, 'amount' => 0]; foreach ($items as $item) { $lineTotal = $item->total ?? 0; $lineTax = 0; if (($addedInvoice->gst ?? 'N') == 'Y' && $item->invoiceItemTaxes) { foreach ($item->invoiceItemTaxes as $tax) { $taxAmt = ($lineTotal * $tax->tax) / 100; $lineTax += $taxAmt; $taxName = strtoupper(optional($tax->taxes)->name ?? ''); if (str_contains($taxName, 'SGST')) { $sgst['rate'] = $tax->tax; $sgst['amount'] += $taxAmt; } elseif (str_contains($taxName, 'CGST')) { $cgst['rate'] = $tax->tax; $cgst['amount'] += $taxAmt; } elseif (str_contains($taxName, 'IGST')) { $igst['rate'] = $tax->tax; $igst['amount'] += $taxAmt; } } } $rows[] = [ 'name' => isset($settings->native_name_flag) && $settings->native_name_flag == 'A' ? $item->products->native_name ?? $item->product_name : $item->product_name ?? '', 'hsn' => $item->products->hsn_code ?? '', 'qty' => $item->quantity ?? 0, 'rate' => $item->price ?? 0, 'amount' => $lineTotal, ]; $subTotal += $lineTotal; $totalTax += $lineTax; } $invoiceAmount = $addedInvoice->final_amount ?? $subTotal + $totalTax; /* Paid so far and what is still outstanding. The controller passes these in; fall back to the payment ledger so the bill is correct however it is rendered. */ $paidTillNow = $paidAmount ?? optional($addedInvoice->payments())->sum('amount') ?? 0; $balanceDue = $balanceAmount ?? max($invoiceAmount - $paidTillNow, 0); $amountWords = ucfirst(amountToWords($invoiceAmount)) . ' only'; /* Filler keeps the body the same depth as the printed stationery */ $fillerHeight = max(240 - $itemCount * 30, 30); @endphp {{-- ACTION BUTTONS (screen only) --}}
Back
{{-- HEADER --}}
GSTIN : {{ $companyGstin }}
INVOICE
CELL : {{ $companyPhone }}
{{ strtoupper($companyName) }}
{{ $companyAddress }}
{{-- INVOICE NUMBER AND DATE --}}
No : {{ $invoiceNo }} Date : {{ $invoiceDate }}
{{-- CUSTOMER DETAILS --}}
To
{{ $billTo }}
GSTIN . {{ $clientGstin }}
{{-- PRODUCT TABLE --}} @foreach ($rows as $index => $row) @endforeach {{-- Empty Rows --}}
S.
NO.
PARTICULARS HSN
CODE
QTY RATE AMOUNT
{{ $index + 1 }} {{ $row['name'] }} {{ $row['hsn'] }} {{ $num($row['qty'], 3) }} {{ $money($row['rate']) }} {{ $money($row['amount']) }}
{{-- AMOUNT AND TOTAL --}}
Rupees : {{ $amountWords }}
 
RECEIVER'S SIGNATURE
Total {{ $money($subTotal) }}
SGST - {{ $sgst['rate'] > 0 ? $num($sgst['rate']) : '' }}% {{ $sgst['amount'] > 0 ? $money($sgst['amount']) : '' }}
CGST - {{ $cgst['rate'] > 0 ? $num($cgst['rate']) : '' }}% {{ $cgst['amount'] > 0 ? $money($cgst['amount']) : '' }}
IGST - {{ $igst['rate'] > 0 ? $num($igst['rate']) : '' }}% {{ $igst['amount'] > 0 ? $money($igst['amount']) : '' }}
Invoice Amount {{ $money($invoiceAmount) }}
Paid {{ $money($paidTillNow) }}
Balance {{ $money($balanceDue) }}
{{-- BANK AND SIGNATURE --}}