<?php
/**
* @author : Zul Zolkaffly (24/08/2016)
*/
?>
<script>

function FinPerfYearChange() {
	var y = $('input[name="yearCurr"], input#year0').val();
	var p = $('input[name="yearPrev"], input#year1').val();
	
	$.post('<?php echo base_url(); ?>apply/financialperformanceajax',{ y:y, p:p },function(result) {

		var obj = (result) ? JSON.parse(result) : null;
		if ( $.isEmptyObject( obj ) ) return;
		
		if ( !$.isEmptyObject( obj['perf'] ) ) {
			$.each(obj['perf'], function(k,v) {
				var $elem = $('#'+k);			
				if($elem.length) $elem.html( accounting.formatNumber(v,2)	);
			});
		}
		
		if ( !$.isEmptyObject( obj['ratios'] ) ) {
			$.each(obj['ratios'], function(k,v) {
				var $elem = $('#'+k);			
				if($elem.length) $elem.html(v);
			});
		}
		
		
		InitCheckUnbalance();
	});
}
</script>

<div class="box box-warning">
	<div class="box-header with-border">
		<h3 class="box-title">Prestasi Kewangan</h3>
		<div class="box-tools pull-right">
			<button class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
		</div>
	</div>
	
	<div class="box-body">
		<table id="ratioTable" class="table table-bordered table-striped datatables">
			<thead>
				<tr>
					<th rowspan="2" class="col-md-8">Perkara</th>
				</tr>
				<tr>
					<th class="col-md-2 text-center">
						Tahun Semasa<br />Berakhir Pada 31/12/<span class="year_curr"><?php echo ($years && $years[0]) ? $years[0] : NULL; ?></span>
					</th>
					<th class="col-md-2 text-center">
						Tahun Sebelum<br />Berakhir Pada 31/12/<span class="year_prev"><?php echo ($years && $years[1]) ? $years[1] : NULL; ?></span>
					</th>
				</tr>
			</thead>
			
			<tbody>
			<?php
			if($perf) {
				$k = 0;
				foreach($perf as $key=>$value) {
					?>
					<tr>
					<td class="blk5"><?php echo $this->lang->line(strtolower(str_replace(" ","",$key))); ?></td>
					<td class="text-center" id="<?php echo "perf_".$k; ?>_0">
						<?php echo ($years && $years[0]) ? number_format($value[$years[0]],2) : NULL; ?>
					</td>
					<td class="text-center" id="<?php echo "perf_".$k; ?>_1">
						<?php echo ($years && $years[1]) ? number_format($value[$years[1]],2) : NULL; ?>
					</td>
					</tr>
					<?php
					$k++;
				}
			}				
			?>
			</tbody>
		</table>
	</div>

</div>

<div class="box box-warning">
	<div class="box-header with-border">
		<h3 class="box-title"><?php echo $this->lang->line('ratio'); ?></h3>
		<div class="box-tools pull-right">
			<button class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
		</div>
	</div>
	
	<div class="box-body">
		<table id="ratioTable" class="table table-bordered table-striped datatables">
			<thead>
				<tr>
					<th rowspan="2" class="col-md-8"><?php echo $this->lang->line('ratio'); ?></th>
				</tr>
				<tr>
					<th class="col-md-2 text-center">
						Tahun Semasa<br />Sehingga 31/12/<span class="year_curr"><?php echo ($years && $years[0]) ? $years[0] : NULL; ?></span>
					</th>
					<th class="col-md-2 text-center">
						Tahun Sebelum<br />Sehingga 31/12/<span class="year_prev"><?php echo ($years && $years[1]) ? $years[1] : NULL; ?></span>
					</th>
				</tr>
			</thead>
			
			<tbody>
			<?php
			if($ratios) {	
				foreach($ratios as $key=>$value) {
					if($value['details']) {
						foreach($value['details'] as $index=>$item) {
							?>
							<tr>
							<td class="blk5"><?php echo $this->lang->line(strtolower($item['name'])); ?></td>
							<td class="text-center" id="<?php echo "fp_ratio_".$key."_".$index; ?>_0">
								<?php echo ($years && $years[0]) ? $item['data'][$years[0]] : NULL; echo ($value['name'] == "Income Ratio") ? "%" : NULL; ?>
							</td>
							<td class="text-center" id="<?php echo "fp_ratio_".$key."_".$index; ?>_1">
								<?php echo ($years && $years[1]) ? $item['data'][$years[1]] : NULL; echo ($value['name'] == "Income Ratio") ? "%" : NULL; ?>
							</td>
							</tr>
							<?php
						}
					}		
				}
			}				
			?>
			</tbody>
		</table>
	</div>

</div>



