<?php session_start();	
$PageSecurity = 1;
$tabindex=0;
include('includes/DefinePaymentClass.php');
include('includes/SQL_CommonFunctions.inc');
include('CRM/functions.php');
$s=new db_query();

?>
<script src="ui/jquery.ui.timepicker.js"></script>
<link rel="stylesheet" href="css/new_mxerp.css">
<style>
#showdata {
	display: block;
	background: url(Default.png) no-repeat;
	top: 0px;
	left: 0px;
	width: 300px;
	min-height: 60px;
	z-index:0;
}
#back {
	display: none;
	top: 0px;
	left: 0px;
	width: 300px;
	min-height: 60px;
	z-index:0;
}
.tab_div{font-size:12px;}
</style>
<div class="body_contain">
<div class="tab_div">
<h1>Incentive Calculation</h1>
<form method="post" action="">
    <table width="100%" border="0" cellpadding="3" cellspacing="0">
        <tr class="row1">
            <td width="13%"><strong>Branch</strong></td>
            <td width="35%">
                <select name="branch" id="branch" style="width:98%;">
                    <option value="0">--All--</option>
                    	<?php $Sitesql="select * from locations where  CompanyId='".$_SESSION['ACGCompanyId']."' and loccode in('".$_SESSION['AssignedBranch']."') order by locationname";
                    	$SiteRes=DB_query($Sitesql,$db);                            
                    	while($SiteRow=DB_fetch_array($SiteRes)){?>
                                <option value="<?php  echo $SiteRow['loccode'];?>" <?php  echo $_REQUEST['site']==$SiteRow['loccode']?'selected':''?> >
                                <?php  echo $SiteRow['locationname'];?>
                                </option>
                             <?php } ?>
                </select>
                </td>
           <!-- <td width="13%" style="text-align:center;"><strong>Appraisal No.</strong></td>
            <td width="20%">
            <input type="text" style="width:80%;" readonly="true" value="Auto Generate" name="app_no" id="app_no" ></td>-->
            <td width="13%"><strong>Effective Financial Year</strong></td>
            <td>
              <select name="financial_year_id" id="financial_year_id" style="width:98%; background:#f8f8f8; border:#878787 1px solid;">
                  <!-- onchange="get_rating_data(this.value);-->
                  <option value=""> Select financial year</option>
                <?php $fyear="select * from company_financial_years";
                  $fyearRes=DB_query($fyear,$db); 
                  while($yearRow=DB_fetch_array($fyearRes)){?>?>
                  <option value="<?php echo $yearRow['id'];?>"><?php echo ConvertSQLDate($yearRow['year_start'])."-TO-".ConvertSQLDate($yearRow['year_end']); ?></option>
                <?php } ?>
              </select>         
            </td>
        </tr>
        <tr class="row1">
            <td colspan="6" style="text-align: center;"><button name="save" value="save" type="submit">Search</button></td>
        </tr>
  </table>   

		<p align="left"><a href="<?php echo "index.php?route=HRModule/Master/incentive_calculation".$rurl.'&action=AddNew'?>"><input type="button" name="Create" value="Add New" class="search" /></a></p>

    <div id ="employee_detail">
    <table width="100%" cellspacing="0" cellpadding="3" border="1" align="center">
    <tbody>
    <tr>
      <th width="4%">S. No.</th>
      <th width="10%">Branch</th>    
      <th width="10%">Emplyee Code</th>
      <th>Emplyee Name</th>
      <th width="10%">Monthly CTC</th>
      <th width="10%">Incentive Days</th>
      <th width="10%">Incentive Amount</th>
    </tr>
    <?php 

if(isset($_REQUEST['save']))
{

    
   
  if($_REQUEST['branch']!='0')
  {
        $filter[]="branch='".$_REQUEST['branch']."'";
  }
  
  if($_REQUEST['financial_year_id']!='') 
  {
  $filter[]="eff_fin_year='".$_REQUEST['financial_year_id']."'";
  }
   
  $filter[]="1=1";
  //print_r($filter);
  if(isset($filter))
  {
            $filter1=implode(" and " ,$filter);
                // Dealer And User Check
           $incent="select * from hr_insentive_calculation  where $filter1 order by id";
}
}
else{ 

 $incent="select * from hr_insentive_calculation order by id";
}    
    $i=1;
    $IncentRes=DB_query($incent,$db);                            
    while($insentRow=DB_fetch_array($IncentRes)){?>
<tr>
  <td><?php echo $i; ?></td> 
  <td><?php echo $s->GetFieldValue('locations',"loccode='".$insentRow['branch']."'",'locationname');?></td>
  <td><?php echo $s->GetFieldValue('empmaster',"id='".$insentRow['empid']."'",'emp_code');?></td>
  <td><?php echo $s->GetFieldValue('empmaster',"id='".$insentRow['empid']."'",'emp_name');?></td>
  <td style="text-align:right;"><?php echo $insentRow['month_ctc'];?></td>
  <td style="text-align:right;"><?php echo $insentRow['incentive_days'];?></td>
  <td style="text-align:right;"><?php echo $insentRow['incentive_amount']; ?></td>
</tr>
<?php $i++; } ?>
</table>
 </div>
    
</form>
   </div>
   </tbody>

<script>
   

function get_rating_data(str)
{  
  //  alert(str);
 var branch=document.getElementById("branch").value;
  if(str=='' )
      {
          alert("Please Select Date ");          
          document.getElementById("financial_year_id").focus();
      }
      else{
  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)
    {
    document.getElementById("employee_detail").innerHTML=xmlhttp.responseText;
    }
  }

xmlhttp.open("POST","ajax_incentive_calculation.php?num="+str+"&branch="+branch,true);
xmlhttp.send();
}
}


function ajax_getemployee_detail(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);
       var data=xmlhttp.responseText.split("__");
       document.getElementById("emp_code").value=data[0];
       document.getElementById("emp_sal").value=data[1];
       document.getElementById("growth").value=data[2];
       document.getElementById("appraisal_rate").value=data[3];
       document.getElementById("revised_sal").value=data[4];
    }
  }
xmlhttp.open("POST","ajax_getemployee_detail.php?emp="+str.value,true);
xmlhttp.send();
}

</script>
