| Current Path : /var/www/html/mmishra/iws8/html/ilight/ |
| Current File : /var/www/html/mmishra/iws8/html/ilight/stutilization.inc |
<h3>Stock Utilization</h3>
<center>
<?php
$tbl = "st_stockout";
$ids = $_REQUEST["id"];
$complaintno = $_REQUEST["complaint_no"];
$category = $_REQUEST["category"];
$subcategory = $_REQUEST["subcategory"];
$item = $_REQUEST["item"];
$qtyout = $_POST["qty_out"];
if (!$qtyout) $qtyout = 1;
$unit = $_POST["unit"];
$xqtyout = $_POST["xqty_out"];
$dated = date("Y-m-d");
if ($_POST["submit"] == 'SAVE') {
//utilization entry
if (mysql_num_rows(mysql_query("select * from $tbl where id=$id"))) {
mysql_query("update $tbl set qty_out=$qtyout,unit='$unit',dated=now()
where id=$id");
//adjust qty in category table
mysql_query("update st_category set qty_out=qty_out-$xqtyout+$qtyout where id=$category");
//adjust qty in subcategory table
mysql_query("update st_subcategory set qty_out=qty_out-$xqtyout+$qtyout where id=$subcategory");
//adjust qty in item table
mysql_query("update st_items set qty_out=qty_out-$xqtyout+$qtyout where id=$item");
} else {
mysql_query("insert into $tbl(complaint_no,item,qty_out,unit,dated)
values($complaintno,$item,$qtyout,'$unit',now())");
//increase qty in category table
mysql_query("update st_category set qty_out=qty_out+$qtyout where id=$category");
//increase qty in subcategory table
mysql_query("update st_subcategory set qty_out=qty_out+$qtyout where id=$subcategory");
//increase qty in item table
mysql_query("update st_items set qty_out=qty_out+$qtyout where id=$item");
}
//send email to indentor
$rs = mysql_query("select * from employees where emp_no=(select employee from st_complaints where complaint_no=$complaintno)");
if (mysql_num_rows($rs)) {
$o = mysql_fetch_object($rs);
$empname = $o->emp_name;
$email = $o->email;
//$email = 'mmishra@iiita.ac.in';
}
$str = "Dear Indentor ($empname)
<br><br>
With reference to your Indent No. $complaintno, following items have been issued in your name recently from the central store. This is for your information and record pl.
<br><br>
".indent_issued($complaintno);
if ($email) automailer($email, "Complaint Attended/Resolved", $str);
}
echo "Select Complaint No. <select name='complaint_no' onchange=\"javascript: document.location.href='?pg=$pg&complaint_no='+this.value\">
<option value=''></option>";
$rs = mysql_query("select * from st_complaints where status='Progress' order by complaint_no");
if (mysql_num_rows($rs)) {
while ($o = mysql_fetch_object($rs)) {
echo "<option value='$o->complaint_no'";
if ($o->complaint_no == $complaintno) {
echo " selected";
$complaintdate = $o->complaint_date;
$employee = $o->employee;
$problem = $o->problem;
$location = $o->location;
$technician = technician_detail($o->technician);
$status = $o->status;
}
echo ">$o->complaint_no ($o->employee => $o->location)</option>";
}
} else {
echo "<option value=''>No any complaint under progress</option>";
}
echo "</select><br><br>";
if ($complaintno) {
//item list
echo "<table width='90%' border='1' style='border-collapse: collapse'>
<tr><th colspan='5'><h3 style='color:red'>[ Problem: $problem ]<br>
[ User: ".employee_detail($employee).", Location: $location ]<br>
[ Dated: $complaintdate, Technician: $technician, Status: $status ]</h3>
Items utilized in resolving the above complaint</th></tr>
<tr><th>No</th><th nowrap>Item Description</th><th>Qty</th><th>Status</th><th>Dated</th></tr>";
if ($status == 'Progress') {
//add new item
echo "<tr><td>+</td>";
if (!$id) {
echo "<td><select name='category' onchange=\"javascript: document.location.href='?pg=$pg&complaint_no=$complaintno&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 ">$o->code</option>";
}
echo "</select>
<select name='subcategory' onchange=\"javascript: document.location.href='?pg=$pg&complaint_no=$complaintno&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 ">$o->code</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></td>
<td><input type='text' name='qty_out' size='5' value='$qtyout'>
<select name='unit'>";
foreach ($units as $ut) {
echo "<option value='$ut'".($ut==$unit ? ' selected' : '').">$ut</option>";
}
echo "</select></td>
<td><select name='status'>";
foreach ($ostatuss as $st) {
echo "<option value='$st'>$st</option>";
}
echo "</select></td><td>".date("Y-m-d")."</td></tr>
<tr><th>Add</th><td colspan='4'><input type='text' name='itemadd' value='' size='50'>
Select category, subcategory of item from above list and type item name here, if it is not listed above.</td></tr>";
} else {
echo "<td colspan='4'><a href='?pg=$pg&complaint_no=$complaintno&id='>item</a></td>";
}
echo "</tr>";
$sr = mysql_query("select * from st_stockout where complaint_no=$complaintno order by item");
while ($q = mysql_fetch_object($sr)) {
$j++;
echo "<tr>";
if ($id == $q->id) {
//find category and subcategory of the item
$ps = mysql_query("select * from st_items where id=$q->item");
if (mysql_num_rows($ps)) {
$p = mysql_fetch_object($ps);
$category = $p->category;
$subcategory = $p->subcategory;
}
//list dropdown box for selection of item
echo "<td>$j</td>
<td><select name='category' onchange=\"javascript: document.location.href='?pg=$pg&complaint_no=$complaintno&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 ">$o->code</option>";
}
echo "</select>
<select name='subcategory' onchange=\"javascript: document.location.href='?pg=$pg&complaint_no=$complaintno&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 ">$o->code</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 == $q->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_out' size='5' value='$q->qty_out'>
<select name='unit'>";
foreach ($units as $ut) {
echo "<option value='$ut'".($ut==$q->unit ? ' selected' : '').">$ut</option>";
}
echo "</select></td>
<td><select name='status'>";
foreach ($ostatuss as $st) {
echo "<option value='$st'".($q->status == $st ? ' selected' : '') .">$st</option>";
}
echo "</select></td>";
} else {
echo "<td><a href='?pg=$pg&complaint_no=$complaintno&id=$q->id'>$j</a></td><td>".item_detail($q->item)."</td>
<td>$q->qty_out $o->unit</td><td>$q->status</td>";
}
echo "<td>$q->dated</td></tr>";
}
echo "<tr><th colspan='4'><input type='submit' name='submit' value='SAVE'></th><th>";
if ($id) echo "<input type='submit' name='submit' value='DELETE'>";
echo "</th></tr>";
} else {
echo "<tr><th colspan='5'>Current status of this complaint is '$status'. For utilization of an item, complaint must be under 'Progress'.</th><th>";
}
}
?>
</table>
</center>