<?php
   if(isset($_POST['save']))
   {$i=0;$subloanOpening='';
       $loanOpening="insert into emp_loan_opening(site,emp_id,opening_year,opening,advance,dept_id,desig_id) values";
     for($t=0;$t<count($_REQUEST['loan_opening']);$t++)
     {     if($_REQUEST['loan_opening'][$t]!='')
             {
              $emp_id=$_REQUEST['emp_id'][$t];
	         $subloanOpening.=($i==0)?"(":",(";
             $subloanOpening.="'".$_REQUEST['site']."','".$emp_id."','".$_REQUEST['opening_year']."','".$_REQUEST['loan_opening'][$t]."','".$_REQUEST['advance_opening'][$t]."','".$_REQUEST['department']."','".$_REQUEST['designation']."')";
             $i++;}
     }
       if($subloanOpening!='')
        DB_query($loanOpening.$subloanOpening,$db);
	   $s->pageLocation("index.php?route=HRModule/employee_opening_loan".$rurl);
}



  


?>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div"> <h1><?php echo $s->GetFieldValue("modules_form","moduleid='".$_REQUEST['modid']."' and id='".$_REQUEST['frmid']."'","frm_name"); ?></h1>
<form method="post" action="" onsubmit="return validation();">
<table width="100%" border="0" align="center" cellpadding="3" cellspacing="0">
<tr class="row1">
 <td class="tabledata1"><strong>Branch</strong></td>
 <td><select name="site" id="site" style="width:150px;" onchange="showEmployee(this.value)" >
	  <option value="0">---Select---</option>
	  <?php 
		$site_sql=DB_query("Select loccode,locationname from locations",$db);
		while($site_row=DB_fetch_array($site_sql))
		{
		?>
	   <option value="<?php echo $site_row['loccode'];?>"<?php echo ($emp_site==$site_row['loccode']?'selected':'')?>><?php echo $site_row['locationname'];?></option>
			<?php } ?>
		  </select></td>
   <td><strong>Department</strong></td>
   <td><select id="department" name="department" onchange="getDesignation();showEmployee('');">
    <option value="0">---Select---</option>
   <?php
          $resultDept=DB_query("select * from deptmaster where CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
          while($rowDept=DB_fetch_array($resultDept))
          {?>
          <option value="<?php echo $rowDept['id']; ?>"> <?php echo $rowDept['deptname']; ?></option>
          <?php 
          }
        ?>
   </select></td>

    <td><strong>Designation</strong></td>
   <td><select id="designation" name="designation" onchange="showEmployee('');"><option value="0">Select....</option></select></td>  
  <td class="tabledata1"><strong>Opening Year</strong></td>
  <td><select name="opening_year" id="opening_year">
  
  <?php for($t=date("Y");$t>=2000;$t--)
  {
  ?>
  <option value="<?php echo $t; ?>"><?php echo $t; ?> </option>
  <?php } ?> </select>
   </td>
</tr>
</table>
<br>
<div id="show1">


</div>
</form>
<div class="modal1" ></div>

<style type="text/css" >
.button{ background-color:#666666;
color: #FFFFFF;
height:25px;
margin:0px 5px 0px 5px;
border:1px solid #359CA2;
}
.link{ color:#9900CC; font-family:"Comic Sans MS"; letter-spacing:1px
}
</style>

<script>
  function validation()
  {
    if($('#department').val()==0)
    {
      alert('Please select department.');
      return false;
    }
    if($('#designation').val()==0)
    {
      alert('Please select designation.');
      return false;
    }
     return true;

  }

function showEmployee(str)
{
    if($('#site').val()==0)
    {
      alert('Please select Branch.');
      return false;
    }

 $.ajax({
            url : "ajax_employee_loan.php",
            type : "POST",
            data : {             
            site:$('#site').val(),
            dept_id:$('#department').val(),
            desg_id:$('#designation').val()
            },
            success : function(data) {//alert(data);
              
             $('#show1').html(data); 
 
                          }
          });

}

function getDesignation()
{
     $.ajax({
            url : "ajax_emp_loan_edit.php",
            type : "POST",
            data : {
            action:'getDesignation',             
            dept_id:$('#department').val()
            },
            success : function(data) {//alert(data);
              $('#designation').html(data);
                          }
          });
}
</script>
<style>
  .modal1 { 
    visibility:hidden;   
    position:   fixed;
    z-index:    99999;
    top:        0;
    left:       0;
    height:     100%;
    width:      100%;
     background: rgba( 105, 105, 105, .4 ) 
                url('images/loading123.gif') 
                50% 50% 
                no-repeat;
}
body.loading .modal1 {
    visibility: visible;
}
  </style>
  <script type="text/javascript">
$( document ).ajaxStart(function() {
  
     $(".modal1").css("visibility", "visible");
});
$(document).ready(function(){
  $("body").ajaxStop(function(){
     $(".modal1").css("visibility", "hidden");
   });
});

function validate()
{

if(document.getElementById("opening_year").value=='0')
{
 alert("Must Select Opening Year") ;
 return false; 
}
if(document.getElementById("site").value=='0')
{
 alert("Must Select Site") ;
 return false; 
}
return true;

}


</script>
