@extends('print.layout') @section('title', 'Vendor Ledger - ' . ($vendor['fname'] ?? 'N/A')) @section('content')
Vendor Ledger
{{-- Vendor Information --}}
Vendor No: {{ $vendor['vendor_no'] ?? 'N/A' }}
Vendor Name: {{ $vendor['fname'] ?? 'N/A' }}
Address: {{ $vendor['address'] ?? 'N/A' }}
Phone: {{ $vendor['phone1'] ?? 'N/A' }}
Report Period: {{ $dfrom ?? 'All Time' }} to {{ $dto ?? 'Current' }}
Opening Balance: {{ number_format($oBalance ?? 0, 2) }}
Vendor Type: {{ $vendor['vendor_type'] == '1' ? 'Contractor' : 'Vendor' }}
{{-- Ledger Transactions Table --}} @if(isset($detail) && count($detail) > 0)

Transaction History

@php $runningBalance = $oBalance ?? 0; @endphp @if($oBalance != 0) @endif @foreach($detail as $transaction) @php $debit = $transaction->debit ?? 0; $credit = $transaction->credit ?? 0; // For vendor/contractor ledger (liability account): // DB debit (displayed as Credit) = purchases/work done, increases liability = ADD to balance // DB credit (displayed as Debit) = payments made, decreases liability = SUBTRACT from balance // Include ALL transaction types - no filtering $runningBalance += $debit - $credit; // For vendor/contractor ledger, reverse the display (DB debit shown in credit column, DB credit shown in debit column) $displayDebit = $credit; $displayCredit = $debit; @endphp @endforeach
@endif {{-- Summary Section --}}
Total Purchases: {{ number_format($detail->sum('debit') ?? 0, 2) }}
Total Payments: {{ number_format($detail->sum('credit') ?? 0, 2) }}
Current Balance: {{ number_format($runningBalance ?? 0, 2) }}
{{-- Balance Status --}}

Account Status

@if($runningBalance > 0) Credit Balance: Company owes vendor {{ number_format(abs($runningBalance), 2) }} @elseif($runningBalance < 0) Debit Balance: Vendor owes company {{ number_format(abs($runningBalance), 2) }} @else Balanced Account: No outstanding amount @endif
@endsection