@php
$balance = $total;
$balanceOut = 0;
$balanceOut2 = 0;
$balance_pending = 1;
@endphp
@forelse ($payments as $payment)
@php
$amount = floatval($payment->amount ?? 0);
$balanceNote = $payment->exact_amount;
if ($payment->status->label() == 'Paid') {
$balance -= $amount;
$balanceOut = $payment->exact_amount + $balanceOut2;
}
if($payment->status->label() == 'Pending' && $balance_pending != 0){
if ($balanceOut2 == 0) {
// First pending invoice
$balanceOut2 = $payment->exact_amount;
} else {
// Subsequent pending invoices
$balanceOut2 += $payment->exact_amount;
}
}
if($balance_pending == 0){
$balanceOut2 = $payment->exact_amount;
}
@endphp
| {{ $payment->invoiced_at?->format('d/m/Y') ?? '-' }} |
@if($payment->status->label() == 'Pending'){{ $payment->invoice_no ?? '' }} - {{ $payment->invoiced_at?->copy()->addMonth()->format('m/Y') ?? '' }} @endif
@if($payment->status->label() == 'Paid'){{ $payment->invoice_no ?? '' }} - {{ $payment->invoiced_at?->copy()->addMonth()->format('m/Y') ?? '' }} @endif |
|
@if($payment->status->label() == 'Pending'){{ number_format($payment->exact_amount ?? '-', 2) }} @endif
@if($payment->status->label() == 'Paid'){{ number_format($payment->exact_amount ?? '-', 2) }} @endif
|
@if($payment->status->label() == 'Paid'){{ number_format($balanceOut, 2) }} @endif
@if($payment->status->label() == 'Pending'){{ number_format($balanceOut2, 2) }}@endif |
@foreach ($payment->items->reject(fn($i)=>is_null($i->credit_debit_note_id)) as $item)
@php
$balanceNote += match($item->type) {
App\Models\Traits\Enum\TransactionType::CREDIT => -$item->amount,
App\Models\Traits\Enum\TransactionType::DEBIT => $item->amount,
default => 0,
};
if($balanceNote == 0){
$balance_pending = 0;
}
@endphp
| {{ $item->created_at?->format('d/m/Y') ?? '-' }} |
{{ str_replace('Metro-INVN-', 'Metro-' . ($item->type->value ?? '') . '-', $payment->invoice_no ?? '') }} - {{ $payment->invoiced_at?->copy()->addMonth()->format('m/Y') ?? '' }} |
@if ($item->type->value === 'CN'){{ number_format($item->amount ?? '-', 2) }}@endif |
@if ($item->type->value === 'DN'){{ number_format($item->amount ?? '-', 2) }}@endif |
{{ number_format($balanceNote, 2) }} |
@endforeach
@php if($payment->status->label() == 'Paid'){
$balanceOut -= $payment->exact_amount;
@endphp
| {{ $payment->received_time?->format('d/m/Y') ?? '-' }} |
{{ $payment->invoice_no ?? '' }}@if($payment->status->label() == 'Paid') - Payment @endif |
@if($payment->status->label() == 'Paid'){{ number_format($balanceNote, 2) }} @endif |
@if($payment->status->label() == 'Pending'){{ $payment->exact_amount ?? '-' }}@endif |
@if($payment->status->label() == 'Paid') {{ number_format($balanceOut, 2) }} @endif |
@php } @endphp
@empty
| No record found |
@endforelse
| {{now()->format('d/m/Y')}} |
Balance b/f
| |
{{ number_format($balance, 2) }} |
{{ number_format($balance, 2) }} |
| RINGGIT MALAYSIA :
@php
$formatter = new NumberFormatter('en', NumberFormatter::SPELLOUT);
$whole = floor($balance);
$cents = round(($balance - $whole) * 100);
$words = ucfirst($formatter->format($whole));
if ($cents > 0) {
$words .= " and " . $formatter->format($cents) . " cents";
}
echo strtoupper($words);
@endphp ONLY
|
RM : |
{{ number_format($balance, 2) }} |