@extends('layouts.portal')
@section('title', 'Payments')
@section('subtitle', 'Verify learner payment proofs, issue receipts and keep the ledger of everything received.')
@section('actions') Overdue invoices @endsection
@section('content')
@php
$f = $filters;
$st = $f['status'] ?? null;
$tabs = ['' => 'All', 'paid' => 'Paid', 'pending' => 'Pending', 'failed' => 'Rejected', 'refunded' => 'Refunded'];
$img = fn ($p) => in_array(strtolower(pathinfo((string) $p->proof_path, PATHINFO_EXTENSION)), ['jpg', 'jpeg', 'png', 'webp', 'gif'], true);
@endphp
Paid this month {{ money($kpi['month']) }} {{ now()->format('F Y') }}
Total collected {{ money($kpi['collected']) }} verified payments
Awaiting verification {{ money($kpi['pending_amount']) }} {{ $pending->count() }} payment{{ $pending->count() === 1 ? '' : 's' }} in the queue
Refunded {{ money($kpi['refunded']) }} marked as refunded
Payment proofs to verify {{ $pending->count() ? $pending->count().' pending' : 'All caught up' }}
@if($pending->isEmpty())
@else
@foreach($pending as $p)
@php $who = $p->user?->name ?? $p->invoice?->customer_name ?? 'Unknown customer'; @endphp
@if($p->proof_path)
@if($img($p))
@else
PDF proof
@endif
@else
Reference only
@endif
{{ $who }} {{ money2($p->amount) }}
@if($p->invoice && (float) $p->amount > $p->invoice->balance() + 0.01)
Amount is more than the invoice balance — it cannot be approved as is.
@endif
Reject
@endforeach
@endif
Payment ledger
@foreach($tabs as $k => $label)
{{ $label }} {{ $k === '' ? $counts->sum() : ($counts[$k] ?? 0) }}
@endforeach
Receipt Customer Invoice Amount Status Actions
@forelse($payments as $p)
@php $who = $p->user?->name ?? $p->invoice?->customer_name ?? '—'; @endphp
@if($p->receipt_no && $p->status === 'paid'){{ $p->receipt_no }} @elseif($p->receipt_no){{ $p->receipt_no }} @elsePending @endif{{ ($p->paid_at ?? $p->created_at)->format('d M Y, g:i A') }}
{{ $who }} @if($p->transaction_ref)Ref {{ $p->transaction_ref }} @endif
@if($p->invoice){{ $p->invoice->number }} @else— @endif
{{ money2($p->amount) }} {{ $methods[$p->method] ?? ucfirst(str_replace('_', ' ', (string) $p->method)) }}
@if($p->proof_path)
@endif
@if($p->status === 'paid')
@elseif($p->status === 'pending')
Review
@endif
@empty
@endforelse
{{ $payments->links() }}
@foreach($pending as $p)
Reject {{ money2($p->amount) }} payment
The customer is emailed the reason and can submit a new proof from their invoice page.
@endforeach
@foreach($payments->where('status', 'paid') as $p)
Refund {{ money2($p->amount) }}
Marks receipt {{ $p->receipt_no }} as refunded and recalculates the invoice balance. Money is not moved automatically — return it to the customer yourself.
@csrf
Reason (optional)
Cancel Mark as refunded
@endforeach
@endsection