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

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

class ViewDetailInventarisasi extends HtmlResponse
{
   function TemplateModule()
   {
      $this->SetTemplateBasedir(GTFWConfiguration::GetValue('application','docroot').
         'module/'.Dispatcher::Instance()->mModule.'/template');
      $this->SetTemplateFile('view_detail_inventarisasi.html');
   }
   
   function ProcessRequest()
   {
      $Obj = new AppInventarisasi;
      
      // inisialisasi data
      $KIB = $Obj->GetCbxJenisKib();
      foreach ($KIB as $value) $kib[$value['id']] = $value['kode'];
      $return['kib'] = json_encode($kib);
      
      $return['list_biaya_lain'] = $Obj->GetListBiayaLain();
      $return['data'] = $Obj->GetInventarisasiDetailById($_GET['id']->Integer()->Raw());
		$return['data']['link_foto'] = Dispatcher::Instance()->GetUrl('download', 'ReadFile', 'view', 'html').'&pid=3&file='.$return['data']['invNamaFile'];
      // ---------
      
      // inisialisasi link address
      $return['link']['url_back'] = Dispatcher::Instance()->GetUrl('inventarisasi_detail', 'inventarisasi', 'view', 'html');
      // ---------

      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)
   {
      if ($data == null) return null;
      
      // set Label
      $this->TemplateLabeling();
      $this->mrTemplate->AddVar('content', 'JUDUL', (isset($_GET['id']))?'Ubah':'Tambah');
      // ---------
      
      // render link
      $this->mrTemplate->AddVars('content', $data['link'], '');
      // ---------
      
      // render KIB list
      $this->mrTemplate->AddVar('content', 'JSON_KIB_LIST', $data['kib']);
      // ---------
      
      // render form default value
      $biayaLain = $data['data']['biaya_lain'];
      unset($data['data']['biaya_lain']);
	  
	  $data['data']['invNilaiPerolehanSatuan']=number_format($data['data']['invNilaiPerolehanSatuan'], 2, ',', '.');
	  $data['data']['invNilaiFaktur']=number_format($data['data']['invNilaiFaktur'], 2, ',', '.');
	  $data['data']['invTotalPerolehan']=number_format($data['data']['invTotalPerolehan'], 2, ',', '.');
	  @$data['data']['invNJOP']=number_format($data['data']['invDetNJOP'], 2, ',', '.');
      $this->mrTemplate->AddVars('content', $data['data'], '');
      // ---------
      
      // render biaya lain
      if (empty($data['list_biaya_lain']))
         $this->mrTemplate->AddVar('biaya_lain', 'BIAYA_LAIN_EMPTY', 'YES');
      else
      {
         $this->mrTemplate->AddVar('biaya_lain', 'BIAYA_LAIN_EMPTY', 'NO');
         foreach ($data['list_biaya_lain'] as $value)
         {
            $this->mrTemplate->AddVar('biaya_item', 'BIAYAID', $value['id']);
            $this->mrTemplate->AddVar('biaya_item', 'BIAYANAME', $value['name']);
            @$this->mrTemplate->AddVar('biaya_item', 'BIAYANILAI', $biayaLain[$value['id']]);
            $this->mrTemplate->parseTemplate('biaya_item', 'a');
         }
      }
      // ---------
   }
}
?>