<?php
include "../../include/config.php";
include "../../function/inc_function.php";
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="data_konversi_barang' . date('Y-m-d H:i:s') . '.xls"');
header('Cache-Control: max-age=0');

$fromdate = $_REQUEST['fromdate'];
$todate = $_REQUEST['todate'];
?>
<table width="100%" border="0">
    <tr>
        <td colspan="11" align="left"><strong>DATA KONVERSI BARANG</strong></td>
    </tr>
    <tr>
        <td colspan="11" align="left"><strong>PERIODE : <?= $fromdate; ?> s/d <?= $todate; ?></strong></td>
    </tr>
</table>
<table width="100%" border="1">
    <tr>
        <th align="center" bgcolor="#D1D1D1" rowspan="2">NO</th>
        <th align="center" bgcolor="#D1D1D1" rowspan="2">NOMOR TRANSAKSI</th>
        <th align="center" bgcolor="#D1D1D1" rowspan="2">TANGGAL</th>
        <th align="center" bgcolor="#D1D1D1" colspan="5">BARANG JADI</th>
        <th align="center" bgcolor="#D1D1D1" colspan="4">DETAIL BARANG KONVERSI</th>
    </tr>
    <tr>
        <th align="center" bgcolor="#D1D1D1">KODE</th>
        <th align="center" bgcolor="#D1D1D1">NAMA</th>
        <th align="center" bgcolor="#D1D1D1">JUMLAH</th>
        <th align="center" bgcolor="#D1D1D1">SATUAN</th>
        <th align="center" bgcolor="#D1D1D1">ALASAN</th>
        <th align="center" bgcolor="#D1D1D1">KODE</th>
        <th align="center" bgcolor="#D1D1D1">NAMA</th>
        <th align="center" bgcolor="#D1D1D1">JUMLAH</th>
        <th align="center" bgcolor="#D1D1D1">SATUAN</th>
    </tr>
    <?php
    $qd = mysql_query("SELECT a.kv_no,a.kv_date,b.prod_code AS hcode,b.prod_name AS hname,a.kv_qty,a.kv_grade,b.prod_sat AS hsat,
    d.prod_code AS dcode,d.prod_name AS dname,c.kvd_qty,d.prod_sat AS dsat
    FROM konversi_barangjadi a
    INNER JOIN product b ON b.id = a.kv_prodid
    INNER JOIN konversi_barangjadi_detail c ON c.kvd_hid = a.id
    INNER JOIN product d ON d.id = c.kvd_prodid
    WHERE a.kv_date BETWEEN '$fromdate' AND '$todate' AND a.kv_status <> 100 ORDER BY a.id DESC");
    $no = 1;
    while ($dd = mysql_fetch_object($qd)) {
    ?>
        <tr>
            <td align="center"><?= $no; ?></td>
            <td align="center"><?= $dd->kv_no; ?></td>
            <td align="center"><?= $dd->kv_date; ?></td>
            <td align="left"><?= $dd->hcode; ?></td>
            <td align="left"><?= $dd->hname; ?></td>
            <td align="right"><?= number_format($dd->kv_qty, 2, '.', ''); ?></td>
            <td align="left"><?= $dd->hsat; ?></td>
            <td align="center"> GRADE <?= $dd->kv_grade; ?></td>
            <td align="left"><?= $dd->dcode; ?></td>
            <td align="left"><?= $dd->dname; ?></td>
            <td align="right"><?= number_format($dd->kvd_qty, 2, '.', ''); ?></td>
            <td align="center"><?= $dd->dsat; ?></td>
        </tr>
    <?php $no++;
    }  ?>
</table>