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

<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>
							<table>
								<tr>
									<td><span><b>DEPARTMENT</b></span></td>
									<td><span><b style="padding-left: 2rem;">:</b></span></td>
									<?php if(!empty($this->session->userdata('sv_flight_filter_dept')) && $this->session->userdata('sv_flight_filter_dept') != 'ALL'){ ?>
										<td><span><b style="padding-left: 1rem;"><?php echo $department['name'].' ['.$department['branch_name'].']'; ?></b></span></td>
									<?php } else {?>
										<?php if($_SESSION['module_data']['role']=='admin'){ ?>
											<td><span><b style="padding-left: 1rem;">ALL</b></span></td>
										<?php } else{ ?>
											<td><span><b style="padding-left: 1rem;"><?php echo $_SESSION['user']['department_name'].' ['.$_SESSION['user']['branch_name'].']'; ?></b></span></td>
										<?php } ?>
									<?php } ?>
								</tr>
								<!-- <tr>
									<td><span><b>GUEST</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_flight_filter_gname')))?($this->session->userdata('sv_flight_filter_gname')):'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_flight_filter_status')))?(str_replace('_',' ',$this->session->userdata('sv_flight_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_flight_filter_year')))?($this->session->userdata('sv_flight_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_flight_filter_month')))?($this->session->userdata('sv_flight_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 FLIGHT BOOKING</b></h3>
			</div>
		</div>
		<div class="row">
			<div class="col">
				<p style="border-top: 3px solid; width: 33rem;"></p><br>
			</div>
		</div>
		<div class="row">
			<div class="col d-flex" style="padding-left: 5rem;">
				<div class="align-self-end w-100">
					<div class="row">
						<div class="col-4">
							<b>STAFF ID</b>
						</div>
						<div class="col">
							<p class="report-font">:
								<?php echo (!empty($listFlightBooking[0]['staff_id']))?strtoupper($listFlightBooking[0]['staff_id']):'N/A'; ?>
							</p>
						</div>
					</div>

					<div class="row">
						<div class="col-4">
							<b>STAFF NAME</b>
						</div>
						<div class="col">
							<p class="report-font">: 
								<?php echo (!empty($listFlightBooking[0]['requestor']))?$listFlightBooking[0]['requestor'].' ['.$listFlightBooking[0]['requestor_email'].']':''; ?>
							</p>
						</div>
					</div>

					<div class="row">
						<div class="col-4">
							<b>DEPARTMENT</b>
						</div>
						<div class="col">
							<p class="report-font">: 
								<?php echo (!empty($listFlightBooking[0]['dept_name']))?$listFlightBooking[0]['dept_name'].'/'.$listFlightBooking[0]['branchName']:''; ?>
							</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($listFlightBooking[0]['createdTS']))?date('d-m-Y',strtotime($listFlightBooking[0]['createdTS'])):''; ?>
							</p>
						</div>
					</div>
                    
                    <div class="row">
						<div class="col-4">
							<b>FLIGHT NAME</b>
						</div>
						<div class="col">
							<p class="report-font">: 
								<?php echo (!empty($listFlightBooking[0]['flight_name']))?$listFlightBooking[0]['flight_name']:''; ?>
							</p>
						</div>
					</div>

					<div class="row">
						<div class="col-4">
							<b>NO. OF PASSENGERS</b>
						</div>
						<div class="col">
							<p class="report-font">:
								<?php echo (!empty($listFlightBooking[0]['no_of_passengers']))?strtoupper($listFlightBooking[0]['no_of_passengers']):'N/A'; ?>
							</p>
						</div>
					</div>

					<div class="row">
						<div class="col-4">
							<b>ORIGIN</b>
						</div>
						<div class="col">
							<p class="report-font">:
								<?php echo (!empty($listFlightBooking[0]['origin']))?$listFlightBooking[0]['origin']:''; ?>
							</p>
						</div>
					</div>

					<div class="row">
						<div class="col-4">
							<b>DESTINATION</b>
						</div>
						<div class="col">
							<p class="report-font">: 
								<?php echo (!empty($listFlightBooking[0]['destination']))?$listFlightBooking[0]['destination']:''; ?>
							</p>
						</div>
					</div>

					
					<div class="row">
						<div class="col-4">
							<b>DEPARTURE DATE AND TIME</b>
						</div>
						<div class="col">
							<p class="report-font">: 
							    <?php echo (!empty($listFlightBooking[0]['departure_date'] && $listFlightBooking[0]['departure_time']))?date('d-m-Y',strtotime($listFlightBooking[0]['departure_date'])).' / '.$listFlightBooking[0]['departure_time']:''; ?>
							</p>
						</div>
					</div>

					<div class="row">
						<div class="col-4">
							<b>RETURN DATE AND TIME</b>
						</div>
						<div class="col">
							<p class="report-font">: 
                                <?php echo (!empty($listFlightBooking[0]['return_date'] && $listFlightBooking[0]['return_time']))?date('d-m-Y',strtotime($listFlightBooking[0]['return_date'])).' / '.$listFlightBooking[0]['return_time']:''; ?>
							</p>
						</div>
					</div>

                    <div class="row">
						<div class="col-4">
							<b>MEAL</b>
						</div>
						<div class="col">
							<p class="report-font">: 
								<?php if ($listFlightBooking[0]['meal'] == 1){
                                    echo 'Yes';
                                } else {
                                    echo 'No';
                                } ?>
							</p>
						</div>
					</div>
                    
                    <div class="row">
						<div class="col-4">
							<b>BAGGAGE</b>
						</div>
						<div class="col">
							<p class="report-font">: 
								<?php echo (!empty($listFlightBooking[0]['baggage']))?$listFlightBooking[0]['baggage']:''; ?>
							</p>
						</div>
					</div>

                    <div class="row">
						<div class="col-4">
							<b>CLASS OF FLIGHT</b>
						</div>
						<div class="col">
							<p class="report-font">: 
                                <?php if($listFlightBooking[0]['flight_class'] == 1){
									echo 'First Class';
								} elseif($listFlightBooking[0]['flight_class'] == 2) {
									echo 'Business Class';
								} else {
										echo 'Economy Class';
								} ?>
							</p>
						</div>
					</div>

                    <div class="row">
						<div class="col-4">
							<b>STATUS</b>
						</div>
						<div class="col">
							<p class="report-font">: 
                                <?php echo ($listFlightBooking[0]['status_app']==null || $listFlightBooking[0]['status_app']=='Pending' )?'Pending ':str_replace('_',' ',$listFlightBooking[0]['status_app']); ?>

							</p>
						</div>
					</div>

				</div>
			</div>
		</div>
	</div>
	<div class="row">
		<div class="col-12">
			<b>GUEST DETAIL</b>
			<br><br>
			<table class="table table-bordered p-0 m-0" width="100%">
				<thead class="text-center">
					<th>#</th>
					<th>Staff Name</th>
					<th>Staff Detail</th>
				</thead>
				<tbody>
					<?php foreach($listFlightBooking as $key_detail => $detail){ 
						if(!empty($detail['guest_id'])){
							$flight_guest_id 	= explode(',',$detail['flight_guest_id']);
							$guest_id 			= explode(',',$detail['guest_id']);
							$guest_name 		= explode(',',$detail['guest_name']);
							$guest_phone 		= explode(',',$detail['guest_phone']);
							$guest_passport 	= explode(',',$detail['guest_passport']);
							$guest_ic_no 		= explode(',',$detail['guest_ic_no']);

							foreach($guest_name as $key => $name){ ?>
								<tr>
									<td class="text-center"><?php echo $key+1; ?></td>
									<td><?php echo $name; ?></td>
									<td>
										<div class="row">
											<div class="col-3">Ic. No.</div>
											<div class="col-1">:</div>
											<div class="col-8"><?php echo $guest_ic_no[$key]; ?></div>
										</div>
										<div class="row">
											<div class="col-3">Phone</div>
											<div class="col-1">:</div>
											<div class="col-8"><?php echo $guest_phone[$key]; ?></div>
										</div>
										<div class="row">
											<div class="col-3">Passport</div>
											<div class="col-1">:</div>
											<div class="col-8"><?php echo $guest_passport[$key]; ?></div>
										</div>
									</td>
								</tr>
							<?php } 
						} 
					} ?>
				</tbody>
			</table>
		</div>		
	</div>
