<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" />
				</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_invoice_filter_dept')) && $this->session->userdata('sv_invoice_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_invoice_filter_entity')) && ($this->session->userdata('sv_invoice_filter_entity') != 'ALL'))?($this->session->userdata('sv_invoice_filter_entity')):'ALL'; ?></b></span></td>
								</tr>
								<tr>
									<td><span><b>BRANCH</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_invoice_filter_branch')) && ($this->session->userdata('sv_invoice_filter_branch') != 'ALL'))?($this->session->userdata('sv_invoice_filter_branch')):'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_invoice_filter_requester')) && ($this->session->userdata('sv_invoice_filter_requester') != 'ALL'))?($this->session->userdata('sv_invoice_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_invoice_filter_approver')) && ($this->session->userdata('sv_invoice_filter_approver') != 'ALL'))?($this->session->userdata('sv_invoice_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_invoice_filter_preparer')) && ($this->session->userdata('sv_invoice_filter_preparer') != 'ALL'))?($this->session->userdata('sv_invoice_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_invoice_filter_status')) && ($this->session->userdata('sv_invoice_filter_status') != 'ALL'))?($this->session->userdata('sv_invoice_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_invoice_filter_date_from')) && ($this->session->userdata('sv_invoice_filter_date_from') != 'ALL'))?date('d M Y',strtotime($this->session->userdata('sv_invoice_filter_date_from'))):'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_invoice_filter_date_to')) && ($this->session->userdata('sv_invoice_filter_date_to') != 'ALL'))?date('d M Y',strtotime($this->session->userdata('sv_invoice_filter_date_to'))):'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 INVOICE REQUEST</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($listInvoiceRequest[0]['requester_staff_id']))?strtoupper($listInvoiceRequest[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($listInvoiceRequest[0]['requester_name']))?$listInvoiceRequest[0]['requester_name'].' ['.$listInvoiceRequest[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($listInvoiceRequest[0]['dept_name']))?$listInvoiceRequest[0]['dept_name'].'/'.$listInvoiceRequest[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($listInvoiceRequest[0]['createdTS']))?date('d-m-Y',strtotime($listInvoiceRequest[0]['createdTS'])):''; ?>
								</p>
							</div>
						</div>

						<div class="row">
							<div class="col-4">
								<b>INVOICE DETAIL</b>
							</div>
							<div class="col">
								<p class="report-font">
									<?php echo (!empty($listInvoiceRequest[0]['inv_form_no']))?': <b>Invoice No. - </b>'.$listInvoiceRequest[0]['inv_form_no'].'<br>':''; ?>
									<?php echo (!empty($listInvoiceRequest[0]['total']))?': <b>Invoice Total - </b>RM'.number_format($listInvoiceRequest[0]['total'],2):''; ?>
									<?php
                                        $management_fee = 0;
                                        if($listInvoiceRequest[0]['prepared_status'] == 1)
                                        {
                                            $management_fee += ($listInvoiceRequest[0]['total'] * 0.2);
                                        }

										echo ($management_fee > 50)?'<br>: <b>Management Fee - </b>RM'.number_format(50,2):'<br>: <b>Management Fee - </b>RM'.number_format($management_fee,2); 
									?>
								</p>
							</div>
						</div>

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

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

						<div class="row">
							<div class="col-4">
								<b>STATUS</b>
							</div>
							<div class="col">
								<?php if($listInvoiceRequest[0]['approval_status'] == 0){ ?>
									: <b>Approval Status - </b>Pending
								<?php } else { ?>
								: <b>Approval Status - </b>
								<?php if($listInvoiceRequest[0]['approval_status'] == 1)
								{
									echo 
									' Approved
									<br>
									: <b>Approved By - </b>'.$listInvoiceRequest[0]['approved_by_name'];
									echo ($listInvoiceRequest[0]['approval_remark'])?'<br>: <b>Remark - </b>'.$listInvoiceRequest[0]['approval_remark']:'';
								}else{
									echo 
									' Rejected
									<br>
									: <b>Rejected By - </b>'.$listInvoiceRequest[0]['approved_by_name'];
									echo ($listInvoiceRequest[0]['approval_remark'])?'<br>: <b>Remark - </b>'.$listInvoiceRequest[0]['approval_remark']:'';
								}
								?>
								<?php if($listInvoiceRequest[0]['approval_status'] != 2){ ?>
									<br>
									: <b>Finance Status : </b>
									<?php if($listInvoiceRequest[0]['prepared_status'] == 0)
									{
										echo 'Pending';
									}
									elseif($listInvoiceRequest[0]['prepared_status'] == 1)
									{
										echo 
										' Completed
										<br>
										: <b>Prepared By - </b>'.$listInvoiceRequest[0]['prepared_by_name']; 
									}else{
										echo 
										' Duplicate<br>
										: <b>Prepared By - </b>'.$listInvoiceRequest[0]['prepared_by_name'];
									}
									?>
								<?php } ?>
							<?php } ?>
							</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="11%">Invoice No</th>
                <th class="text-center" width="12%">MGS Job ID</th>
                <th class="text-center" width="12%">Entity</th>
                <th class="text-center" width="12%">Branch</th>
                <th class="text-center" width="12%">Department </th>
                <th class="text-center" width="12%">Requester</th>
                <th class="text-center" width="12%">Status</th>
                <?php if($finance_staff) echo '<th class="text-center" width="9%">Management Fee (RM)</th>'; ?>
                <th class="text-center" width="12%">Invoice Amount (RM)</th>
            </thead>
            <tbody>
                <?php if(!empty($listInvoiceRequest)) { ?> 
                    <?php foreach($listInvoiceRequest as $key => $row) {
                        ?>
                        <tr>
                            <td class="text-center"><?php echo $key+1; ?></td>
                            <td class="text-center"><?php echo $row['inv_form_no']; ?></td>
                            <td>
                                <?php echo ($row['job_id'])?'<b>Job ID : </b>'.str_pad($row['job_id'],5,0,STR_PAD_LEFT).'<br><br>':''; ?>
                                
                                <?php echo '<b>Client : </b>'.$row['customerName']; ?>
                            </td>
                            <td><?php echo $row['entity_name']; ?></td>
                            <td><?php echo ($row['inv_branch'])?$row['inv_branch']:'N/A'; ?></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><br>Pending
                                    <?php $disabled = ''; ?>
                                <?php } else { $disabled = 'disabled'; ?>
                                    <b>Approval Status : </b><br>
                                    <?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'];
                                    }
                                    ?>
                                    <?php if($row['approval_status'] != 2){ ?>
	                                    <br><br>
	                                    <b>Finance Status : </b><br>
	                                    <?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 } ?>
                                <?php } ?>
                            </td>
                            <td class="text-center"><?php echo number_format($row['total'],2); ?></td>
                            <?php 
                            if($finance_staff) 
                            {
                                $management_fee = 0;
                                if($row['prepared_status'] == 1)
                                {
                                    $management_fee += ($row['total'] * 0.2);
                                }

                                echo '<td class="text-center">';
                                echo ($management_fee > 50)?number_format(50,2):number_format($management_fee,2);
                                echo '</td>';
                            }
                            ?>
                        </tr>
                    <?php } ?>
                <?php } ?>
            </tbody>
        </table>	
    </div>	
<?php } ?>