@extends('layouts.app')
@section('title', __('Customer Ledger').' - '.$customer->name)
@section('content')
<div class="card">
    <div class="card-body p-4">
        @include('reports.partials.header', ['title' => __('Customer Ledger'), 'period' => $customer->name])
        <div class="d-flex justify-content-between align-items-start gap-3 mb-3">
            <div><h5>{{ $customer->name }}</h5><span class="text-muted">{{ $customer->phone }}</span></div>
            <div class="text-end"><small>{{ __('Current Due') }}</small><h5 class="text-danger money">{{ number_format($customer->balance, 2) }} {{ $moneyCode }}</h5><button onclick="window.print()" class="btn btn-light btn-sm no-print"><i class="fa-solid fa-print me-1"></i>{{ __('Print') }}</button></div>
        </div>
        <div class="table-responsive">
            <table class="table mt-3">
                <thead><tr><th>{{ __('Date') }}</th><th>{{ __('Description') }}</th><th>{{ __('Reference') }}</th><th class="text-end">{{ __('Debit') }}</th><th class="text-end">{{ __('Credit') }}</th><th class="text-end">{{ __('Balance') }}</th></tr></thead>
                <tbody>
                    @php($balance = 0)
                    @foreach($entries as $entry)
                        @php($balance += $entry['debit'] - $entry['credit'])
                        <tr><td>{{ \App\Support\DualDate::format($entry['date'], 'd M Y') }}</td><td>{{ $entry['description'] }}</td><td>{{ $entry['reference'] }}</td><td class="text-danger text-end money">{{ $entry['debit'] ? number_format($entry['debit'], 2) : '-' }}</td><td class="text-success text-end money">{{ $entry['credit'] ? number_format($entry['credit'], 2) : '-' }}</td><td class="text-end fw-bold money">{{ number_format($balance, 2) }}</td></tr>
                    @endforeach
                </tbody>
            </table>
        </div>
    </div>
</div>
@if(!empty($appSettings['report_footer']))<p class="text-center text-muted small mt-3">{{ $appSettings['report_footer'] }}</p>@endif
@endsection
