@extends('index') @section('content')

Customer Detail

@csrf
Good job!
Good job!
@if(!empty($dfrom) && !empty($dto)) @endif {{-- --}}
Customer: {{$customer['customer_no']}} - {{$customer['fname']}} {{$customer['lname']}} Currency: {{$currencyName}}Date From: {{date("d-m-Y", strtotime($dfrom))}} Date To: {{date("d-m-Y", strtotime($dto))}}{{($balance > 0)? 'Receivable':'Payable'}} Amount: {{number_format(abs($balance))}}Payable Amount: {{number_format($balance)}}
@php $index = 1; $balance = $oBalance; @endphp @if($oBalance != 0) @endif @if($detail->count()) @foreach($detail as $item) @php // For customer ledger: // - Deliveries (stored in debit) should display in Debit column // - Payments (stored in debit) should display in Credit column // - For order payments with cc_amount, use cc_amount instead of debit // - For general vouchers (transaction_type = 'generalVoucher'): // - Use cc_amount for display and balance // - If credit IS NULL: display cc_amount in Credit column (customer credit) // - If debit IS NULL: display cc_amount in Debit column (customer charge) $isPayment = isset($item->transaction_type) && $item->transaction_type == 'orderPayment'; $isGeneralVoucher = isset($item->transaction_type) && $item->transaction_type == 'generalVoucher'; if ($isGeneralVoucher && !empty($item->cc_amount)) { // General Voucher: stored in cc_amount // Determine column by strict NULL check: // - If credit is NULL: display cc_amount in Credit column (customer credit) // - If debit is NULL: display cc_amount in Debit column (customer charge) if (is_null($item->credit)) { // Credit Voucher (Credit to Customer) - credit IS NULL $displayDebit = 0; $displayCredit = $item->cc_amount; $balance += $item->cc_amount; // Decreases customer liability (increases balance) } else if (is_null($item->debit)) { // Debit Voucher (Charge to Customer) - debit IS NULL $displayDebit = $item->cc_amount; $displayCredit = 0; $balance -= $item->cc_amount; // Increases customer liability (reduces balance) } else { // Fallback: both have values, shouldn't happen but handle gracefully $displayDebit = 0; $displayCredit = 0; } } elseif ($isPayment) { // Payment: stored in debit, but display in credit column // Use cc_amount if available (customer currency), otherwise use debit (PKR) $displayDebit = 0; $displayCredit = !empty($item->cc_amount) ? $item->cc_amount : ($item->debit ?? 0); // For balance calculation, use cc_amount if available $amountToUse = !empty($item->cc_amount) ? $item->cc_amount : ($item->debit ?? 0); $balance += $amountToUse; // Payment increases balance (reduces receivable) } else { // Delivery: stored in debit, display in debit column $displayDebit = $item->debit ?? 0; $displayCredit = $item->credit ?? 0; isset($item->debit) ? $balance -= $item->debit : ''; isset($item->credit) ? $balance += $item->credit : ''; } @endphp @endforeach @endif @if($cBalance != 0) @endif
Sr. Date Transaction Type Debit Credit Balance Action
{{$index++}} {{\Carbon\Carbon::parse($dfrom)->format('d-m-Y')}} Opening Balance {{ $oBalance > 0 ? number_format(abs($oBalance)) : '' }} {{ $oBalance < 0 ? number_format(abs($oBalance)) : '' }} {{ number_format($oBalance) }}
{{ $loop->index + 1 }} {{ isset($item->stock_date) ? \Carbon\Carbon::parse($item->stock_date)->format('d-m-Y') : (isset($item->transaction_date) ? $item->transaction_date : '') }} @if(isset($item->transaction_type)) {{ucfirst($item->transaction_type)}} @elseif(isset($item->stock_no)) Delivery - ({{$item->stock_no}}) @else Unknown Type @endif {{ $displayDebit > 0 ? number_format($displayDebit) : '' }} {{ $displayCredit > 0 ? number_format($displayCredit) : '' }} {{number_format($balance)}} @if(isset($item->transaction_type)) @if($item->transaction_type == 'openingBalance') View @elseif($item->transaction_type == 'generalVoucher') View @else View @endif @elseif(isset($item->stock_no)) View @endif
{{$index++}} {{\Carbon\Carbon::parse($dto)->format('d-m-Y')}} Closing Balance {{ $cBalance < 0 ? number_format(abs($cBalance)) : '' }} {{ $cBalance > 0 ? number_format(abs($cBalance)) : '' }} {{ $balance ? number_format($balance += $cBalance) : number_format($oBalance + $cBalance) }}
Sr. Date Transaction Type Debit Credit Balance Action
@endsection