<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<h1><?php echo $s->getField('modules_form','id',$_REQUEST['frmid'],'frm_name'); ?></h1>
<?php //error_reporting(0);
include('includes/fun-php.php');
$modid=$_REQUEST['modid'];
$frmid=$_REQUEST['frmid'];

//$timestamp = '1267372800';
//$date = date('Y-m-d H:i:s', $timestamp);
//echo $date;

$rurl="index.php?route=master_payslip&action=View&modid=".$modid."&frmid=".$frmid.""; ?>
<form action="" method="post">
	<table border="0" cellpadding="3" cellspacing="0" width="100%" align="center">
	<tr class="row1">
	<td width="13%" align="right"><strong>Branch</strong></td>
	<td width="32%"><select name="site" id="site" onchange="showemp(this.value)" style="width:98%;">
    <option value="0">Select</option>
    <?php
    $sql_site=DB_query("select * from locations",$db);
    while($row=DB_fetch_array($sql_site))
    {
    ?>
    <option value="<?php echo $row['loccode']; ?>" <?php if($_REQUEST['site']==$row['loccode']) { ?> selected <?php }?> ><?php echo $row['locationname']; ?></option>
    <?php } ?>
	</select>
    </td>
	<td width="13%" align="right"><strong>Employee</strong></td>
	<td><select name="empcode" id="empcode" style="width:98%;">
		<option value="0">Select</option>
      <?php
     $sql_emp=DB_query("select * from empmaster where emp_site='".$_REQUEST['site']."'",$db);
     while($row1=DB_fetch_array($sql_emp))
     {
     ?>
     <option value="<?php echo $row1['id'] ?>" <?php if($_REQUEST['empcode']==$row1['id']) { ?> selected <?php }?>  ><?php echo $row1['emp_name'] ?></option>
     <?php } ?>
     </select>
		</td>
</tr>
<tr class="row1">
 <td align="right"><strong>Month</strong></td>
 <td><select name="paymonth"  style="width:98%;">
 <?php
 $arr=array(1=>"Jan","Feb","Mar","Apr","May","June","July","Aug","Sept","Oct","Nov","Dec");
 foreach ($arr as $key => $value) {
 	$p='';
 	if( $key==$_REQUEST['paymonth'])
	$p='selected';
   ?><option value="<?php echo $key;?>" <?php echo $p;?> ><?php echo $value;?></option>
 <?php } ?></select>
	  </td>   
  <td align="right"><strong>Year</strong></td>
 <td><select name="payyear"  style="width:98%;">
 <?php 
 for($i=date('Y');$i>2000;$i--)
 {
 	$p='';
 	if( $i==$_REQUEST['payyear'])
	$p='selected';
 ?>
 <option value="<?php echo $i;?>" <?php echo $p;?>><?php echo $i;?></option>
 <?php  } ?>
</select></td>  
  </tr>
  <tr class="row1">
  <td colspan="4" style="text-align:center;"><input type="submit" name="Search" class="search" value="Search"/></td>
  </tr>
  </table>	
