<?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_appraisal_master']['branch']=$_REQUEST['branch'];
$_REQUEST['hr_appraisal_master']['valid_from']=FormatDateForSQL($_REQUEST['validfrom']);
$_REQUEST['hr_appraisal_master']['valid_to']=FormatDateForSQL($_REQUEST['validto']);
$_REQUEST['hr_appraisal_master']['prepared']=$_REQUEST['prepared'];  
$_REQUEST['hr_appraisal_master']['period']=$_REQUEST['period'];   
$_REQUEST['hr_appraisal_master']['increment_type']=$_REQUEST['inc_type']; 
$_REQUEST['hr_appraisal_master']['salary_from']=$_REQUEST['fromsal']; 
$_REQUEST['hr_appraisal_master']['salary_to']=$_REQUEST['tosal'];  
$_REQUEST['hr_appraisal_master']['created_by']=$_SESSION['UserID'];  
$_REQUEST['hr_appraisal_master']['created_date']=date('Y-m-d');
$_REQUEST['hr_appraisal_master']['CompanyId']=$_SESSION['ACGCompanyId'];
$_REQUEST['hr_appraisal_master']['approved']=$_REQUEST['approved'];
//$_REQUEST['hr_appraisal_master']['eff_fin_year']=$_REQUEST['finacial_year'];

//$sql= $s->insertRecord('hr_applcnt_rgstn',$_REQUEST['hr_applcnt_rgstn'])  ;
   $condd="id='".$_REQUEST['id']."'";
 $s->RecordEdit('hr_appraisal_master',$_REQUEST['hr_appraisal_master'],$condd); 


$condition="hr_appraisal_master_id='".$_REQUEST['id']."'";
//$s->DeleteRecord(perf_appraisal_master_details,$condition);
 for($k=0;$k<count($_REQUEST['rate']);$k++)
      {
        if($_REQUEST['rate'][$k]!='')
        {
          if($_REQUEST['rate_id'][$k]!='')
          {
          
        $dataEmpSal['hr_appraisal_master_id']=$_REQUEST['id'];
        $dataEmpSal['rating']=$_REQUEST['rate'][$k];
        $dataEmpSal['rating_desc']=$_REQUEST['rate_desc'][$k];
        $dataEmpSal['appraisal']=$_REQUEST['appraisal'][$k];
        $condd1="id='".$_REQUEST['rate_id'][$k]."'";
        $s->RecordEdit('hr_appraisal_master_details',$dataEmpSal,$condd1); 
      }
        
        else{
          $dataEmpSal['hr_appraisal_master_id']=$_REQUEST['id'];
          $dataEmpSal['rating']=$_REQUEST['rate'][$k];
          $dataEmpSal['rating_desc']=$_REQUEST['rate_desc'][$k];
          $dataEmpSal['appraisal']=$_REQUEST['appraisal'][$k];
          $s->RecordInsert('hr_appraisal_master_details',$dataEmpSal);
        }
        }
      }
     
   
    $s->pageLocation("index.php?route=HRModule/Master/perf_appraisal_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;
}

<?php $appregil= DB_query("select * from hr_appraisal_master where id='".$_REQUEST['id']."'",$db);
          $RData=DB_fetch_array($appregil);
?>
</style>
<div class="body_contain">
<div class="tab_div">
<h1>Appraisal Rating Policies</h1>
<form method="post" action="">
   <table cellpadding="3" cellspacing="0" width="100%" border="0">
        <tr class="row1">
            <td><strong>Branch</strong></td>
            <td colspan="3"><select name="branch" id="branch" disabled="disabled">
                 <option value="0">All</option>
                 <?php $locsql= DB_query("select * from locations where mst_companyid='".$_SESSION['ACGCompanyId']."' and loccode in ('".$_SESSION['AssignedBranch']."') order by locationname",$db);
                while($locres=DB_fetch_array($locsql)) {  ?>
                 <option value="<?php echo $locres['loccode']; ?>" <?php if($RData['branch']==$locres['loccode']){ echo "selected"; }?>><?php echo $locres['locationname']; ?></option> 
                 <?php  } ?>
                </select></td>
                <td><strong>Effective Financial Year</strong></td>
                <td colspan="3">
                  <select name="finacial_year" id="finacial_year" disabled="disabled">
                  <?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 if($RData['eff_fin_year']==$yearRow['id']){ echo "selected"; }?> ><?php echo ConvertSQLDate($yearRow['year_start'])." - TO - ".ConvertSQLDate($yearRow['year_end']); ?></option>
                <?php } ?>
