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

require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/setting/business/Setting.class.php';

class PrintLaporanPengelolaan extends HtmlResponse {

	function TemplateBase()
	{
		$this->SetTemplateBasedir(GTFWConfiguration::GetValue('application', 'docroot') . 'main/template/');
		$this->SetTemplateFile('document-print.html');
		$this->SetTemplateFile('layout-common-print.html');
	}
	
   function TemplateModule() 
	{
      $this->SetTemplateBasedir(GTFWConfiguration::GetValue('application','docroot').'module/laporan_pengelolaan_bhp/template');
      $this->SetTemplateFile('print_laporan_pengelolaan.html');
   }
      
   function ProcessRequest() 
	{
      $Obj = new Pengelolaan();
		$Obj2 = new Setting();
		
		$arrSetting = $Obj2->GetSetting();
		$get = (is_object($_GET)) ? $_GET->AsArray() : $_GET;
		$notrans = $get['no'];
		$id = $get['id'];
		$bulan = $get['mon'];
		$tahun = $get['year'];
		$alamat 		= GTFWConfiguration::GetValue('organization', 'city');
		$namacetak	 	= $_SESSION['username'];
		$tglcetak		= IndonesianDate(date('Y-m-d'), 'YYYY-MM-DD');
		
		//$totalData = $Obj->GetCountDataPengelolaan($notrans, $id, $arrSetting['3']['settingValue']);
		$itemViewed = 100000;
		$startRec = 0 ;
		
		$data=$Obj->GetDataPengelolaan($startRec, $itemViewed, $notrans, $id, $arrSetting['3']['settingValue'],$bulan,$tahun);
		$return['alamat'] = $alamat; 
		$return['nama'] = $namacetak; 
		$return['tanggal'] = $tglcetak; 
		$return['waktu'] = date("d-m-Y H:i:s"); 
		$return['data'] = $data;
		$return['id'] = $id;
		return $return;  
   }
   
   function ParseTemplate($data = NULL) 
	{			
		if($data['id']==''){
			$data['unit_nama'] = "Semua Unit kerja";
		} else {
			$data['unit_nama'] = $data['data'][0]['unit_nama'];
		}
		$this->mrTemplate->AddVar('content', 'UNIT_NAMA', $data['unit_nama']);
		$this->mrTemplate->AddVar('content', 'ALAMAT', $data['alamat']);
		$this->mrTemplate->AddVar('content', 'TANGGAL', $data['tanggal']);
		$this->mrTemplate->AddVar('content', 'WAKTU', $data['waktu']);
		$this->mrTemplate->AddVar('content', 'NAMA', $data['nama']);
		
		if (empty($data['data']))
		{
			$this->mrTemplate->addVar('data_grid', 'IS_DATA_EMPTY', 'YES');
			return;
		}
		else 
		{	
			$this->mrTemplate->addVar('data_grid', 'IS_DATA_EMPTY', 'NO');
			   
			$i=1;
			foreach($data['data'] as $value){
				$value['number']=$i;
				$value['trans_tanggal'] = IndonesianDate($value['trans_tanggal'], 'YYYY-MM-DD');
				$this->mrTemplate->AddVars('data_list', $value, '');
 				$this->mrTemplate->parseTemplate('data_list', 'a');	
 				$i++; 
			}
// 			for ($i=0; $i<count($data); $i++) 
// 			{
// 				$no = $i+1;
// 				$data[$i]['number'] = $no;
// 				if ($no % 2 != 0) $data[$i]['class_name'] = 'table-common-even';
// 				else $data[$i]['class_name'] = '';
					
// 				$data[$i]['trans_tanggal'] = IndonesianDate($data[$i]['trans_tanggal'], 'yyyy-mm-dd');
						
// 				$this->mrTemplate->AddVars('data_list', $data[$i], 'DATA_');
// 				$this->mrTemplate->parseTemplate('data_list', 'a');	 
// 			}
		}	
   }
}
?>
