Your IP : 216.73.216.40


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

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

<?php

$tbl = 'indents';

$id = $_REQUEST["id"];
$indentno = $_REQUEST["indent_no"];
$dateindent = $_REQUEST['date_indent'];
if (!$dateindent) $dateindent = date("Y-m-d");
$purpose = $_POST['purpose'];
$location = $_POST['location'];
$empno = $_POST['emp_no'];
$account = $_POST['account'];
$recommendation = $_POST['recommendation'];
$category = $_REQUEST["category"];
$subcategory = $_REQUEST["subcategory"];
$item = $_REQUEST["item"];
$itemadd = $_POST["itemadd"];
$qtydemand = $_POST['qty_demand'];
$unit = $_POST['unit'];
$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"))) {
		//update existing indent
		mysql_query("update $tbl set date_indent='$dateindent',purpose='$purpose',location='$location',
		emp_no='$empno',account='$account',recommendation='$recommendation'
		where indent_no=$indentno");
	} else {
		//insert new indent
		mysql_query("insert into $tbl(date_indent,purpose,location,emp_no,account,recommendation)
		values('$dateindent','$purpose','$location','$empno','$account','$recommendation')");
		$indentno = mysql_insert_id();
	}

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

	//item entry	
	if (mysql_num_rows(mysql_query("select * from indent_items where id=$id"))) {
		//update existing items of indent
		mysql_query("update indent_items set item=$item,qty_demand=$qtydemand,qty_out=$qtyout,unit='$unit',approx_cost=$approxcost
		where id=$id");
	} else if ($item) {
		//insert new items of indent
		mysql_query("insert into indent_items(indent_no,item,qty_demand,qty_out,unit,approx_cost)
		values($indentno,$item,$qtydemand,$qtyout,'$unit',$approxcost)");
	}
} else if ($_POST["submit"] == 'DELETE') {
	if ($id) {
		//delete item record
		mysql_query("delete from indent_items where id=$id");
		$id = 0;
	} else {
		//delete items first and then delete indent
		mysql_query("delete from indent_items where indent_no=$indentno");
		mysql_query("delete from $tbl where indent_no=$indentno");
		$indentno = 0;
	}
} else if ($_REQUEST["revive"] == 1) {
	mysql_query("update indents set status='Pending' where indent_no=$indentno");
	$status = 'Pending';

} else if ($_REQUEST["cancel"] == 1) {
	mysql_query("update indents set status='Cancelled' where indent_no=$indentno");
	$status = 'Cencelled';

} else if ($_REQUEST["icancel"] == 1) {
	mysql_query("delete from indent_items where id=$id");
	
} else if ($_REQUEST["settle"] == 1) {
	mysql_query("update indents set status='Issued' where indent_no=$indentno");
	$status = 'Issued';

} 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)");
    if (mysql_num_rows($rs)) {
	$o = mysql_fetch_object($rs);
        $item = $o->id;
        $category = $o->category;
        $subcategory = $o->subcategory;
    }
}

$rs = mysql_query("select * from $tbl where indent_no=$indentno");
if (mysql_num_rows($rs)) {
	$o = mysql_fetch_object($rs);
    $dateindent = $o->date_indent;
    $purpose = $o->purpose;
    $location = $o->location;
    $empno = $o->emp_no;
    $account = $o->account;
    $recommendation = $o->recommendation;
    $status = $o->status;
	$dated = $o->dateUpdation;
}

echo "<center>
<table width='80%'>
<tr height='50pt'><th nowrap width='25%'>".($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><th nowrap width='50%'>".($indentno ? "Status: $status ($dated)" : '').
($status == 'Cancelled' ? "[ <a href='?pg=$pg&revive=1&indent_no=$indentno'>Revive</a> ]" : '').
($status == 'Approved' ? "[ <a href='?pg=$pg&settle=1&indent_no=$indentno'>Settle</a> ]" : '').
"</th><th nowrap width='25%'>Indent Date ";

$myCalendar = new tc_calendar("date_indent", true, false);
$myCalendar->setIcon("images/iconCalendar.gif");
$myCalendar->setDate(date('d', strtotime($dateindent)), date('m', strtotime($dateindent)), date('Y', strtotime($dateindent)));
$myCalendar->setPath("calendar/");
$myCalendar->setYearInterval(2016, date("Y"));
$myCalendar->setAlignment('left', 'bottom');
$myCalendar->writeScript();	  


echo "</th></tr></table>";

