Müşteri Tahsilatları

@php // Tüm payments'ları yükle ve toplamları hesapla $payments = $patient->payments()->with(['items', 'transactions.currency'])->get(); // Para birimi bazında toplamları hesapla $currencyTotals = []; foreach ($payments as $payment) { foreach ($payment->items as $item) { $currencyCode = $item->currency->code ?? 'TRY'; if (!isset($currencyTotals[$currencyCode])) { $currencyTotals[$currencyCode] = [ 'grand_total' => 0, 'paid_total' => 0, 'remaining_total' => 0, ]; } $currencyTotals[$currencyCode]['grand_total'] += $item->total; } // Transactions'dan ödenen tutarları ekle foreach ($payment->transactions as $transaction) { $currencyCode = $transaction->currency->code ?? 'TRY'; if (!isset($currencyTotals[$currencyCode])) { $currencyTotals[$currencyCode] = [ 'grand_total' => 0, 'paid_total' => 0, 'remaining_total' => 0, ]; } $currencyTotals[$currencyCode]['paid_total'] += $transaction->amount; } } // Kalan tutarları hesapla foreach ($currencyTotals as $currency => &$totals) { $totals['remaining_total'] = $totals['grand_total'] - $totals['paid_total']; } @endphp @if($payments->count() > 0)
@foreach($currencyTotals as $currencyCode => $totals)

{{ $currencyCode }} - Özet

Toplam Borç
{{ number_format($totals['remaining_total'], 2) }} {{ $currencyCode }}
Ödenen
{{ number_format($totals['paid_total'], 2) }} {{ $currencyCode }}
Toplam Fatura
{{ number_format($totals['grand_total'], 2) }} {{ $currencyCode }}
@endforeach

Fatura Detayları

@foreach($payments->sortByDesc('invoice_date') as $payment) @php // Payment Items bazında toplam hesapla $itemsByCurrency = $payment->items->groupBy(fn($item) => $item->currency->code ?? 'TRY'); // Transactions bazında ödenen hesapla $paidByCurrency = $payment->transactions->groupBy(fn($trans) => $trans->currency->code ?? 'TRY'); @endphp @endforeach
Fatura Tarihi Randevu Hizmetler Toplam Tutar Ödenen Kalan Durum
{{ $payment->invoice_date ? $payment->invoice_date->format('d/m/Y') : 'N/A' }} @if($payment->appointment) {{ $payment->appointment->title ?? 'Randevu #' . $payment->appointment->id }} @else Randevu dışı @endif
@foreach($payment->items->unique('service_id') as $item)
• {{ $item->service->name ?? 'Hizmet' }}
@endforeach
@foreach($itemsByCurrency as $currency => $items)
{{ number_format($items->sum('total'), 2) }} {{ $currency }}
@endforeach
@foreach($itemsByCurrency as $currency => $items) @php $paidAmount = $paidByCurrency->get($currency)?->sum('amount') ?? 0; @endphp
{{ number_format($paidAmount, 2) }} {{ $currency }}
@endforeach
@foreach($itemsByCurrency as $currency => $items) @php $totalAmount = $items->sum('total'); $paidAmount = $paidByCurrency->get($currency)?->sum('amount') ?? 0; $remaining = $totalAmount - $paidAmount; @endphp
{{ number_format($remaining, 2) }} {{ $currency }}
@endforeach
@php $totalGrandTotal = $payment->items->sum('total'); $totalPaid = $payment->transactions->sum('amount'); $isFullyPaid = $totalPaid >= $totalGrandTotal; $isOverdue = $payment->due_date && $payment->due_date->isPast() && !$isFullyPaid; @endphp @if($isFullyPaid) Ödendi @elseif($isOverdue) Vadesi Geçmiş @else Beklemede @endif
@php $overduePayments = $payments->filter(function($payment) { $totalGrandTotal = $payment->items->sum('total'); $totalPaid = $payment->transactions->sum('amount'); return $payment->due_date && $payment->due_date->isPast() && $totalPaid < $totalGrandTotal; }); $overdueByCurrency = []; foreach ($overduePayments as $payment) { foreach ($payment->items->groupBy(fn($item) => $item->currency->code ?? 'TRY') as $currency => $items) { $totalAmount = $items->sum('total'); $paidAmount = $payment->transactions ->where('currency.code', $currency) ->sum('amount'); $remaining = $totalAmount - $paidAmount; if (!isset($overdueByCurrency[$currency])) { $overdueByCurrency[$currency] = 0; } $overdueByCurrency[$currency] += $remaining; } } @endphp @if($overduePayments->count() > 0)

Vadesi Geçmiş Borçlar

{{ $overduePayments->count() }} adet vadesi geçmiş fatura bulunmaktadır.

@foreach($overdueByCurrency as $currency => $amount)

{{ $currency }}: {{ number_format($amount, 2) }}

@endforeach
@endif @else

Herhangi bir borç kaydı bulunmuyor

Bu müşterinin henüz herhangi bir fatura veya borç kaydı yoktur.

@endif