<?php 
include('config.php');

$fdate 			= dtosql($_POST['fdate']);
$tdate 			= dtosql($_POST['tdate']);
$pm 			= $_POST['pm'];
$outlet_id 		= $_POST['outlet_id'];
$ums 			= $_POST['ums'];
$ums 			= "";

$sql_st = "SELECT SUM(log_inqty-log_outqty) as stokawal 
			FROM invlog where pm_autoid = '$pm' 
			 AND log_refdate < '$fdate' AND outlet_id = '$outlet_id'";
$st_conn = $conn->query($sql_st);
$stok = $st_conn->fetch_assoc();

$stokawal = $stok['stokawal'];
$xstokawal = $stokawal;

$sql = "SELECT * FROM invlog WHERE 
					pm_autoid = '$pm' 
				AND 
					outlet_id = '$outlet_id' 
				AND 
					(log_refdate BETWEEN '$fdate' AND '$tdate')
				AND 
					outlet_id = '$outlet_id'
				ORDER BY log_refdate , log_autoid";
$dcon = $conn->query($sql) or die($sql);

$sqldesc = "SELECT * FROM invtranstype";
$desc_con = $conn->query($sqldesc) or die($sqldesc);
while($x = $desc_con->fetch_assoc()){
	$xid = $x['itt_autoid'];
	$xtipedesc[$xid] = $x['itt_desc'];
	}
?>


<table class="tbl-input">
<tr class="bold">
	<td style="width:100px;">Tanggal</td>
    <td style="width:180px;">No Referensi</td>
    <td>Tipe Transaksi</td>
    <td class="tr">Stok Awal</td>
    <td class="tr">Stok Masuk</td>
    <td class="tr">Stok Keluar</td>
    <td class="tr">Stok Akhir</td>
</tr>
<?php while($rs = $dcon->fetch_assoc()){ 

$tipe 		= $rs['log_refmod'];
$inqty 		= $rs['log_inqty'];
$outqty 	= $rs['log_outqty'];
$stokakhir 	= $inqty - $outqty;




$tipedesc = $rs['itt_desc'];	


$stokakhir = ($stokawal + $inqty) - $outqty;

?>
<tr>
	<td><?php echo dtostr($rs['log_refdate'])?></td>
    <td><?php echo $rs['log_refno']?></td>
    <td><?php echo $tipedesc?></td>
    <td class="tr"><?php echo number_format($stokawal)?></td>
    <td class="tr color_blue"><?php echo number_format($inqty)?></td>
    <td class="tr color_red"><?php echo number_format($outqty)?></td>
    <td class="tr color_green bold"><?php echo number_format($stokakhir)?></td>
</tr>
<?php 
	$stokawal = $stokakhir;
	$tstokawal = $stokawal;
	$tinqty = $tinqty + $inqty;
	$toutqty = $toutqty + $outqty;
	$tstokakhir = $stokakhir;
} 
$tstokakhir = $xstokawal + ($tinqty - $toutqty);
?>
<tr style="background-color:#FFFFCC" class="bold">
	<td colspan="3" class="tr">TOTAL</td>
    <td class="tr"><?php echo number_format($xstokawal)?></td>
    <td class="tr color_blue"><?php echo number_format($tinqty)?></td>
    <td class="tr color_red"><?php echo number_format($toutqty)?></td>
    <td class="tr color_green"><?php echo number_format($tstokakhir)?></td>
</tr>

</table>