<?php include("../../include/dbconnect.php"); 


for($ind = 0;$ind <=count($record);$ind++)
{
		if(!empty($min_no))
		{
			$result = mysql_query("select order_record,remarks from labourinv where record= '$record[$ind]' ") or die(mysql_error());
			$row = mysql_fetch_row($result);
			$order_record=$row[0];
			$s_remarks = $row[1];
			$m_date = substr($min_date[$ind],6,4).'-'.substr($min_date[$ind],3,2).'-'.substr($min_date[$ind],0,2);
			if(empty($row[1]))
			{
				$new_s_remarks=$remarks[$ind];
			}
			else
			{
				$new_s_remarks=$row[2].','.$remarks[$ind];
			
			}			
			
			
			$query = "update labourinv set approved_qty = '$approved_qty[$ind]',min_no ='$min_no[$ind]',min_date ='$m_date',rejected_qty ='$rejected_qty[$ind]',remarks='$new_s_remarks' where record ='$record[$ind]' ";
			mysql_query($query) or die(mysql_error());

		}
		
		$result = mysql_query("select app_qty,rejected_qty,remarks,min_no,schedule_qty,issued_qty,balance_qty from orders where record= '$order_record' ") or die(mysql_error());
		$row = mysql_fetch_row($result);
		$old_app_qty=$row[0];
		$old_rejected_qty=$row[1];
		
		$schedule_qty = $row[4];
		$issued_qty=$row[5];
		$balance_qty=$row[6];
		
		$new_app_qty=$old_app_qty+$approved_qty[$ind];
		$new_rej_qty=$old_rejected_qty+$rejected_qty[$ind];
		
		$new_issued_qty = $issued_qty+$approved_qty[$ind];
		
		
		if(!empty($min_no) and ($new_issued_qty >= $schedule_qty))
		{
			$app_status='Approved';
		}
			if(empty($row[2]))
			{
				$new_remarks=$remarks[$ind];
			}
			else
			{
				$new_remarks=$row[2].','.$remarks[$ind];
			
			}
			
			
			$mindt=$m_date;				
			if(!empty($min_no[$ind]))
			{
				$min_no[$ind] = $min_no[$ind].'('.$min_date[$ind].')';
			}
			
			if(empty($row[3]))
			{
				$new_min=$min_no[$ind];
			}
			else
			{
				$new_min=$row[3].','.$min_no[$ind];
			
			}	
			if ( isset($submit) && $submit == "Submit")
			{
				
				$query="update orders set remarks='$new_remarks', min_no='$new_min',return_date='$mindt',app_status='$app_status',app_qty='$new_app_qty',rejected_qty='$new_rej_qty' where record = '$order_record' ";
				mysql_query($query) or die(mysql_error());
			}
}
?>
<table>
<tr><td colspan=4 align=middle>

<h4><a href="view_sele.php">View Order Details  </a>
<h4><a href="reject_input_new.php">Enter Another Approval Entry  </a>

<br><br><font size=1><center><a href= "../../index.html">Return to index page</center></font></table>
