<?php

CLASS kom extends RasioProject
{
	protected $set;
	protected $enableCk = true;

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

	protected function set()
	{
		$this->set->em 			= $this->em;
		$this->set->modul 		= 'Komisi';
		$this->set->dBaseH 		= 'kom';
		$this->set->dBaseD 		= false;
		$this->set->dBasePk 	= array('kd_kom');
		$this->set->dSort 		= 'asc';
		$this->set->form 		= $this->setForm();
		$this->set->clearForm 	= array();
		$this->set->notNull 	= array("kd_sub", "tgl", "persen");
		$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;
		return $this->set;
	}
	
	protected function setForm()
	{
		$rwd = 25;
		$row = $row + $rwd;
		$form[] = array('row' => $row, 'col' => 25, "label" => array("name" => "Kode Komisi", "width" => 100), "input" => array("type" => 'text',	'attr' => array("name" => 'kd_kom', "size" => 20, 'readonly' => true)));

		$row = $row + $rwd;
		$form[] = array('row' => $row, 'col' => 220, "label" => false, "input" => array("type" => 'text',	'attr' => array("name" => 'nm_sub', "size" => 50, 'readonly' => true)));
		$form[] = array('row' => $row, 'col' => 25, "label" => array("name" => "User", "width" => 100), "input" => array("type" => 'text',	'attr' => array("name" => 'kd_sub', "size" => 10, 'after' => 'load("sub", "false", "sub")', 'display' => 'sub', 'target' => 'nm_sub')));

		$row = $row + $rwd;
		$form[] = array('row' => $row, 'col' => 25, "label" => array("name" => "Tgl. Berlaku", "width" => 100), "input" => array("type" => 'text',	'attr' => array("name" => 'tgl', "size" => 10, 'class' => 'tanggal')));

		$row = $row + $rwd;
		$form[] = array('row' => $row, 'col' => 25, "label" => array("name" => "Persentase", "width" => 100), "input" => array("type" => 'text',	'attr' => array("name" => 'persen', "size" => 4, 'class' => 'decimal')));

		$row = $row + $rwd;
		$form[] = array('row' => $row, 'col' => 25, "label" => array("name" => "By", "width" => 100), "input" => array("type" => 'text',	'attr' => array("name" => 'chusr', 'size' => 15, 'readonly' => true)));
		$row = $row + $rwd;
		$form[] = array('row' => $row, '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" => 'Kode', 'attr' => 'a.kd_kom', "sort" => 'true', "width" => 50, 'align' => 'left');
		$res->attr[]	= array("label" => 'Sub', 'attr' => 'a.kd_sub', "sort" => 'true', "width" => 50, 'align' => 'left');
		$res->attr[]	= array("label" => 'Nama', 'attr' => 'a.nm_sub', "sort" => 'true', "width" => 200, 'align' => 'left');
		$res->attr[]	= array("label" => 'Tgl. Berlaku', 'attr' => 'a.tgl', "sort" => 'true', "width" => 100, 'align' => 'left', 'class' => 'tanggal', 'type' => 'date');
		$res->attr[]	= array("label" => 'Persentase', 'attr' => 'a.persen', "sort" => 'true', "width" => 40, 'align' => 'right', "type" => 'numeric', 'dec' => 2);
		
		return $res;
	}
	
	protected function setPrint()
	{
		$kode = new Kode;
		$res->sortA = $kode->getPk($this->set->dBasePk);
		$res->sortT = 'asc';
		$res->width = '1000px';
		
		$res->attr[]	= array("label" => 'Kode', 'attr' => 'a.kd_kom', "sort" => 'true', "width" => 50, 'align' => 'left', 'filter' => true);
		$res->attr[]	= array("label" => 'Sub', 'attr' => 'a.kd_sub', "sort" => 'true', "width" => 50, 'align' => 'left', 'filter' => true);
		$res->attr[]	= array("label" => 'Nama', 'attr' => 'a.nm_sub', "sort" => 'true', "width" => 200, 'align' => 'left', 'filter' => true);
		$res->attr[]	= array("label" => 'Tgl. Berlaku', 'attr' => 'a.tgl', "sort" => 'true', "width" => 100, 'align' => 'left', 'class' => 'tanggal', 'type' => 'date');
		$res->attr[]	= array("label" => 'Persentase', 'attr' => 'a.persen', "sort" => 'true', "width" => 40, 'align' => 'right', "type" => 'numeric', 'dec' => 2);
		
		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){
			if(empty($_POST['kd_sub'])){
				$_POST['nm_sub'] = '';
			}
			
			if($_POST['_prosesAction'] == 'simpan'){
				$_POST['kd_kom'] = date("ymdHis");
			}
			
			$basic->proses($_POST, $this->set, array());
		}
		$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 account()
	{
		$data = $this->em->getFind("acc", "nmac", array("kdac = '".$_GET['idRef']."'"));
		
		$res->target = $_GET['target'];
		$res->nama 	= $data->nmac;
		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";
	}
}