<?php
   include('session.php');
   include('header1.php');

// start role specific 
$user_role = $_SESSION['role'];
$companyID = $_SESSION['companyselect'];



?>


<main role="main" class="col-md-9 ml-sm-auto col-lg-10 px-4">
  <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
    <h1 class="h2">Add Employee</h1>
    <div class="btn-toolbar mb-2 mb-md-0">
      
    </div>
  </div>

  <form method = "POST" action="addEmployee1.php">

    <?php

    $sqlGetLatestFileNo = "SELECT employeefileno
      FROM employees
      WHERE companyid = $companyID
      ORDER BY employeeid DESC
      LIMIT 1;";

    $resultLatestFileNo = mysqli_query($db,$sqlGetLatestFileNo);

    $countFileNumber = mysqli_num_rows($resultLatestFileNo);

    $LATESTFILENO = "";

    if ($countFileNumber !== 0) {

            while ($fileno = mysqli_fetch_array($resultLatestFileNo)) {

              $LATESTFILENO = "<i>Latest: " . $fileno['employeefileno'] . "</i>";
            }

          } else {
            $LATESTFILENO = "No employee on records";
          }

    ?>
    <div class="alert alert-danger" role="alert" id = "errorbar" style="display: none;"></div>
    <input type = "hidden" name = "companyselectid" value = "<?php echo $companyID; ?>">
    <p>File Number* <?php echo $LATESTFILENO; ?>
      <input type="text" name="employee_fileno" id = "nu_employeefileno" required class="form-control"> 
    </p>

    <p>Surname*
      <input type="text" name="employee_surname" required class="form-control"> 
    </p>

    <p>Maiden Name
      <input type="text" name="employee_maiden_name" class="form-control"> 
    </p>

    <p>Name*
      <input type="text" name="employee_name" required class="form-control"> 
    </p>

    <p>National Identity Card*
      <input type="text" name="employee_nic" required class="form-control"> 
    </p>

    <p>Citizen of Mauritius?*
      <select name="employee_citizenship" required class="form-control">
        <option value="Y">YES</option>
        <option value="N">NO</option>
      </select>
    </p>

    <p>TAN Number
      <input type="text" name="employee_tan" class="form-control"> 
    </p>

    <p>Date of Birth*
      <input type="date" name="employee_dob" required class="form-control"> 
    </p>

    <p>Gender*
      <select name="employee_gender" id="employee_gender" class="form-control" required>
        <option value="Male">Male</option> 
        <option value="Female">Female</option>
      </select>
    </p>

    <p>Joining Date*
      <input type="date" name="employee_joining_date" required class="form-control"> 
    </p>

    <p>PAYE Rate*
      <select name="employee_paye_rate" id="employee_paye_rate" class="form-control" required>
        <option value="10">10%</option> 
        <option value="12.5">12.5%</option> 
        <option value="15">15%</option>
      </select>
    </p>

    <p>EDF Amount*
      <input type="numeric" name="employee_edf_amount" required class="form-control"> 
    </p>


    <p>EDF Months Value*
      <select name="employee_edf_months" id="employee_edf_months" class="form-control" required>
        <option value="1">1</option>
        <option value="2">2</option>
        <option value="3">3</option>
        <option value="4">4</option>
        <option value="5">5</option>
        <option value="6">6</option>
        <option value="7">7</option>
        <option value="8">8</option>
        <option value="9">9</option>
        <option value="10">10</option>
        <option value="11">11</option>
        <option value="12">12</option>
        <option value="13" selected>13</option>
      </select>
    </p>

    <p>Full Time*
      <select name="employee_fulltime" required class="form-control">
        <option value="Y">YES</option>
        <option value="N">NO</option>
      </select>
    </p>

    <p>Corporate Approved Pension Scheme*
      <select name="employee_pension" required class="form-control">
        <option value="Y">YES</option>
        <option value="N">NO</option>
      </select>
    </p>

    <p>Employee Contribution Code*
      <select name="employee_contributioncode" required class="form-control">
        <option value="V">V</option>
        <option value="X">X - Excempt Employee (Age > 18)</option>
        <option value="G">G - PH Employee having aggregate monthly wage bill <= MUR 3000</option>
        <option value="S">S - Normal Employee</option>
        <option value="N">N - Public Sector Employee</option>
        <option value="D">D - Self Employed</option>
      </select>
    </p>

    <input type="submit" id="butsaveNU" disabled="disabled">

    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>

    <script type="text/javascript">
    
    $(document).ready(function(){
         $("#nu_employeefileno").keyup(function(){
               var employeefileno = $(this).val().trim();
               var companyid = <?php echo $companyID ?>;
            
            if(employeefileno != ''){

               $.ajax({
                  url: 'checkEmployee.php',
                  type: 'post',
                  data: {employeefileno: employeefileno,companyid: companyid},
                  success: function(response){
                      //$(\"#button_response\").html(response);
                    if(response == "OK") {
                      document.getElementById("butsaveNU").disabled = false;
                      document.getElementById('errorbar').setAttribute('style','display:none;');
                    } else if (response == "KO"){
                      document.getElementById("butsaveNU").disabled = true;
                      document.getElementById('errorbar').setAttribute('style','');
                      document.getElementById('errorbar').innerHTML = "User Already on System!";
                    }
                   }
               });
            }else{
               
            }

          });

       });
  </script>



  </form>
  <br>
  <br>

        </main>
      </div>
    </div>

<?php
   include('footer1.php');
?>