<!DOCTYPE html>

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

	
	if ($_SESSION['nama'] == ''){
		header('Location:index.php');
	}
	else{
?>
<html>
<?php
	include "updatestok2.php";
?>
  <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>
            STOCK MOVEMENT
            <small>Data Pergerakan Stock</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">Stock Movement</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">
				  
				  <?php
					$dt = strtotime('today GMT');
					$tglawal = $_GET['tglawal'];
					$tglakhir = $_GET['tglakhir'];
						
					if ($tglawal == ""){
						$tglawal = date('Y-m-d', strtotime('first day of this month', $dt));
					}
					
					if ($tglakhir == ""){
						$tglakhir = date('Y-m-d', strtotime('last day of this month', $dt)); 
					}
					
					$saldo = mysql_result(mysql_query("select sum(qty) from qqtmpproduk where tax = 'Tax' and billdate < '$tglawal' and produk = $_GET[id]"),0);
					
					$saldo2 = format_rupiah($saldo);
					
					$produk = mysql_result(mysql_query("select produk from produk where id = $_GET[id]"),0);
					echo"$produk <br> Saldo Awal : $saldo2";
					
					echo"<br><br>
						<form method=POST action='aksicust.php?module=movement&act=tax&id=$_GET[id]'>
								<table>
									<tr>
										<td>
												<div class='input-group'>
													<i class='fa fa-calendar'> From </i> <input value = '$tglawal' name ='awal' type = 'date'>
												</div>
										</td>
										<td> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
										</td>
										<td>
												<div class='input-group'>
													<i class='fa fa-calendar'> To</i> <input value = '$tglakhir' name='akhir' type = 'date'>
												</div>
										</td>
										<td>
												<div class='input-group'>
													<button type='submit'> GO </button></form>
												</div>
										</td>
									</tr>
								</table>";
				  ?>
				  </h3>
				  <br><br>
				  
                </div><!-- /.box-header -->
                <div class="box-body">
                  <table id="example1" class="table table-bordered table-striped">
                    <thead>
                      <tr>
                        <th>Tgl</th>
                        <th>Ref</th>
						<th>Harga Jual</th>
						<th>Masuk</th>
						<th>Keluar</th>
						<th>Stok</th>
                      </tr>
                    </thead>
                    <tbody>
					<?php

						$cek = mysql_query("Select * from  qqtmpproduk where   tax = 'Tax' and (billdate >= '$tglawal' and billdate <= '$tglakhir') and produk = $_GET[id] order by dateadded asc");
						while ($r=mysql_fetch_array($cek)){	
							//$cust = $r['pk'];
							$tgl =  tgl_ind($r['dateadded']) ;
							
							if ($r['jenis'] == "KeluarTax" || $r['jenis'] == "Retur JualTax"){
								$jual = format_rupiah($r['harga']);
							}else{
								$jual = "";
							}
							
							if ($r['qty'] < 0 ){
								$masuk = "";
								$keluar = $r['qty'] * -1;
							}else{
								$masuk = format_rupiah($r['qty']);
								$keluar = "";
							}
							
							$qty = $r['qty'];
							$saldo = $saldo + $qty;
							echo "<tr>
									<td> $tgl </td>
									<td> $r[jenis] # $r[billno]  -  $r[custname]</td>
									<td> $jual </td>
									<td> $masuk </td>
									<td> $keluar </td>
									<td> $saldo </td>
								  </tr>";
						}
					?>
                        
                     
                    </tbody>
                    <tfoot>
                      <tr>
                        <th>Tgl</th>
                        <th>Ref</th>
						<th>Harga Jual</th>
						<th>Masuk</th>
						<th>Keluar</th>
						<th>Stok</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 () {
        $("#example2").DataTable();
        $('#example1').DataTable({
          "paging": true,
          "lengthChange": false,
          "searching": false,
          "ordering": false,
          "info": true,
          "autoWidth": false
        });
      });
    </script>
  </body>
</html>
<?php 
	}
?>