Your IP : 216.73.216.40


Current Path : /var/www/html/mmishra/istore/
Upload File :
Current File : /var/www/html/mmishra/istore/stmonthlyuse.inc

<h3>Monthly Outflow</h3>

<?php

$monthyear = $_REQUEST["monthyear"];

if (!$monthyear) $monthyear = date("Y-m");
$cal = explode("-", $monthyear);
$m = $cal[1];
$y = $cal[0];

echo "Select month <select name='monthyear' onchange=\"javascript: document.location.href='?pg=$pg&monthyear='+this.value\">
<option value=''></option>";

$rs = mysql_query("select distinct concat(year(dateUpdation),'-',month(dateUpdation)) as monthyear from st_stockout order by dateUpdation desc");
while ($o = mysql_fetch_object($rs)) {
	if (strlen($o->monthyear) == 6) $myear = str_replace("-","-0",$o->monthyear); 
	else $myear = $o->monthyear; 
	echo "<option value='$myear'";
	if ($myear == $monthyear) echo " selected";
	echo ">$myear</option>";
}
echo "</select> 
<center>";

$no = cal_days_in_month(CAL_GREGORIAN, $m, $y);
echo "<table border='1' width='90%'>
<tr><th rowspan='2'>Sr</th><th rowspan='2'>Dates =><br>Items v</th>
<th rowspan='2'>Opening</th><th colspan='$no'>Date-wise item outflow in the month $monthyear</th>
<th rowspan='2'>Out</th><th rowspan='2'>Closing</th></tr>
<tr>";
for ($i=1; $i <= $no; $i++) {
	echo "<th>".($i < 10 ? '0' : '')."$i</th>";
}
echo "</tr>";
$sl = 0;
$rs = mysql_query("select id,code,description from st_items order by code");
while ($o = mysql_fetch_object($rs)) {
	$z++;
	$item = $o->id;
	echo "<tr><td>$z</td><td>$o->code ($o->description)</td>";
	
	//opening stock of the month
    //total received qty in the previous months
	$sr = mysql_query("select sum(qty_in) as rq from st_stockin where item=$item and dateUpdation<'$monthyear-01' group by item");
    if (mysql_num_rows($sr)) {
		$q = mysql_fetch_object($sr);
		$rqty = $q->rq;
	} else 
		$rqty = 0;
	
	//total used qty in the previous months
	$sr = mysql_query("select sum(qty_out) as uq from st_stockout where item=$item and date(dateUpdation)<'$monthyear-01' group by item");
	if (mysql_num_rows($sr)) {
		$q = mysql_fetch_object($sr);
		$uqty = $q->uq;
	} else 
		$uqty = 0;
	
	//opening qty = total received - total used
	$oqty = $rqty - $uqty;
    echo "<td>$oqty</td>";

	//this month used qty
	$tot = 0;
	for ($i=1; $i <= $no; $i++) {
		$d = ($i<10 ? '0'.$i : $i);
		$sr = mysql_query("select sum(qty_out) as qout from st_stockout where item=$item and date(dateUpdation)='$monthyear-$d' group by item");
		echo '<td>';
		if (mysql_num_rows($sr)) {
			$q = mysql_fetch_object($sr);
			$iqty = $q->qout;
			$tot += $iqty;
			echo number_format($iqty, 0);
		} else {
			echo '';
		}
		echo '</td>';
	}
	//total qty used this month
	echo "<td>$tot</td>";

	//closing stock of the month
	//total received qty till the end of this month
    $sr = mysql_query("select sum(qty_in) as rq from st_stockin where item=$item and dateUpdation<='$monthyear-$no' group by item");
    if (mysql_num_rows($sr)) {
        $q = mysql_fetch_object($sr);
        $rqty = $q->rq;
    } else 
		$rqty = 0;
	
	//closing stock = total received - total used
	$cqty = $rqty - ($uqty + $tot);
	echo "<td>$cqty</td></tr>";
}
	
?>
</table>
</center>