  
<?php 
$kdtoko = $this->session->userdata('kd_toko');
?>

  <div class="content-wrapper" style="margin-bottom: 20px">
    <div class="container">
      <div class="row pad-botm">
          <div  class="col-md-12">
		  <?php if ($kdtoko=='ZZZZZ') { ?>
				<form class="header-line" class="form-inline" action="<?php echo base_url('kasir/rekap1/') ?>" method="post">
					<tr>
						<td>Kedai</td>
						<td>:</td>
						<td>
							<select  name="kedai" id="kedai" required>
								<option height='45px' 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="BLT01">Blitar</option>
								<option <?php {echo 'selected';}?> value="KNR01">Srengat</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="JBG01">Jombang</option>
								<option <?php {echo 'selected';}?> value="JBG03">Djoetek</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>
						</td>
					<td>Dari Tgl</td>
					<td>:</td>			
					<td><input name='utgl' id='utgl' type='date' VALUE='<?php echo date("Y-m-d") ?>' ></input></td>
					<td>Smp Tgl</td>
					<td>:</td>			
					<td><input name='stgl' id='stgl' type='date' VALUE='<?php echo date("Y-m-d") ?>' ></input></td>
					<button  class="btn" type="submit" ><font color='blue' ><b>GO</b></font></button>
					
					</tr>
				</form>	
		  <?php } else { ?>
		  <form class="header-line" class="form-inline" action="<?php echo base_url('kasir/rekap/') ?>" method="post">
					<tr>
					<td>Tanggal</td>
					<td>:</td>			
					<td><input name='utgl' id='utgl' type='date' VALUE='<?php echo date("Y-m-d") ?>' ></input></td>
					<button  class="btn" type="submit" ><font color='blue' ><b>GO</b></font></button>
					</tr>
				</form>	
		  <?php } ?>	
			<!-- <h5 >REKAP <?php echo date_indo($tanggal) ?> <span class="pull-right"><a id="btnRekap" class="btn btn-danger" href="<?php echo base_url('kasir/cetak-rekap1') ?>">Cetak Rekap</a></span></h5>	-->
          </div>
      </div>
	 
       <div class="row">
        <div class="col-md-12">
            <h4><strong>Penjualan </strong><span class="pull-right"><a id="btnRekap" class="btn btn-danger" href="<?php echo base_url('kasir/cetak-rekap1' ) ?>">Cetak Rekap</a></span></h4> 
            <table id="tbPenjualan" class="table table-bordered table-striped table-responsive">
              <thead>
                <tr>
                  <th>No</th>
                  <th>Nomor Faktur</th>
				  <th>Tanggal</th>
                  <th>Waktu</th>
                  <th>Total</th>
                  <th>Diskon</th>
				  <th>PPn</th>
				  <th>Ongkir</th>
                  <th>Netto</th>
                  <th>Reguler</th>
				  <th>Reg. DO</th>
				  <th>Reg. TA</th>
				  <th>Gofood</th>
                  <th>Grabfood</th>
				  <th>Shopeefood</th>
                  <th>Kedai</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, 0, ',', '.') ?></td>
                  <td align="right"><?php echo number_format($key->diskon, 0, ',', '.') ?></td>
				  <td align="right"><?php echo number_format($key->nppn, 0, ',', '.') ?></td>
				  <td align="right"><?php echo number_format($key->ongkir, 0, ',', '.') ?></td>
                  <td align="right"><?php echo number_format($key->total_penjualan_sdiskon, 0, ',', '.') ?></td>
                  <td align="right"><?php echo number_format($key->reg, 0, ',', '.') ?></td>
                  <td align="right"><?php echo number_format($key->regdo, 0, ',', '.') ?></td>
				  <td align="right"><?php echo number_format($key->regta, 0, ',', '.') ?></td>
				  <td align="right"><?php echo number_format($key->gofood, 0, ',', '.') ?></td>
				  <td align="right"><?php echo number_format($key->grab, 0, ',', '.') ?></td>
				  <td align="right"><?php echo number_format($key->shopee, 0, ',', '.') ?></td>
                  <td><?php echo $key->kdcabang ?></td>
				  
				  <?php if($kdtoko=='ZZZZZ') { ?>
				  <td align="center"><a href="javascript:void(0);" class="lihat_record" title="Lihat Detail" data-faktur="<?php echo $key->no_faktur_penjualan ?>">Detail</a></td>		
                  </td>
				  <?php } else { ?>
                  <td>
						<form target="printstruk" id="formCetakStruk" class="form-inline" action="<?php echo base_url('kasir/cetak-struk/') ?>" onsubmit="window.location('about:blank','printstruk','width=500,height=400');" method="post">
							<input type="hidden" name="sum_print" id="sum_print" value="<?php echo $key->total_penjualan_sdiskon ?>">
							<input type="hidden" name="diskon_print" id="diskon_print" value="<?php echo $key->diskon ?>">
							<input type="hidden" name="nofak_print" id="nofak_print" value="<?php echo $key->no_faktur_penjualan ?>">
							<input type="hidden" name="debet_print" id="debet_print" value="0">
							<input type="hidden" name="bank_print" id="bank_print">
							<button onclick="newTransaksi();" type="submit" id="btnCetakStruk" class="btn btn-primary" style="width:75px;height:25px; text-align: center;" >PRINT</button>
						</form>
									
                  </td>
				  <?php } ?>
                </tr>
