<?php defined('BASEPATH') OR exit('No direct script access allowed'); 
$from_date = isset($from_date) ? format_date($from_date) :'';
$to_date = isset($to_date) ? format_date($to_date): '';
$companyName = get_company("name");

if(!empty($dualView)) {
	
	$leftViewCnt = count($leftView);
	$rightViewCnt = count($rightView);
	$indirectleftViewCnt = count($indirectLeftView);
	$indirectrightViewCnt = count($indirectRightView);
}

?>
<div class="header">
	<div class="width100 ac fs-18">
		<?php echo $companyName; ?>
	</div>
	<div class="width100 ac fs-16">
		<?php echo $file_name; ?>
	</div>
	<?php if(!empty($from_date) && !empty($to_date)) { ?>
		<div class="width100 ac fs-12">
			<?php echo $from_date; ?> - 
			<?php echo $to_date; ?>
		</div>
	<?php } ?>
	<?php if(!empty($to_date) && empty($from_date)) { ?>
		<div class="width100 ac fs-12">
			as at
			<?php echo $to_date; ?>
		</div>
	<?php } ?>
	<?php if(!empty($branchName)) { ?>
		<div class="width100 ac fs-12">
			<?php echo $branchName; ?>
		</div>
	<?php } ?>
</div>

<div class="content" >
	<?php $width = !empty($dualView) ? "50%" : "100%"; ?>
	<div width="<?php echo $width; ?>" class="fl pad">
		<table class="width100 table1" >
			<thead class="head">
				<?php 
					echo "<tr>";
						foreach($leftViewheading as $headkey => &$headval) { 
						echo '<th class="fs-12"  align="'.($headval['align']).'" style="width:'. $headval['wid'].' !important" ><b>'.$headval['name']."</b></th>";
					} 
					echo "</tr>";
				?>
			</thead>
			<tbody>
				<?php foreach($leftView as $key => $val) { 
						echo "<tr>";
						
						foreach($leftViewheading as $headkey => &$headval) { 
							$class = strpos($val[$headkey], 'botop') !== false ?  "botop" : "";
							$class = strpos($val[$headkey], 'bobottom') !== false ?  $class." bobottom" : $class;
							
							if(!empty($val['addBg'])) {
								$class = $class . " background";
							}
							$right = strpos($val[$headkey], 'rightAlign') !== false ?  "right" : '';
							
							//print_R($right);
							
							echo '<td class="'.$class.'" align="'.($right ? $right : $headval['align']).'" style="width:'. $headval['wid'].' !important" >';
							echo (!empty($val[$headkey]) ? $val[$headkey] : "");
							if (!empty($headval["caption"]) && !empty($val[$headval["caption"]]))
							{
								echo ' <small>' . $val[$headval["caption"]] . '</small>';
							}
							echo "</td>";
						} 
						echo "</tr>";
					}?>
				
			</tbody>
		</table>
	</div>
	<?php if(!empty($dualView) ) { ?>
		<div  width="50%" class="fr pad">
			<table class="width100 table2" >
			<thead class="head">
				<?php 
					echo "<tr>";
						foreach($rightViewheading as $headkey => &$headval) { 
						echo '<th class="fs-12"  align="'.($headval['align']).'" style="width:'. $headval['wid'].' !important" ><b>'.$headval['name']."</b></th>";
					} 
					echo "</tr>";
				?>
			</thead>
				<?php if(!empty($rightView)) { ?>
				<tbody>
					<?php foreach($rightView as $key => $val) { 
							echo "<tr>";
							
							foreach($rightViewheading as $headkey => &$headval) { 
								$class = strpos($val[$headkey], 'botop') !== false ?  "botop" : "";
								$class = strpos($val[$headkey], 'bobottom') !== false ?  $class." bobottom" : $class;
								if(!empty($val['addBg'])) {
									$class = $class . " background";
								}
								echo '<td class="'.$class.'" align="'.$headval['align'].'" style="width:'. $headval['wid'].'" >'.$val[$headkey]."</td>";
							} 
							echo "</tr>";
						}?>
					
				</tbody>
				<?php } ?>
			</table>
		</div>
	<?php } ?>
	