</select>
                  <!--<input type="text"  readonly  name="finacial_year" value="<?php  echo ConvertSQLDate($RData['valid_from'])." TO ". ConvertSQLDate($RData['valid_to']); ?>">-->
                <input type="hidden" class="datepicker" name="validfrom" value="<?php  echo ConvertSQLDate($RData['valid_from']);  ?>">
                  <input type="hidden" class="datepicker" value="<?php echo ConvertSQLDate($RData['valid_to']); ?>" name="validto">
                  <input type="hidden"  value="<?php  echo $RData['id']; ?>" name="id">
              </td>
                <!--<td><strong>To</strong></td>
                <td><input type="text" class="datepicker" value="<?php  echo ConvertSQLDate($_SESSION['financialYrEnd'])  ?>" name="validto"></td>-->               
        </tr>
        <tr class="row1">
            <td><strong>Period</strong></td>
            <td><select name="period" id="period">
                    <option value="a">Annual</option>
                   <!-- <option value="m">Monthly</option>-->
                </select></td>
            <td><strong>Increment Type</strong></td>
            <td><select name="inc_type" id="inc_type">
                    <option value="s">Salary</option>
                    <!--<option value="i">Incentive</option>-->
                </select></td>
                <td><!--<strong>Prepared By</strong>--></td>
            <td>              
              <input type="hidden" name="prepared" id="prepared" value="<?php 
                if($RData['prepared']!=""){
                  echo $RData['prepared'];
                }else{
              echo  $s->GetFieldValue('www_users'," id='".$_SESSION['UserID']."' " ,'realname');
              }  ?>"></td>
        </tr>
        <tr class="row1">
            <td width="13%"><strong>Salary From Month</strong></td>
            <td width="13%">
              <select name="fromsal">
                <option value="4" <?php if($RData['salary_from']=="4"){ echo "selected" ; } ?>>Apr</option>
                <option value="5" <?php if($RData['salary_from']=="5"){ echo "selected"; } ?>>May</option>
                <option value="6" <?php if($RData['salary_from']=="6"){ echo "selected"; } ?>>June</option>
                <option value="7" <?php if($RData['salary_from']=="7"){ echo "selected"; } ?>>July</option>
                <option value="8" <?php if($RData['salary_from']=="8"){ echo "selected"; } ?>>Aug</option>
                <option value="9" <?php if($RData['salary_from']=="9"){ echo "selected"; } ?>>Sept</option>
                <option value="10" <?php if($RData['salary_from']=="10"){ echo "selected"; } ?>>Oct</option>
                <option value="11" <?php if($RData['salary_from']=="11"){ echo "selected"; } ?>>Nov</option>
                <option value="12" <?php if($RData['salary_from']=="12"){ echo "selected"; } ?>>Dec</option>
                <option value="1" <?php if($RData['salary_from']=="1"){ echo "selected"; } ?>>Jan</option>
                <option value="2" <?php if($RData['salary_from']=="2"){ echo "selected"; } ?>>Feb</option>
                <option value="3" <?php if($RData['salary_from']=="3"){ echo "selected"; } ?>>March</option>  
                </select>


            <!--  <input type="text" onkeypress="return isNumberKey(event)" onblur="javascript:checkfrmsal(this)" name="fromsal" id="fromsal">--></td>
            <td width="10%"><strong>To Month</strong></td>
            <td width="12%">
                <select name="tosal">
                <option value="1" <?php if($RData['salary_to']=="1"){ echo "selected" ; } ?>>Jan</option>
                <option value="2" <?php if($RData['salary_to']=="2"){ echo "selected" ; } ?>>Feb</option>
                <option value="3" <?php if($RData['salary_to']=="3"){ echo "selected" ; } ?>>March</option>                 
                <option value="4" <?php if($RData['salary_to']=="4"){ echo "selected" ; } ?>>Apr</option>
                <option value="5" <?php if($RData['salary_to']=="5"){ echo "selected" ; } ?>>May</option>
                <option value="6" <?php if($RData['salary_to']=="6"){ echo "selected" ; } ?>>June</option>
                <option value="7" <?php if($RData['salary_to']=="7"){ echo "selected" ; } ?>>July</option>
                <option value="8" <?php if($RData['salary_to']=="8"){ echo "selected" ; } ?>>Aug</option>
                <option value="9" <?php if($RData['salary_to']=="9"){ echo "selected" ; } ?>>Sept</option>
                <option value="10" <?php if($RData['salary_to']=="10"){ echo "selected" ; } ?>>Oct</option>
                <option value="11" <?php if($RData['salary_to']=="11"){ echo "selected" ; } ?>>Nov</option>
                <option value="12" <?php if($RData['salary_to']=="12"){ echo "selected" ; } ?>>Dec</option>
               </select>

     <!--<input type="text" onkeypress="return isNumberKey(event)" onblur="javascript:checktosal(this)" id="tosal" name="tosal">--></td>
            <td width="13%"><strong>Approved By</strong></td>
            <td><input type="text" name="approved" id="approved" value="<?php echo $RData['approved']; ?>"></td>
        </tr>  
    </table>
    <br> 

   <table cellpadding="3" cellspacing="0" width="100%" border="1" style="border:#808080 1px solid;"> 
  <tr>
    <!--<td style="text-align:center;"><strong>Growth From (%)</strong></td>
    <td style="text-align:center;"><strong>Growth To (%)</strong></td>-->
    <th width="10%" style="text-align:center;"><strong>Rating </strong></th>
    <th style="text-align:center;"><strong>Description</strong></th>
    <th width="10%" style="text-align:center;"><strong>Appraisal (%)</strong></th>
  </tr>

