@extends('layouts.app')
@section('title',$payment->receipt_number)
@section('content')
@php($business=$payment->branch->business)
<x-ui.page-toolbar :title="$payment->receipt_number" description="Loan payment receipt" :breadcrumbs="[['label'=>'Dashboard','url'=>route('dashboard')],['label'=>'Loan Payments','url'=>route('loan-payments.index')],['label'=>$payment->receipt_number]]"><x-slot:actions><button class="mf-btn" onclick="window.print()">Print receipt</button><a class="mf-btn mf-btn-primary" href="{{ route('documents.payment-receipt.pdf',$payment) }}">Download PDF</a></x-slot:actions></x-ui.page-toolbar>
<div class="mx-auto max-w-3xl mf-card payment-document">
<div class="border-b p-5 flex justify-between gap-4"><div class="flex gap-3">@if($business->logo_path)<img src="{{ route('document-branding.asset',[$business,'logo']) }}" alt="Company logo" class="h-14 w-20 object-contain">@endif<div><h2 class="text-lg font-semibold">{{ $business->name }}</h2><p class="text-xs text-muted-foreground">{{ collect([$business->address,$business->phone,$business->email])->filter()->join(' · ') }}</p><p class="text-xs text-muted-foreground">{{ $payment->branch->name }} · Loan Payment Receipt</p></div></div><div class="text-right"><div class="font-semibold">{{ $payment->receipt_number }}</div><div class="text-xs text-muted-foreground">{{ $payment->payment_date->format('d M Y') }}</div><div class="text-xs text-muted-foreground">Reg {{ $business->registration_number ?: 'N/A' }} · TIN {{ $business->tin ?: 'N/A' }}</div></div></div>
<div class="p-5 space-y-5">
<div class="grid gap-4 sm:grid-cols-2 text-sm"><div><div class="text-xs text-muted-foreground">Customer</div><div class="font-medium">{{ $payment->customer->full_name }}</div><div class="text-xs text-muted-foreground">{{ $payment->customer->customer_number }} · {{ $payment->customer->phone }}</div></div><div><div class="text-xs text-muted-foreground">Loan</div><div class="font-medium">{{ $payment->loan->loan_number }}</div><div class="text-xs text-muted-foreground">{{ $payment->loan->product->name }}</div></div><div><div class="text-xs text-muted-foreground">Method / Account</div><div class="font-medium">{{ str($payment->method)->replace('_',' ')->title() }}</div><div class="text-xs text-muted-foreground">{{ $payment->financialAccount->name }}</div></div><div><div class="text-xs text-muted-foreground">Reference</div><div class="font-medium">{{ $payment->reference ?: '—' }}</div></div></div>
<div class="rounded-md border p-4"><div class="text-xs text-muted-foreground">Amount received</div><div class="mt-1 text-2xl font-semibold">{{ $business->currency_symbol ?: $business->currency }} {{ number_format((float)$payment->amount,2) }}</div></div>
<div class="mf-table-frame"><table class="mf-table"><thead><tr><th>Allocation</th><th class="text-right">Amount</th></tr></thead><tbody><tr><td>Principal</td><td class="text-right">{{ number_format((float)$payment->principal_amount,2) }}</td></tr><tr><td>Interest</td><td class="text-right">{{ number_format((float)$payment->interest_amount,2) }}</td></tr><tr><td>Fees</td><td class="text-right">{{ number_format((float)$payment->fees_amount,2) }}</td></tr><tr><td>Penalties</td><td class="text-right">{{ number_format((float)$payment->penalties_amount,2) }}</td></tr></tbody></table></div>
<div class="flex justify-between border-t pt-4 text-sm"><span>Remaining loan balance</span><strong>{{ number_format((float)$payment->loan->total_outstanding,2) }}</strong></div>
@if($payment->notes)<div class="text-sm"><span class="text-muted-foreground">Notes:</span> {{ $payment->notes }}</div>@endif
<div class="grid grid-cols-2 gap-10 pt-10 text-xs"><div class="border-t pt-2">Received by: {{ $payment->receiver?->name ?? 'System' }}</div><div class="border-t pt-2">Customer signature</div></div>
@if($business->stamp_path)<div class="flex justify-end"><img src="{{ route('document-branding.asset',[$business,'stamp']) }}" alt="Company stamp" class="max-h-20 max-w-28 object-contain"></div>@endif
</div></div>
@endsection
@push('styles')<style>@media print{.mf-sidebar,.mf-topbar{display:none!important}.mf-content{margin:0!important}.mf-page{padding:0!important}.payment-document{border:0!important;box-shadow:none!important}}</style>@endpush
