<!DOCTYPE html>
<html>
<head>
<title><?php echo $this->data->set->modul ?></title>
<script src="<?php echo $this->baseUrl ?>assets/js/jquery-1.7.2.min.js" type="text/javascript"></script>
<style>
#_apankReport{
	margin: 0px auto;
}
#_judulReport{
	text-align: center;
	font-size: 16px;
	font-family: arial;
	font-weight: bold;
}
#_filterReport{
	text-align: center;
	font-size: 12px;
	font-family: arial;
}
#_bodyReportTop{
	overflow: auto;
	width: 100%;
	background-color: #EDF1F2;
	margin: 0px auto;
	text-align: center;
}
._tableReport{
	background-color: #EDF1F2;
	border-top: 1px solid #616363;
	border-left: 1px solid #616363;
}
._tableReport tr td{
	background-color: #fff;
}
._tableReportHead{
	border-bottom: 1px solid #616363;
	border-right: 1px solid #616363;
	font-family: arial;
	font-size: 12px;
}
._tableReportHead2{
	border-right: 1px solid #616363;
	font-family: arial;
	font-size: 12px;
}
._tableReportHeadGrup{
	border-bottom: 1px solid #616363;
	border-right: 1px solid #616363;
	font-family: arial;
	font-size: 12px;
	background-color: #EDF1F2;
}
._tableReportInput{
	border: none;
	background-color: #E6F5FA;
	color: #161717;
	padding: 2px;
}
._tableReportInputData{
	border: none;
	background-color: #fff;
	color: #161717;
	padding: 2px;
}
._tableReportInputDataGrup{
	border: none;
	background-color: #EDF1F2;
	color: #161717;
	padding: 2px;
}
._tableReport tbody {
    overflow: auto;
	height: 500px;
}
#_tableReport thead > tr{
    display:block;
}
#_tableReport tbody{
    display:block;
}
._tablePadding2{
    padding: 2px;
}
#_button{
	text-align: center; 
	margin-top: 5px;
}
#_disFooter{
	margin-top: 5px;
	font-size: 12px;
	font-family: arial;
}
#_disFooter ._header{
	font-weight: bold;
}
#_disFooter ._repTable{
	margin-top: 5px;
	margin-bottom: 10px;
	font-size: 12px;
	font-family: arial;
	border-top: 1px solid #616363;
	border-left: 1px solid #616363;
	border-bottom: 1px solid #616363;
}
#_disFooter ._repTable tbody tr th{
	margin-top: 5px;
	font-size: 12px;
	font-family: arial;
	border-bottom: 1px solid #616363;
	border-right: 1px solid #616363;
	padding: 2px;
}
#_disFooter ._repTable tbody tr td{
	margin-top: 5px;
	font-size: 12px;
	font-family: arial;
	border-right: 1px solid #616363;
	padding: 2px;
}
</style>
</head>
<body>
<?php 
$width = 40;
$vWdth = array();
$hed1 = array();
$hed2 = array();
$hedJ = 1;
foreach($this->data->set->display as $row){
	$width = $width + ($row['width'] + 3);
	
	$id = $row['id'];
	$vWdth[$id]->width 	= $row['width'];
	$vWdth[$id]->dec 	= $row['dec'];
	
	$row2 = $row;
	$idH = $row['id'];
	if(!empty($row['induk'])){
		$idH = $row['induk'];
		$hedJ = 2;
	}else{
		$row2['nama'] = '';
	}
	if(empty($hed1[$idH])){
		$hed1[$idH] = $row;
	}
	$hed1[$idH]['widthH'] = $hed1[$idH]['widthH'] + ($row['width']);
	$hed1[$idH]['child'][] = $row;
	
	$hed2[] = $row2;
}

$rumus = new RumusReport;

$atrHit = array();
foreach($this->data->set->hitung as $r){
	$atrHit[$r] = $r;
}
?>

