 <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <div class="content-header">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-6">
            <h1 class="m-0 text-dark">Edit Employee</h1>
          </div><!-- /.col -->
          <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="#">Employee</a></li>
              <li class="breadcrumb-item active">Edit Employee</li>

            </ol>
          </div><!-- /.col -->
        </div><!-- /.row -->
      </div><!-- /.container-fluid -->
    </div>
    <!-- /.content-header -->
    <!-- Main content -->
    <section class="content">
      <div class="container-fluid">

        <div class="row">
          <div class="col-sm-12">
            <div class="card card-default">
              <div class="card-header">
                <h3 class="card-title">Edit Employee</h3>
                <div class="card-tools">
                  <a href="<?php echo base_url()?>admin/employee/view_all_employee" class="btn btn-primary btn-sm"><i class="fa fa-eye" aria-hidden="true"></i> View Employee</a>
                </div>
              </div>
              <!-- /.card-header -->
              <?php echo form_open_multipart('admin/employee/update_employee/'.$employee->user_id); ?>
              <div class="card-body">
                <div class="row">
                  <div class="col-md-9">
                    <div class="form-group">
                       <label for="inputEmail" class="col-sm-12 col-form-label">Employee Name <span class="required">*</span></label>
                       <div class="col-sm-12">
                          <input class="form-control"  name="user_name" placeholder="Enter Employee Name" required="required" value="<?php echo $employee->user_name; ?>">
                       </div>
                    </div>
                  </div>

                  <div class="col-md-3">
                    <div class="form-group">
                       <label for="inputEmail" class="col-sm-12 col-form-label">Employee Date of Birth <span class="required">*</span></label>
                       <div class="col-sm-12">
                          <input class="form-control" type="date"  name="user_dob" placeholder="Enter Employee Owner Name" required="required" value="<?php echo $employee->user_dob; ?>">
                       </div>
                    </div>
                  </div>
                  <div class="col-md-3">
                    <div class="form-group">
                       <label for="inputEmail" class="col-sm-12 col-form-label">Employee Role <span class="required">*</span></label>
                       <div class="col-sm-12">
                          <select class="form-control"  name="user_role"  required="required">
                              <option value="">Select</option>
                              <?php 
                              $user_id = user_id();
                              $this->db->where_not_in('role_name', ['Super Admin', 'Admin', 'Branch']);
                              $all_role = $this->db->get('role_permission')->result();
                              foreach ($all_role as $role):
                              ?>
                                 <option <?php if($employee->user_role == $role->role_name){echo 'selected';}?> value="<?php echo $role->role_name; ?>"><?php echo $role->role_name; ?></option>
                              <?php endforeach ?>
                          </select>
                       </div>
                    </div>
                  </div>
                  <div class="col-md-3">
                    <div class="form-group">
                       <label for="inputEmail" class="col-sm-12 col-form-label">Employee Gender <span class="required">*</span></label>
                       <div class="col-sm-12">
                          <select class="form-control"  name="user_gender" placeholder="Enter Employee Owner Name" required="required">
                            <option <?php if($employee->user_gender == 'Male'){echo 'selected';}?> value="Male">Male</option>
                            <option <?php if($employee->user_gender == 'Female'){echo 'selected';}?> value="Female">Female</option>
                          </select>
                       </div>
                    </div>
                  </div>
                  <div class="col-md-6">
                    <div class="form-group">
                       <label for="inputEmail" class="col-sm-12 col-form-label">Employee Email ID <span class="required">*</span></label>
                       <div class="col-sm-12">
                          <input class="form-control" type="email"  name="user_email" placeholder="Enter Employee Email ID" required="required" value="<?php echo $employee->user_email; ?>">
                       </div>
                    </div>
                  </div>
                  <div class="col-md-6">
                    <div class="form-group">
                       <label for="inputEmail" class="col-sm-12 col-form-label">Employee Mobile No. <span class="required">*</span></label>
                       <div class="col-sm-12">
                          <input class="form-control" type="number"  name="user_mobile" placeholder="Enter Employee Mobile No." required="required" value="<?php echo $employee->user_mobile; ?>">
                       </div>
                    </div>
                  </div>
                  <div class="col-sm-6">
                      <div class="form-group">
                         <label for="inputName" class="col-sm-12 col-form-label">Employee Pin Code <span >*</span></label>
                         <div class="col-sm-12">
                            <input type="number" name="user_pin_code" id="pin_code" class="form-control" placeholder="Enter Employee Pin Code" required="required" value="<?php echo $employee->user_pin_code; ?>">
                         </div>
                      </div>
                   </div>
                   <div class="col-sm-12">
                      <div class="form-group">
                         <label for="inputName" class="col-sm-12 col-form-label">Employee Address *</label>
                         <div class="col-sm-12">
                            <textarea type="text" name="user_village" class="form-control" placeholder="Enter Employee Address" required><?php echo $employee->user_village; ?></textarea>
                         </div>
                      </div>
                   </div>
                   
                   <div class="col-sm-4">
                      <div class="form-group">
                         <label for="inputName" class="col-sm-12 col-form-label">Employee Area <span >*</span></label>
                         <div class="col-sm-12">
                            <select name="user_taluka" id="area" class="form-control" required="required">
                               <option value="<?php echo $employee->user_taluka; ?>"><?php echo $employee->user_taluka; ?></option>
                            </select>
                         </div>
                      </div>
                   </div>
                   <div class="col-sm-4">
                      <div class="form-group">
                         <label for="inputName" class="col-sm-12 col-form-label">Employee Dist <span >*</span></label>
                         <div class="col-sm-12">
                            <input type="text" name="user_dist" id="city" class="form-control" placeholder="Enter Employee Dist" required="required" readonly="" value="<?php echo $employee->user_dist; ?>">
                         </div>
                      </div>
                   </div>
                   <div class="col-sm-4">
                      <div class="form-group">
                         <label for="inputName" class="col-sm-12 col-form-label">Employee State <span >*</span></label>
                         <div class="col-sm-12">
                            <input type="text" name="user_state" id="state" class="form-control" placeholder="Enter Employee State" required="required" readonly="" value="<?php echo $employee->user_state; ?>">
                         </div>
                      </div>
                   </div>
                   <div class="col-sm-3">
                      <div class="form-group">
                         <label for="inputName" class="col-sm-12 col-form-label">Employee Photo </label>
                         <div class="col-sm-12">
                            <input type="file" name="user_photo" class="form-control" placeholder="Enter Employee Registration Fee" >
                         </div>
                      </div>
                   </div>
                   <div class="col-sm-3">
                      <div class="form-group">
                         <label for="inputName" class="col-sm-12 col-form-label">Employee Payment Type <span >*</span></label>
                         <div class="col-sm-12">
                            <select type="text" name="employee_pay_type" onchange="pay_type(this.value)" class="form-control"  required="required" >
                              <option value="">Select Type</option>
                              <option <?php if($employee->employee_pay_type == 1){echo 'selected';} ?> value="1">Incentive Basis</option>
                              <option <?php if($employee->employee_pay_type == 2){echo 'selected';} ?> value="2">Hourly Basis</option>
                              <option <?php if($employee->employee_pay_type == 3){echo 'selected';} ?> value="3">Monthly Basis</option>
                            </select>
                         </div>
                      </div>
                   </div>
                   
                    <div class="col-sm-3">
                      <div class="form-group">
                         <label for="inputName" class="col-sm-12 col-form-label"><b id="pay_value"></b><span >*</span></label>
                         <div class="col-sm-12">
                            <input type="text" name="employee_pay_value" class="form-control" placeholder="Enter Value" required="required" value="<?php echo $employee->employee_pay_value ?>">
                         </div>
                      </div>
                   </div>
                   <div class="col-sm-3">
                      
                   </div>
                   <div class="col-sm-3">
                      <div class="form-group">
                         <label for="inputName" class="col-sm-12 col-form-label">Preview Employee Photo </label>
                         <div class="col-sm-12">
                            <img src="<?php echo base_url() ?><?php echo $employee->user_photo ?>" width="100px">
                         </div>
                      </div>
                   </div>
                  <div class="col-md-12">
                    <div class="form-group">
                       <button name="form1" style="float: right" type="submit" class="btn btn-success">Update</button>
                    </div>
                  </div>
                  <?php echo form_close() ?>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </section>
  </div>

<script type="text/javascript">
$('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();
      }
    });
});
$( document ).ready(function() {
    pay_type(<?php echo $employee->employee_pay_value; ?>)
});
function pay_type(e) 
{
   if(e == 1)
   {
      $('#pay_value').html('Incentive(%)');
   }
   else if(e == 2)
   {
      $('#pay_value').html('Rate Per Hour (Rs.)');
   }
   else
   {
      $('#pay_value').html('Salary (Rs.)');
   }
}
</script>