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

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

$pagename = "Lap Penjualan";

$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[$user_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 Penjualan - <?php echo $_outlet_name[$user_outlet]?>
            <br>
            <?php echo iddate2($fdate)?> -  <?php echo iddate($tdate)?> 
            </td>
        </tr>
    	<tr class="bold">
        	<td style="width:30px;">No</td>
                	<td style="width:135px">No Nota</td>
                	<td style="width:135px">Tanggal</td>
                    <td>Nama Item</td>
                    <td class="tr">Harga Jual</td>
                    <td class="tr"style="width:120px">Qty</td>
                    <td class="tr">Subtotal</td>
	</tr>
	</thead>

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

  $sql = " SELECT * FROM posheader a, posdetail b WHERE a.pos_autoid = b.pos_autoid AND 
  			(a.pos_transdate BETWEEN '$fdate' AND '$tdate') AND a.outlet_autoid = '$outlet' $filter_query_2 ORDER BY a.pos_transdate";
  $dcon = $conn->query($sql) or die($sql); 
  while($rs = $dcon->fetch_assoc()){
		
	$subtotal = $rs['posd_qty'] * $rs['posd_price'];
?> 
	<tr>
                	<td><?php echo $i?></td>
                	<td><?php echo $rs['pos_transno']?></td>
                    <td><?php echo dtostr(substr($rs['pos_transdate'],0,10))?></td>
                    <td><?php echo $rs['pm_name']?></td>
                    <td class="tr"><?php echo number_format($rs['posd_price'])?></td>
                    <td class="tr"><?php echo $rs['posd_qty']?></td>

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

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

</html>