<!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)." )";
	}

$url = "index";
?>
<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 class="noprint">
<div class="tbprint">
        <input type="button" value="Print" class="btn btn-primary btn-sm" onclick="window.print()"/>
        <input type="button" value="Back" class="btn btn-danger btn-sm" onclick="window.location.href='index'"/>
</div>
<br>
<br>
<br>
</div>
<div>
    <table class="table" width="1600" border="1" bordercolor="#CCCCCC" style="font-size:12px">
    <thead>
    	<tr class="bold">
        	<td colspan="12">
            Laporan Penjualan - <?php echo $_outlet_name[$outlet]?>
            <br>
            <?php echo iddate2($fdate)?> -  <?php echo iddate($tdate)?> 
            </td>
        </tr>

<tr class="bold">
    <td style="width:150px">No Penjualan</td>
    <td style="width:120px">Tanggal</td>
    <td>Customer</td>
    <td class="tc">Nama Item</td>
    <td class="tc">Harga</td>
    <td class="tc">Qty</td>
    <td class="tc">Qty Pabrik</td>
    <td class="tc">Subtotal</td>
    <td class="tc">Retur</td>
    <td class="tc">Potongan</td>
    <td style="color:#990000" class="tc">Total Adj</td>
    <td class="tc">Nett</td>
</tr>
<?php
$gtotal = 0;
$gtotal_qtyp = 0;
$gtotal_rp = 0;

  $sql = " SELECT * FROM soheader a, sodetail b WHERE a.so_autoid = b.so_autoid AND
  			(a.so_transdate BETWEEN '$fdate' AND '$tdate') AND a.outlet_autoid = '$outlet' AND a.so_status = 2 $filter_query_2 ORDER BY a.so_autoid";
  $dcon = $conn->query($sql) or die($sql); 
  while($rs = $dcon->fetch_assoc()){
		$subtotal = $rs['sd_qtyp'] * $rs['sd_price'];
		$total_adj = ($rs['sd_qtyr'] * $rs['sd_price']) + $rs['sd_potongan'];
		$total_nett = $subtotal - $total_adj;
?> 
	<tr>
             <td><?php echo $rs['so_transno']?></td>
             <td><?php echo dtostr(substr($rs['so_transdate'],0,10))?></td>
             <td><?php echo $rs['cust_name']?></td>
             <td><?php echo $rs['pm_name']?></td>
             <td class="tr"><?php echo number_format($rs['sd_price'])?></td>
             <td class="tr"><?php echo number_format($rs['sd_qty'],2)?></td>
             <td class="tr"><?php echo number_format($rs['sd_qtyp'],2)?></td>
             <td class="tr bold"><?php echo number_format($subtotal)?></td>
             <td class="tr"><?php echo number_format($rs['sd_qtyr'],2)?></td>
             <td class="tr"><?php echo number_format($rs['sd_potongan'],2)?></td>
             <td style="color:#990000" class="tr"><?php echo number_format($total_adj)?></td>
             <td class="tr bold"><?php echo number_format($total_nett)?></td>
             
	</tr>
<?php 
$gtotal = $gtotal + $rs['sd_qty'];
$gtotal_qtyp = $gtotal_qtyp + $rs['sd_qtyp'];
$gtotal_rp = $gtotal_rp + $subtotal;

$gtotal_qtyr = $gtotal_qtyr + $rs['sd_qtyr'];
$gtotal_pot = $gtotal_pot + $rs['sd_potongan'];

$gtotal_adj = $gtotal_adj + $total_adj;

$gtotal_nett = $gtotal_nett + $total_nett;
} ?>
<tr class="bold" style="background-color:#AAFDBD">
	<td colspan="5" class="tr">TOTAL PENJUALAN <?php echo $_outlet_name[$outlet]?></td>
	<td class="tr"><?php echo number_format($gtotal,2)?> Kg</td>
	<td class="tr"><?php echo number_format($gtotal_qtyp,2)?> Kg</td>
    <td class="tr"><?php echo number_format($gtotal_rp)?></td>
    <td class="tr"><?php echo number_format($gtotal_qtyr,2)?></td>
    <td class="tr"><?php echo number_format($gtotal_pot)?></td>
    <td style="color:#990000" class="tr"><?php echo number_format($gtotal_adj)?></td>
    <td class="tr"><?php echo number_format($gtotal_nett)?></td>
</tr>
    
</table>
</div>
</body>

</html>