<?php
$subtot += $key->total_penjualan;
$diskon += $key->diskon;
$grandtot += $key->total_penjualan_sdiskon;
$ongkir += $key->ongkir;
$rg += $key->reg;
$rgdo += $key->regdo;
$rgta += $key->regta;
$gofood += $key->gofood;
$grab += $key->grab;
$shopee += $key->shopee;
$nppn += $key->nppn;
?>
                <?php endforeach?>
              </tbody>
                  <thead>
                    <tr>
						<td colspan="4" align="center">Total Penjualan</td>
						<td align="right"><?php echo number_format($subtot, 0, ',', '.') ?></td>
						<td align="right"><?php echo number_format($diskon, 0, ',', '.') ?></td>
						<td align="right"><?php echo number_format($nppn, 0, ',', '.') ?></td>
						<td align="right"><?php echo number_format($ongkir, 0, ',', '.') ?></td>
						<td align="right"><?php echo number_format($grandtot, 0, ',', '.') ?></td>
						<td align="right"><?php echo number_format($rg, 0, ',', '.') ?></td>
						<td align="right"><?php echo number_format($rgdo, 0, ',', '.') ?></td>
						<td align="right"><?php echo number_format($rgta, 0, ',', '.') ?></td>
						<td align="right"><?php echo number_format($gofood, 0, ',', '.') ?></td>
						<td align="right"><?php echo number_format($grab, 0, ',', '.') ?></td>
						<td align="right"><?php echo number_format($shopee, 0, ',', '.') ?></td>
                        <td></td>
                        <td></td>
                      <td></td>
                    </tr>
                  </thead>
            </table>
            <h4><strong>Pengeluaran</strong></h4>
            <table id="tbPengeluaran" class="table table-bordered table-striped table-responsive">
              <thead>
                <tr>
                  <th>No</th>
                  <th>User</th>
                  <th>Jenis</th>
                  <th>Keterangan</th>
                  <th>Biaya</th>
                </tr>
              </thead>
              <tbody>
                <?php foreach ($pengeluaran->result() as $key): ?>
                <tr>
                  <td align="center"><?php echo $noo++ ?></td>
                  <td><?php echo $key->id_user ?></td>
                  <td><?php echo $key->jenis ?></td>
                  <td><?php echo $key->ket ?></td>
                  <td align="right"><?php echo number_format($key->biaya, 0, ',', '.') ?></td>
                </tr>
<?php
$tot_biaya += $key->biaya;
?>
                <?php endforeach?>
              </tbody>
                  <thead>
                    <tr>
                      <td colspan="4" align="center">Total</td>
                      <td align="right"><?php echo number_format($tot_biaya, 0, ',', '.') ?></td>
                    </tr>
                  </thead>
            </table>
        </div>
      </div>
    </div>
  </div>
     <!-- CONTENT-WRAPPER SECTION END-->
    <section class="footer-section">
        <div class="container">
            <div class="row">
                <div class="col-md-12">
                   &copy; Copyright <?php echo date('Y') ?>, <a href="enambelasapp.my.id" target="_blank">Mandiri</a>
                </div>
            </div>
        </div>
    </section>
    <!-- FOOTER SECTION END-->
    <!-- JAVASCRIPT FILES PLACED AT THE BOTTOM TO REDUCE THE LOADING TIME  -->
    <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/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>
      $('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);
      
      $('#btnCetakStruk').on('click',function(e){
            var belanja = $('#sum_belanja').val();
            var cash = $('#cash_print').val();
            var debet = $('#debet_print').val();
            var kembali = (Number(cash)+Number(debet))-Number(belanja);
           
              $('#formCetakStruk').submit(function() {
                    window.open('about:blank','printstruk','width=500,height=400');
                    this.target = 'printstruk';
                   ;
                    
              });
        });
 
      
    $('#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');
    });
    $("#btnRekap").on('click', function(e){
      e.preventDefault();
      var url = $(this).attr('href');
      window.open(url, '_blank', 'location=yes,height=600,width=500,scrollbars=yes,status=yes');
    });

    </script>

</body>
</html>