<?php
//********************************************INSERT THE DATA********************START HERE**********************************

if($_REQUEST['save'])
{
	if($_REQUEST['sub_amendment']['amendment_no']!=''){	
	$amendment_date=FormatDateForSQL($_REQUEST['sub_amendment']['amendment_date']);
	$_REQUEST['sub_amendment']['amendment_date']=$amendment_date;
	$start_date=FormatDateForSQL($_REQUEST['sub_amendment']['start_date']);
	$_REQUEST['sub_amendment']['start_date']=$start_date;
	$completion_date=FormatDateForSQL($_REQUEST['sub_amendment']['completion_date']);
	$_REQUEST['sub_amendment']['completion_date']=$completion_date;
	$_REQUEST['sub_amendment']['approval_status']='Pending';
	extract($_REQUEST['sub_amendment']);
	$s->RecordInsert('sub_amendment',$_REQUEST['sub_amendment']);
	$lastId=DB_Last_Insert_ID($db,'sub_amendment','id');
	for($i=0;$i<$_REQUEST['counter'];$i++)
	{
	$data['pid']=$lastId;
	$data['group_id']=$_REQUEST['group_id'][$i];
	$data['activity_id']=$_REQUEST['activity_id'][$i];
	$data['work_order_qty']=$_REQUEST['work_order_qty'][$i];
	$data['ammd_qty']=$_REQUEST['amendment_qty'][$i];
	$data['operation1']=$_REQUEST['add_subt'][$i];
	$data['curr_qty']=$_REQUEST['current_qty'][$i];
	$data['work_order_rate']=$_REQUEST['work_order_rate'][$i];
	$data['ammd_rate']=$_REQUEST['amendment_rate'][$i];
	$data['operation2']=$_REQUEST['add1_sub1'][$i];
	$data['curr_rate']=$_REQUEST['current_rate'][$i];
	$data['net_ammount']=$_REQUEST['net_amount'][$i];
	
	$s->RecordInsert('sub_amendment_chield',$data);
	}
	unset($_REQUEST['sub_amendment']);
	unset($_SESSION['abc']);
	unset($_SESSION['ammenment']);	
	//print_r($_REQUEST); exit;
	$_SESSION['success_msg']="Saved Successfully";	
	echo "<script>location.href='index.php?route=SubContractors/workOrder/work_order_amendment_index&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
	}
	else
	{
	echo "<script>alert('Try Again');</script>";
	}
}

//********************************************INSERT THE DATA********************END HERE**********************************





//********************************************UPADTE THE DATA********************START HERE**********************************



if(isset($_REQUEST['update']))
{
	$condition="pid='".$_REQUEST['amed']."'";
	$s->DeleteRecord('sub_amendment_chield',  $condition);
	for($k=0;$k<$_REQUEST['counter_ammd_edit'];$k++)
	{
	$data['pid']=$_REQUEST['amed'];
	$data['group_id']=$_REQUEST['group_id'][$k];
	$data['activity_id']=$_REQUEST['activity_id'][$k];
	$data['work_order_qty']=$_REQUEST['work_order_qty'][$k];
	$data['ammd_qty']=$_REQUEST['amendment_qty'][$k];
	$data['operation1']=$_REQUEST['add_subt'][$k];
	$data['curr_qty']=$_REQUEST['current_qty'][$k];
	$data['work_order_rate']=$_REQUEST['work_order_rate'][$k];
	$data['ammd_rate']=$_REQUEST['amendment_rate'][$k];
	$data['operation2']=$_REQUEST['add1_sub1'][$k];
	$data['curr_rate']=$_REQUEST['current_rate'][$k];
	$data['net_ammount']=$_REQUEST['net_amount'][$k];
	$s->RecordInsert('sub_amendment_chield',$data);
	}
	unset($_SESSION['ammenment_edit']);
	$_SESSION['success_msg']="Update Successfully";
	echo "<script>location.href='index.php?route=SubContractors/workOrder/work_order_amendment_index&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
}



//********************************************UPADTE THE DATA********************END HERE**********************************







//***************************************************DELETE ITEM IN CASE OF EDIT*******START HERE**************************	
	
if($_REQUEST['delitem2'])
{  
	for($p=0;$p<count($_REQUEST['delrow']);$p++)
	{	
	$Delete_Query=DB_query("Delete From sub_amendment_chield where id='".$_REQUEST['delrow'][$p]."'",$db);
	$_SESSION['success_msg']="Deleted Successfully";	
	}
}

