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

class ViewDetilUsulanBarang extends HtmlResponse {

	function TemplateBase()
   {
      $this->SetTemplateBasedir(GTFWConfiguration::GetValue('application', 'docroot') . 'main/template/');
      $this->SetTemplateFile('document-common-popup.html');
      $this->SetTemplateFile('layout-common-popup.html');
   }
   
   function TemplateModule()
   {
      $this->SetTemplateBasedir(GTFWConfiguration::GetValue('application','docroot').
         'module/pb_usulan/template');
      $this->SetTemplateFile('pop_up_usulan_detil.html');
   }
	
	function ProcessRequest() {
		$Obj = new Usulan;	
		
		if (isset($_GET['id']))
      {
         $result = $Obj->getDataUsulanBarangById($_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)
   {    
		if (count($data['detil']) === 0)
		{
			$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++;
      }
		$this->mrTemplate->AddVars('content', $data['data'], '');
	}
}
?>
