<?php
require_once GTFWConfiguration::GetValue( 'application', 'docroot').'module/' . Dispatcher::Instance()->mModule . '/business/DhsBarangJasa.class.php';

class PopupDhsBarangJasa extends HtmlResponse
{

	function TemplateBase()
   {
      $this->SetTemplateBasedir(GTFWConfiguration::GetValue('application', 'docroot') . 'main/template/');
      $this->SetTemplateFile('document-common-popup.html');
      $this->SetTemplateFile('layout-common-popup.html');
   }
   
   function TemplateModule()
   {
      $this->SetTemplateBasedir(GTFWConfiguration::GetValue('application','docroot').'module/'.Dispatcher::Instance()->mModule.'/template');
      $this->SetTemplateFile('popup_dhs_barang_jasa.html');
   }
   
   function ProcessRequest()
   {
      $Obj = new DhsBarangJasa;
      
      $arrData = array(
      	array(
      		'barangId' => '1',
      		'barangNama' => 'APPLE MacBook Air',
      		'barangSatuan' => 'Unit',
      		'barangHps' => '12566400'
      	),
      	array(
      		'barangId' => '2',
      		'barangNama' => 'SAMSUNG Galaxy Tab 2 7.0 Espresso 16GB - Silver',
      		'barangSatuan' => 'Unit',
      		'barangHps' => '3499000'
      	),
      	array(
      		'barangId' => '3',
      		'barangNama' => 'TRANSCEND JETFLASH USB 3.0 4 GB',
      		'barangSatuan' => 'Unit',
      		'barangHps' => '92000'
      	),
      	array(
      		'barangId' => '4',
      		'barangNama' => 'X-ROAD 150S',
      		'barangSatuan' => 'Unit',
      		'barangHps' => '14950000'
      	),
      	array(
      		'barangId' => '5',
      		'barangNama' => 'Megelli 250 RE & RV',
      		'barangSatuan' => 'Unit',
      		'barangHps' => '34900000'
      	)
      );

      $arrUrl = array(
      	'url_search' => Dispatcher::Instance()->GetUrl(Dispatcher::Instance()->mModule, Dispatcher::Instance()->mSubModule, Dispatcher::Instance()->mAction, Dispatcher::Instance()->mType)
      );
      
      $return['barang'] = $arrData;
      $return['url'] = $arrUrl;
      return $return;
   }
   
	function ParseTemplate($data = NULL)
   {
   	// parse url
   	$this->mrTemplate->AddVars('content', $data['url'], '');
		
		// parse data 
		if (count($data['barang']) === 0){
			$this->mrTemplate->AddVar('data', 'DATA_EMPTY', 'YES');
			return;
		} else {
			$this->mrTemplate->AddVar('data', 'DATA_EMPTY', 'NO');
			
			$dataBarang = $data['barang'];
			
			$i = 1;
			foreach ($dataBarang as $key => $value){
				$value['number'] = $i;
				$value['baranghps_format'] = number_format($value['barangHps'], '0', '', '.');
            $this->mrTemplate->AddVars('data_item', $value, 'DATA_');
            $this->mrTemplate->parseTemplate('data_item', 'a');
            $i++;
			}
		} 
   	
   }
}
?>
