<div class="collapse" id="collapseAction">
	<div class="card card-body">
            <div class="row">
                  <div class="col">
                        <h4 class="card-title">Employment Detail</h4>
                  </div>
            </div>
		<hr>
		<div class="container">
			<div class="row">
				<div class="btn-group ml-auto">
					<?php if ($role == 'admin'): ?>
						<a class="btn btn-info btn-sm" style="margin-bottom:15px; width: 200px;" href="<?php echo base_url('/hr/StaffProfile/actionReport/'.$staff_id.'/17'); ?>" target="_blank">
							<i class="fa fa-print"></i> Print
						</a>
					<?php endif ?>
				</div>
			</div>
		</div>

		<div class="table-responsive">
			<table class="table table-bordered">
				<thead>
					<tr>
						<th>Action Type (Effective date) </th>
						<th>Description</th>
						<th>Created At</th>
						<!-- <th>Action</th> -->
					</tr>
				</thead>
				<tbody>
					<?php if(!empty($join_groups)) foreach ($join_groups as $key => $join_group): ?>
					<tr>
						<td><?php echo (!empty($action_type = $join_group->action_type_name))?$action_type:'N/A'; ?> (<?php echo (!empty($effetive_date = $join_group->action_efective_date))?date('d-F-Y',strtotime($effetive_date)):'N/A'; ?>)</td>
						<td>
							<label><b>Reason </b></label>               : <?php echo (!empty($reason = $join_group->reason))?$reason:'N/A'; ?> <br>
                                          <label><b>Contract Element </b></label>     : <?php echo (!empty($join_group->contract_element))?$join_group->contract_element:'N/A'; ?> <br>
                                          <label><b>Employee Group</b></label>        : <?php echo (!empty($emp_group = $join_group->employee_group))?$emp_group:'N/A';  ?> <br>
                                          <label><b>Employee Subgroup/Level </b></label>    : <?php echo (!empty($emp_subgroup = $join_group->employee_subgroup_designation))?$emp_subgroup:'N/A';  ?> <br>
							<label><b>Employee Grade - Positions </b></label>    : 

                                          <?php if($join_group->level > 0){ ?>
                                                <?php echo (!empty($grade = $join_group->employee_grade))?$grade:'N/A'; ?> 
                                                (<?php echo (!empty($level = $join_group->level))?integerToRoman($level):'N/A'; ?>) - 
                                                <?php echo (!empty($position = $join_group->position_hiring))?$position:'N/A'; ?> <br>
                                          <?php } else { ?>
                                                <?php echo (!empty($grade = $join_group->employee_grade))?$grade:'N/A'; ?> - <?php echo (!empty($position = $join_group->position_hiring))?$position:'N/A'; ?> <br>
                                          <?php } ?>

							<label><b>Designation </b></label>          : <?php echo (!empty($position_information = $join_group->designation))?$position_information:'N/A'; ?> <br>
							<label><b>Reporting To</b></label>          : <?php echo (!empty($reporting_name = $join_group->user_reporting_name))?$reporting_name:'N/A'; ?> <br>
							<label><b>Business Entity </b></label>	  : <?php echo (!empty($business_entity = $join_group->business_entity))?$business_entity:'N/A'; ?> <br>
							<label><b>Branch </b></label>               : <?php echo (!empty($branch = $join_group->branch))?$branch:'N/A'; ?> <br>
							<label><b>Personnel Area</b></label>        : <?php echo (!empty($personnel_area = $join_group->personnel_area))?$personnel_area:'N/A'; ?> <br>
							<label><b>Personal subarea </b></label>     : <?php echo (!empty($personal_subarea = $join_group->personal_subarea))?$personal_subarea:'N/A'; ?> <br>
                                          <label><b>Employment Status</b></label>     : <?php echo (!empty($join_group->is_active))?'ACTIVE':'INACTIVE'; ?> <br>                                          
						</td>
						<td><?php echo $join_group->created_at; ?></td>
						<!-- <td class="test-center">
							<div class="btn-group">
								<button class="btn btn-success btn-sm" data-content="<?php //echo base64_encode(json_encode($join_group)); ?>" data-toggle="modal" data-target="#editUserEmpDetail" onclick="populateEmpDetail(this)"><i class="fas fa-edit"></i></button>
								<button class="btn btn-danger btn-sm" onclick="removeActionEmploymentDetail(this)" data-id="<?php //echo $join_group->id; ?>"><i class="fas fa-trash"></i></button>
							</div>
						</td> -->
					</tr>
					<?php endforeach ?>
				</tbody>
			</table>
		</div>
			
	</div><br>
