<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>
		<?php
		$login = $this->login;
		if(!empty($login['user'])){
			echo $login['user'].' | ';
		}
		$menu = new Menu;
		echo $menu->setTitileMenu($this->getParameter['modul'], $this->getParameter['asliGetCotroller']);
		?> 
  </title>
  
  
		<link rel='stylesheet' href='<?php echo $this->baseUrl ?>assets/thema/apankGrid2019/css/bootstrap.min.css'>
		<link rel="stylesheet" href="<?php echo $this->baseUrl ?>assets/thema/apankGrid2019/css/style.css">
		<script src='<?php echo $this->baseUrl ?>assets/js/jquery-1.7.2.min.js'></script>
		<script src="<?php echo $this->baseUrl ?>assets/js/apank.js" type="text/javascript"></script>
		<script src="<?php echo $this->baseUrl ?>assets/js/accounting.js" type="text/javascript"></script>
		<script src="<?php echo $this->baseUrl ?>assets/js/jquery.meio.mask.js" type="text/javascript"></script>

  
</head>

<body>

<?php
$hed = array();
$tmp = array();
$no  = 0;
foreach($this->data->hed as $k => $r){
	$id = $r['attr'];
	$tmp[$id] = $k;
	$hed[$no++] = $r;
}
$det = $this->data->det;
$fix = $tmp[$this->data->fix];
$kan = $fix + 1;
$max = count($this->data->hed);

$wdh = 0;
for($i = 0; $i < $kan; $i++){
	$r  = $hed[$i];
	$wdh = $wdh + $r['size'];
}

$height = (int)$this->data->height;
if($height <= 0){
	$height = 500;
}

$width = (int)$this->data->width;
if($width <= 0){
	$width = 700;
}

?>

<style type="text/css">
.fixedTable-header {
  margin-left: <?php echo $wdh ?>px;
}
.fixedTable-sidebar {
  width: <?php echo $wdh ?>px;
  height: <?php echo $height ?>px;
}
.fixedTable-body {
  height: <?php echo $height ?>px;
  width: <?php echo $width ?>px;
}
.fixedTable-header {
  width: <?php echo $width ?>px;
}
._judulInputan{
	font-size: 14px;
	font-weight: bold;
	margin-top: 10px;
	margin-left: 10px;
}
</style>

<p class="_judulInputan"><?php echo $this->data->judul ?></p>
<?php if($this->data->form == true){ ?>
	<form method="POST" action="">
<?php }?>

