<?php
$kode = new Kode;
?>
<script type="text/javascript">
$(document).ready(function(){
		_createDetailInDb = function(_tabDet){
			<?php
				$baris = 1;
				$dataNotDup = array();
				foreach($this->data->dataDetail as $r){
			?>
					_tabDet+= '<tr id="barisDet_<?php echo $baris ?>">';
					<?php if($this->data->detail->autoNo == true){ ?>
						_tabDet+= '<td style="width: 30px;" class="_detTdItem"><input type="text" class="_detTd" style="width: 30px" name="no[<?php echo $baris ?>]" id="_no_<?php echo $baris ?>" autocomplete="off" value="<?php echo $baris ?>" readonly></td>';
					<?php 
					}
					$rows = 1;
					foreach($this->data->detail->attr as $keyD => $row){ 
						$idDet = $row['attr'];
						$type = "text";
						if(!empty($row['type'])){
							$type = $row['type'];
						}
						$dis = '';
						if(strtoupper($type) == strtoupper('hidden')){
							$dis = '; display: none';
						}else{
							$tambah = $kode->setAttrDetail($row, $baris);
						}
						
						if($row['noduplicate'] == true){
							if(empty($dataNotDup) or $dataNotDup[$idDet] != $r->$idDet){
								$dataNotDup[$idDet] = $r->$idDet;
							}else{
								$r->$idDet = '';
							}
						}
						$_imgSel = false;
						if(!empty($row['select'])){
							$_imgSel = true;
						}
						$after = $row['after'];
						$after = explode("(", $after);
						$after = trim(strtolower($after[0]));
						$_imgLod = false;
						if($after == 'load'){
							$_imgLod = true;
						}
						if($row['mode'] == 'date'){
							if(!empty($r->$idDet)){
								$r->$idDet = date("d/m/Y", strtotime($r->$idDet));
							}
						}
					?>
						_btnSel = '';
						<?php if($_imgSel == true){ ?>
							_btnSel = '<input row="<?php echo $rows ?>" col="<?php echo $baris ?>" idd="<?php echo $idDet.'_'.$baris ?>" class="_imgCariD _buttonSelectD" value="" type="button">';
						<?php } ?>
						<?php if($_imgLod == true){ ?>
							_btnSel = '<input row="<?php echo $rows ?>" col="<?php echo $baris ?>" _idd="<?php echo $idDet.'_'.$baris ?>" _nno="<?php echo $idDet.'_'.$baris ?>" class="_imgCariD _buttonLoadD" value="" _ttb="&pkBrowse=&get_def=&get_def=undefined" type="button">';
						<?php } ?>
						_tabDet+= '<td style="width: <?php echo $row['width'] ?>px; <?php echo $dis ?>" class="_detTdItem"><input type="<?php echo $type ?>" row="<?php echo $rows ?>" col="<?php echo $baris ?>" class="text _detTd _detTd_<?php echo $baris ?>_<?php echo $rows ?> <?php echo $row['class'] ?>" style="width:<?php echo ($row['width']) ?>px" name="<?php echo $idDet ?>[<?php echo $baris ?>]" id="<?php echo $idDet.'_'.$baris ?>" autocomplete="off" value="<?php echo $r->$idDet ?>" title="<?php echo $r->$idDet ?>" dec="<?php echo (int)$row['dec'] ?>" disabled _mode="cursor" <?php echo $tambah ?>>'+_btnSel+'</td>';
					<?php 
						$rows++;
					} 
					?>
					_tabDet+= '<tr>';
			<?php 
					$baris++;
				}
			?>
			return _tabDet;
		}
		_createDetailAwal = function(){
			_tabDet = '<tr id="barisDet_1">';
			<?php 
			$rows = 1;
			$baris = 1;
			foreach($this->data->detail->attr as $keyD => $row){ 
				$idDet = $row['attr'];
				$type = "text";
				if(!empty($row['type'])){
					$type = $row['type'];
				}
				
				$clsEx = explode(" ", $row['class']);
				foreach($clsEx as $rCls){
					if(strtoupper($rCls) == strtoupper('decimal')){
						$r->$idDet = number_format($r->$idDet, (int)$row['dec']);
					}
				}
				
				$dis = '';
				if(strtoupper($type) == strtoupper('hidden')){
					$dis = '; display: none';
				}else{
					$tambah = $kode->setAttrDetail($row, $baris);
				}

				$_imgSel = false;
				if(!empty($row['select'])){
					$_imgSel = true;
				}
				$after = $row['after'];
				$after = explode("(", $after);
				$after = trim(strtolower($after[0]));
				$_imgLod = false;
				if($after == 'load'){
					$_imgLod = true;
				}
			?>
				_btnSel = '';
				<?php if($_imgSel == true){ ?>
					_btnSel = '<input row="<?php echo $rows ?>" col="<?php echo $baris ?>" idd="<?php echo $idDet.'_'.$baris ?>" class="_imgCariD _buttonSelectD" value="" type="button">';
				<?php } ?>
				<?php if($_imgLod == true){ ?>
					_btnSel = '<input row="<?php echo $rows ?>" col="<?php echo $baris ?>" _idd="<?php echo $idDet.'_'.$baris ?>" _nno="<?php echo $idDet.'_'.$baris ?>" class="_imgCariD _buttonLoadD" value="" _ttb="&pkBrowse=&get_def=&get_def=undefined" type="button">';
				<?php } ?>
				_tabDet+= '<td style="width: <?php echo $row['width'] ?>px;<?php echo $dis ?>" class="_detTdItem"><input type="<?php echo $type ?>" row="<?php echo $rows ?>" col="<?php echo $baris ?>" class="text _detTd _detTd_<?php echo $baris ?>_<?php echo $rows ?> <?php echo $row['class'] ?>" style="width:<?php echo ($row['width']) ?>px" name="<?php echo $idDet ?>[<?php echo $baris ?>]" id="<?php echo $idDet.'_'.$baris ?>" autocomplete="off" value="<?php echo $r->$idDet ?>" title="<?php echo $r->$idDet ?>" disabled _mode="cursor" <?php echo $tambah ?>></td>';
			<?php 
				$rows++;
			} 
			?>
			_tabDet+= '<tr>';
			return _tabDet;
		}
		_makeLoadDetail = function(){
			
			<?php if(count($this->data->dataDetail) > 0){ ?>
				$('#_lastBarisDet').val('<?php echo (count($this->data->dataDetail) + 1) ?>');
				_tabDet = _createDetailInDb('');
			<?php }else{ ?>
				$('#_lastBarisDet').val(2);
				_tabDet = _createDetailAwal('');
			<?php } ?>
			
			$('#_detBody').html(_tabDet);
			setDec();
			display('<?php echo $this->data->funct ?>', 1);
		}
		_makeLoadDetail();
		
		if($('#_prosesAction').val() === ''){
		
		}else{
			$('._detTd').removeAttr("disabled");
		}
})
</script>