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

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


   function __construct() {
		$this->_POST = $_POST->AsArray();
		$this->pageView = Dispatcher::Instance()->GetUrl('pb_usulan', 'usulanVerifikasi', 'view', 'html');
		$this->pageInput = Dispatcher::Instance()->GetUrl('pb_usulan', 'verifikasi', 'view', 'html');
   }
	
	public function CheckData()
   {
      $arrReturn['status']=true;  
		if (!empty($this->_POST['listBarang'])) foreach ($this->_POST['listBarang'] as $key=>$value)
      {
         if (intval($value['usulanBrgDetJmlApprove']) != $value['usulanBrgDetJmlApprove'] OR $value['usulanBrgDetJmlApprove'] == 0)
         {
            $arrReturn['status'] = false;
				$arrReturn['message'] = 'Jumlah DO harus numeris dan nilainya lebih dari 0.';
				return $arrReturn;
            break;
         }
         $this->_POST['listBarang'][$key]['usulanBrgDetJmlApprove'] = intval($value['usulanBrgDetJmlApprove']);
		}
   }
	
	public function Update()
   {
		$result = $this->CheckData();
		if($result['status']===false){
         return $result;
		}
		
		$Obj = new VerifikasiUsulan();
		if($this->_POST['approval']==3){
			$result =  $Obj->updateVerifikasiApproval($this->_POST);
		} else {
			$result =  $Obj->updateVerifikasi($this->_POST);
		}
		
		$arrReturn['status'] = $result;
      if($result)
         $arrReturn['message'] = 'Verifikasi Data Sukses';
      else
         $arrReturn['message'] = 'Verifikasi Data Gagal';
      return $arrReturn;
   }
}
?>