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

$pagename = "Lap Pembelian - Produk";

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

$pm_autoid = $_POST['pm_autoid'];



	
	$filter_q = "";
    foreach($pm_autoid as $value)
    {
		if($value){
			$txt = " c.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>
    <table class="table" width="1600" border="1" bordercolor="#CCCCCC" style="font-size:12px">
    <thead>
    	<tr class="bold">
        	<td colspan="9">
            Laporan Pembelian - Produk
            <br>
            <?php echo iddate2($fdate)?> -  <?php echo iddate($tdate)?> 
            </td>
        </tr>
    	<tr class="bold">
        	<td style="width:30px;">No</td>
            <td style="width:320px;">Nama Item</td>
            <td class="tr" style="width:80px">Harga</td>
            <td class="tr" style="width:80px">Qty</td>
            <td class="tr" style="width:120px">Subtotal</td>
	</tr>
	</thead>

<?php
$i = 1;
$gtotal_qty = 0;
$gtotal_amount = 0;

  $sql = " SELECT SUM(b.pod_qty) as qty, SUM(b.pod_price * b.pod_qty) as subtotal, c.pm_name, b.pod_price FROM poheader a, podetail b, mst_product c 
  			WHERE a.po_autoid = b.po_autoid AND  b.pm_autoid = c.pm_autoid AND
			(a.po_transdate BETWEEN '$fdate' AND '$tdate') AND a.po_status = 1 $filter_query GROUP BY c.pm_autoid ";
  $dcon = $conn->query($sql) or die($sql);
  
  while($rs = $dcon->fetch_assoc()){
		


?> 
	<tr>
    	<td><?php echo $i?></td>
        <td><?php echo $rs['pm_name']?></td>
        <td class="tr"><?php echo number_format($rs['pod_price'])?></td>
        <td class="tr"><?php echo number_format($rs['qty'],1)?></td>
        <td class="tr"><?php echo number_format($rs['subtotal'])?></td>
	</tr>
<?php 
$i = $i + 1;
$gtotal_qty 	= $gtotal_qty + $rs['qty'];
$gtotal_amount 	= $gtotal_amount + $rs['subtotal'];
} ?>
	<tr class="bold">
    	<td colspan="3" class="tr">Jumlah</td>
        <td class="tr"><?php echo $gtotal_qty?></td>

        <td class="tr"><?php echo number_format($gtotal_amount)?></td>
	</tr>
</table>
</div>
</body>

</html>