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

<header>
	<div class="row">
		<div class="col-12">
			<div class="t-corp pull-left">
				<div class="t-corp-logo">
					<img src="<?php echo (isset($entity_logo))?base_url().'assets/images/entity_logo/'.$entity_logo.'.png':base_url().'assets/images/logo/salihin-logo.png'; ?>" alt="company 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_petty_cash_advance_filter_dept')) && $this->session->userdata('sv_petty_cash_advance_filter_dept') != 'ALL'){ ?>
										<td><span><b style="padding-left: 1rem;"><?php echo $department['name'].' ['.$department['branch_name'].']'; ?></b></span></td>
									<?php } else {?>
										<?php if($finance_staff){ ?>
											<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>ENTITY</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_petty_cash_advance_filter_entity')))?($this->session->userdata('sv_petty_cash_advance_filter_entity')):'ALL'; ?></b></span></td>
								</tr>
								<tr>
									<td><span><b>REQUESTER</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_petty_cash_advance_filter_requester')))?($this->session->userdata('sv_petty_cash_advance_filter_requester')):'ALL'; ?></b></span></td>
								</tr>
								<tr>
									<td><span><b>APPROVER</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_petty_cash_advance_filter_approver')))?($this->session->userdata('sv_petty_cash_advance_filter_approver')):'ALL'; ?></b></span></td>
								</tr>
								<tr>
									<td><span><b>PREPARER</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_petty_cash_advance_filter_preparer')))?($this->session->userdata('sv_petty_cash_advance_filter_preparer')):'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_petty_cash_advance_filter_status')))?($this->session->userdata('sv_petty_cash_advance_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_qr_code_filter_year')))?($this->session->userdata('sv_qr_code_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_qr_code_filter_month')))?($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 PETTY CASH / ADVANCE REQUEST</b></h3>
				</div>
			</div>
			<div class="row">
				<div class="col">
					<p style="border-top: 3px solid; width: 51.5rem;"></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($listPettyCashAdvance[0]['requester_staff_id']))?strtoupper($listPettyCashAdvance[0]['requester_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($listPettyCashAdvance[0]['requester_name']))?$listPettyCashAdvance[0]['requester_name'].' ['.$listPettyCashAdvance[0]['requester_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($listPettyCashAdvance[0]['dept_name']))?$listPettyCashAdvance[0]['dept_name'].' / '.$listPettyCashAdvance[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($listPettyCashAdvance[0]['createdTS']))?date('d-m-Y',strtotime($listPettyCashAdvance[0]['createdTS'])):''; ?>
								</p>
							</div>
						</div>

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

						<div class="row">
							<div class="col-4">
								<b>REQUEST TYPE</b>
							</div>
							<div class="col">
								<p class="report-font">:
									<?php
									if($listPettyCashAdvance[0]['request_type'] == 0) echo 'Petty Cash';
									elseif($listPettyCashAdvance[0]['request_type'] == 1) echo 'Cash Advance';
									elseif($listPettyCashAdvance[0]['request_type'] == 2) echo 'Reimbursement';
									elseif($listPettyCashAdvance[0]['request_type'] == 3) echo 'Perks';
									else echo '';
									?>
								</p>
							</div>
						</div>

						<?php if($listPettyCashAdvance[0]['customerName'] != ''){ ?>
							<div class="row">
								<div class="col-4">
									<b>CLIENT</b>
								</div>
								<div class="col">
									<p class="report-font">
										<?php echo ': <b>Client : </b>'.$listPettyCashAdvance[0]['customerName']; ?>
										<?php echo ($listPettyCashAdvance[0]['job_id'])?'<br>: <b>Job ID : </b>'.str_pad($listPettyCashAdvance[0]['job_id'],5,0,STR_PAD_LEFT):''; ?>

									</p>
								</div>
							</div>
						<?php } ?>

						<div class="row">
							<div class="col-4">
								<b>STATUS</b>
							</div>
							<div class="col">
								<p class="report-font">
									<?php if($listPettyCashAdvance[0]['approval_status'] == 0){ ?>
										: <b>Approval Status - </b>Pending
									<?php } else { ?>
										: <b>Approval Status - </b>
										<?php if($listPettyCashAdvance[0]['approval_status'] == 1)
										{
											echo 
											' Approved
											<br>
											: <b>Approved By - </b>'.$listPettyCashAdvance[0]['approved_by_name'];
										}else{
											echo 
											' Rejected
											<br>
											: <b>Rejected By - </b>'.$listPettyCashAdvance[0]['approved_by_name'];
										}
										?>
										<br>
										: <b>Finance Status - </b>
										<?php if($listPettyCashAdvance[0]['prepared_status'] == 0)
										{
											echo 'Pending';
										}elseif($listPettyCashAdvance[0]['prepared_status'] == 1)
										{
											echo 
											' Completed
											<br>
											: <b>Prepared By - </b>'.$listPettyCashAdvance[0]['prepared_by_name']; 
										}else{
											echo 
											' Duplicate<br>
											: <b>Prepared By - </b>'.$listPettyCashAdvance[0]['prepared_by_name'];
										}
										?>
									<?php } ?>
								</p>
							</div>
						</div>

						<div class="row">
							<div class="col-4">
								<b>DETAIL</b>
							</div>
							<div class="col">
								<p class="report-font">	
									<?php
									$desc_explode 	= explode('->', $listPettyCashAdvance[0]['description']);
									$amount_explode = explode('->', $listPettyCashAdvance[0]['description_amount']);
									?>
									<?php if(sizeof($desc_explode) > 0) foreach($desc_explode as $key => $desc){ ?>
										: <b><?php echo $desc.' - </b>RM'.number_format($amount_explode[$key],2).'<br>'; ?>
									<?php } ?>
								</p>
							</div>
						</div>

						<div class="row">
							<div class="col-4">
								<b>AMOUNT</b>
							</div>
							<div class="col">
								<p class="report-font">
									<?php echo ($listPettyCashAdvance[0]['total_approved'] > 0)?': <b>Amount Approved</b> : RM'.number_format($listPettyCashAdvance[0]['total_approved'],2):': <b>Amount Request</b> : RM'.number_format($listPettyCashAdvance[0]['total'],2) ?>
						            <?php echo ($listPettyCashAdvance[0]['cash_balance'] > 0)?'<br>: <b>Cash Balance</b> : RM'.number_format($listPettyCashAdvance[0]['cash_balance'],2):''; ?>
						            <?php echo ($listPettyCashAdvance[0]['balance_received'] > 0)?'<br>: <b>Balance Received</b> : RM'.number_format($listPettyCashAdvance[0]['balance_received'],2):''; ?>
								</p>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
<?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%">Client</th>
				<th class="text-center" width="15%">Entity</th>
				<th class="text-center" width="15%">Department </th>
				<th class="text-center" width="15%">Requester</th>
				<th class="text-center" width="15%">Status</th>
				<th class="text-center" width="15%">Amount (RM)</th>
			</thead>
			<tbody>
				<?php if(!empty($listPettyCashAdvance)) { ?> 
					<?php foreach($listPettyCashAdvance as $key => $row) { ?>
						<tr>
							<td class="text-center"><?php echo $key+1; ?></td>
							<td>
								<?php echo '<b>Client : </b>'.$row['customerName']; ?>
								<?php echo ($row['job_id'])?'<br><br><b>Job ID : </b>'.str_pad($row['job_id'],5,0,STR_PAD_LEFT):''; ?>

							</td>
							<td><?php echo $row['entity_name']; ?></td>
							<td><?php echo $row['dept_name'].' / '.$row['branchName']; ?></td>
							<td><?php echo $row['requester_name'];//.' ['.$row['requester_email'].']'; ?></td>
							<td>
								<?php if($row['approval_status'] == 0){ ?>
									<b>Approval Status : </b>Pending
								<?php } else { ?>
									<b>Approval Status : </b>
									<?php if($row['approval_status'] == 1)
									{
										echo 
										'Approved
										<br>
										<b>Approved By : </b>'.$row['approved_by_name'];
									}else{
										echo 
										'Rejected
										<br>
										<b>Rejected By : </b>'.$row['approved_by_name'];
									}
									?>
									<br><br>
									<b>Finance Status : </b>
									<?php if($row['prepared_status'] == 0)
									{
										echo 'Pending';
									}
									elseif($row['prepared_status'] == 1)
									{
										echo 
										'Completed
										<br>
										<b>Prepared By : </b>'.$row['prepared_by_name']; 
									}else{
										echo 
										'Duplicate<br>
										<b>Prepared By : </b>'.$row['prepared_by_name'];
									}
									?>
								<?php } ?>
							</td>
							<!-- <td class="text-center"><?php //echo number_format($row['total'],2) ?></td> -->
							<td>
	                            <?php echo ($row['total_approved'] > 0)?'<b>Amount Approved</b> : RM'.number_format($row['total_approved'],2):'<b>Amount Request</b> : RM'.number_format($row['total'],2) ?>
	                            <?php echo ($row['cash_balance'] > 0)?'<br><b>Cash Balance</b> : RM'.number_format($row['cash_balance'],2):''; ?>
	                            <?php echo ($row['balance_received'] > 0)?'<br><b>Balance Received</b> : RM'.number_format($row['balance_received'],2):''; ?>
	                        </td>
						</tr>
					<?php } ?>
				<?php } ?>
			</tbody>
		</table>	
	</div>	
<?php } ?>