<?php
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/pb_usulan_history/business/UsulanHistory.class.php';

class ViewPopupDetilUsulan extends HtmlResponse {

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

   function ProcessRequest() {
		$Obj = new UsulanHistory;	
		
		if (isset($_GET['id']))
      {
         $result = $Obj->getDataUsulanHistoryById($_GET['id']->Integer()->Raw());
         if ($result === false) unset($_GET['id']);
         else
         {
            $result[0]['filePath'] = $Obj->mFilePath.$result[0]['file'];
            $data = $result[0];
				$dataDetil = $result;
         }
      }
		
		$return['data'] = $data;
		$return['detil'] = $dataDetil;
		return $return;
   }

   function ParseTemplate($data = NULL) {
		$this->mrTemplate->AddVars('content', $data['data'], '');
		
		if (empty($data['detil']))
		{
			$this->mrTemplate->AddVar('data', 'DATA_EMPTY', 'YES');
			return;
		} else {
			$this->mrTemplate->AddVar('data', 'DATA_EMPTY', 'NO');
			$i = 1;
			foreach ($data['detil'] as $value)
			{
				$value['no'] = $i;
				$value['class_name'] = ($i % 2) ? 'table-common-even' : '';
				$value['total'] = $value['brgHps']*$value['jmlDO'];
				$value['total'] = number_format($value['total'],2,',','.');
				$value['totalusulan'] = $value['brgNilai']*$value['jmlDO'];
				$value['totalusulan'] = number_format($value['totalusulan'],2,',','.');
				$value['brgHps'] = number_format($value['brgHps'],2,',','.');
				$value['brgNilai'] = number_format($value['brgNilai'],2,',','.');
				$value['jmlDO'] = (int)$value['jmlDO'];
				$this->mrTemplate->AddVars('data_item', $value, '');
				$this->mrTemplate->parseTemplate('data_item', 'a');   
				$i++;
			}
		}
   }
}
?>