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

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

 
   // DB_query("insert into perf_year_appraisal (branch,appraisal_no,eff_fi_year,prepared,approved,created_by,created_date,companyid,apprisal_policy_master_detail_id) value('".$_REQUEST['branch']."','".$final_string."','".$_REQUEST['financial_year_id']."','".$_REQUEST['prepared']."','".$_REQUEST['approved']."','".$_SESSION['UserID']."','".date('Y-m-d')."','".$_SESSION['ACGCompanyId']."','".$_REQUEST['achivment']."')",$db);  

 //$last_id=  DB_Last_Insert_ID($db, perf_year_appraisal, id);;

  date_default_timezone_set('Asia/Calcutta');
    for($i=0;$i<count($_REQUEST['p_a_id']);$i++)
    {
            
      
        if(isset($_REQUEST['p_a_id'][$i]))
        {
                     
                     $applicable_date=$_REQUEST['ap_year']."-".$_REQUEST['ap_month']."-01";
        DB_query("insert into hr_insentive_calculation (hr_year_appraisal_detail_id,empid,month_ctc,incentive_days,incentive_amount,created_by,created_date,branch,eff_fin_year,appl_from_month,appl_from_year,key_staff,applicable_date) value('".$_REQUEST['p_a_id'][$i]."','".$_REQUEST['empid'][$i]."','".$_REQUEST['monthctc'][$i]."','".$_REQUEST['insent_days'][$i]."','".$_REQUEST['insent_amout'][$i]."','".$_SESSION['UserID']."','".date('Y-m-d H:i:s')."','".$_REQUEST['branch']."','".$_REQUEST['financial_year_id']."','".$_REQUEST['ap_month']."','".$_REQUEST['ap_year']."','".$_REQUEST['staff_type']."','".$applicable_date."') ",$db); 

    
        }
    }
    //die;
    //$s->pageLocation("index.php?Application=performance&modid=".$_REQUEST['modid']);  
}
?>
<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" cellspacing="0" cellpadding="3">
        <tr class="row1">
            <td width="13%"><strong>Branch</strong></td>
            <td width="20%">
                <select name="branch" id="branch" style="width:98%;" onchange="get_rating_data();">
                    <option value="0">---select--</option>
                    	<?php $Sitesql="select * from locations where  CompanyId='".$_SESSION['ACGCompanyId']."' and loccode in('".$_SESSION['AssignedBranch']."')";
                    	$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%"><strong>Staff Type</strong></td>
                <td width="20%">
                <select name="staff_type" id="staff_type" style="width:98%;" onchange="get_rating_data();">
                    <option value="0">--Select--</option>
                    <option value="k">Key Staff</option>
                    <option value="s">Support Staff</option>
                    <option value="os">Other Staff</option>
                    <option value="oss">Other Support Staff</option>                   
                    </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><strong>Applicable from month</strong></td>
            <td>
                <select name="ap_month" id="ap_month" style="width:48%; background:#f8f8f8; float:left; margin-right:3px;" onchange="get_rating_data(this.value);">
                  <option value="1">Jan</option>
                  <option value="2">Feb</option>
                  <option value="3">March</option>                 
                  <option value="4">Apr</option>
                  <option value="5">May</option>
                  <option value="6">June</option>
                  <option value="7">July</option>
                  <option value="8">Aug</option>
                  <option value="9">Sept</option>
                  <option value="10">Oct</option>
                  <option value="11">Nov</option>
                  <option value="12">Dec</option>                
              </select>  
              <select name="ap_year" id="ap_year" style="width:48%; background:#f8f8f8; float:left;" onchange="get_rating_data(this.value);">
                <option value="2015">2015</option>
                <option value="2016">2016</option>
                <option value="2017">2017</option>                
                <option value="2018">2018</option>
                <option value="2019">2019</option>
                <option value="2020">2020</option>
                <option value="2021">2021</option>
                <option value="2022">2022</option>
                <option value="2023">2023</option>
                <option value="2024">2024</option>
                <option value="2025">2025</option>
                <option value="2026">2026</option>                
              </select>          
            </td>
            <td colspan="4"></td>
        </tr>
    </table>
    <br>
        <div id ="employee_detail">

    </div>
    <p align="center"></p>
    
</form>
   </div>
   </div>
<script>
   
   function setyear(){
    document.getElementById("financial_year_id").value='';
       document.getElementById("branch").focus();
   }

function get_rating_data(str)
{  
  //  alert(str);
 var str = document.getElementById("financial_year_id").value
 var branch=document.getElementById("branch").value;
 var staff_type=document.getElementById("staff_type").value;
  if(branch=="0")
  {
    alert("Please Select branch ");          
      document.getElementById("branch").focus();
      document.getElementById("financial_year_id").value='';
      return false;
  }
   if(staff_type=="0")
  {
    alert("Please Select Staff Type ");          
      document.getElementById("staff_type").focus();
      document.getElementById("financial_year_id").value='';
      return false;
  }

  if(str=='' )
      {
          alert("Please Select Financial Year ");          
          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+"&staff_type="+staff_type,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>