<div id="_apankReport">
	<div id="_headerReportTop">
		<div id="_judulReport"><?php echo $this->data->set->modul ?></div>
		<div id="_filterReport"><?php echo $this->data->filter ?></div>
	</div>
	<div id="_bodyReportTop" style="width: <?php echo $width ?>px">
		<table style="width: <?php echo $width ?>px" border="0" cellspacing="0" cellpadding="0" id="_tableReport" class="_tableReport">
			<thead>
				<?php
				if(count($hed1) > 0){
				?>
				<tr>
					<?php 
					foreach($hed1 as $inNm => $row){
						$clsHd = '_tableReportHead';
						$align = 'left';
						if($row['type'] == 'numeric'){
							$align = 'right';
						}
						$plusHed = 0;
						$rowspan = 1;
						if(count($row['child']) > 1){
							$plusHed 	= (count($row['child']) * 4) - 2;
							$align 		= 'center';
						}else{
							$rowspan 	= 2;
							if($hedJ > 1){
								$clsHd = '_tableReportHead2';
							}
						}
						$row['widthH'] = $plusHed + $row['widthH'];
						
						if(!empty($row['induk'])){
							$valNm = $row['induk'];
						}else{
							$valNm = $row['nama'];
						}
						
					?>	
						<th rowspan="<?php echo $rowspan ?>" style="width: <?php echo $row['widthH'] ?>px" class="<?php echo $clsHd ?>">
							<input type="text" readonly class="_tableReportInput" value="<?php echo strtoupper($valNm) ?>" style="width: <?php echo $row['widthH'] ?>px; text-align: <?php echo $align ?>">
						</th>
					<?php
					}
					?>
					<th style="width: 10px">.....</th>
				</tr>
				<?php
				}
				?>
				<?php
				if($hedJ > 1){
				?>
				<tr>
					<?php 
					foreach($hed2 as $row){
						$align = 'left';
						if($row['type'] == 'numeric'){
							$align = 'right';
						}
					
					?>
						<th style="width: <?php echo $row['width'] ?>px" class="_tableReportHead">
							<input type="text" readonly class="_tableReportInput" value="<?php echo $row['nama'] ?>" style="width: <?php echo $row['width'] ?>px; text-align: <?php echo $align ?>">
						</th>
					<?php } ?>
					<th style="width: 10px">.....</th>
				</tr>
				<?php
				}
				?>
			</thead>
			<tbody id="_tableReportBody" style="height: 500px">
				<?php
				$nom = 1;
				$no = 0;
				$grup = '';
				$vHit = array();
				$grbB = $this->data->set->groupBy;
				$repo = new Report;
				foreach($this->data->data as $n => $i){
					$no = $no + 1;
					if(count($this->data->set->hitung) > 0 or !empty($grbB)){
						if(!empty($grbB)){
							if($grup != $i->$grbB){
								if($n > 0){
									if(count($this->data->set->hitung) > 0){
									?>
										<tr>
											<?php 
											foreach($this->data->hit as $kHit => $rHit){ 
												if($rHit->cl > 0){
													$nm = $rHit->nm;
													$_idG = $rHit->nm;
													$pd = '';
													if(!empty($nm)){
														$nm = $vHit[$grup]->$nm;
														$nm = number_format($nm, (int)$vWdth[$_idG]->dec);
													}
													if($kHit == 0){
														$nm = 'Total';
														$pd = "; padding: 2px;";
													}
													if($rHit->cl < 100){
									?>
										<td colspan="<?php echo $rHit->cl ?>" class="_tableReportHeadGrup" style="text-align: right <?php echo $pd ?>; background-color: #EDF1F2">
											<?php if($kHit == 0){ echo $nm; }else{ ?>
												<input type="text" readonly class="_tableReportInputDataGrup" style="width: <?php echo $vWdth[$_idG]->width ?>px; text-align: right" value="<?php echo $nm ?>">
											<?php } ?>
										</td>
									<?php 
											}
										}
									} 
									?>
								</tr>
							<?php
							}
							
						}
						if(count($this->data->set->groupDis) > 0){
							$nmGrup = '';
							foreach($this->data->set->groupDis as $kGrup => $nGrup){
								if(!empty($nmGrup)){
									$nmGrup.= ', ';
								}
								if(!empty($kGrup)){
									$nmGrup.= $kGrup.' : '.$i->$nGrup;
								}else{
									$nmGrup.= $i->$nGrup;
								}
							}
							$nom = 1;
						?>
						<tr>
							<td class="_tableReportHeadGrup" colspan="<?php echo count($this->data->set->display) ?>" style="background-color: #fff">
								<?php echo $nmGrup ?>
							</td>
						</tr>
				<?php
					}
					$grup = $i->$grbB;
					if(count($this->data->set->groupByFo) > 0 and $no > 1){
						$grupFotDis = $repo->setFoter2($this->data->set, $iNew);
				?>
					<tr>
						<td class="_tableReportHeadGrup" colspan="<?php echo count($this->data->set->display) ?>" style="background-color: #EDF1F2; padding: 2px">
							<?php echo $grupFotDis ?>
						</td>
					</tr>
				<?php
								}
							}
						}
					}
				?>
					<tr>
					<?php
					foreach($this->data->set->display as $row){
						$align = '';
						$id = $row['id']; 
						
						$val = $i->$id;
						if(!empty($row['set'])){
							$funct = 'set'.$row['set'];
							$val = $rumus->$funct($i);
						}
						
						if(!empty($atrHit[$id])){
							$idGrpH = '';
							if(!empty($grbB)){
								$idGrpH = $i->$grbB;
							}
							$vHit[$idGrpH]->$id = $vHit[$idGrpH]->$id + $val;
						}
						
						if($row['type'] == 'no'){
							$align = 'right';
							$val = $nom++;
						}
						if($row['type'] == 'numeric'){
							$align = 'right';
							$val = number_format($val, (int)$row['dec']);
						}
						
						if($row['_number'] == true){
							$val = $no;
						}
								
						if($row['noduplicate'] == true){
							if($sama[$id] != $val){
								$sama[$id] = $val;
								
							}else{
								$val = '';
							}
						}
						
					?>
						<td style="width: <?php echo $row['width'] ?>px" class="_tableReportHead">
							<input type="text" readonly class="_tableReportInputData" style="width: <?php echo $row['width'] ?>px; text-align: <?php echo $align ?>" value="<?php echo $val ?>">
						</td>
					<?php 
					}
					?>
					</tr>
				<?php
					$iNew = $i;
				} 
				if(count($this->data->set->hitung) > 0){
				?>
				<tr>
					<?php 
					foreach($this->data->hit as $kHit => $rHit){ 
						if($rHit->cl > 0 and $rHit->cl < 100){
							$nm = $rHit->nm;
							$_idG = $rHit->nm;
							$pd = '';
							if(!empty($nm)){
								$nm = $vHit[$grup]->$nm;
								$nm = number_format($nm, (int)$vWdth[$_idG]->dec);
							}
							if($kHit == 0){
								$nm = 'Total';
								$pd = "; padding: 2px;";
							}
					?>
						<td colspan="<?php echo $rHit->cl ?>" class="_tableReportHeadGrup" style="text-align: right <?php echo $pd ?>; background-color: #EDF1F2">
							<?php if($kHit == 0){ echo $nm; }else{ ?>
								<input type="text" readonly class="_tableReportInputDataGrup" style="width: <?php echo $vWdth[$_idG]->width ?>px; text-align: right" value="<?php echo $nm ?>">
							<?php } ?>
						</td>
					<?php 
						}
					} 
					?>
				</tr>
				<?php } 
				if(count($this->data->set->groupByFo) > 0){
				?>
					<tr>
						<td class="_tableReportHeadGrup" colspan="<?php echo count($this->data->set->display) ?>" style="background-color: #EDF1F2; padding: 2px">
							<?php echo $grupFotDis ?>
						</td>
					</tr>
				<?php } ?>
			</tbody>
		</table>
	</div>
	<div id="_button">
		<input type="button" class="_button" value="Classic" id="cetak">
		<input type="button" class="_button" value="PDF" id="pdf">
		<input type="button" class="_button" value="Excel" id="excel">
	</div>
	<div id="_disFooter">
		<?php
		if(!empty($this->data->set->footer) and $this->data->set->footer != false and count($this->data->set->footer) > 0){
			foreach($this->data->set->footer as $row){
				echo '<div class="page-break">';
				echo '<div class="_bodyLap">';
				echo '<div class="_header">'.$row->header.'</div>';
				echo $row->body;
				echo $row->footer;
				echo "<div>";
			}
		}
		?>
	</div>
</div>
<?php
$ref = $_SERVER['QUERY_STRING'];
$ref = str_ireplace("ref=", "", $ref);
$url = $this->baseUrl.$ref;

?>

<script type="text/javascript">
$(document).ready(function(){
	_tWidth = parseInt("<?php echo $width ?>");
	_width  = parseInt(screen.width) - 30;
	_height = parseInt(screen.height) - 230;

	if(_tWidth > _width){
		$('#_bodyReportTop').css("width", _width+"px");
	}
	$('#_tableReportBody').css("height", _height+"px");
	
	$('._button').click(function(){
		_url = "<?php echo $url ?>";
		_id  = this.id;
		_url = _url+'&convert='+_id;
		window.open(_url);
	})
})
</script>
</body>
</html>
