<?php

/*
 @ClassName : Print Buku Inventaris
 @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_inventaris/business/AppLaporanInventaris.class.php';
//set Label for module
require_once GTFWConfiguration::GetValue( 'application', 'docroot') .
'module/label/response/Label.proc.class.php';
class printLaporanInventaris extends HtmlResponse {

   function TemplateModule() {
      $this->SetTemplateBasedir(GTFWConfiguration::GetValue('application','docroot').'module/laporan_inventaris/template');
      $this->SetTemplateFile('print_laporan_inventaris.html');
   }
   
   function TemplateBase() {
      $this->SetTemplateBasedir(GTFWConfiguration::GetValue('application', 'docroot') . 'main/template/');
      $this->SetTemplateFile('document-print.html');
      $this->SetTemplateFile('layout-common-print.html');
   }
      
   function ProcessRequest() {
      $Obj = new AppLaporanInventaris ();
      $return['data']= $Obj->GetDataInventaris(Dispatcher::Instance()->Decrypt($_GET['unit']),Dispatcher::Instance()->Decrypt($_GET['barangId']),Dispatcher::Instance()->Decrypt($_GET['tahun']));
      #print_r($return['data']);
      
      $return['kondisi']= $Obj->GetKondisiBarang();
      
      $return['unit']=$_GET['unit'];
      $return['barang_id']=$_GET['barangId'];
      $return['tahun']=$_GET['tahun'];
		
   	return $return;  
   }
   
   function ParseTemplate($data = NULL) {
      
      if($data['unit']=='all') $this->mrTemplate->addVar('content','NAMA_UPB','Semua Unit kerja');
      else $this->mrTemplate->addVar('content','NAMA_UPB',$data['data']['0']['unitkerjaNama']);
      	
      if($data['barang_id']=='') $this->mrTemplate->addVar('content','KODE_SUB_KELOMPOK','Semua Kode Sub Kelompok');
      else $this->mrTemplate->addVar('content','KODE_SUB_KELOMPOK',$data['data']['0']['kode_barang']);
      
      if($data['tahun']=='' || $data['tahun']=='all') $this->mrTemplate->addVar('content','TAHUN','Semua Tahun Pengadaan');
      else $this->mrTemplate->addVar('content','TAHUN',$data['tahun']);
      
      $this->mrTemplate->addVar('content','COUNT_KONDISI',count($data['kondisi']));
      
      //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');
		}
		
      
      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]['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->parseTemplate('data_item','a');
			}
   }
}
?>
