<?php 
if($_REQUEST['save_finish'])
{
	$pbs_group=implode(",",$_REQUEST['pbse_code']);
	$date=date('Y-m-d');
	$data['project']=$_REQUEST['project'];
	$data['block']=$_REQUEST['block'];
	$data['pbs_work_group']=$pbs_group;
	$data['posted_date']=$date;
	$data['date']=FormatDateForSQL($_REQUEST['date']);
	$s->RecordInsert('monthly_budget_entry',$data);
	$lstid= DB_Last_Insert_ID($db,'monthly_budget_entry', $id);
	for($i=0;$i<count($_REQUEST['group_id']);$i++)
	{
		$datarray['pid']=$lstid;
		$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);
}
?>


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

	
<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 ",$db);	?>
 <select class="input_border" style="width:350px;"   name='project' onchange="ShowDiv(this.value,'hid_blockdiv','estimation_block.php')">
 <option value='000'> -- Select Project -- </option>
 <?php 				 
					while($row_branch=DB_fetch_array($sql_state))
					{
					   $p='';
					   if($row_branch['loccode']==$FetchdataRow['project'])
					   $p='selected';
					   echo "<option value='".$row_branch['loccode']."' $p >".$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",$db);	
	echo "<select  class='input_border' style='width:350px;' name='block'  >";					
	echo "<option value='000'> -- Select Block -- </option>";
	while($row=DB_fetch_array($sql))
	{
		$pe='';
		if($row['id']==$FetchdataRow['block'])
		$pe='selected';
		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 parent_id='0'",$db); ?>
	<select name="pbse_code[]" id="pbse_code" multiple style="width:350px;" onchange="getreqitemdata();" >
	<option value="0">Select Group</option>
	<?php while($grpRow=DB_fetch_array($grp)) { 
	
	$sel='';
	if($FetchdataRow['pbse_code']==$grpRow['id'])
	$sel='selected';
	?>
	<option value="<?php echo $grpRow['id']; ?>"<?php echo $sel; ?>><?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"  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>
<!--  <tr bgcolor="#FFFFFF" onMouseOver="this.style.backgroundColor='#fffeb3'; this.style.color='#00f';" onMouseOut="this.style.backgroundColor='#FFF'; this.style.color='#000000';" >
    <td class="tabledata1">11.</td>
    <td class="tabledata1"><center><input name="select" type="checkbox" value="" /></center></td>
    <td class="tabledata1" style="white-space:nowrap">Permanent Works</td>
    <td class="tabledata1">0.00</td>
    <td class="tabledata1">0.00</td>
    <td class="tabledata1">0.00</td>
    <td class="tabledata1">0.00</td>
    <td class="tabledata1">0.00</td>
    <td class="tabledata1">0.00</td>
    <td class="tabledata1">0.00</td>
  </tr>
--></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>
