<section class="container">
	<?php if (isset($filter)) { ?>
	<div class="row">
		<div class="col-12">
			<?php
			foreach ($filter as $key => $value) {
				$length = strlen(ltrim(rtrim($key)));
				$tab = '';
				if ($length <= 4) {
					$tab = "\t\t\t";
				} else if ($length <=8) {
					$tab = "\t\t";
				} else {
					$tab = "\t";
				}
			?>
			<div class="row">
				<pre class="col-sm-4 col-xs-7 pull-left"><?php echo ltrim(rtrim($key)).$tab; ?>:&nbsp;<b><?php echo $value; ?></b>&nbsp;&nbsp;&nbsp;</pre>
			</div>
			<?php } ?>
		</div>
	</div>
	<?php } ?>
	<?php if (isset($table) && $table != false) { ?>
	<div class="row">
		<div class="table">
			<div class="container" style="border: 1px solid black">
				<div class="row mt-5 ml-3 mr-3 pl-0" style="border:1px solid #dedede;">	
					<div class="col-4 pt-4">
						<img  src="<?php echo base_url().'assets/images/logo/salihin-logo.png'; ?>" alt="company logo"  class="img img-full"/>
					</div>
					<div class="col text-right pt-4 pb-4" style="border-left: 1px solid #dedede;">	
						<b><?php echo ($table[0]->name)? $table[0]->name :''?></b> 
						<br><?php echo ($table[0]->address) ? $table[0]->address : '' ?>
                        <br><?php echo ($table[0]->postcode) ? $table[0]->postcode : '' ?>
                        <?php echo ($table[0]->city) ? $table[0]->city : '' ?>  
                        <br><?php echo ($table[0]->state) ? $table[0]->state : '' ?>
                        <br><?php echo ($table[0]->country) ? $table[0]->country : '' ?>    
					</div>
				</div>
				<div class="row ml-3 mr-3">	
					<div class="col-4 pt-4 pb-4" style="border-left: 1px solid #dedede;border-bottom: 1px solid #dedede;">	
						<b>Salary/Wages Month:</b> <?php echo (!empty($table[0]->month) && !empty($table[0]->year))?date('M',mktime(0,0,0,$table[0]->month,10)).' '.$table[0]->year:''; ?>
					</div>
					<div class="col-4 pt-4 pb-4" style="border-left: 1px solid #dedede;border-right: 1px solid #dedede;border-bottom: 1px solid #dedede;">	<b>IC No:</b> <?php echo ($table[0]->employeeIC)? $table[0]->employeeIC:''; ?>
					</div>
					<div class="col-4 pt-4 pb-4" style="border-right:1px solid #dedede;border-bottom: 1px solid #dedede;">	
						<b>Department:</b> <?php echo ($table[0]->department)?$table[0]->department:''?>							
					</div>
				</div>
				<div class="row ml-3 mr-3">	
					<div class="col-4 pt-4 pb-4" style="border-left: 1px solid #dedede;border-bottom: 1px solid #dedede;">	
						<b>Name:</b> <?php echo ($table[0]->employeeName) ? $table[0]->employeeName :''?>
					</div>
					<div class="col-4 pt-4 pb-4" style="border-left: 1px solid #dedede;border-right: 1px solid #dedede;border-bottom: 1px solid #dedede;">	<b>Employee ID:</b> <?php echo ($table[0]->employeeID) ? $table[0]->employeeID:''?>
					</div>
					<div class="col-4 pt-4 pb-4" style="border-right:1px solid #dedede;border-bottom: 1px solid #dedede;">	
						<b>Designation:</b> <?php echo ($table[0]->position)?$table[0]->position:''?>	
					</div>
				</div>
				<div class="row" >
					<div class="col-12">
						<table width="100%">				
							<tbody>
								<tr class="row">
									<td class="col col-4 ml-4 border-0">
  										<div class="panel panel-default" style="height: 100%">
    										<div class="panel-heading">Salary summary</div>
    											<div class="panel-body pt-0">
    												<table border="0" width="100%">
    													<?php
                                                        $total_allowance = 0;
    													
                                                        if(!empty($allowance)) foreach ($allowance as $aw) {
                                                            if ($aw->description == 'Basic Pay') {                                                            	
    													?>
    													<tr class="p-0 m-0">
    														<td class="border-0 p-0 m-0"><?php echo $aw->description; ?></td>
    														<!-- <td class="border-0 p-0 m-0">:</td> -->
    														<td class="border-0 p-0 m-0 pull-right  "><?php echo number_format($aw->amount,2)?></td>
    														

    													</tr>
    													<?php
    													   }else{
                                                            $total_allowance+=$aw->amount;
                                                           }
                                                        }
    													?> 
                                                        <tr class="p-0 m-0">
                                                            <td class="border-0 p-0 m-0"> Allowance</td>
                                                            <!-- <td class="border-0 p-0 m-0">:</td> -->
                                                            <td class="border-0 p-0 m-0 pull-right "><?php echo number_format($total_allowance,2)?></td>
                                                            

                                                        </tr>

    													<tr class="p-0 m-0">
    														<td class="col-10 border-0 pl-0">Gross Pay</td>
    														<!-- <td class="border-0 p-0 m-0">:</td> -->
    														<td class="border-1 border-bottom text-right pr-0"><?php echo ($table[0]->grossPay) ? number_format($table[0]->grossPay,2) : ''; ?></td>
    														<!--td class=" border-1 border-bottom text-right">
    															<?php echo number_format($total_allowance,2);
	    														?>
    														</td-->
    														
    													</tr>
                                                        <tr>
                                                            <td class="border-0 p-0 m-0">&nbsp;&nbsp;</td>
                                                            <td class="border-0 p-0 m-0">&nbsp;&nbsp;</td>
                                                            <!-- <td class="border-0 p-0 m-0">&nbsp;&nbsp;</td> -->
                                                            
                                                        </tr>
    													<?php
                                                            $total_deduction = 0;

                                                            if(!empty($deduction)){
        														foreach ($deduction as $deduct) {
                                                                    $total_deduction += $deduct->amount;
    													?>
    														
    													<?php } }?>
                                                        <tr class="p-0 m-0">
                                                            <td class="border-0 p-0 m-0"> Deduction</td>
                                                            <!-- <td class="border-0 p-0 m-0">:</td> -->
                                                            <td class="border-0 p-0 m-0 pull-right "><?php echo number_format($total_deduction,2) ?></td>
                                                            
                                                        </tr>
    													<tr class="p-0 m-0">
    														<td class="border-0 pl-1 m-0">Nett Pay</td>
    														<!-- <td class="border-0 p-0 m-0">:</td> -->
    														<td class="border-1 border-bottom m-0 pull-right pr-0"><?php echo ($table[0]->netPay) ? number_format($table[0]->netPay ,2): ''; ?></td>
    														
    													</tr>
    												</table>
    											</div>
  											</div>
									</td>
									<td class="col border-0">
										
  											<div class="panel panel-default" style="height: 100%">
    											<div class="panel-heading">ALLOWANCE</div>
    											<div class="panel-body pt-0">
    												<table border="0" width="100%">
    													<tr>
    														<td class="border-0 p-0 m-0">
    															<?php
	    														foreach ($allowance as $aw) {
	    														     if($aw->description != 'Basic Pay' & $aw->description != 'Allowance'){
                                                                         echo $aw->description.'<br/>';
                                                                    }   

	    															if($aw->description != 'Basic Pay' & $aw->description == 'Allowance'){
	    																 echo $aw->description.'<br/>';
	    															}  															
	    														}
	    														?>
	    										
    														</td>
    														<td class="border-0 border-bottom p-0 m-0" align="right">
    															<?php
	    														foreach ($allowance as $aw) {

                                                                    if($aw->description != 'Basic Pay' & $aw->description != 'Allowance'){
                                                                        echo number_format ($aw->amount,2).'<br/>';
                                                                    }
	    														 
	    															if($aw->description != 'Basic Pay' & $aw->description == 'Allowance'){
	    																echo number_format ($aw->amount,2).'<br/>';
	    															}
    															
	    														}
	    														
	    														?>
    														</td>
    													
    													

    													</tr>
    													<tr>
    														<td class="border-0 col-10 pl-0 border-0 ">
    															Total Allowance
    														</td>
    														<td class=" border-1 border-bottom text-right pr-0">
    															<?php echo number_format($total_allowance,2);
	    														?>
    														</td>
    													</tr>
    													
    												</table>
    											</div>
  											</div>
										
									</td>
									<td class="col mr-4 border-0">
										
  											<div class="panel panel-default" style="height: 100%">
    											<div class="panel-heading">DEDUCTION</div>
    											<div class="panel-body pt-0">
    												<table border="0" width="100%">

    													<?php
                                                            if($deduction != false){
    														foreach ($deduction as $deduct) {
    													?>
    														<tr>
    															<td class="border-0 p-0">
    																<?php 
    																	echo $deduct->description;
    																	if($deduct->description == 'EPF' || $deduct->description == 'SOCSO'){
    																		echo ' \'Yee';
    																	}
    																?>
    															</td>
    															<!-- <td class="border-0 p-0">:</td> -->
    															<td class="border-0 p-0 text-right"><?php echo number_format($deduct->amount,2);?></td>
    															<td class="border-0 p-0 m-0 text-right">
    																<?php
    																if($deduct->description == 'EPF'){
    																	foreach ($employer as $contribute) {
    																		if($contribute->description == 'Employer EPF'){
    																			echo number_format($contribute->amount,2);
    																		}
    																	}
    																		echo ' \'Yer';
    																}
    																if($deduct->description == 'SOCSO'){
    																	foreach ($employer as $contribute) {
    																	if($contribute->description == 'Employer SOCSO'){
    																			echo number_format($contribute->amount,2);
    																		}
    																	}
    																	echo ' \'Yer';
    																}
    																if($deduct->description == 'SIP'){
    																	foreach ($employer as $contribute) {
    																	if($contribute->description == 'Employer SIP'){
    																			echo number_format($contribute->amount,2);
    																		}
    																	}
    																	echo ' \'Yer';
    																}
    																?>
    															</td>
    														</tr>
    													<?php }}?>
    													
    														<tr>
    															<td class=" border-0 pl-0 m-0">Total Deduction</td>
    															<td class="border-1 border-bottom pr-0 text-right"><?php echo number_format($total_deduction,2)?></td>

    														</tr>
    														

    												</table>
    											</div>
  											</div>									
									</td>									
								</tr>
								<tr class="row">
									<td class="col ml-4 mr-4 pb-5 border-0">
										<div class="panel panel-default mb-2" style="height: 65%">
    										<div class="panel-body">
    											<div class="pt-0"> 						
    												<b><?php echo strtoupper($netWord.' only');?><b>
												</div>
    										</div>
    										</div>
    										<div class="text-center">
    											<small> This is a computer generate pay advice printout. No signature is required.</small>
    										</div>
    								</td>
								</tr>			
						
					<?php 	

					} ?>

					
					</div>
					</tbody>

							
				<?php ?>
				<?php
				if (isset($table['footer']['total-column'])) {
					$footer = sizeof($table['footer']['total-column']);
				?>


				<tfoot>
					<tr>
						<td>&nbsp;</td>
						<td colspan="<?php echo sizeof($table['header']) - sizeof($grandTotal); ?>" class="tar"><?php echo $table['footer']['title']; ?></td>
						<?php foreach ($grandTotal as $total) { ?>
						<td class="tar"><?php echo number_format($total, 2); ?></td>
						<?php } ?>
					</tr>
				</tfoot>
				<?php } ?>
				

			</table>
			</div>
		</div>
			
		</div>
	</div>

	<?php if (isset($table['total-title'])) { ?>
	<div class="row">
		<div class="col-xs-12">
			<div class="col-xs-6 col-sm-5 col-md-4 pull-right grand-total form-horizontal">
				<?php
				if (isset($table['total-title']) && count($table['total-title'] == count($sum))) {
					foreach ($table['total-title'] as $title) {
				?>
				<div class="form-group">
					<label class="col-xs-7 total-title"><?php echo $title; ?>:</label>
					<div class="col-xs-5">
						<span class="total-value"><?php echo number_format(array_shift($sum), 2); ?></span>
					</div>
				</div>
				<?php
					}
				}
				?>
			</div>
		</div>
	</div>
	<?php } ?>
</section> 