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

if($_REQUEST['save']!='')
{

$_REQUEST['hr_incentive_master']['branch']=$_REQUEST['branch'];
$_REQUEST['hr_incentive_master']['eff_fin_year']=$_REQUEST['financial_year_id'];
$_REQUEST['hr_incentive_master']['key_staff']=$_REQUEST['Staff_type'];  
$_REQUEST['hr_incentive_master']['prepared']=$_REQUEST['prepared'];   
$_REQUEST['hr_incentive_master']['created_by']=$_SESSION['UserID'];  
$_REQUEST['hr_incentive_master']['created_date']=date('Y-m-d');
$_REQUEST['hr_incentive_master']['CompanyId']=$_SESSION['ACGCompanyId'];
$_REQUEST['hr_incentive_master']['approved']=$_REQUEST['approved'];
$s->RecordInsert('hr_incentive_master',$_REQUEST['hr_incentive_master']); 
$last_id=DB_Last_Insert_ID($db,'hr_incentive_master','id');

 for($k=0;$k<count($_REQUEST['rate']);$k++)
      {
        if($_REQUEST['rate'][$k]!='')
        {
        foreach($_REQUEST['apr_id'][$_REQUEST['per_id'][$k]] as $key=>$value)  
        {
        $dataEmpSal['hr_incetive_master_id']=$last_id;
        $dataEmpSal['hr_appraisal_master_details_id']=$_REQUEST['per_id'][$k];      
        $dataEmpSal['apprisal_policy_master_detail_id']=$value;
        $dataEmpSal['result']=$_REQUEST['result'][$_REQUEST['per_id'][$k]][$key];
        $s->RecordInsert('hr_incentive_master_detail',$dataEmpSal);
          }
        }
      }

   // $s->pageLocation("index.php?route=TaskMgt/perf_task_assign_index".$rurl);
}


?>
<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;
}
</style>
<div class="body_contain">
<div class="tab_div">
<h1>Incentive Master</h1>
<form method="post" action="" onsubmit="return validation() ;">
   <table cellpadding="3" cellspacing="0" width="100%" border="0">
        <tr class="row1">
            <td width="13%"><strong>Branch</strong></td>
            <td width="35%"><select name="branch" id="branch" style="width:98%;" onchange="removefinyear();">
                 <option value="0">All</option>
                 <?php $locsql= DB_query("select * from locations where mst_companyid='".$_SESSION['ACGCompanyId']."' and loccode in ('".$_SESSION['AssignedBranch']."')",$db);
                while($locres=DB_fetch_array($locsql)) {  ?>
                 <option value="<?php echo $locres['loccode']; ?>"><?php echo $locres['locationname']; ?></option> 
                 <?php  } ?>
                </select></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>Staff Type</strong></td>
            <td><select name="Staff_type" id="Staff_type" style="width:98%;">
                    <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><strong>Prepared By</strong></td>-->
            <input type="hidden" name="prepared" id="prepared" style="width:98%;" value="<?php echo  $s->GetFieldValue('www_users'," id='".$_SESSION['UserID']."' " ,'realname'); ?>"></td>
            <td><strong>Approved By</strong></td>
            <td><input type="text" style="width:98%;" name="approved" id="approved" value=""></td>
        </tr>        
		</table>
    <br>
  <div id="rating_data">      
  <table width="100%" border="1" align="center" cellpadding="3" cellspacing="0" style="border:#808080 1px solid;">
    <tr>    
      <th width="10%" style="text-align:center;"><strong>Rating</strong></th>
      <th style="text-align:center;"><strong>Description</strong></th>
      <?php $SQL1="select * from apprisal_policy_master_detail order by id ASC";
      $result1=DB_query($SQL1,$db,$ErrMsg);
      $i=0;
      while($resrow1=DB_fetch_array($result1)) { ?>
      <th width="10%" style="text-align:center;"><strong>over <?php echo number_format($resrow1['revenue_ach']); ?>%</strong></th>
      <?php } ?>
    </tr>
    <tr>   
      <td><input type="text" name="rate[<?php echo $i; ?>]" style="width:98%;"></td>
      <td><input type="text" name="rate_desc[<?php echo $i; ?>]" style="width:98%;"></td>
      <td><input type="text" name="over_100[<?php echo $i; ?>]" style="width:98%;"></td>
      <td><input type="text" name="over_110[<?php echo $i; ?>]" style="width:98%;"></td>
      <td><input type="text" name="over_120[<?php echo $i; ?>]" style="width:98%;"></td>
      <td><input type="text" name="over_140[<?php echo $i; ?>]" style="width:98%;"></td>
    </tr>  
  </table>	
  </div>

		  <p align="center"><button name="save" value="save" type="submit">Save</button> 
         <a href="index.php?route=HRModule/Master/incentive_master<?php echo $rurl?>"><button name="cancel" value="" type="button" >Cancel</button></a></p>
</form>

</div>
</div>

<script>
   




 function validation()
 {

 var branch=document.getElementById("branch").value;
  var financial_year_id=document.getElementById("financial_year_id").value;
 

   if(branch=='')
      {
          alert("Please select Branch");
        
          document.getElementById("branch").focus();
          return false;
      }
     if(financial_year_id=='')
      {
          alert("Please select Effective financial Year");
        
          document.getElementById("financial_year_id").focus();
          return false;
      }

 }  



function removefinyear(){
 //var num= document.getElementById("branch").value;
 document.getElementById("financial_year_id").value='';
 document.getElementById("financial_year_id").focus();
    //financial_year_id
}

function generate_row()
{  
  var num= document.getElementById("app_num").value;
  if(num==0)
      {
          alert("Can not be zero");
          document.getElementById("app_num").value="";
          document.getElementById("app_num").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("all_data").innerHTML=xmlhttp.responseText;
    }
  }

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

 
function get_rating_data(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("rating_data").innerHTML=xmlhttp.responseText;
    }
  }

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


</script>
<SCRIPT language=Javascript>

       function isNumberKey(evt)
       {
          var charCode = (evt.which) ? evt.which : event.keyCode;
          if (charCode != 46 && charCode > 31 
            && (charCode < 48 || charCode > 57))
             return false;

          return true;
       }
  function checkfrmsal(str)
  {
      
      var id=str.id;
      if(str.value==""){
          
            document.getElementById(id).value=0;
      }
      else
          {
              var val=parseFloat(str.value);
       document.getElementById(id).value=val.toFixed(2);       
          }
  }
  
  function checktosal(str)
  {
      var val=parseFloat(str.value);
      var id=str.id;
     var from=document.getElementById("fromsal").value;
     if(from!=""){
      if(str.value=='')
       document.getElementById(id).value=0;
      else
          {
              if(parseFloat(document.getElementById("fromsal").value)>=val)
                {
                  alert("From salary must be less than To Salary");
                    document.getElementById(id).value=0;    
                }  
                else
                {
                     document.getElementById(id).value=val.toFixed(2);
                }
          }
     }
     else
         {
            alert("Please enter From Salary First ");
            document.getElementById(id).value=0;
            document.getElementById("fromsal").focus();
         }
  }
    </SCRIPT>
