<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>Payment Advise</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."";
$month_arr=array('1'=>'January','2'=>'February','3'=>'March','4'=>'April','5'=>'May','6'=>'June','7'=>'July','8'=>'August','9'=>'September','10'=>'October','11'=>'November','12'=>'December');
$bonus_rs = DB_fetch_array(DB_query("SELECT bonus_cal_per,cal_type FROM bonus_defination_master",$db));
if($bonus_rs['cal_type']=='m'){
  $c=1;
}else{
  $c=12;
}

?>
<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").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%;">
<form action="" method="post" name="frm" id="frm">
<table width="100%" border="0" cellpadding="3" cellspacing="0">

<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>Employee<font color="#FF0000">*</font> :</strong></td>
    <td align="left" valign="top"><select name="employee" id="employee" style="width:150px;">
          <option value="All">---All---</option>
     <?php if($_REQUEST['site']!=''){
      $emp_sql=DB_query("Select id, emp_code,emp_name from empmaster WHERE emp_site='".$_REQUEST['site']."' order by emp_name",$db);
        }else{
        $emp_sql=DB_query("Select id, emp_code,emp_name from empmaster order by emp_name",$db);
        }
      while($emp_row=DB_fetch_array($emp_sql)){?>
      <option value="<?php echo $emp_row['id'];?>" <?php if($_POST['employee']==$emp_row['id']) echo "selected";?>><?php echo $emp_row['emp_name'].' ( '.$emp_row['emp_code'].' ) ' ;?></option>
      <?php }?>
      </select>
      </td>
  <td align="left" valign="top"><?php if($bonus_rs['cal_type']!='m'){ ?><strong>Year :</strong><?php }?></td>
    <td align="left" valign="top">
    <?php if($bonus_rs['cal_type']!='m'){ ?>
    <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>
    <?php } ?>
    </td>

  </tr>
  <tr>
    <td align="left" valign="top"><strong>From Month :</strong></td>
    <td align="left" valign="top"><select name="paymonth" id="paymonth"  style="width:150px;">
    <?php if($bonus_rs['cal_type']=='y'){
    $arr=array(1=>"January");
    }
    if($bonus_rs['cal_type']=='f'){
    $arr=array(4=>"April");
    }
    if($bonus_rs['cal_type']=='m'){
    $arr=array(1=>"January","February","March","April","May","June","July","August","September","October","November","December");
    }
        foreach ($arr as $key => $value) {
        $p='';
        if( $key==$_POST['paymonth'])
        $p='selected';?>
      <option value="<?php echo $key;?>" <?php echo $p;?> ><?php echo $value;?></option>
    <?php } ?>
    </select></td>
    <?php if($bonus_rs['cal_type']!='m'){ ?>
    <td align="left" valign="top"><strong>To Month :</strong></td>
    <td align="left" valign="top"><select name="paymonth1" id="paymonth1"  style="width:150px;">
    <?php if($bonus_rs['cal_type']=='y'){
    $arr=array(12=>"December");
    }
    if($bonus_rs['cal_type']=='f'){
    $arr=array(3=>"March");
    }
   
        foreach ($arr as $key => $value) {
        $p='';
        if( $key==$_POST['paymonth'])
        $p='selected';?>
      <option value="<?php echo $key;?>" <?php echo $p;?> ><?php echo $value;?></option>
    <?php } ?>
    </select></td>
    <?php }else{?>
  <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>
     <?php } ?>
     <td></td>
     <td></td>
  </tr>
  
  <tr class="row1">
    <td colspan="6" 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>

