<!DOCTYPE html><html lang="id"><head><meta charset="utf-8"><title>Kuitansi <?= e($pay['payment_no']) ?></title>
<style>body{font-family:Arial,sans-serif;font-size:12px;margin:24px;color:#222}h1{font-size:17px;color:#1f3864;margin:0 0 2px}
h2{font-size:14px;margin:16px 0 8px}table{width:100%;border-collapse:collapse;margin-top:8px}
th{background:#1f3864;color:#fff;padding:6px;text-align:left;font-size:11px;border:1px solid #1f3864}
td{padding:5px 6px;border:1px solid #d7d7d7;font-size:11px}.num{text-align:right}.tot td{background:#dce6f1;font-weight:700}
.lbl{color:#666;width:150px;display:inline-block}.big{font-size:19px;font-weight:700;color:#1f3864;margin:10px 0}
.ttd{margin-top:44px;display:flex;gap:60px}.ttd div{flex:1;font-size:11px}.line{margin-top:52px;border-top:1px solid #888;padding-top:4px}
@media print{.noprint{display:none}body{margin:10mm}}
button{padding:7px 14px;margin-bottom:12px;border:1px solid #1f3864;background:#1f3864;color:#fff;border-radius:5px;cursor:pointer}</style>
</head><body>
<div class="noprint"><button onclick="window.print()">Cetak</button> <button onclick="window.close()" style="background:#fff;color:#1f3864">Tutup</button></div>
<h1><?= e(setting('umum.nama_perusahaan','')) ?></h1>
<div style="font-size:11px;color:#666"><?= e(setting('umum.alamat_perusahaan','')) ?></div>
<h2>KUITANSI PENERIMAAN PEMBAYARAN</h2>
<div><span class="lbl">Nomor Kuitansi</span>: <strong><?= e($pay['payment_no']) ?></strong></div>
<div><span class="lbl">Tanggal</span>: <?= tglPanjang($pay['payment_date']) ?></div>
<div><span class="lbl">Diterima dari</span>: <strong><?= e($pay['customer_name'] ?: '-') ?></strong></div>
<div><span class="lbl">Metode</span>: <?= e(\App\Services\PaymentService::METHODS[$pay['method']] ?? $pay['method']) ?><?= $pay['bank_name'] ? ' — ' . e($pay['bank_name']) : '' ?></div>
<div><span class="lbl">Nomor Referensi</span>: <?= e($pay['reference_no'] ?: '-') ?></div>
<div class="big">Rp <?= nf($pay['amount'],0) ?></div>
<h2>Rincian Alokasi</h2>
<table><thead><tr><th>No. Invoice</th><th>Tgl Invoice</th><th>Jatuh Tempo</th><th class="num">Total Tagihan</th><th class="num">Dialokasikan</th><th class="num">Sisa Saldo</th></tr></thead>
<tbody><?php foreach ($allocations as $a): ?>
<tr><td><?= e($a['invoice_no']) ?></td><td><?= tgl($a['invoice_date']) ?></td><td><?= tgl($a['due_date']) ?></td>
<td class="num"><?= e(rp($a['net_amount'])) ?></td><td class="num"><?= e(rp($a['amount'])) ?></td><td class="num"><?= e(rp($a['outstanding_amount'])) ?></td></tr>
<?php endforeach; ?>
<tr class="tot"><td colspan="4">TOTAL DITERIMA</td><td class="num"><?= e(rp(array_sum(array_map(fn($a)=>(float)$a['amount'],$allocations)))) ?></td><td></td></tr>
</tbody></table>
<?php if ($pay['notes']): ?><p style="font-size:11px;margin-top:10px"><strong>Catatan:</strong> <?= e($pay['notes']) ?></p><?php endif; ?>
<div class="ttd"><div>Diterima oleh,<div class="line"><?= e($pay['created_by_name'] ?: userName()) ?></div></div>
  <div>Disetujui oleh,<div class="line"><?= e($pay['approved_by_name'] ?: '(...................................)') ?></div></div></div>
<div style="font-size:10px;color:#888;margin-top:20px">Dicetak <?= tglWaktu(App\Core\Dates::now()) ?> melalui SIPIUTANG</div>
<script>window.addEventListener('load',()=>setTimeout(()=>window.print(),400))</script></body></html>
