<?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 ViewExcelLapPosisiKeuangan2 extends XlsResponse
{
	var $mWorksheets = array(
		'Data'
	);
	
	function GetFileName() 
	{

		// name it whatever you want
		
		return 'LapPosisiKeuangan' . date('d-m-Y') . '.xls';
	}
	
	function ProcessRequest() 
	{
		$Obj = new AppLapPosisiKeuangan();
		$tgl_akhir = Dispatcher::Instance()->Decrypt($_GET['tgl_akhir']);
		$gridList = $Obj->GetLaporanAll($tgl_akhir);
		
		if (empty($gridList)) 
		{
			$this->mWorksheets['Data']->write(0, 0, 'Data kosong');
		}
		else
		{
			$fTitle = $this->mrWorkbook->add_format();
			$fTitle->set_bold();
			$fTitle->set_size(12);
			$fTitle->set_align('center');

			#set colom
			$fColNomorbold = $this->mrWorkbook->add_format();
			$fColNomorbold->set_border(1);
			$fColNomorbold->set_bold();
			$fColNomorbold->set_size(10);
			//$fColKegiatan->set_column(1,1, 300);
			$fColNomorbold->set_align('center');
			
			$fColNilaibold = $this->mrWorkbook->add_format();
			$fColNilaibold->set_border(1);
			$fColNilaibold->set_bold();
			$fColNilaibold->set_size(10);

			//$fColKegiatan->set_column(1,1, 300);
			$fColNilaibold->set_align('right');
			$fColNomor = $this->mrWorkbook->add_format();
			$fColNomor->set_border(1);

			#$fColNomor->set_bold();
			$fColNomor->set_size(10);

			//$fColKegiatan->set_column(1,1, 300);
			$fColNomor->set_align('center');
			$fColNomorakun = $this->mrWorkbook->add_format();
			$fColNomorakun->set_border(1);
			$fColNomorakun->set_size(10);
			$fColNomorakun->set_align('left');
			
			$fColCtn = $this->mrWorkbook->add_format();
			$fColCtn->set_border(1);
			$fColCtn->set_size(10);
			$fColCtn->set_align('left');
			
			$fColCtnBold = $this->mrWorkbook->add_format();
			$fColCtnBold->set_border(1);
			$fColCtnBold->set_size(10);
			$fColCtnBold->set_bold();
			$fColCtnBold->set_align('left');
			
			$fColNilai = $this->mrWorkbook->add_format();
			$fColNilai->set_border(1);
			$fColNilai->set_size(10);
			$fColNilai->set_align('right');
			
			$fColCtnitalic = $this->mrWorkbook->add_format();
			$fColCtnitalic->set_border(1);
			$fColCtnitalic->set_italic();
			$fColCtnitalic->set_size(10);
			$fColCtnitalic->set_align('left');
			
			$fColNilaitalic = $this->mrWorkbook->add_format();
			$fColNilaitalic->set_border(1);
			$fColNilaitalic->set_italic();
			$fColNilaitalic->set_size(10);
			$fColNilaitalic->set_align('right');
			
			#format widht column
			$this->mWorksheets['Data']->set_column($coll, $coll, 50);
			$this->mWorksheets['Data']->set_column($coll+1, $coll+1, 20);
			
			#set header
			$this->mWorksheets['Data']->write(0, 0, 'Laporan Posis Keuangan / Modal', $fTitle);
			$this->mWorksheets['Data']->merge_cells($row, $coll, $row, $coll + 1);
			$row+= 2;
			$coll = 0;
			$this->mWorksheets['Data']->write($row, $coll, 'Untuk Tahun Yang Berakhir Tanggal ' . IndonesianDate($tgl_akhir, 'yyyy-mm-dd') , $fTitle);
			$this->mWorksheets['Data']->merge_cells($row, $coll, $row + 1, $coll + 1);
			$row+= 2;
			$coll = 0;
			$this->mWorksheets['Data']->write($row, $coll, 'AKTIVA', $fTitle);
			$this->mWorksheets['Data']->merge_cells($row, $coll, $row + 1, $coll + 1);

			//------------------------------------------untuk aktiva lancar----------------------------------------------------------------
			$row+= 2;
			$coll = 0;
			$this->mWorksheets['Data']->write($row, $coll, 'Aktiva Lancar', $fColNomorbold);
			$this->mWorksheets['Data']->merge_cells($row, $coll, $row + 1, $coll);
			$coll++;
			$this->mWorksheets['Data']->write($row, $coll, 'Jumlah (Rp)', $fColNomorbold);
			$this->mWorksheets['Data']->merge_cells($row, $coll, $row + 1, $coll);
			
			for ($i = 0;$i < count($gridList);$i++) 
			{
				
				if ($gridList[$i]['kelJnsNama'] == 'Aktiva Lancar') 
				{
					$row+= 2;
					$coll = 0;
					$this->mWorksheets['Data']->write($row, $coll, $gridList[$i]['nama_kel_lap'], $td);
					$this->mWorksheets['Data']->merge_cells($row, $coll, $row + 1, $coll);
					$coll++;
					$this->mWorksheets['Data']->write($row, $coll, number_format($gridList[$i]['nilai'], 2, ',', '.') , $fColNilai);
					$this->mWorksheets['Data']->merge_cells($row, $coll, $row + 1, $coll);
					$jmlAktvLancar+= $gridList[$i]['nilai'];
				}
			}
			$row+= 2;
			$coll = 0;
			$this->mWorksheets['Data']->write($row, $coll, 'Jumlah Aktiva Lancar', $fColCtnitalic);
			$this->mWorksheets['Data']->merge_cells($row, $coll, $row + 1, $coll);
			$coll++;
			$this->mWorksheets['Data']->write($row, $coll, number_format($jmlAktvLancar, 2, ',', '.') , $fColNilaitalic);
			$this->mWorksheets['Data']->merge_cells($row, $coll, $row + 1, $coll);

			//------------------------------------------untuk aktiva tidak lancar----------------------------------------------------------------
			$row+= 2;
			$coll = 0;
			$this->mWorksheets['Data']->write($row, $coll, 'Aktiva Tidak Lancar', $fColNomorbold);
			$this->mWorksheets['Data']->merge_cells($row, $coll, $row + 1, $coll);
			$coll++;
			$this->mWorksheets['Data']->write($row, $coll, 'Jumlah (Rp)', $fColNomorbold);
			$this->mWorksheets['Data']->merge_cells($row, $coll, $row + 1, $coll);
			
			for ($i = 0;$i < count($gridList);$i++) 
			{
				
				if ($gridList[$i]['kelJnsNama'] == 'Aktiva Tidak Lancar') 
				{
					$row+= 2;
					$coll = 0;
					$this->mWorksheets['Data']->write($row, $coll, $gridList[$i]['nama_kel_lap'], $td);
					$this->mWorksheets['Data']->merge_cells($row, $coll, $row + 1, $coll);
					$coll++;
					$this->mWorksheets['Data']->write($row, $coll, number_format($gridList[$i]['nilai'], 2, ',', '.') , $fColNilai);
					$this->mWorksheets['Data']->merge_cells($row, $coll, $row + 1, $coll);
					$jmlAktvTdkLancar+= $gridList[$i]['nilai'];
				}
			}
			$row+= 2;
			$coll = 0;
			$this->mWorksheets['Data']->write($row, $coll, 'Jumlah Aktiva Tidak Lancar', $fColCtnitalic);
			$this->mWorksheets['Data']->merge_cells($row, $coll, $row + 1, $coll);
			$coll++;
			$this->mWorksheets['Data']->write($row, $coll, number_format($jmlAktvTdkLancar, 2, ',', '.') , $fColNilaitalic);
			$this->mWorksheets['Data']->merge_cells($row, $coll, $row + 1, $coll);

			//-------------------Jumlah Aktiva---
			$row+= 2;
			$coll = 0;
			$totalAktiva = $jmlAktvLancar + $jmlAktvTdkLancar;
			$this->mWorksheets['Data']->write($row, $coll, 'JUMLAH AKTIVA', $fColCtnBold);
			$this->mWorksheets['Data']->merge_cells($row, $coll, $row + 1, $coll);
			$coll++;
			$this->mWorksheets['Data']->write($row, $coll, number_format($totalAktiva, 2, ',', '.') , $fColNilai);
			$this->mWorksheets['Data']->merge_cells($row, $coll, $row + 1, $coll);

			//--------------------------------------------untuk kewajiban dan aktiva bersih
			$row+= 2;
			$coll = 0;
			$this->mWorksheets['Data']->write($row, $coll, 'KEWAJIBAN DAN AKTIVA BERSIH', $fTitle);
			$this->mWorksheets['Data']->merge_cells($row, $coll, $row + 1, $coll + 1);

			//------------------------------------------untuk Kewajiban Jangka Pendek----------------------------------------------------------------
			$row+= 2;
			$coll = 0;
			$this->mWorksheets['Data']->write($row, $coll, 'Kewajiban Jangka Pendek', $fColNomorbold);
			$this->mWorksheets['Data']->merge_cells($row, $coll, $row + 1, $coll);
			$coll++;
			$this->mWorksheets['Data']->write($row, $coll, 'Jumlah (Rp)', $fColNomorbold);
			$this->mWorksheets['Data']->merge_cells($row, $coll, $row + 1, $coll);
			
			for ($i = 0;$i < count($gridList);$i++) 
			{
				
				if ($gridList[$i]['kelJnsNama'] == 'Kewajiban Jangka Pendek') 
				{
					$row+= 2;
					$coll = 0;
					$this->mWorksheets['Data']->write($row, $coll, $gridList[$i]['nama_kel_lap'], $td);
					$this->mWorksheets['Data']->merge_cells($row, $coll, $row + 1, $coll);
					$coll++;
					$this->mWorksheets['Data']->write($row, $coll, number_format($gridList[$i]['nilai'], 2, ',', '.') , $fColNilai);
					$this->mWorksheets['Data']->merge_cells($row, $coll, $row + 1, $coll);
					$jmlJngkaPendek+= $gridList[$i]['nilai'];
				}
			}
			$row+= 2;
			$coll = 0;
			$this->mWorksheets['Data']->write($row, $coll, 'Jumlah Kewajiban Jangka Pendek', $fColCtnitalic);
			$this->mWorksheets['Data']->merge_cells($row, $coll, $row + 1, $coll);
			$coll++;
			$this->mWorksheets['Data']->write($row, $coll, number_format($jmlJngkaPendek, 2, ',', '.') , $fColNilaitalic);
			$this->mWorksheets['Data']->merge_cells($row, $coll, $row + 1, $coll);

			//------------------------------------------untuk Kewajiban Jangka Panjang----------------------------------------------------------------
			$row+= 2;
			$coll = 0;
			$this->mWorksheets['Data']->write($row, $coll, 'Kewajiban Jangka Panjang', $fColNomorbold);
			$this->mWorksheets['Data']->merge_cells($row, $coll, $row + 1, $coll);
			$coll++;
			$this->mWorksheets['Data']->write($row, $coll, 'Jumlah (Rp)', $fColNomorbold);
			$this->mWorksheets['Data']->merge_cells($row, $coll, $row + 1, $coll);
			
			for ($i = 0;$i < count($gridList);$i++) 
			{
				
				if ($gridList[$i]['kelJnsNama'] == 'Kewajiban Jangka Panjang') 
				{
					$row+= 2;
					$coll = 0;
					$this->mWorksheets['Data']->write($row, $coll, $gridList[$i]['nama_kel_lap'], $td);
					$this->mWorksheets['Data']->merge_cells($row, $coll, $row + 1, $coll);
					$coll++;
					$this->mWorksheets['Data']->write($row, $coll, number_format($gridList[$i]['nilai'], 2, ',', '.') , $fColNilai);
					$this->mWorksheets['Data']->merge_cells($row, $coll, $row + 1, $coll);
					$jmlJngkaPanjang+= $gridList[$i]['nilai'];
				}
			}
			$row+= 2;
			$coll = 0;
			$this->mWorksheets['Data']->write($row, $coll, 'Jumlah Kewajiban Jangka Panjang', $fColCtnitalic);
			$this->mWorksheets['Data']->merge_cells($row, $coll, $row + 1, $coll);
			$coll++;
			$this->mWorksheets['Data']->write($row, $coll, number_format($jmlJngkaPanjang, 2, ',', '.') , $fColNilaitalic);
			$this->mWorksheets['Data']->merge_cells($row, $coll, $row + 1, $coll);

			//------------------------------------------untuk  Aktiva Bersih----------------------------------------------------------------
			$row+= 2;
			$coll = 0;
			$this->mWorksheets['Data']->write($row, $coll, 'Aktiva Bersih', $fColNomorbold);
			$this->mWorksheets['Data']->merge_cells($row, $coll, $row + 1, $coll);
			$coll++;
			$this->mWorksheets['Data']->write($row, $coll, 'Jumlah (Rp)', $fColNomorbold);
			$this->mWorksheets['Data']->merge_cells($row, $coll, $row + 1, $coll);
			
			for ($i = 0;$i < count($gridList);$i++) 
			{
				
				if ($gridList[$i]['kelJnsNama'] == 'Aktiva Bersih') 
				{
					$row+= 2;
					$coll = 0;
					$this->mWorksheets['Data']->write($row, $coll, $gridList[$i]['nama_kel_lap'], $td);
					$this->mWorksheets['Data']->merge_cells($row, $coll, $row + 1, $coll);
					$coll++;
					$this->mWorksheets['Data']->write($row, $coll, number_format($gridList[$i]['nilai'], 2, ',', '.') , $fColNilai);
					$this->mWorksheets['Data']->merge_cells($row, $coll, $row + 1, $coll);
					$jmlAktivaBersih+= $gridList[$i]['nilai'];
				}
			}
			$row+= 2;
			$coll = 0;
			$this->mWorksheets['Data']->write($row, $coll, 'Jumlah Aktiva Bersih', $fColCtnitalic);
			$this->mWorksheets['Data']->merge_cells($row, $coll, $row + 1, $coll);
			$coll++;
			$this->mWorksheets['Data']->write($row, $coll, number_format($jmlAktivaBersih, 2, ',', '.') , $fColNilaitalic);
			$this->mWorksheets['Data']->merge_cells($row, $coll, $row + 1, $coll);

			//-------------------JUMLAH KEWAJIBAN DAN AKTIVA BERSIH---
			$row+= 2;
			$coll = 0;
			$totalKwjibanBersih = $jmlJngkaPendek + $jmlJngkaPanjang + $jmlAktivaBersih;
			$this->mWorksheets['Data']->write($row, $coll, 'JUMLAH KEWAJIBAN DAN AKTIVA BERSIH', $fColCtnBold);
			$this->mWorksheets['Data']->merge_cells($row, $coll, $row + 1, $coll);
			$coll++;
			$this->mWorksheets['Data']->write($row, $coll, number_format($totalKwjibanBersih, 2, ',', '.') , $fColNilai);
			$this->mWorksheets['Data']->merge_cells($row, $coll, $row + 1, $coll);
		}
	}
}
?>