<?php if($_REQUEST['Search']){
  $_SESSION['payyear']=$_REQUEST['payyear'];
  if($_REQUEST['site']!='000')
  $filter[]="site= '".$_REQUEST['site']."'";
  if($_REQUEST['employee']!='All')
  $filter[]="emp_id= '".$_REQUEST['employee']."'";
  if($_REQUEST['payyear']!='')
  $filter[]="year= '".$_REQUEST['payyear']."'";
  if($filter!='')
  { 
  $filter=implode(' and ',$filter); 
  }
  else
  {
  $filter="1=1";
  }
  $empid =DB_query("SELECT distinct(emp_id) FROM hr_monthly_bonus_cal_details WHERE $filter",$db);
  while($allid=DB_fetch_array($empid))
  {
   $idArr[]=$allid['emp_id'];
  }
  if(!empty($idArr)){
  if(count($idArr)>1){
   $idArray=implode("','",$idArr);
  }else{
   $idArray=$idArr[0];
  }
}else{
  $idArray=0;
}
$_SESSION['bonus_calReport1']="SELECT L.loccode,L.locationname FROM locations AS L INNER JOIN empmaster AS E ON L.loccode=E.emp_site WHERE E.id IN ('".$idArray."')";
$loccd=DB_query("SELECT L.loccode,L.locationname FROM locations AS L INNER JOIN empmaster AS E ON L.loccode=E.emp_site WHERE E.id IN ('".$idArray."')",$db);
while($allcd=DB_fetch_array($loccd))
  {
   $locArr[$allcd['loccode']]=$allcd['locationname'];
  }?>

<p align="right"><a href="print_bonuscal_sheet_report.php" target="_blank"><strong>Print</strong></a>&nbsp;&nbsp;&nbsp;&nbsp;
<a href="export_bonuscal_sheet_report.php?itemdata=<?php echo $_REQUEST['itemdata'];?>&status=<?php echo $_REQUEST['status'];?>" 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($bonus_rs['cal_type']=='y'){
    $arrM=array(1=>"January","February","March","April","May","June","July","August","September","October","November","December");
    }
    if($bonus_rs['cal_type']=='f'){
    $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",);
    }
    if($bonus_rs['cal_type']=='m'){
    $mon=$s->getField('hr_monthly_bonus_cal_details','hr_monthly_bonus_cal_id',$_REQUEST['id'],'month');
    $arrM=array($mon=>$month_arr[$mon]);
    }
    $p=0;
    if(!empty($arrM)){
    foreach ($arrM as $key => $value) {?>
      <th><strong><?php echo $value;?></strong></th>
      <?php $p++;} }?>
      <th>Total</th>
    </tr>
  <?php $i=1;
   if(!empty($locArr)){
    foreach ($locArr as $key1 => $value1) {
  $sql=DB_query("SELECT distinct(emp_id) FROM hr_monthly_bonus_cal_details WHERE $filter AND site='".$key1."'",$db);
  $_SESSION['bonus_calReport2']="SELECT distinct(emp_id) FROM hr_monthly_bonus_cal_details WHERE $filter AND site='".$key1."'";
    ?>
   <tr><td colspan="<?php echo $c+7?>"><?php echo $value1?></td></tr>
 <?php 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) { 
    $payBasic = DB_fetch_array(DB_query("SELECT bonus FROM hr_monthly_bonus_cal_details WHERE month='".$key."' AND year='".$_REQUEST['payyear']."' AND emp_id='".$row['emp_id']."'",$db));
      ?> <td class="tabledata1"><?php echo $basic_tot[]=($payBasic['bonus']!=''?$payBasic['bonus']:0); ?></td>
      <?php $j++;} }?>
      <td align="left"><?php if(!empty($basic_tot)){ echo $bonus=array_sum($basic_tot);}else{ echo $bonus=0;} ?></td>
    </tr>
    <?php $i++;}}else{
    ?><tr><td align="left" colspan=<?php echo $c+7?>>Sorry!!! No Data Found</td></tr>
    <?php }
    }
    }else{?><tr><td align="left" colspan=<?php echo $c+7?> style="text-align:center;">Sorry!!! No Data Found</td><?php } ?></tr>
</table>
</form>
<?php }   ?>
  </div></div>
</div>
</div>