<?php

CLASS nbeli extends RasioProject
{
	protected $set;
	protected $jenis = 1;
	protected $enableCk = true;

	public function __construct($config)
	{
		$this->getConfig($config);
		$this->validation();
		$this->set();
	}

	protected function set()
	{
		$this->set->em 			= $this->em;
		$this->set->alias 		= 'PBL';
		$this->set->modul 		= 'Nota Pembelian';
		$this->set->dBaseH 		= 'nbl';
		$this->set->dBaseD 		= false;
		$this->set->dBasePk 	= array('nonbl');
		$this->set->setKode 	= array("del" => '-', 'length' => 4, 'var' => array("alias", 'tgl'));
		$this->set->where 		= array("jenis = '".$this->jenis."'");
		$this->set->dSort 		= 'asc';
		$this->set->form 		= $this->setForm();
		$this->set->clearForm 	= array();
		$this->set->notNull 	= array("tgl", "kd_sub");
		$this->set->grid 		= $this->setGrid();
		$this->set->cetak 		= $this->setPrint();
		$this->set->button 		= array("Save", "First", "Prev", "Next", "Last", "Browse", "Add", "Del", "Edit", "prinT");
		$this->set->addClear 	= true;
		//$this->set->push 		= true;
		$this->set->posting 	= 'nbeli';
		$this->set->detail 		= $this->setDetail();
		$this->set->funct 		= '_creatingNotaB';
		
		if($_GET['retur'] == 'undefined'){
			$this->set->sqlGrid = $this->queryData();
		}
		
		return $this->set;
	}
	
	protected function queryData()
	{
		$sql = $this->em->addSelect("a.*, a.nonbl as pk");
		$sql = $this->em->getFrom($this->set->dBaseH, 'a');
		$sql = $this->em->getWhere("a.control = 1");
		return $sql;
	}
	
	protected function setForm()
	{
	    $row = 0;
		$form[] = array('row' => $row, 'col' => 25, "label" => array("name" => "No. Nota", "width" => 100), "input" => array("type" => 'text',	'attr' => array("name" => 'nonbl', "size" => 20, "readonly" => true)));
		$form[] = array('row' => $row, 'col' => 500, "label" => array("name" => "Tanggal", "width" => 100), "input" => array("type" => 'text',	'attr' => array("name" => 'tgl', "size" => 10, 'class' => 'tanggal')));

		//$form[] = array('row' => 25, 'col' => 25, "label" => array("name" => "No.Ref#", "width" => 100), "input" => array("type" => 'text',	'attr' => array("name" => 'noref', "size" => 20, 'after' => 'load("lpb", "false", "loadDisplay")', 'display' => 'loadDisplay', 'load'=> 'nota', 'loadAfter' => 'detLpb', 'loadAct' => 'simpan,update', 'loadHide' => 'update', 'target' => 'kd_cabang=>kd_cabang,nm_cabang=>nm_cabang,kd_sub=>kd_sub,nm_sub=>nm_sub,kd_gudang=>kd_gudang,nm_gudang=>nm_gudang,noref=>nolpb,ppn=>ppn,diskg=>diskg,tgl_datang=>tgl,ket=>ket,ket2=>ket2,ket3=>ket3')));
		//$form[] = array('row' => 25, 'col' => 285, "label" => false, "input" => array("type" => 'text',	'attr' => array("name" => 'tgl_datang', "size" => 10, 'mode' => 'date', 'readonly' => true)));
		
		//$form[] = array('row' => 50, 'col' => 220, "label" => false, "input" => array("type" => 'text',	'attr' => array("name" => 'nm_cabang', "size" => 30, 'readonly' => true)));
		//$form[] = array('row' => 50, 'col' => 25, "label" => array("name" => "Profit Center", "width" => 100), "input" => array("type" => 'text',	'attr' => array("name" => 'kd_cabang', "size" => 9, 'readonly' => true)));
		
		$row += 25;
		$form[] = array('row' => $row, 'col' => 220, "label" => false, "input" => array("type" => 'text',	'attr' => array("name" => 'nm_sub', "size" => 30, 'readonly' => true, 'child' => 'prv')));
		$form[] = array('row' => $row, 'col' => 25, "label" => array("name" => "Supplier", "width" => 100), "input" => array("type" => 'text',	'attr' => array("name" => 'kd_sub', "size" => 9, 'after' => 'load("mastersupp", "false", "loadDisplay")', 'display' => 'loadDisplay', 'target' => 'nm_sub=>nm_sub')));

		//$form[] = array('row' => 100, 'col' => 220, "label" => false, "input" => array("type" => 'text',	'attr' => array("name" => 'nm_gudang', "size" => 30, 'readonly' => true)));
		//$form[] = array('row' => 100, 'col' => 25, "label" => array("name" => "Penerimaan", "width" => 100), "input" => array("type" => 'text',	'attr' => array("name" => 'kd_gudang', "size" => 9, 'readonly' => true)));

        $row += 25;
		$form[] = array('row' => $row, 'col' => 25, "label" => array("name" => "Keterangan", "width" => 100), "input" => array("type" => 'text',	'attr' => array("name" => 'ket', "size" => 30)));
		//$form[] = array('row' => 50, 'col' => 500, "label" => array("name" => "&nbsp;", "width" => 100), "input" => array("type" => 'text',	'attr' => array("name" => 'ket2', "size" => 30)));
		//$form[] = array('row' => 75, 'col' => 500, "label" => array("name" => "&nbsp;", "width" => 100), "input" => array("type" => 'text',	'attr' => array("name" => 'ket3', "size" => 30)));
		$row += 25;
		$form[] = array('row' => $row, 'col' => 25, "label" => array("name" => "Status", "width" => 100), "input" => array("type" => 'text',	'attr' => array("name" => 'control', "size" => 10, 'readonly' => true)));
		$form[] = array('row' => $row, 'col' => 500, "label" => array("name" => "<input type='button' id='_loadTimbang' value='Load Timbangan'>", "width" => 100), "input" => false);
		
		//$form[] = array('row' => 425, 'col' => 500, "label" => array("name" => "Sub Total", "width" => 100), "input" => array("type" => 'text',	'attr' => array("name" => 'stot', "size" => 20, 'readonly' => true, 'class' => 'decimal')));
		
		//$form[] = array('row' => 450, 'col' => 500, "label" => array("name" => "Disc. Global (%)", "width" => 100), "input" => array("type" => 'text',	'attr' => array("name" => 'diskg', "size" => 4, 'class' => 'decimal _hitungPo')));
		//$form[] = array('row' => 450, 'col' => 660, "label" => array("name" => " +", "width" => 20), "input" => array("type" => 'text',	'attr' => array("name" => 'diskg2', "size" => 4, 'class' => 'decimal _hitungPo')));

		//$form[] = array('row' => 475, 'col' => 500, "label" => array("name" => "Nilai Diskon", "width" => 100), "input" => array("type" => 'text',	'attr' => array("name" => 'diskg_nilai', "size" => 20, 'readonly' => true, 'class' => 'decimal')));
		//$form[] = array('row' => 500, 'col' => 500, "label" => array("name" => "DPP", "width" => 100), "input" => array("type" => 'text',	'attr' => array("name" => 'dpp', "size" => 20, 'readonly' => true, 'class' => 'decimal')));
		
		//$form[] = array('row' => 525, 'col' => 500, "label" => array("name" => "PPN", "width" => 100), "input" => array("type" => 'text',	'attr' => array("name" => 'ppn', "size" => 4, 'after' => 'select("")', 'select' => 'ppn', 'class' => '_hitungPo')));
		//$form[] = array('row' => 525, 'col' => 660, "label" => false, "input" => array("type" => 'text',	'attr' => array("name" => 'ppn_nilai', "size" => 10, 'readonly' => true, 'class' => 'decimal')));
		
		$row += 300;
		$form[] = array('row' => $row, 'col' => 500, "label" => array("name" => "Grand Total", "width" => 100), "input" => array("type" => 'text',	'attr' => array("name" => 'gtot', "size" => 10, 'readonly' => true, 'class' => 'decimal')));
		
		$row += 50;
		$form[] = array('row' => $row, 'col' => 25, "label" => array("name" => "By", "width" => 100), "input" => array("type" => 'text',	'attr' => array("name" => 'chusr', 'size' => 15, 'readonly' => true)));
		$form[] = array('row' => $row, 'col' => 500, "label" => array("name" => "Last", "width" => 100), "input" => array("type" => 'text',	'attr' => array("name" => 'chtime', 'size' => 20, 'readonly' => true, 'mode' => 'datetime')));
		return $form;
	}
	
	public function setDetail()
	{
		$res->width 	= 670;
		$res->height	= 225;
		$res->col		= 25;
		$res->row		= 105;
		$res->data		= 'nbld';
		$res->pk		= 'nonbl';
		$res->sort		= 'nonbld';
		
		$res->attr[] = array("label" => 'No. LPB',		"attr" => 'noref', 	'width' => 130, 	'after' => 'load("tbeli", "false", "loadDisplay")', 'display' => 'loadDisplay', 'target' => 'kd_inv=>kd_inv,nm_inv=>nm_inv,qty=>qty,humid=>humid,harga=>harga,total=>total', 'load' => 'nbl,nonbl,kd_sub', 'notnull' => true, 'loadAfter' => '_hitungPoB');
		
		$res->attr[] = array("label" => 'Material',		"attr" => 'kd_inv', 	'width' => 80, 'notnull' => true,	'readonly' => true);
		$res->attr[] = array("label" => 'Nama',		"attr" => 'nm_inv', 	'width' => 150, 'notnull' => true,	'readonly' => true);
		$res->attr[] = array("label" => 'Berat',		"attr" => 'qty',		'width' => 40, 'class' => 'decimal _hitungPoB');
		$res->attr[] = array("label" => 'Refraksi (%)',		"attr" => 'humid',		'width' => 80, 'class' => 'decimal _hitungPoB');
		$res->attr[] = array("label" => 'Harga',	"attr" => 'harga',		'width' => 50, 'class' => 'decimal _hitungPoB');
		
		//$res->attr[] = array("label" => 'Dis.1(%)',	"attr" => 'diskon_2',	'width' => 40, 'class' => 'decimal _hitungPo');
		//$res->attr[] = array("label" => 'Dis.2(%)',	"attr" => 'diskon_3',	'width' => 40, 'class' => 'decimal _hitungPo');
		//$res->attr[] = array("label" => 'Dis.3(%)',	"attr" => 'diskon_4',	'width' => 40, 'class' => 'decimal _hitungPo', 'type' => 'hidden');
		//$res->attr[] = array("label" => 'Dis.4(%)',	"attr" => 'diskon_5',	'width' => 40, 'class' => 'decimal _hitungPo', 'type' => 'hidden');
		//$res->attr[] = array("label" => 'Dis.5(%)',	"attr" => 'diskon_6',	'width' => 40, 'class' => 'decimal _hitungPo', 'type' => 'hidden');
		//$res->attr[] = array("label" => 'Dis.Rp',	"attr" => 'diskon',		'width' => 60, 'class' => 'decimal _hitungPo', 'type' => 'hidden');
		//$res->attr[] = array("label" => 'Ket', 		"attr" => 'ket_det', 	'width' => 150);
		
		$res->attr[] = array("label" => 'Total',	"attr" => 'total',		'width' => 80, 'class' => 'decimal', 'dec' => 2, 'readonly' => true);
		
		return $res;
	}
	
	public function detTimbang()
	{
    	$this->layout = "null";
    	$noref = "";
    	if(!empty($_POST['timbang'])){
    		foreach($_POST['timbang'] as $k){
    			if(!empty($noref)){
    				$noref.= ' or ';
    			}
    			$noref.= "(a.nolpb = '$k')";
    		}
    	}
	
		$sql = $this->em->addSelect("a.*, a.nolpb as noref");
		$sql = $this->em->getFrom("lpb", 'a');
		$sql = $this->em->addLeftJoin("nbld", 'b', array("a.nolpb = b.noref"));
		$sql = $this->em->addLeftJoin("nbl", 'c', array("b.nonbl = c.nonbl"));
		$sql = $this->em->getWhere("(b.noref is null or b.noref = '')");
		$sql = $this->em->andWhere("a.control = 1");
		if(!empty($_GET['kd_sub'])){
		    $sql = $this->em->andWhere("a.kd_sub = '".$_GET['kd_sub']."'");
		}
		else{
		    echo "<script>alert('Mohon isi supplier dulu...')</script>";
		    return;
		}
		if(!empty($noref)){
    		$sql = $this->em->andWhere("($noref)");
    	}
		$eks = $this->em->queryEks($sql);
		$tmp = $this->em->getFetchObject($eks);
		//var_dump($sql);
		$tot = 0;
		$data = array();
		foreach($tmp as $r){
        	$r->total = ($r->qty - ($r->qty * ($r->humid / 100))) * $r->harga;
        	$tot += $r->total;
        	$data[] = $r;
		}
		
		$file = __CLASS__.'_'.date("ymdhis").rand(100, 999);
		$this->sessionDet($file, $this->set, $data);
		echo "<script>_listLoadDetail('".$file."', '')</script>";
		echo "<script>$('#apankForm').empty();</script>";
		echo "<script>$('#gtot').val(".$tot.");</script>";
	}
	
	public function loadTimbang()
    {
    	if(empty($_GET['kd_sub'])){
    		echo "<script>alert('Mohon isi supplier dulu...')</script>";
    		return;
    	}
    	$kd_sub = $_GET['kd_sub'];
    
    	$sql = $this->em->addSelect("a.*, a.nolpb as noref");
    	$sql = $this->em->getFrom("lpb", 'a');
    	$sql = $this->em->addLeftJoin("nbld", 'b', array("a.nolpb = b.noref"));
    	$sql = $this->em->addLeftJoin("nbl", 'c', array("b.nonbl = c.nonbl"));
    	$sql = $this->em->getWhere("(b.noref is null or b.noref = '')");
    	$sql = $this->em->andWhere("a.control = 1");
    	$sql = $this->em->andWhere("a.kd_sub = '".$kd_sub."'");
    	$sql = $this->em->getMultiSort("a.nolpb");
    
    	$eks = $this->em->queryEks($sql);
    	$tmp = $this->em->getFetchObject($eks);
    
    	$data = "<form method='POST' id='_pilihTimbang' action=''>";
    	$data.= "<table id='_tabBonus'>";
    	$data.= "<thead>";
    	$data.= "<tr>";
    	$data.= "<th width='30' align='center'><input type='checkbox' id='cekAll'></th>";
    	$data.= "<th width='130'>No. LPB</th>";
    	$data.= "<th width='80'>Material</th>";
    	$data.= "<th width='150'>Nama</th>";
    	$data.= "<th width='40' align='right'>Berat</th>";
    	$data.= "<th width='80' align='right'>Refraksi (%)</th>";
    	$data.= "<th width='50' align='right'>Harga</th>";
    	$data.= "<th width='80' align='right'>Total</th>";
    	$data.= "</tr>";
    	$data.= "</thead>";
    	$data.= "<tbody>";
    	foreach($tmp as $r){
    		$id = str_ireplace("/", "_", $r->noref);
    		$id = str_ireplace(".", "_", $id);
    		$r->total = ($r->qty - ($r->qty * ($r->humid / 100))) * $r->harga;
    
    		$data.= "<tr>";
    		$data.= "<td><input type='checkbox' class='_cekTimbang' name='timbang[".$r->noref."]' id='cek_$id' value='".$r->noref."'></td>";
    		$data.= "<td>".$r->noref."</td>";
    		$data.= "<td>".$r->kd_inv."</td>";
    		$data.= "<td>".$r->nm_inv."</td>";
    		$data.= "<td>".$r->qty."</td>";
    		$data.= "<td>".$r->humid."</td>";
    		$data.= "<td>".$r->harga."</td>";
    		$data.= "<td>".number_format($r->total, 2)."</td>";
    		$data.= "</tr>";
    	}
    	$data.= "</tbody>";
    	$data.= "</table>";
    	$data.= "<p style='text-align: center'><input type='submit' value='Pilih'></p>";
    	$data.= "</form>";
    
    	echo $data;
    	echo "<script type='text/javascript'>
    		$(document).ready(function(){
    			$('#_tabBonus').flexigrid({
    				width: 670,
    				height: 225,
    				title: 'Daftar Timbangan (LPB) Belum Diproses',
    			});
    		})
    	</script>";
    
    	$this->layout = "null";
    }
	
	protected function setGrid()
	{
		$kode = new Kode;
		$res->page 	= 50;
		$res->sortA = $kode->getPk($this->set->dBasePk);
		$res->sortT = 'asc';
		
		$res->attr[]	= array("label" => 'No.Jurnal', 'attr' => 'a.nonbl', "sort" => 'true', "width" => 150, 'align' => 'left', 'focus' => 'true');
		$res->attr[]	= array("label" => 'Tanggal', 'attr' => 'a.tgl', "sort" => 'true', "width" => 70, 'align' => 'center', 'type' => 'date');
		$res->attr[]	= array("label" => 'Kirim', 'attr' => 'a.nm_cabang', "sort" => 'true', "width" => 150, 'align' => 'left');
		$res->attr[]	= array("label" => 'Supplier', 'attr' => 'a.nm_sub', "sort" => 'true', "width" => 200, 'align' => 'left');
		$res->attr[]	= array("label" => 'Keterangan', 'attr' => 'a.ket', "sort" => 'true', "width" => 150, 'align' => 'left');
		$res->attr[]	= array("label" => 'Status', 'attr' => 'a.control', "sort" => 'true', "width" => 40, 'align' => 'left', "DisplayFunc" => 'setControl');

		return $res;
	}
	
	protected function setPrint()
	{
		$kode = new Kode;
		$res->sortA = $kode->getPk($this->set->dBasePk);
		$res->sortT = 'asc';
		$res->width = '600px';
		
		$res->attr[]	= array("label" => 'No. Jurnal', 'attr' => 'a.nonbl', "sort" => 'true', "width" => 200, 'align' => 'left', 'filter' => true, 'default' => 'nonbl');

		return $res;
	}
	
	public function Index()
	{
		$this->data = $this->set;
		$this->view = "default/index";
	}
	
	public function data()
	{
		$basic = new Basic;
		$this->data = $basic->data($_GET, $this->set);
		$this->view = "default/displayData";
		$this->layout = "view";
	}
	
	public function Find()
	{
		$basic = new Basic;
		$this->data = $basic->find($_GET, $this->set);
		$this->view = "default/displayForm";
		$this->layout = "view";
	}
	
	protected function validasi()
	{
		$basic = new Basic;
		$error[] = $basic->validasiBasic($_POST, $this->set, false);

		$kd_inv = $_POST['kd_inv'];
		foreach($kd_inv as $row){
			if(!empty($row)){
				$cek = $this->em->getFind("inv", "kd_inv", array("kd_inv = '$row'"));
				if(empty($cek->kd_inv)){
					echo "<script>$('#_displayErrorPopUp').html('Kode Artikel $row Tidak terdaftar')</script>";
					$error[] = false;
				}
			}
		}
	
		$error[] = $this->cekStatus($_POST['nonbl']);
		return $basic->getError($error);
	}
	
	public function cekStatus($nojnl, $alert = false)
	{
		//$data = $this->em->getFind("nbl", "nonbl", array("noref = '$nojnl'", "(a.control = '1' or a.control is null or a.control = '0')"));
		//if(!empty($data->nonbl)){
			// echo "<script>alert('LPB Sudah dibuatkan Nota Beli ".$data->nonbl."')</script>";
			// return false;
		// }
		return true;
	}
	
	protected function kode($get = array())
	{
		$date = new date;
		$post = array();
		$post['alias'] 	= $this->set->alias;
		$post['tgl'] 	= date("ym", strtotime($date->serialDate($_POST['tgl'])));
		//$post['cabang'] = $_POST['kd_cabang'];
		
		$basic = new Basic;
		return $basic->kode($this->set, $post, $_POST);
	}
	
	public function proses()
	{
	    ini_set("display_errors","On");
		$basic = new Basic;
		$date  = new Date;
		$kode  = new Kode;
		$validasi = $this->validasi();
		if($validasi == true){
			$this->set->nojnl = $this->kode($_POST);
			
			$tambah = array();
			$tambah['jenis'] 	= $this->jenis;
			$tambah['kd_cabang'] = 'HO';
    		$tambah['nm_cabang'] = 'HEAD OFFICE';
    		$tambah['kd_gudang'] = 'GD';
    		$tambah['nm_gudang'] = 'GUDANG';
			$_POST['tgl'] 		= $date->serialDate($_POST['tgl']);
			$_POST['control'] 	= 1;
			
			$no = 1;
			$qb = array();
			$qb[] = $this->deleteDet($this->set->nojnl['nojnl']);
			foreach($_POST['noref'] as $n => $row){
				if(!empty($row)){
					$qb[] = $this->saveDet($n, $this->set->nojnl['nojnl'], $no++);
				}
			}

			$sql = $basic->proses3($_POST, $this->set, $tambah, $qb, array(), true);
			$save = $basic->posting($this->set, $sql, $this->set->posting);
			
			// echo "<pre>";
			// var_dump($sql);

			if($save != false){
				$nom = $this->em->getFind($this->set->dBaseH, "_no", array("nonbl = '".$this->set->nojnl['nojnl']."'"));
				$nom = $nom->_no;
				$_SESSION['findNo'.$nom] = $this->set;
				echo "<script>makeSuccesNewForm('$nom')</script>";
			}else{
				echo "<script>$('#_displayErrorPopUp').html('Proses Gagal!')</script>";
			}
		}
		$this->layout = "null";
	}
	
	public function saveDet($id, $pk, $nom)
	{
		$kode = new Kode;
		$attr = array();
		foreach($this->set->detail->attr as $k => $r){
			$no = $r['attr'];
			$attr[$no] = $_POST[$no][$id];
		}
		$attr['nonbld'] = $pk.'.'.date("ymdHis").$kode->getRight($nom, 3, 0);
		$attr['nonbl'] = $pk;
		
		$sql = $this->em->addInsert($this->set->detail->data);
		$sql = $this->em->addAttrIns($attr);

		return $sql;
	}

	public function deleteDet($id)
	{
		$sql = $this->em->addDelete('nbld');
		$sql = $this->em->getWhere("nonbl = '$id'");
		return $sql;
	}
	
	public function Delete()
	{
		$_GET['nonbl'] = str_ireplace("__--__", "/", $_GET['nonbl']);
			
		if($this->cekStatus($_GET['nonbl']) == true){
			$qb = array();
			$basic = new Basic;
			
			$nbl = $this->em->getFind("nbl", "noref", array("nonbl = '".$_GET['nonbl']."'"));
			if(!empty($nbl->noref)){
				$posting = new Posting;
				$qb = $posting->lpb($this->set, $nbl->noref, true);
			}
			
			$this->data = $basic->delete2($_GET, $this->set, $qb);
		}
		$this->layout = "null";
	}
	
	public function Pending()
	{
		$_GET['nonbl'] = str_ireplace("__--__", "/", $_GET['nonbl']);
			
		if($this->cekStatus($_GET['nonbl']) == true){
			$qb = array();
			$basic = new Basic;
			
			$nbl = $this->em->getFind("nbl", "noref", array("nonbl = '".$_GET['nonbl']."'"));
			if(!empty($nbl->noref)){
				$posting = new Posting;
				$qb = $posting->lpb($this->set, $nbl->noref, true);
			}
			
			$this->data = $basic->pending($_GET, $this->set, $qb);
		}
		$this->layout = "null";
	}
	
	public function push()
	{
		$nojnl = $_GET['filPrintanonbl'];
		$pk = $this->set->dBasePk[0];
		$data = $this->em->getFind($this->set->dBaseH, "control, '".$this->set->alias."' as alias, to_char(tgl, 'yymm') as tgl, kd_cabang as cabang, '$nojnl' as nojnl", array("$pk = '$nojnl'"));
		$this->set->url = $this->baseUrl;
		$this->layout = 'null';
		$basic  = new Basic;
		$basic->cekTmp($this->set, $data);
		$this->layout = "null";
	}
	
	public function cetak()
	{
		$this->data->kode = $_GET['filPrintanonbl'];
		$this->layout = "null";
		$this->pdf();
	}
	
	public function pdf()
	{
		$basic = new Basic;
		$this->data->data 	= $this->em->getFind("nbl", "*", array("nonbl = '".$_GET['filPrintanonbl']."'"));
		$this->data->det 	= $this->em->getFindBy("nbld", "*", array("nonbl = '".$_GET['filPrintanonbl']."'"), "nonbld asc");
		$this->data->gudang = $this->em->getFind("cabang", "*", array("kd_cabang = '".$this->data->data->kd_cabang."'"));
		$this->data->sub 	= $this->em->getFind("sub", "*", array("kd_sub = '".$this->data->data->kd_sub."'"));

		$this->view = "nbeli";
		$this->layout = "printFormPdf";
	}
	
	public function load()
	{
		$basic = new Basic;
		$this->data = $basic->load($_GET, $this->set);
		$this->layout = "null";
	}
	
	public function popUp()
	{
		$basic = new Basic;
		$this->data = $basic->data($_GET, $this->set);
		$this->view = "default/displayDataPopUp";
		$this->layout = "view";
	}
	
	public function Detail()
	{
		$this->view = "default/detail";
		$this->layout = "view";
	}
	
	public function detLpb()
	{
		if(!empty($_GET['nonbl'])){
			$res = $this->em->getFindBy("nlbd", "*", array("nonbl = '".$_GET['nonbl']."'"), "nonbld");
		}else{
			$lpb = $this->em->getFind("lpb", "*", array("nolpb = '".$_GET['nolpb']."'"));
			if(!empty($lpb->noref)){
				$sql = $this->em->addSelect("b.*, a.qty");
				$sql = $this->em->getFrom("lpbd", 'a');
				$sql = $this->em->addLeftJoin("beli_det", 'b', array("a.kd_inv = b.kd_inv", "b.no_po = '".$lpb->noref."'"));
				$sql = $this->em->getWhere("a.nolpb = '".$_GET['nolpb']."'");
				$sql = $this->em->getMultiSort("a.nolpbd asc");
				$eks = $this->em->queryEks($sql);
				$res = $this->em->getFetchObject($eks);
			}else{
				$sql = $this->em->addSelect("a.*, c.hargab as harga");
				$sql = $this->em->getFrom("lpbd", 'a');
				$sql = $this->em->addLeftJoin("inv", 'b', array("a.kd_inv = b.kd_inv"));
				$sql = $this->em->addLeftJoin("satuan", 'c', array("a.kd_inv = c.kd_inv", "a.satuan = c.nmsat"));
				$sql = $this->em->getWhere("a.nolpb = '".$_GET['nolpb']."'");
				$sql = $this->em->getMultiSort("a.nolpbd asc");
				$eks = $this->em->queryEks($sql);
				$tmp = $this->em->getFetchObject($eks);
				$res = array();
				foreach($tmp as $r){
					$res[$r->nolpbd] = $r;
				}
			}
		}
		
				
		$this->sessionDet(__CLASS__, $this->set, $res);
		echo "<script>$('#ket_file').val('".$_GET['file']."')</script>";
		echo "<script>_listLoadDetail('".__CLASS__."', '_hitungPo')</script>";
		echo "<script>$('#apankForm').empty()</script>";
		$this->layout = "null";
	}
	
	public function loadDisplay()
	{
		$pk = $this->set->dBasePk[0];
		$data = $this->em->getFind($this->set->dBaseH, '*', array("$pk = '".$_GET['idRef']."'"));
		$basic = new Basic;
		$res = $basic->loadDisplay($data, $_GET);
		echo json_encode($res);
		$this->layout = "null";
	}
}