<?php $appregils= DB_query("select * from hr_appraisal_master_details where hr_appraisal_master_id='".$_REQUEST['id']."' order by id ",$db);
      $j=0;
          while($RDatas=DB_fetch_array($appregils)){
          ?>
          <tr>
      <td><input type="hidden" name="rate_id[<?php echo $j; ?>]" value="<?php echo $RDatas['id'];?>">

        <input type="text" name="rate[<?php echo $j; ?>]" value="<?php echo $RDatas['rating'];?>"></td>
     <td><input type="text" name="rate_desc[<?php echo $j; ?>]" value="<?php echo $RDatas['rating_desc'];?>" ></td>
    <td><input type="text" name="appraisal[<?php echo $j; ?>]" value="<?php echo $RDatas['appraisal'];?>" ></td>
  </tr>
    <?php $j++; } ?>
  <?php 
  for($i=$j;$i<10;$i++){ ?>
  <tr>
    <!--<td><input type="text" name="growthfrom[<?php echo $i; ?>]"></td>
    <td><input type="text" name="growthto[<?php echo $i; ?>]"></td>-->
     <td><input type="text" name="rate[<?php echo $i; ?>]"></td>
     <td><input type="text" name="rate_desc[<?php echo $i; ?>]"></td>
    <td><input type="text" name="appraisal[<?php echo $i; ?>]"></td>
  </tr>
   <?php } ?>
</table>	
		<p align="center">
        <button name="save" value="save" type="submit">Save</button> 
        &nbsp;<a href="index.php?route=TaskMgt/perf_appraisal_index<?php echo $rurl?>">
        <button name="cancel" value="" type="button" >Cancel</button></a></p>
</form>
   
</div>
</div>




<script>
   
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,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>