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

class ProcessPenyesuaian
{
	var $_POST;
	var $Obj;
	var $pageView;
	var $pageInput;
	//css hanya dipake di view
	var $cssDone = "notebox-done";
	var $cssFail = "notebox-warning";

	var $return;

	function __construct() {
		$this->Obj = new AppInventarisasi;
		$this->_POST = $_POST->AsArray();
		$this->pageView = Dispatcher::Instance()->GetUrl('inventarisasi', 'inventarisasi', 'view', 'html');
		$this->pageInput = Dispatcher::Instance()->GetUrl('inventarisasi', 'inventarisasiPenyesuaian', 'view', 'html');
   }
   
   function Check ()
   {
      if (isset($this->_POST['btnbalik'])) return $this->pageView;
      if (!isset($this->_POST['invKodeBarang'])) return $this->pageInput;
      unset($this->_POST['btnsimpan']);
      
      $msg = array();
      foreach(array('mstPenystnUmrEko', 'mstPenystnNilaiPerolehan', 'mstPenystnNilaiResidu') as $key)
         if (intval($this->_POST[$key]) <= 0)
         {
            $msg[] = 'Semua isian harus diisi dan nilainya tidak boleh kurang dari atau sama dengan nol!';
            break;
         }
      
      if (count($msg) > 0)
      {
         $this->msg = array($this->_POST, $msg, '');
         return $this->pageInput."&id=".$_GET['id']->Integer();
      }
		
      return true;
   }
   
   function Penyesuaian()
   {
      $check = $this->Check();
      if ($check !== true)
      {
         @Messenger::Instance()->Send('inventarisasi', 'inventarisasiPenyesuaian', 'view', 'html', $this->msg, Messenger::NextRequest);
         return $check;
      }
      
      $result = $this->Obj->PenyesuaianAset($_GET['id']->Integer()->Raw(), $this->_POST);
      if ($result === 0)
         $msg = array(1=>'Proses Penyesuaian Aset Berhasil Dilakukan.', $this->cssDone);
      else $msg = array(1=>'Proses Penyesuaian Aset Gagal!', $this->cssFail);
      Messenger::Instance()->Send('inventarisasi', 'inventarisasi', 'view', 'html', $msg, Messenger::NextRequest);
      
      return $this->pageView;
   }
}
?>