<?php
/**
* @package : ViewLapNeracaAset
* @copyright : Copyright (c) PT Gamatechno Indonesia
* @Analyzed By : Nanang Ruswianto
* @author : Didi Zuliansyah
* @version : 01
* @startDate : 2013-08-14
* @lastUpdate : 2013-08-14
* @description : Laporan Neraca Aset
*/

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

class ViewLapNeracaAset extends HtmlResponse {

	function TemplateModule() {
		$this->SetTemplateBasedir(GTFWConfiguration::GetValue( 'application', 'docroot').'module/'.Dispatcher::Instance()->mModule.'/template');
		$this->SetTemplateFile('view_lap_neraca_aset.html');
	}

	function ProcessRequest() {
		$obj = new lapNeracaAset();

		if(isset($_POST['cari'])){
			$_POST = $_POST->AsArray();
			$unitId = $_POST['unit'];
			$unitName = $_POST['unitnama'];
			$tanggal = $_POST['tanggal_year'].'-'.$_POST['tanggal_mon'].'-'.$_POST['tanggal_day'];
		}else{
			$tanggal = date('Y-m-d');
		}
		
		#combo date
		Messenger::Instance()->SendToComponent('tanggal', 'Tanggal', 'view', 'html', 'tanggal',array($tanggal,$obj->getInventarisOldestDate()), Messenger::CurrentRequest);

		$return['data'] = $obj->getDataLaporan($tanggal,$unitId);
		
		# filter vars
		$return['unit']['unitnama'] = $unitName;
		$return['unit']['unit'] = $unitId;
		$return['date'] = $tanggal;
		
		return $return;
	}

	function ParseTemplate($data = NULL) {
		
		# filter component
		$urlAction = Dispatcher::Instance()->GetUrl(Dispatcher::Instance()->mModule, Dispatcher::Instance()->mSubModule, Dispatcher::Instance()->mAction, Dispatcher::Instance()->mType);
		$this->mrTemplate->addVar('content','URL_ACTION',$urlAction);
		$urlPopup = Dispatcher::Instance()->GetUrl(Dispatcher::Instance()->mModule, 'PopupUnitKerja', 'view', 'html');
      	$this->mrTemplate->addVar('content','URL_POPUP',$urlPopup);
      	$this->mrTemplate->addVar('content','UNITNAMA',$data['unit']['unitnama']);
      	$this->mrTemplate->addVar('content','UNIT',$data['unit']['unit']);
      	
      	# url print & excel
      	$urlPrint = Dispatcher::Instance()->GetUrl(Dispatcher::Instance()->mModule, 'printLapNeracaAset', 'view', 'html').'&unit='.$data['unit']['unit'].'&unitname='.$data['unit']['unitnama'].'&tanggal='.$data['date'];
      	$urlExcel = Dispatcher::Instance()->GetUrl(Dispatcher::Instance()->mModule, 'excelLapNeracaAset', 'view', 'xlsx').'&unit='.$data['unit']['unit'].'&unitname='.$data['unit']['unitnama'].'&tanggal='.$data['date'];
      	$this->mrTemplate->addVar('content','URL_CETAK',$urlPrint);
      	$this->mrTemplate->addVar('content','URL_EXCEL',$urlExcel);
      	
		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');
			$unitId = $data['unit']['unit'];
			$tanggal = $data['date'];
			$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, ',', '.');
				$data[$i]['url_popup'] = Dispatcher::Instance()->GetUrl(Dispatcher::Instance()->mModule, 'PopupInventarisasi', 'view', 'html').'&id='.$data[$i]['id'].'&unit='.$unitId.'&date='.$tanggal;
				$this->mrTemplate->AddVars('data_item', $data[$i], 'DIR_');
				$this->mrTemplate->parseTemplate('data_item', 'a');
			}
			$this->mrTemplate->AddVar('content', 'TOTAL', number_format($total, 2, ',', '.'));
		}
	}
}

?>