<?php 
if($_REQUEST['save_finish'])
{
	
	
	$del=DB_query("delete from monthly_budg_entry_child where id='".$_REQUEST['id']."'",$db);
	for($i=0;$i<count($_REQUEST['group_id']);$i++)
	{
		$datarray['pid']=$_REQUEST['id'];
		$datarray['pbse_group']=$_REQUEST['group'][$i];
		$datarray['pbs_name']=$_REQUEST['group_name'][$i];
		$datarray['material_amt']=$_REQUEST['material_amt'][$i];
		$datarray['labour_amt']=$_REQUEST['labour_amt'][$i];
		$datarray['equep_amt']=$_REQUEST['Equp_amt'][$i];
		$datarray['subc_amt']=$_REQUEST['subcon_amt'][$i];
		$datarray['other_amt']=$_REQUEST['other_amt'][$i];
		$datarray['total_amt']=$_REQUEST['total_amt'][$i];
		
		$s->RecordInsert('monthly_budg_entry_child',$datarray);
	}
   $s->pageLocation("index.php?route=PMS/Transcations/detailed_budget_entry_view".$rurl);
}
$sql=DB_query("select * from  monthly_budget_entry where id='".$_REQUEST['id']."'",$db);
$rowdata=DB_fetch_array($sql);
$FetchdataRow['project']=$rowdata['project'];
$FetchdataRow['block']=$rowdata['block'];
$FetchdataRow['pbse_code']=$rowdata['pbs_work_group'];
$data1=$rowdata['date'];
?>
<?php 
class getpse
{

public function getpse()  
		{
		 
		}
function getPSEGroupName($pid)
{
global $db;
$amit=array();
//echo "select id, pbse_description from psm_psb_project where parent_id='".$pid."'";
	$x=DB_query("select id, pbse_description from psm_psb_project where parent_id='".$pid."'",$db);
	while($xrow=DB_fetch_array($x))
	{ ?>
	<?php echo $xrow['pbse_description'].'<br>';
	$amit[]=$xrow['id'];
	 
	}
	$amit1=implode(",",$amit);
	?>
	<input type="hidden" name="group_name[]" value="<?php echo $amit1; ?>" id="group_name" />
<?php } }
$gettest=new getpse();
?>

<link href="css/tender_project.css" rel="stylesheet" type="text/css" />

	<script src="js1/jquery-1.7.2.js"></script>
	<script src="js1/jquery.ui.widget.js"></script>
	<script src="js1/jquery.ui.tabs.js"></script>

<script>
	$(function() {
		$( "#tabs" ).tabs();
	});
	</script>
<script type="text/javascript" language="javascript">
function getreqitemdata()
{
	
var opt = frm.pbse_code;  
  var numofoptions = opt.length  
  //alert(numofoptions);
    var selValue = new Array  
    var j = 0  
    for (i=0; i<numofoptions; i++)  
    {  
      if (opt[i].selected === true)  
      {  
        selValue[j] = opt[i].value  
        j++  
      }  
    }  
  
    selValue = selValue.join("','")  
   	//var arrayItem=document.getElementById("arrayItem").value;
	if(selValue=="")
  {
  //document.getElementById("sub_id").innerHTML="";
  return;
  }		
  //alert(selValue);

var xmlhttp;
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("groupname").innerHTML=xmlhttp.responseText;
    }
  }
  xmlhttp.open("GET","getgroup_text.php?site="+selValue,true);
xmlhttp.send();

//xmlhttp.open("GET","getSort.php?s="+str+"&cat="+cat,true);

}

function calculate_value(i)
{
 var a=document.getElementById("material_amt_"+i).value;
 var b=document.getElementById("labour_amt_"+i).value;
 var c=document.getElementById("Equp_amt_"+i).value;
 var d=document.getElementById("subcon_amt_"+i).value;
 var e=document.getElementById("other_amt_"+i).value;
 var sum=parseFloat(a)+parseFloat(b)+parseFloat(c)+parseFloat(d)+parseFloat(e);
 document.getElementById("total_amt_"+i).value=sum;
 
}

</script>
<form name="frm" method="post">
<div class="tender_main_page">
<h1>Monthly Budget Entry</h1>
<!-- Body Content Start -->
<div id="body_content">
	<!-- TAble 1 Start --><div>
	
	<table width="100%" border="0" cellspacing="0" cellpadding="3">
<!--  <tr class="row1">
    <td style="width:120px;" class="tabledata">Tender Project</td>
    <td><input style="width:680px;" class="input_border" /></td>
  </tr> -->
  
  <tr class="row1">
    <td class="tabledata" style="width:250px;">Project <span style="color:#FF0000">*</span></td>
    <td>
	  <?php $sql_state=DB_query("SELECT loccode,locationname FROM  locations where loccode='".$FetchdataRow['project']."' ",$db);	?>
 <select class="input_border" style="width:350px;"   name='project' onchange="ShowDiv(this.value,'hid_blockdiv','estimation_block.php')">
 
 <?php 				 
					while($row_branch=DB_fetch_array($sql_state))
					{
					  
					   echo "<option value='".$row_branch['loccode']."' >".$row_branch['locationname']."</option>";
					}
				 
					?>
 
  </select>
	</td>

  </tr>
  <tr class="row1">
    <td class="tabledata">Block <span style="color:#FF0000">*</span></td>
    <td><div id='hid_blockdiv'> 
