<?php
require_once GTFWConfiguration::GetValue( 'application', 'docroot').
   'module/'.Dispatcher::Instance()->mModule.'/business/Verifikasi.class.php';

//set Label for module
require_once GTFWConfiguration::GetValue( 'application', 'docroot') .
   'module/label/response/Label.proc.class.php';

class ViewDoVerifikasi extends HtmlResponse
{
   function TemplateModule()
   {
      $this->SetTemplateBasedir(GTFWConfiguration::GetValue('application','docroot').
         'module/'.Dispatcher::Instance()->mModule.'/template');
      $this->SetTemplateFile('view_do_verifikasi.html');
   }
   
   function ProcessRequest()
   {
      $Obj = new Verifikasi;
      
      // inisialisasi messaging
		$msg = Messenger::Instance()->Receive(__FILE__);
      $this->Data = $msg[0][0];
		$this->Pesan = $msg[0][1];
		$this->css = $msg[0][2];
      // ---------

      // inisialisasi default value
      $data = array();
      if (is_array($this->Data))
			$detail = $this->Data;
		elseif (isset($_GET['id']))
      {
         $detail = $Obj->GetPengadaanDetail();
         $detail['tglSPK'] = date ("d F Y", strtotime($detail['tglSPK']));
			$detail['pengadaanBAVerifikasi'] = 'BA.'.date("Ymd.His");
      }
      $return['detail'] = $detail;
      unset($return['detail']['id'], $return['detail']['name'], $return['detail']['golbrgId']);
      // ---------
      
      // render Combo Box
      $status = $Obj->GetCbxStatusVerifikasi();
      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'status', array('statusVerifikasi', $status, $detail['statusVerifikasi'], false, ''), Messenger::CurrentRequest);
      // ---------
      
      // Generate data structure
      $return['dataGrid'] = $Obj->GetKomponenList();
      foreach (array_keys($return['dataGrid']) as $key)
      {
         $return['dataGrid'][$key]['pengadaanDetHargaFaktur'] = number_format($return['dataGrid'][$key]['pengadaanDetHargaFaktur'], 2, ',', '.');
         $return['dataGrid'][$key]['biayaLain'] = number_format($return['dataGrid'][$key]['biayaLain'], 2, ',', '.');
         $return['dataGrid'][$key]['pengadaanDetTotalPerolehan'] = number_format($return['dataGrid'][$key]['pengadaanDetTotalPerolehan'], 2, ',', '.');
         if (isset($detail['id']) && in_array($return['dataGrid'][$key]['pengadaanDetId'], $detail['id'])) $return['dataGrid'][$key]['checked'] = 'checked';
         if ($return['dataGrid'][$key]['pengadaanDetVerifikasi'] == 'sesuai') $return['dataGrid'][$key]['disabled'] = 'disabled';
      }
      // ---------
      
      // inisialisasi url
      $return['url']['back'] = Dispatcher::Instance()->GetUrl(Dispatcher::Instance()->mModule, 'pengadaanList', 'view', 'html');
      $return['url']['action'] = Dispatcher::Instance()->GetUrl(Dispatcher::Instance()->mModule, 'verifikasi', 'do', 'html')."&id=".$_GET['id'];
      // ---------
      
      $return['start'] = 1;
      return $return;
   }
   
   function TemplateLabeling(){
      $ObjLabel = new GetModuleLabel();
      $arrLabel = $ObjLabel->GetLabel();
      
      //patTemplate name yang memiliki label2 dinamic
      $arrContent=array("content");
      
      for($i=0;$i<count($arrContent);$i++){
         for($j=0;$j<count($arrLabel);$j++){
            $this->mrTemplate->AddVar($arrContent[$i],$arrLabel[$j]['labelCode'],$arrLabel[$j]['labelName']);
         }
      }
   }
   
   function ParseTemplate($data = NULL)
   {
      //set Label
      $this->TemplateLabeling();
      
      // Render message box
      if($this->Pesan)
      {
         $msg = '';
         if (is_array($this->Pesan)) foreach ($this->Pesan as $value)
            $msg .= "\t$value<br/>\n";
         else $msg .= $this->Pesan;
         
			$this->mrTemplate->SetAttribute('warning_box', 'visibility', 'visible');
			$this->mrTemplate->AddVar('warning_box', 'ISI_PESAN', $msg);
			$this->mrTemplate->AddVar('warning_box', 'CLASS_PESAN', $this->css);
		}
      // ---------
      
      // Render Pengadaan Detail
      $this->mrTemplate->AddVars('content', $data['detail'], '');
      // ---------
      
      // Render URL
      $this->mrTemplate->AddVars('content', $data['url'], 'URL_');
      // ---------
      
      // Render data grid
		if (empty($data['dataGrid']))
		{
			$this->mrTemplate->AddVar('data', 'DATA_EMPTY', 'YES');
			return;
		}
		else $this->mrTemplate->AddVar('data', 'DATA_EMPTY', 'NO');
      
		$i = $data['start'];
      foreach ($data['dataGrid'] as $value)
      {
			$value['nomor'] = $i;
			$value['class_name'] = ($i % 2) ? 'table-common-even' : '';
            
         $this->mrTemplate->AddVars('data_item', $value, '');
			$this->mrTemplate->parseTemplate('data_item', 'a');
         
         $i++;
      }
      // ---------
   }
}
?>