@if(count($reportData) > 0)

Customer: {{ (isset($customer_id) && is_scalar($customer_id) && isset($customer[$customer_id])) ? $customer[$customer_id] : ($previousLedger->customer_name ?? 'N/A') }}

From: {{ date('d-M-Y', strtotime($start_date)) }} To: {{ date('d-M-Y', strtotime($end_date)) }}

@php $totalDebit = $totalCredit = $totalReturn = $totalPurchase = $totalPurchasePayment = 0; if(isset($previousLedger)) { $previousTotalBill = $previousLedger->total_bill; $previousPaymentAmount = $previousLedger->payment_amount; $previousDue = $previousLedger->total_due + $customerOpeningDue; } else { $previousTotalBill = $previousPaymentAmount = $previousDue = 0; } $runningBalance = $previousDue; @endphp @foreach($reportData as $value) @php $row_debit = 0; $row_credit = 0; $row_return = 0; if($value->table_name == 'sales' || $value->table_name == 'purchase_payment') { $row_debit = $value->amount; $runningBalance += $row_debit; if ($value->table_name == 'sales') $totalDebit += $row_debit; else $totalPurchasePayment += $row_debit; } else { $row_credit = $value->amount; $runningBalance -= $row_credit; if($value->table_name == 'sale_return') { $row_return = $value->amount; $totalReturn += $row_return; } elseif($value->table_name == 'purchase') { $totalPurchase += $value->amount; } else { $totalCredit += $value->amount; } } $branchCode = 'N/A'; if(!empty($value->branch_name) && $value->branch_name != 'N/A'){ $words = explode(' ', $value->branch_name); $branchCode = ''; foreach($words as $w) { $branchCode .= strtoupper(substr($w, 0, 1)); } } @endphp @endforeach
S/L Date Particulars Branch-Ref NO Sales/Pur. Payment (Debit) Sales Return (Credit) Collection / Purchase (Credit) Due Balance
Previous Ledger ({{ date('d-M-Y', strtotime($start_date)) }}): {{ number_format($previousTotalBill, 2) }} 0.00 {{ number_format($previousPaymentAmount, 2) }} {{ number_format($previousDue, 2) }}
{{ $loop->iteration }} {{ date('d-M-Y', strtotime($value->date)) }} {{ ucwords(str_replace('_', ' ', $value->table_name)) }} {{ $branchCode }}-{{ $value->code }} {{ $row_debit > 0 ? number_format($row_debit, 2) : '' }} {{ $row_return > 0 ? number_format($row_return, 2) : '' }} {{ ($row_credit > 0 && $value->table_name != 'sale_return') ? number_format($row_credit, 2) : '' }} {{ number_format($runningBalance, 2) }}
Final Ledger: {{ number_format($totalDebit + $totalPurchasePayment + $previousTotalBill, 2) }} {{ number_format($totalReturn, 2) }} {{ number_format($totalCredit + $totalPurchase + $previousPaymentAmount, 2) }} {{ number_format($runningBalance, 2) }}
@if($totalPurchase > 0 || $totalPurchasePayment > 0) @endif
MIS Snapshot (Summary)
Total Sales (Invoice Amount) {{ number_format($totalDebit, 2) }}
Total Collection (Cash/Bank) {{ number_format($totalCredit, 2) }}
Total Sales Return {{ number_format($totalReturn, 2) }}
Total Purchase (Combined) {{ number_format($totalPurchase, 2) }}
Total Paid for Purchase {{ number_format($totalPurchasePayment, 2) }}
Net Balance Status @if($runningBalance > 0) Receivable: {{ number_format($runningBalance, 2) }} @else Payable: {{ number_format(abs($runningBalance), 2) }} @endif
@endif