<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
   <div class="content-header">
      <div class="container-fluid">
         <div class="row mb-2">
            <div class="col-sm-6">
               <h1 class="m-0 text-dark">Add Workforce</h1>
            </div>
            <div class="col-sm-6">
               <ol class="breadcrumb float-sm-right">
                  <li class="breadcrumb-item"><a href="<?php echo base_url() ?>admin/admin/dashboard">Dashboard</a></li>
                  <li class="breadcrumb-item"><a href="#">Workforce Management</a></li>
                  <li class="breadcrumb-item active">Add Workforce </li>
               </ol>
            </div>
         </div>
      </div>
   </div>
   <section class="content">
      <div class="container">
         <div class="row"> 
            <div class="col-md-12 col-lg-12">
               <div class="container-fluid">
                  
                  <div class="card card-default">
                     <div class="card-header">
                        <h3 class="card-title">Add New Workforce</h3>
                        <div class="float-right">
                           <a href="<?php echo base_url() ?>/admin/user/role_permission" class="btn btn-warning btn-sm">Add New Role</a>
                           <a href="<?php echo base_url() ?>/admin/member/view_all_designation" class="btn btn-info btn-sm">Add New Designation</a>
                           <a href="<?php echo base_url() ?>/admin/employee/view_all_employee" class="btn btn-success btn-sm">View All Workforce</a>
                        </div>
                     </div>
                     <?php echo form_open('admin/employee/new_employee_add'); ?>
                     <div class="card-body">
                        <div class="row">
                           <div class="col-sm-3">
                              <div class="form-group row">
                                 <label for="inputName" class="col-sm-12 col-form-label">Workforce Role <span style="color:red">*</span></label>
                                 <div class="col-sm-12">
                                    <select type="text" onchange="check_role(this.value)" name="user_role" class="form-control" required="required">
                                       <option value="">Select Role</option>
                                       <?php foreach ($all_role as $role):?>
                                          <option value="<?php echo $role->role_name ?>"><?php echo $role->role_name ?></option>
                                       <?php endforeach;?>
                                    </select>
                                 </div>
                              </div>
                           </div>
                           <div class="col-sm-3">
                              <div class="form-group row">
                                 <label for="inputName" class="col-sm-12 col-form-label">Workforce Designation <span style="color:red">*</span></label>
                                 <div class="col-sm-12">
                                    <select type="text" name="user_designation" class="form-control" required="required">
                                       <option value="">Select</option>
                                       <?php foreach ($all_designation as $designation):?>
                                          <option value="<?php echo $designation->role_name ?>"><?php echo $designation->role_name ?></option>
                                       <?php endforeach;?>
                                    </select>
                                 </div>
                              </div>
                           </div>
                           <div class="col-sm-6">
                              <div class="form-group row">
                                 <label for="inputName" class="col-sm-12 col-form-label">Workforce Name <span style="color:red">*</span></label>
                                 <div class="col-sm-12">
                                    <input type="text" name="user_name" class="form-control" placeholder="Enter Workforce Owner Name" required="required">
                                 </div>
                              </div>
                           </div>
                           <div class="col-sm-6">
                              <div class="form-group row">
                                 <label for="inputName" class="col-sm-12 col-form-label">Workforce Email ID <span style="color:red">*</span></label>
                                 <div class="col-sm-12">
                                    <input type="email" id="email_a" onchange="checkemail(this.value)" name="user_email" class="form-control" placeholder="Enter Workforce Email ID" required="required" pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$">
                                 </div>
                              </div>
                           </div>
                           <div class="col-sm-6">
                              <div class="form-group row">
                                 <label for="inputName" class="col-sm-12 col-form-label">Workforce Mobile No. <span style="color:red">*</span></label>
                                 <div class="col-sm-12">
                                    <input type="text" onchange="checkmobile(this.value)" name="user_mobile" class="form-control" placeholder="Enter Workforce Mobile No. (** This is Login ID **)" required="required" pattern="[1-9]{1}[0-9]{9}">
                                 </div>
                              </div>
                           </div>
                           <div class="col-sm-12">
                              <div class="form-group row">
                                 <label for="inputName" class="col-sm-12 col-form-label">Workforce Pin Code <span style="color:red">*</span></label>
                                 <div class="col-sm-12">
                                    <input type="number" name="user_pin_code" id="pin_code" class="form-control" placeholder="Enter Workforce Pin Code" required="required">
                                 </div>
                              </div>
                           </div>
                           <div class="col-sm-12">
                              <div class="form-group row">
                                 <label for="inputName" class="col-sm-12 col-form-label">Workforce Address </label>
                                 <div class="col-sm-12">
                                    <textarea type="text" name="user_address" class="form-control" placeholder="Enter Workforce Address" ></textarea>
                                 </div>
                              </div>
                           </div>
                           
                           <div class="col-sm-4">
                              <div class="form-group row">
                                 <label for="inputName" class="col-sm-12 col-form-label">Workforce Area <span style="color:red">*</span></label>
                                 <div class="col-sm-12">
                                    <select name="user_work_taulka" id="area" class="form-control" required="required">
                                       <option value="">Select A Area</option>
                                    </select>
                                 </div>
                              </div>
                           </div>
                           <div class="col-sm-4">
                              <div class="form-group row">
                                 <label for="inputName" class="col-sm-12 col-form-label">Workforce Dist <span style="color:red">*</span></label>
                                 <div class="col-sm-12">
                                    <input type="text" name="user_work_dist" id="city" class="form-control" placeholder="Workforce Dist" required="required" readonly="">
                                 </div>
                              </div>
                           </div>
                           <div class="col-sm-4">
                              <div class="form-group row">
                                 <label for="inputName" class="col-sm-12 col-form-label">Workforce State <span style="color:red">*</span></label>
                                 <div class="col-sm-12">
                                    <input type="text" name="user_work_state" id="state" class="form-control" placeholder="Workforce State" required="required" readonly="">
                                 </div>
                              </div>
                           </div>
                           <div class="col-sm-6 hide_on_teacher">
                              <div class="form-group row">
                                 <label for="inputName" class="col-sm-12 col-form-label">Workforce Paid Status <span style="color:red">*</span></label>
                                 <div class="col-sm-12">
                                    <select name="user_paid_status" id="paid_status" class="form-control" placeholder="Enter Workforce Owner Aadhar Card No">
                                       <option value="">Select</option>
                                       <option value="Paid">Paid</option>
                                       <option value="Rental">Rental</option>
                                    </select>
                                 </div>
                              </div>
                           </div>
                           <div class="col-sm-6 hide_on_teacher">
                              <div class="form-group row">
                                 <label for="inputName" class="col-sm-12 col-form-label">Workforce Pay/Rental Amount <span style="color:red">*</span></label>
                                 <div class="col-sm-12">
                                    <input name="user_rental_amount" id="rental_amt" type="number" class="form-control" placeholder="Enter Workforce Pay/Rental Amount">
                                      
                                 </div>
                              </div>
                           </div>
     
                        </div>
                        
                        <div class="form-group row" id="submit_button">
                           <div class="offset-sm-0 col-sm-10">
                              <button onclick="return confirm('Are You Sure. You Want to Add Workforce ?')"  type="submit" class="btn btn-success setting-submit" name="submit">Save</button>
                           </div>
                        </div>   
                        
                     </div>
                     <?php echo form_close(); ?>
                  </div>
               </div>
            </div>
          </div>
         </div>
      </div>
   </div>
