<?php
	if(($this->session->userdata('sv_maintenance_filter_month') && $this->session->userdata('sv_maintenance_filter_month') != 'no result')){
		if($this->session->userdata('sv_maintenance_filter_month') == '01'){
	         $month = "JANUARY";
	    }else if($this->session->userdata('sv_maintenance_filter_month') == '02'){
	         $month = "FEBRUARY";
	    }else if($this->session->userdata('sv_maintenance_filter_month') == '03'){
	         $month = "MARCH";
	    }else if($this->session->userdata('sv_maintenance_filter_month') == '04'){
	         $month = "APRIL";
	    }else if($this->session->userdata('sv_maintenance_filter_month') == '05'){
	         $month = "MAY";
	    }else if($this->session->userdata('sv_maintenance_filter_month') == '06'){
	         $month = "JUNE";
	    }else if($this->session->userdata('sv_maintenance_filter_month') == '07'){
	         $month = "JULY";
	    }else if($this->session->userdata('sv_maintenance_filter_month') == '08'){
	         $month = "AUGUST";
	    }else if($this->session->userdata('sv_maintenance_filter_month') == '09'){
	         $month = "SEPTEMBER";
	    }else if($this->session->userdata('sv_maintenance_filter_month') == '10'){
	         $month = "OCTOBER";
	    }else if($this->session->userdata('sv_maintenance_filter_month') == '11'){
	         $month = "NOVEMBER";
	    }else if($this->session->userdata('sv_maintenance_filter_month') == '12'){
	         $month = "DECEMBER";
        }else if($this->session->userdata('sv_maintenance_filter_month') == 'ALL'){
	         $month = "ALL";
	    }else  $month = "Unknown";
	}

// debug($this->session->userdata('sv__maintenance'));

?>

<header>
	<div class="row">
		<div class="col-12">
			<div class="t-corp pull-left">
				<div class="t-corp-logo">
					<img src="<?php echo base_url().'assets/images/logo/salihin-logo.png'; ?>" alt="company logo" />
				</div>
				<div class="t-corp-name"><b>SPS</b> | HR SYSTEM</div>
			</div>
			<div class="report-title pull-right" style="padding-top: 30px;">
				<h5><?php echo (isset($title) ? $title : 'Report'); ?></h5>
			</div>
		</div>
	</div>
	<div class="row">
		<div class="col-12">
			<table class="company">
				<tr>
					<td class="divider">
						<span class="line">&nbsp;</span>
					</td>
					<td class="details">
						<span><b>SALIHIN (AF 1426)</b></span>
						<span>555, Jalan Samudra Utara 1, Taman Samudra, Batu Caves,</span>
						<span>68100, Batu Caves, Selangor</span>
						<span>Phone: 03-6185 9970 &nbsp;&nbsp; Fax: 03-6185 9970</span>
						<span>Website: salihin.com.my</span>
					</td>
					<?php if(!empty($ID)){ ?>
						<td class="divider">
							<span class="line">&nbsp;</span>
						</td>
					<?php } else { ?>
						<td class="divider">
							<span class="line">&nbsp;</span>
							<?php //if(!empty($this->session->userdata('sv_maintenance_filter_dept')) && $this->session->userdata('sv_maintenance_filter_dept') != 'ALL' ){ ?>
								<!-- <span><b>DEPARTMENT &emsp;&nbsp;: <?php //echo $department['name'].' ['.$department['branch_name'].']'; ?></b></span> -->
							<?php //} else {?>
								<?php //if($_SESSION['module_data']['role']=='admin'){ ?>
									<!-- <span><b>DEPARTMENT &emsp;&nbsp;: ALL</b></span> -->
								<?php //} else{ ?>
									<!-- <span><b>DEPARTMENT &emsp;&nbsp;: <?php //echo $_SESSION['user']['department_name'].' ['.$_SESSION['user']['branch_name'].']'; ?></b></span> -->
								<?php //} ?>
							<?php //} ?>

							<table>
								<tr>
									<td><span><b>OFFICE UNIT</b></span></td>
									<td><span><b style="padding-left: 2rem;">:</b></span></td>
									<td><span><b style="padding-left: 1rem;"><?php echo (!empty($this->session->userdata('sv_maintenance_filter_office_unit')))?($this->session->userdata('sv_maintenance_filter_office_unit')):'ALL'; ?></b></span></td>
								</tr>
								<tr>
									<td><span><b>FLOOR</b></span></td>
									<td><span><b style="padding-left: 2rem;">:</b></span></td>
									<td><span><b style="padding-left: 1rem;"><?php echo (!empty($this->session->userdata('sv_maintenance_filter_floor')))?($this->session->userdata('sv_maintenance_filter_floor')):'ALL'; ?></b></span></td>
								</tr>
								<tr>
									<td><span><b>CATEGORY</b></span></td>
									<td><span><b style="padding-left: 2rem;">:</b></span></td>
									<td><span><b style="padding-left: 1rem;"><?php echo (!empty($this->session->userdata('sv_maintenance_filter_complaint_category')))?($this->session->userdata('sv_maintenance_filter_complaint_category')):'ALL'; ?></b></span></td>
								</tr>
								<tr>
									<td><span><b>STATUS</b></span></td>
									<td><span><b style="padding-left: 2rem;">:</b></span></td>
									<td><span><b style="padding-left: 1rem;"><?php echo (!empty($this->session->userdata('sv_maintenance_filter_status')))?($this->session->userdata('sv_maintenance_filter_status')):'ALL'; ?></b></span></td>
								</tr>
								<tr>
									<td><span><b>YEAR</b></span></td>
									<td><span><b style="padding-left: 2rem;">:</b></span></td>
									<td><span><b style="padding-left: 1rem;"><?php echo (!empty($this->session->userdata('sv_maintenance_filter_year')))?($this->session->userdata('sv_maintenance_filter_year')):'ALL'; ?></b></span></td>
								</tr>
								<tr>
									<td><span><b>MONTH</b></span></td>
									<td><span><b style="padding-left: 2rem;">:</b></span></td>
									<td><span><b style="padding-left: 1rem;"><?php echo (!empty($this->session->userdata('sv_maintenance_filter_month')))?($this->session->userdata('sv_maintenance_filter_month')):'ALL'; ?></b></span></td>
								</tr>
							</table>
						</td>
					<?php } ?>
				</tr>
			</table>
		</div>
	</div>
