<?php
/*
	@ClassName : ViewLapAktivitas
	@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 : Jan 22, 2009
	@LastUpdate : Jan 22, 2009
	@Description :
*/

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 ViewLapPosisiKeuangan extends HtmlResponse {

   function TemplateModule() {
      $this->SetTemplateBasedir(GTFWConfiguration::GetValue('application','docroot').'module/lap_posisi_keuangan/template');
      $this->SetTemplateFile('view_lap_posisi_keuangan.html');
   }
   
   function ProcessRequest() {
      $Obj = new AppLapPosisiKeuangan();
      
      $post = $_POST->AsArray();
	  
      if(!empty($post['tanggal_akhir_day']))
         $tgl = $post['tanggal_akhir_year'] ."-". $post['tanggal_akhir_mon'] ."-". $post['tanggal_akhir_day'];
      else
         $tgl = date("Y-m-d");
	
      //tahun untuk combo
      $tahunTrans = $Obj->GetMinMaxThnTrans();
      Messenger::Instance()->SendToComponent('tanggal', 'Tanggal', 'view', 'html', 'tanggal_akhir',
         array($tgl, $tahunTrans['minTahun'], $tahunTrans['maxTahun']), Messenger::CurrentRequest);
         
      $return['laporan_all'] = $Obj->GetLaporanAll($tgl);
      
      
      $return['tgl_akhir'] = $tgl;
      return $return;
   }
   
   function ParseTemplate($data = NULL) {
   
      $this->mrTemplate->AddVar('content', 'URL_SEARCH', Dispatcher::Instance()->GetUrl('lap_posisi_keuangan', 'LapPosisiKeuangan', 'view', 'html'));
      $this->mrTemplate->AddVar('content', 'URL_CETAK', 
      Dispatcher::Instance()->GetUrl('lap_posisi_keuangan', 'CetakLapPosisiKeuangan', 'view', 'html') . 
      '&tgl_akhir=' . Dispatcher::Instance()->Encrypt($data['tgl_akhir']) . 
      '&cetak=' . Dispatcher::Instance()->Encrypt('yes'));
      
      /*$this->mrTemplate->AddVar('content', 'URL_EXCEL',
		Dispatcher::Instance()->GetUrl('lap_posisi_keuangan', 'ExcelLapPosisiKeuangan', 'view', 'xls') . 
		'&tgl_akhir=' . Dispatcher::Instance()->Encrypt($data['tgl_akhir']) . 
		'&cetak=' . Dispatcher::Instance()->Encrypt('yes'));*/
	  
	  //revisi---------------------------
	  $this->mrTemplate->AddVar('content', 'URL_EXCEL',
      Dispatcher::Instance()->GetUrl('lap_posisi_keuangan', 'ExcelLapPosisiKeuangan2', 'view', 'xls') . 
      '&tgl_akhir=' . Dispatcher::Instance()->Encrypt($data['tgl_akhir']) . 
      '&cetak=' . Dispatcher::Instance()->Encrypt('yes'));
	  
	  
	  $this->mrTemplate->AddVar('content', 'URL_RTF',
      Dispatcher::Instance()->GetUrl('lap_posisi_keuangan', 'RtfLapPosisiKeuangan', 'print', 'rtf') . 
      '&tgl_akhir=' . Dispatcher::Instance()->Encrypt($data['tgl_akhir']) . 
      '&cetak=' . Dispatcher::Instance()->Encrypt('yes'));
      //end revisi-----------------------
	  
      $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->AddVar($templateName,'URL_DETAIL', Dispatcher::Instance()->GetUrl('lap_posisi_keuangan', 'detilLapPosisiKeuangan', 'view', 'html'). '&dataId=' . $gridList[$i]['kellapId'].'&tgl='.$data['tgl_akhir']);
               $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, ',', '.'));
      
   }
}
?>
