Your IP : 216.73.216.40


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

<h2 align='left'>Indent Form</h2>

<?php

$tbl = 'indents';

$id = $_REQUEST["id"];
$indentno = $_REQUEST["indent_no"];
$indentdate = $_POST['indent_date'];
if (!$indentdate) $indentdate = date("Y-m-d");
$purpose = $_POST['purpose'];
$employee = $_POST['employee'];
$recommendation = $_POST['recommendation'];
$category = $_REQUEST["category"];
$subcategory = $_REQUEST["subcategory"];
$item = $_POST["item"];
$itemadd = $_POST["itemadd"];
$qtydemand = $_POST['qty_demand'];
$qtyout = $_POST['qty_out'];
$approxcost = $_POST['approx_cost'];
if (!$status) $status = 'Pending';

if ($_POST["submit"] == 'SAVE') {
	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())");
	}

	if (!$id && $itemadd) {
        	mysql_query("insert into $st_items(code,description,subcategory,category,dated) 
		values('$code','New item added from indent form',$subcategory,$category,now())");
		$id = 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 if ($item) {
		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");
} else if ($_REQUEST["accept"] == 'Yes') {
	mysql_query("update indents set status='Pending' where indent_no=$indentno");
} 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 indent_items where id=$id)");
        while ($o = mysql_fetch_object($rs)) {
                $item = $o->id;
                $category = $o->category;
                $subcategory = $o->subcategory;
        }
}

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)) {
        $indentdate = $o->indent_date;
        $purpose = $o->purpose;
        $employee = $o->employee;
        $recommendation = $o->recommendation;
        $status = $o->status;
}

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='$indentdate'></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>";

if (!$indentno) {
	echo "<tr><th colspan='4'><input type='submit' name='submit' value='SAVE'></th></tr>";
} else {
	echo $id;
	//item list
	echo "</table>
	<table width='90%' 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>";

	//add new item
	if (!$id && $status == 'Pending') {
		echo "<tr><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>";

        	$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.00'></td></tr>
		<tr><th>Add</th><td><input type='text' name='itemadd' value='' size='50'></td>
		<td colspan='3'>Select category, subcategory above and type new item here if it is not listed above.</td></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='4'><input type='submit' name='submit' value='SAVE'></th>".
		($id ? "<th><input type='submit' name='submit' value='DELETE'></th>" : '<th></th>');
		echo "</tr>";
	}
}

echo "<tr><td colspan='5' align='center'>Status: $status".
($status == 'Cancelled' ? "<a href='?pg=$pg&accept=Yes&indent_no=$indentno'>Re-accept</a>" : '').
"</td></tr>";

?>

</table>
</center>