</div>

<!-- modal editUserEmpDetail-->
<div class="modal" id="editUserEmpDetail" tabindex="-1" role="dialog">
  <div class="modal-dialog modal-lg" role="document">
    <div class="modal-content">

      <form action="<?php echo base_url('hr/StaffProfile/updateEmploymentDetail'); ?>" method="post">
            <div class="modal-header">
              <h5 class="modal-title">Edit User Employment Detail</h5>
              <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                <span aria-hidden="true">&times;</span>
              </button>
            </div>
            <div class="modal-body">
                  <input type="hidden" class="form-control" value="<?php echo current_url(); ?>" name="url">
                  <input type="hidden" class="form-control" id="idEditJoiningGroup" name="id">

            	<div class="row">
            		<div class="col">
            			<label><b>Reason</b></label>
            			<select class="form-control" name="reason" id="reasonEditJoiningGroup">
            				<?php foreach ($hiringReasons as $key => $reason): ?>
            					<option value="<?php echo $reason->id; ?>"><?php echo $reason->type; ?></option>
            				<?php endforeach ?>
            			</select>
            		</div>
            		<div class="col">
                              <label><b>Contract Element</b></label>
                              <select class="form-control" name="contract_elem" id="contractElementJoiningGroup">
                                    <?php foreach ($contractTypes as $key => $contractType): ?>
                                          <option value="<?php echo $contractType->id; ?>"><?php echo $contractType->type; ?></option>
                                    <?php endforeach ?>
                              </select>
                        </div>
            	</div>

                  <div class="row">
                        <div class="col">
                              <label><b>Employee Group</b></label>
                              <select class="form-control" name="emp_group" id="empGroupJoiningGroup">
                                    <?php foreach ($employee_groups as $key => $group): ?>
                                          <option value="<?php echo $group->id; ?>"><?php echo $group->type; ?></option>
                                    <?php endforeach ?>
                              </select>
                        </div>
                        <div class="col">
                              <label><b>Employee Subgroup/Level</b></label>
                              <select class="form-control" name="emp_subgroup" id="empSubgroupJoiningGroup" onchange="subgroupSelect(this);">
                                    <?php foreach ($parentPositions as $key => $parentPositions): ?>
                                          <option value="<?php echo $parentPositions->id; ?>"><?php echo $parentPositions->position; ?></option>
                                    <?php endforeach ?>
                              </select>
                        </div>
                  </div>

            	<div class="row">
                        <div class="col">
                              <label><b>Grade - Positions</b></label>
                              <select class="form-control" name="position" id="positionEditJoiningGroup" onchange="positionSelect(this);">
                                    <?php foreach ($jobPositions as $key => $position): ?>
                                          <option value="<?php echo $position->id; ?>">
                                                <?php if($position->level > 0){ ?>
                                                      <?php echo $position->grade; ?> (<?php echo integerToRoman($position->level); ?>) - <?php echo $position->position; ?> 
                                                <?php } else { ?>
                                                      <?php echo $position->grade; ?> - <?php echo $position->position; ?>
                                                <?php } ?>
                                                
                                          </option>
                                    <?php endforeach ?>
                              </select>
                        </div>
            		<div class="col">
            			<label><b>Designation</b></label>
                              <select class="form-control" name="pos_info" id="posInfoEditJoiningGroup" >
                                    <?php if(!empty($designations)) foreach ($designations as $key => $designation): ?>
                                          <option value="<?php echo $designation->id; ?>"><?php echo $designation->designation; ?></option>
                                    <?php endforeach ?>
                              </select>
            		</div>
            	</div>


            	<div class="row">
					<div class="col">
						<label><b>Business Entity</b></label>
						<select name="business_entity" id="businessEntityJoiningGroup" class="form-control">
								<?php if(!empty($business_entities)) foreach($business_entities as $business_entity): ?>
									<option value="<?php echo $business_entity->id; ?>"><?php echo $business_entity->name; ?></option>
								<?php endforeach ?>
						</select>
					</div>
            		<div class="col">
            			<label><b>Branch</b></label>
            			<select class="form-control" name="branch" id="branchJoiningGroup">
            				<?php if(!empty($branches)) foreach ($branches as $key => $branch): ?>
            					<option value="<?php echo $branch['id']; ?>"><?php echo $branch['name']; ?></option>
            				<?php endforeach ?>
            			</select>
            		</div>
            	</div>

            	<div class="row">
            		<div class="col">
            			<label><b>Personnel Area (Department)</b></label>
            			<select class="form-control" name="personnel_area" id="personnelAreaJoiningGroup">
            				<?php foreach ($departments as $key => $department): ?>
            					<option value="<?php echo $department['id']; ?>"><?php echo $department['name']; ?></option>	
            				<?php endforeach ?>
            			</select>
            		</div>
            		<div class="col">
            			<label><b>Personal subarea (Division)</b></label>
            			<select class="form-control" name="personal_area" id="personalAreaJoiningGroup">
            				<?php foreach ($divisions as $key => $division): ?>
            					<option value="<?php echo $division->id; ?>"><?php echo $division->name; ?></option>
            				<?php endforeach ?>
            			</select>
            		</div>
            	</div>

            	<div class="row">
                        <div class="col">
                              <label><b>Reporting To</b></label>
                              <select class="form-control" name="reporting_to" id="empReportingToJoiningGroup">
                                    <?php 
                                          if(!empty($allStaff)) foreach ($allStaff as $key => $staff) {
                                    ?>
                                          <option value="<?php echo $staff['id']; ?>"><?php echo $staff['name']; ?></option>
                                    <?php
                                          }
                                    ?>
                              </select>
                        </div>
                        <div class="col">
                              <label><b>Employment Status</b></label>
                              <select class="form-control" name="status" id="empStatusJoiningGroup">
                                    <option value="1">Active</option>
                                    <option value="0">Inactive</option>
                              </select>
                        </div>
                  </div>

            	
            </div>
            <div class="modal-footer">
                  <button type="button" class="btn btn-danger btn-sm" style="margin-bottom:15px; width: 200px;" data-dismiss="modal"><i class="fa fa-ban"></i> Cancel</button>
                  <button type="submit" class="btn btn-success btn-sm" style="margin-bottom:15px; width: 200px;"><i class="fa fa-save"></i> save</button>
            </div>
      </form>
    </div>
  </div>
