<!DOCTYPE html>
<html lang="id">

<head>
    <meta charset="UTF-8">
    <title>Laporan_Penjualan_MegaMart</title>
    <style>
        body {
            font-family: 'Courier New', Courier, monospace;
            color: #000;
            padding: 20px;
            font-size: 12px;
        }

        .header {
            text-align: center;
            margin-bottom: 30px;
            border-bottom: 2px dashed #000;
            padding-bottom: 10px;
        }

        .header h2 {
            margin: 0;
            font-size: 18px;
            font-weight: bold;
        }

        table {
            border-collapse: collapse;
            margin-top: 15px;
            width: 100%;
        }

        table th,
        table td {
            border: 1px solid #000;
            padding: 8px;
            text-align: left;
        }

        table th {
            background-color: #f2f2f2;
            font-weight: bold;
        }

        .total-box {
            text-align: right;
            margin-top: 20px;
            font-size: 14px;
            font-weight: bold;
            border-top: 2px dashed #000;
            padding-top: 10px;
        }
    </style>
</head>

<body>

    <div class="header">
        <h2>MEGA MART REKAPITULASI PENJUALAN</h2>
        <p>Sistem Manajemen Hubungan Pelanggan (CRM) Berbasis Web</p>
        <p>Tanggal Cetak: {{ now()->isoFormat('LLLL') }}</p>
    </div>

    <!-- 📊 Ringkasan Statistik Singkat di Atas Tabel -->
    <div style="margin-bottom: 15px; font-weight: bold;">
        <p>Total Pesanan Sukses: {{ $transaksiSuksesCount }} Pesanan</p>
        <p>Total Kupon CRM Diklaim: {{ $kuponTerpakai }} Kali</p>
    </div>

    <table>
        <thead>
            <tr>
                <th>ID Transaksi</th>
                <th>Tanggal</th>
                <th>Nama Pelanggan</th>
                <th>Status</th>
                <th>Total Bayar</th>
            </tr>
        </thead>
        <tbody>
            @foreach($transaksis as $t)
            <tr>
                <td>#TRX-{{ $t->id }}</td>
                <td>{{ $t->created_at->format('d/m/Y H:i') }}</td>
                <td>{{ $t->pelanggan->nama ?? 'Umum' }}</td>
                <td style="text-transform: uppercase;">{{ $t->status }}</td>
                <td>Rp {{ number_format($t->total_bayar, 0, ',', '.') }}</td>
            </tr>
            @endforeach
        </tbody>
    </table>

    <div class="total-box">
        TOTAL OMSET BERHASIL DIBUKUKAN: Rp {{ number_format($totalOmset, 0, ',', '.') }}
    </div>

    <script>
        window.print();
    </script>

</body>

</html>