<?php
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/lap_posisi_keuangan/business/AppLapPosisiKeuangan.class.php';
require_once GTFWConfiguration::GetValue('application', 'docroot') . 'main/function/date.php';

class ViewCetakLapPosisiKeuangan extends HtmlResponse {

   function TemplateModule() {
      $this->SetTemplateBasedir(GTFWConfiguration::GetValue('application','docroot').'module/lap_posisi_keuangan/template');
      $this->SetTemplateFile('view_cetak_lap_posisi_keuangan.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 AppLapPosisiKeuangan();
      $get = $_GET->AsArray();
      if(!empty($get['tgl_akhir']))
         $tgl = $get['tgl_akhir'];
      else
         $tgl = date("Y-m-d");
      
      $return['laporan_all'] = $Obj->GetLaporanAll($tgl);

      $return['tgl_akhir'] = $tgl;
      return $return;
   }
   
   function ParseTemplate($data = NULL) {
      $this->mrTemplate->AddVar('content', 'TGL_AKHIR', IndonesianDate($data['tgl_akhir'], 'yyyy-mm-dd'));
      
      $this->mrTemplate->AddVar('content', 'EKUITAS_AWAL', number_format($data['laba_thn_lalu']['saldo_akhir'], 2, ',', '.'));

      $gridList = $data['laporan_all'];
      
      
      for($i=0;$i<count($gridList);$i++){
         
         $plusValue[$gridList[$i]['kellapJnsId']] = $plusValue[$gridList[$i]['kellapJnsId']]+$gridList[$i]['nilai'];
            
         switch($gridList[$i]['kellapJnsId']){
            
            CASE '15':$templateName = 'data_item_aktiva_lancar';
                     break;
            CASE '16':$templateName = 'data_item_aktiva_tidak_lancar';
                     break;
            CASE '17':$templateName = 'data_item_kewajiban_jangka_pendek';
                     break;
            CASE '18':$templateName = 'data_item_kewajiban_jangka_panjang';
                     break;
            CASE '19':$templateName = 'data_item_aktiva_bersih';
                     break;
            DEFAULT : $templateName = "";
                     break;
         }
            if(!empty($templateName)){
               $this->mrTemplate->AddVar($templateName,'LAP_NAMA_KEL_LAP',$gridList[$i]['nama_kel_lap']);
               
               if($gridList[$i]['nilai'] < 0)
						$this->mrTemplate->AddVar($templateName,'LAP_JML','('.number_format(str_replace('-','',$gridList[$i]['nilai']), 2, ',', '.').')');
					else
						$this->mrTemplate->AddVar($templateName,'LAP_JML', number_format($gridList[$i]['nilai'], 2, ',', '.'));
						
               $this->mrTemplate->parseTemplate($templateName,'a');
            }
         
      }
      
      if($plusValue['15'] < 0)
			$this->mrTemplate->AddVar('content', 'JUMLAH_AKTIVA_LANCAR','('.number_format(str_replace('-','',$plusValue['15']), 2, ',', '.').')');
		else
			$this->mrTemplate->AddVar('content', 'JUMLAH_AKTIVA_LANCAR', number_format($plusValue['15'], 2, ',', '.'));
		
      if($plusValue['16'] < 0)
			$this->mrTemplate->AddVar('content', 'JUMLAH_AKTIVA_TIDAK_LANCAR','('.number_format(str_replace('-','',$plusValue['16']), 2, ',', '.').')');
		else
			$this->mrTemplate->AddVar('content', 'JUMLAH_AKTIVA_TIDAK_LANCAR', number_format($plusValue['16'], 2, ',', '.'));
			
      $totalAktiva = $plusValue['15']+$plusValue['16'];
      if($totalAktiva < 0)
			$this->mrTemplate->AddVar('content', 'JUMLAH_AKTIVA','('.number_format(str_replace('-','',$totalAktiva), 2, ',', '.').')');
		else
			$this->mrTemplate->AddVar('content', 'JUMLAH_AKTIVA', number_format($totalAktiva, 2, ',', '.'));
		
		if($plusValue['17'] < 0)
			$this->mrTemplate->AddVar('content', 'JUMLAH_KEWAJIBAN_JANGKA_PENDEK','('.number_format(str_replace('-','',$plusValue['17']), 2, ',', '.').')');
		else
			$this->mrTemplate->AddVar('content', 'JUMLAH_KEWAJIBAN_JANGKA_PENDEK', number_format($plusValue['17'], 2, ',', '.'));
		
		if($plusValue['18'] < 0)
			$this->mrTemplate->AddVar('content', 'JUMLAH_KEWAJIBAN_JANGKA_PANJANG','('.number_format(str_replace('-','',$plusValue['18']), 2, ',', '.').')');
		else
			$this->mrTemplate->AddVar('content', 'JUMLAH_KEWAJIBAN_JANGKA_PANJANG', number_format($plusValue['18'], 2, ',', '.'));
			
      if($plusValue['19'] < 0)
			$this->mrTemplate->AddVar('content', 'JUMLAH_AKTIVA_BERSIH','('.number_format(str_replace('-','',$plusValue['19']), 2, ',', '.').')');
		else
			$this->mrTemplate->AddVar('content', 'JUMLAH_AKTIVA_BERSIH', number_format($plusValue['19'], 2, ',', '.'));
      $kewajibanAktivaBersih = $plusValue['17']+$plusValue['18']+$plusValue['19'];
      if($kewajibanAktivaBersih < 0)
			$this->mrTemplate->AddVar('content', 'JUMLAH_KEWAJIBAN_AKTIVA_BERSIH','('.number_format(str_replace('-','',$kewajibanAktivaBersih), 2, ',', '.').')');
		else
			$this->mrTemplate->AddVar('content', 'JUMLAH_KEWAJIBAN_AKTIVA_BERSIH', number_format($kewajibanAktivaBersih, 2, ',', '.'));
			
   }
   
}
?>
