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

class ViewListLaporanSpmSp2d extends HtmlResponse
{
	function TemplateModule ()
   {
		$this->SetTemplateBasedir(GTFWConfiguration::GetValue('application','docroot').'module/'.Dispatcher::Instance()->mModule.'/template');
		$this->SetTemplateFile('view_list_laporan_spm_sp2d.html');
	}
	
	function ProcessRequest ()
   {
		$Obj = new LaporanSpmSp2d;
		$_POST = $_POST->AsArray();
		
   	if(empty($_POST))
		{
			$tglAwal = date('Y-01-01');
			$tglAkhir = date('Y-m-d');
			$keyword = "";	
		} 
			else 
		{
			$tglAwal = $_POST['tanggal_awal_year'].'-'.$_POST['tanggal_awal_mon'].'-'.$_POST['tanggal_awal_day'];
			$tglAkhir = $_POST['tanggal_akhir_year'].'-'.$_POST['tanggal_akhir_mon'].'-'.$_POST['tanggal_akhir_day'];
			$keyword = $_POST['keyword'];
   	}
		
		Messenger::Instance()->SendToComponent('tanggal', 'Tanggal', 'view', 'html', 'tanggal_awal', array($tglAwal), Messenger::CurrentRequest);
      Messenger::Instance()->SendToComponent('tanggal', 'Tanggal', 'view', 'html', 'tanggal_akhir', array($tglAkhir), Messenger::CurrentRequest);
		
		$search = array(
			'tglAwal' => $tglAwal,
			'tglAkhir' => $tglAkhir,
			'keyword' => $keyword,
		);
		
		$return['golongan'] = $Obj->GetDataGolonganBarang();
		$return['data'] = array();
		$return['search'] = $search;
      return $return;
	}
	
	function ParseTemplate ($data = NULL)
   {
   	
   	$this->mrTemplate->AddVars('content', $data['search'], '');
   	
      $this->mrTemplate->AddVar('content', 'URL_SEARCH', Dispatcher::Instance()->GetUrl(Dispatcher::Instance()->mModule, 'listLaporanSpmSp2d', 'view', 'html'));
		$tglAwal = $search['tglAwal'];
		$tglAkhir = $search['tglAkhir'];

		$this->mrTemplate->AddVar('content', 'URL_CETAK', 
		Dispatcher::Instance()->GetUrl(Dispatcher::Instance()->mModule, 'cetakLaporanSpmSp2d', 'view', 'html') . 
		'&tglAwal=' .$tglAwal. 
		'&tglAkhir=' .$tglAkhir);
		
		$this->mrTemplate->AddVar('content', 'URL_CETAK_XLS', 
		Dispatcher::Instance()->GetUrl(Dispatcher::Instance()->mModule, 'excelLaporanSpmSp2d', 'view', 'xlsx') . 
		'&tglAwal=' .$tglAwal. 
		'&tglAkhir=' .$tglAkhir);
	
		#set kolom header table nya
      for($i=0;$i<count($data['golongan']);$i++){
      	$this->mrTemplate->addVar('golongan_barang','GOLONGAN_BARANG',$data['golongan'][$i]['golbrgNama']);
      	$this->mrTemplate->parseTemplate('golongan_barang','a');
		}
		
		if(empty($data['data'])){
			#set colspan jika kosong
			$this->mrTemplate->addVar('data','EMPTY_WIDTH',count($data['golongan'])+4);	
      	$this->mrTemplate->AddVar('data','DATA_EMPTY','YES');
		} else {
			$this->mrTemplate->AddVar('data','DATA_EMPTY','NO');	
		}
	}
}
?>
