<?php
include '../koneksi.php';

header("Content-type: application/vnd-ms-excel");
header("Content-Disposition: attachment; filename=Data_Piutang.xls");
?>

<table border="1" width="100%">
<tr>
  <th colspan="5">DATA PIUTANG</th>
</tr>
<tr>
  <th>No</th>
  <th>Kode</th>
  <th>Tanggal</th>
  <th>Keterangan</th>
  <th>Nominal</th>
</tr>

<?php
$no=1;
$total=0;
$data = mysqli_query($koneksi,"SELECT * FROM piutang ORDER BY piutang_id DESC");
while($d=mysqli_fetch_array($data)){
?>
<tr>
  <td><?= $no++ ?></td>
  <td>PTG-000<?= $d['piutang_id'] ?></td>
  <td><?= date('d/m/Y', strtotime($d['piutang_tanggal'])) ?></td>
  <td><?= $d['piutang_keterangan'] ?></td>
  <td><?= $d['piutang_nominal'] ?></td>
</tr>
<?php $total += $d['piutang_nominal']; } ?>

<tr>
  <th colspan="4">TOTAL</th>
  <th><?= $total ?></th>
</tr>
</table>
