<div class="collapse" id="collapseEmployment">
	<div class="card card-body">
		<h4 class="card-title">Previous Employment Details</h4>
		<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.'/5'); ?>" target="_blank">
							<i class="fa fa-print"></i> Print
						</a>
					<?php endif ?>
				</div>
			</div>
		</div>
	
		<div class="table-responsive">
			<table id="table_employment" class="table table-hover table-bordered">
				<thead>
					<tr>
						<th>Action types (Effective date)</th>
						<th>Details</th>
						<th>Created At</th>
						<!-- <?php if($role == 'admin'): ?>
						<th>Action</th>
						<?php endif ?> -->
					
					</tr>
				</thead>
				<tbody>
					<?php if($jobHistories) foreach ($jobHistories  as $key => $history): ?>
						<tr class="link-row">
							<td scope="row">
								<?php
									echo $history->action_type.'<br/><b>( '.date('d-F-Y',strtotime($history->action_efective_date)).' )</b>';
								?>
							</td>
							<td>
								<b>Employer Name : </b> <?php echo $history->employer_name; ?> <br>
								<b>Employer Address : </b> <?php echo $history->employer_address; ?> <br>
								<b>Position : </b> <?php echo $history->position; ?> <br>
								<b>Lengths of Service : </b> <?php echo $history->length_of_service; ?> <br>
								<b>Date Join : </b> <?php echo mysql_to_date_format((!empty($history->date_enter))?$history->date_enter:null);  ?> <br>
								<b>Date To : </b><?php echo mysql_to_date_format(!empty($history->date_exit)?$history->date_exit:null);  ?> <br>
								<b>Description : </b> <?php echo $history->description;  ?>
							</td>
							<td><?php echo $history->created_at; ?></td>
							<?php if($role == 'admin'): ?>
							<!-- <td class="text-center">
								<div class="btn-group" role="group">
									<button onclick="btnEditJobs(this)" class="btn btn-success btn-sm" data-content="<?php //echo base64_encode(json_encode($history))?>" data-toggle="modal" data-target="#employmentModal"><i class="fas fa-edit"></i></button>
									<button onclick="btnRemoveJobs(<?php //echo $history->id; ?>)" class="btn btn-danger btn-sm"><i class="fas fa-trash"></i></button>
								</div>
							</td> -->
							<?php endif ?>
						
						</tr>
					<?php endforeach ?>
				</tbody>
			</table>
		</div><br>

		<h4 class="card-title">Experience Level</h4>
		<hr>

			<?php if(!empty($totalWorkingExperienceOTH)){ 

				$sum_day = 0;

				foreach ($totalWorkingExperienceOTH  as $key => $totalExperience){ 
					$day_diff = $totalExperience['day_diff'];
					$sum_day += $day_diff;
				}

			}else{
				$sum_day = 0;
			}

			$date_joined = new DateTime($staff_date_joined[0]->date_joined);
			$curr_date	 = new DateTime(date('Y-m-d'));		

			$sum_day_join_salihin = $curr_date->diff($date_joined)->format('%a');

			//totalSALIHIN
			$convertSAL = $sum_day_join_salihin; // days you want to convert

			$yearsSAL = ($convertSAL / 365) ; // days / 365 days
			$yearsSAL = floor($yearsSAL); // Remove all decimals

			$monthSAL = ($convertSAL % 365) / 30; 
			$monthSAL = floor($monthSAL); // Remove all decimals

			$daysSAL  = ($convertSAL % 365) % 30; 

			//totalOTHERS
			$convertOTH = $sum_day; 

			$yearsOTH = ($convertOTH / 365) ; 
			$yearsOTH = floor($yearsOTH); 

			$monthOTH = ($convertOTH % 365) / 30; 
			$monthOTH = floor($monthOTH); 

			$daysOTH  = ($convertOTH % 365) % 30; 

			//totalALL
			$convert = $sum_day + $sum_day_join_salihin; 

			$years = ($convert / 365) ; 
			$years = floor($years); 

			$month = ($convert % 365) / 30; 
			$month = floor($month); 

			$days  = ($convert % 365) % 30; 

			$totalYearExperienceSAL = $yearsSAL.' years, '.$monthSAL.' months and '.$daysSAL.' days';
			$totalYearExperienceOTH = $yearsOTH.' years, '.$monthOTH.' months and '.$daysOTH.' days';
			$totalYearExperience 	= $years.' years, '.$month.' months and '.$days.' days';

			if($years >= 7){
				$pro = 'High-Skill Employee';
			}else if($years >= 3 && $years < 7){
				$pro = 'Semi-Skill Employee';
			}else{
				$pro = 'Low-Skill Employee';
			}
			?>

			<div class="table-responsive">
				<table id="table_proff" class="table table-hover table-bordered">
					<thead>
						<tr>
							<th>Type</th>
							<th>Details</th>
						</tr>
					</thead>
					<tbody>
						<tr>
							<td>Working Experience (SALIHIN) <i class="fa fa-info-circle" style="color:#50B0F3;" title="*From SALIHIN date joined [<?php echo $staff_date_joined[0]->date_joined; ?>] until now."></i></td>
							<td><?php if(!empty($totalYearExperienceSAL)){ echo $totalYearExperienceSAL; } else { echo 'None.'; } ?></td>
						</tr>
						<tr>
							<td>Working Experience (Others) <i class="fa fa-info-circle" style="color:#50B0F3;" title="*From date joined other than SALIHIN."></i></td>
							<td><?php if(!empty($totalYearExperienceOTH)){ echo $totalYearExperienceOTH; } else { echo 'None.'; }?></td>
						</tr>
						<tr>
							<td>Total Working Experience <i class="fa fa-info-circle" style="color:#50B0F3;" title="*From 1st day of start working until now."></i></td>
							<td><?php if(!empty($totalYearExperience)){ echo $totalYearExperience; } else { echo 'None.'; }?></td>
						</tr>
						<tr>
							<td>Professionalism <i class="fa fa-info-circle" style="color:#50B0F3;" title="*High Skill : 7 Years and above | Semi Skill : 3 - 6 Years | Low Skill : Less than 3 Years"></i></td>
							<td><?php if(!empty($pro)){ echo $pro; } else { echo 'None.'; } ?></td>
						</tr>
					</tbody>
				</table>
			</div>
	</div><br>
