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

<h3>Detail Nota <?= $model->nomor ?></h3>

<p>
<?= Html::a('🖨 Cetak',['print','id'=>$model->id],[
    'class'=>'btn btn-primary',
    'target'=>'_blank'
]) ?>

<?= Html::a('PDF',['pdf','id'=>$model->id],[
    'class'=>'btn btn-warning',
    'target'=>'_blank'
]) ?>
</p>

<b>Pelanggan:</b> <?= Html::encode($model->pelanggan) ?><br>
<b>Tanggal:</b> <?= $model->tanggal ?>

<hr>

<table class="table table-bordered">
<thead>
<tr>
  <th>Barang</th>
  <th>Qty</th>
  <th>Diskon %</th>
  <th>Harga</th>
  <th>Subtotal</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><?= $i->diskon ?>%</td>
  <td><?= number_format($i->harga) ?></td>
  <td><?= number_format($subtotal) ?></td>
</tr>
<?php endforeach; ?>
</tbody>
<tfoot>
<tr>
  <th colspan="4">Subtotal</th>
  <th><?= number_format($totalBeforePPN) ?></th>
</tr>

<?php if($model->ppn > 0): ?>
<tr>
  <th colspan="4">PPN 11%</th>
  <th><?= number_format($model->ppn) ?></th>
</tr>
<?php endif; ?>

<tr>
  <th colspan="4">Grand Total</th>
  <th><?= number_format($model->total) ?></th>
</tr>
</tfoot>
</table>
