@php // SEZ buyers are always inter-state (IGST) under GST. $companyState = strtolower(trim($company->state ?? 'Maharashtra')); $partyState = strtolower(trim($saleReturn->party->state ?? '')); $isInterState = ($companyState !== $partyState && !empty($partyState)) || ($saleReturn->party->is_sez ?? false); $bankAccount = method_exists($company, 'defaultBankAccount') ? $company->defaultBankAccount() : null; // Pagination — split items across pages $allItems = $saleReturn->items->values(); $totalItems = $allItems->count(); $itemsPerPage1 = $allItems->count() > 20 ? 30 : 18; $itemsPerPage2 = 18; $itemPages = []; if ($totalItems <= $itemsPerPage1) { $itemPages[] = $allItems; } else { $itemPages[] = $allItems->slice(0, $itemsPerPage1)->values(); $remaining = $allItems->slice($itemsPerPage1)->values(); while ($remaining->count() > 0) { $itemPages[] = $remaining->slice(0, $itemsPerPage2)->values(); $remaining = $remaining->slice($itemsPerPage2)->values(); } } $totalPages = count($itemPages); $copyLabels = ['(ORIGINAL FOR RECIPIENT)', '(DUPLICATE FOR SUPPLIER)']; @endphp @foreach($copyLabels as $copyIndex => $copyLabel) @if($copyIndex > 0)
@endif @for($pageNum = 0; $pageNum < $totalPages; $pageNum++) @php $pageItems = $itemPages[$pageNum]; $isFirstPage = ($pageNum === 0); $isLastPage = ($pageNum === $totalPages - 1); $startIndex = $isFirstPage ? 0 : $itemsPerPage1 + (($pageNum - 1) * $itemsPerPage2); $maxSlots = $isFirstPage ? $itemsPerPage1 : $itemsPerPage2; $usedSlots = 0; foreach ($pageItems as $itm) { $nameLen = strlen($itm->product->name ?? 'Product'); $usedSlots += $nameLen > 30 ? 2 : 1; } $fillerRows = $isLastPage ? max(0, $maxSlots - $usedSlots) : 0; @endphp @if($pageNum > 0)
@endif {{-- Header --}}
CREDIT NOTE {{ $copyLabel }}
{{-- Company + Buyer + Return meta (repeats on every page) --}}
{{-- Company Details --}}
@if(!empty($logoBase64)) @elseif($company->logo_path) @endif
{{ $company->legal_name ?? $company->name }}
{{ $company->billing_address }}
GSTIN: {{ $company->gstin }} | State: {{ $company->state ?? 'Maharashtra' }}
Ph: {{ $company->phone }} | {{ $company->email }}@if($company->website) | {{ $company->website }}@endif
@if($company->msme_number)
MSME/Udyam : {{ $company->msme_number }}
@endif
{{-- Buyer Details (the customer who returned goods) --}}
Issued to (Buyer)
{{ $saleReturn->party->name ?? '—' }}
{{ $saleReturn->party->billing_address ?? '' }}
{{ $saleReturn->party->state ?? '' }}@if($saleReturn->party && $saleReturn->party->pincode) - {{ $saleReturn->party->pincode }}@endif, India
GSTIN/UIN : {{ $saleReturn->party->gst_number ?? 'Unregistered' }}   State Name : {{ $saleReturn->party->state ?? '' }}
Contact : {{ $saleReturn->party->mobile ?? '' }}@if($saleReturn->party && $saleReturn->party->contact_person)   Contact Person : {{ $saleReturn->party->contact_person }}@endif
@if($saleReturn->party && $saleReturn->party->msme_number)
MSME/Udyam No. : {{ $saleReturn->party->msme_number }}
@endif
Credit Note No.
{{ $saleReturn->return_no ?: 'CR-' . $saleReturn->id }}
Dated
{{ optional($saleReturn->invoice_date)->format('d-M-y') }}
Ref. Bill No.
{{ $saleReturn->bill_no ?: '—' }}
Reason
{{ strtoupper($saleReturn->reason ?? '') }}
{{-- Items Table --}} @foreach($pageItems as $item) @php $itemHsn = $item->hsn ?: ($item->product->hsn ?? ''); $itemUnit = $item->unit ?: ($item->product->unit ?? ''); $itemTaxPercent = $item->tax_percent ?? 0; $rateInclTax = $item->rate * (1 + ($itemTaxPercent / 100)); @endphp @endforeach {{-- Filler rows on last page --}} @for($f = 0; $f < $fillerRows; $f++) @endfor @if(!$isLastPage) @endif @if($isLastPage) {{-- Tax Lines --}} @if($isInterState) @else @endif @if($saleReturn->pf_amount) @if($saleReturn->pf_tax_amount) @endif @endif @if($saleReturn->roundoff != 0) @endif @php $firstItem = $saleReturn->items->first(); $totalUnit = $firstItem && ($firstItem->unit ?: ($firstItem->product->unit ?? null)) ? ($firstItem->unit ?: $firstItem->product->unit) : 'Pcs'; @endphp @endif
Sl Description of Goods HSN/SAC GST% Quantity Rate Rate
(Incl. Tax)
Amount
{{ $startIndex + $loop->iteration }} {{ $item->product->name ?? 'Product' }} {{ $itemHsn }} {{ function_exists('indian_number') ? indian_number($itemTaxPercent, 0) : number_format($itemTaxPercent, 0) }}% {{ function_exists('indian_number') ? indian_number($item->qty, 0) : number_format($item->qty, 0) }} {{ $itemUnit }} {{ function_exists('indian_number') ? indian_number($item->rate, 2) : number_format($item->rate, 2) }} {{ function_exists('indian_number') ? indian_number($rateInclTax, 2) : number_format($rateInclTax, 2) }} {{ function_exists('indian_number') ? indian_number($item->line_amount, 2) : number_format($item->line_amount, 2) }}
 
