<?php include("parent/callMe.php"); ?>
<?php  include("sessioncheck.php");

$branch=$_SESSION['branch'];
$user_id=$_REQUEST['emp'];

$m->where("user_id", $_REQUEST['emp']);
$m->where ("branch_id", $_SESSION['branch']);
$userName = $m->get("edu_user_config");


 ?>
<!DOCTYPE html>
<html lang="en">
  <head>
    
    <title>Employee Advance Salary | EduPortal</title>
    <?php include('RootMe/css_links.php');?>
  

  </head>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

 
  <body class="nav-md">
    <div class="container body">
      <div class="main_container">
        <div class="col-md-3 left_col">
     
            <?php include('RootMe/sidebar.php');?>

              <?php include('RootMe/header.php');?>
     
        <!-- page content -->
          <div class="right_col" role="main">
          <div class="row" style="background-color: white;">
           
  <section class="add_sub_agent" id="table_sub_agent">
  <div class="container">

 <div class="" style="margin-top:10px;">
   
      

                                    <!-- page content -->
        
  <div class="">
    
      <h3 style="margin-left: 15px;">Advance Salary (<?php echo $userName[0]['user_fname'];?>)</h3>
            <div class="row">
          
              <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="x_panel">
            
                  <div class="x_content">
          
     
                    <form action="<?php echo DOMAIN.AgentDirectory;?>parent/InsertMe.php" method="post" enctype="multipart/form-data" class="form-horizontal form-label-left" >

                    <?php if (!isset($_REQUEST['advup'])) { ?>
                      
                      <input type="hidden" name="action" value="Add_Emp_Advance_Salary" />

                    <input type="hidden" name="user_id" value="<?php echo $_REQUEST['emp'];?>">
                    <?php } else { 

                      $sql = "SELECT * FROM eduportal_user_advance_salary where branch_id='$branch' and user_id='$user_id' and id_advance_salary=".$_REQUEST['advup'];
                      $userAdvanceSalariesUpdate = $m->query($sql);

                      ?>

                      <input type="hidden" name="action" value="Update_Emp_Advance_Salary" />

                    <input type="hidden" name="user_id" value="<?php echo $_REQUEST['emp'];?>">

                    <input type="hidden" name="id_advance_salary" value="<?php echo $_REQUEST['advup'];?>">

                    <?php } ?> 
                    
          
              <div class="item form-group">
                        
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="email">

                         Session <span class="required">*</span>
                        </label>
                        
                        <div class="col-md-6 col-sm-6 col-xs-12">
                          <select name="session" class="form-control" >

                        <?php

                         $match;
                          if(!isset($_REQUEST['session'])){
                            $match=$_SESSION['current_session'];
                          }else { $match=$_REQUEST['session']; }
                         
                        
                        $WorkAssignList = $m->get("edu_session_config");
                        foreach($WorkAssignList as $WorkAssignListVal)
                        { ?>

                           <option <?php if($match==$WorkAssignListVal['session_id']){echo 'selected';}?> value="<?php echo $WorkAssignListVal['session_id']; ?>"><?php echo $WorkAssignListVal['session_year']; ?></option>


                                <?php
                        } ?>

                        </select>
                        </div>

<br><br>


               <label class="control-label col-md-3 col-sm-3 col-xs-12" for="email">

                         Month <span class="required">*</span>
                        </label>
                        
                        <div class="col-md-6 col-sm-6 col-xs-12">
                          <select name="mnth" class="form-control" >

                        <?php

                        $qr = "select * from  employee_payroll where branch_id='$branch' and user_id='$user_id' order by payroll_id  desc limit 1";
                        $user_salary =  $m->query ($qr);

                        $m->where("Month_Id", $user_salary[0]['month_id']);
                        $MonthName = $m->get("eduportal_month_config");
                         ?>

                           <option <?php if($userAdvanceSalariesUpdate[0]['session_id']==$MonthName[0]['Month_Id']){echo 'selected';}?> value="<?php echo $MonthName[0]['Month_Id']; ?>"><?php echo $MonthName[0]['Month_Name']; ?></option>
                        

                        </select>
                        </div>

