<?php
/**
* @package ViewUsulanVerifikasi
* @copyright Copyright (c) PT Gamatechno Indonesia
* @analyst Dyan Galih <galih@gamatechno.com>
* @version 0.1
* @startDate 2011-01-20
* @lastUpdate 2011-01-20
* @description View usulan History
*/

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

class ViewUsulanVerifikasi extends HtmlResponse {

   function TemplateModule() {
      $this->SetTemplateBasedir(GTFWConfiguration::GetValue( 'application', 'docroot').'module/pb_usulan_verifikasi/template');
      $this->SetTemplateFile('view_usulan_verifikasi.html');
   }

   function ProcessRequest() {
		$Obj = new VerifikasiUsulan();
      
		// inisialisasi messaging
		$msg = Messenger::Instance()->Receive(__FILE__);
      $this->Data = $msg[0][0];
		$this->Pesan = $msg[0][1];
		$this->css = $msg[0][2];
		
		// inisialisasi filter
      $filter = array();
      
      if (isset($_POST['action'])) $filter = $_POST->AsArray();
      elseif (isset($_GET['page']) && is_array($this->Data)) $filter = $this->Data;
		
		$dataGet = $_GET->AsArray();
		if($dataGet['noUsulan']!=''){
			$filter['noUsulan'] = $dataGet['noUsulan'];
		} 
		
		Messenger::Instance()->Send('pb_usulan_verifikasi', 'usulanBarang', 'view', 'html', array($filter), Messenger::UntilFetched);
      $return['filter'] = $filter;
      // ---------
		
      // Inisialisasi komponen paging
      $totalData = $Obj->getDataCountVerifikasiUsulan($filter);
      $itemViewed = 20;
      if (isset($_GET['page'])) $currPage = $_GET['page']->Integer()->Raw();
      if (!isset($currPage) OR $currPage < 1) $currPage = 1;
      $startRec = ($currPage - 1) * $itemViewed;
      
      $url = Dispatcher::Instance()->GetUrl(Dispatcher::Instance()->mModule, Dispatcher::Instance()->mSubModule, Dispatcher::Instance()->mAction, Dispatcher::Instance()->mType). '&noUsulan=' . Dispatcher::Instance()->Encrypt($filter['noUsulan']);

      Messenger::Instance()->SendToComponent('paging', 'paging', 'view', 'html', 'paging_top', array($itemViewed, $totalData, $url, $currPage), Messenger::CurrentRequest);
      $return['start'] = $startRec+1;
      // ---------

      if ($totalData > 0) $return['dataGrid'] = $Obj->getDataVerifikasiUsulan($filter, $startRec, $itemViewed);
      else $return['dataGrid'] = array();
      
      return $return;
   }

   function ParseTemplate($data = NULL) {
		$urlVerifikasi = Dispatcher::Instance()->GetUrl('pb_usulan_verifikasi', 'verifikasi', 'view', 'html');
		$urlSearch = Dispatcher::Instance()->GetUrl('pb_usulan_verifikasi', 'usulanVerifikasi', 'view', 'html');
		$urlDetil = Dispatcher::Instance()->GetUrl('pb_usulan_verifikasi', 'detilVerifikasi', 'view', 'html');
		$this->mrTemplate->AddVar('content', 'URL_SEARCH', $urlSearch);
		
		$this->mrTemplate->AddVars('content', $data['filter'], '');
		
      if (empty($data['dataGrid'])) {
            $this->mrTemplate->AddVar('data_grid', 'DATA_EMPTY', 'YES');
         } else {
            $this->mrTemplate->AddVar('data_grid', 'DATA_EMPTY', 'NO');

            $dataList = $data['dataGrid'];

         for ($i=0; $i<sizeof($dataList); $i++) {
            $no = $i+$data['start'];
            $dataList[$i]['nomor'] = $no;

            if ($no % 2 != 0)
               $dataList[$i]['class_name'] = 'table-common-even';
            else
               $dataList[$i]['class_name'] = '';
				
				if($dataList[$i]['status_id']!=1 && $dataList[$i]['status_id']!=6 ){
					$dataList[$i]['dsp_edit'] = 'none';
				}
				
				$dataList[$i]['brgNilai'] = number_format($dataList[$i]['brgNilai'], 2, ',', '.');
            $dataList[$i]['url_detil'] = $urlDetil.'&id='.$dataList[$i]['usulanId'];
            $dataList[$i]['url_verfikasi'] = $urlVerifikasi.'&id='.$dataList[$i]['usulanId'];
            $this->mrTemplate->AddVars('data_item', $dataList[$i], '');
            $this->mrTemplate->parseTemplate('data_item', 'a');
         }
      }
   }
}
?>