</section>
</div>

<style type="text/css">
#alert3, .hide_on_teacher
{
   display: none;
}
</style>
<script type="text/javascript">
function check_role(e) 
{
   if(e == 'Teacher')
   {
      $('.hide_on_teacher').show();
      $('#paid_status').attr('required', true);
      $('#rental_amt').attr('required', true);
   }
   else
   {
      $('.hide_on_teacher').hide();
      $('#paid_status').attr('required', false);
      $('#rental_amt').attr('required', false);
   }
}
$('body').on('change', '#pin_code', function () {
    let pin_code = $('#pin_code').val();
    if (pin_code == 0) {
            swal ( "Oops" ,  "Please Enter Pin Code!" ,  "warning" );
        return false;
    }
    $.ajax({
      beforeSend: function() {
         $(".loader").show();
      },
      type: "GET",
      dataType:"JSON",
      async: true,
      url: '<?php echo base_url(); ?>/admin/admin/get_aadress_detaile_by_pin_code/'+pin_code,
      success: function (data) 
      {
          $('#area').html(data.area);
          $('#city').val(data.city);
          $('#state').val(data.state);
          $(".loader").hide();
      },
      error: function () {
        $(".loader").hide();
      }
    });
});

function checkemail(e) 
{
   $.ajax({
      beforeSend: function() {
         $(".loader").show();
      },
      type: "POST",
      dataType:"JSON",
      async: true,
      data : {email: e},
      url: '<?php echo base_url(); ?>/admin/admin/check_email',
      success: function (data) 
      {
          if(data)
          {
            swal('Opps!', "Email ID Already Exits", 'error');
            $('#submit_button').hide();
          }
          else
          {
            $('#submit_button').show();
          }
          $(".loader").hide();
      },
      error: function () {
        $(".loader").hide();
      }
    });
}
function checkmobile(e) 
{
   $.ajax({
      beforeSend: function() {
         $(".loader").show();
      },
      type: "POST",
      dataType:"JSON",
      async: true,
      data : {mobile: e},
      url: '<?php echo base_url(); ?>/admin/admin/check_mobile_avaliblity',
      success: function (data) 
      {
          if(data)
          {
            swal('Opps!', "Mobile No. Already Exits", 'error');
            $('#submit_button').hide();
          }
          else
          {
            $('#submit_button').show();
          }
          $(".loader").hide();
      },
      error: function (e) {
        $(".loader").hide();
        console.log(e.responseText)
      }
    });
}
</script>