<div class="fixedTable" id="demo">
  <header class="fixedTable-header">
    <table class="table table-bordered">
      <thead>
        <tr>
			<?php
			for($i = $kan; $i < $max; $i++){
				$r = $hed[$i];
				$r['judul'] = trim($r['judul']);
			?>
				<th style="min-width: <?php echo $r['size'] ?>px; width: <?php echo $r['size'] ?>px">
					<input type='text' readonly disabled class="_textApankGrid" style="width: <?php echo ($r['size']-2) ?>px" value="<?php echo $r['judul'] ?>">
				</th>
			<?php } ?>
        </tr>
      </thead>
    </table>
  </header>
  <aside class="fixedTable-sidebar">
    <table class="table table-bordered">
      <tbody>
		<?php 
		$nom = 1;
		foreach($det as $row){ 
		?>
			<tr>
				<?php 
				for($i = 0; $i < $kan; $i++){
					$r  = $hed[$i];
					$id = $r['attr'];
					$read = '';
					if(!empty($r['readonly'])){
						$read = 'readonly';
					}
					$idIns = $id.'_'.$nom;
				?>
					<td style="min-width: <?php echo $r['size'] ?>px; width: <?php echo $r['size'] ?>px">
						<input type='text' <?php echo $read ?> id="<?php echo $idIns ?>" class="_textApankGrid <?php echo $r['class']?>" style="width: <?php echo ($r['size']-2) ?>px" name="<?php echo $id."[".$nom."]" ?>" value="<?php echo $row->$id ?>">
					</td>
				<?php 
				} 
				?>
			</tr>
		<?php 
			$nom++;
		} 
		?>
      </tbody>
    </table>
  </aside>
  
  <div class="fixedTable-body">
    <table class="table table-bordered">
      <tbody>
		<?php 
		$nom = 1;
		foreach($det as $row){ 
		?>
			<tr>
				<?php 
				for($i = $kan; $i < $max; $i++){
					$r  = $hed[$i];
					$id = $r['attr'];
					
					
					$read = '';
					$cls  = '_inputAct';
					if(!empty($r['readonly'])){
						$read = 'readonly';
						$cls  = '';
					}else{
						$kunci = $r['kunci'];
						if(!empty($row->$kunci)){
							$r['select'] = '';
							$read = 'readonly';
							$cls  = '';
							$r['readonly'] = true;
						}
					}
					$idIns = $id.'_'.$nom;
					
					
					if(!empty($r['select'])){
				?>
					<td style="min-width: <?php echo $r['size'] ?>px; width: <?php echo $r['size'] ?>px">
						<select <?php echo $read ?> id="<?php echo $idIns ?>" class="_textApankGrid _detTdSel <?php echo $r['class']?> _td_<?php echo $nom ?>_<?php echo $i ?> <?php echo $cls ?>" col="<?php echo $i ?>" name="<?php echo $id."[".$nom."]" ?>" row="<?php echo $nom ?>" style="width: <?php echo ($r['size']-2) ?>px">
						<?php
						foreach($r['select'] as $r2){
							echo "<option value='$r2'>".$r2;
						}
						?>
						</select>
					</td>
				<?php 
					}else{
				?>
					<td style="min-width: <?php echo $r['size'] ?>px; width: <?php echo $r['size'] ?>px">
						<input type='text' <?php echo $read ?> id="<?php echo $idIns ?>" class="_textApankGrid _detTd <?php echo $r['class']?> _td_<?php echo $nom ?>_<?php echo $i ?> <?php echo $cls ?>" col="<?php echo $i ?>" name="<?php echo $id."[".$nom."]" ?>" row="<?php echo $nom ?>" style="width: <?php echo ($r['size']-2) ?>px" value="<?php echo $row->$id ?>">
					</td>
				<?php 
					}
				} 
				?>
			</tr>
		<?php 
		$nom++;
		} 
		?>
      </tbody>
    </table>
  </div>
</div>

<?php if($this->data->form == true){ ?>
		<div style="margin-top: 5px; position: fixed; right: 0; bottom: 0">
			<?php echo $this->data->tambah ?>
			<input type="submit" value="Proses">
		</div>
	</form>
<?php }?>

    <script src="<?php echo $this->baseUrl ?>assets/thema/apankGrid2019/js/index.js"></script>


</body>

</html>
<script type='text/javascript'>
$(document).ready(function(){
	makeNavigasi = function(_row, _col){
		$('._detTd').keyup(function(e){
			
			if(e.which === 37 || e.which === 38 || e.which === 39 || e.which === 40){
				_row = parseInt(_row);
				_col = parseInt(_col);
				
				row = parseInt($(this).attr('row'));
				col = parseInt($(this).attr('col'));
				
				if(e.which === 37){ //Kiri
					if(col <= 1){
						row = row - 1;
						col = _col;
					}else{
						col = col - 1;
					}
				}
				if(e.which === 38){ //Atas
					row = row - 1;
				}
				if(e.which === 39){ //Kanan
					if(col >= _col){
						row = row + 1;
						col = 1;
					}else{
						col = col + 1;
					}
				}
				if(e.which === 40){ //Bawah
					row = row + 1;
				}
				$('._td_'+row+'_'+col).focus().select();
			}
		})
		$('._detTdSel').keyup(function(e){
			
			_row = parseInt(_row);
			_col = parseInt(_col);
			
			row = parseInt($(this).attr('row'));
			col = parseInt($(this).attr('col'));

			if(e.which === 13){ //Bawah
				col = col + 1;
			}
			if(e.which === 8){ //Bawah
				col = col - 1;
			}
			$('._td_'+row+'_'+col).focus().select();
		})
	}
	setDec();
	<?php echo $this->data->js ?>
})
</script>