<?php
/*
 @ClassName : View Input Pengendalian Barang
 @Copyright : PT Gamatechno Indonesia
 @Analyzed By : Nanang Ruswianto <nanang@gamatechno.com>
 @Designed By : Rosyid <rosyid@gamatechno.com>
 @Author By : Dyan Galih <galih@gamatechno.com>
 @Version : 1.0
 @StartDate : Okt 15, 2008
 @LastUpdate : Okt 16, 2008
 @Description :
*/
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 ViewDetailPengendalianBarang 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/pengendalian_barang/template');
      $this->SetTemplateFile('view_detail_pengendalian_barang.html');
   }
   
   function ProcessRequest()
   {
   	$Obj = new PengendalianBarang();
   	
      // inisialisasi header
      $data = $Obj->GetPengendalianByIdForDetail($_GET['id']->Integer()->Raw());
      // $data['pengBrgLokasi'] = str_replace(' ', '&nbsp;', $data['pengBrgLokasi']);
      $data['pengBrgLokasi'] = str_replace('->', ' &raquo;&nbsp;', $data['pengBrgLokasi']);
      $data['pengBrgTgl'] = date('d F Y', strtotime($data['pengBrgTgl']));
      if ($data['pengFile'] && is_readable(GTFW_APP_DIR.'/'.$Obj->mFilePath.$data['pengFile']))
      {
         $data['pengFileName'] = preg_replace('|^PB-(.*)-[0-9a-f]{5}\.([^\.]*)$|i','\1.\2',$data['pengFile']);
         $data['pengFilePath'] = $Obj->mFilePath.$data['pengFile'];
         $data['pengFileInfo'] = '('.number_format(filesize(GTFW_APP_DIR.'/'.$Obj->mFilePath.$data['pengFile'])/1024, 2, '.', ',')." KB)";
      }
      else $data['pengFileInfo'] = 'Tidak ada';
      $return['dataGrid'] = $data['barangPengendalian'];
      unset($data['barangPengendalian']);
      $return['data'] = $data;
      // ---------
      
      // inisialisasi url
      $return['url']['back'] = Dispatcher::Instance()->GetUrl(Dispatcher::Instance()->mModule, 'pengendalianBarang', 'view', 'html')."&page=1";
      $return['url']['log'] = Dispatcher::Instance()->GetUrl(Dispatcher::Instance()->mModule, 'logPengendalianBarang', 'view', 'html');
      // ---------
      
      return $return;
   }
   
	function ParseTemplate($data = NULL)
   {
      $this->TemplateLabeling();
      
      // Render URL
      $this->mrTemplate->AddVars('content', $data['url'], 'URL_');
      // ---------
      
      // render header
      $this->mrTemplate->AddVars('content', $data['data'], '');
      // ---------
      
      // Render data grid
		if (empty($data['dataGrid']))
		{
			$this->mrTemplate->AddVar('data', 'DATA_EMPTY', 'YES');
			return;
		}
		else $this->mrTemplate->AddVar('data', 'DATA_EMPTY', 'NO');
      
		$i = 1;
      foreach ($data['dataGrid'] as $value)
      {
			$value['nomor'] = $i;
			$value['class_name'] = ($i % 2) ? 'table-common-even' : '';
			$value['url_log'] = $data['url']['log'] . "&id=". $value['barangId'];
			$totalBiaya += $value['pengBrgHrgJual'];
			$value['pengBrgHrgJual'] = number_format($value['pengBrgHrgJual'], 2, ',', '.');
        
			
         $this->mrTemplate->AddVars('data_item', $value, '');
         $this->mrTemplate->parseTemplate('data_item', 'a');
         
         $i++;
      }
      // ---------
		$this->mrTemplate->AddVar('data', 'TOTAL_BIAYA', number_format($totalBiaya, 2, ', ', '.'));
   }
}
?>
