<link rel="stylesheet" type="text/css" href="css/table_frize_1.css">
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain" style="width:100%;">
<div class="tab_div" style="width:100%;">
<h1><?php echo $s->GetFieldValue("modules_form","id='".$_REQUEST['frmid']."' and moduleid='".$_REQUEST['modid']."'","frm_name");?></h1>
<?php 
//unset($_SESSION['employee_code']);
//error_reporting(0);
include('./includes/fun-php.php');
include('./includes/fun-HRClass.php');
$modid=$_REQUEST['modid'];
$frmid=$_REQUEST['frmid'];
$target_rurl="index.php?route=HRModule/SalaryProcess_new&modid=".$modid."&frmid=".$frmid."";
$rurl_view="index.php?route=View_master_payslip&action=View&modid=".$modid."&frmid=".$frmid."";

$apprisal_rs = DB_fetch_array(DB_query("SELECT apprisal_type FROM apprisal_policy_master",$db));
if($apprisal_rs['apprisal_type']=='y'){
    $arrM=array(1=>"January","February","March","April","May","June","July","August","September","October","November","December");
    $m=12;
   }else{
    $arrM=array(4=>"April",5=>"May",6=>"June",7=>"July",8=>"August",9=>"September",10=>"October",11=>"November",12=>"December",1=>"January",2=>"February",3=>"March");
    $m=3;
   }
$arrear_de = DB_fetch_array(DB_query("SELECT * FROM hr_arrear_sheet WHERE id='".$_REQUEST['id']."'",$db));?>
  <script>//alert("You not process current month salary.");</script>
  <script>
function chk_employee()
{
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("employee_code").innerHTML=xmlhttp.responseText;
  }
  }
  var site=document.getElementById("site").value;
  xmlhttp.open("GET","check_data_hr.php?section=chk_employee_site&site="+site,true);
  xmlhttp.send();
}
</script>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain" style="width:100%;">
<div class="tab_div" style="width:100%;">
<table width="100%" border="0" cellpadding="3" cellspacing="0">
<form action="" method="post" name="frm" id="frm">
<tr class="row1">
<td style="padding:0px;">
  <table width="100%" border="0" cellspacing="0" cellpadding="2">
  <tr>
    <td align="left" valign="top"><strong>Site :</strong></td>
    <td align="left" valign="top"><select name="site" id="site" style="width:150px;" onclick="chk_employee();">
      <option value="000">---ALL---</option>
      <?php $site_sql=DB_query("Select loccode, locationname from locations  where CompanyId='".$_SESSION['ACGCompanyId']."' and loccode in('".$_SESSION['AssignedBranch']."')",$db);
      while($site_row=DB_fetch_array($site_sql)){?>
      <option value="<?php echo $site_row['loccode'];?>"<?php echo ($_REQUEST['site']==$site_row['loccode']?'selected':'');?>><?php echo $site_row['locationname'];?></option>
      <?php } ?>
    </select></td>
   <td align="left" valign="top"><strong>From Month :</strong></td>
    <td align="left" valign="top"><select name="fm_month" id="fm_month"  style="width:150px;">
    <?php
       if($arrM){
        foreach ($arrM as $key => $value) {
        $p='';
        if( $key==$_REQUEST['fm_month'])
        $p='selected';?>
      <option value="<?php echo $key;?>" <?php echo $p;?> ><?php echo $value;?></option>
    <?php } }?>
    </select></td>
    <td align="left" valign="top"><strong>To Month :</strong></td>
    <td align="left" valign="top"><select name="to_month" id="to_month"  style="width:150px;">
    <!--<option value="">--Select--</option>-->
    <?php if($arrM){
        foreach ($arrM as $key => $value) {
        $p='';
        if($_REQUEST['to_month']==''){
        $p=$m;
        }else{
        $p=$_REQUEST['to_month'];
        }
        if( $key==$p)
        $p='selected';?>
      <option value="<?php echo $key;?>" <?php echo $p;?> ><?php echo $value;?></option>
    <?php } } ?>
    </select></td>
    <td align="left" valign="top"><strong>Year :</strong></td>
    <td align="left" valign="top"><select name="payyear" id="payyear"  style="width:150px;">
    <?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="8" align="center" valign="top" style="text-align:center;">
    <input type="submit" name="Search" class="search" value="Search" onclick="return chksalprocess()"/>
      &nbsp;</td>
    </tr>