<?php 
//echo "SELECT id,block_name FROM  sub_block_master where prjct_name='".$project."' ";
$sql=DB_query("SELECT id,block_name FROM  sub_block_master where id='".$FetchdataRow['block']."' ",$db);	
	echo "<select  class='input_border' style='width:350px;' name='block'  >";					
	
	while($row=DB_fetch_array($sql))
	{
		
		echo "<option value='".$row['id']."' $pe >".$row['block_name']."</option>";
	}
   echo "</select>";
?>
</div></td>
  
  </tr>

  <tr class="row1">
    <td class="tabledata">PBS Work Group <span style="color:#FF0000">*</span></td>
    <td>
	<?php $grp=DB_query("select * from psm_psb_project where id='".$FetchdataRow['pbse_code']."'",$db); ?>
	<select name="pbse_code[]" id="pbse_code" multiple style="width:350px;"  >
	
	<?php while($grpRow=DB_fetch_array($grp)) { 
	
	
	?>
	<option value="<?php echo $grpRow['id']; ?>"><?php echo $grpRow['pbse_description']; ?></option>
	<?php } ?>
	</select>
	</td>
  
  </tr>

<tr class="row1">
	<td class="tabledata">Date <span style="color:#FF0000">*</span></td>
    <td>
	<input type="text" name="date" class="datepicker"  value="<?php echo CovertSQLDate($data1); ?>"   style="width:350px;" />
	</td>
	
</tr>

</table>
	</div><!-- TAble 1 Close -->
	
	<br />

<!-- TAble 2 Start --><div>


<div class="cl"></div>
<div style="width:810px; overflow:auto; height:250px;">
			
<table id="groupname" width="100%" border="1" cellspacing="0" cellpadding="0">
  <tr class="row2">
    <td class="tabledata">Sno.</td>
	<td class="tabledata">Select</td>
	<td class="tabledata">PBS Group</td>
	<td class="tabledata">PBSE Name</td>
	<td class="tabledata">Material Amt.</td>
	<td class="tabledata">Labour Amt.</td>
	<td class="tabledata">Equipment Amt.</td>
	<td class="tabledata">SubContract Amt.</td>
	<td class="tabledata">Other Element Amt.</td>
	<td class="tabledata">Total Amount</td>
  </tr>
  <?php 
  $i=1;
  
  $sqldata=DB_query("select * from monthly_budg_entry_child where pid='".$_REQUEST['id']."'",$db);
  $i=0;
  while($sel_groupRow=DB_fetch_array($sqldata))  {?>
  <tr bgcolor="#FFFFFF" onMouseOver="this.style.backgroundColor='#fffeb3'; this.style.color='#00f';" onMouseOut="this.style.backgroundColor='#FFF'; this.style.color='#000000';" >
    <td class="tabledata1"><?php echo $i+1; ?></td>
    <td class="tabledata1"><center><input name="select" type="checkbox" value="" />
	<input name="group_id[]" value="<?php echo $sel_groupRow['pbse_group']; ?>" type="hidden" />
	</center></td>
    <td class="tabledata1" style="white-space:nowrap">
		<?php echo $s->getField('psm_psb_project','id',$sel_groupRow['pbse_group'],'pbse_description');  ?>
		<input name="group[]" value="<?php echo $sel_groupRow['pbse_group']; ?>" type="hidden" />
		</td>
    <td class="tabledata1" style="white-space:nowrap;">
	
 	<?php
 echo $s->getField('psm_psb_project','id',$sel_groupRow['pbs_name'],'pbse_description');  ?>
	
<input type="hidden" name="group_name[]" value="<?php echo $sel_groupRow['pbs_name']; ?>" />
</td>
    <td class="tabledata1"><input type="text" name="material_amt[]" id="material_amt_<?php echo $i; ?>"  value="<?php echo $sel_groupRow['material_amt'];?>" /></td>
    <td class="tabledata1"><input type="text" name="labour_amt[]" id="labour_amt_<?php echo $i; ?>" value="<?php echo $sel_groupRow['labour_amt'];?>" /></td>
    <td class="tabledata1"><input type="text" name="Equp_amt[]" id="Equp_amt_<?php echo $i; ?>" value="<?php echo $sel_groupRow['equep_amt'];?>" /></td>
    <td class="tabledata1"><input type="text" name="subcon_amt[]" id="subcon_amt_<?php echo $i; ?>" value="<?php echo $sel_groupRow['subc_amt'];?>"  /></td>
    <td class="tabledata1"><input type="text" name="other_amt[]" id="other_amt_<?php echo $i; ?>" value="<?php echo $sel_groupRow['other_amt'];?>" /></td>
    <td class="tabledata1"><input type="text" name="total_amt[]" id="total_amt_<?php echo $i; ?>" onfocus="calculate_value(<?php echo $i; ?>);"  value="<?php echo $sel_groupRow['total_amt'];?>"/></td>
  </tr>
  <?php $i++; } ?>
</table>
</div>
<div class="cl"></div>
</div>
<!-- TAble 2 Close -->
</div><!-- Body Content Close -->
<div style="height:30px;"></div>
<div class="button_nav" style="padding-right:10px;">
	<input type="button" value="Save & Continue" class="submit_button" />&nbsp;&nbsp;&nbsp;&nbsp;
	<input type="submit" name="save_finish" value="Save & Finish" class="submit_button" />&nbsp;&nbsp;&nbsp;&nbsp;
	<input type="button" value="Close" class="submit_button" />
</div>
</div>
</form>
