@php $companyState = strtolower(trim($company->state ?? 'Maharashtra')); $partyState = strtolower(trim($purchaseReturn->party->state ?? '')); $isInterState = ($companyState !== $partyState && !empty($partyState)) || ($purchaseReturn->party->is_sez ?? false); $bankAccount = method_exists($company, 'defaultBankAccount') ? $company->defaultBankAccount() : null; $pfAmt = $purchaseReturn->pf_amount ?? 0; $pfTax = $purchaseReturn->pf_tax_amount ?? 0; $adjTaxAnalysis = collect($taxAnalysis)->values()->toArray(); if ($pfAmt > 0 && count($adjTaxAnalysis) > 0) { $adjTaxAnalysis[0]['taxable_value'] += $pfAmt; $adjTaxAnalysis[0]['total_tax'] += $pfTax; if ($isInterState) { $adjTaxAnalysis[0]['rate'] = $adjTaxAnalysis[0]['rate'] ?? ($purchaseReturn->items->first()->tax_percent ?? 0); } else { $adjTaxAnalysis[0]['cgst_amount'] += $pfTax / 2; $adjTaxAnalysis[0]['sgst_amount'] += $pfTax / 2; } } $allItems = $purchaseReturn->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 SUPPLIER)', '(DUPLICATE FOR SELF)']; @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 --}}
DEBIT NOTE {{ $copyLabel }}
{{-- Company (issuer) + Supplier (recipient) + Return meta --}}
{{-- Company Details (issuer) --}}
@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
{{-- Supplier Details (the party being debited) --}}
Issued to (Supplier)
{{ $purchaseReturn->party->name ?? '—' }}
{{ $purchaseReturn->party->billing_address ?? '' }}
{{ $purchaseReturn->party->state ?? '' }}@if($purchaseReturn->party && $purchaseReturn->party->pincode) - {{ $purchaseReturn->party->pincode }}@endif, India
GSTIN/UIN : {{ $purchaseReturn->party->gst_number ?? 'Unregistered' }}   State Name : {{ $purchaseReturn->party->state ?? '' }}
Contact : {{ $purchaseReturn->party->mobile ?? '' }}@if($purchaseReturn->party && $purchaseReturn->party->contact_person)   Contact Person : {{ $purchaseReturn->party->contact_person }}@endif
Debit Note No.
{{ $purchaseReturn->return_no ?: 'DR-' . $purchaseReturn->id }}
Dated
{{ optional($purchaseReturn->invoice_date)->format('d-M-y') }}
Ref. Bill No.
{{ $purchaseReturn->bill_no ?: '—' }}
Mode
{{ ucfirst($purchaseReturn->mode ?? '') }}
Reason
{{ strtoupper($purchaseReturn->reason ?? '') }}
Document Type
Debit Note
Supply Type
{{ $isInterState ? 'Inter-State (IGST)' : 'Intra-State (CGST+SGST)' }}
Document Type
Debit Note
{{-- 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 @for($f = 0; $f < $fillerRows; $f++) @endfor @if(!$isLastPage) @endif @if($isLastPage) @if($isInterState) @else @endif @if($pfAmt > 0) @endif @if($purchaseReturn->roundoff != 0) @endif @php $firstItem = $purchaseReturn->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($purchaseReturn->amount_total, 2) : number_format($purchaseReturn->amount_total, 2) }}
IGST {{ function_exists('indian_number') ? indian_number($purchaseReturn->tax_total, 2) : number_format($purchaseReturn->tax_total, 2) }}
CGST {{ function_exists('indian_number') ? indian_number($purchaseReturn->tax_total / 2, 2) : number_format($purchaseReturn->tax_total / 2, 2) }}
SGST {{ function_exists('indian_number') ? indian_number($purchaseReturn->tax_total / 2, 2) : number_format($purchaseReturn->tax_total / 2, 2) }}
P&F {{ function_exists('indian_number') ? indian_number($pfAmt, 2) : number_format($pfAmt, 2) }}
R.Off {{ $purchaseReturn->roundoff < 0 ? '(-)' : '' }}{{ function_exists('indian_number') ? indian_number(abs($purchaseReturn->roundoff), 2) : number_format(abs($purchaseReturn->roundoff), 2) }}
Debit Amount {{ function_exists('indian_number') ? indian_number($purchaseReturn->items->sum('qty'), 0) : number_format($purchaseReturn->items->sum('qty'), 0) }} {{ $totalUnit }} {{ function_exists('indian_number') ? indian_number($purchaseReturn->grand_total, 2) : number_format($purchaseReturn->grand_total, 2) }}
@if($isLastPage)
Amount Chargeable (in words)
Indian Rupees {{ $amountInWords }} Only
E. & O.E
@if($isInterState) @else @endif @foreach($adjTaxAnalysis 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($purchaseReturn->amount_total + $pfAmt, 2) : number_format($purchaseReturn->amount_total + $pfAmt, 2) }} {{ function_exists('indian_number') ? indian_number($purchaseReturn->tax_total + $pfTax, 2) : number_format($purchaseReturn->tax_total + $pfTax, 2) }} {{ function_exists('indian_number') ? indian_number($purchaseReturn->tax_total + $pfTax, 2) : number_format($purchaseReturn->tax_total + $pfTax, 2) }} {{ function_exists('indian_number') ? indian_number(($purchaseReturn->tax_total + $pfTax) / 2, 2) : number_format(($purchaseReturn->tax_total + $pfTax) / 2, 2) }} {{ function_exists('indian_number') ? indian_number(($purchaseReturn->tax_total + $pfTax) / 2, 2) : number_format(($purchaseReturn->tax_total + $pfTax) / 2, 2) }} {{ function_exists('indian_number') ? indian_number($purchaseReturn->tax_total + $pfTax, 2) : number_format($purchaseReturn->tax_total + $pfTax, 2) }}
Declaration
This debit note {{ $purchaseReturn->return_no ?: 'DR-'.$purchaseReturn->id }} is issued against Purchase Invoice @if($purchaseReturn->bill_no){{ $purchaseReturn->bill_no }}@elseN/A@endif dated {{ optional($purchaseReturn->invoice_date)->format('d-M-y') }} for ₹ {{ function_exists('indian_number') ? indian_number($purchaseReturn->grand_total, 2) : number_format($purchaseReturn->grand_total, 2) }}. Goods are returned for the reason indicated above. Kindly pass the credit accordingly.
for {{ $company->name }}

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