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

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

class PopupDetilSewaAset extends HtmlResponse {
   
	function TemplateModule()
   {
      $this->SetTemplateBasedir(GTFWConfiguration::GetValue('application','docroot').
         'module/sewa_aset/template');
      $this->SetTemplateFile('popup_detil_sewa_aset.html');
   }
   
   function ProcessRequest()
   {
   	$Obj = new SewaAset();
   	
      $data = $Obj->GetDataSewaAsetById($_GET['id']);
      $return['data'] = $data;
      
      return $return;
   }
   
	function ParseTemplate($data = NULL)
   {  
		$dataForm = $data['data'][0];
  
		// render header
		$dataForm['sewa_tanggal_awal'] = IndonesianDate($dataForm['sewa_tanggal_awal'], 'yyyy-mm-dd');
		$dataForm['sewa_tanggal_akhir'] = IndonesianDate($dataForm['sewa_tanggal_akhir'], '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['asetHargaSewa']*$value['jumlah_hari']) - $value['asetPotongan'];
			$value['subtotal']= ($value['asetHargaSewa']*$value['jumlah_hari']) - $value['asetPotongan'];
			$value['asetHargaSewa']=number_format($value['asetHargaSewa'], 2, ',', '.');
			$value['asetPotongan']=number_format($value['asetPotongan'], 2, ',', '.');
			$value['subtotal']=number_format($value['subtotal'], 2, ',', '.');
				$this->mrTemplate->AddVars('data_item', $value, '');
				$this->mrTemplate->parseTemplate('data_item', 'a');
				
				$i++;
      }
      // ---------
		$this->mrTemplate->AddVar('data', 'TOTAL_BIAYA', number_format($totalBiaya, 2, ', ', '.'));
   }
}
?>
