<!DOCTYPE html>
<head>
    <title><?php echo @$title ?></title>
    <link rel="stylesheet" href="<?php echo base_url('assets/css/nota.css?time='. md5(time())) ?>">
</head>
<body class="struk" onload="printOut()">
    <section class="sheet">
        <table cellpadding="0" cellspacing="0">
        <tr>
            <td align="center"><?php echo @$toko ?></td>
        </tr>
        <tr>
            <td align="center"><?php echo @$alamat.'<br>Telepon: '.@$telepon ?></td>
        </tr>
        </table>
        =========================
        <table cellpadding="0" cellspacing="0" style="width:100%">
        <tr>
            <td align="left" class="txt-left">Tanggal&nbsp;</td>
            <td align="left" class="txt-left">:</td>
            <td align="left" class="txt-left">&nbsp;<?php echo @$tanggal ?></td>
        </tr>
        <tr>
            <td align="left" class="txt-left">Nota&nbsp;</td>
            <td align="left" class="txt-left">:</td>
            <td align="left" class="txt-left">&nbsp;<?php echo @$invoice ?></td>
        </tr>
        <tr>
            <td align="left" class="txt-left">Kasir</td>
            <td align="left" class="txt-left">:</td>
            <td align="left" class="txt-left">&nbsp;<?php echo @$pegawai ?></td>
        </tr>
        <?php
        if (@$kdmember) {
            ?>
            <tr>
                <td align="left" class="txt-left">Kode Member</td>
                <td align="left" class="txt-left">:</td>
                <td align="left" class="txt-left">&nbsp;<?php echo @$kdmember ?></td>
            </tr>
            <tr>
                <td align="left" class="txt-left">Nama Member</td>
                <td align="left" class="txt-left">:</td>
                <td align="left" class="txt-left">&nbsp;<?php echo @$member ?></td>
            </tr>
            <?php
        }
        ?>
        </table>
        <br>
        <table cellpadding="0" cellspacing="0" style="width:100%" border="0">
        <tr>
            <td align="center" class="txt-left">Item</td>
            <td align="center" width="15%">Qty</td>
            <td align="left" width="20%">Harga</td>
            <td align="right" width="">Total</td>
        </tr>
        <tr>
            <td align="left" colspan="4" class="txt-left">=========================</td>
        </tr>
        <?php
        $subtot=0;
        $totpot=0;
        foreach($datajual as $hasil) {
            if ($hasil->jumlah_jual) {
               $hargasatuan=($hasil->total_harga+$hasil->potongan)/$hasil->jumlah_jual; 
            } else {
                $hargasatuan=0;
            }
            $total=$hasil->jumlah_jual*$hargasatuan;
            if ($hasil->bonus>0) {
                $bonus='+'.$hasil->bonus;
            } else {
                $bonus='';
            }
            ?>
            <tr>
                <td align="left" class="txt-left" colspan="4"><?php echo $hasil->barang ?></td>
            </tr>
            <tr>
                <td align="right" valign="bottom">
                    <?php
                    if ($hasil->potongan) {
                        echo 'Disc. -'.number_format($hasil->potongan,0,',','.').'<br>';
                    }
                    echo $hasil->jumlah_jual.$bonus.' '.$hasil->satuan_jual;
                    ?>
                </td>
                <td align="center" valign="bottom"><?php echo 'x' ?></td>
                <td align="left" valign="bottom"><?php echo number_format($hargasatuan,0,',','.') ?></td>
                <td align="right" valign="bottom"><?php echo number_format($total,0,',','.') ?></td>
            </tr>
            <?php
            $subtot=$subtot+$total;
            $totpot=$totpot+$hasil->potongan;
        }
        ?>
        <!--
        <?php
        if (@$dataretur) {
            $totretur=0;
            foreach($dataretur as $hasil) {
                $total=number_format($hasil->total_harga,0,',','.');
                ?>
                <tr>
                    <td align="left" class="txt-left" colspan="4"><?php echo $hasil->barang ?></td>
                </tr>
                <tr>
                    <td align="right"></td>
                    <td align="center"><?php echo '-'.$hasil->jumlah_retur ?></td>
                    <td align="left"><?php echo $hasil->harga_jual ?></td>
                    <td align="right"><?php echo $total ?></td>
                </tr>
                <?php
                $totretur=$totretur+$hasil->total_harga;
            }
        }
        ?>
        -->
        <tr>
            <td align="left" colspan="4" class="txt-left">
                ---------------------------------------------
            </td>
        </tr>
        <tr>
            <td align="left" colspan="3">Sub Total</td>
            <td align="right"><?php echo number_format($subtot,0,',','.') ?></td>
        </tr>
        <?php
        if ($totpot) {
            ?>
            <tr>
                <td align="left" colspan="3">Diskon</td>
                <td align="right"><?php echo '-'.number_format($totpot,0,',','.') ?></td>
            </tr>
            <?php
        }
        $tb=$subtot-$totpot;
        ?>
        <tr>
            <td align="left" colspan="3">Total Belanja</td>
            <td align="right"><?php echo number_format($tb,0,',','.') ?></td>
        </tr>
        <?php
        if (@$tukarpoin && @$dataretur==false) {
            $tukarpoin=@number_format($tukarpoin,0,',','.');
            ?>
            <tr>
                <td align="left" colspan="3">Tukar Poin (<?php echo '-'.@$kurangipoin ?>)</td>
                <td align="right"><?php echo $tukarpoin ?></td>
            </tr>
            <?php
        }
        ?>
        <?php
        if (@$tunai && @$dataretur==false) {
            $tunai=@number_format($tunai,0,',','.');
            ?>
            <tr>
                <td align="left" colspan="3">Bayar Tunai</td>
                <td align="right"><?php echo $tunai ?></td>
            </tr>
            <?php
        }
        ?>
        <?php
        if (@$non && @$dataretur==false) {
            $non=@number_format($non,0,',','.');
            ?>
            <tr>
                <td align="left" colspan="3">Bayar Non Tunai</td>
                <td align="right"><?php echo $non ?></td>
            </tr>
            <?php
        }
        ?>
        <?php
        if (@$cashout) {
            $cashout=@number_format($cashout,0,',','.');
            ?>
            <tr>
                <td align="left" colspan="3">Cashout</td>
                <td align="right"><?php echo $cashout ?></td>
            </tr>
            <?php
        }
        ?>
        <?php
        if (@$dataretur) {
            $totretur=number_format($totretur,0,',','.');
            ?>
            <!--<tr>
                <td align="left" colspan="3">Kembalian Retur</td>
                <td align="right"><?php echo $totretur ?></td>
            </tr>-->
            <?php
        } else {
            if (@$tukarkoin) {
                ?>
                <tr>
                    <td align="left" colspan="3">Simpanan Koin</td>
                    <td align="right"><?php echo $tukarkoin ?></td>
                </tr>
                <?php
            }
            if (@$piutang) {
                $nmkem='Kurang Bayar';
                $kembali=@number_format($piutang,0,',','.');
            } else {
                $nmkem='Kembali';
                $kembali=@number_format($kembali,0,',','.');
            }
            ?>
            <tr>
                <td align="left" colspan="3"><?php echo $nmkem ?></td>
                <td align="right"><?php echo $kembali ?></td>
            </tr>
            <?php
        }
        ?>
        <tr>
            <td colspan="4">&nbsp;</td>
        </tr>
        <?php
        if (@$kdmember) {
            ?>
            <tr>
                <td align="left">Poin</td>
                <td align="right" colspan="3"><?php echo $poin ?></td>
            </tr>
            <tr>
                <td align="left">Saldo Koin</td>
                <td align="right" colspan="3"><?php echo $koin ?></td>
            </tr>
            <?php
        }
        ?>
        </table>
        <br>
        <?php
        $footer = 'Terima kasih atas kunjungan anda';
        $starSpace = ( 32 - strlen($footer) ) / 2;
        $starFooter = str_repeat('*', $starSpace+1);
        echo($starFooter. '&nbsp;'.$footer . '&nbsp;'. $starFooter."<br/><br/><br/><br/>");
        echo '<p>&nbsp;</p>';
        ?>
</section>
<script>
var lama=1000;
t=null;
function printOut() {
    window.print();
    t=setTimeout("self.close()",lama);
}
</script>
</body>
</html>