<?php
@session_start();
$branch_id=$_SESSION['branch_id'];
 
	include_once("class/class.MySQL.php");
	$db	=new MySQL();
 
 $y=$_GET['yrs'];
 $mn=$_GET['mns'];
 $dyss=$_GET['dys'];
 if($mn)
 {
 
 
     ///month wise
	 
	 
//echo "SELECT date_join FROM employee e where `date_join` LIKE '%$y%' ";
$sel_datss = mysql_query("SELECT date_join FROM employee e where `date_join` LIKE '%$y%' and branchid='$branch_id' ");
 $sel_datss = mysql_num_rows($sel_datss);
   $arr=array();
      
for($j=1; $j<=$dyss; $j++)
{


  if($j<10){
 $datsrt=$y.'-'.$mn.'-0'.$j;
// $datend=$y.'-0'.$j.'-31';
 }else{ $datsrt=$y.'-'.$mn.'-'.$j;
// $datend=$y.'-'.$j.'-31';
 }
//echo "SELECT distinct t.e_date,t.e_id FROM employee e,time t where e.date_join LIKE '%$y%'  and e.e_id=t.e_id and   t.e_date='$datsrt'  GROUP BY t.e_date,t.e_id".'<br />';
$sel_emp_pcnt = mysql_query("SELECT distinct t.e_date,t.e_id FROM employee e,time t where e.date_join LIKE '%$y%'  and e.e_id=t.e_id and   t.e_date='$datsrt' and e.branchid='$branch_id'  GROUP BY t.e_date,t.e_id");

 $sel_emp_pcnt = mysql_num_rows($sel_emp_pcnt);

 $ppercnt=($sel_emp_pcnt*100);
 $ppercnt=$ppercnt/($sel_datss);
 $arr[$j]['ppercnt']= round($ppercnt);
	

?>

<?php /*?><input type="text" name="pcntemp" id="pcntemp<?php echo $j;?>" value="<?php echo round($ppercnt); ?>"><?php */?>
<?php

}


 }
 
 ///if end
 
 
 else
 {
//echo "SELECT date_join FROM employee e where `date_join` LIKE '%$y%' ";
$sel_datss = mysql_query("SELECT date_join FROM employee e where `date_join` LIKE '%$y%' and branchid='$branch_id' ");
 $sel_datss = mysql_num_rows($sel_datss);
   $arr=array();
      
for($j=1; $j<=12; $j++)
{

  if($j<10){
 $datsrt=$y.'-0'.$j.'-01';
 $datend=$y.'-0'.$j.'-31';
 }else{ $datsrt=$y.'-'.$j.'-01';
 $datend=$y.'-'.$j.'-31';}

$sel_emp_pcnt = mysql_query("SELECT distinct t.e_date,t.e_id FROM employee e,time t where e.date_join LIKE '%$y%'  and e.e_id=t.e_id and   t.e_date BETWEEN '$datsrt' AND '$datend' and e.branchid='$branch_id' GROUP BY t.e_date,t.e_id");

 $sel_emp_pcnt = mysql_num_rows($sel_emp_pcnt);

 $ppercnt=($sel_emp_pcnt*100);
 $ppercnt=$ppercnt/($sel_datss*30);
 $arr[$j]['ppercnt']= round($ppercnt);
	

?>

<?php /*?><input type="text" name="pcntemp" id="pcntemp<?php echo $j;?>" value="<?php echo round($ppercnt); ?>"><?php */?>
<?php

//var_dump($arr);
}

}//else end 
 	echo '{"name":'.json_encode($arr).'}';
?>