</div>

<div class="modal fade" id="employmentModal">
	<div class="modal-dialog modal-lg">
		<div class="modal-content">
			<div class="modal-header">
				<h5 class="modal-title" id="racks-modal-title">Add Previous Employment Details</h5>
				<button type="button" class="close" data-dismiss="modal" aria-label="Close">
					<span aria-hidden="true">&times;</span>
				</button>
			</div>
			<form action="<?php echo base_url('/hr/StaffProfile/createJobHistory/'.$staff_id); ?>" method="POST" class="form-horizontal" id="mdl-job-history-form">
				<div class="modal-body">
					<input type="hidden" class="form-control" name="id" id="mdl-job-history-id">
					<div class="row form-group">
						<div class="col">
							<label for="bank_name">Date Join</label>
							<input type="text" class="datepicker form-control" placeholder="DD-MM-YYYY" name="date_enter" id="mdl-job-history-date-join" autocomplete="off">
						</div>
						<div class="col">
							<label for="bank_name">To</label>
							<input type="text" class="datepicker form-control" placeholder="DD-MM-YYYY" name="date_exit" id="mdl-job-history-date-exit" autocomplete="off">
						</div>
					</div>
					<div class="form-group">
						<label for="bank_name">Employer Name</label>
						<input type="text" class="form-control" placeholder="Enter Employer Name" name="employer_name" id="mdl-job-history-employer-name">
					</div>	
					<div class="form-group">
						<label for="bank_branch">Employer Address</label>
						<input type="text" class="form-control" placeholder="Enter Employer Address" name="employer_address" id="mdl-job-history-employer-address">
					</div>
					<div class="form-group">
						<label for="bank_branch">Position</label>
						<input type="text" class="form-control" placeholder="Enter Position" name="position" id="mdl-job-history-position">
					</div>
					<div class="form-group">
						<label for="bank_branch">Lengths of Services</label>
						<input type="text" class="form-control" placeholder="Enter Lengths of Services" name="length_of_service" id="mdl-job-history-los">
					</div>	
					<div class="form-group">
						<label for="bank_name">Description</label>
						<textarea class="form-control" rows="5" name="description" id="mdl-job-history-description"></textarea>
					</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> Submit</button>
				</div>
			</form>
		</div>
	</div>
</div>