<?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']!='')
{



  $prefixcode="APP";
  $sql="SELECT app_code from hr_appraisal_master where  CompanyId='".$_SESSION['ACGCompanyId']."' order by id desc limit 0,1";
    $result = DB_query($sql,$db);
    $numrows = DB_num_rows($result);
    if($numrows>0)
    {
      $myrow=DB_Fetch_array($result);
      //$ExplBill=explode("/",$myrow['orderNo']);
      //substr($MaxQut['QutNo'],-5);  
      $Explcode =substr($myrow['app_code'],-5);
      
      //echo $maxval = $ExplBill[2];
       $maxval=$Explcode ;
    }
    else
    {$maxval=0;}
   

    $strChar=$prefixcode;
     $strFinal = $maxval+1;
     $strBothFinal = $strChar.str_pad($strFinal,5,"0",STR_PAD_LEFT);

    // echo $strBothFinal;
    // die;
     
    DB_query("INSERT into hr_appraisal_master (branch,app_code,valid_from,valid_to,prepared,period,increment_type,salary_from,salary_to,created_by,created_date,CompanyId,approved,eff_fin_year) values ('".$_REQUEST['branch']."','".$strBothFinal."','".FormatDateForSQL($_REQUEST['validfrom'])."','".FormatDateForSQL($_REQUEST['validto'])."','".$_REQUEST['prepared']."','".$_REQUEST['period']."','".$_REQUEST['inc_type']."','".$_REQUEST['fromsal']."','".$_REQUEST['tosal']."','".$_SESSION['UserID']."','".date('y-m-d')."','".$_SESSION['ACGCompanyId']."','".$_REQUEST['approved']."','".$_REQUEST['financial_year_id']."')",$db);
    $last_id=DB_Last_Insert_ID($db,'hr_appraisal_master','id');
    for($i=0;$i<count($_REQUEST['appraisal']);$i++)
    {
        if($_REQUEST['appraisal'][$i]!=''){
   DB_query(" INSERT into hr_appraisal_master_details (hr_appraisal_master_id,rating,rating_desc,appraisal) value('".$last_id."','".$_REQUEST['rate'][$i]."','".$_REQUEST['rate_desc'][$i]."','".$_REQUEST['appraisal'][$i]."')",$db);
        }
    }    
   // $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><?php echo $page_title; ?></h1>
<form method="post" action="" onsubmit="return validation() ;">
   <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">
                 <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 echo $locres['locationname']; ?></option> 
                 <?php  } ?>
                </select></td>
                <td><strong>Effective Financial Year</strong></td>
                <td>
                 <select name="financial_year_id" id="financial_year_id" onchange="chekdata(this.value);">
                  <option value=""> --Select--</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>
                <input type="hidden" class="datepicker" name="validfrom" value="<?php  echo ConvertSQLDate($_SESSION['financialYrStart'])  ?>">
                  <input type="hidden" class="datepicker" value="<?php  echo ConvertSQLDate($_SESSION['financialYrEnd'])  ?>" name="validto">
                  <div id="vel"></div>
              </td>
                <!--<td><strong>To</strong></td>
                <td><input type="text" style="width:80%;" 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 echo  $s->GetFieldValue('www_users'," id='".$_SESSION['UserID']."' " ,'realname');   ?>"></td>
            <td></td>
        </tr>
        <tr class="row1">
            <td width="13%"><strong>Salary From Month</strong></td>
            <td width="13%">
              <select name="fromsal">
                <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>
                <option value="1">Jan</option>
                <option value="2">Feb</option>
                <option value="3">March</option>  
              </select><!--  <input type="text" style="width:80%;" 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">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>
                 <!--<input type="text" style="width:80%;" 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=""></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 for($i=0;$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> <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 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 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();
}
}

function chekdata(){

var branch= document.getElementById("branch").value;
var fin_year= document.getElementById("financial_year_id").value;
  if(fin_year==0)
      {
          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)
    {
      //alert(xmlhttp.responseText);
      if(xmlhttp.responseText==1)
      {
        alert("Already Created for this year");
      document.getElementById("financial_year_id").value='';
      document.getElementById("financial_year_id").focus(); 
      }


    }
  }

xmlhttp.open("POST","ajax_check_apprisal.php?num="+fin_year+"&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>