Continued on next page... {{ function_exists('indian_number') ? indian_number($pageItems->sum('line_amount'), 2) : number_format($pageItems->sum('line_amount'), 2) }}
Sub Total {{ function_exists('indian_number') ? indian_number($saleReturn->amount_total, 2) : number_format($saleReturn->amount_total, 2) }}
IGST {{ function_exists('indian_number') ? indian_number($saleReturn->tax_total, 2) : number_format($saleReturn->tax_total, 2) }}
CGST {{ function_exists('indian_number') ? indian_number($saleReturn->tax_total / 2, 2) : number_format($saleReturn->tax_total / 2, 2) }}
SGST {{ function_exists('indian_number') ? indian_number($saleReturn->tax_total / 2, 2) : number_format($saleReturn->tax_total / 2, 2) }}
P&F {{ function_exists('indian_number') ? indian_number($saleReturn->pf_amount, 2) : number_format($saleReturn->pf_amount, 2) }}
P&F Tax ({{ $saleReturn->pf_tax_percent }}%) {{ function_exists('indian_number') ? indian_number($saleReturn->pf_tax_amount, 2) : number_format($saleReturn->pf_tax_amount, 2) }}
R.Off {{ $saleReturn->roundoff < 0 ? '(-)' : '' }}{{ function_exists('indian_number') ? indian_number(abs($saleReturn->roundoff), 2) : number_format(abs($saleReturn->roundoff), 2) }}
Credit Amount {{ function_exists('indian_number') ? indian_number($saleReturn->items->sum('qty'), 0) : number_format($saleReturn->items->sum('qty'), 0) }} {{ $totalUnit }} {{ function_exists('indian_number') ? indian_number($saleReturn->grand_total, 2) : number_format($saleReturn->grand_total, 2) }}
@if($isLastPage) {{-- Amount in Words --}}
Amount Chargeable (in words)
Indian Rupees {{ $amountInWords }} Only
E. & O.E
{{-- Tax Analysis Table + QR --}}
@if(!empty($qrBase64))
Scan to pay
@elseif($company->qr_code_path)
Scan to pay
@else
QR
@endif
@if($isInterState) @else @endif @foreach($taxAnalysis as $tax) @if($isInterState) @else @endif @endforeach @if($isInterState) @else @endif
Taxable
Value
IGST Total
Tax Amount
Rate Amount
Taxable
Value
Central Tax State Tax Total
Tax Amount
Rate Amount Rate Amount
{{ function_exists('indian_number') ? indian_number($tax['taxable_value'], 2) : number_format($tax['taxable_value'], 2) }}{{ $tax['rate'] }}% {{ function_exists('indian_number') ? indian_number($tax['total_tax'], 2) : number_format($tax['total_tax'], 2) }} {{ function_exists('indian_number') ? indian_number($tax['total_tax'], 2) : number_format($tax['total_tax'], 2) }}{{ $tax['cgst_rate'] }}% {{ function_exists('indian_number') ? indian_number($tax['cgst_amount'], 2) : number_format($tax['cgst_amount'], 2) }} {{ $tax['sgst_rate'] }}% {{ function_exists('indian_number') ? indian_number($tax['sgst_amount'], 2) : number_format($tax['sgst_amount'], 2) }} {{ function_exists('indian_number') ? indian_number($tax['total_tax'], 2) : number_format($tax['total_tax'], 2) }}
{{ function_exists('indian_number') ? indian_number($saleReturn->amount_total, 2) : number_format($saleReturn->amount_total, 2) }} {{ function_exists('indian_number') ? indian_number($saleReturn->tax_total, 2) : number_format($saleReturn->tax_total, 2) }} {{ function_exists('indian_number') ? indian_number($saleReturn->tax_total, 2) : number_format($saleReturn->tax_total, 2) }} {{ function_exists('indian_number') ? indian_number($saleReturn->tax_total / 2, 2) : number_format($saleReturn->tax_total / 2, 2) }} {{ function_exists('indian_number') ? indian_number($saleReturn->tax_total / 2, 2) : number_format($saleReturn->tax_total / 2, 2) }} {{ function_exists('indian_number') ? indian_number($saleReturn->tax_total, 2) : number_format($saleReturn->tax_total, 2) }}
{{-- Declaration & Bank Details --}}
Declaration
This credit note {{ $saleReturn->return_no ?: 'CR-'.$saleReturn->id }} is issued against Invoice @if($saleReturn->bill_no){{ $saleReturn->bill_no }}@elseN/A@endif dated {{ optional($saleReturn->invoice_date)->format('d-M-y') }} for ₹ {{ function_exists('indian_number') ? indian_number($saleReturn->grand_total, 2) : number_format($saleReturn->grand_total, 2) }}. Goods returned are accepted as per the reason indicated above.
@if($bankAccount)
Company's Bank Details
A/c Holder's Name : {{ $bankAccount->name ?? $company->name }}
Bank Name : {{ $bankAccount->bank_name }}
A/c No. : {{ $bankAccount->account_no }}
Branch & IFS Code : {{ $bankAccount->branch }} & {{ $bankAccount->ifsc }}
@endif
for {{ $company->name }}

Authorised Signatory
This is a Computer Generated Credit Note
@endif @endfor @endforeach