<?php
/**
 * @package ProcBhpPindahGudang
 * @copyright Copyright (c) PT Gamatechno Indonesia
 * @author Didi Zuliansyah <didi@gamatechno.com>
 * @version 0.1
 * @startDate 2013-01-01
 * @lastUpdate 2013-01-01
 * @description Class ProcBhpPindahGudang
 */

require_once Configuration::Instance()->GetValue( 'application', 'docroot') . 'module/'.Dispatcher::Instance()->mModule.'/business/BhpPindahGudang.class.php';

class ProcBhpPindahGudang {
	var $Obj;
	var $_POST;
	var $error = 0;
	var $pesanError = "";
	var $pageView;
	var $pageInput;

	var $cssDone = "notebox-done";
	var $cssFail = "notebox-warning";

	function __construct() {
		$this->Obj = new BhpPindahGudang();
		$this->_POST = $_POST->AsArray();
		$this->pageView = Dispatcher::Instance()->GetUrl(Dispatcher::Instance()->mModule, 'BhpPindahGudang', 'view', 'html');
		$this->pageInput = Dispatcher::Instance()->GetUrl(Dispatcher::Instance()->mModule, 'InputBhpPindahGudang', 'view', 'html');
	}
	
	function checkEmptyField(){
		$fieldArr = array('notrans','unitasalid','unittujuanid','gudangasal','gudangtujuan','tglpindah_day','tglpindah_mon','tglpindah_year');
		foreach ($fieldArr as $field){
			if($this->_POST[$field] == '') $this->error++;
		}
		if(count($this->_POST['barangList']) == 0 ) $this->error++;
		if($this->error != 0) $this->pesanError = 'Field bertanda * wajib diisi';
	}
	
	function returnValue($status,$urlRedirect,$msg,$css){
		$return['status'] = $status;
		$return['msg'] = $msg;
		$return['css'] = $css;
		$return['url'] = $urlRedirect;
		return $return;
	}
	
	function AddBhpPindahGudang(){
		if(isset($this->_POST['simpan'])) {
			$this->checkEmptyField();
			if($this->error != 0){
				return $this->returnValue(false, '', $this->pesanError, $this->cssFail);
			} else {
				$add = $this->Obj->InsertBhpPindahGudang($this->_POST);
				if ($add == true){
					Messenger::Instance()->Send(Dispatcher::Instance()->mModule, 'BhpPindahGudang', 'view', 'html', array($this->_POST, 'Penambahan Data Berhasil Dilakukan', $this->cssDone),Messenger::NextRequest);
					//$msg = 'Penambahan Berhasil Dilakukan';
					//$css = $this->cssDone;
				} else {
					Messenger::Instance()->Send(Dispatcher::Instance()->mModule, 'BhpPindahGudang', 'view', 'html', array($this->_POST, 'Gagal Menambah Data', $this->cssFail),Messenger::NextRequest); 
					//$msg = 'Gagal Menambah Data';
					//$css = $this->cssFail;
				}
				return $this->returnValue(true, $this->pageView, $msg, $css);
			}
		}
		return $this->returnValue(true, $this->pageView, '', '');
	}
}
?>