echo "<table width='80%' border='0' style='border-collapse: collapse'>
<tr><td>Purpose</td><td><input type='text' name='purpose' size='80' value='$purpose'></td>
<td width='10%'>Location</td><td><select name='location'>";
foreach ($locations as $lc) {
	echo "<option value='$lc'".($lc == $location ? ' selected' : '').">$lc</option>";
}
echo "</select></td></tr>
<tr><td width='10%'>Indentor</td><td width='60%'>".employee_list($empno)."
Account <select name='account'>";
foreach ($accounts as $ac) {
	echo "<option value='$ac'".($ac == $o->account ? ' selected' : '').">$ac</option>";
}
echo "</select></td>
<td>Recommendor</td><td><input type='text' name='recommendation' size='30' value='$recommendation'></td></tr>";

if ($indentno) {
	//item list
	echo "<table width='90%' border='1' style='border-collapse: collapse'>
	<tr><th>No.</th><th nowrap>Particulars</th><th>Demand Qty</th><th>Approve Qty</th><th>Out Qty</th><th>Approx Cost</th><th>Last Indent</th></tr>";

	//add new item
	//if (!$id && ($status == 'Pending' || $status == 'Approved')) {
	if (!$id && $status == 'Pending') {
		echo "<tr><td>New</td>
		<td><select name='category' onchange=\"javascript: document.location.href='?pg=$pg&indent_no=$indentno&item=$item&id=$id&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</option>";
        }
	    echo "</select>

        <select name='subcategory' onchange=\"javascript: document.location.href='?pg=$pg&indent_no=$indentno&item=$item&id=$id&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</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 ">$o->code ($o->description)</option>";
        }
	    echo "</select></td>
        <td><input type='text' name='qty_demand' size='5' value='1'>
        <select name='unit'>";
		foreach ($units as $qu) {
			echo "<option value='$qu'".($qu == $o->unit ? ' selected' : '').">$qu</option>";
		}
		echo "</select></td><td>--</td>
        <td><input type='text' name='qty_out' size='5' value='0'> *</td>
	    <td>Rs. <input type='text' name='approx_cost' size='10' value='0.00'></td><td></td></tr>
		<tr><th>Add</th><td colspan='6'><font color='red'>Select category, subcategory, item from the above list, otherwise, type item description here =></font>
		<input type='text' name='itemadd' value='' size='50'></td></tr>";
	} else if ($status == 'Pending'){
		echo "<tr><td colspan='6'><a href='?pg=$pg&indent_no=$indentno&id='>New</a></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&item=$item&id=$id&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</option>";
			}
			echo "</select>
			
			<select name='subcategory' onchange=\"javascript: document.location.href='?pg=$pg&indent_no=$indentno&item=$item&id=$id&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</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 ">$o->code ($o->description)</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'>
        	<select name='unit'>";
			foreach ($units as $qu) {
				echo "<option value='$qu'".($qu == $q->unit ? ' selected' : '').">$qu</option>";
			}
			echo "</select></td>
			<td><input type='text' name='qty_approve' size='5' value='$q->qty_approve'></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>
			<td></td>";
		} else {
			$no++;
			echo "<th><a href='?pg=$pg&indent_no=$indentno&id=$q->id'>$j</a>";
			echo ($status == 'Pending' && stock_status($q->item) > 0.00 ? "<font size=+1 color='red'>*</font>" : '');
			echo "</th><td>".item_inventory($q->item)."</td>
			<td>".number_format($q->qty_demand,2)." $q->unit</td>
			<td>".number_format($q->qty_approve,2)." $q->unit</td>
			<td>".number_format($q->qty_out,2).' '.$q->unit.(!$q->qty_out ? " [ <a href='?pg=$pg&indent_no=$indentno&id=$q->id&icancel=1'>X</a> ]" : '')."</td>
			<td>Rs. $q->approx_cost</td><td>";
			
			$rr = mysql_query("select i.indent_no,i.date_indent as dated,t.item from indents as i left join indent_items as t on i.indent_no=t.indent_no where i.emp_no='$empno' and t.item=$q->item and t.id<$q->id limit 0,1");
			if (mysql_num_rows($rr)) {
				$r = mysql_fetch_object($rr);
				echo "<a href='?pg=$pg&indent_no=$r->indent_no'>$r->indent_no</a> ( $r->dated )";
			} else 
				echo "--";
			echo "</td>";
		}
		echo "</tr>";
	}
}

if ($status == 'Pending') {
	echo "<tr><th colspan='6'><input type='submit' name='submit' value='SAVE'></th>";
	if ($indentno) echo "<th><input type='submit' name='submit' value='DELETE'></th>";
} else if ($status == 'Approved' && $id) {
	echo "<tr><th colspan='6'><input type='submit' name='submit' value='SAVE'></th>";
	if ($indentno) echo "<th><input type='submit' name='submit' value='DELETE'></th>";
} else if ($status == 'Issued' && !$no) {
	echo "<tr><td colspan='6'></td><th><input type='submit' name='submit' value='DELETE'></th>";
}
?>

</tr>
</table>
Items with <font size=+1 color='red'>*</font> marked are available in the Store stock.
</center>