<!DOCTYPE HTML>
<?php 
include('config.php');

$pagename = "Laporan Stok";

$fdate = dtosql($_POST['fdate']);
$tdate = dtosql($_POST['tdate']);
$itt_autoid = $_POST['itt_autoid'];

if($itt_autoid){
	$itt_filter = " AND a.itt_autoid = '$itt_autoid'";
	}
	
$pm_autoid = $_POST['pm_autoid'];



	
	$filter_q = "";
    foreach($pm_autoid as $value)
    {
		if($value){
			$txt = " b.pm_autoid = '$value' or";	
			$filter_q = $filter_q.$txt;
		}
		
    }


	if($filter_q){
		$filter_query = " AND ( ".substr_replace($filter_q ,"", -2)." )";
	}

?>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title><?php echo $pagename?></title>
    <?php include('../../common/script_css.php');?>

</head>
<body class="print_body">
<?php include('../../sys/navprint.php')?>
<div class="px-1">
    <table class="table" width="1600" border="1" bordercolor="#CCCCCC" style="font-size:12px">
    <thead>
    	<tr class="bold">
        	<td colspan="10">
            <?php echo $pagename?>
            <br>
            <?php echo iddate2($fdate)?> -  <?php echo iddate($tdate)?> 
            </td>
        </tr>
    	<tr class="bold">
        	<td style="width:30px;">No</td>
            <td style="width:220px;">Tipe Transaksi</td>
        	<td style="width:200px;">No Referensi</td>
        	<td style="width:100px;">Tanggal</td>            
            <td style="width:120px;">Kode Produk</td>
        	<td style="width:300px;">Nama Produk</td>
            <td class="tr" style="width:100px;">Harga</td>
            <td class="tr" style="width:100px;">Qty Masuk</td>
            <td class="tr" style="width:100px;">Qty Keluar</td>
 		   	<td class="tr" style="width:100px;">Jumlah</td>
	</tr>
	</thead>

<?php
$i = 1;
$total_in_qty = 0;
$total_out_qty = 0;

  $sql = " SELECT * FROM invlog a , mst_product b WHERE a.pm_autoid = b.pm_autoid 
  			AND (a.log_refdate BETWEEN '$fdate' AND '$tdate') $filter_query $itt_filter ORDER BY a.log_refdate";
  $dcon = $conn->query($sql) or die($sql);
  while($rs = $dcon->fetch_assoc()){
		

	$in_qty = $rs['log_inqty'];
	$out_qty = $rs['log_outqty'];
	$log_price = $rs['log_price'];
	$total = ($in_qty - $out_qty) * $log_price;
?> 
	<tr>
    	<td><?php echo $i?></td>
        <td><?php echo $rs['itt_desc']?></td>
        <td><?php echo $rs['log_refno']?></td>
        <td><?php echo dtostr($rs['log_refdate'])?></td>
        <td><?php echo $rs['pm_code']?></td>
        <td><?php echo $rs['pm_name']?></td>
        <td class="tr"><?php echo number_format($log_price,2)?></td>
        <td class="tr"><?php echo $in_qty?></td>
        <td class="tr"><?php echo $out_qty?></td>
        <td class="tr"><?php echo number_format($total,2)?></td>
	</tr>
<?php 
$i = $i + 1;
$total_in_qty = $total_in_qty + $in_qty;
$total_out_qty = $total_out_qty + $out_qty;
$stotal = $stotal + $total;

} ?>
	<tr class="bold">
    	<td class="tr" colspan="7">TOTAL</td>
        <td class="tr"><?php echo $total_in_qty?></td>
        <td class="tr"><?php echo $total_out_qty?></td>
	      <td class="tr"><?php echo number_format($stotal,2)?></td>
    </tr>
</table>
</div>
</body>

</html>