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

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

class ViewDetailBarang extends HtmlResponse {
	function TemplateModule()
   {
		$this->SetTemplateBasedir(GTFWConfiguration::GetValue('application','docroot').
         'module/kodefikasi_barang_perencanaan/template');
		$this->SetTemplateFile('view_detail_barang.html');
	}
   
   function ProcessRequest()
   {
      $Obj = new Kodefikasi;
      
      // inisialisasi messaging
		$msg = Messenger::Instance()->Receive(__FILE__);
		$this->Pesan = $msg[0][1];
		$this->css = $msg[0][2];
      
      // inisialisasi default value
      if (!isset($_GET['id']) OR !($data = $Obj->GetDetailBarangById($_GET['id']->Integer()->Raw())))
      {
         $this->RedirectTo(Dispatcher::Instance()->GetUrl('kodefikasi_barang_perencanaan', 'kodefikasi', 'view', 'html'));
         return NULL;
      }
	  
	  $data['link_foto'] = "document/barang/".$data['foto_barang'];
      $return['data'] = $data;
      // ---------
      
      // inisialisasi link address
      $return['link']['url_back'] = Dispatcher::Instance()->GetUrl('kodefikasi_barang_perencanaan', 'kodefikasi', 'view', 'html');
      $return['link']['url_edit'] = Dispatcher::Instance()->GetUrl('kodefikasi_barang_perencanaan', 'inputBarang', 'view', 'html').'&id='.$data['idBarang'];
      $return['link']['url_delete'] = Dispatcher::Instance()->GetUrl('confirm', 'confirmDelete', 'do', 'html').
         "&urlDelete=".Dispatcher::Instance()->Encrypt('kodefikasi_barang_perencanaan|deleteBarang|do|html').
         "&urlReturn=".Dispatcher::Instance()->Encrypt('kodefikasi_barang_perencanaan|detailBarang|view|html-id-'.$data['idBarang']).
         "&label=".Dispatcher::Instance()->Encrypt('Kodefikasi Barang').
         "&id=".Dispatcher::Instance()->Encrypt($data['idBarang']).
         "&dataName=".Dispatcher::Instance()->Encrypt($data['namaBarang']);
      // ---------
      
      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)
      {
			$this->mrTemplate->SetAttribute('warning_box', 'visibility', 'visible');
			$this->mrTemplate->AddVar('warning_box', 'ISI_PESAN', $this->Pesan);
			$this->mrTemplate->AddVar('warning_box', 'CLASS_PESAN', $this->css);
		}
      // ---------
      
      // render link
      $this->mrTemplate->AddVars('content', $data['link'], '');
      // ---------
      
      // render detail barang
      $form = $data['data'];
	 
	  if (!empty($form['umurEkonomis'])){
	  $form['umurEkonomis'] = $form['umurEkonomis'].' bulan';}else
	  {$form['umurEkonomis'] = '';}
	  
	  $form['nilaiResidu'] = number_format($form['nilaiResidu'],2,',','.');
      $this->mrTemplate->AddVars('content', $form, 'VALUE_');
      // ---------
   }
}
?>