</table>
  </td>
</tr></table>
</form>

<?php if($_REQUEST['Search']){
  if($_REQUEST['site']!='000')
  {
  $empSql=DB_query("Select * from empmaster WHERE emp_site='".$_REQUEST['site']."'",$db);
      while($empRow = DB_fetch_array($empSql))
        {
          $empArr[]=$empRow['id'];
        }
        if(!empty($empArr)){
       $empArray=implode("','",$empArr);
       }
  $filter[]="B.emp_id IN ('".$empArray."')";
  }
  if($_REQUEST['payyear']!='')
  $filter[]="A.payyear='".$_REQUEST['payyear']."'";

  if(!empty($filter))
  {
  $filter=implode(' and ',$filter);
  }
  else
  {
  $filter="1=1";
  }
?>
<p align="right"><a href="print_arrear_sheet_report.php" target="_blank"><strong>Print</strong></a>&nbsp;&nbsp;&nbsp;&nbsp;
<a href="export_arrear_sheet_report.php" target="_blank"><strong>Excel</strong></a>&nbsp;&nbsp;&nbsp;&nbsp;</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <th>Sr No</th>
    <th >Employee Code</th>
    <th >Employee Name</th>
    <th >Designation</th>
    <?php 
    if(!empty($arrM)){
    foreach ($arrM as $key => $value) { 
      ?>
    <th class="tabledata1"><strong><?php echo $value;?></strong></th>
      <?php $p++;} }?>
    <th class="tabledata1"><strong>Total</strong></th>
    <th class="tabledata1"><strong>Paid Status</strong></th>
    </tr>
  <?php $i=1;
  $sql=DB_query("SELECT B.* FROM hr_arrear_sheet AS A INNER JOIN hr_arrear_sheet_details AS B WHERE $filter",$db);
  $_SESSION['ArrearSheetReport']="SELECT B.* FROM hr_arrear_sheet AS A INNER JOIN hr_arrear_sheet_details AS B WHERE $filter";
   if(DB_num_rows($sql)>0){
  while($row=DB_fetch_array($sql)){
    ?>
  <tr>
    <td align="center"><?php echo $i;?></td>
    <td align="center"><?php echo $s->getField('empmaster','id',$row['emp_id'],'emp_code');?></td>
    <td align="left"><?php echo $s->getField('empmaster','id',$row['emp_id'],'emp_name');?></td>
    <td align="left"><?php  $design=$s->getField('empmaster','id',$row['emp_id'],'designation');
    echo $s->getField('desigmaster','id',$design,'designame');?></td>
   <?php $j=0;
    if(!empty($arrM)){
    foreach ($arrM as $key => $value) { 
      if($key>=$row['fm_month'] && $key<=$row['to_month'])
        $apprisal_amt=$row['apprisal_amt'];
      else
        $apprisal_amt=0;
      ?> <td class="tabledata1"><?php echo $basic[$key][]=$apprisal_amt; ?></td>
      <?php $j++;} }?>
      <td align="left"><?php echo $arrear_amt_tot[]=$row['arrear_amount'];?></td>
    <td align="left"><?php echo $row['paid_status'];?></td>
    </tr>
    <?php $i++;}}else{?>
 <tr class="row1"><td style="text-align:center;" class="tabledata1" colspan="<?php echo $p+7?>">No Data Found !!</td></tr>
<?php } ?>
    <?php if(DB_num_rows($sql)>1){?>
    <tr><td colspan="4" style="text-align:right;"><strong>Total :</strong></td>
    <?php if(!empty($arrM)){
    foreach ($arrM as $key => $value) { ?>
     <td class="tabledata1"><?php echo array_sum($basic[$key])?></td>
     <?php }}?>
     <td class="tabledata1"><?php echo array_sum($arrear_amt_tot)?></td>
     <td>&nbsp;</td>
    </tr>
    <?php } ?>
</table>
  <?php }   ?>
  </div></div>
</div>
</div>