<?php

require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/'.Dispatcher::Instance()->mModule.'/business/AppInventarisasi.class.php';
require_once GTFWConfiguration::GetValue('application', 'docroot') . 'main/function/date.php';

class printLaporanIndukInventaris extends HtmlResponse {

   function TemplateModule() {
      $this->SetTemplateBasedir(GTFWConfiguration::GetValue('application','docroot').'module/'.Dispatcher::Instance()->mModule.'/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 ProcessRequest() {
   	  # increase execution time & memory
   	  set_time_limit(0);
   	  ini_set('memory_limit', '512M');
   	  ini_set('max_execution_time', 600);
   	  
      $Obj = new AppInventarisasi();
      
      if (!empty($_GET))
      {
      	$filter = $_GET->AsArray();
      	$tmp = explode('-',$filter['tglAwal']);
      	$filter['tanggal_awal_year'] = $tmp[0];
      	$filter['tanggal_awal_mon'] = $tmp[1];
      	$filter['tanggal_awal_day'] = $tmp[2];
      	 
      	$tmp = explode('-',$filter['tglAkhir']);
      	$filter['tanggal_akhir_year'] = $tmp[0];
      	$filter['tanggal_akhir_mon'] = $tmp[1];
      	$filter['tanggal_akhir_day'] = $tmp[2];
      	$data_list = $Obj->GetInventarisasi($filter,0,0,TRUE);
      	$return['total_perolehan'] = $Obj->GetTotalPerolehan($filter);
      	$return['unit'] = $Obj->GetDataUnitById($filter['unit']);
      	$return['tglAwal'] = $filter['tglAwal'];
      	$return['tglAkhir'] = $filter['tglAkhir'];
      	$return['inv'] = $data_list;
      }
		
   	return $return;  
   }
   
   function ParseTemplate($data = NULL) {
   	
   	if (empty($data['inv'])) {
         $this->mrTemplate->AddVar('data', 'DATA_EMPTY', 'YES');
   	}else{
   		 $this->mrTemplate->AddVar('content', 'NAMA_UPB', $data['unit']['unitkerjaNama']);
   		 $this->mrTemplate->AddVar('content', 'ALAMAT', GTFWConfiguration::GetValue('organization', 'city'));
   		 $this->mrTemplate->AddVar('content', 'TANGGAL', IndonesianDate(date('Y-m-d'), 'YYYY-MM-DD'));
   		 $this->mrTemplate->AddVar('content', 'TGLAWAL', IndonesianDate($data['tglAwal'], 'YYYY-MM-DD'));
   		 $this->mrTemplate->AddVar('content', 'TGLAKHIR', IndonesianDate($data['tglAkhir'], 'YYYY-MM-DD'));
   		 $this->mrTemplate->AddVar('content', 'NAMA', $_SESSION['username']);
   		 $this->mrTemplate->AddVar('content', 'TOTAL_PEROLEHAN', number_format($data['total_perolehan'],2,',','.'));
         $this->mrTemplate->AddVar('data', 'DATA_EMPTY', 'NO');
         $start=1;
         $company_type = GTFWConfiguration::GetValue('application','company_type');
         for($i=0; $i<count($data['inv']); $i++) {
            $nomor = $i+$start;
            $data['inv'][$i]['nomor'] = $nomor;
            $data['inv'][$i]['KIB'] = ($company_type == '1') ? '<span style="border-bottom: 1px solid black">'.str_replace('|','</span><br/>',$data['inv'][$i]['KIB']) : str_replace('|','<br/><span style="border-top: 1px solid black">',$data['inv'][$i]['KIB'])."</span>";
            if($nomor % 2 != 0)
               $data['inv'][$i]['class_name'] = 'table-common-even';
            else
               $data['inv'][$i]['class_name'] = '';

            $data['inv'][$i]['lokasi_aset'] = str_replace(array(' ','@@'),array('&nbsp;', ' &raquo;&nbsp;'),$data['inv'][$i]['lokasi_aset']);
            $data['inv'][$i]['nilai_perolehan'] = number_format($data['inv'][$i]['nilai_perolehan'],2,',','.');
            //$data['inv'][$i]['nilai_buku'] = number_format($data['inv'][$i]['nilai_buku'],2,',','.');
			$data['inv'][$i]['tgl_pengadaan'] = IndonesianDate($data['inv'][$i]['tgl_pengadaan'], 'YYYY-MM-DD');
			$data['inv'][$i]['tgl_pencatatan'] = IndonesianDate($data['inv'][$i]['tgl_pencatatan'], 'YYYY-MM-DD');
            
          	if($data['inv'][$i]['golBarang']==4||$data['inv'][$i]['golBarang']==5||$data['inv'][$i]['golBarang']==8){
				$data['inv'][$i]['display'] = "none";
			} 
			
            $this->mrTemplate->AddVars('data_item', $data['inv'][$i], 'INV_');
            $this->mrTemplate->parseTemplate('data_item', 'a');
         }
   	}
   }
}
?>