</header>

<?php if(!empty($ID)){ ?>
	<div class="container">
		<div class="col-12" style="margin-top:2rem">
			<div class="row">
				<div class="col">
					<h3><b>DETAIL OF MAINTENANCE REQUEST</b></h3>
				</div>
			</div>
			<div class="row">
				<div class="col">
					<p style="border-top: 3px solid; width: 41.4rem;"></p><br>
				</div>
			</div>
			<div class="row">
				<div class="col-1" >
				</div>
				<div class="col d-flex">
					<div class="align-self-end w-100">
						<div class="row">
							<div class="col-4">
								<b>STAFF NAME</b>
							</div>
							<div class="col">
								<p class="report-font">: 
									<?php echo (!empty($MaintenanceListDetail[0]['requestor']))?$MaintenanceListDetail[0]['requestor']:'N/A'; ?>
								</p>
							</div>
						</div>
						<div class="row">
							<div class="col-4">
								<b>STAFF ID</b>
							</div>
							<div class="col">
								<p class="report-font">: 
									<?php echo (!empty($MaintenanceListDetail[0]['staff_id']))?$MaintenanceListDetail[0]['staff_id']:'N/A'; ?>
								</p>
							</div>
						</div>
						<div class="row">
							<div class="col-4">
								<b>DEPARTMENT</b>
							</div>
							<div class="col">
								<p class="report-font">: 
									<?php echo (!empty($MaintenanceListDetail[0]['dept_name']))?$MaintenanceListDetail[0]['dept_name'].'/'.$MaintenanceListDetail[0]['branchName']:'N/A'; ?>
								</p>
							</div>
						</div>
						<div class="row">
							<div class="col-4">
								<b>OFFICE UNIT</b>
							</div>
							<div class="col">
								<p class="report-font">: 
									<?php echo (!empty($MaintenanceListDetail[0]['office_unit']))?$MaintenanceListDetail[0]['office_unit']:'N/A'; ?>
								</p>
							</div>
						</div>
						<div class="row">
							<div class="col-4">
								<b>FLOOR</b>
							</div>
							<div class="col">
								<p class="report-font">: 
									<?php echo (!empty($MaintenanceListDetail[0]['floor']))?$MaintenanceListDetail[0]['floor']:'N/A'; ?>
								</p>
							</div>
						</div>
						<div class="row">
							<div class="col-4">
								<b>COMPLAINT CATEGORY</b>
							</div>
							<div class="col">
								<p class="report-font">: 
									<?php echo (!empty($MaintenanceListDetail[0]['complain_category']))?$MaintenanceListDetail[0]['complain_category']:'N/A'; ?>
								</p>
							</div>
						</div>
						<div class="row">
							<div class="col-4">
								<b>PROBLEM</b>
							</div>
							<div class="col">
								<p class="report-font">: 
									<?php echo (!empty($MaintenanceListDetail[0]['problem']))?$MaintenanceListDetail[0]['problem']:'N/A'; ?>
								</p>
							</div>
						</div>
						<div class="row">
							<div class="col-4">
								<b>FILE NAME</b>
							</div>
							<div class="col">
								<p class="report-font">: 
									<?php echo (!empty($MaintenanceListDetail[0]['photo_title']))?$MaintenanceListDetail[0]['photo_title']:'N/A'; ?>
								</p>
							</div>
						</div>
						<div class="row">
							<div class="col-4">
								<b>DATE REQUEST</b>
							</div>
							<div class="col">
								<p class="report-font">: 
									<?php echo (!empty($MaintenanceListDetail[0]['createdTS']))?date('d-m-Y',strtotime($MaintenanceListDetail[0]['createdTS'])):'N/A'; ?>
								</p>
							</div>
						</div>
						<div class="row">
							<div class="col-4">
								<b>DATE FIXED</b>
							</div>
							<div class="col">
								<p class="report-font">: 
									<?php echo ($MaintenanceListDetail[0]['date_fixed'] != '0000-00-00')?date('d-m-Y',strtotime($MaintenanceListDetail[0]['date_fixed'])):''; ?>
								</p>
							</div>
						</div>
						
                        <div class="row">
							<div class="col-4">
								<b>STATUS</b>
							</div>
							<div class="col">
								<p class="report-font">: <?php //debug($rsCarBookingList);?>
                                    <?php echo ($MaintenanceListDetail[0]['status']==null || $MaintenanceListDetail[0]['status']=='Pending' )?'Pending ':str_replace('_',' ',$MaintenanceListDetail[0]['status_app']); ?>
								</p>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>

<?php echo $approval; ?>

    <?php } else { ?>

	<div class="col-12 table-responsive " style="margin-top:2rem">
		<table class="table table-bordered" width="100%" border="1">
			<thead>
				<th class="sorting border-top text-center" tabindex="0" rowspan="1" colspan="1" aria-label="#: activate to sort column ascending">
					#
				</th>
				<th class="sorting border-top text-center" tabindex="0" rowspan="1" colspan="1">
					Office unit
				</th>
				<th class="sorting border-top text-center" tabindex="0" rowspan="1" colspan="1">
					Complaint Category
				</th>
				<th class="sorting border-top text-center" tabindex="0" rowspan="1" colspan="1">
					Problem
				</th>
				<th class="sorting border-top text-center" tabindex="0" rowspan="1" colspan="1">
					File Name
				</th>
				<th class="sorting border-top text-center" tabindex="0" rowspan="1" colspan="1">
					Request Date
				</th>
				<th class="sorting border-top text-center" tabindex="0" rowspan="1" colspan="1">
					Fix Date
				</th>
				<th class="sorting border-top text-center" tabindex="0" rowspan="1" colspan="1" >
                    Status
                </th>     
			</thead>

			<tbody id="print_maintenance_list">
				<?php if(!empty($MaintenanceList) && is_array($MaintenanceList)) { ?> 
					<?php foreach($MaintenanceList as $key => $row) { //debug($row); ?>
						<tr>
							<td class="text-center"><?php echo $key+1; ?></td>
							<td>Unit: <?php echo $row['office_unit']; ?><br>Floor: <?php echo $row['floor']; ?></td>
							<td><?php echo $row['complain_category']; ?></td>
							<td><?php echo $row['problem']; ?></td>
							<td><?php echo $row['photo_title']; ?></td>
							<td class="text-center"><?php echo date('d-m-Y',strtotime($row['createdTS'])); ?></td>
							<td class="text-center"><?php echo ($row['date_fixed'] != '0000-00-00')?date('d-m-Y',strtotime($row['date_fixed'])):''; ?></td>
                            <td class="text-center"><?php echo ($row['status_app']==null || $row['status_app']=='Pending' )?'Pending':str_replace('_',' ',$row['status_app']); ?>
						</tr>
					<?php } ?>
				<?php } ?>
			</tbody>	
		</table>	
	</div>
<?php } ?>