Your IP : 216.73.216.40


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

<h3>Stock Utilization</h3>
<center>

<?php
$tbl = "st_stockout";

$employee = $_REQUEST["employee"];
$indentno = $_REQUEST["indent_no"];

$z = 0;
$dated = date("Y-m-d");
$note = "<p>
? set quantity to zero if it is not yet issued.<br>
Indented items will be listed here till all items are issued.<br>
Issued items will be <font size=+1 color='red'>*</font> marked for identification and to avoid any confusion. 
</p>";

if ($_POST["submit"] == 'ISSUE') {
	$ids = $_POST["id"];
	$items = $_POST["item"];
	$qtyouts = $_POST["qty_out"];
	$xqtyouts = $_POST["xqty_out"];
	$units = $_POST["unit"];
	$no = $_POST['no'];
	if (!$no) $no = 0;
	
	//get category/subcategory of item
	foreach ($ids as $id) {
		$rs = mysql_query("select * from st_items where id=$items[$z]");
		if (mysql_num_rows($rs)) {
			$o = mysql_fetch_object($rs);
			$category = $o->category;
			$subcategory = $o->subcategory;
		
			//utilization entry
			if (mysql_num_rows(mysql_query("select * from $tbl where id=$id"))) {
				mysql_query("update $tbl set qty_out=$qtyouts[$z],unit='$units[$z]',dated=now() 
				where id=$id");
				//update out quantity if it is changed
				if ($xqtyouts[$z] != $qtyouts[$z]) {
					//adjust qty in category table
					mysql_query("update st_category set qty_out=qty_out-$xqtyouts[$z]+$qtyouts[$z] where id=$category");
					//adjust qty in subcategory table
					mysql_query("update st_subcategory set qty_out=qty_out-$xqtyouts[$z]+$qtyouts[$z] where id=$subcategory");
					//adjust qty in item table
					mysql_query("update st_items set qty_out=qty_out-$xqtyouts[$z]+$qtyouts[$z] where id=$items[$z]");
					//adjust qty in indent item table
					mysql_query("update indent_items set qty_out=qty_out-$xqtyouts[$z]+$qtyouts[$z] where indent_no=$indentno and item=$items[$z]");
					$alert = 1;
				}
			} else {
        	        	mysql_query("insert into $tbl(indent_no,item,qty_out,unit,dated) 
				values($indentno,$items[$z],$qtyouts[$z],'$units[$z]',now())");
				//increase qty in category table
				mysql_query("update st_category set qty_out=qty_out+$qtyouts[$z] where id=$category");
				//increase qty in subcategory table
				mysql_query("update st_subcategory set qty_out=qty_out+$qtyouts[$z] where id=$subcategory");
				//increase qty in item table
				mysql_query("update st_items set qty_out=qty_out+$qtyouts[$z] where id=$items[$z]");
				//adjust qty in indent item table
				//mysql_query("update indent_items set qty_out=qty_out+$qtyouts[$z] where indent_no=$indentno and item=$items[$z]");
				mysql_query("update indent_items set qty_out=$qtyouts[$z] where indent_no=$indentno and item=$items[$z]");
			}
			$z++;
		}
       	}

	//send email to indentor
	if ($alrt) {
		$rs = mysql_query("select * from employees where emp_no=(select employee from indents where indent_no=$indentno)");
       		if (mysql_num_rows($rs)) {
                	$o = mysql_fetch_object($rs);
	                $empname = $o->emp_name;
        	        $email = $o->email;
                	//$email = 'mmishra@iiita.ac.in';
	
			$sr = mysql_query("select * from indents where indent_no=$indentno");
       			if (mysql_num_rows($sr)) {
                		$q = mysql_fetch_object($sr);
                		$purpose = $q->purpose;
	                	$location = $q->location;
        	        	$account = $q->account;
        		}
        	}
		$str = "Dear Indentor
		<br><br>	
		With reference to your Indent No. $indentno for the purpose of '$purpose' at location $location, 
		follwing items have been issued under your '$account' account recently from the central store. 
		This is for your information and record pl.
		<br><br>".
		indent_issued($indentno).
		"<br>
		At the time of nodues certification, you will be liable for returnable items issued in your personal account only. 
		However, all the non-consumable including fixture items will be settled as per hand over policy of the Institute.";
        
		//if ($email) automailer($email, "Material Issued", $str);

	}
	
	//mark indent as issued
	$rs = mysql_query("select * from indent_items where qty_approve<>qty_out and indent_no=$indentno");
	if (!mysql_num_rows($rs)) {
		mysql_query("update indents set status='Issued' where indent_no=$indentno");
		$indentno = 0;
	}

	/*
	$i = 0;
	$j = 0;
	$rs = mysql_query("select item,qty_approve,qty_out from indent_items where indent_no=$indentno");
	while ($o = mysql_fetch_object($rs)) {
		$i++;
		if ($o->qty_approve == $o->qty_out) $j++;
	}
	//if issued items = indented items, set status of indent to ISSUED
	if ($i == $j) {
		mysql_query("update indents set status='Issued' where indent_no=$indentno");
		$indentno = 0;
	}
	*/
}


echo "<div align='left'>
Select employee <select name='employee' onchange=\"javascript: document.location.href='?pg=$pg&employee='+this.value\">
<option value=''></option>";

$rs = mysql_query("select emp_no,emp_name,designation from employees order by emp_name");
while ($o = mysql_fetch_object($rs)) {
        echo "<option value='$o->emp_no'";
        if ($o->emp_no == $employee) echo " selected";
        echo ">$o->emp_name</option>";
}

echo "</select>

indent No. <select name='indent_no' onchange=\"javascript: document.location.href='?pg=$pg&employee=$employee&indent_no='+this.value\">
<option value=''></option>";

$rs = mysql_query("select * from indents where employee='$employee' and status='Approved' order by indent_no");
while ($o = mysql_fetch_object($rs)) {
        echo "<option value='$o->indent_no'";
        if ($o->indent_no == $indentno) {
		echo " selected";
		$dateindent = $o->date_indent;
		$purpose = $o->purpose;
		$recommendation = ($o->recommendation ? $o->recommendation : '--');
		$status = $o->status;
	}
        echo ">$o->indent_no</option>";
}

echo "</select> Only APPROVED indents are listed here.
</div>";

if ($indentno) {
	echo "<table width='90%' border='1' style='border-collapse: collapse'>
	<tr><th colspan='7'>[ Purpose: $purpose ] [ Recommendation: $recommendation ] [ Indent Date: $dateindent ]</th></tr>
	<tr><th>No.</th><th>Particulars</th><th>Qty Demand</th><th>Qty Approve</th><th>Qty Issued</th><th>Approx Cost</th><th>Dated</th></tr>";

	$rs = mysql_query("select * from indent_items where indent_no=$indentno order by id");
	while ($o = mysql_fetch_object($rs)) {
		$i++;
		$id = 0;
		$star = '';
		$item = $o->item;
		$qtydemand = $o->qty_demand;
		$qtyapprove = $o->qty_approve;
		$qtyout1 = $o->qty_out; //qty out prior to approval to meet the urgency
		$qtyout = $qtyapprove - $qtyout1; //remaining qty to issue
		$unit = $o->unit;
		$idate = $dated;
	        //if already issued, put a star mark

	        
		$sr = mysql_query("select * from $tbl where indent_no=$indentno and item=$item");
               	if (mysql_num_rows($sr)) {
			$q = mysql_fetch_object($sr);
			$id = $q->id;
			//add previous issued qty (at the time of indent receiving)
			$qtyout2 = $q->qty_out; //qty out after approval
               		//qty may be either 0 or less due to short stock
			if ($qtyout2 == $qtyapprove) {
				$j++;
				$idate = $q->dated;
				$star = "<font size='+1' color='red'>*</font>";
			}
		}

		echo "<tr><td>$i $star</td><td>". item_detail($item). "</td><td>". number_format($qtydemand,2). "</td><td>". number_format($qtyapprove,2). "</td><td>";
	
		if ($qtyapprove == $qtyout2) {
			echo $qtyout2. " $unit";
		} else { 
			//$qtyout = $qtyapprove - $qtyout;
			echo "<input type='hidden' name='id[]' value='$id'>
			<input type='hidden' name='item[]' value='$item'>
			<input type='hidden' name='xqty_out[]' value='$qtyout2'>
			?<input type='text' name='qty_out[]' value='$qtyout' size='5'> 
			$unit ".($qtyout1 ? " ($qtyout1 already issued)" : '')."
			<input type='hidden' name='unit[]' value='$unit'>";
		}
		
		echo "</td><td>$o->approx_cost</td><td>$idate</td></tr>";
	}
	if ($i > $j) echo "<tr><th colspan='7'><input type='submit' name='submit' value='ISSUE'></th></tr>";
	echo "</table><input type='hidden' name='no' value='$i'> $note";
}

?>
</center>