| Current Path : /var/www/html/mmishra/iws8/html/istore/ |
| Current File : /var/www/html/mmishra/iws8/html/istore/inindents.inc.mm |
<h2 align='left'>Indent Form</h2>
<?php
$tbl = 'indents';
$id = $_REQUEST["id"];
$indentno = $_REQUEST["indent_no"];
$indentdate = $_POST['indent_date'];
$purpose = $_POST['purpose'];
$employee = $_POST['employee'];
$recommendation = $_POST['recommendation'];
$category = $_REQUEST["category"];
$subcategory = $_REQUEST["subcategory"];
$item = $_POST["item"];
$qtydemand = $_POST['qty_demand'];
$qtyout = $_POST['qty_out'];
$approxcost = $_POST['approx_cost'];
if ($_POST["submit"] == 'SAVE') {
foreach ($items as $item) {
if (mysql_num_rows(mysql_query("select * from $tbl where indent_no=$indentno"))) {
mysql_query("update $tbl set indent_date='$indentdate',purpose='$purpose',
employee='$employee',recommendation='$recommendation',dated=now()
where indent_no=$indentno");
} else {
mysql_query("insert into $tbl(indent_date,purpose,employee,recommendation,dated)
values('$indentdate','$purpose','$employee','$recommendation',now())");
$indentno = mysql_insert_id();
}
//item entry
if (mysql_num_rows(mysql_query("select * from indent_items where id=$id"))) {
mysql_query("update indent_items(item_no=$item,qty_demand=$qtydemand,
qty_out=$qtyout,approx_cost=$approxcost,dated=now()
where id=$id");
} else {
mysql_query("insert into indent_items(indent_no,item,qty_demand,qty_out,approx_cost,dated)
values($indentno,$item,$qtydemand,$qtyout,$approxcost,now())");
}
}
} else if ($_POST["submit"] == 'DELETE') {
mysql_query("delete from indent_items where id=$id");
}
echo "<center>
<table width='50%'><tr><th>".($indentno ? "<a href='?pg=$pg'>New</a>" : '')."
Indent No. <input type='text' name='indent_no' size='10' value='$indentno'>
<input type='submit' name='submit' value='FIND'></th></tr>
</table>";
$rs = mysql_query("select * from $tbl where indent_no=$indentno");
while ($o = mysql_fetch_object($rs)) {
$indent_date = $o->indent_date;
$purpose = $o->purpose;
$employee = $o->employee;
$recommendation = $o->recommendation;
$status = $o->status;
}
if (!$indent_date) $indent_date = date("Y-m-d");
if (!$status) $status = 'Pending';
echo "<table width='80%' border='1' style='border-collapse: collapse'>
<tr><td>Purpose</td><td><input type='text' name='purpose' size='50' value='$purpose'></td>
<td width='10%'>Indent Date</td><td><input type='text' name='indent_date' size='10' value='$indent_date'></td></tr>
<tr><td width='10%'>Employee</td><td width='60%'>".employee_list($employee)."</td>
<td>Recommendation</td><td><input type='text' name='recommendation' size='30' value='$recommendation'></td></tr>
</table>";
if ($indentno) {
//item list
echo "<table width='100%' border='1' style='border-collapse: collapse'>
<tr><th>No.</th><th nowrap>Indent Item</th><th>Qty Demand</th><th>Qty Out</th><th>Approx Cost</th></tr>";
echo "<tr>";
if (!$id) {
echo "<td>New</td>
<td><select name='category' onchange=\"javascript: document.location.href='?pg=$pg&indent_no=$indentno&category='+this.value\">
<option value=''></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>
<select name='subcategory' onchange=\"javascript: document.location.href='?pg=$pg&indent_no=$indentno&category=$category&subcategory='+this.value\">
<option value=''></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>
<select name='item'>
<option value=''></option>";
$item = 0;
$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_demand' size='5' value='1'></td>
<td><input type='text' name='qty_out' size='5' value='0'></td>
<td><input type='text' name='approx_cost' size='10' value='0'></td>";
} else {
$rs = mysql_query("select * from st_items where id=(select item from indent_items where id=$id)");
while ($o = mysql_fetch_object($rs)) {
$category = $o->category;
$subcategory = $o->subcategory;
$item = $o->id;
}
echo "<td colspan='5'><a href='?pg=$pg&indent_no=$indentno&category=$category&subcategory=$subcategory'>+</a></td>";
}
echo "</tr>";
$sr = mysql_query("select * from indent_items where indent_no=$indentno order by item");
while ($q = mysql_fetch_object($sr)) {
$j++;
echo "<tr>";
if ($id == $q->id) {
echo "<td>$j</td>
<td><select name='category' onchange=\"javascript: document.location.href='?pg=$pg&indent_no=$indentno&category='+this.value\">
<option value=''></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>
<select name='subcategory' onchange=\"javascript: document.location.href='?pg=$pg&indent_no=$indentno&category=$category&subcategory='+this.value\">
<option value=''></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>
<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>
<input type='hidden' name='id' value='$q->id'></td>
<td><input type='text' name='qty_demand' size='5' value='$q->qty_demand'></td>
<td><input type='text' name='qty_out' size='5' value='$q->qty_out'></td>
<td><input type='text' name='approx_cost' size='10' value='$q->approx_cost'></td>";
} else {
echo "<td><a href='?pg=$pg&indent_no=$indentno&id=$q->id'>$j</a></td><td>".item_detail($q->item)."</td>
<td>$q->qty_demand</td><td>$q->qty_out</td><td>$q->approx_cost</td>";
}
echo "</tr>";
}
if ($status == 'Pending') {
echo "<tr><th colspan='5'><input type='submit' name='submit' value='SAVE'>".
($id ? "<input type='submit' name='submit' value='DELETE'>" : '')."</th></tr>";
}
echo "</table>
Status: $status";
}
?>
</center>