//***************************************************DELETE ITEM IN CASE OF EDIT*******END HERE**************************

	
	
//***************************************************DELETE ROW*******START HERE**************************************	
	
if($_REQUEST['delitem'])		 
{
	$arr=array();
	$ListItem=explode('#',$_SESSION['list']);
	for($i=0;$i<count($_REQUEST['delrow']);$i++)
	{
	$key = array_search($_REQUEST['delrow'][$i], $ListItem );		 
	if($key!=false || $key==0)
	unset($ListItem[$key]);
	$itemlist1=implode("#",$ListItem);
	$_SESSION['list']=$itemlist1;
	} 
}


	
//***************************************************DELETE ROW*******END HERE**************************************









//********************************************TAKE IN SESSION********************START HERE**********************************


if($_REQUEST['add_work'])
{
	$_SESSION['sub_amendment']['project']=$_REQUEST['sub_amendment']['project'];
	$_SESSION['sub_amendment']['block']=$_REQUEST['sub_amendment']['block'];
	$_SESSION['sub_amendment']['contractor']=$_REQUEST['sub_amendment']['contractor'];
	$_SESSION['sub_amendment']['work_order_no']=$_REQUEST['sub_amendment']['work_order_no'];
	$_SESSION['sub_amendment']['amendment_no']=$_REQUEST['sub_amendment']['amendment_no'];
	$_SESSION['sub_amendment']['amendment_date']=$_REQUEST['sub_amendment']['amendment_date'];
	$_SESSION['sub_amendment']['start_date']=$_REQUEST['sub_amendment']['start_date'];
	$_SESSION['sub_amendment']['completion_date']=$_REQUEST['sub_amendment']['completion_date'];
	$_SESSION['sub_amendment']['remarks']=$_REQUEST['sub_amendment']['remarks'];
}

if($_REQUEST['AMIT']=='1')
{
	$subammd=$_SESSION['sub_amendment']['project'];
	$block=$_SESSION['sub_amendment']['block'];
	$contractor=$_SESSION['sub_amendment']['contractor'];
	$workorderno=$_SESSION['sub_amendment']['work_order_no'];
	$amendment_no=$_SESSION['sub_amendment']['amendment_no'];
	$amendment_date=$_SESSION['sub_amendment']['amendment_date'];
	$start_date=$_SESSION['sub_amendment']['start_date'];
	$completion_date=$_SESSION['sub_amendment']['completion_date'];
	$remarks=$_SESSION['sub_amendment']['remarks'];
}

//********************************************TAKE IN SESSION********************END HERE**********************************



//********************************************UNSET IN SESSION********************START HERE**********************************

if($_REQUEST['cancel']!='')
{
	unset($_SESSION['list']);
	unset($_SESSION['abc']);
	unset($_SESSION['ammenment']);
	unset($_SESSION['ammenment_edit']);
	unset($subammd);
	unset($block);
	unset($contractor);
	unset($workorderno);
	unset($amendment_no);
	unset($amendment_date);
	unset($start_date);
	unset($completion_date);
	unset($remarks);
}

//********************************************UNSET IN SESSION********************END HERE**********************************


?>




<!---------------------------------------------------JS FILES------------------START HERE--------------------------------->

<script type="text/javascript">
function calc_qty(i)
{
	var qty1=document.getElementById("work_order_qty_"+i).value;
	var qty2=document.getElementById("amendment_qty_"+i).value;
	var ctr=document.getElementById("add_subt_"+i).value;
	
	if (ctr=="+")
	{
	var current_qty1=parseInt(qty1)+parseInt(qty2);
	// alert(parseInt(qty1)+parseInt(qty2));
	document.getElementById("current_qty_"+i).value=  current_qty1 ;
	}
	else if(ctr=="-")
	{
	var current_qty2=parseInt(qty1-qty2);
	document.getElementById("current_qty_"+i).value=current_qty2; 
	}
	else
	{
	alert("insert + or -");
	} 
}


