<?php

CLASS msubkat extends RasioProject
{
	protected $set;
	protected $enableCk = true;
	protected $jenis = 37;

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

	protected function set()
	{
		$this->set->em 			= $this->em;
		$this->set->modul 		= 'Master Sub Kategori';
		$this->set->dBaseH 		= 'skat';
		$this->set->dBaseD 		= false;
		$this->set->dBasePk 	= array('kd_skat');
		$this->set->where 		= array();
		$this->set->dSort 		= 'asc';
		$this->set->form 		= $this->setForm();
		$this->set->clearForm 	= array();
		$this->set->notNull 	= array("nm_skat", "kd_kat");
		$this->set->grid 		= $this->setGrid();
		$this->set->cetak 		= $this->setPrint();
		$this->set->button 		= array("First", "Prev", "Next", "Last", "Browse", "Add", "Del", "Edit", "prinT");
		$this->set->addClear 	= true;
		$this->set->funct 		= 'mSkat';
		return $this->set;
	}
	
	protected function setForm()
	{
		$form[] = array('row' => 0, 'col' => 25, "label" => array("name" => "Kode", "width" => 100), "input" => array("type" => 'text',	'attr' => array("name" => 'kd_skat', "size" => 8, 'readonly' => true)));
		$form[] = array('row' => 25, 'col' => 25, "label" => array("name" => "Prefik", "width" => 100), "input" => array("type" => 'text',	'attr' => array("name" => 'prefik', "size" => 4)));
		$form[] = array('row' => 50, 'col' => 25, "label" => array("name" => "Nama", "width" => 100), "input" => array("type" => 'text',	'attr' => array("name" => 'nm_skat', "size" => 30)));

		$form[] = array('row' => 75, 'col' => 220, "label" => false, "input" => array("type" => 'text',	'attr' => array("name" => 'nm_kat', "size" => 50, 'readonly' => true)));
		$form[] = array('row' => 75, 'col' => 25, "label" => array("name" => "Kategori", "width" => 100), "input" => array("type" => 'text',	'attr' => array("name" => 'kd_kat', "size" => 10, 'after' => 'select("")', 'select' => 'kat', 'select_width' => 280, 'select_height' => 245, 'select_label' => "Kode=>50;Name=>200", 'select_target' => "name=>nm_kat", 'select_warning' => true, 'display' => 'selectDisplay')));
		
		$form[] = array('row' => 100, 'col' => 25, "label" => array("name" => "Keterangan", "width" => 100), "input" => array("type" => 'text',	'attr' => array("name" => 'ket', "size" => 40)));

		$form[] = array('row' => 150, 'col' => 25, "label" => array("name" => "By", "width" => 100), "input" => array("type" => 'text',	'attr' => array("name" => 'chusr', 'size' => 15, 'readonly' => true)));
		$form[] = array('row' => 150, 'col' => 500, "label" => array("name" => "Last", "width" => 100), "input" => array("type" => 'text',	'attr' => array("name" => 'chtime', 'size' => 20, 'readonly' => true)));
		return $form;
	}
	
	protected function setGrid()
	{
		$kode = new Kode;
		$res->page 	= 50;
		$res->sortA = $kode->getPk($this->set->dBasePk);
		$res->sortT = 'asc';
		
		$res->attr[]	= array("label" => 'Kd Kat', 'attr' => 'a.kd_kat', "sort" => 'true', "width" => 70, 'align' => 'left');
		$res->attr[]	= array("label" => 'Km Kat', 'attr' => 'a.nm_kat', "sort" => 'true', "width" => 150, 'align' => 'left');
		$res->attr[]	= array("label" => 'Kode', 'attr' => 'a.kd_skat', "sort" => 'true', "width" => 70, 'align' => 'left');
		$res->attr[]	= array("label" => 'Nama', 'attr' => 'a.nm_skat', "sort" => 'true', "width" => 150, 'align' => 'left');
		$res->attr[]	= array("label" => 'Keterangan', 'attr' => 'a.ket', "sort" => 'true', "width" => 200, 'align' => 'left');
		
		return $res;
	}
	
	protected function setPrint()
	{
		$kode = new Kode;
		$res->sortA = $kode->getPk($this->set->dBasePk);
		$res->sortT = 'asc';
		$res->width = '900px';
		
		$res->attr[]	= array("label" => 'Kd.Kat', 'attr' => 'a.kd_kat', "sort" => 'true', "width" => 80, 'align' => 'left', 'filter' => true);
		$res->attr[]	= array("label" => 'Nm.Kat', 'attr' => 'a.nm_kat', "sort" => 'true', 'width' => 200, 'align' => 'left', 'filter' => true);
		$res->attr[]	= array("label" => 'Kode', 'attr' => 'a.kd_skat', "sort" => 'true', "width" => 80, 'align' => 'left', 'filter' => true);
		$res->attr[]	= array("label" => 'Nama', 'attr' => 'a.nm_skat', "sort" => 'true', 'width' => 200, 'align' => 'left', 'filter' => true);
		$res->attr[]	= array("label" => 'Keterangan', 'attr' => 'a.ket', "sort" => 'true', 'align' => 'left', 'filter' => true);
		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);
		return $basic->getError($error);
	}

	public function proses()
	{
		$basic = new Basic;
		$validasi = $this->validasi();
		if($validasi == true){
			$tambah = array();
			if($_POST['_prosesAction'] == 'simpan'){
				$tambah['kd_skat'] 	= strtoupper($_POST['kd_kat'].'-'.$_POST['prefik']);
				$_POST['kd_skat'] 	= $tambah['kd_skat'];
			}
			$basic->proses($_POST, $this->set, $tambah);
		}
		$this->layout = "null";
	}
	
	public function Delete()
	{
		$basic = new Basic;
		$this->data = $basic->delete($_GET, $this->set);
		$this->layout = "null";
	}
	
	public function cetak()
	{
		$basic = new Basic;
		$this->data->data = $basic->printer($_GET, $this->set);
		$this->data->width = $this->set->cetak->width;
		$this->view = "default/cetak";
		$this->layout = "print";
	}
	
	public function load()
	{
		$basic = new Basic;
		$this->data = $basic->load($_GET, $this->set);
		$this->layout = "null";
	}
	
	
	public function Disdefload()
	{
		$data = $this->em->getFind("skat", "nm_skat", array("kd_skat = '".$_GET['idRef']."'"));
		
		$res->target = $_GET['target'];
		$res->nama 	= $data->nm_skat;
		echo json_encode($res);
		$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 Select()
	{
		$data = $this->em->getFindBy($this->set->dBaseH, "kd_skat as kode, CONCAT(kd_skat, '___', nm_skat) as nama", array(), "kd_skat");
		
		$res->jum 	= count($data);
		$res->data 	= $data;
		$res->div 	= strtoupper($_GET['idDiv']);
		
		echo json_encode($res);
		$this->layout = "null";
	}
}