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

//set Label for module
require_once GTFWConfiguration::GetValue( 'application', 'docroot') .
   'module/label/response/Label.proc.class.php';

class ViewLogPengendalianBarang extends HtmlResponse
{
	function TemplateBase()
   {
      if (isset($_GET['popup']))
      {
         $this->SetTemplateBasedir(GTFWConfiguration::GetValue('application', 'docroot') . 'main/template/');
         $this->SetTemplateFile('document-common-popup.html');
         $this->SetTemplateFile('layout-common-popup.html');
         return;
      }
      parent::TemplateBase();
   }
   
   function TemplateModule()
   {
      $this->SetTemplateBasedir(GTFWConfiguration::GetValue('application','docroot').'module/pengendalian_barang/template');
      $this->SetTemplateFile('view_log_pengendalian_barang.html');
   }
   
	function ProcessRequest()
   {
      $Obj = new PengendalianBarang;
      
      // Inisialisasi link URL
      $return['link']['url_back'] = $_SERVER['HTTP_REFERER'];
      // ---------
      
      // Generate dataGrid
      $return['dataHeader'] = $Obj->GetLogHeader($_GET['id']->Integer()->Raw());
      $return['dataBody'] = $Obj->GetLogPengendalianBarang($_GET['id']->Integer()->Raw());
      // ---------
      
      return $return;
	}
	
   function TemplateLabeling(){
      $ObjLabel = new GetModuleLabel();
      $arrLabel = $ObjLabel->GetLabel();
      
      //patTemplate name yang memiliki label2 dinamic
      $arrContent=array("content");
      
      for($i=0;$i<count($arrContent);$i++){
         for($j=0;$j<count($arrLabel);$j++){
            $this->mrTemplate->AddVar($arrContent[$i],$arrLabel[$j]['labelCode'],$arrLabel[$j]['labelName']);
         }
      }
   }
   
	function ParseTemplate($data = NULL)
   {
      //set Label
      $this->TemplateLabeling();
      
      // render link
      if (!isset($_GET['popup']))
      {
         $this->mrTemplate->AddVars('link_back_atas', $data['link'], '');
         $this->mrTemplate->AddVars('link_back_bawah', $data['link'], '');
         $this->mrTemplate->SetAttribute('link_back_atas', 'visibility', 'visible');  
         $this->mrTemplate->SetAttribute('link_back_bawah', 'visibility', 'visible');  
      }
      
      // header
      $this->mrTemplate->AddVars('content', $data['dataHeader'], '');
      
      // body
      $i = 1;
      foreach ($data['dataBody'] as $value)
      {
         $value['number'] = $i;
         $value['class_name'] = ($i % 2) ? '' : 'table-common-even';
         $value['pengBrgTgl'] = date('d F Y', strtotime($value['pengBrgTgl']));
		 $totalBiaya += $value['biaya'];
		 
         if ($value['biaya'] > 0)
            $value['biaya'] = number_format($value['biaya'],2,',','.');
         else $value['biaya'] = 'Tidak Ada';
         
         $this->mrTemplate->AddVars('data_log', $value, '');
         $this->mrTemplate->parseTemplate('data_log', 'a');
         $i++;
      }
	  
	  //untuk total biaya
	  $this->mrTemplate->AddVar('content', 'TOTAL_BIAYA', number_format($totalBiaya,2,',','.'));
	}
}
?>
