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

class ViewUpdatePengembangan extends HtmlResponse {

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

   function ProcessRequest() {
   	  
		$Obj = new KdpPengembangan();
   	
		$msg = Messenger::Instance()->Receive(__FILE__);
		$this->Data = $msg[0][0];
		$this->Pesan = $msg[0][1];
		$this->css = $msg[0][2];   	
   	
      if (is_array($this->Data)){
         $data = $this->Data;
      } elseif (isset($_GET['kdpId'])){
         $result = $Obj->GetDataKdpPengembanganById($_GET['kdpId']->Integer()->Raw());
         if ($result == false) unset($_GET['kdpId']);
         else
         {
            $data = $result;
         }
      }
      
      $kondisiBarang = $Obj->GetDataKondisiBararang();
      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'kondisi_barang',array('kondisi_barang', $kondisiBarang, $data['KONDISI_ID'], '', ''),Messenger::CurrentRequest);
      
      $bangun = $Obj->GetDataCaraBangun();
      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'cara_bangun',array('cara_bangun', $bangun, $data['BANGUN_ID'], '', ''),Messenger::CurrentRequest);

		Messenger::Instance()->SendToComponent('tanggal', 'tanggal', 'view', 'html', 'tgl_pembukuan', array($data['TGL_BUKU'], '2000', date('Y')), Messenger::CurrentRequest);
		
		Messenger::Instance()->SendToComponent('tanggal', 'tanggal', 'view', 'html', 'tgl_awal_kontrak', array($data['TGL_AWAL'], '2000', date('Y')), Messenger::CurrentRequest);
		Messenger::Instance()->SendToComponent('tanggal', 'tanggal', 'view', 'html', 'tgl_akhir_kontrak', array($data['TGL_AKHIR'], '2000', date('Y')), Messenger::CurrentRequest);
		
		$data['JSON_DETAIL_BARANG'] = json_encode((!empty($data['detail_barang'])) ? $data['detail_barang'] : new stdClass);
		unset($data['detail_barang']);
		
      $return['data'] = $data;

      return $return;   	 
   }

   function ParseTemplate($data = NULL) {
   	  
		if ($this->Pesan) {
			$this->mrTemplate->SetAttribute('warning_box', 'visibility', 'visible');
			$this->mrTemplate->AddVar('warning_box', 'ISI_PESAN', $this->Pesan);
			$this->mrTemplate->AddVar('warning_box', 'NOTEBOX', $this->css);
		}
   	  
		$urlAction = Dispatcher::Instance()->GetUrl('kdp_pengembangan', 'UpdateKdpPengembangan', 'do', 'html').'&kdpId='.$data['data']['KDP_ID'];
		$label = 'Pengembangan KDP';
		$this->mrTemplate->AddVar('content','TITLE', $label);
		$this->mrTemplate->AddVar('content','URL_ACTION', $urlAction);
		$urlPopup = Dispatcher::Instance()->GetUrl('kdp_pengembangan','PopupKodeKdp','view','html');
		$this->mrTemplate->AddVar('content','URL_POPUP', $urlPopup);
	  	
	  	$data['data']['NILAI_ASET'] = number_format($data['data']['NILAI_ASET'],2,',','.');
		$this->mrTemplate->AddVars('content', $data['data'],'');  		 	  
   }
}
?>
