<!DOCTYPE html>
<?php 
	session_start();
	@ob_start();
	include "../../config/koneksi.php";
	include "../../config/fungsi_rupiah.php";
	include "../../config/fungsi_indotgl.php";

?>
<html>
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>GATRATANI | Invoice</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    
    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
        <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>
  <body onload="window.print();">
    <div class="wrapper">
      <!-- Main content -->
      <section class="invoice">
        <!-- title row -->
        
        <!-- info row -->
        <div class="row invoice-info">
			<div class="col-xs-12">
			  <h2 class="page-header">
				<i class="fa fa-shopping-cart" ></i> KARTU STOK
			  </h2>
			</div><!-- /.col -->
			
			 <div class="col-sm-12 ">
			<?php
			  $produk = $_GET['produk'];
			  $awal  = $_GET['awal'];
			  $akhir = $_GET['akhir'];
			  $saldo = $_GET['saldo'];
			  $namaproduk = mysql_result(mysql_query("select produk from produk where id = $produk"),0);
			  
			  $tawal  = tgl_ind($awal);
			  $takhir = tgl_ind($akhir);
			  
			  $saldo2 = format_rupiah($saldo);
				
				echo "<table style='width:100%'>
						<tr>
							<td width='15%'>Tanggal </td>
							<td width='2%'>: </td>
							<td width='83%'> $tawal s/d $takhir</td>
						</tr>
						<tr>
							<td>Produk </td>
							<td>: </td>
							<td> $namaproduk</td>
						</tr>
						<tr>
							<td>Saldo Awal </td>
							<td>: </td>
							<td> $saldo2</td>
						</tr>

					  </table>
				";
			
			
			  ?>
            </div><!-- /.col -->
        </div><!-- /.row -->

        <!-- Table row -->
        <div class="row">
          <div class="col-xs-12 table-responsive">
            <table style="width:100%">
              <thead>
                <tr>
                    <th height=20px>Nota</th>
                    <th align='center'>Tanggal</th>
					<th align='center'>Keterangan</th>
                    <th align='center'>Masuk</th>
					<th align='center'>Keluar</th>
                    <th align='center' >Saldo</th>
                </tr>
              </thead>
             <tbody>
				<?php
				$i = 0;
				$cek = mysql_query("Select * from qqtmpproduk  where (billdate >= '$awal' and billdate <= '$akhir') and produk = $produk order by dateadded asc");
				while ($r=mysql_fetch_array($cek)){	
					if ($r['jenis'] == "Keluar" || $r['jenis'] == "Retur Jual" ){
						$nota = "AA".substr($r['billdate'],2,2).substr($r['billdate'],5,2)." ".str_pad($r['billno'], 4, "0", STR_PAD_LEFT);	
					}else{
						$nota = "EE".substr($r['billdate'],2,2).substr($r['billdate'],5,2)." ".str_pad($r['billno'], 4, "0", STR_PAD_LEFT);
					}
					
					$tgl =  tgl_ind($r['dateadded']) ;
					$ket=$r['custname'];
					if ($r['qty'] < 0 ){
						$masuk = "";
						$keluar = format_rupiah($r['qty'] * -1);
					}else{
						$masuk = format_rupiah($r['qty']);
						$keluar = "";
					}
					
					$qty = $r['qty'];
					$saldo = $saldo + $qty;
					
					$saldo2 = format_rupiah($saldo);
							
					echo"
					  <tr>
						<td height=10px width='15%' align = center>$nota</td>
						<td width='15%'>$tgl</td>
						<td width='35%' align = left>$ket</td>
						<td width='10%' align=right>$masuk</td>
						<td width='10%' align = right>$keluar</td>
						<td width='15%' align=right>$saldo2</td>
					  </tr>";
				}
				
				
				
				?>
             </tbody>
            </table>
          </div><!-- /.col -->
        </div><!-- /.row --> 
<hr align="center" color="black">
        <div class="row">
          <!-- accepted payments column -->
          <div>
			<div class="table-responsive">
                <table  style="width:100%">
               

				 
                </table>
            </div>
          </div><!-- /.col -->
         
        </div><!-- /.row -->
      </section><!-- /.content -->
    </div><!-- ./wrapper -->

    <!-- AdminLTE App -->
	<style>

    body {
      font-family:Courier New;
	  font-weight: bold;
	  font-size:12px;
    }
	th {
		border-top: 1px solid black;
		border-bottom: 1px solid black;
	}
    </style>
    <script src="../../dist/js/app.min.js"></script>
  </body>
</html>
