<!DOCTYPE html>
<html>
<head>
    <title>Laporan Transaksi</title>
    <style>
        body { font-family: sans-serif; font-size: 12px; }
        h3 { text-align: center; }
        table { width: 100%; border-collapse: collapse; margin-top: 10px; }
        th, td { border: 1px solid #333; padding: 6px; text-align: left; }
        th { background: #eee; }
        .summary { margin-bottom: 20px; }
    </style>
</head>
<body>
    <h3>Laporan Transaksi PAMSIMAS</h3>
    <p>Periode: {{ $request->start_date }} s/d {{ $request->end_date }}</p>
    <div class="summary">
        <p>Total Lunas: Rp {{ number_format($summary['totalPaid'], 0, ',', '.') }}</p>
        <p>Total Belum Bayar: Rp {{ number_format($summary['totalUnpaid'], 0, ',', '.') }}</p>
        <p>Jumlah Transaksi: {{ $summary['totalTransactions'] }}</p>
    </div>
    <table>
        <thead>
            <tr>
                <th>No</th>
                <th>ID Tagihan</th>
                <th>Pelanggan</th>
                <th>Total (Rp)</th>
                <th>Status</th>
                <th>Metode</th>
                <th>Tgl Dibuat</th>
                <th>Tgl Dibayar</th>
            </tr>
        </thead>
        <tbody>
            @foreach($invoices as $index => $inv)
            <tr>
                <td>{{ $index + 1 }}</td>
                <td>{{ $inv->invoice_number }}</td>
                <td>{{ $inv->user->name ?? '-' }}</td>
                <td>{{ number_format($inv->total_amount, 0, ',', '.') }}</td>
                <td>{{ $inv->status }}</td>
                <td>{{ $inv->payment_method ?? '-' }}</td>
                <td>{{ $inv->created_at->format('d M Y') }}</td>
                <td>{{ $inv->paid_at ? $inv->paid_at->format('d M Y') : '-' }}</td>
            </tr>
            @endforeach
        </tbody>
    </table>
</body>
</html>