@php $counter = 1; @endphp @foreach($payments as $payment)
Payment {{ $counter }} of {{ $payments->count() }}

SchoolERP Solutions

123 Education Street, Tech City

Email: billing@schoolerp.com | Phone: +91 98765 43210

PAYMENT RECEIPT

#RCP-{{ $payment->id }}

Date: {{ \Carbon\Carbon::parse($payment->payment_date)->format('M d, Y') }}

PAID

Received From:

{{ $school->name }}

{{ $school->address ?? 'Address not available' }}

Email: {{ $school->email }}

Phone: {{ $school->phone ?? 'N/A' }}

Payment Details:

Invoice #: {{ $payment->invoice_number }}

Payment Method: {{ ucfirst(str_replace('_', ' ', $payment->payment_method)) }}

@if($payment->transaction_id)

Transaction ID: {{ $payment->transaction_id }}

@endif

Received By: {{ $payment->receivedBy->name ?? 'Admin' }}

@if($payment->previous_balance != 0) @endif @if($payment->balance_remaining != 0) @endif
Description Amount
Invoice Amount ₹{{ number_format($payment->invoice_amount, 2) }}
{{ $payment->previous_balance > 0 ? 'Previous Balance (Due)' : 'Previous Balance (Advance)' }} {{ $payment->previous_balance > 0 ? '+' : '' }}₹{{ number_format(abs($payment->previous_balance), 2) }}
Total Payable ₹{{ number_format($payment->total_payable, 2) }}
Amount Paid ₹{{ number_format($payment->amount_paid, 2) }}
{{ $payment->balance_remaining > 0 ? 'Balance Due' : 'Advance Credit' }} ₹{{ number_format(abs($payment->balance_remaining), 2) }}
Amount Received: ₹{{ number_format($payment->amount_paid, 2) }}
@if($payment->notes)

Notes: {{ $payment->notes }}

@endif
@php $counter++; @endphp @endforeach

Payment Summary

@php $remaining = $invoice->total_amount - $payments->sum('amount_paid'); @endphp @if($remaining > 0) @else @endif
Total Invoice Amount: ₹{{ number_format($invoice->total_amount, 2) }}
Total Paid: ₹{{ number_format($payments->sum('amount_paid'), 2) }}
Balance Due: ₹{{ number_format($remaining, 2) }}
FULLY PAID
{{-- 🆕 DELETE LAST PAYMENT - Only if NO credit note linked (check ALL payments) --}} @php // 🔒 FIX: Check ALL payments for credit note, not just last one $hasCreditNote = $payments->contains(function($payment) { return !is_null($payment->credit_note_id); }); @endphp @if(!$hasCreditNote) @else {{-- 🆕 Show locked status if credit note exists --}} @endif