<!DOCTYPE html>

<?php 
	session_start();
	@ob_start();
	include "../../config/koneksi.php";
	include "../../config/fungsi_rupiah.php";
	include "../head.php";

	
	if ($_SESSION['nama'] == ''){
		header('Location:index.php');
	}
	else{
?>
<html>

  <body class="hold-transition skin-blue sidebar-mini layout-boxed">
    <div class="wrapper">
		<?php include "../header.php";?>
      
		<?php include "../menu.php";?>
      

      <!-- Content Wrapper. Contains page content -->
      <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
          <h1>
            Product Data exc Nol Stock
            <small>Data Product</small>
          </h1>
          <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
            <li><a href="#">Product</a></li>
            <li class="active">Product Data</li>
          </ol>
        </section>

        <!-- Main content -->
        <section class="content">
          <div class="row">
            <div class="col-xs-12">
              
              <div class="box">
                <div class="box-header">
                  <h3 class="box-title">List Product exc Nol Stock</h3><br><br>
				  <a href="add.php" class="btn btn-sm btn-info btn-flat pull-left">Product Baru</a> <br><br>
				  
                </div><!-- /.box-header -->
                <div class="box-body">
                  <table id="example1" class="table table-bordered table-striped">
                    <thead>
                      <tr>
                        <th>Product</th>
        
						<th>Stock</th>
						<th>Harga Jual</th>
						<th></th>
                      </tr>
                    </thead>
                    <tbody>
					<?php
						//$cek = mysql_query("Select * from  produk where del <> 'Y' order by produk asc");
						$cek = mysql_query("SELECT produk,sum(qty) as stok FROM qqtmpproduk where produk not in (select id from produk where del = 'Y') group by produk union all select id ,0 from produk where del = 'N' and id not in (SELECT produk FROM qqtmpproduk group by produk)");
						//$cek = mysql_query("Select produk.id as id, produk.produk as produk ,produk.category as category,produk.unit_rp as unit_rp,sum(IFNULL(stok, 0) + IFNULL(stoktax,0)) as stok from  produk left join  qprodukall on  qprodukall.id = produk.id where produk.del <> 'Y' group by produk.id, produk.produk,produk.category,produk.unit_rp");
						while ($r=mysql_fetch_array($cek)){	
							$cust = $r['produk'];
							$produk = mysql_result(mysql_query("select produk from produk where id = $r[produk]"),0);
							$cat = mysql_result(mysql_query("select category from categories where pk = (select category from produk where id = $r[produk] )"),0);
							//$stok2 = mysql_result(mysql_query("Select sum(qty) from  qqtmpproduk where produk = $cust"),0);
							$stok = format_rupiah($r['stok']);
							
							$jual = format_rupiah(mysql_result(mysql_query("select unit_rp from produk where id = $r[produk]"),0));
							
							if ($r['stok'] > 0){
							
								echo "<tr>
										<td>$produk </td>
							
										<td>$stok</td>
										<td>$jual</td>
										<td><a href='edit.php?id=$cust'><span class='label label-success'>Edit</span></a><a href='aksicust.php?id=$cust&module=cust&act=delete''><span class='label label-danger'>Delete</span></a>  </td>
									  </tr>";
							}
						}
					?>
                        
                     
                    </tbody>
                    <tfoot>
                      <tr>
                        <th>Product</th>
        
						<th>Stock</th>
						<th>Harga Jual</th>
                        <th></th>
                      </tr>
                    </tfoot>
                  </table>
                </div><!-- /.box-body -->
              </div><!-- /.box -->
            </div><!-- /.col -->
          </div><!-- /.row -->
        </section><!-- /.content -->
      </div><!-- /.content-wrapper -->
		<?php include "../footer.php";?>
		

      <!-- Control Sidebar -->
      <aside class="control-sidebar control-sidebar-dark">

        <!-- Tab panes -->
        <div class="tab-content">
          <!-- Home tab content -->
          <div class="tab-pane" id="control-sidebar-home-tab">

          </div><!-- /.tab-pane -->

        </div>
      </aside><!-- /.control-sidebar -->
      <!-- Add the sidebar's background. This div must be placed
           immediately after the control sidebar -->
      <div class="control-sidebar-bg"></div>
    </div><!-- ./wrapper -->

    <!-- jQuery 2.1.4 -->
    <script src="../../plugins/jQuery/jQuery-2.1.4.min.js"></script>
    <!-- Bootstrap 3.3.5 -->
    <script src="../../bootstrap/js/bootstrap.min.js"></script>
    <!-- DataTables -->
    <script src="../../plugins/datatables/jquery.dataTables.min.js"></script>
    <script src="../../plugins/datatables/dataTables.bootstrap.min.js"></script>
    <!-- SlimScroll -->
    <script src="../../plugins/slimScroll/jquery.slimscroll.min.js"></script>
    <!-- FastClick -->
    <script src="../../plugins/fastclick/fastclick.min.js"></script>
    <!-- AdminLTE App -->
    <script src="../../dist/js/app.min.js"></script>
    <!-- AdminLTE for demo purposes -->
    <script src="../../dist/js/demo.js"></script>
    <!-- page script -->
    <script>
      $(function () {
        $("#example1").DataTable();
        $('#example2').DataTable({
          "paging": true,
          "lengthChange": false,
          "searching": false,
          "ordering": true,
          "info": true,
          "autoWidth": false
        });
      });
    </script>
  </body>
</html>
<?php 
	}
?>