function calc_qty1(i)
{
	var qty3=document.getElementById("work_order_rate_"+i).value;
	var qty4=document.getElementById("amendment_rate_"+i).value;
	var ctr1=document.getElementById("add1_sub1_"+i).value;
	
	if (ctr1=="+")
	{
	
	var current_qty3=parseInt(qty3)+parseInt(qty4);
	// alert(parseInt(qty1)+parseInt(qty2));
	document.getElementById("current_rate_"+i).value=current_qty3 ;
	}
	else if(ctr1=="-")
	{
	var current_qty4=parseInt(qty3-qty4);
	document.getElementById("current_rate_"+i).value=current_qty4; 
	}
	else
	{
	alert("insert + or -");
	} 
}
function calc_netamt(i)
{
	var qty5=document.getElementById("current_qty_"+i).value;
	var qty6=document.getElementById("current_rate_"+i).value;
	var net_amt=parseInt(qty5*qty6);
	document.getElementById("net_amount_"+i).value=net_amt;
}	 
</script>

<!---------------------------------------------------JS FILES------------------END HERE------------------------------------->



<!---------------------------------------------------AJAX FILES-------------START HERE------------------------------------->


<script type="text/javascript">
function getblock1(str)
{
	//alert(str);
	var xmlhttp;
	if(str=='')
	{
	document.getElementById("block1").innerHTML='';
	return false;
	}
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if(xmlhttp.readyState==4 && xmlhttp.status==200)
	{
	var data=xmlhttp.responseText;
	document.getElementById("block1").innerHTML=data;
	}
	}
	xmlhttp.open("GET","block_ajax1.php?block1="+str,true);
	xmlhttp.send();
}



