<?php
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/gedung/business/AppGedung.class.php';
//set Label for module
require_once GTFWConfiguration::GetValue( 'application', 'docroot') .
'module/label/response/Label.proc.class.php';
class ViewPenyesuaianGedung extends HtmlResponse {


   function TemplateModule() {
      $this->SetTemplateBasedir(GTFWConfiguration::GetValue('application','docroot').'module/gedung/template');
      $this->SetTemplateFile('input_penyesuaian.html');
   }
   
   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 ProcessRequest() {
      $Obj = new AppGedung();
      $get = $_GET->AsArray();
      
      // inisialisasi messaging
		$msg = Messenger::Instance()->Receive(__FILE__);
      $post = $msg[0][0];
		$notebox['msg'] = $msg[0][1];
		$notebox['css'] = $msg[0][2];
      $return['notebox'] = $notebox;
      // ---------
      
      //get data by id
      if (is_array($post))
      {
         $gedung['gd_id'] = $post['gedung_id'];
         $gedung['gd_brg_id'] = $post['aset_id'];
         $gedung['aset_kode'] = $post['kode_aset'];
         $gedung['aset_nama'] = $post['kode'];
         $gedung['gd_kode'] = $post['gedung_kode'];
         $gedung['gd_nama'] = $post['gedung_nama'];
         $gedung['umur_ekonomis'] = $post['umur_ekonomis'];
         $gedung['umur_teknis'] = $post['umur_teknis'];
         $gedung['nilai_residu'] = $post['nilai_residu'];
         $gedung['nilai_perolehan'] = $post['nilai_perolehan'];
         
         $gedung['umur_ekonomis_baru'] = $post['umur_ekonomis_baru'];
         $gedung['umur_teknis_baru'] = $post['umur_teknis_baru'];
         $gedung['nilai_residu_baru'] = $post['nilai_residu_baru'];
         $gedung['nilai_perolehan_baru'] = $post['nilai_perolehan_baru'];
      }
      else $gedung = $Obj->GetGedungById(Dispatcher::Instance()->Decrypt($get['id_gedung']));
      $penyusutan = $Obj->GetDataPenyusutanGedung(Dispatcher::Instance()->Decrypt($get['id_gedung']));
      $return['detil_gedung'] = $gedung;
      $return['penyusutan'] = $penyusutan;
      return $return;
   }
   
   function ParseTemplate($data = NULL) {
      #print_r($data['fasilitas_ref']);
      #print_r($data['fasilitas_gedung']);
      //set Label
      $this->TemplateLabeling();
      
      // render message box
      if($data['notebox']['msg'])
      {
			$this->mrTemplate->SetAttribute('warning_box', 'visibility', 'visible');
			$this->mrTemplate->AddVar('warning_box', 'ISI_PESAN', $data['notebox']['msg']);
			$this->mrTemplate->AddVar('warning_box', 'CLASS_PESAN', $data['notebox']['css']);
		}
      // ---------

      $url_action = Dispatcher::Instance()->GetUrl('gedung', 'PenyesuaianGedung' , 'do', 'html');
      $this->mrTemplate->AddVar('content', 'LABEL_ACTION', 'Update');
      $this->mrTemplate->AddVar('content', 'URL_ACTION', $url_action);
      
      if(!empty($data['detil_gedung'])) {
         $this->mrTemplate->AddVar('content', 'ASET_KODE', $data['detil_gedung']['aset_kode']);
         $this->mrTemplate->AddVar('content', 'ASET_NAMA', $data['detil_gedung']['aset_nama']);
         $this->mrTemplate->AddVar('content', 'GEDUNG_KODE', $data['detil_gedung']['gd_kode']);
         $this->mrTemplate->AddVar('content', 'ASET_ID', $data['detil_gedung']['gd_brg_id']);
         $this->mrTemplate->AddVar('content', 'GEDUNG_ID', $data['detil_gedung']['gd_id']);
         $this->mrTemplate->AddVar('content', 'GEDUNG_NAMA', $data['detil_gedung']['gd_nama']);
         $this->mrTemplate->AddVar('content', 'UMUR_TEKNIS', $data['detil_gedung']['umur_teknis']);
         $this->mrTemplate->AddVar('content', 'NILAI_RESIDU', number_format($data['detil_gedung']['nilai_residu'], 2, ',', '.'));
      }
      
      if(!empty($data['penyusutan'])) {
         $this->mrTemplate->AddVar('content', 'UMUR_EKONOMIS', $data['penyusutan']['sisa_umur_ekonomis']);
         $this->mrTemplate->AddVar('content', 'NILAI_PEROLEHAN', number_format($data['penyusutan']['nilai_akhir'], 2, ',', '.'));
      } else {
         $this->mrTemplate->AddVar('content', 'UMUR_EKONOMIS', $data['detil_gedung']['umur_ekonomis']);
         $this->mrTemplate->AddVar('content', 'NILAI_PEROLEHAN', number_format($data['detil_gedung']['nilai_perolehan'], 2, ',', '.'));
      }
   }
}
?>