<?php

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

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

	protected function set()
	{
		$log = SESSION;
		$tgl = $_SESSION[$log]['login']['date'];
		
		$this->set->em 			= $this->em;
		$this->set->alias 		= 'BJM';
		$this->set->modul 		= 'Data Register Piutang';
		$this->set->dBaseH 		= 'acr';
		$this->set->dBaseD 		= false;
		$this->set->dBasePk 	= array('nojnl');
		$this->set->dSort 		= 'asc';
		$this->set->form 		= $this->setForm();
		$this->set->clearForm 	= array('selisih');
		$this->set->notNull 	= array("tgl", "kd_cabang");
		$this->set->grid 		= $this->setGrid();
		$this->set->cetak 		= $this->setPrint();
		$this->set->button 		= array("First", "Prev", "Next", "Last", "Browse");
		$this->set->addClear 	= true;
		$this->set->detail 		= $this->setDetail();
		$this->set->funct 		= '_creatingJurnal';
		$this->set->where 		= array("alias = 'RSB'");
		$this->set->where[]		= "tgl = '".date("Y-m-d", strtotime($tgl))."'";
		$this->set->where[]		= "kdac like '0.0.04%'";
		$this->set->funct 		= '_dataReg';
		return $this->set;
	}
	
	protected function setForm()
	{
		$row = 0;
		$form[] = array('row' => $row, 'col' => 25, "label" => array("name" => "No.Jurnal", "width" => 100), "input" => array("type" => 'text',	'attr' => array("name" => 'nojnl', "size" => 25, "readonly" => true)));
		
		$row = $row + 25;
		$form[] = array('row' => $row, 'col' => 220, "label" => false, "input" => array("type" => 'text',	'attr' => array("name" => 'nmac', "size" => 30, 'readonly' => true)));
		$form[] = array('row' => $row, 'col' => 25, "label" => array("name" => "Account", "width" => 100), "input" => array("type" => 'text',	'attr' => array("name" => 'kdac', "size" => 9, 'readonly' => true)));
		
		$row = $row + 25;
		$form[] = array('row' => $row, 'col' => 220, "label" => false, "input" => array("type" => 'text',	'attr' => array("name" => 'nm_sub', "size" => 30, 'readonly' => true)));
		$form[] = array('row' => $row, 'col' => 25, "label" => array("name" => "Sub", "width" => 100), "input" => array("type" => 'text',	'attr' => array("name" => 'kd_sub', "size" => 9, 'readonly' => true)));

		$row = $row + 25;
		$form[] = array('row' => $row, 'col' => 220, "label" => false, "input" => array("type" => 'text',	'attr' => array("name" => 'nm_cabang', "size" => 30, 'readonly' => true)));
		$form[] = array('row' => $row, 'col' => 25, "label" => array("name" => "Profit Center", "width" => 100), "input" => array("type" => 'text',	'attr' => array("name" => 'kd_cabang', "size" => 9, 'readonly' => true)));

		$row = $row + 25;
		$form[] = array('row' => $row, 'col' => 25, "label" => array("name" => "No. Referensi", "width" => 100), "input" => array("type" => 'text',	'attr' => array("name" => 'ket', "size" => 20)));

		$row = 0;
		$form[] = array('row' => $row, 'col' => 500, "label" => array("name" => "Tanggal", "width" => 100), "input" => array("type" => 'text',	'attr' => array("name" => 'tgl', "size" => 10, 'mode' => 'date')));

		$row = $row + 25;
		$form[] = array('row' => $row, 'col' => 500, "label" => array("name" => "Saldo Awal", "width" => 100), "input" => array("type" => 'text',	'attr' => array("name" => 'awal', "size" => 15, 'readonly' => true, 'class' => 'decimal')));

		$row = $row + 25;
		$form[] = array('row' => $row, 'col' => 500, "label" => array("name" => "Debet", "width" => 100), "input" => array("type" => 'text',	'attr' => array("name" => 'debet', "size" => 15, 'readonly' => true, 'class' => 'decimal')));

		$row = $row + 25;
		$form[] = array('row' => $row, 'col' => 500, "label" => array("name" => "Credit", "width" => 100), "input" => array("type" => 'text',	'attr' => array("name" => 'credit', "size" => 15, 'readonly' => true, 'class' => 'decimal')));

		$row = $row + 25;
		$form[] = array('row' => $row, 'col' => 500, "label" => array("name" => "Saldo Akhir", "width" => 100), "input" => array("type" => 'text',	'attr' => array("name" => 'akhir', "size" => 15, 'readonly' => true, 'class' => 'decimal')));

		
		
		
		
		$form[] = array('row' => 475, 'col' => 25, "label" => array("name" => "By", "width" => 100), "input" => array("type" => 'text',	'attr' => array("name" => 'chusr', 'size' => 15, 'readonly' => true)));
		$form[] = array('row' => 475, 'col' => 500, "label" => array("name" => "Last", "width" => 100), "input" => array("type" => 'text',	'attr' => array("name" => 'chtime', 'mode' => 'datetime', 'size' => 20, 'readonly' => true)));
		return $form;
	}
	
	public function setDetail()
	{
		$dte = new Date;
		$log = SESSION;
		$tgl = $_SESSION[$log]['login']['date'];
		$awl = date("Y-m-01", strtotime($tgl));
		$akr = $dte->getPenjumlahanTanggal($awl, 1, 0, 0);
		
		$res->width 	= 950;
		$res->height	= 300;
		$res->col		= 25;
		$res->row		= 135;
		$res->data		= 'acd';
		$res->pk		= 'nojnl';
		$res->select	= 'nojnl as nojnld, tgl as tgld, ket as ketd, debet as debetd, credit as creditd';
		$res->where		= array();
		$res->where[]	= array("mode" => 'atr', "val" => "kdac");
		$res->where[]	= array("mode" => 'atr', "val" => "kd_sub");
		$res->where[]	= array("mode" => 'string', "val" => "tgl >= '".$awl."'");
		$res->where[]	= array("mode" => 'string', "val" => "tgl < '".$akr."'");
		$res->sort		= 'tgl, nojnl';
		
		$res->attr[] = array("label" => 'No. Transaksi',	"attr" => 'nojnld', 	'width' => 150, 	'readoly' => true);
		$res->attr[] = array("label" => 'Tanggal',			"attr" => 'tgld', 		'width' => 70, 		'readoly' => true, 		'mode' => 'date');
		$res->attr[] = array("label" => 'Keterangan',		"attr" => 'ketd', 		'width' => 250, 	'readoly' => true);
		$res->attr[] = array("label" => 'Debet',			"attr" => 'debetd',		'width' => 100, 	'readoly' => true, 		'class' => 'decimal');
		$res->attr[] = array("label" => 'Credit',			"attr" => 'creditd',	'width' => 100, 	'readoly' => true, 		'class' => 'decimal');
		$res->attr[] = array("label" => 'Saldo',			"attr" => 'saldo',		'width' => 100, 	'readoly' => true, 		'class' => 'decimal');

		return $res;
	}
	
	protected function setGrid()
	{
		$kode = new Kode;
		$res->page 	= 50;
		$res->sortA = $kode->getPk($this->set->dBasePk);
		$res->sortT = 'asc';
		
		$res->attr[]	= array("label" => 'Tanggal', 'attr' => 'a.tgl', "sort" => 'true', "width" => 70, 'align' => 'center', 'type' => 'date');
		$res->attr[]	= array("label" => 'Acc', 'attr' => 'a.kdac', "sort" => 'true', "width" => 80);
		$res->attr[]	= array("label" => 'Nama Account', 'attr' => 'a.nmac', "sort" => 'true', "width" => 200);
		$res->attr[]	= array("label" => 'Kode', 'attr' => 'a.kd_sub', "sort" => 'true', "width" => 50);
		$res->attr[]	= array("label" => 'Nama', 'attr' => 'a.nm_sub', "sort" => 'true', "width" => 200);
		
		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.nojnl', "sort" => 'true', "width" => 200, 'align' => 'left', 'filter' => true, 'default' => 'nojnl');

		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";
	}
	
	
	public function cetak()
	{
		$basic = new Basic;
		$this->data->data 	= $this->em->getFind("umh", "*", array("nojnl = '".$_GET['filPrintanojnl']."'"));
		$this->data->pk 	= $this->em->getFind("umd", "*", array("nojnl = '".$_GET['filPrintanojnl']."'"));
		$this->data->det 	= $this->em->getFindBy("umd", "*, debet as jumlah", array("nojnl = '".$_GET['filPrintanojnl']."'", "(pk != '1' or pk is null)"), "noumd asc");
		$this->data->set 	= $this->set;
		$this->data->mode 	= 'Keluar Dari';
		$this->view = "buktiMemo";
		$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";
	}
}