</div>

<?php echo $approval; ?>
<?php } else { ?>

<div class="col-12 table-responsive " style="margin-top:2rem">
	<table class="table table-bordered p-0 m-0" width="100%">
		<thead>
            <th class="text-center" width="5%">
                #
            </th>
            <th class="text-center" width="15%">
                Requestor
            </th>
            <th class="text-center" width="10%">
                Flight Name
            </th>
            <th class="text-center" width="5%">
                No. of Passengers
            </th>
            <th class="text-center" width="15%">
                Origin
            </th>
            <th class="text-center" width="15%">
                Destination
            </th>
            <th class="text-center" width="10%">
                Departure Date and Time
            </th>
            <th class="text-center" width="10%">
                Return Date and Time
            </th>
            <th class="text-center" width="10%">
                Status
            </th>
        </thead>

        <tbody>
            <?php if(!empty($listFlightBooking) && is_array($listFlightBooking)) { ?>
                <?php foreach ($listFlightBooking as $key => $row) {  ?>
                    <tr>
                        <td class="text-center"><?php echo $key+1 ?></td>
                        <td>
                            <b>Requested By : </b><br><?php echo $row['requestor'].' ['.$row['requestor_email'].']'; ?>
                            <br><br>
                            <b>Created By : </b><br><?php echo $row['created_name'].' ['.$row['created_email'].']' ?>
                        </td>
                        <td><?php echo strtoupper($row['flight_name']); ?></td>
                        <td class="text-center"><?php echo $row['no_of_passengers'] ?></td>
                        <td><?php echo strtoupper($row['origin']); ?></td>
                        <td><?php echo strtoupper($row['destination']); ?></td>
                        <td class="text-center"><?php echo date ('d-m-Y', strtotime($row['departure_date'])) . ' / ' . $row['departure_time']; ?></td>
                        <td class="text-center"><?php echo date ('d-m-Y', strtotime($row['return_date'])) . ' / ' . $row['return_time']; ?></td>
                        <td class="text-center">
                            <?php echo ($row['status_app']==null || $row['status_app']=='Pending' )?'Pending':str_replace('_',' ',$row['status_app']); ?> 
                        </td>
                    </tr>
                <?php } ?>
            <?php } ?>
        </tbody>
	</table>
</div>
<?php } ?>	


