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

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

class ViewInputBarang extends HtmlResponse
{
   function TemplateModule()
   {
      $this->SetTemplateBasedir(GTFWConfiguration::GetValue('application','docroot').
         'module/kodefikasi_barang/template');
      $this->SetTemplateFile('input_barang.html');
   }
   
   function ProcessRequest()
   {
      $Obj = new Kodefikasi;
      
      // inisialisasi messaging
		$msg = Messenger::Instance()->Receive(__FILE__);
      $this->Data = $msg[0][0];
		$this->Pesan = $msg[0][1];
		$this->css = $msg[0][2];
      // End
      
      // Inisialisasi nilai default
      if (is_array($this->Data)) $data = $this->Data;
      elseif (isset($_GET['id']))
      {
         $result = $Obj->GetDataBarangById($_GET['id']->Integer()->Raw());
         if ($result) $data = $result;
         else unset($_GET['id']);
      }
      else $data = array
         (
            'golongan' => '',
            'bidang' => '',
            'bidang_name' => '',
            'kelompok' => '',
            'kelompok_name' => '',
            'subKelompok' => '',
            'subKelompok_name' => '',
            'kode' => '',
            'nama' => '',
            'jenisBarang' => 0,
            'satuanBarang' => 0,
            'hps' => 1,
				'nilaiResidu' =>1,
				'umurEkonomis' => 1
         );
      
      if (!isset($data['subKelompokOld']))
      {
         $data['subKelompokOld'] = $data['subKelompok'];
         $data['kodeOld'] = $data['kode'];
      }
	  
	  $data['link_foto'] = "document/barang/".$data['foto_barang'];
      $return['data'] = $data;
      // ---------
      
      // Render Combobox....
      $GolList = $Obj->GetComboGolongan();
      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'cari_golongan', array('golongan', $GolList, $data['golongan'], 'false', 'id="POP_UP_GOLONGAN"'), Messenger::CurrentRequest);
      
      $JnsBarangList = $Obj->GetComboJnsBarang();
      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'jenis_barang', array('jenisBarang', $JnsBarangList, $data['jenisBarang'], false, ''), Messenger::CurrentRequest);
      
      $StnBarangList = $Obj->GetComboStnBarang();
      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'satuan_barang', array('satuanBarang', $StnBarangList, $data['satuanBarang'], false, ''), Messenger::CurrentRequest);
      // ---------
      
      // Inisialisasi link URL
      $return['url']['pop_up_bidang'] = Dispatcher::Instance()->GetUrl('kodefikasi_barang','popupBidang','view','html');
      $return['url']['pop_up_kelompok'] = Dispatcher::Instance()->GetUrl('kodefikasi_barang','popupKelompok','view','html');
      $return['url']['pop_up_sub_kelompok'] = Dispatcher::Instance()->GetUrl('kodefikasi_barang','popupSubKelompok','view','html');
      $return['url']['action'] = Dispatcher::Instance()->GetUrl('kodefikasi_barang','inputBarang','do','html');
      if (isset($_GET['id'])) $return['url']['action'] .= "&id=".$_GET['id'];
      // ---------
      
      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 URL
      $this->mrTemplate->AddVars('content', $data['url'], 'URL_');
      // ---------
      
      // 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 form
      if (isset($_GET['id']))
         $data['data']['judul'] = 'Ubah';
      else $data['data']['judul'] = 'Tambah';
      
      $this->mrTemplate->AddVars('content', $data['data'], '');
      // ---------
   }
}
?>
