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

$pagename = "Laporan Stok";

$tahun = $_POST['tahun'];
$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 = " 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="14">
            Pemakaian Barang
            <br>
            <?php echo ($tahun)?>
            </td>
        </tr>
    	<tr class="bold">
        	<td style="width:30px;">No</td>
            <td style="width:220px;">Nama Item</td>
			<td class="tc">Jan</td>
            <td class="tc">Feb</td>
            <td class="tc">Mar</td>
            <td class="tc">Apr</td>
            <td class="tc">Mei</td>
            <td class="tc">Jun</td>
            <td class="tc">Jul</td>
            <td class="tc">Aug</td>
            <td class="tc">Sep</td>
            <td class="tc">Okt</td>
            <td class="tc">Nov</td>
            <td class="tc">Des</td>
	</tr>
	</thead>

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

  $sql = " SELECT * FROM mst_product WHERE 1 $filter_query ORDER BY pm_name";
  $dcon = $conn->query($sql) or die($sql);
  while($rs = $dcon->fetch_assoc()){
		
	$pm_autoid = $rs['pm_autoid'];
?> 
	<tr>
    	<td><?php echo $i?></td>
        <td><?php echo $rs['pm_name']?></td>
		<?php 
		for($n=1;$n<=12;$n++){
			
		$sqln = "SELECT SUM(log_outqty) as qty FROM invlog where month(log_refdate) = $n AND year(log_refdate) = '$tahun' AND pm_autoid = '$pm_autoid' AND itt_autoid = 32 ";
	  	$dconn = $conn->query($sqln) or die($sqln);
		$rsn = $dconn->fetch_assoc();		
		$out_qty = $rsn['qty'];
		?>
        <td class="tr"><?php echo number_format($out_qty)?></td>
        <?php } ?>
	</tr>
<?php 
$i = $i + 1;


} ?>
</table>
</div>
</body>

</html>