@php use App\Services\ProformaGstService; /* * TAX INVOICE laid out per "TAX INVOICE Format (2).docx": one bordered * 7-column table (S.no 5% | Description 30% | HSN/SAC 11.5% | GST Rate 6.5% * | Man days 7.5% | Rate 9% | Amount 30%), company block top-left with the * Invoice Date / Invoice No cells on the right, BILL TO block, item rows, * GST rows, total, amount in words, signatory and bank details. */ // Indian digit grouping: 28,25,413.00 $inr = function ($n) { $n = number_format((float) $n, 2, '.', ''); [$i, $d] = explode('.', $n); $last3 = substr($i, -3); $rest = substr($i, 0, -3); if ($rest !== '') { $last3 = preg_replace('/\B(?=(\d{2})+(?!\d))/', ',', $rest) . ',' . $last3; } return $last3 . '.' . $d; }; $subtotal = (float) ($invoice->subtotal ?? $invoice->amount); $cgst = (float) ($invoice->cgst ?? 0); $sgst = (float) ($invoice->sgst ?? 0); $igst = (float) ($invoice->igst ?? 0); $totalGst = $cgst + $sgst + $igst; $grandTotal = (float) ($invoice->grand_total ?? $subtotal + $totalGst); // GST rate shown against each GST row, derived from the stored amounts $pct = fn ($gst) => $subtotal > 0 ? rtrim(rtrim(number_format($gst / $subtotal * 100, 2), '0'), '.') . '%' : ''; /* * BILL TO block: client name (bold), address lines, "State, Code - NN.", * "India." and the client's own GST / UIN. The state code comes from the * first two digits of the client's GST number; when the GST number is * missing or malformed, the state is matched from the address instead, and * whatever cannot be resolved is simply left out. */ $gstService = new ProformaGstService(); // GST state codes -> display names (reverse of ProformaGstService::STATE_CODES) $stateNames = [ '01' => 'Jammu and Kashmir', '02' => 'Himachal Pradesh', '03' => 'Punjab', '04' => 'Chandigarh', '05' => 'Uttarakhand', '06' => 'Haryana', '07' => 'Delhi', '08' => 'Rajasthan', '09' => 'Uttar Pradesh', '10' => 'Bihar', '11' => 'Sikkim', '12' => 'Arunachal Pradesh', '13' => 'Nagaland', '14' => 'Manipur', '15' => 'Mizoram', '16' => 'Tripura', '17' => 'Meghalaya', '18' => 'Assam', '19' => 'West Bengal', '20' => 'Jharkhand', '21' => 'Odisha', '22' => 'Chhattisgarh', '23' => 'Madhya Pradesh', '24' => 'Gujarat', '25' => 'Daman and Diu', '26' => 'Dadra and Nagar Haveli and Daman and Diu', '27' => 'Maharashtra', '29' => 'Karnataka', '30' => 'Goa', '31' => 'Lakshadweep', '32' => 'Kerala', '33' => 'Tamil Nadu', '34' => 'Puducherry', '35' => 'Andaman and Nicobar Islands', '36' => 'Telangana', '37' => 'Andhra Pradesh', '38' => 'Ladakh', '97' => 'Others Territory', ]; // Client / company name: the typed company name, else the linked client or project $billToName = trim((string) $invoice->company_name) ?: ($invoice->client->company_name ?? null) ?: ($invoice->project->project_name ?? null); $clientGst = trim((string) $invoice->gst_no); // State code: first two digits of the client's GST number, else from the address $stateCode = preg_match('/^\d{2}/', $clientGst, $m) && isset($stateNames[$m[0]]) ? $m[0] : null; $addressLines = array_values(array_filter(array_map('trim', preg_split('/\r\n|\r|\n|,/', (string) $invoice->address)), fn ($l) => $l !== '')); if ($stateCode === null) { foreach ($addressLines as $line) { if (($code = $gstService->stateCodeFromName($line)) && isset($stateNames[$code])) { $stateCode = $code; break; } } } $stateName = $stateCode !== null ? $stateNames[$stateCode] : null; // The state and country get their own lines below, so drop them from the // address parts; a pincode part joins the part before it ("Erode - 638401") $parts = array_values(array_filter($addressLines, function ($line) use ($gstService, $stateName) { $bare = rtrim(trim($line), '.'); if (strcasecmp($bare, 'india') === 0) return false; if ($stateName !== null && $gstService->stateCodeFromName($bare) !== null) return false; return true; })); $billToLines = []; foreach ($parts as $part) { if (preg_match('/^\d{6}\.?$/', $part) && $billToLines) { $billToLines[count($billToLines) - 1] .= ' - ' . rtrim($part, '.'); } else { $billToLines[] = $part; } } // Pack the address parts into grouped lines (max ~35 chars) instead of one // part per line; a part carrying the pincode always gets its own line $packedLines = []; $current = ''; foreach ($billToLines as $part) { $hasPincode = (bool) preg_match('/\d{6}/', $part); if ($hasPincode) { if ($current !== '') { $packedLines[] = $current; $current = ''; } $packedLines[] = $part; continue; } $candidate = $current === '' ? $part : $current . ',' . $part; if ($current !== '' && strlen($candidate) > 35) { $packedLines[] = $current; $current = $part; } else { $current = $candidate; } } if ($current !== '') { $packedLines[] = $current; } $billToLines = $packedLines; /* * Full-page A4 layout: mPDF cannot stretch a table to the page height, so * the leftover page height is estimated and spread across the layout - * taller item/GST rows, a deeper signatory / words / bank area and two * moderate gaps - instead of one big empty cell. Constants below are * calibrated against the measured render (content ~181mm for a 6-row * invoice with a 7-line BILL TO block). When content outgrows the page, * everything falls back to the compact base sizes and flows cleanly. */ $billToTextLines = ($billToName ? 1 : 0) + count($billToLines) + ($stateName ? 1 : 0) + 1 /* India. */ + (filled($clientGst) ? 1 : 0); $itemRows = 2 + ((float) $invoice->service_cost > 0 ? 1 : 0); $gstRows = 1 + ($cgst > 0 ? 1 : 0) + ($sgst > 0 ? 1 : 0) + ($igst > 0 ? 1 : 0); $rowCount = $itemRows + $gstRows + 1; // + Total Invoice Value row $descWrapLines = max(1, (int) ceil(mb_strlen((string) $invoice->description) / 45)); $contentHeight = 10 + 27 + 7 // title, seller block, BILL TO label + ($billToTextLines * 3.9 + 2) // BILL TO block + 9 + ($rowCount * 6.3) // header + item/GST/total rows + (($descWrapLines - 1) * 4) // wrapped description lines + 12 + 7 + 25 + 17; // base spacers, words header, words/signatory, bank $usableHeight = 266; // A4 usable height, kept a little short of the true 271.6mm as a safety margin $spare = max(0, $usableHeight - $contentHeight); $rowExtra = min(7, ($spare * 0.45) / max(1, $rowCount)); // taller data rows $sigExtra = min(15, $spare * 0.18); // deeper signatory cell $wordsExtra = min(10, $spare * 0.10); // deeper amount-in-words cell $bankExtra = min(8, $spare * 0.07); // deeper bank details cell $left = max(0, $spare - ($rowExtra * $rowCount) - $sigExtra - $wordsExtra - $bankExtra); $rowH = round(6.3 + $rowExtra, 1); $spacer1 = round(6 + $left * 0.5, 1); $spacer2 = round(6 + $left * 0.5, 1); @endphp
| TAX INVOICE | ||||||
|
CUMANS MANPOWER SOLUTIONS PVT LTD No.31/4, Kamaraj Nagar, Gandhi Nagar, Karamadai, Mettupalayam, Coimbatore – 641104. Tamilnadu, Code - 33. GST /UIN : 33AAJCC3390F1ZT |
Invoice Date: {{ $invoice->invoice_date ? date('d.m.Y', strtotime($invoice->invoice_date)) : '' }} | |||||
| Invoice No: {{ $invoice->invoice_number }} | ||||||
| BILL TO | ||||||
|
@if($billToName){{ strtoupper($billToName) }} @endif @foreach($billToLines as $line){{ $line }}, @endforeach @if($stateName){{ $stateName }}, Code - {{ $stateCode }}. @endif India. @if(filled($clientGst))GST / UIN : {{ $clientGst }}@endif |
||||||
| S.no | Description of Goods | HSN/SAC | {{-- non-breaking spaces: mPDF ignores white-space:nowrap on cells --}}GST Rate | Man days | Rate | Amount |
|---|---|---|---|---|---|---|
| {{ $sno++ }} | {{ $invoice->description }} | {{ $invoice->hsn_code }} | _ | _ | {{ $inr($invoice->amount) }} | |
| {{ $sno++ }} | Service Charges | _ | _ | {{ $inr($invoice->service_cost) }} | ||
| {{ $sno++ }} | GST Gross Value | _ | _ | {{ $inr($subtotal) }} | ||
| Total GST | _ | _ | {{ $inr($totalGst) }} | |||
| {{ $sno++ }} | CGST@ | {{ $pct($cgst) }} | _ | _ | {{ $inr($cgst) }} | |
| {{ $sno++ }} | SGST@ | {{ $pct($sgst) }} | _ | _ | {{ $inr($sgst) }} | |
| {{ $sno++ }} | IGST@ | {{ $pct($igst) }} | _ | _ | {{ $inr($igst) }} | |
| Total Invoice Value | {{ $inr($grandTotal) }} | |||||
| Invoice Amount In Words : | For CuManS Manpower Solutions Pvt Ltd | |||||
| {{ ProformaGstService::amountInIndianWords($grandTotal) }} | Authorized Signatory | |||||
|
Company Bank Details : Bank Name: SBI Bank | A/c No. 40143018676 | IFSC: SBIN0000990 GST : 33AAJCC3390F1ZT |
||||||