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

class ViewInputPerbaikanBarangHistory extends HtmlResponse
{	
   function TemplateModule()
   {
      $this->SetTemplateBasedir(GTFWConfiguration::GetValue('application','docroot').
         'module/perbaikan_barang_history/template');
      $this->SetTemplateFile('view_input_perbaikanbarang_history.html');
   }
   
   function ProcessRequest()
   {
   	$Obj = new PerbaikanBarangHistory();
   	
      // 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)){
         $data = $this->Data;
      } elseif(isset($_GET['idPerbaikanBarangHistory'])){
         $result = $Obj->GetDataPerbaikanBarangHistoryById($_GET['idPerbaikanBarangHistory']->Integer()->Raw());
         if ($result === false) unset($_GET['idPerbaikanBarangHistory']);
         else 
				$data = $result[0];
				$data['idPerbaikanBarangHistory']=$_GET['idPerbaikanBarangHistory']->Integer()->Raw();
      }
      
		//-- combobox start here 
		$dataStatus = $Obj->GetStatusAset();
      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'status_aset', array('status_aset', $dataStatus, $data['invDetAsetStatusId'], false, ''), Messenger::CurrentRequest);
		
		$dataKondisi = $Obj->GetKondisiAset();
      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'kondisi_aset', array('kondisi_aset', $dataKondisi, $data['kondisibrgId'], false, ''), Messenger::CurrentRequest);
		
		$dataSatuan = $Obj->GetSatuanAset();
      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'satuan_aset', array('satuan_aset', $dataSatuan, '', false, ''), Messenger::CurrentRequest);
		$return['json']['satuan'] = json_encode($dataSatuan);
		//-- end of combobox
		
      $return['data'] = $data;
		
		// inisialisasi url
      $return['url']['action'] = Dispatcher::Instance()->GetUrl(Dispatcher::Instance()->mModule, 'inputPerbaikanBarangHistory', 'do', 'html');
		$return['url']['action'] .= "&id=".$_GET['idPerbaikanBarangHistory'];
      // ---------
      
      return $return;
   }
   
	function ParseTemplate($data = NULL)
   {
      // render message box
		if ($this->Pesan) {
			$this->mrTemplate->SetAttribute('warning_box', 'visibility', 'visible');
			$this->mrTemplate->AddVar('warning_box', 'ISI_PESAN', $this->Pesan);
		}
      // ---------

      // Render URL
      $this->mrTemplate->AddVars('content', $data['url'], 'URL_');

		// Render Jason Data
		$this->mrTemplate->AddVar('content', 'JSON_COMBO_SATUAN', $data['json']['satuan']);
		// ----------
      
      // render default form value
      if ($_REQUEST['idPerbaikanBarangHistory']!="") {$data['data']['mode'] = "Ubah";}
      else {
			$data['data']['mode'] = "Tambah";
		  
			$data['data']['nomorBA']='BAB'.date('mdY-hms');}
			$data['data']['perbaikanBiaya'] = number_format($data['data']['perbaikanBiaya'], 2, ', ', '.');
			$this->mrTemplate->AddVars('content', $data['data'], '');
			
			// ---------
			$this->mrTemplate->AddVar('content', 'URL_KEMBALI', Dispatcher::Instance()->GetUrl('perbaikan_barang_history', 'perbaikanBarangHistory', 'view', 'html'));
			$this->mrTemplate->AddVar('content', 'URL_ACTION', Dispatcher::Instance()->GetUrl('perbaikan_barang_history', 'addPerbaikanBarangHistory', 'do', 'html') . "&id=" . Dispatcher::Instance()->Encrypt($_GET['idPerbaikanBarangHistory']));
			$this->mrTemplate->AddVar('content', 'URL_ADD_MITRAKERJA', Dispatcher::Instance()->GetUrl('perbaikan_barang_history', 'mitraKerja', 'popup', 'html') );	
			$this->mrTemplate->AddVar('content', 'URL_ADD_INVDET', Dispatcher::Instance()->GetUrl('perbaikan_barang_history', 'invDet', 'popup', 'html') );	
      
   }
}
?>
