<?php
use yii\helpers\Html;
?>

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Nota</title>

<style>

/* ====== UKURAN THERMAL ===== */
body{
  font-family: monospace;
  font-size:12px;
}

.thermal{
  width:58mm;   /* ganti 80mm jika printer besar */
  margin:auto;
}

.center{text-align:center;}
.right{text-align:right;}

hr{
  border:none;
  border-top:1px dashed #000;
}

/* TABLE ITEM */
table{
  width:100%;
  border-collapse:collapse;
}

th,td{
  font-size:11px;
}

.qty{width:12%;}
.nama{width:36%;}
.diskon{width:12%;}
.harga{width:20%;}
.sub{width:20%;}

@media print{
  button{display:none;}
}

</style>
</head>

<body>

<div class="thermal">

  <div class="center">
    <strong><?= $cluster->vNama; ?></strong><br>
    <span style=" font-size:11px;"><?= $cluster->vAlamat; ?></span><br>
    Telp 0812xxxxxxx
  </div>

  <hr>

  No : <?= $model->nomor ?><br>
  Tgl: <?= date('d/m/Y',strtotime($model->tanggal)) ?><br>
  Plg: <?= Html::encode($model->pelanggan) ?>

  <hr>

  <table>
    <thead>
      <tr>
        <th class="nama">Item</th>
        <th class="qty">Qty</th>
        <th class="diskon">Disc%</th>
        <th class="harga right">Harga</th>
        <th class="sub right">Sub</th>
      </tr>
    </thead>
    <tbody>
    <?php 
    $totalBeforePPN = 0;
    foreach($model->items as $i):
        $subtotal = $i->qty * $i->harga * (1 - $i->diskon/100);
        $totalBeforePPN += $subtotal;
    ?>
      <tr>
        <td><?= Html::encode($i->barang->nama) ?></td>
        <td><?= $i->qty ?></td>
        <td class="right"><?= $i->diskon ?>%</td>
        <td class="right"><?= number_format($i->harga) ?></td>
        <td class="right"><?= number_format($subtotal) ?></td>
      </tr>
    <?php endforeach; ?>
    </tbody>
  </table>

  <hr>

  <table>
    <tr>
      <td><b>Subtotal</b></td>
      <td class="right"><b><?= number_format($totalBeforePPN) ?></b></td>
    </tr>

    <?php if($model->ppn > 0): ?>
    <tr>
      <td><b>PPN 11%</b></td>
      <td class="right"><b><?= number_format($model->ppn) ?></b></td>
    </tr>
    <?php endif; ?>

    <tr>
      <td><b>Grand Total</b></td>
      <td class="right"><b><?= number_format($model->total) ?></b></td>
    </tr>
  </table>

  <hr>

  <div class="center">
    Terima Kasih 🙏<br>
    Barang yang sudah dibeli<br>
    tidak dapat dikembalikan
  </div>

  <br>

  <button onclick="window.print()">🖨 Cetak</button>

</div>

</body>
</html>
