<?php

/*
 @ClassName : Print Laporan DIR
 @Copyright : PT Gamatechno Indosnesia
 @Analyzed By : Nanang Ruswianto <nanang@gamatechno.com>
 @Designed By : Rosyid <rosyid@gamatechno.com>
 @Author By : Dyan Galih <galih@gamatechno.com>
 @Version : 1.0
 @StartDate : Nov 11, 2008
 @LastUpdate : Nov 11, 2008
 @Description :
*/

require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/laporan_induk_inventaris/business/AppLaporanIndukInventaris.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 printLaporanIndukInventaris extends HtmlResponse {

   function TemplateModule() {
      $this->SetTemplateBasedir(GTFWConfiguration::GetValue('application','docroot').'module/laporan_induk_inventaris/template');
      $this->SetTemplateFile('print_laporan_induk_inventaris.html');
   }
   
   function TemplateBase() {
      $this->SetTemplateBasedir(GTFWConfiguration::GetValue('application', 'docroot') . 'main/template/');
      $this->SetTemplateFile('document-print.html');
      $this->SetTemplateFile('layout-common-print.html');
   }
   
   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 ProcessRequest() {
      $Obj = new AppLaporanIndukInventaris ();
		//-- 
		$alamat 			= GTFWConfiguration::GetValue('organization', 'city');
		$namacetak	 	= $_SESSION['username'];
		$tglcetak		= IndonesianDate(date('Y-m-d'), 'YYYY-MM-DD');
		
		$return['alamat'] = $alamat;
		$return['nama'] = $namacetak;
		$return['tanggal'] = $tglcetak;
      $return['data']= $Obj->GetDataIndukInventaris(Dispatcher::Instance()->Decrypt($_GET));
      $return['penguasaan']= $Obj->GetPenguasaanBarang();
      $return['kondisi']= $Obj->GetKondisiBarang();
      
      $return['unit']=$_GET['unit'];
		
   	return $return;  
   }
   
   function ParseTemplate($data = NULL) {
   	
      $this->TemplateLabeling();      
      
      $this->mrTemplate->addVar('content','NAMA_UPB',$data['data']['0']['unitkerjaNama']);
      
      $this->mrTemplate->addVar('content','COUNT_KONDISI',count($data['kondisi']));
      $this->mrTemplate->addVar('content','COUNT_PENGUASAAN',count($data['penguasaan']));
      $this->mrTemplate->addVar('content','ALAMAT', $data['alamat']);
      $this->mrTemplate->addVar('content','NAMA', $data['nama']);
      $this->mrTemplate->addVar('content','TANGGAL', $data['tanggal']);
      
      //set title additional column header
      for($i=0;$i<count($data['kondisi']);$i++){
      	$this->mrTemplate->addVar('kondisi_barang','KONDISI_BARANG',$data['kondisi'][$i]['kondisibrgNama']);
      	$this->mrTemplate->parseTemplate('kondisi_barang','a');
		}
		
		for($i=0;$i<count($data['penguasaan']);$i++){
      	$this->mrTemplate->addVar('penguasaan_barang','PENGUASAAN_BARANG',$data['penguasaan'][$i]['statuspengbrgNama']);
      	$this->mrTemplate->parseTemplate('penguasaan_barang','a');
		}
		
      
      if(empty($data['data'])){
      	$this->mrTemplate->AddVar('data','DATA_EMPTY','YES');
			$this->mrTemplate->addVar('data','EMPTY_WIDTH',count($data['penguasaan'])+count($data['kondisi'])+17);
      	return;
		}else
			$this->mrTemplate->AddVar('data','DATA_EMPTY','NO');
			
			$dataGrid = $data['data'];
			$no = 1;
			for($i=0;$i<count($dataGrid);$i++){
				$dataGrid[$i]['no'] = $no+$i;
				$dataGrid[$i]['jumlah_perolehan_sum'] = $dataGrid[$i]['jumlah_perolehan'];
				$dataGrid[$i]['satuan_perolehan'] = number_format($dataGrid[$i]['satuan_perolehan'], 2, ',', '.');
				$dataGrid[$i]['jumlah_perolehan'] = number_format($dataGrid[$i]['jumlah_perolehan'], 2, ',', '.');
				$this->mrTemplate->AddVars('data_item',$dataGrid[$i],'DIR_');
				
				
				$this->mrTemplate->clearTemplate('kondisi_barang_value');
				for($j=0;$j<count($data['kondisi']);$j++){
               $this->mrTemplate->AddVar('kondisi_barang_value','KONDISI_BARANG_VALUE',$dataGrid[$i]['kondisi_'.$data['kondisi'][$j]['kondisibrgId']]);
					$this->mrTemplate->parseTemplate('kondisi_barang_value','a');
				}
				
				
				$this->mrTemplate->clearTemplate('penguasaan_barang_value');
				for($j=0;$j<count($data['penguasaan']);$j++){
               $this->mrTemplate->AddVar('penguasaan_barang_value','PENGUASAAN_BARANG_VALUE',$dataGrid[$i]['penguasaan_'.$data['penguasaan'][$j]['statuspengbrgId']]);
					$this->mrTemplate->parseTemplate('penguasaan_barang_value','a');
				}
				
				$jumlah_perolehan_sum += $dataGrid[$i]['jumlah_perolehan_sum'];
				$this->mrTemplate->parseTemplate('data_item','a');
			}
			
			$cols = count($data['penguasaan']) + count($data['kondisi']) + 14;
			$this->mrTemplate->addVar('content','COLS', $cols);
			$this->mrTemplate->addVar('content','TOTAL_PEROLEHAN', number_format($jumlah_perolehan_sum, 2, ',', '.'));	
   }
}
?>