<br><br>



             <label class="control-label col-md-3 col-sm-3 col-xs-12" for="email">

                         Date <span class="required">*</span>
                        </label>
                        
                        <div class="col-md-6 col-sm-6 col-xs-12">
                          <input type="date" value="<?php echo $userAdvanceSalariesUpdate[0]['salary_date'];?>" name="advance_salry_date" class="form-control">
                        </div>

<br><br>
                          
                         <label class="control-label col-md-3 col-sm-3 col-xs-12" for="email">

                        	Advance Salary <span class="required">*</span>
                        </label>
                        
                        <div class="col-md-6 col-sm-6 col-xs-12">
                          <input class="form-control col-md-8 col-xs-12" type="number"  name="advance_salary" placeholder="eg 25000 " value="<?php echo $userAdvanceSalariesUpdate[0]['user_advance_salary']; ?>">
                        </div>
<br><br>
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="email">

                          Remarks <span class="required">*</span>
                        </label>
                        
                        <div class="col-md-6 col-sm-6 col-xs-12">
                          <input class="form-control col-md-8 col-xs-12"  name="remarks" placeholder="Any reasons " value="<?php echo $userAdvanceSalariesUpdate[0]['remarks']; ?>">
                        </div>

                      </div>              
                   
                     

                      <div class="form-group">
                        <div class="col-md-6 col-md-offset-7">
                          
                          <button id="send" type="submit" class="btn btn-primary" >Save Record</button>
                         
                        </div>
                      </div>

                    </form>
              
          </div>
                </div>
              </div>
            </div>
          </div>
       
        

        <!-- /page content -->



  </div>
  <div class="clearfix"></div>
</section>           

<?php



$sql = "SELECT * FROM eduportal_user_advance_salary where branch_id='$branch' and user_id='$user_id' ";


$userAdvanceSalaries = $m->query($sql);
 //print_r($categories);
 
     ?>




     <div class="t col-md-12 col-sm-12 col-xs-12">
        <h3>Advance Salary List<small> (<?php echo count($userAdvanceSalaries);?> records)</small></h3>
     </div>

            
          
    <form action="emp_advance_salary.php?<?php echo session_id().session_id().session_id().session_id().session_id(); ?>&from=<?php echo $_GET['from'];?>&to=<?php echo $_GET['to'];?>">

                
                
          <div class="col-md-12">      
                 <div class="col-md-3 col-sm-12 col-xs-12" style="padding:8px; float:left;"  id="col1">
                 <div class="form-group ">

                 <label class="required"> Session</label>
                 <select name="session" class="form-control" >

                        <?php

                         $match;
                          if(!isset($_REQUEST['session'])){
                            $match=$_SESSION['current_session'];
                          }else { $match=$_REQUEST['session']; }
                         
                        
                        $WorkAssignList = $m->get("edu_session_config");
                        foreach($WorkAssignList as $WorkAssignListVal)
                        { ?>

                           <option <?php if($match==$WorkAssignListVal['session_id']){echo 'selected';}?> value="<?php echo $WorkAssignListVal['session_id']; ?>"><?php echo $WorkAssignListVal['session_year']; ?></option>


                                <?php
                        } ?>

                        </select>
                       
                  </div>
                  </div>                      
             

                  <div class="col-md-3 col-sm-12 col-xs-12" style="padding:8px; float:left;"  id="col2">

                       <div class="form-group ">

                          <label class="required"> Employee Name</label>
                              <select name="emp" class="form-control" >

                        <?php
                        
                         
                          $m->where("status", '0');
                          $m->where("branch_id", $_SESSION['branch']);                          
                          $m->orderBy("user_id", 'asc');
                          $WorkAssignList = $m->get("edu_user_config");
                        foreach($WorkAssignList as $WorkAssignListVal)
                        { ?>

                           <option <?php if($_REQUEST['emp']==$WorkAssignListVal['user_id']){echo 'selected';}?> value="<?php echo $WorkAssignListVal['user_id']; ?>"><?php echo $WorkAssignListVal['user_fname']; ?></option>


                                <?php
                        } ?>

                        </select>
                       
                          </div>
                  </div>  
                  
                  
                  <div class="col-md-1 " style="padding:8px;">
                <div class="form-group ">
                   <input type="hidden" name="addaccountAdmin" value="1">
                <button type="submit" class="btn btn-primary" style="margin-top: 24px;">Search</button>
                </div>
              </div> 
                             
        </div>            
      </form>          
    

