<?php if($lihat){?>
<?php
$q=mysqli_query($connect, "SELECT a.*,b.nama_toko,c.user_nama FROM `transaksi` a, `toko` b, `users` c WHERE b.ID=a.ID_toko and c.ID=a.ID_user and a.hapus='0' and a.id_ ='$lihat'") or die(mysqli_error($connect));
$b=mysqli_fetch_array($q);
$q_kasir=mysqli_query($connect, "select nama from karyawan where ID='$b[ID_karyawan]' and ID_user='$b[ID_user]'");
if(mysqli_num_rows($q_kasir)){
	$kasir=mysqli_fetch_array($q_kasir);
}else{
	$q_user=mysqli_query($connect, "select user_nama from users where ID='$b[ID_user]'");
	$kasir=mysqli_fetch_array($q_user);
}
$status = ($b['status']==1)?'<span class="label bg-blue">sale</span>':'<span class="label bg-orange">void</span>';
$ppn = ($b['pajak']==1)?'<span class="label bg-orange">yes</span>':'<span class="label bg-grey">no</span>';
$no_trx='<span title="ID - '.$b['nama_toko'].'">'.$b['ID_toko'].'</span>-<span title="No Struk">'.$b['no_struk'].'</span>';	
?>
<div class="row clearfix">
  <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
    <div class="card">
      <div class="header">
        <h2>VIEW DETAIL TRANSACTION <?php echo $status;?> <span class="label bg-blue-grey"><?php echo $no_trx;?></span> <span title="User"><?php echo $b['user_nama'];?></span></h2>
      </div>
      <div class="body">
	  	<div class="row">
			<div class="col-xs-6">
				 <div class="form-group">
            <label>Store Name</label>
            <div class="form-line">
              <?php echo $b['nama_toko'];?>
            </div>
          </div>
		   <div class="form-group">
            <label>Operator</label>
            <div class="form-line">
              <?php echo $kasir[0];?>
            </div>
          </div>
           <div class="form-group">
            <label>Date Transaction</label>
            <div class="form-line">
              <?php echo $b['waktu'];?>
            </div>
          </div>
         <div class="form-group">
            <label>TAX(10%)</label>
            <div class="form-line">
              <?php echo $ppn;?><br>
            </div>
          </div>
		  <div class="form-group">
            <label>Status</label>
            <div class="form-line">
              <?php echo $status;?><br>
            </div>
          </div>
			</div>
			<div class="col-xs-6">
				 <div class="form-group">
            <label>Subtotal</label>
            <div class="form-line">
              <?php echo number_format($b['subtotal'],0,',','.');?>
            </div>
          </div>
		   <div class="form-group">
            <label>Discount</label>
            <div class="form-line">
              <?php echo $b['diskon'];?>%
            </div>
          </div>
           <div class="form-group">
            <label>GrandTotal</label>
            <div class="form-line">
              <?php echo number_format($b['grandtotal'],0,',','.');?>
            </div>
          </div>
         <div class="form-group">
            <label>Pay</label>
            <div class="form-line">
               <?php echo number_format($b['bayar'],0,',','.');?>
            </div>
          </div>
		   <div class="form-group">
            <label>Back</label>
            <div class="form-line">
               <?php echo number_format($b['kembali'],0,',','.');?>
            </div>
          </div>
			</div>
		</div>
		<div class="row">
			<div class="col-xs-12">
			<table class="ms table table-bordered table-striped table-hover">
            <thead>
              <tr>
                <th>#</th>
                <th>Item</th>
				<th>Qty</th>
                <th>Total</th>
              </tr>
            </thead>
            <tbody>
				<?php
					$i=0;
					$qk=mysqli_query($connect, "select * from transaksi_detail a, produk b where a.ID_produk=b.ID and a.ID_transaksi='$b[id_]'") or die(mysqli_error($connect));
					while($bk=mysqli_fetch_array($qk)){
						$i++;
				?>
					<tr>
						<td align="center"><?php echo $i;?></td>
						<td><?php echo $bk['nama_produk'];?></td>
						<td align="right"><?php echo $bk['qty'];?></td>
						<td align="right"><?php echo number_format($bk['total'],0,',','.');?></td>
					</tr>
				
				<?php } ?>
            </tbody>
          </table>
			</div>
		</div>
        <div class="form-group">
          <button type="button" class="btn btn-sm bg-blue-grey waves-effect back">Back</button>
        </div>
      </div>
    </div>
  </div>
</div>
<?php }else{?>
<div class="row clearfix">
  <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
    <div class="card">
      <div class="header">
        <h2>DATA TRANSACTION</h2>
      </div>
      <div class="body">
      	<table class="table table-bordered table-striped table-hover dataTable js-exportable">
            <thead>
              <tr>
                <th>#</th>
                <th>User</th>
                <th>Store</th>
				<th>Operator</th>
                <th>Invoice</th>
                <th>Status</th>
                <th>Qty</th>
				<th>Subtotal</th>
				<th>Discount</th>
				<th>TAX</th>
				<th>Total</th>
				<th>Date</th>
                <th>Action</th>
              </tr>
            </thead>
            <tbody>
            </tbody>
          </table>
      </div>
    </div>
  </div>
</div>
<?php } ?>
<script type="text/javascript">
$( document ).ready(function() {
$('.dataTable').DataTable({
		 "bSort":false,
		 "bProcessing": true,
         "serverSide": true,
         "ajax":{
            url :"<?php echo getConfig($connect, 'base_url');?>processData.php",
            type: "post",
			data:{p:'<?php echo $page;?>'},
            error: function(a,e,t){
				swal({
					title: "Something Wrong!",
					text: formatErrorMessage(a,e),
					type: "error",
					showCancelButton: !1,
					closeOnConfirm: !0
				}, function() {
					if(a.responseText){
						$("#hasil").html(a.responseText);
					}else{
						$("#hasil").html("Error : "+formatErrorMessage(a,e));
					}
				});
              	$("table").css("display","none");
            },
			complete: function(a,e,t){
				noClick2();
				initAjax(true);
			}
          },
		 responsive: !1,
		 width:'100%',
		 "autoWidth": false,
		 columnDefs: [
		 	{"targets": 0,"className": "text-center"},
			{"targets": 3,"className": "text-center"},
			{"targets": 4,"className": "text-center"},
			{"targets": 8,"className": "text-center"},
			{"targets": 5,"className": "text-right"},
			{"targets": 6,"className": "text-right"},
			{"targets": 7,"className": "text-right"},
			{"targets": 9,"className": "text-right"},
			{"targets": 10,"className": "text-center"},
			{"targets": 12,"className": "text-center","width":"100","style":"nowrap","searchable": false}
			 ]
        }); 
});
</script>