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

require_once GTFWConfiguration::GetValue('application', 'docroot') . 'main/function/date.php';

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

class PopupDetilLelangBarang extends HtmlResponse
{
	
	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 TemplateModule()
   {
      $this->SetTemplateBasedir(GTFWConfiguration::GetValue('application','docroot').
         'module/pelelangan_barang/template');
      $this->SetTemplateFile('popup_detil_lelang_barang.html');
   }
   
   function ProcessRequest()
   {
   	$Obj = new LelangBarang();
   	
      // inisialisasi header
      $data = $Obj-> GetDataLelangBarangById($_GET['idLelangBarang']);
      $return['data'] = $data;
      // ---------
      return $return;
   }
   
	function ParseTemplate($data = NULL)
   {
      $this->TemplateLabeling();
      
	  $dataForm = $data['data'][0];
  
      // render header
	  $dataForm['tanggal_lelang']=IndonesianDate($dataForm['tanggal_lelang'], 'yyyy-mm-dd');
      $this->mrTemplate->AddVars('content', $dataForm, '');
      // ---------
      
      // Render data grid
		if (empty($data['data']))
		{
			$this->mrTemplate->AddVar('data', 'DATA_EMPTY', 'YES');
			return;
		}
		else $this->mrTemplate->AddVar('data', 'DATA_EMPTY', 'NO');
      
		$i = 1;
      foreach ($data['data'] as $value)
      {
		$value['nomor'] = $i;
		
		$totalBiaya +=$value['lelangBiaya'];
		$value['lelangBiaya']=number_format($value['lelangBiaya'], 2, ',', '.');
		$value['total_harga']=number_format($value['total_harga'], 2, ',', '.');
         $this->mrTemplate->AddVars('data_item', $value, '');
         $this->mrTemplate->parseTemplate('data_item', 'a');
         
         $i++;
      }
      // ---------
		$this->mrTemplate->AddVar('data', 'TOTAL_BIAYA', number_format($totalBiaya, 2, ', ', '.'));
   }
}
?>
