@extends('master.app') @section('title', 'Customer Ledger') @section('pageCSS') @endsection @section('body') @php use Illuminate\Support\Facades\Route; $info = \App\Models\Info::find(1); // WhatsApp share only if a specific customer is selected and has phone/mobile $selectedCustomerId = request('customer_id'); $selectedCustomer = null; if($selectedCustomerId && $selectedCustomerId !== 'all'){ $selectedCustomer = $customers->firstWhere('id', (int)$selectedCustomerId); } $custPhone = $selectedCustomer->phone ?? $selectedCustomer->mobile ?? null; $waPhone = $custPhone ? preg_replace('/\D+/', '', $custPhone) : null; if($waPhone && str_starts_with($waPhone, '0')){ $waPhone = '93'.ltrim($waPhone,'0'); // Afghanistan style (adjust if needed) } $waMsg = "Ledger Summary\n" ."Customer: ".($selectedCustomer->name ?? 'All')."\n" ."Currency: ".(request('currency_id') ?? 'all')."\n" ."From: ".(request('from_date') ?? 'All')." To: ".(request('to_date') ?? 'All')."\n" ."Opening: ".number_format($openingBalance,2)."\n" ."Debit: ".number_format($periodDebit,2)."\n" ."Credit: ".number_format($periodCredit,2)."\n" ."Closing: ".number_format($closingBalance,2)."\n" ."— ".($info->business_name ?? 'Company'); $waUrl = ($waPhone) ? ("https://wa.me/".$waPhone."?text=".urlencode($waMsg)) : null; @endphp
Customer Ledger
Running Balance (Auto)
Reset {{-- Print current page --}} {{-- ✅ Print Pro (separate print page + barcode/qr) --}} Print Pro {{-- ✅ WhatsApp summary --}} @if($waUrl) WhatsApp Share @else @endif
{{-- ✅ Filters --}}
{{-- ✅ KPI --}}
Opening Balance
{{ number_format($openingBalance, 2) }}
Debit (Sale)
{{ number_format($periodDebit, 2) }}
Credit (Received/Return/Advance/Other)
{{ number_format($periodCredit, 2) }}
Closing Balance
{{ number_format($closingBalance, 2) }}
{{-- ✅ Ledger Table --}}
{{-- ✅ Opening row --}} @php $running = (float)$openingBalance; @endphp @forelse($rows as $k => $r) @php $debit = (float) ($r->bill_total ?? 0); $credit = (float) ($r->amount ?? 0); $running = $running + $debit - $credit; $type = $trxTitles[$r->transaction_id] ?? ('TID-'.$r->transaction_id); // ✅ route mapping (safe by Route::has) $link = null; if ((int)$r->transaction_id === 1 && Route::has('customer_bill.show')) { $link = route('customer_bill.show', $r->module_rid); } elseif ((int)$r->transaction_id === 2 && Route::has('customer_recieved.show')) { $link = route('customer_recieved.show', $r->module_rid); } // elseif ((int)$r->transaction_id === 3 && Route::has('customer_return_bill.show')) { // $link = route('customer_return_bill.show', $r->module_rid); // } elseif ((int)$r->transaction_id === 4) { if (Route::has('customer_advance.show')) { $link = route('customer_advance.show', $r->module_rid); } elseif (Route::has('customer_advance.edit')) { $link = route('customer_advance.edit', $r->module_rid); } } @endphp @empty @endforelse
# Date Customer CUR Type Ref Debit Credit Running Action
Opening Balance {{ number_format($openingBalance, 2) }}
{{-- for paginator --}} {{ method_exists($rows,'firstItem') ? ($rows->firstItem() + $k) : ($k+1) }} {{ $r->date }} {{ $r->customer->name ?? '-' }} {{ $r->currency->title_en ?? '-' }} @if((int)$r->transaction_id === 1) {{ $type }} @elseif((int)$r->transaction_id === 2) {{ $type }} @elseif((int)$r->transaction_id === 3) {{ $type }} @elseif((int)$r->transaction_id === 4) {{ $type }} @else {{ $type }} @endif {{ $r->module_rid }} {{ number_format($debit, 2) }} {{ number_format($credit, 2) }} {{ number_format($running, 2) }} @if($link) View @else - @endif
No data found
{{-- Pagination --}}
{{ $rows->links('pagination::bootstrap-4') }}
{{-- ✅ Print Footer Branding --}}
@endsection