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

$outlet 	= $_POST['outlet'];
$pm_autoid 		= $_POST['pm_autoid'];

$pagename = "Lap Pembelian";

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




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


	if($filter_q_2){
		$filter_query_2 = " AND ( ".substr_replace($filter_q_2 ,"", -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?> - <?php echo $_outlet_name[$outlet]?></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="8">
            Laporan Pembelian - <?php echo $_outlet_name[$outlet]?>
            <br>
            <?php echo iddate2($fdate)?> -  <?php echo iddate($tdate)?> 
            </td>
        </tr>

<tr class="bold">
    <td>No Pembelian</td>
    <td>Tanggal</td>
	<td>Supplier</td>
	<td>No Anggota</td>
	<td>Nama Item</td>
	<td class="tr">Harga Beli</td>
	<td class="tr">Qty</td>
    <td class="tr">Subtotal</td>
 
</tr>
<?php
$total_all = 0;


  $sql = " SELECT SUM(b.prd_qty) as total_qty, SUM(b.prd_qty * b.prd_price) as total_price, a.supp_name, a.member_regno FROM prheader a , prdetail b WHERE  a.pr_autoid = b.pr_autoid AND
  			(a.pr_transdate BETWEEN '$fdate' AND '$tdate') AND a.outlet_autoid = '$outlet' AND a.pr_status = 2 and a.member_regno <> ''  group by a.member_regno order by SUM(b.prd_qty * b.prd_price) desc";
  $dcon = $conn->query($sql) or die($sql); 
  while($rs = $dcon->fetch_assoc()){
		

	
	
	$subtotal = ($rs['prd_qty']  * $rs['prd_price']);
?> 
	<tr>
             <td><?php echo $rs['pr_transno']?></td>
             <td><?php echo dtostr(substr($rs['pr_transdate'],0,10))?></td>
			<td><?php echo $rs['supp_name']?></td>
			<td><?php echo $rs['member_regno']?></td>
			 <td class="tl"><?php echo $rs['pm_name']?></td>
			 <td class="tr"><?php echo number_format($rs['total_qty'])?></td>
             <td class="tr"><?php echo number_format($rs['total_price'],2)?></td>
			 <td class="tr"><?php echo number_format($subtotal)?></td>
	</tr>
<?php 
$gtotal = $gtotal + $subtotal;
$total_qty = $total_qty + $rs['prd_qty'];
} ?>
<tr class="bold" style="background-color:#AAFDBD">
	<td colspan="6" class="tr">TOTAL PEMBELIAN <?php echo $_outlet_name[$outlet]?></td>
	<td class="tr"><?php echo number_format($total_qty,2)?></td>
	<td class="tr"><?php echo number_format($gtotal)?></td>
</tr>
    
</table>
</div>
</body>

</html>