<?php
	if(($this->session->userdata('sv_credit_note_filter_month') && $this->session->userdata('sv_credit_note_filter_month') != 'no result')){
		if($this->session->userdata('sv_credit_note_filter_month') == '01'){
	         $month = "JANUARY";
	    }else if($this->session->userdata('sv_credit_note_filter_month') == '02'){
	         $month = "FEBRUARY";
	    }else if($this->session->userdata('sv_credit_note_filter_month') == '03'){
	         $month = "MARCH";
	    }else if($this->session->userdata('sv_credit_note_filter_month') == '04'){
	         $month = "APRIL";
	    }else if($this->session->userdata('sv_credit_note_filter_month') == '05'){
	         $month = "MAY";
	    }else if($this->session->userdata('sv_credit_note_filter_month') == '06'){
	         $month = "JUNE";
	    }else if($this->session->userdata('sv_credit_note_filter_month') == '07'){
	         $month = "JULY";
	    }else if($this->session->userdata('sv_credit_note_filter_month') == '08'){
	         $month = "AUGUST";
	    }else if($this->session->userdata('sv_credit_note_filter_month') == '09'){
	         $month = "SEPTEMBER";
	    }else if($this->session->userdata('sv_credit_note_filter_month') == '10'){
	         $month = "OCTOBER";
	    }else if($this->session->userdata('sv_credit_note_filter_month') == '11'){
	         $month = "NOVEMBER";
	    }else if($this->session->userdata('sv_credit_note_filter_month') == '12'){
	         $month = "DECEMBER";
        }else if($this->session->userdata('sv_credit_note_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_credit_note_filter_dept')) && $this->session->userdata('sv_credit_note_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_credit_note_filter_entity')))?($this->session->userdata('sv_credit_note_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_credit_note_filter_branch')))?($this->session->userdata('sv_credit_note_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_credit_note_filter_requester')))?($this->session->userdata('sv_credit_note_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_credit_note_filter_approver')))?($this->session->userdata('sv_credit_note_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_credit_note_filter_preparer')))?($this->session->userdata('sv_credit_note_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_credit_note_filter_status')))?($this->session->userdata('sv_credit_note_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 CREDIT NOTE 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($listCreditNoteRequest[0]['requester_staff_id']))?strtoupper($listCreditNoteRequest[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($listCreditNoteRequest[0]['requester_name']))?$listCreditNoteRequest[0]['requester_name'].' ['.$listCreditNoteRequest[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($listCreditNoteRequest[0]['dept_name']))?$listCreditNoteRequest[0]['dept_name'].'/'.$listCreditNoteRequest[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($listCreditNoteRequest[0]['createdTS']))?date('d-m-Y',strtotime($listCreditNoteRequest[0]['createdTS'])):''; ?>
								</p>
							</div>
						</div>

						<div class="row">
							<div class="col-4">
								<b>CREDIT NOTE NO</b>
							</div>
							<div class="col">
								<p class="report-font">: 
									<?php echo (!empty($listCreditNoteRequest[0]['cn_form_no']))?$listCreditNoteRequest[0]['cn_form_no']:''; ?>
								</p>
							</div>
						</div>

						<div class="row">
							<div class="col-4">
								<b>ENTITY</b>
							</div>
							<div class="col">
								<p class="report-font">:
									<?php echo (!empty($listCreditNoteRequest[0]['entity_name']))?$listCreditNoteRequest[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 ($listCreditNoteRequest[0]['job_id'])?': <b>Job ID : </b>'.str_pad($listCreditNoteRequest[0]['job_id'],5,0,STR_PAD_LEFT).'<br>':''; ?>
	                                
	                                <?php echo ': <b>Client : </b>'.$listCreditNoteRequest[0]['customerName']; ?>
	                            </p>
							</div>
						</div>

						<div class="row">
							<div class="col-4">
								<b>STATUS</b>
							</div>
							<div class="col">
								<?php if($listCreditNoteRequest[0]['approval_status'] == 0){ ?>
									: <b>Approval Status - </b>Pending
								<?php } else { ?>
								: <b>Approval Status - </b>
								<?php if($listCreditNoteRequest[0]['approval_status'] == 1)
								{
									echo 
									' Approved
									<br>
									: <b>Approved By - </b>'.$listCreditNoteRequest[0]['approved_by_name'];
								}else{
									echo 
									' Rejected
									<br>
									: <b>Rejected By - </b>'.$listCreditNoteRequest[0]['approved_by_name'];
								}
								?>
								<br>
								: <b>Finance Status : </b>
								<?php if($listCreditNoteRequest[0]['prepared_status'] == 0)
								{
									echo 'Pending';
								}
								elseif($listCreditNoteRequest[0]['prepared_status'] == 1)
								{
									echo 
									' Completed
									<br>
									: <b>Prepared By - </b>'.$listCreditNoteRequest[0]['prepared_by_name']; 
								}else{
									echo 
									' Duplicate<br>
									: <b>Prepared By - </b>'.$listCreditNoteRequest[0]['prepared_by_name'];
								}
								?>
							<?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%">Credit Note 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>
                <th class="text-center" width="12%">Amount (RM)</th>
            </thead>
            <tbody>
                <?php if(!empty($listCreditNoteRequest)) { ?> 
                    <?php foreach($listCreditNoteRequest as $key => $row) {
                        ?>
                        <tr>
                            <td class="text-center"><?php echo $key+1; ?></td>
                            <td class="text-center"><?php echo $row['cn_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'];
                                    }
                                    ?>
                                    <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 } ?>
                            </td>
                            <td class="text-center"><?php echo (isset($_SESSION['sv__credit_note']))?$row['total']:number_format($row['total'],2); ?></td>
                        </tr>
                    <?php } ?>
                <?php } ?>
            </tbody>
        </table>	
    </div>	
<?php } ?>