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

class ViewPengadaanBarangInput extends HtmlResponse
{
   function TemplateModule()
   {
      $this->SetTemplateBasedir(GTFWConfiguration::GetValue('application','docroot').
         'module/pb_pengadaan_barang/template');
      $this->SetTemplateFile('view_pengadaan_barang_input.html');
   }

   function ProcessRequest()
   { 
		$Obj = new PengadaanBarang();
		
		$msg = Messenger::Instance()->Receive(__FILE__);
		$this->Data = $msg[0][0];
		$this->Pesan = $msg[0][1];
		$this->css = $msg[0][2];
		
		$result = $Obj->GetDataPengadaanBarangById($_GET['id']);
		$data = $result[0];
		
      if (is_array($this->Data))
         $data = $this->Data;
		
		if (!isset($data['pb_tanggal']))
      {
         $spkTime = (isset($data['pengadaanTglSPK'])) ? strtotime($data['pengadaanTglSPK']) : time();
         list($data['pb_tanggal'],$data['pb_bulan'],$data['pb_tahun']) = explode('-', date('d-m-Y', $spkTime));
      }

		$cbxJenisBarang = $Obj->GetComboJenisBarang();
      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'jenis_barang', array('jenis_barang', $cbxJenisBarang, $data['jenis_barang'], false, ''), Messenger::CurrentRequest);
		
		$cbxTanggal = $Obj->GetComboTahun(1, 31, true);
      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'pb_tanggal', array('pb_tanggal', $cbxTanggal, $data['pb_tanggal'], false, ''), Messenger::CurrentRequest);

      $cbxBulan= $Obj->GetComboTahun(1, 12, true);
      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'pb_bulan', array('pb_bulan', $cbxBulan, $data['pb_bulan'], false, ''), Messenger::CurrentRequest);

      $cbxTahun = $Obj->GetComboTahun(date('Y') - 4, date('Y'), false);
      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'pb_tahun', array('pb_tahun', $cbxTahun, $data['pb_tahun'], false, ''), Messenger::CurrentRequest);
		
		$comboJlrPengadaan = $Obj->GetComboJlrPengadaan();
      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'jalur_pengadaan', array('pengadaanJlrPengBrgId', $comboJlrPengadaan, $data['pengadaanJlrPengBrgId'], false, ''), Messenger::CurrentRequest);
		
		$comboSumberDana = $Obj->GetComboSumberDana();
      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'sumber_dana', array('pengadaanSumberdanaId', $comboSumberDana, $data['pengadaanSumberdanaId'], false, ''), Messenger::CurrentRequest);
		
		$comboMitraKerja = $Obj->GetComboMitraKerja();
      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'mitra_kerja', array('pengadaanMitraId', $comboMitraKerja, $data['pengadaanMitraId'], false, ''), Messenger::CurrentRequest);
		
		// here set url
      $return['url']['action'] = Dispatcher::Instance()->GetUrl('pb_pengadaan_barang', 'pengadaanBarangInput', 'do', 'json').'&id='.$_GET['id'];
		$return['url']['popup_mak'] = Dispatcher::Instance()->GetUrl('pb_pengadaan_barang', 'Mak', 'popup', 'html');
		$return['url']['popup_barang'] = Dispatcher::Instance()->GetUrl('pb_pengadaan_barang', 'Barang', 'popup', 'html');
		$return['data'] = $data;
		
		if(empty($data['barangUsulList'])){
			$data['barangUsulList'] = $result;
		}
		
		$return['json']['barang'] = json_encode($data['barangUsulList']);
      unset($return['data']['barangUsulList']);
		
		
      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->AddVars('content', $data['url'], 'URL_');
		
		$data['data']['label'] = (isset($_GET['id'])) ? 'Ubah' : 'Tambah';
		$this->mrTemplate->AddVars('content', $data['json'], 'JSON_' );
      $this->mrTemplate->AddVars('content', $data['data'], '');
   }
}
?>