Your IP : 216.73.216.40


Current Path : /var/www/html/mmishra/iws8/html/ilight/
Upload File :
Current File : /var/www/html/mmishra/iws8/html/ilight/stcomplaints.inc.old

<h2 align='left'>User Complaint</h2>

<?php

$tbl = 'st_complaints';

$id = $_REQUEST["id"];
$complaintno = $_REQUEST["complaint_no"];
$complaintdate = $_POST['complaint_date'];
if (!$complaintdate) $complaintdate = date("Y-m-d");
$problem = $_POST['problem'];
$employee = $_POST['employee'];
$location = $_POST['location'];
$technician = $_POST['technician'];
$category = $_REQUEST["category"];
$subcategory = $_REQUEST["subcategory"];
$item = $_POST["item"];
$itemadd = $_POST["itemadd"];
$qtyout = $_POST['qty_out'];
if (!$qtyout) $qtyout = 0;
$qtyin = $_POST['qty_in'];
if (!$qtyin) $qtyin = 0;
$status = $_REQUEST['status'];
if (!$status) $status = 'Pending';

if ($_POST["submit"] == 'SAVE') {
	if (mysql_num_rows(mysql_query("select * from $tbl where complaint_no=$complaintno"))) {
		//update existing indent
		mysql_query("update $tbl set complaint_date='$complaintdate',problem='$problem',
		employee='$employee',location='$location',technician='$technician',status='$status',dated=now()
		where complaint_no=$complaintno");
	} else {
		//insert new indent
		mysql_query("insert into $tbl(complaint_date,problem,employee,location,technician,status,dated)
		values('$complaintdate','$problem','$employee','$location','$technician','Pending',now())");
		$complaintno = mysql_insert_id();
	}

	if (!$id && $itemadd) {
        	//store new item in the item master
		mysql_query("insert into $st_items(code,description,subcategory,category,dated) 
		values('$code','New item added from complaint form',$subcategory,$category,now())");
		$id = mysql_insert_id();
	}

	//item entry	
	if (mysql_num_rows(mysql_query("select * from st_useditems where id=$id"))) {
		//update existing items of indent
		mysql_query("update st_useditems set complaint_no=$complaint_no,item=$item,qty_out=$qtyout,qty_in=$$qtyin,dated=now()
		where id=$id");
	} else if ($item) {
		//insert new items of indent
		mysql_query("insert into st_useditems(complaint_no,item,qty_out,qty_in,dated)
		values($complaintno,$item,$qtyout,$qtyin,now())");
	}
} else if ($_POST["submit"] == 'DELETE') {
	if ($id) {
		//delete item record
		mysql_query("delete from st_useditems where id=$id");
		$id = 0;
	} else {
		//delete items first and then delete indent
		mysql_query("delete from st_useditems where complaint_no=$complaintno");
		mysql_query("delete from $tbl where complaint_no=$complaintno");
		$complaintno = 0;
	}
} else if ($_REQUEST["revive"] == 'Yes') {
	mysql_query("update $tbl set status='Pending' where complaint_no=$complaintno");

} else if ($_POST["submit"] == 'FIND') {
	$id = 0; $item = 0; $category = 0; $subcategory = 0;
}

if (!$item) {
        $rs = mysql_query("select * from st_items where id=(select item from st_useditems where id=$id)");
        while ($o = mysql_fetch_object($rs)) {
                $item = $o->id;
                $category = $o->category;
                $subcategory = $o->subcategory;
        }
}

$rs = mysql_query("select * from $tbl where complaint_no=$complaintno");
if (mysql_num_rows($rs)) {
	$o = mysql_fetch_object($rs);
        $complaintdate = $o->complaint_date;
        $problem = $o->problem;
        $employee = $o->employee;
        $location = $o->location;
        $technician = $o->technician;
        $status = $o->status;
} else {
	$err = "<font color='red'>Complaint No. does not exist.</font>";
}

echo "<center>
<table width='50%'>
<tr><th>".($complaintno ? "[ <a href='?pg=$pg'>New</a> ] " : '')."
Complaint No. <input type='text' name='complaint_no' size='10' value='$complaintno'>
<input type='submit' name='submit' value='FIND'> ".
($status == 'Cancelled' ? "[ <a href='?pg=$pg&revive=Yes&complaint_no=$complaintno'>Revive</a> ]" : '').
"</th></tr></table>";

echo "<table width='80%' border='1' style='border-collapse: collapse'>
<tr valign='top'><td>Dated<br><input type='text' name='complaint_date' size='10' value='$complaintdate'><br>
Problem<br><textarea name='problem' rows='2' cols='50'>$problem</textarea></td>
<td>User<br>".employee_list($employee)."<br>
Location<br><input type='text' name='location' size='40' value='$location'><br>
Technician<br>".technician_list($technician)."</td></tr>";

if ($complaintno && $err) {
	echo $err;
} else if ($complaintno) {
	//item list
	echo "<table width='90%' border='1' style='border-collapse: collapse'>
	<tr><th colspan='4'><h3 style='color:red'>[ Status: ";
	foreach ($statuss as $st) {
		echo "<input type='radio' name='status' value='$st'";
		if ($st == $status) echo 'checked';
		echo "> $st ";
	} 
	echo " ]</h3>Materials ".($status == 'Resolved' ? 'used' : 'required')." to resolve above complaint</th></tr>
	<tr><th>No.</th><th nowrap>Item Description</th><th>Qty Out (to user)</th><th>Qty In (from user)</th></tr>";

	//add new item
	echo "<tr><td>+</td>";
	if (!$id && $status == 'Pending') {
		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='0'></td>
	        <td><input type='text' name='qty_in' size='5' value='0'></td></tr>
		<tr><th>Add</th><td colspan='3'><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_useditems where complaint_no=$complaintno 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&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>
			<input type='hidden' name='id' value='$q->id'></td>
			<td><input type='text' name='qty_out' size='5' value='$q->qty_out'></td>
			<td><input type='text' name='qty_in' size='5' value='$q->qty_in'></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</td><td>$q->qty_in</td>";
		}
		echo "</tr>";
	}
}

if ($status != 'Cancelled' || $status != 'Resolved') {
	echo "<tr><th colspan='2'><input type='submit' name='submit' value='SAVE'></th><th colspan='2'>";

	if (!$err && $complaintno) {
		echo "<input type='submit' name='submit' value='DELETE'>";
	}
}

?>
</th></tr>
</table>
</center>