<?php  if(isset($_SESSION['addsuccessexp'])){?>

<div id="snackbar"><script> toastFunction();</script> Your Recored is Sucessfully Added</div>

<?php  unset($_SESSION['addsuccessexp']); }?>


          
          <?php  if(isset($_SESSION['upsuccessexp'])){?>


            <div class="alert alert-success" id="msg">
             <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
              <strong>Success!</strong> Record is updated successfully...
            </div>


          <?php  unset($_SESSION['upsuccessexp']); }?>
          

          <?php  if(isset($_SESSION['deleteexp'])){?>


            <div class="alert alert-danger" id="msg">
             <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
              <strong>Danger!</strong> Record is deleted successfully...
            </div>


          <?php  unset($_SESSION['deleteexp']); }
          ?>

<style type="text/css">

.center {
  margin-left: auto;
  margin-right: auto;
}

</style>
<table id="datatable" class="table table-striped table-bordered center"style="background-color: white;">
                      <thead>
                        <tr>
                          <th width="1%">S.No</th>
                          <th width="10%">dates</th>
                          <th width="10%">Advance Amount</th>  
                          <th width="10%">Remarks</th>
                          <th width="10%">Action</th>                         
                          
                         

                        </tr>
                      </thead>
                      <tbody>

                        
<?php  
$count=1;
$date= date("Y-m-d");
$branch=$_SESSION['branch'];
$userID=$_REQUEST['emp'];

$sessionidid;
    
    if($_GET["session"]!=NULL ){

      $sessionidid= $_GET["session"];
    }
    else{
      
      $sessionidid= $_SESSION['current_session'];
    }

foreach ($userAdvanceSalaries as $userAdvanceSalary) {
  
   
?>
                        <tr>
                          <td style="text-align:center;"><?php echo $count; $count++;?></td>
                          <td><?php echo date("d-M-Y",strtotime($userAdvanceSalary['salary_date']));?></td>
                          <td><?php echo $userAdvanceSalary['user_advance_salary'];?></td>
                          <td><?php echo $userAdvanceSalary['remarks'];?></td>
                          <td>

                            <a style="padding: 0px 5px; font-size:14px;"  href="emp_advance_salary.php?<?php echo session_id().session_id().session_id().session_id().session_id();?>&advup=<?php echo $userAdvanceSalary['id_advance_salary'];?>&emp=<?php echo $_REQUEST['emp'];?>" style="cursor:pointer;"  class="btn btn-success"> <i class="fa fa-pencil" aria-hidden="true"></i></a>


                            <a href="<?php echo DOMAIN.AgentDirectory;?>parent/InsertMe.php?deleteAdv=<?php echo $userAdvanceSalary['id_advance_salary'];?>&user_id=<?php echo $_REQUEST['emp'];?>&action=Delete_Emp_Advance_Salary" style="padding: 0px 5px; font-size:14px;" onClick="return confirm('Are you sure you want to delete this record');"  class="btn btn-danger"><i class="fa fa-remove"></i> </a>

                          </td>                          

                        </tr>
<?php } ?>
                      

                      </tbody>
                    </table>
           
          </div>
        </div>

            </div>
          </div>
        </div>
        <!-- /page content -->
  

    
  <?php include('RootMe/js_linksscript.php');?>
  </body>
</html>
<script>
function toastFunction() {
  var x = document.getElementById("snackbar");
  x.className = "show";
  setTimeout(function(){ x.className = x.className.replace("show", ""); }, 3000);
}
</script>