Your IP : 216.73.216.40


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

<h3>Stock Receipt</h3>
<center>

<?php
$tbl = "st_stockin";

$id = $_REQUEST["id"];
$billno = $_REQUEST["bill_no"];
$category = $_REQUEST["category"];
$subcategory = $_REQUEST["subcategory"];
$item = $_REQUEST["item"];
$dated = date("Y-m-d");

/*
if (!$category) {
        $sr = mysql_query("select * from st_items where id=$id");
  	if (mysql_num_rows($sr)) {
		$q = mysql_fetch_object($sr);
               	$category = $q->category;
               	$subcategory = $q->subcategory;
        }
}
*/

if ($_POST["submit"] == 'SAVE') {
	$qtyin = $_POST["qty_in"];
	$xqtyin = $_POST["xqty_in"];
	$unit = $_POST["unit"];
	$rate = $_POST["rate"];

	if (mysql_num_rows(mysql_query("select * from $tbl where id=$id"))) {
		mysql_query("update $tbl set bill_no='$billno',qty_in=$qtyin,unit='$unit',rate=$rate,dated=now() 
		where id=$id");
		//adjust qty in category table
		mysql_query("update st_category set qty_in=qty_in-$xqtyin+$qtyin where id=$category");
		//adjust qty in subcategory table
		mysql_query("update st_subcategory set qty_in=qty_in-$xqtyin+$qtyin where id=$subcategory");
		//adjust qty in item table
		mysql_query("update st_items set qty_in=qty_in-$xqtyin+$qtyin where id=$item");
	} else {
                mysql_query("insert into $tbl(bill_no,item,qty_in,unit,rate,dated) 
		values('$billno',$item,$qtyin,'$unit',$rate,now())");
		//increase qty in category table
		mysql_query("update st_category set qty_in=qty_in+$qtyin where id=$category");
		//increase qty in subcategory table
		mysql_query("update st_subcategory set qty_in=qty_in+$qtyin where id=$subcategory");
		//increase qty in item table
		mysql_query("update st_items set qty_in=qty_in+$qtyin where id=$item");
	}
}

if ($_POST["submit"] == 'DELETE') {
	mysql_query("delete from $tbl where id=$id");
	//reduce qty in category table
	mysql_query("update st_category set qty_in=qty_in-$xqtyin where id=$category");
	//reduce qty in subcategory table
	mysql_query("update st_subcategory set qty_in=qty_in-$xqtyin where id=$subcategory");
	//decude qty in item table
	mysql_query("update st_items set qty_in=qty_in-$xqtyin where id=$item");
}

echo "<div align='left'>
Select bill No. <select name='bill_no' onchange=\"javascript: document.location.href='?pg=$pg&bill_no='+this.value\">
<option value=''></option>";

$rs = mysql_query("select * from st_bills order by id desc limit 0,15");
while ($o = mysql_fetch_object($rs)) {
        echo "<option value='$o->bill_no'";
        if ($o->bill_no == $billno) echo " selected";
        echo ">$o->bill_no</option>";
}
echo "</select>
<br>
Select category	<select name='category' onchange=\"javascript: document.location.href='?pg=$pg&bill_no=$billno&category='+this.value\">
<option value=''>Category</option>";

$rs = mysql_query("select * from st_category order by code");
while ($o = mysql_fetch_object($rs)) {
	echo "<option value='$o->id'";
	if ($o->id == $category) echo " selected";
	echo ">$o->code ($o->qty_in/$o->qty_out)</option>";
}
echo "</select> 
	
Subcategory <select name='subcategory' onchange=\"javascript: document.location.href='?pg=$pg&bill_no=$billno&category=$category&subcategory='+this.value\">
<option value=''>Subcategory</option>";

$rs = mysql_query("select * from st_subcategory where category=$category order by code");
while ($o = mysql_fetch_object($rs)) {
       	echo "<option value='$o->id'";
       	if ($o->id == $subcategory) echo " selected";
       	echo ">$o->code ($o->qty_in/$o->qty_out)</option>";
}
echo "</select> 
			
</div>";


if ($billno) {
	echo "<table width='60%' border='1' style='border-collapse: collapse'>
	<tr><th>No.</th><th>Item</th><th>Qty.</th><th>Unit</th><th>Rate</th><th nowrap>Dated</th></tr>";

	if (!$id) {
		echo "<tr><td>New</td>
		<td><select name='item'>
		<option value=''></option>";

		$rs = mysql_query("select * from st_items where category=$category and subcategory=$subcategory order by code");
		while ($o = mysql_fetch_object($rs)) {
       			echo "<option value='$o->id'";
       			if ($o->id == $item) echo " selected";
       			echo ">$o->code ($o->qty_in/$o->qty_out)</option>";
		}
		echo "</select></td>
		<td><input type='text' name='qty_in' size='5' value='0'></td>
		<td><select name='unit'>";
                foreach ($units as $qu) {
                        echo "<option value='$qu'>$qu</option>";
                }
                echo "</select></td>
     		<td><input type='text' name='rate' size='5' value='0'></td><td>$dated</td></tr>
		<tr><th colspan='5'><input type='submit' name='submit' value='SAVE'></th></tr>";
	} else {
		echo "<tr><td>New</td><td colspan='5'><a href='?pg=$pg&bill_no=$billno&category=$category&subcategory=$subcategory'>Item</a></td></tr>";
	}
	
	$rs = mysql_query("select * from $tbl where bill_no='$billno' order by dated desc");
	while ($o = mysql_fetch_object($rs)) {
		$i++;        
        	//get category and subcategory
		$sr = mysql_query("select * from st_items where id=$o->item");
	  	if (mysql_num_rows($sr)) {
			$q = mysql_fetch_object($sr);
               		$category = $q->category;
	               	$subcategory = $q->subcategory;
        	}
       		
		echo "<tr><td><a name='$i' href='?pg=$pg&bill_no=$billno&category=$category&subcategory=$subcategory&item=$o->item&id=$o->id#$i'>$i</a></td>";
		if ($o->id == $id) {
        		echo "<td><select name='item'>
			<option value=''></option>";

        	        $sr = mysql_query("select * from st_items where category=$category and subcategory=$subcategory order by code");
                	while ($q = mysql_fetch_object($sr)) {
                        	echo "<option value='$q->id'";
                        	if ($q->id == $item) echo " selected";
                        	echo ">$q->code ($q->qty_in/$q->qty_out)</option>";
                	}
                	echo "</select></td>
        		<td><input type='text' name='qty_in' size='5' value='$o->qty_in'></td>
			<td><select name='unit'>";
                	foreach ($units as $qu) {
                        	echo "<option value='$qu'".($o->unit == $qu ? ' selected' : '').">$qu</option>";
                	}
                	echo "</select></td>
   			<td><input type='text' name='rate' size='5' value='$o->rate'></td>
			<td>$o->dated<input type='hidden' name='xqty_in' value='$o->qty_in'></td>
			<tr><th colspan='5'><input type='submit' name='submit' value='SAVE'></th>
			<th><input type='submit' name='submit' value='DELETE'>
			<input type='hidden' name='id' value='$o->id'></th></tr>";
        	} else {
			echo "<td>".item_detail($o->item)."</td><td>$o->qty_in</td><td>$o->unit</td><td>$o->rate</td><td nowrap>$o->dated</td>";
		}
		echo "</tr>";
	}
	echo "<table>

	<h3>Previous Receipts</h3>
	<table width='67%' border='1' style='border-collapse: collapse'>
	<tr><th>No.</th><th>Bill No.</th><th>Item</th><th>Qty.</th><th>Unit</th><th>Rate</th><th nowrap>Dated</th></tr>";

	//items received under previous bills
	$rs = mysql_query("select * from $tbl where item in (select id from st_items where category=$category and subcategory=$subcategory) order by dated desc");
        while ($o = mysql_fetch_object($rs)) {
                $i++;
                echo "<tr><td>$i</td><td>$o->bill_no</td><td>".item_detail($o->item)."</td><td>$o->qty_in</td><td>$o->unit</td><td>$o->rate</td><td nowrap>$o->dated</td></tr>";
        }
	echo "</table>";
}
?>
</center>