<?php
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/pengembalian_aset/business/PengembalianAset.class.php';

class PengembalianAsetProc {

   var $_POST;
	var $Obj;
	var $pageView;
	var $pageInput;

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

	var $return;
	var $decId;
	var $encId;

   function __construct() {
		$this->Obj		= new PengembalianAset();
		$this->_POST 	= $_POST->AsArray();

		$this->decId 	= Dispatcher::Instance()->Decrypt($_REQUEST['dataId']);
		$this->encId 	= Dispatcher::Instance()->Encrypt($this->decId);
		$this->pageView		= Dispatcher::Instance()->GetUrl('pengembalian_aset', 'pengembalianAset', 'view', 'html').'&grp='.Dispatcher::Instance()->Encrypt($this->_POST['sewa_id']);
		$this->pageInput 		= Dispatcher::Instance()->GetUrl('pengembalian_aset', 'inputPengembalianAset', 'view', 'html');
		$this->tglPengembalian = $this->_POST['tgl_pengembalian_year'].'-'.$this->_POST['tgl_pengembalian_mon'].'-'.$this->_POST['tgl_pengembalian_day'];
		$this->idUser = Security::Instance()->mAuthentication->getcurrentuser()->GetUserId();
	}
	
	function GenerateNumber()
	{
		$code		= "PSA";
		$generate = $code.'-'.date('Ymd-His');
		return $generate;
	}

   public function Update()
   {
      if(isset($this->_POST['cancel'])){
			return $this->pageView;
		}
		
		$id = Dispatcher::Instance()->Decrypt($_GET['id']);
		$pengembalianAsetList = $this->_POST['pengembalianAsetList'];
		
		$this->Obj->StartTrans();
			$this->Obj->DoAddPengembalianAset($this->_POST['sewa_id'], $this->GenerateNumber(), $this->_POST['keterangan'], $this->tglPengembalian, $this->idUser);
			
			if(!empty($pengembalianAsetList))
			{
				foreach($pengembalianAsetList as $value){
					$addPengembalianDetil = $this->Obj->DoAddPengembalianAsetDet($value['asetId'], $value['terlambat'],$value['rusak'], $value['ganti'], $value['subKeterangan'], $value['statusId']);
				}
			}

		$this->Obj->EndTrans($addPengembalianDetil);

		if ($addPengembalianDetil === true)
		{
			Messenger::Instance()->Send('pengembalian_aset', 'pengembalianAset', 'view', 'html', array($this->_POST, 'Perubahan Data Berhasil Dilakukan', $this->cssDone),Messenger::NextRequest);
		}
			else
		{
			Messenger::Instance()->Send('pengembalian_aset', 'pengembalianAset', 'view', 'html', array($this->_POST,'Gagal Merubah Data', $this->cssFail),Messenger::NextRequest);
		}
	
		return $this->pageView;
   }
}
?>