<!DOCTYPE html>
<html lang="id">
<head>
    <meta charset="UTF-8">
    <title>NOTA TEMPO - {{ $sale->invoice_number }}</title>
    <style>
        @media print {
            @page {
                size: 210mm 148mm;
                margin: 0;
            }
        }
        body {
            font-family: 'Courier New', Courier, monospace;
            font-size: 12px;
            margin: 20px;
            color: #000;
        }
        .header-table { width: 100%; margin-bottom: 5px; }
        .title { text-align: center; font-size: 16px; font-weight: bold; text-decoration: underline; margin: 5px 0; }
        
        /* Style khusus untuk Nama Cabang agar Besar dan Tebal */
        .branch-name {
            font-size: 18px;
            font-weight: bold;
            text-transform: uppercase;
        }
        
        .items-table { width: 100%; border-collapse: collapse; margin: 10px 0; }
        .items-table th { border-top: 1px dashed #000; border-bottom: 1px dashed #000; text-align: left; padding: 5px; }
        .items-table td { padding: 3px 5px; vertical-align: top; }
        .border-bottom { border-bottom: 1px dashed #000; }
        
        .total-section { width: 100%; margin-top: 5px; }
        .signatures { width: 100%; margin-top: 15px; text-align: center; }
        .signature-box { height: 50px; vertical-align: bottom; }
    </style>
</head>
<body onload="window.print()">
    <table class="header-table">
        <tr>
            <td width="55%">
                {{-- Menampilkan Nama Cabang (RISKI JAYA 1) dengan Huruf Besar & Tebal --}}
                <span class="branch-name">{{ $sale->branch->name ?? 'RISKI JAYA 1' }}</span><br>
                {{ $sale->branch->address ?? 'Alamat Toko' }}
            </td>
            <td width="45%" align="right">
                No: {{ $sale->invoice_number }}<br>
                Tgl: {{ $sale->created_at->format('d/m/Y H:i') }}<br>
                Pelanggan: {{ $sale->customer->name ?? 'Umum' }}
            </td>
        </tr>
    </table>

    <div class="title">NOTA TEMPO / KREDIT</div>

    <table class="items-table">
        <thead>
            <tr>
                <th width="50%">Nama Barang</th>
                <th align="right">Qty</th>
                <th align="right">Harga</th>
                <th align="right">Subtotal</th>
            </tr>
        </thead>
        <tbody>
            @foreach($sale->items as $item)
            <tr>
                <td>{{ $item->product->name }}</td>
                <td align="right">{{ number_format($item->quantity, 0) }}</td>
                <td align="right">{{ number_format($item->unit_price, 0, ',', '.') }}</td>
                <td align="right">{{ number_format($item->total_price, 0, ',', '.') }}</td>
            </tr>
            @endforeach
            <tr>
                <td colspan="4" class="border-bottom"></td>
            </tr>
        </tbody>
    </table>

    <table class="total-section">
        <tr>
            <td width="60%">
                @if($sale->due_date)
                <i>Ket: Pembayaran jatuh tempo pada {{ \Carbon\Carbon::parse($sale->due_date)->format('d/m/Y') }}</i>
                @endif
            </td>
            <td width="40%" align="right">
                <strong>GRAND TOTAL: Rp {{ number_format($sale->grand_total, 0, ',', '.') }}</strong>
            </td>
        </tr>
    </table>

    <table class="signatures">
        <tr>
            <td width="33%">Penerima / Sopir<br><br><br><br>( ................. )</td>
            <td width="33%">Pelanggan<br><br><br><br>( ................. )</td>
            <td width="33%">Hormat Kami,<br><br><br><br>( {{ $sale->user->name }} )</td>
        </tr>
    </table>
</body>
</html>