<?php
include('pdf_header.php');
include('pdf_ohc_header.php');
?>
<table border="1" width="100%">
	<?php
	$sql = base64_decode($filterkey);

	$result = mysqli_query($conn, $sql);

	// echo $result;
	?><tr>

		<th>EMP Code</th>
		<th>Patient Name</th>
		<th>Father Name</th>
		<th>Designation</th>
		<th>Department</th>
		<th>Aadhar No</th>
		<th>Date Of Joining</th>
		<th>Date Of Birth</th>
		<th>Age</th>
		<th>Ohc</th>
		<th>Gender</th>
		<th>Blood Group</th>
		<th>Primary phone</th>
		<th>Grade</th>
		<th>Plant</th>
		<th>Email</th>
		<th>Status</th>
		<th>Is First Aider</th>

	</tr>
	<?php
	$count = 0;
	error_reporting(E_ERROR | E_PARSE);
	while ($rowOfEmployee = mysqli_fetch_array($result)) {
		$count = $count + 1;

		$doj = trim($rowOfEmployee['doj']);

		if ($doj == '0000-00-00' || $doj == null || $doj == '30/11/-0001' ||  $doj == '1970-01-01') {
			$doj =  "Not Available";
		} else {
			$doj = trim($doj);
		}


		$dob = trim($rowOfEmployee['dob']);

		if ($dob == '0000-00-00' || $dob == null || $dob == '30/11/-0001' ||  $dob == '1970-01-01') {
			$dob =  "Not Available";
		} else {
			$dob = trim($dob);
		}


		$age =  0;
		if ($dob == '0000-00-00' || $dob == null || $dob == '30/11/-0001' ||  $row_employee['dob'] == '1970-01-01') {
			$age =  "Not Available";
		} else {
			$birthday = DateTime::createFromFormat('Y-m-d', $dob, new DateTimeZone('Asia/Kolkata'));

			if ($birthday !== false) {
				$currentDate = new DateTime(null, new DateTimeZone('Asia/Kolkata'));
				$interval = $birthday->diff($currentDate);
				$age = $interval->y;
			}
		}
		$ohc = '';

		if ($rowOfEmployee['ohc_type_id'] != '') {
			$ohc = getFieldFromTable('ohc_type_name', 'ohc_type', 'ohc_type_id', $rowOfEmployee['ohc_type_id']);
		}
		$status = $rowOfEmployee['status'];
	?>
		<tr>

			<td><?php echo $rowOfEmployee['emp_code'] ?></td>
			<td><?php echo $rowOfEmployee['patient_name'] ?></td>
			<td><?php echo $rowOfEmployee['father_name'] ?></td>
			<td><?php echo $rowOfEmployee['designation_name'] ?></td>
			<td><?php echo $rowOfEmployee['dept_name'] ?></td>
			<td><?php echo $rowOfEmployee['aadhar_no'] ?></td>
			<td><?php echo $doj ?></td>
			<td><?php echo $dob ?></td>
			<td><?php echo $age ?></td>
			<td><?php echo $ohc ?></td>
			<td><?php echo $rowOfEmployee['gender'] ?></td>
			<td><?php echo $rowOfEmployee['blood_group'] ?></td>
			<td><?php echo $rowOfEmployee['primary_phone'] ?></td>
			<td><?php echo getFieldFromTable('grade_name', 'grade_master', 'grade_id', $rowOfEmployee['grade_id']); ?></td>
			<td><?php echo getFieldFromTable('plant_name', 'plant_master', 'plant_id', $rowOfEmployee['plant_id']); ?></td>
			<td><?php echo $rowOfEmployee['offiial_email_id']; ?></td>
			<td><?php echo $status ?></td>
			<td><?php echo $rowOfEmployee['is_first_aid'] == 1 ? 'Yes' : 'No' ?></td>
		</tr>
	<?php

	}
	?>
</table>
<?php
include('pdf_footer.php');
?>