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

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

class ViewUsulanDetail extends HtmlResponse
{
   function TemplateModule()
   {
      $this->SetTemplateBasedir(GTFWConfiguration::GetValue('application','docroot').
         'module/usulan_barang/template');
      $this->SetTemplateFile('view_usulan_detail.html');
   }
   
   function ProcessRequest()
   {
      $Obj = new Usulan;
      
      // inisialisasi default value
      $data = $Obj->GetUsulanDetailById($_GET['id']->Integer()->Raw());
      if (!$data) $data = null;
      $return['data'] = $data;
      // ---------
      
      // inisialisasi link address
      $return['url']['back'] = Dispatcher::Instance()->GetUrl('usulan_barang', 'usulanList', 'view', 'html');
      // ---------
      
      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)
   {
      if ($data == null) return null;
      
      // set Label
      $this->TemplateLabeling();
      $this->mrTemplate->AddVar('content', 'JUDUL', (isset($_GET['id']))?'Ubah':'Tambah');
      // ---------
      
      // render link
      $this->mrTemplate->AddVars('content', $data['url'], 'URL_');
      // ---------
      
      // render data detail
      $detailBarang = $data['data']['detail_barang'];
      unset($data['data']['detail_barang']);
		$data['data']['usulanBrgMstTglUsulan'] = date('d F Y', $data['data']['usulanBrgMstTglUsulan']);
      $this->mrTemplate->AddVars('content', $data['data'], '');
      // ---------
      
      // render list barang
      if (empty($detailBarang))
         $this->mrTemplate->AddVar('data', 'DATA_EMPTY', 'YES');
      else
      {
         $this->mrTemplate->AddVar('data', 'DATA_EMPTY', 'NO');
         foreach ($detailBarang as $key=>$value)
         {
            $value['usulanBrgDetJml'] = number_format($value['usulanBrgDetJml'],0,',','.');
            $value['usulanBrgTotal1'] = number_format($value['usulanBrgTotal1'],2,',','.');
            $value['usulanBrgTotal2'] = number_format($value['usulanBrgTotal2'],2,',','.');
            
            $this->mrTemplate->AddVars('data_item', $value, '');
            $this->mrTemplate->AddVar('data_item', 'NOMOR', $key + 1);
            $this->mrTemplate->AddVar('data_item', 'CLASS_NAME', ($key % 2) ? '' : 'table-common-even');
            
            $this->mrTemplate->parseTemplate('data_item', 'a');
         }
      }
      // ---------
   }
}
?>