</div>
<div class="content" >
	<?php $width = !empty($dualView) ? "50%" : "100%"; ?>
	<div width="<?php echo $width; ?>" class="fl pad">
		<table class="width100 table3" >
			
			<tbody>
				<?php if(!empty($indirectLeftView )) { foreach($indirectLeftView as $key => $val) { 
						echo "<tr>";
						
						foreach($leftViewheading as $headkey => &$headval) { 
							$class = strpos($val[$headkey], 'botop') !== false ?  "botop" : "";
							$class = strpos($val[$headkey], 'bobottom') !== false ?  $class." bobottom" : $class;
							if(!empty($val['addBg'])) {
								$class = $class . " background";
							}
							$right = strpos($val[$headkey], 'rightAlign') !== false ?  "right" : '';
							//print_R($right);
							
							echo '<td class="'.$class.'" align="'.($right ? $right : $headval['align']).'" style="width:'. $headval['wid'].' !important" >'.(!empty($val[$headkey]) ? $val[$headkey] : "")."</td>";
						} 
						echo "</tr>";
					} }?>
				
			</tbody>
		</table>
	</div>
	<?php if(!empty($dualView) && !empty($indirectRightView)) { ?>
		<div  width="50%" class="fr pad">
			<table class="width100 table4" >
			
				<tbody>
					<?php foreach($indirectRightView as $key => $val) { 
							echo "<tr>";
							
							foreach($rightViewheading as $headkey => &$headval) { 
								$class = strpos($val[$headkey], 'botop') !== false ?  "botop" : "";
							$class = strpos($val[$headkey], 'bobottom') !== false ?  $class." bobottom" : $class;
								if(!empty($val['addBg'])) {
									$class = $class . " background";
								}
								echo '<td class="'.$class.'" align="'.$headval['align'].'" style="width:'. $headval['wid'].'" >'.$val[$headkey]."</td>";
							} 
							echo "</tr>";
						}?>
					
				</tbody>
			</table>
		</div>
	<?php } ?>
	
</div>
<div>
	<table width="50%">
		
		<?php if(!empty($leftViewTotal)) {
		foreach(array($leftViewTotal) as $key => $val) { 
		echo "<tr class='head'>";

			foreach($leftViewheading as $headkey => &$headval) { 
				$class = strpos($val[$headkey], 'botop') !== false ?  "botop" : "";
							$class = strpos($val[$headkey], 'lightbotop') !== false ?  $class." lightbotop" : $class;
			
				$class = $class." fs-12";
				$right = strpos($val[$headkey], 'rightAlign') !== false ?  "right" : '';
				echo '<td class="'.$class.'" align="'.$headval['align'].'" style="width:'. $headval['wid'].' !important" ><b>'.($val[$headkey] ? $val[$headkey] : "0.00")."</b></td>";
				} 
			
			} }?>
	

			<?php if(!empty($rightViewTotal)) { foreach(array($rightViewTotal) as $key => $val) { 
			foreach($rightViewheading as $headkey => &$headval) { 
				$class = strpos($val[$headkey], 'botop') !== false ?  "botop" : "";
							$class = strpos($val[$headkey], 'bobottom') !== false ?  $class." bobottom" : $class;
				
				$class = $class." fs-12";
				echo '<td class="'.$class.'" align="'.$headval['align'].'" style="width:'. $headval['wid'].' !important" ><b>'.($val[$headkey] ? $val[$headkey] : "0.00")."</b></td>";
			} 
		echo "</tr>";
		}}?>
	</table>
</div>

<style>
	<?php if(!empty($dualView)) { ?>
		<?php 
		
		if($leftViewCnt > $rightViewCnt) { ?>
			.table1 td:nth-child(<?php echo count($leftViewheading); ?>) {        
				border-right: 1px solid #000000 !important;
			}
		<?php } ?>

		<?php if($rightViewCnt >= $leftViewCnt) { ?>
		.table2 td:nth-child(1) {        
			border-left: 1px solid #000000 !important;
		}
		<?php } ?>
		<?php if($indirectleftViewCnt > $indirectrightViewCnt) {  ?>
			.table3 td:nth-child(<?php echo count($leftViewheading); ?>) {        
				border-right: 1px solid #000000 !important;
			}
		<?php } ?>
		<?php if($indirectrightViewCnt >= $indirectleftViewCnt) { ?>
		.table4 td:nth-child(1) {        
			border-left: 1px solid #000000 !important;
		}
		<?php } ?>
	<?php } ?>
	.fl {
		float : left;
	}
	
	td.botop {
		border-top : 1px solid grey ;
		
	}
	td.bobottom {
		border-bottom : 1px solid grey ;
		
		
	}
	td.lightbotop {
		border-bottom : 1px solid grey !important;
	}
	.boleft {
		
	}
	
	table {
		border-collapse: collapse !important;
		border-spacing: 0 ;
		overflow: wrap ;
		table-layout: fixed;
	}
	<?php if(!empty($leftViewheading ) && !empty($isComparison)) { ?>
		td {
			border-right: 1px solid #D3D3D3;
		}

		.table1 td:nth-child(<?php echo count($leftViewheading); ?>) {        
			border-right: 1px solid white !important;
		}
	<?php } ?>
	.head th,.head td {
		border-top:1px solid black;
		border-bottom:1px solid black;
	}
	/*.content {
		border-top:1px solid black;
		border-bottom:1px solid black;
	}*/
	.width100 {
		width : 100%;
	}
	.rightAlign {
		text-align : right !important;
	}
	.ac {
		text-align : center;
	}
	.fs-18 {
		font-size : 18px;
	}
	.fs-16 {
		font-size : 16px;
	}
	.fs-15 {
		font-size : 15px;
	}
	.fs-12 {
		font-size : 12px;
	}
	.ital {
		font-style : italic !important;
	}
	.background {
		background-color : #F0F0F0;
	}
	td {
		padding : 2px;
	}
	
</style>
