<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <meta name="robots" content="noindex, nofollow">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
    <meta name="description" content="Enambelasapp.my.id" />
    <meta name="author" content="Suroto" />
    <link rel="icon" type="image/png" href="<?php echo base_url('assets/') ?>/img/favicon.png"/>
    <!--[if IE]>
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <![endif]-->
    <title>Laporan Penjualan Transaksi</title>
    <link href="<?php echo base_url() ?>/assets/css/bootstrap.css" rel="stylesheet" />
    <link href="<?php echo base_url() ?>/assets/css/font-awesome.css" rel="stylesheet" />
    <link href="<?php echo base_url() ?>/assets/css/style.css" rel="stylesheet" />

</head>
<body>
    <div class="container">
        <div align="center" class="no-print" id="formFilter" style="background-color: #F5F5F5;padding: 4px">
          <form class="form-inline" action="" method="get">
            <input type="hidden" name="filter" id="filter" value="ok">
            <div class="col-md-12">
              <div class="form-group">
                  <label for="kdpromo">Jenis Promo : </label>
                    <select name="kdpromo" id="kdpromo" required>
                    <option height='35px' value="">Pilih Kode Promo</option>
                    <?php foreach ($kdpromo->result() as $key): ?>
                        <option height='35px' value="<?php echo $key->idprogram ?>"><?php echo $key->idprogram .' - '. $key->namapromo ?></option>
                    <?php endforeach?>
                </select>
			  </div>
			 
            <div class="form-group">
			  <label for="kedai">Kedai : </label>
					<select  name="kedai" id="kedai" class="form-control" required>
						<option height='35px' value="">Pilih Kedai</option>
						<option <?php {echo 'selected';}?> value="KDR01">Ngronggo</option>
						<option <?php {echo 'selected';}?> value="KDR02">Polim</option>
						<option <?php {echo 'selected';}?> value="KDR06">Penanggungan</option>
						<option <?php {echo 'selected';}?> value="KDR04">Gumul</option>
						<option <?php {echo 'selected';}?> value="KDR05">Pare</option>
						<option <?php {echo 'selected';}?> value="NJK01">Nganjuk</option>
						<option <?php {echo 'selected';}?> value="NJK02">Kertosono</option>
						<option <?php {echo 'selected';}?> value="NJK03">Warujayeng</option>
						<option <?php {echo 'selected';}?> value="BLT01">Blitar</option>
						<option <?php {echo 'selected';}?> value="JBG01">Jombang</option>
						<option <?php {echo 'selected';}?> value="JBG03">Djoetek</option>
						<option <?php {echo 'selected';}?> value="KNR01">Srengat</option>
						<option <?php {echo 'selected';}?> value="MJK01">Moker 1</option>
						<option <?php {echo 'selected';}?> value="MJK02">Moker 2</option>
						<option <?php {echo 'selected';}?> value="MJK03">Moker 3</option>
						<option <?php {echo 'selected';}?> value="MJK04">Pandan</option>
						<option <?php {echo 'selected';}?> value="MJK05">Mojosari</option>
						<option <?php {echo 'selected';}?> value="MLG01">Malang</option>
						<option <?php {echo 'selected';}?> value="SDR01">Sepanjang</option>
					</select>
			  </div>
			 </div> 
			  <div class="form-group">
                <label for="a">Tanggal : </label>
                <select name="a" id="a" class="form-control">
                <?php for ($i = 1; $i <= 31; $i++) {?>
                  <option <?php if ($i == $tgl) {echo 'selected';}?> value="<?php echo sprintf('%02d', $i) ?>"><?php echo sprintf('%02d', $i) ?></option>
                <?php }?>
                </select>
                <select name="b" id="b" class="form-control">
                <?php for ($i = 1; $i <= 12; $i++) {?>
                  <option <?php if ($i == $bln) {echo 'selected';}?> value="<?php echo sprintf('%02d', $i) ?>"><?php echo sprintf('%02d', $i) ?></option>
                <?php }?>
                </select>
                <select name="c" id="c" class="form-control">
                <?php for ($i = 2016; $i <= date('Y'); $i++) {?>
                  <option <?php if ($i == $thn) {echo 'selected';}?> value="<?php echo $i ?>"><?php echo $i ?></option>
                <?php }?>
                </select>
              </div>
              <div class="form-group">
                <label for="pwd"> s/d </label>
                <select name="d" id="d" class="form-control">
                    <?php for ($i = 1; $i <= 31; $i++) {?>
                    <option <?php if ($i == $tgl) {echo 'selected';}?> value="<?php echo sprintf('%02d', $i) ?>"><?php echo sprintf('%02d', $i) ?></option>
                    <?php }?>
                </select>
                <select name="e" id="e" class="form-control">
                <?php for ($i = 1; $i <= 12; $i++) {?>
                    <option <?php if ($i == $bln) {echo 'selected';}?> value="<?php echo sprintf('%02d', $i) ?>"><?php echo sprintf('%02d', $i) ?></option>
                <?php }?>
                </select>
                <select name="f" id="f" class="form-control">
                <?php for ($i = 2016; $i <= date('Y'); $i++) {?>
                  <option <?php if ($i == $thn) {echo 'selected';}?> value="<?php echo $i ?>"><?php echo $i ?></option>
                <?php }?>
                </select>
              </div>
              <button type="submit" class="btn btn-danger">Filter</button>
              <a href=""><button type="button" class="btn btn-success" onclick="window.print();return false;">Print</button></a>
              <a href="<?php echo base_url('dashboard/') ?>"><img height="30px" src="<?php echo base_url() ?>/assets/img/home.png" />Home</a>
          </form>
        </div>
            <h4 align="center">LAPORAN PENJUALAN TRANSAKSI</h4>
            <h5 align="center">CV.QTA</h5>
            <?php if ($filter): ?>
                <h5 align="center">TANGGAL : <?php echo date_indo($awal) . " s/d " . date_indo($akhir) ?></h5>
            <?php else: ?>
            <h5 align="center">TANGGAL : <?php echo date_indo($tanggal) ?></h5>
            <?php endif?>
            
            <?php if($jpromo=='2') { ?>
            <table id="tbStok" class="table table-bordered table-striped table-responsive">
              <thead>
                <tr>
                  <th>No</th>
                  <th>Nomor Faktur</th>
                  <th>Tanggal</th>
                  <th>Waktu</th>
                  <th>Kode</th>
                  <th>Menu</th>
                  <th>H.Reg</th>
                  <th>H.Promo</th>
                  <th>Diskon</th>
                  <th>Qty</th>
                  <th>Total</th>
                  <th>Aksi</th>
                </tr>
              </thead>
              <tbody>
                <?php foreach ($penjualan->result() as $key): ?>
                <tr>
                  <td align="center"><?php echo $no++ ?></td>
                  <td><?php echo $key->no_faktur_penjualan ?></td>
                  <td><?php echo $key->tgl_penjualan ?></td>
                  <td><?php echo $key->waktu ?></td>
                  <td><?php echo $key->kd_barang ?></td>
                  <td><?php echo $key->nm_barang ?></td>
                  <td align="right"><?php echo number_format($key->harga1, 0, ',', '.') ?></td>
                  <td align="right"><?php echo number_format($key->harga, 0, ',', '.') ?></td>
                  <td align="right"><?php echo number_format(($key->harga1-$key->harga), 0, ',', '.') ?></td>
                   <td align="right"><?php echo number_format(($key->jumlah-$key->qty), 0, ',', '.') ?></td>
                  <td align="right"><?php echo number_format((($key->harga1-$key->harga)*($key->jumlah-$key->qty)), 0, ',', '.') ?></td>
                  <td align="center" class="no-print"><a href="javascript:void(0);" class="lihat_record" title="Lihat Detail" data-faktur="<?php echo $key->no_faktur_penjualan ?>">Lihat</a></td>
                </tr>
<?php
$subtot += ($key->harga1-$key->harga);
$diskon += (($key->harga1-$key->harga)*($key->jumlah-$key->qty));
$grandtot += $key->total_penjualan_sdiskon;
$cash += ($key->jumlah-$key->qty);
$debet += $key->debet;
?>
                <?php endforeach?>
              </tbody>
                  <thead>
                    <tr>
                      <td colspan="8" align="center">Total</td>
                      <td align="right"><?php echo number_format($subtot, 0, ',', '.') ?></td>
                      <td align="right"><?php echo number_format($cash, 0, ',', '.') ?></td>
                      <td align="right"><?php echo number_format($diskon, 0, ',', '.') ?></td>
                      <td></td>
                    </tr>
                  </thead>
            </table>
        <?php   } else { ?>
        <table id="tbStok" class="table table-bordered table-striped table-responsive">
              <thead>
                <tr>
                  <th>No</th>
                  <th>Nomor Faktur</th>
                  <th>Tanggal</th>
                  <th>Waktu</th>
                  <th>Bruto</th>
                  <th>Pb1</th>
                  <th>Total</th>
                  <th>Disc</th>
                  <th>N.Disc</th>
                  <th>Netto</th>
                  <th>Aksi</th>
                </tr>
              </thead>
              <tbody>
                <?php foreach ($penjualan->result() as $key): ?>
                <tr>
                  <td align="center"><?php echo $no++ ?></td>
                  <td><?php echo $key->no_faktur_penjualan ?></td>
                  <td><?php echo $key->tgl_penjualan ?></td>
                  <td><?php echo $key->waktu ?></td>
                  <td align="right"><?php echo number_format($key->total_penjualan_sdiskon) ?></td>
                  <td align="right"><?php echo number_format($key->nppn) ?></td>
                  <td align="right"><?php echo number_format($key->total_penjualan_sdiskon+$key->nppn) ?></td>
                  <td align="right"><?php echo number_format($key->disc) ?></td>
                  <td align="right"><?php echo number_format($key->ndisc) ?></td>
                  <td align="right"><?php echo number_format($key->netto) ?></td>
                  <td align="center" class="no-print"><a href="javascript:void(0);" class="lihat_record" title="Lihat Detail" data-faktur="<?php echo $key->no_faktur_penjualan ?>">Lihat</a></td>
                </tr>
<?php
$subtot += ($key->total_penjualan_sdiskon);
$nppn += ($key->nppn);
$total += ($key->nppn+$key->total_penjualan_sdiskon);
$diskon += ($key->ndisc);
$grandtot += ($key->netto);

?>
                <?php endforeach?>
              </tbody>
                  <thead>
                    <tr>
                      <td colspan="4" align="center">Total</td>
                      <td align="right"><?php echo number_format($subtot) ?></td>
                      <td align="right"><?php echo number_format($nppn) ?></td>
                      <td align="right"><?php echo number_format($total) ?></td>
                      <td></td>
                      <td align="right"><?php echo number_format($diskon) ?></td>
                      <td align="right"><?php echo number_format($grandtot) ?></td>
                      <td></td>
                    </tr>
                  </thead>
            </table>
        <?php } ?>
