<?php

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

class ViewPrintLapNeracaAset extends HtmlResponse {

   function TemplateModule() {
      $this->SetTemplateBasedir(GTFWConfiguration::GetValue('application','docroot').'module/'.Dispatcher::Instance()->mModule.'/template');
      $this->SetTemplateFile('print_lap_neraca_aset.html');
   }
   
   function TemplateBase() {
      $this->SetTemplateBasedir(GTFWConfiguration::GetValue('application', 'docroot') . 'main/template/');
      $this->SetTemplateFile('document-print.html');
      $this->SetTemplateFile('layout-common-blank-print.html');
   }
   
   function ProcessRequest() {
      	$Obj = new lapNeracaAset();
		
      	$data = $_GET->AsArray();
      	
		$return['unitEselon'] = GTFWConfiguration::GetValue('organization', 'company_name');
		$return['alamat'] = GTFWConfiguration::GetValue('organization', 'city');
		$user = $Obj->getUserData();
		$return['nama'] = $user['RealName'];
		$return['tanggalCetak'] = IndonesianDate(date('Y-m-d'), 'YYYY-MM-DD');
		$return['tanggal'] = IndonesianDate($_GET['tanggal'],'YYYY-MM-DD');
		$dateTemp = explode('-', $_GET['tanggal']);
		$return['tahun'] = $dateTemp[0];
		$return['kodeSimak'] = 	GTFWConfiguration::GetValue('organization', 'kode_kemendiknas').".".
								GTFWConfiguration::GetValue('organization', 'kode_eselon1').".".
								GTFWConfiguration::GetValue('organization', 'kode_wilayah').".".
								GTFWConfiguration::GetValue('organization', 'kode_universitas');
      	$return['data'] = $Obj->getDataLaporan($_GET['tanggal'],$_GET['unit']);
      	$unit = $Obj->getDataUnitKerjaById($_GET['unit']);
      	$return['unitName'] = $unit['unitkerjaNama'];
      	$return['kodeSimak'] .= ".".$unit['unitkerjaKode'];

   		return $return;  
   }
   
   function ParseTemplate($data = NULL) {
      	$this->mrTemplate->addVar('content','UNITESELON', $data['unitEselon']);
      	$this->mrTemplate->addVar('content','UNITNAME', $data['unitName']);
		$this->mrTemplate->addVar('content','ALAMAT', $data['alamat']);
      	$this->mrTemplate->addVar('content','NAMA', $data['nama']);
      	$this->mrTemplate->addVar('content','TANGGALCETAK', $data['tanggalCetak']);
		$this->mrTemplate->addVar('content','TAHUN', $data['tahun']);
      	$this->mrTemplate->addVar('content','TANGGAL', $data['tanggal']);
      	$this->mrTemplate->addVar('content','KODESIMAK', $data['kodeSimak']);
      
   		if (count($data['data']) == 0){
			$this->mrTemplate->AddVar('data', 'DATA_EMPTY', 'YES');
			$this->mrTemplate->AddVar('content', 'TOTAL', '0');
			return;
		}else{
			$this->mrTemplate->AddVar('data', 'DATA_EMPTY', 'NO');
			$data = $data['data'];
			$total = 0;
			for ($i=0; $i<sizeof($data); $i++){
				$total=$total+$data[$i]['jumlah'];
				$data[$i]['jumlah'] = number_format($data[$i]['jumlah'], 2, ',', '.');
				$this->mrTemplate->AddVars('data_item', $data[$i], 'DIR_');
				$this->mrTemplate->parseTemplate('data_item', 'a');
			}
			$this->mrTemplate->AddVar('content', 'TOTAL', number_format($total, 2, ',', '.'));
		}
   }
}
?>
