


<?php
if ( ! function_exists('GetStateName')) {
	function GetStateName($s) {
    $CI = & get_instance();
		$t = $CI->general_model->get_all('_ref_state');
		
		if(!$t) return NULL;
		$r = NULL;
		foreach($t as $key=>$value) {
			$i = (isset($value->fldid)) ? $value->fldid : 0;
			$d = (isset($value->fldname)) ? $value->fldname : 0;
			if($i == $s) {
				$r = $d;
				break;
			}
		}
		return $r;
	}
}

if ( ! function_exists('GetPositionName')) {
	function GetPositionName($s) {
    $CI = & get_instance();
		$t = $CI->general_model->get_all('_ref_position');
		
		if(!$t) return NULL;
		$r = NULL;
		foreach($t as $key=>$value) {
			$i = (isset($value->posID)) ? $value->posID : 0;
			$d = (isset($value->posMal)) ? $value->posMal : 0;
			if($i == $s) {
				$r = $d;
				break;
			}
		}
		return $r;
	}
}
?>

<div class="box box-warning" style="margin-bottom: 5px !important;">
	<div class="box-header with-border"><strong><?php echo ($data) ? $data['title'] : NULL; ?></strong></div>
	<div class="box-body">
	<?php
		if($data['data']) {			
			//echo "<pre>";
			//print_r($data['data']);
			//echo "</pre>";
			//echo "<br />";
			$showpercent = FALSE;
			if (strpos(strtoupper($data['title']), "MARGIN") !== FALSE) $showpercent = TRUE;
			if (strpos(strtoupper($data['title']), "PULANGAN KE ATAS") !== FALSE) $showpercent = TRUE;
			
			$keys = array_keys($data['data'][0]);	
			$ceys = array("anotherShare","changeName","changeAddress","changeShareholder","changeDirector");
			$intersect = array_intersect($ceys, $keys);
			if(!empty($intersect)) {
				$pop = array_pop($intersect);
				$changed = TRUE;
				echo "<strong>";
				echo ($data['data'][0][$pop]) ? "ADA" : "TIADA";
				echo " ".(($pop=="anotherShare") ? "KEPENTINGAN DI SYARIKAT LAIN" : "PERUBAHAN")."</strong>";
			} else {
				$changed = FALSE;
			}
			
			echo "<table class=\"table table-bordered table-responsive table-hover\">\n";
			echo "<thead>\n";
			echo "<tr>\n";
			echo "<th>#</th>\n";
			foreach($keys as $key) {
				if(!in_array($key, array("ID","companyID","anotherShare","changeName","changeAddress","changeShareholder","changeDirector"))) {
					echo "<th style=\"text-align: left;\">".($this->lang->line($key))."</th>\n";
				}
			}
			echo "</tr>\n";
			echo "</thead>\n";
			
			echo "<tbody>\n";
			foreach($data['data'] as $key=>$value) {
				echo "<tr>";
				echo "<td>".($key+1)."</td>\n";
				if($value) {
					foreach($value as $index=>$item) {
						if(!in_array($index, array("ID","companyID","anotherShare","changeName","changeAddress","changeShareholder","changeDirector"))) {
							if(in_array(strtoupper($index), array("UNIT","COST"))) {
								echo "<td>".(number_format($item,2))."</td>\n";
							} else if (strtoupper($index) == "BUMI") {
								echo "<td>".(($item) ? "<i class=\"fa fa-check\"></i>" : "<i class=\"fa fa-times\"></i>")."</td>\n";
							} else if (strtoupper($index) == "POSITION") {
								echo "<td>".(GetPositionName($item))."</td>\n";
							} else {
								echo "<td>".$item.((strtoupper($index)=="VALUE") ? (($showpercent) ? "%" : NULL) : NULL)."</td>\n";
							}
						}
					}
				} else {
					for($i=0; $i<count($keys); $i++) {
						echo "<td>&nbsp;</td>\n";
					}
				}
				echo "</tr>";
			}
			
			echo "</tbody>\n";
			echo "</table>\n";
		}
	?>
	</div>
	<br />
</div>