<!DOCTYPE html>
<html>
<head>
    <title>Laporan Pembelian</title>
    <style>
        body { font-family: sans-serif; font-size: 12px; }
        table { width: 100%; border-collapse: collapse; margin-top: 20px; }
        th, td { border: 1px solid #ddd; padding: 8px; text-align: left; }
        th { background-color: #f2f2f2; }
        .header { text-align: center; margin-bottom: 20px; }
        .footer { position: fixed; bottom: 0; width: 100%; text-align: right; font-size: 10px; }
        .badge { padding: 2px 5px; border-radius: 3px; font-size: 10px; color: #fff; }
        .bg-info { background-color: #17a2b8; }
    </style>
</head>
<body>
    <div class="header">
        <h2>Laporan Pembelian</h2>
        <p>Warkop Cak Imin - Akuntansi SIA</p>
        <p>Tanggal Cetak: {{ date('d/m/Y H:i') }}</p>
    </div>

    @foreach($branches as $branch)
    @php
        $branchPurchases = $purchases->where('branch', $branch->name);
    @endphp
    @if($branchPurchases->count() > 0)
    <h3>Cabang: {{ $branch->name }}</h3>
    <table>
        <thead>
            <tr>
                <th>No</th>
                <th>Tanggal</th>
                <th>Item/Produk</th>
                <th>Jumlah</th>
                <th>Total Harga</th>
            </tr>
        </thead>
        <tbody>
            @foreach($branchPurchases as $index => $purchase)
            <tr>
                <td>{{ $index + 1 }}</td>
                <td>{{ \Carbon\Carbon::parse($purchase->date)->format('d/m/Y') }}</td>
                <td>{{ $purchase->item }}</td>
                <td>{{ $purchase->quantity }}</td>
                <td>Rp {{ number_format($purchase->total_price, 0, ',', '.') }}</td>
            </tr>
            @endforeach
        </tbody>
        <tfoot>
            <tr>
                <th colspan="4" style="text-align: right;">Total</th>
                <th>Rp {{ number_format($branchPurchases->sum('total_price'), 0, ',', '.') }}</th>
            </tr>
        </tfoot>
    </table>
    @endif
    @endforeach

    <div class="footer">
        Halaman 1
    </div>
</body>
</html>