function showWorkOrderNo(str)
{
	//alert(str);
	if (str=="")
	{
	document.getElementById("work_order_no").innerHTML="";
	return;
	}
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if (xmlhttp.readyState==4 && xmlhttp.status==200)
	{
	document.getElementById("work_order_no").innerHTML=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET","get_work_order_no.php?str="+str,true);
	xmlhttp.send();
}

 function showdata(str)
{  
	//alert(str);
	if (str=="")
	{
	document.getElementById("work_order_no_data").innerHTML="";
	return;
	}
	var xmlhttp;
	if (window.XMLHttpRequest)
	{
	xmlhttp=new XMLHttpRequest();
	}
	else
	{
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if (xmlhttp.readyState==4 && xmlhttp.status==200)
	{
	var data=xmlhttp.responseText.split("__");
	document.getElementById("work_order_no_data").innerHTML=data[0];
	document.getElementById("AMMDNO").innerHTML=data[1];
	document.getElementById("start_date").innerHTML=data[2];
	document.getElementById("completion_date").innerHTML=data[3];	
	}
	}
	xmlhttp.open("GET","get_work_order_no_data.php?work_order_no="+str+"&amd="+12,true);
	xmlhttp.send();
}


function showdata123(str)
{
	alert(str);
	if (str=="")
	{
	document.getElementById("work_order_no_data").innerHTML="";
	return;
	}
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if (xmlhttp.readyState==4 && xmlhttp.status==200)
	{
	document.getElementById("work_order_no_data").innerHTML=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET","get_work_order_no_data.php?work_order_no="+str,true);
	xmlhttp.send();
}
</script>


<!---------------------------------------------------AJAX FILES-------------END HERE------------------------------------->







<!----------------------------------------------PARENT TABLE IN CASE OF EDIT---START HERE------------------------------------->


<h3>Work Order Amendment</h3>
<form action="" method="post">
<?php if($_REQUEST['action']=='ammd_edit' && $_REQUEST['amed']){ 

$recEdit=DB_fetch_array($s->GetRecordById('sub_amendment','id='.$_REQUEST['amed']));
extract($recEdit);
?>
<table width="100%" border="0" cellspacing="2" cellpadding="2">
  <tr>
    <th width="16%" class="tabledata"><div align="left">Project</div></th>
    <td width="31%"><?php echo $s->GetFieldValue('locations',"loccode='".$project."'",'locationname'); ?></td>
    <th width="15%" class="tabledata"><div align="left">Block</div></th>
    <td width="35%" id="block1"><?php echo $s->GetFieldValue('sub_block_master',"id='".$block."'",'block_name');?></td>
  </tr>
  <tr>
    <th class="tabledata"><div align="left">Contractor</div></th>
    <td><?php echo $s->GetFieldValue('sub_contractor_definition',"id='".$contractor."'",'contractor_name');?></td>
 
    <th class="tabledata"><div align="left">Work Order No.</div></th>
    <td id="work_order_no"><?php echo $s->GetFieldValue('sub_preparation',"id='".$work_order_no."'",'work_order_no');?></td>
  	</tr>
  <tr>
    <th class="tabledata"><div align="left">Amendment No.</div></th>
    <td id="AMMDNO"><?php echo $amendment_no;?></td>
	 <th class="tabledata"><div align="left">Amendment Date</div></th>
    <td><?php echo ConvertSQLDate($amendment_date); ?></td>
  </tr>
    <tr>
	<th class="tabledata"><div align="left">Start Date
	  </div>
	<td id="start_date"><?php echo ConvertSQLDate($start_date); ?></td>
	 <th class="tabledata"><div align="left">Completion Date</div></th>
    <td id="completion_date"><?php echo ConvertSQLDate($completion_date); ?></td>
	<!--<th class="tabledata">Retention Percentage</th>
    <td><input type="text" name="sub_amendment[retention_percentage]" id="retention_percentage" value="<?php echo $retention_percentage;?>" /></td>
	 <th class="tabledata">Retention Amount</th>
    <td><input type="text" name="sub_amendment[retention_amount]" id="retention_amount" value="<?php echo $retention_amount;?>"/></td>-->
	<td width="3%"></td>
  </tr>
  <tr>
    <th class="tabledata"><div align="left">Remarks</div></th>
    <td colspan="6"><?php echo $remarks;?></td>
  </tr>
    <tr>
	<td colspan="8"><table width="100%" border="0" cellspacing="2" cellpadding="2"><tr>
	  <td colspan="2" style="text-align:right;"><input type="submit" value="Delete" name="delitem2" onclick="return confirm('Are you sure you want to delete?')" /></td>
	  <td width="18%"><input type="button" name="material_recovery_details" value="Material Recovery Details"/></td>
	 <td width="7%"><input type="button" name="wotax" value="WO Tax"/></td>
    <td width="8%"><input type="submit" name="add_work" value="Add Work" onclick="popup('work_order_preparation_addworks.php?<?php echo $rurl.'&action='.$_REQUEST['action']; ?>&amed=<?php echo $_REQUEST['amed']; ?>',1000,600)"/></td>
	<td width="15%"><input type="button" name="terms_conditions" value="Terms & Conditions"/></td>
    </tr></table></td>
  </tr>
</table>


<!----------------------------------------------PARENT TABLE IN CASE OF EDIT---END HERE------------------------------------->
<?php } else { ?>


<!----------------------------------------------PARENT TABLE IN CASE OF ADD---START HERE------------------------------------->

<table width="100%" border="0" cellspacing="2" cellpadding="2">
  <tr>
    <th class="tabledata">Project</th>
    <td><select name="sub_amendment[project]" id="project" onchange="getblock1(this.value)">
		<option value="">Select Project</option>
		<?php 
	$site1="select loccode,locationname from locations";
	$result1=DB_query($site1,$db);		
	while($row=DB_fetch_array($result1))
		{ 
			$select='';
			if($subammd==$row['loccode'])
			$select='selected';
		
		?>
	<option value="<?php echo $row['loccode']?>" <?php echo $select; ?>><?php echo $row['locationname']?></option>
<?php   } ?>	
	</select>
	</td>
    <th class="tabledata">Block</th>
    <td id="block1"><select name="sub_amendment[block]" id="block">
					<option value="">Select Block</option>
			<?php $blockvalue=DB_query("select * from sub_block_master",$db); 
			
			while($blockvalueRow=DB_fetch_array($blockvalue))
			{
			$se='';
			if($block==$blockvalueRow['id'])
			$se='selected';
			?>
			<option value="<?php echo $blockvalueRow['id']; ?>" <?php echo $se; ?>><?php echo $blockvalueRow['block_name']; ?></option>
			<?php } ?>		
					
		</select>
	</td>
  </tr>
  <tr>
    <th class="tabledata">Contractor</th>
    <td><select name="sub_amendment[contractor]" id="contractor" onchange="showWorkOrderNo(this.value)">
      <option value="">Select Contractor </option>
      <?php
		$sqlcategory=DB_query("select * from sub_contractor_definition",$db);
		while($category_row=DB_fetch_array($sqlcategory))
		{
				$s='';
				if($contractor==$category_row['id'])
				$s="selected";
		?>
  <option value="<?php echo $category_row['id'];?>" <?php echo $s;?>><?php echo $category_row['contractor_name'];?></option>
      <?php } ?>
    </select></td>
 
    <th class="tabledata">Work Order No.</th>
    <td id="work_order_no"><select name="sub_amendment[work_order_no]" id="work_order_no1" onchange="showdata(this.value)">
	 					   <option value="">Select Work Order No</option>
		<?php 
			$work_order=DB_query("select * from sub_preparation",$db);
			while($work_orderRow=DB_fetch_array($work_order)) { 
			$s1='';
			if($workorderno==$work_orderRow['id'])
			$s1='selected';
			
			?>
	<option value="<?php echo $work_orderRow['id']; ?>" <?php echo $s1; ?>><?php echo $work_orderRow['work_order_no']; ?></option>
						   
		<?php } ?>
						   </select>
	</td>
  	</tr>
  <tr>
    <th class="tabledata">Amendment No.</th>
    <td id="AMMDNO"><input type="text" name="sub_amendment[amendment_no]" id="amendment_no" value="<?php echo $amendment_no;?>" style="width:150px;" /></td>
	 <th class="tabledata">Amendment Date</th>
    <td><input type="text" name="sub_amendment[amendment_date]" id="amendment_date" value="<?php if($_REQUEST['AMIT']=='1'){ echo $amendment_date;} else { echo date('Y/m/d');} ?>" class="datepicker" style="width:150px;" /></td>
  </tr>
    <tr>
	<th class="tabledata">Start Date
    <td id="start_date"><input type="text" name="sub_amendment[start_date]" id="start_date"  class="datepicker" style="width:150px;" value="<?php echo $start_date; ?>" /></td>
	 <th class="tabledata">Completion Date</th>
    <td id="completion_date"><input type="text" name="sub_amendment[completion_date]"  id="completion_date" class="datepicker" style="width:150px;" value="<?php echo $completion_date; ?>" /></td>
	<!--<th class="tabledata">Retention Percentage</th>
    <td><input type="text" name="sub_amendment[retention_percentage]" id="retention_percentage" value="<?php echo $retention_percentage;?>" /></td>
	 <th class="tabledata">Retention Amount</th>
    <td><input type="text" name="sub_amendment[retention_amount]" id="retention_amount" value="<?php echo $retention_amount;?>"/></td>-->
	</td>
  </tr>
  <tr>
    <th class="tabledata">Remarks</th>
    <td colspan="6"><textarea name="sub_amendment[remarks]" style="width:595px; height:80;"><?php echo $remarks;?></textarea></td>
  </tr>
    <tr>
	<td colspan="8"><table width="100%" border="0" cellspacing="2" cellpadding="2"><tr>
	<td colspan="2"></td>
       <td width="18%"><input type="button" name="material_recovery_details" value="Material Recovery Details"/></td>
	 <td width="7%"><input type="button" name="wotax" value="WO Tax"/></td>
    <td width="8%"><input type="submit" name="add_work" value="Add Work" onclick="popup('work_order_preparation_addworks.php?<?php echo $rurl.'&action='.ammd; ?>',1000,600)"/></td>
	<td width="15%"><input type="button" name="terms_conditions" value="Terms & Conditions"/></td>
    </tr></table></td>
  </tr>
</table>


<!----------------------------------------------PARENT TABLE IN CASE OF ADD---END HERE------------------------------------->




<?php } ?>



<table width="100%" border="0" cellspacing="2" cellpadding="2" id="work_order_no_data">
  <tr>
    <th class="tabledata">Sl No.</th>
    <th class="tabledata">Activity Group</th>
    <th class="tabledata">Activity</th>
    <th class="tabledata">Work Order Qty</th>
    <th class="tabledata">Amendment Qty</th>
    <th class="tabledata">+/-</th>
    <th class="tabledata">Current Qty</th>
    <th class="tabledata">Work Order Rate</th>
    <th class="tabledata">Amendment Rate</th>
    <th class="tabledata">+ / -</th>
    <th class="tabledata">Current Rate</th>
	<th class="tabledata">Net Amount</th>
  </tr>
  
  
  
<?php 

//********************************CHIELD TABLE DATA IN CASE OF AMMED EDIT*********START HERE****************************


if($_REQUEST['action']=='ammd_edit'  && $_REQUEST['amed']!=''){
$s=new db_query();
$sql="SELECT * FROM sub_amendment_chield where pid='".$_REQUEST['amed']."'";
$query=DB_query($sql,$db);
$j=0;
while($row=DB_fetch_array($query)){
$group_name=$s->GetFieldValue('master_boq',"id='".$row['group_id']."'",'group_title');
$activity_name=$s->GetFieldValue('master_boq',"id='".$row['activity_id']."'",'group_title');
?>
	<tr>
		<td><input type="checkbox" name="delrow[]" value="<?php echo $row['id']; ?>" />
		<input type="hidden" name="itemid[]" value="<?php echo $row['id']; ?>" />
		</td>
		<td><?php echo $group_name ?>
		<input name="group_id[]" type="hidden" id="activity_group_<?php echo $j; ?>" value="<?php echo $row['group_id'] ?>"  size="10"  style="width:98%;"/></td> 
		<td><?php echo $activity_name; ?>
		<input name="activity_id[]" type="hidden" id="activity_name_<?php echo $j; ?>" value="<?php echo $row['activity_id'] ?>"  size="10"  style="width:98%;"/></td> 
		<td><input name="work_order_qty[]" type="text" id="work_order_qty_<?php echo $j; ?>" value="<?php echo $row['work_order_qty']; ?>"  size="10"   style="width:98%;"/></td> 
		<td><input name="amendment_qty[]" type="text" id="amendment_qty_<?php echo $j; ?>" value="<?php echo $row['ammd_qty']; ?>"  size="10" style="width:98%;"/></td> 
		<td><input name="add_subt[]" type="text" id="add_subt_<?php echo $j; ?>" value="<?php echo $row['operation1']; ?>"   style="width:98%;" onblur="calc_qty(<?php echo $j; ?>)" /></td>
		<td><input name="current_qty[]" type="text" id="current_qty_<?php echo $j; ?>" value="<?php echo $row['curr_qty']; ?>"   size="10"   style="width:98%;"/></td> 
		<td><input name="work_order_rate[]" type="text" id="work_order_rate_<?php echo $j; ?>" value="<?php echo $row['work_order_rate'] ?>"   size="10"   style="width:98%;"/></td>
		<td><input name="amendment_rate[]" type="text" id="amendment_rate_<?php echo $j; ?>" value="<?php echo $row['ammd_rate']; ?>"  size="10"   style="width:98%;"/></td>
		<td><input name="add1_sub1[]" type="text" id="add1_sub1_<?php echo $j; ?>" value="<?php echo $row['operation2']; ?>" size="10" onblur="calc_qty1(<?php echo $j; ?>)"    style="width:98%;"/></td>
		<td><input name="current_rate[]" type="text" id="current_rate_<?php echo $j; ?>" size="10" value="<?php echo $row['curr_rate'] ?>"   style="width:98%;" onblur="calc_netamt(<?php echo $j; ?>)"/></td>
		<td><input name="net_amount[]" type="text" id="net_amount_<?php echo $j; ?>" value="<?php echo $row['net_ammount']; ?>"   size="10"   style="width:98%;"/></td>
 	</tr>
	<?php $j++; }  ?>
	
<input type="hidden" name="counter_ammd_edit" value="<?php echo $j; ?>" />
	
<?php 	
if(isset($_SESSION['ammenment_edit'])) {
	$itemadd=explode("#",$_SESSION['ammenment_edit']);
	$s=new db_query();
	for($k=0,$i=$j;$k<count($itemadd);$k++,$i++)
	{
	$items="select * from master_boq where id ='".$itemadd[$k]."'";
	$sql_items=DB_query($items,$db);
	$sql_itemsRow=DB_fetch_array($sql_items);
	$parant=$sql_itemsRow['parentid'];
	$group_name=$s->GetFieldValue('master_boq',"id='".$parant."'",'group_title');
	$activity_name=$s->GetFieldValue('master_boq',"id='".$sql_itemsRow['id']."'",'group_title');
?>
	<tr bgcolor="#FFFFFF">
		<td><input type="checkbox" name="delrow[]"   /></td>
		<td><?php echo $group_name; ?>
		<input type="hidden" name="group_id[]" id="activity_group_<?php echo $i; ?>" value="<?php echo $parant;  ?>" size="10"  style="width:98%;" />
		</td>
		<td><?php echo $activity_name; ?>
		<input type="hidden" name="activity_id[]" id="activity_name_<?php echo $i; ?>" value="<?php echo $sql_itemsRow['id'];  ?>" size="10"  style="width:98%;" />
		</td>
		<td><input type="text" name="work_order_qty[]" id="work_order_qty_<?php echo $i; ?>" size="10"   style="width:98%;" /></td>
		<td><input type="text" name="amendment_qty[]" id="amendment_qty_<?php echo $i; ?>" size="10"   style="width:98%;" /></td>
		<td><input type="text" name="add_subt[]" id="add_subt_<?php echo $i; ?>" size="10"   style="width:98%;" onblur="calc_qty(<?php echo $i; ?>)" /></td>
		<td><input type="text" name="current_qty[]" id="current_qty_<?php echo $i; ?>" size="10"   style="width:98%;" /></td>
		<td><input type="text" name="work_order_rate[]" id="work_order_rate_<?php echo $i; ?>" size="10"   style="width:98%;" /></td>
		<td><input type="text" name="amendment_rate[]" id="amendment_rate_<?php echo $i; ?>" size="10"   style="width:98%;" /></td>
		<td><input type="text" name="add1_sub1[]" id="add1_sub1_<?php echo $i; ?>" size="10"   style="width:98%;" onblur="calc_qty1(<?php echo $i; ?>)" /></td>
		<td><input type="text" name="current_rate[]" id="current_rate_<?php echo $i; ?>" size="10"   style="width:98%;" onblur="calc_netamt(<?php echo $i; ?>)" /></td>
		<td><input type="text" name="net_amount[]" id="net_amount_<?php echo $i; ?>"    size="10"   style="width:98%;"/></td>
	</tr>	
		<?php } ?>
		<input type="hidden" name="counter_ammd_edit" value="<?php echo $i; ?>" />
	<?php 	}
?>
	
<?php	} 


//********************************CHIELD TABLE DATA IN CASE OF AMMED EDIT*********END HERE****************************





//********************************CHIELD TABLE DATA IN CASE OF AMMED ADD*********START HERE****************************


else 
{

if(isset($_SESSION['abc'])){
$s=new db_query();
 $sql="SELECT * FROM sub_preparation_child where parentid='".$_SESSION['abc']."'";
$query=DB_query($sql,$db);
$j=0;
while($row=DB_fetch_array($query)){
$group_name=$s->GetFieldValue('master_boq',"id='".$row['group_id']."'",'group_title');
$activity_name=$s->GetFieldValue('master_boq',"id='".$row['activity_id']."'",'group_title');
?>
	<tr>
		<td><input type="checkbox" name="delrow[]" /></td>
		<td><?php echo $group_name ?>
		<input name="group_id[]" type="hidden" id="activity_group_<?php echo $j; ?>" value="<?php echo $row['group_id'] ?>"  size="10"  style="width:98%;"/></td> 
		<td><?php echo $activity_name; ?>
		<input name="activity_id[]" type="hidden" id="activity_name_<?php echo $j; ?>" value="<?php echo $row['activity_id'] ?>"  size="10"  style="width:98%;"/></td> 
		<td><input name="work_order_qty[]" type="text" id="work_order_qty_<?php echo $j; ?>" value="<?php echo $row['qty']; ?>"  size="10"   style="width:98%;"/></td> 
		<td><input name="amendment_qty[]" type="text" id="amendment_qty_<?php echo $j; ?>"  size="10" style="width:98%;"/></td> 
		<td><input name="add_subt[]" type="text" id="add_subt_<?php echo $j; ?>"   style="width:98%;" onblur="calc_qty(<?php echo $j; ?>)" /></td>
		<td><input name="current_qty[]" type="text" id="current_qty_<?php echo $j; ?>"   size="10"   style="width:98%;"/></td> 
		<td><input name="work_order_rate[]" type="text" id="work_order_rate_<?php echo $j; ?>" value="<?php echo $row['rates'] ?>"   size="10"   style="width:98%;"/></td>
		<td><input name="amendment_rate[]" type="text" id="amendment_rate_<?php echo $j; ?>"  size="10"   style="width:98%;"/></td>
		<td><input name="add1_sub1[]" type="text" id="add1_sub1_<?php echo $j; ?>" size="10" onblur="calc_qty1(<?php echo $j; ?>)"    style="width:98%;"/></td>
		<td><input name="current_rate[]" type="text" id="current_rate_<?php echo $j; ?>" size="10" value="<?php echo $row['rates'] ?>"   style="width:98%;" onblur="calc_netamt(<?php echo $j; ?>)"/></td>
		<td><input name="net_amount[]" value="<?php echo $row['net_amt']; ?>" type="text" id="net_amount_<?php echo $j; ?>"   size="10"   style="width:98%;"/></td>
 	</tr>
	<?php $j++; } ?>
	
<?php	} ?>
<?php
if(isset($_SESSION['ammenment'])){
if($_REQUEST['action']=='ammd'){
	$itemadd=explode("#",$_SESSION['ammenment']);
	$s=new db_query();
	for($k=0,$i=$j;$k<count($itemadd);$k++,$i++)
	{
	$items="select * from master_boq where id ='".$itemadd[$k]."'";
	$sql_items=DB_query($items,$db);
	$sql_itemsRow=DB_fetch_array($sql_items);
	$parant=$sql_itemsRow['parentid'];
	$group_name=$s->GetFieldValue('master_boq',"id='".$parant."'",'group_title');
	$activity_name=$s->GetFieldValue('master_boq',"id='".$sql_itemsRow['id']."'",'group_title');
?>
	<tr bgcolor="#FFFFFF">
		<td><input type="checkbox" name="delrow[]"   /></td>
		<td><?php echo $group_name; ?>
		<input type="hidden" name="group_id[]" id="activity_group_<?php echo $i; ?>" value="<?php echo $parant;  ?>" size="10"  style="width:98%;" />
		</td>
		<td><?php echo $activity_name; ?>
		<input type="hidden" name="activity_id[]" id="activity_name_<?php echo $i; ?>" value="<?php echo $sql_itemsRow['id'];  ?>" size="10"  style="width:98%;" />
		</td>
		<td><input type="text" name="work_order_qty[]" id="work_order_qty_<?php echo $i; ?>" size="10"   style="width:98%;" /></td>
		<td><input type="text" name="amendment_qty[]" id="amendment_qty_<?php echo $i; ?>" size="10"   style="width:98%;" /></td>
		<td><input type="text" name="add_subt[]" id="add_subt_<?php echo $i; ?>" size="10"   style="width:98%;" onblur="calc_qty(<?php echo $i; ?>)" /></td>
		<td><input type="text" name="current_qty[]" id="current_qty_<?php echo $i; ?>" size="10"   style="width:98%;" /></td>
		<td><input type="text" name="work_order_rate[]" id="work_order_rate_<?php echo $i; ?>" size="10"   style="width:98%;" /></td>
		<td><input type="text" name="amendment_rate[]" id="amendment_rate_<?php echo $i; ?>" size="10"   style="width:98%;" /></td>
		<td><input type="text" name="add1_sub1[]" id="add1_sub1_<?php echo $i; ?>" size="10"   style="width:98%;" onblur="calc_qty1(<?php echo $i; ?>)" /></td>
		<td><input type="text" name="current_rate[]" id="current_rate_<?php echo $i; ?>" size="10"   style="width:98%;" onblur="calc_netamt(<?php echo $i; ?>)" /></td>
		<td><input type="text" name="net_amount[]" id="net_amount_<?php echo $i; ?>"    size="10"   style="width:98%;"/></td>
	</tr>	
		<?php } ?>
		<input type="hidden" name="counter" value="<?php echo $i; ?>" />
	<?php 	}  }
}


//********************************CHIELD TABLE DATA IN CASE OF AMMED ADD*********END HERE****************************

?>	 
</table>
<p align="center">
	<input type="submit" name="<?php if($_REQUEST['action']=='ammd_edit') {echo 'update';} else{ echo 'save';} ?>" value="<?php if($_REQUEST['action']=='ammd_edit') {echo 'update';} else{ echo 'save';} ?>"/>
	<input type="submit" name="cancel" value="Reset" /><a href="index.php?route=SubContractors/workOrder/work_order_amendment_index&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>"><input type="button" name="back" value="Cancel" /></a>
</p>
</form>