| Current Path : /var/www/html/mmishra/istore/ |
| Current File : /var/www/html/mmishra/istore/ststockin.inc |
<h3>Stockbook Entry</h3>
<center>
<?php
$tbl = "st_stockin";
$id = $_REQUEST["id"];
$challanbillno = $_REQUEST["challanbillno"];
$category = $_REQUEST["category"];
$subcategory = $_REQUEST["subcategory"];
$item = $_REQUEST["item"];
$dated = date("Y-m-d");
if ($_POST["submit"] == 'SAVE') {
$qtyin = $_POST["qty_in"];
$xqtyin = $_POST["xqty_in"];
$unit = $_POST["unit"];
$rate = $_POST["rate"];
if ($qtyin) {
if (mysql_num_rows(mysql_query("select * from $tbl where id=$id"))) {
mysql_query("update $tbl set challanBillNo='$challanbillno',qty_in=$qtyin,unit='$unit',rate=$rate
where id=$id");
//adjust qty in item table
mysql_query("update st_items set qty_in=qty_in-$xqtyin+$qtyin,loginID='$user' where id=$item");
} else {
mysql_query("insert into $tbl(challanBillNo,item,qty_in,unit,rate)
values('$challanbillno',$item,$qtyin,'$unit',$rate)");
//increase qty in item table
mysql_query("update st_items set qty_in=qty_in+$qtyin,loginID='$user' where id=$item");
}
}
}
if ($_POST["submit"] == 'DELETE') {
mysql_query("delete from $tbl where id=$id");
//reduce qty in item table
mysql_query("update st_items set qty_in=qty_in-$xqtyin,loginID='$user' where id=$item");
}
echo "<div align='left'>
Select challan/bill <select name='challanbillno' onchange=\"javascript: document.location.href='?pg=$pg&challanbillno='+this.value\">
<option value=''></option>";
$rs = mysql_query("select * from st_bills where challanNo>'' or billno>'' order by id desc limit 0,15");
while ($o = mysql_fetch_object($rs)) {
if ($o->billNo) {
echo "<option value='$o->billNo'";
if ($o->billNo == $challanbillno) echo " selected";
echo ">B-$o->billNo</option>";
} else if ($o->challanNo) {
echo "<option value='$o->challanNo'";
if ($o->challanNo == $challanbillno) echo " selected";
echo ">C-$o->challanNo</option>";
}
}
echo "</select>
category <select name='category' onchange=\"javascript: document.location.href='?pg=$pg&challanbillno=$challanbillno&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</option>";
}
echo "</select>
Subcategory <select name='subcategory' onchange=\"javascript: document.location.href='?pg=$pg&challanbillno=$challanbillno&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</option>";
}
echo "</select>
</div>";
if ($challanbillno) {
echo "<b>Current Receipt</b><br>
<table width='80%' border='1' style='border-collapse: collapse'>
<tr><th>No.</th><th>Particulars</th><th>Qty In</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'>
<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 colspan='6'><a href='?pg=$pg&challanbillno=$challanbillno&category=$category&subcategory=$subcategory'>New</a></td></tr>";
}
$rs = mysql_query("select * from $tbl where challanbillno='$challanbillno' order by datecreation 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&challanbillno=$challanbillno&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'>
<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->dateUpdation<input type='hidden' name='xqty_in' value='$o->qty_in'></td>
<tr><th colspan='4'><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 $o->unit</td><td>$o->rate</td><td nowrap>$o->dateCreation</td>";
}
echo "</tr>";
}
echo "<table>
<br><br>
<b>Recent 50 Receipts</b><br>";
//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 dateCreation desc limit 0,50");
if (mysql_num_rows($rs)) {
echo "<table width='80%' border='1' style='border-collapse: collapse'>
<tr><th>No.</th><th>Challan/Bill No.</th><th>Particulars</th><th>Qty In</th><th>Rate</th><th nowrap>Dated</th></tr>";
while ($o = mysql_fetch_object($rs)) {
$i++;
echo "<tr><td>$i</td><td>$o->challanBillNo</td><td>".item_detail($o->item)."</td><td>$o->qty_in $o->unit</td><td>$o->rate</td><td nowrap>$o->dateCreation</td></tr>";
}
echo "</table>";
} else {
echo "<h3>None</h3>";
}
}
?>
</center>