<?php

CLASS msales extends RasioProject
{
	protected $set;
	protected $jenis = 3;
	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 		= 'Master Sales';
		$this->set->dBaseH 		= 'sub';
		$this->set->dBaseD 		= false;
		$this->set->dBasePk 	= array('kd_sub');
		$this->set->where 		= array("(jenis = '".$this->jenis."')");
		$this->set->dSort 		= 'asc';
		$this->set->form 		= $this->setForm();
		$this->set->clearForm 	= array("ket_induk");
		$this->set->notNull 	= array("kd_sub", "nm_sub", "alamat", "kota");
		$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()
	{
		$form[] = array('row' => 0, 'col' => 25, "label" => array("name" => "Kode", "width" => 100), "input" => array("type" => 'text',	'attr' => array("name" => 'kd_sub', "size" => 10)));
		$form[] = array('row' => 25, 'col' => 25, "label" => array("name" => "Nama", "width" => 100), "input" => array("type" => 'text',	'attr' => array("name" => 'nm_sub', "size" => 30)));
		$form[] = array('row' => 50, 'col' => 25, "label" => array("name" => "Alamat", "width" => 100), "input" => array("type" => 'text',	'attr' => array("name" => 'alamat', "size" => 40)));
		$form[] = array('row' => 75, 'col' => 25, "label" => array("name" => "Kota", "width" => 100), "input" => array("type" => 'text',	'attr' => array("name" => 'kota', "size" => 30)));
		$form[] = array('row' => 100, 'col' => 25, "label" => array("name" => "Propinsi", "width" => 100), "input" => array("type" => 'text',	'attr' => array("name" => 'propinsi', "size" => 30)));
		$form[] = array('row' => 125, 'col' => 25, "label" => array("name" => "Negara", "width" => 100), "input" => array("type" => 'text',	'attr' => array("name" => 'negara', "size" => 30)));
		$form[] = array('row' => 150, 'col' => 25, "label" => array("name" => "NPPKP", "width" => 100), "input" => array("type" => 'text',	'attr' => array("name" => 'nppkp', "size" => 30)));
		$form[] = array('row' => 175, 'col' => 25, "label" => array("name" => "NPWP", "width" => 100), "input" => array("type" => 'text',	'attr' => array("name" => 'npwp', "size" => 30)));
		$form[] = array('row' => 200, 'col' => 25, "label" => array("name" => "Tgl. Pengukuhan", "width" => 100), "input" => array("type" => 'text',	'attr' => array("name" => 'tgl_pengukuhan', "size" => 10, 'class' => 'tanggal')));

		$form[] = array('row' => 0, 'col' => 450, "label" => array("name" => "Telepon", "width" => 100), "input" => array("type" => 'text',	'attr' => array("name" => 'telp', "size" => 25)));
		$form[] = array('row' => 25, 'col' => 450, "label" => array("name" => "Email", "width" => 100), "input" => array("type" => 'text',	'attr' => array("name" => 'email', "size" => 25)));
		$form[] = array('row' => 50, 'col' => 450, "label" => array("name" => "Fax", "width" => 100), "input" => array("type" => 'text',	'attr' => array("name" => 'fax', "size" => 25)));
		$form[] = array('row' => 75, 'col' => 450, "label" => array("name" => "Contact Person", "width" => 100), "input" => array("type" => 'text',	'attr' => array("name" => 'cp', "size" => 40)));
		
		$form[] = array('row' => 100, 'col' => 620, "label" => false, "input" => array("type" => 'text',	'attr' => array("name" => 'nm_acc_hutang', "size" => 25, 'readonly' => true)));
		$form[] = array('row' => 100, 'col' => 450, "label" => array("name" => "Acc. Hutang", "width" => 100), "input" => array("type" => 'text',	'attr' => array("name" => 'kd_acc_hutang', "size" => 6, 'after' => 'load("Macd", "false", "account")', 'display' => 'account', 'target' => 'nm_acc_hutang')));
		
		$form[] = array('row' => 125, 'col' => 620, "label" => false, "input" => array("type" => 'text',	'attr' => array("name" => 'nm_acc_piutang', "size" => 25, 'readonly' => true)));
		$form[] = array('row' => 125, 'col' => 450, "label" => array("name" => "Acc. Piutang", "width" => 100), "input" => array("type" => 'text',	'attr' => array("name" => 'kd_acc_piutang', "size" => 6, 'after' => 'load("Macd", "false", "account")', 'display' => 'account', 'target' => 'nm_acc_piutang')));
		
		$form[] = array('row' => 150, 'col' => 450, "label" => array("name" => "Keterangan", "width" => 100), "input" => array("type" => 'text',	'attr' => array("name" => 'ket', "size" => 40)));

		$form[] = array('row' => 250, 'col' => 25, "label" => array("name" => "By", "width" => 100), "input" => array("type" => 'text',	'attr' => array("name" => 'chusr', 'size' => 15, 'readonly' => true)));
		$form[] = array('row' => 250, '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_sub', "sort" => 'true', "width" => 70, 'align' => 'left');
		$res->attr[]	= array("label" => 'Nama', 'attr' => 'a.nm_sub', "sort" => 'true', "width" => 150, 'align' => 'left');
		$res->attr[]	= array("label" => 'Alamat', 'attr' => 'a.alamat', "sort" => 'true', "width" => 200, 'align' => 'left');
		$res->attr[]	= array("label" => 'Kota', 'attr' => 'a.kota', "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 = '1900px';
		
		$res->attr[]	= array("label" => 'Kode', 'attr' => 'a.kd_sub', "sort" => 'true', "width" => 200, 'align' => 'left', 'filter' => true);
		$res->attr[]	= array("label" => 'Nama', 'attr' => 'a.nm_sub', "sort" => 'true', 'align' => 'left', 'filter' => true);
		$res->attr[]	= array("label" => 'Alamat', 'attr' => 'a.alamat', "sort" => 'true', "width" => 200, 'align' => 'left', 'filter' => true);
		$res->attr[]	= array("label" => 'Kota', 'attr' => 'a.kota', "sort" => 'true', "width" => 150, 'align' => 'left', 'filter' => true);
		$res->attr[]	= array("label" => 'Propinsi', 'attr' => 'a.propinsi', "sort" => 'true', "width" => 150, 'align' => 'left', 'filter' => true);
		$res->attr[]	= array("label" => 'NPPKP', 'attr' => 'a.nppkp', "sort" => 'true', "width" => 100, 'align' => 'left', 'filter' => true);
		$res->attr[]	= array("label" => 'NPWP', 'attr' => 'a.npwp', "sort" => 'true', "width" => 100, 'align' => 'left', 'filter' => true);
		$res->attr[]	= array("label" => 'Telp', 'attr' => 'a.telp', "sort" => 'true', "width" => 100, 'align' => 'left', 'filter' => true);
		$res->attr[]	= array("label" => 'Email', 'attr' => 'a.email', "sort" => 'true', "width" => 100, 'align' => 'left', 'filter' => true);
		$res->attr[]	= array("label" => 'Fax', 'attr' => 'a.fax', "sort" => 'true', "width" => 100, 'align' => 'left', 'filter' => true);
		$res->attr[]	= array("label" => 'Contact Person', 'attr' => 'a.cp', "sort" => 'true', "width" => 100, 'align' => 'left', 'filter' => true);
		$res->attr[]	= array("label" => 'Acc.Hut', 'attr' => 'a.kd_acc_hutang', "sort" => 'true', "width" => 50, 'align' => 'left', 'filter' => true);
		$res->attr[]	= array("label" => 'Acc.Piut', 'attr' => 'a.kd_acc_piutang', "sort" => 'true', "width" => 50, 'align' => 'left', 'filter' => true);
		$res->attr[]	= array("label" => 'Keterangan', 'attr' => 'a.ket', "sort" => 'true', "width" => 100, '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();
			$tambah['jenis'] = $this->jenis;
			$tambah['hapus'] = 0;
			$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 Disdef()
	{
		$field = 'nm_sub';
		if(!empty($_GET['field'])){
			$field = $_GET['field'];
		}
	
		$data = $this->em->getFind("sub", $field.' as nama', array("kd_sub = '".$_GET['idRef']."'"));
		
		$res->target = $_GET['target'];
		$res->nama 	= $data->nama;
		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_sub as kode, CONCAT(kd_sub, '___', nm_sub) as nama", array("jenis = '".$this->jenis."'"), "kd_sub");
		
		$res->jum 	= count($data);
		$res->data 	= $data;
		$res->div 	= strtoupper($_GET['idDiv']);
		
		echo json_encode($res);
		$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";
	}
}