</div>
<!-- modal editUserEmpDetail -->

<script type="text/javascript">
      function subgroupSelect(elem) 
      {
            console.log($(elem).val());
            $('#positionEditJoiningGroup').empty();
            $('#posInfoEditJoiningGroup').empty();
            var options = '';
            <?php if(!empty($jobPositions)) foreach ($jobPositions as $key => $jobPositions): ?>
                  if ($(elem).val() == <?php echo $jobPositions->parent_id; ?>) {
                        
                        <?php if($jobPositions->level > 0){ ?>
                              let option_list = `<option value="<?php echo $jobPositions->id; ?>" data-grade="<?php echo $jobPositions->grade; ?>">
                                                      <?php echo $jobPositions->grade; ?> (<?php echo integerToRoman($jobPositions->level); ?>) - <?php echo $jobPositions->position; ?> 
                                                   </option>`;
                        <?php }else{ ?>
                              let option_list = `<option value="<?php echo $jobPositions->id; ?>" data-grade="<?php echo $jobPositions->grade; ?>">
                                                      <?php echo $jobPositions->grade; ?> - <?php echo $jobPositions->position; ?>
                                                   </option>`;
                        <?php } ?>
                        
                        options += option_list;

                        // options += '<option value="<?php echo $designation->id; ?>"><?php echo $designation->designation; ?></option>'; 
                  };
            <?php endforeach ?>
            $('#positionEditJoiningGroup').append('<option disabled selected>Please Select Positions</option>'+options);
      }

      function positionSelect(elem) 
      {
            console.log($(elem).val());
            $('#posInfoEditJoiningGroup').empty();
            var options = '';
            <?php if(!empty($designations)) foreach ($designations as $key => $designation): ?>
                  if ($(elem).val() == <?php echo $designation->position_id; ?>) {
                        
                        let option_list = `<option value="<?php echo $designation->id; ?>"><?php echo $designation->designation; ?></option>`;
                        options += option_list;

                        // options += '<option value="<?php echo $designation->id; ?>"><?php echo $designation->designation; ?></option>'; 
                  };
            <?php endforeach ?>
            $('#posInfoEditJoiningGroup').append('<option disabled selected>Please Select Designations</option>'+options);
      }
</script>