</form>	
<?php 
  if($_REQUEST['Search'] )
  {
  	$filter=array();

	if($_REQUEST['payyer']!='')
	$filter[]="A.payslip_year='".$_REQUEST['payyear']."'";	
    if($_REQUEST['paymonth']!='')
   	$filter[]="A.payslip_month='".$_REQUEST['paymonth']."'";
    if($_REQUEST['empcode']!='0')
    $filter[]="B.emp_id ='".$_REQUEST['empcode']."'";	
    if($_REQUEST['site']!='0')
    $filter[]="C.emp_site ='".$_REQUEST['site']."'";
     if(!empty($filter))
	$filter1=implode(" and ",$filter);
      $employer_esi=DB_fetch_array(DB_query("select * from esi_master where site='".$_REQUEST['site']."' and salto<='15000'",$db));
	  $Employee_per=$employer_esi['esiper']; 
	  $Employer_per=$employer_esi['employerper'];
?>
<p align="right"><a href="pf_report_print.php?site=<?php echo $_REQUEST['site']; ?>" target="_blank"><input type="button" class="search" value="Print" /></a></p> 
 <table width="100%" border="1" cellspacing="0" cellpadding="3" style="border:#808080 1px solid; border-collapse:collapse;">
  <tr>
    <th width="6%" rowspan="2"><strong>Emp. No.</strong></th>
    <th width="6%" rowspan="2"><strong>P.F. No</strong></th>
    <th rowspan="2"><strong>Employee Name</strong></th>
    <th width="6%" rowspan="2"><strong>Date of Birth</strong></th>
    <th width="6%" rowspan="2"><strong>Date of Joining</strong></th>
    <th width="5%" rowspan="2"><strong>Abs Days</strong></th>
    <th width="6%" rowspan="2"><strong>Wages</strong></th>
    <th width="6%" rowspan="2"><strong>Employee's PF(12%)</strong></th>
    <th colspan="3"><strong>Employer's PF</strong></th>
    <th width="6%" rowspan="2"><strong>Total PF</strong></th>
    <th width="6%" rowspan="2"><strong>Basic above 15000</strong></th>
    <th colspan="3"><strong>Admin Expenses</strong></th>
    <th width="6%" rowspan="2"><strong>Date of Leaving</strong></th>
    </tr>
  <tr>
    <th width="3%"><strong>PF(3.67%)</strong></th>
    <th width="3%"><strong>EPS(8.33%)</strong></th>
    <th width="3%"><strong>Total</strong></th>
    <th width="3%"><strong>PF(1.1%)</strong></th>
    <th width="3%"><strong>PF(0.5%)</strong></th>
    <th width="3%"><strong>PF(0.01%)</strong></th>
    </tr>
    <?php
     $esi_id=$s->GetFieldValue("deduction_master","name like'%PF%'","id");
	    $GetProcess = "SELECT A.emp_id as emp_id, A.workingdays,A.basic_salary,B.allowance_amount FROM `master_process_salary` A 
	    INNER JOIN payslip_salary B
         ON A.id=B.mst_prosal
        inner join empmaster C
        on A.emp_id=C.id
          WHERE  B.allowance_id='".$esi_id."' AND B.allowance_type='D' and B.allowance_amount!='0.00' and ".$filter1." ";	

	   	   
        $ResultProcess_SalData = DB_query($GetProcess,$db);	 
        if(DB_num_rows($ResultProcess_SalData)>0)
        {
   	   while($RowData = DB_fetch_array($ResultProcess_SalData))
	   {
	
	   	$abs_days=DB_fetch_array(DB_query("select count(*) as abs from daily_attendance where site='".$_REQUEST['site']."' 
	   		and employee='".$RowData['emp_id']."' and month(attendance_date)='".$_REQUEST['paymonth']."' and year(attendance_date)='".$_REQUEST['payyear']."' and pres_abs='A'",$db));
        
	  ?> 
  <tr bgcolor="#FFFFFF">
    <td><?php 	echo $Emp_code= $s->getField('empmaster','id',$RowData['emp_id'],'emp_code');	?></td>
    <td><?php  echo $Pf_no= $s->getField('empmaster','id',$RowData['emp_id'],'PFno')?></td>
    <td><?php 	echo $Emp_name= $s->getField('empmaster','id',$RowData['emp_id'],'emp_name');	?></td>
    <td><?php 	echo $dob= ConvertSQLDate($s->getField('empmaster','id',$RowData['emp_id'],'dob'));	?></td>
    <td><?php 	echo $doj= ConvertSQLDate($s->getField('empmaster','id',$RowData['emp_id'],'doj'));	?></td>
    <td><?php  echo $abs_days= $abs_days['abs']?></td>
    <td class="align_right"><?php  echo  $basic_salary=$RowData['basic_salary']?></td>
    <td class="align_right"><?php  echo $totalpf1=$RowData['allowance_amount'] ;?></td>
    <td class="align_right"><?php echo $totalpf2= round($basic_salary*3.67/100); ?></td>
    <td class="align_right"><?php echo $totalpf3= round($basic_salary*8.33/100); ?></td>
    <td class="align_right"><?php echo  $totalpf=$totalpf2+$totalpf3; ?></td>
    <td class="align_right"><?php echo  $totalpf_amt=$totalpf+$totalpf1; ?></td>
    <td class="align_right"><?php if($basic_salary>15000) { echo $above=$basic_salary-15000; } else { echo $above=0; }?></td>
    <td class="align_right"><?php echo $totalpf4= round($basic_salary*1.1/100); ?></td>
    <td class="align_right"><?php echo $totalpf5= round($basic_salary*0.5/100); ?></td>
    <td class="align_right"><?php echo $totalpf6= round($basic_salary*0.01/100); ?></td>
    <td class="align_right"><?php  $leaving_date= $s->getField('empmaster','id',$RowData['emp_id'],'dol'); if($leaving_date!='0000-00-00') echo $leaving_date1=$leaving_date;else $leaving_date1='';	?></td>
  </tr>
  	<?php
$data[]=array("Pf_no"=>$Pf_no,"Emp_code"=>$Emp_code,"Emp_name"=>$Emp_name,"dob"=>$dob,"doj"=>$doj,"abs_days"=>$abs_days,
	"basic_salary"=>$basic_salary,"totalpf1"=>$totalpf1,"totalpf2"=>$totalpf2,"totalpf3"=>$totalpf3,"totalpf"=>$totalpf,"totalpf_amt"=>$totalpf_amt,"totalpf4"=>$totalpf4,"totalpf5"=>$totalpf5,"totalpf6"=>$totalpf6,"leaving_date"=>$leaving_date1,"above"=>$above);
	}
$_SESSION['Pf_Emp_details']=$data;
	  } else {
	 unset($_SESSION['Pf_Emp_details']); 	
	   ?>
       <tr bgcolor="#fff">
    <td colspan="17" align="center"><strong>No Records Found</strong></td>
    </tr>
    <?php } ?>
</table>


<?php 


} ?>

</div>
</div>

<script type="text/javascript">

function showemp(str)
{
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)
	{
		//alert(xmlhttp.responseText)
	 	document.getElementById("empcode").innerHTML=xmlhttp.responseText;
	
	}
	}   

	xmlhttp.open("GET","ajax_site_wise_emp.php?site="+str,true);
	xmlhttp.send();




}

</script>