</div>
 <script src="<?php echo base_url() ?>/assets/js/jquery-3.3.1.js"></script>
    <script src="<?php echo base_url() ?>/assets/js/jquery.dataTables.min.js"></script>
    <script src="<?php echo base_url() ?>/assets/js/dataTables.buttons.min.js"></script>
    <script src="<?php echo base_url() ?>/assets/js/buttons.flash.min.js"></script>
    <script src="<?php echo base_url() ?>/assets/js/jszip.min.js"></script>
    <script src="<?php echo base_url() ?>/assets/js/pdfmake.min.js"></script>
    <script src="<?php echo base_url() ?>/assets/js/vfs_fonts.js"></script>
    <script src="<?php echo base_url() ?>/assets/js/buttons.html5.min.js"></script>
    <script src="<?php echo base_url() ?>/assets/js/buttons.print.min.js"></script>
    <script src="<?php echo base_url() ?>/assets/js/bootstrap.js"></script>
    <script src="<?php echo base_url() ?>/assets/js/custom.js"></script>
    <script src="<?php echo base_url() ?>/assets/js/sweetalert.min.js"></script>
    <script src="<?php echo base_url() ?>/assets/js/toastr.min.js"></script>
    
    <script>
      $('#tbStok').DataTable({
          "paging":   false,
          "ordering": false,
          "info":     false,
          "searching":     false,
          "dom": 'Bfrtip',
          "buttons": [
            'copy', 'csv', 'pdf', 'print','excel'
        ]
      });
      $('form').attr('autocomplete', 'off');
      $("ul.nav li.dropdown").hover(function(){$(this).find(".dropdown-menu").stop(!0,!0).delay(100).fadeIn(500)},function(){$(this).find(".dropdown-menu").stop(!0,!0).delay(100).fadeOut(500)});
      var pesan="<?php echo $this->session->flashdata('msg'); ?>",error="<?php echo $this->session->flashdata('error'); ?>";pesan?(toastr.options={positionClass:"toast-top-right"},toastr.success(pesan)):error&&swal(error);
      
	function isNumber(evt) {
        evt = (evt) ? evt : window.event;
        var charCode = (evt.which) ? evt.which : evt.keyCode;
        if (charCode > 31 && (charCode < 48 || charCode > 57)) {
            return false;
        }
      return true;
    } 

	$("#jml").keypress(function(e){
        var kd_barang= $('#kbrg').val();
        if(e.which==13){
			document.getElementById('jml').focus();  
        }
    });
    
    </script>
    <script>
    $('#tbPenjualan').on('click','.lihat_record',function(){
        var faktur = $(this).data('faktur');
        var url = "<?php echo base_url('kasir/reprint_struk/') ?>"+faktur;
        window.open(url, '_blank', 'location=yes,height=400,width=500,scrollbars=yes,status=yes');
    });
    
    </script>
</body>
</html>