<?php
function get_children($parent)
{	
global $db;$rurl="modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid'];  
$query = DB_query('SELECT * FROM master_boq WHERE parentid = '.$parent, $db);
if(DB_num_rows($query) > 0)
{		 	
	while($row =DB_fetch_array($query))
	{		
	 $count2=DB_query("select start_date,end_date,durations  from pms_monthly where boq_id='".$row['id']."'",$db);	
	$count3=DB_fetch_array($count2);		
	?>
	<tr>
    <td><?php echo $row['group_title']; ?> </td>
    <td><?php echo $row['qty']; ?></td>
    <td><strong><?php echo $count3['start_date']; ?></strong></td>
	<td><strong><?php echo $count3['end_date']; ?></strong></td>
	<td><strong><?php echo $count3['durations']; ?></strong></td>
  </tr>
  <?php	} }} ?>
<link href="css/tender_project.css" rel="stylesheet" type="text/css" />
<div class="tender_main_page">
<h1>Monthly  Progress Chart</h1>
<form action="" method="post">
<table width="50%" border="0" cellspacing="0" cellpadding="0">
 
 <tr>
    <td class="tabledata1">BOQ Type <span style="color:#FF0000;">*</span></td>
    <td><select name="boq" style="width:250px;">
    	<option value="All">Select</option>
    	<?php
    	$sql=DB_query("select * from master_boq where parentid=0",$db);
		while($row=DB_fetch_array($sql))
		{
    	?>
    	<option value="<?php echo $row['id']; ?>"<?php if($_REQUEST['boq']==$row['id']){ ?>selected="selected" <?php } ?>><?php echo $row['group_title']; ?></option>
    	<?php } ?>
    </select>
    	
    	
    	</td>
 </tr>
  <tr>
  <td colspan="2">&nbsp;</td>	
  	
  </tr>
  <tr>
    <td class="tabledata1" colspan="2" align="center"><input type="submit" name="Search" value="Search" /> </td>
  </tr> 
 
</table>
</form>
<?php
if(isset($_POST['Search']))
{
$qtydata=array();
$per=array();
$name=array();
$sqlqtydata=DB_query("select * from master_boq where parentid='".$_REQUEST['boq']."'",$db);
while($sqlqty=DB_fetch_array($sqlqtydata))
{	
$qtydata[]=$sqlqty['qty'];
$per1=DB_query("select sum(quantity) as amount from mbook_preparation inner join mbook_preparation_child on mbook_preparation.id=mbook_preparation_child.parent_id where pbs_name='".$_REQUEST['boq']."' and activity_unit='".$sqlqty['id']."' ",$db);
$perdata=DB_fetch_array($per1);

$per[]=$perdata['amount'];
$name[]=substr($sqlqty['group_title'],0,25);
//echo "name".substr($sqlqty['group_title'],0,25)."Totalqty".$sqlqty['qty']."Done qty".$perdata['amount'];
//echo "<br>";
}
	
}	


for($i=0;$i<count($qtydata);$i++)
{
$data5[]=$qtydata[$i];
$data7[]=$per[$i];
$data8[]=$name[$i];
}



//$data6=array_chunk($data5,1); 

$_SESSION['query']=$data5;
$_SESSION['query1']=$data7;
$_SESSION['query2']=$data8;


?>
<div id="body_content">
<div class="left_part">
  <!--left table 1 start 
    left table 1 close -->
<div style="border:#93959c solid 1px; width:260px; overflow:auto; height:300px;">
<table width="100%" border="1" >
  <tr><th>Task Name</th><th>Total Qty</th><th>Completed Qty</th><th>Percentage</th></tr>
  <?php   
  for($k=0;$k<count($data8);$k++)
  {
  	if($data7[$k]!=0)
 $per=round(($data7[$k]/$data5[$k])*100,2);
  else
 $per=0;
	?>
	<tr>
	<td><strong><?php echo $data8[$k];  ?></strong></td>
	<td><strong><?php echo $data5[$k]; ?></strong></td>
	<td><strong><?php  if($data7[$k]=='') echo "0"; else echo $data7[$k];  ?></strong></td>
	<td><strong><?php echo $per; ?></strong></td>
	</tr>
	<?php } ?>
</table>  	
  </div>
    </div> 
<div class="right_part">  


<iframe src="montlyprogresschart/progresschart.php" style="width:500px; height:300px" ></iframe>
  
</div>

<!-- Right Table 2 Close-->
</div><!-- Close Right Part -->
  <div class="cl"></div>
</div>
<!-- Body Content Close -->
<div style="height:30px;"></div>
</div>


