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

require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/setting/business/Setting.class.php';

class PrintLaporanPengelolaan extends XlsResponse {
   var $mWorksheets = array('Data');
	
	function GetFileName() {
      return 'LaporanPengelolaan'.date("Y-m-d").'.xls';
   }
	
   function ProcessRequest()
   {
		$Obj = new Pengelolaan();
		$Obj2 = new Setting();
		
		$arrSetting = $Obj2->GetSetting();
		
		$notrans = $_GET['no'];
		$id = $_GET['id'];
		//$alamat 			= GTFWConfiguration::GetValue('organization', 'city');
		//$namacetak	 	= $_SESSION['username'];
		//$tglcetak		= IndonesianDate(date('Y-m-d'), 'YYYY-MM-DD');
		
		$totalData = $Obj->GetCountDataPengelolaan($notrans, $id, $arrSetting['3']['settingValue']);
		$itemViewed = 100000;
		$startRec = 0 ;
		
		$return=$Obj->GetDataPengelolaan($startRec, $itemViewed, $notrans, $id, $arrSetting['3']['settingValue']);

		if (empty($return)) {
         $this->mWorksheets['Data']->write(0, 0, 'Data kosong');
      } else {
		
			$fTitle = $this->mrWorkbook->add_format();
		   $fTitle->set_bold();
         $fTitle->set_size(12);
         $fTitle->set_align('vcenter');
			
			$fTitleSmall = $this->mrWorkbook->add_format();
         $fTitleSmall->set_size(10);
         $fTitleSmall->set_align('vcenter');

			$header = $this->mrWorkbook->add_format();
		   $header->set_bold();
         $header->set_size(14);
         $header->set_align('vcenter'); 
			
		   $fTableTitle = $this->mrWorkbook->add_format();
         $fTableTitle->set_border(1);
		   $fTableTitle->set_bold();
         $fTableTitle->set_size(10);
         $fTableTitle->set_align('center');
			
			$fColData = $this->mrWorkbook->add_format();
         $fColData->set_border(1);
			
			$this->mWorksheets['Data']->write(0, 0, GTFWConfiguration::GetValue('organization', 'company_name'), $header);
			$this->mWorksheets['Data']->write(2, 0, 'Laporan Pengelolaan BHP', $fTitle);
			if($_GET['id']==''){
				$data['data']['unit_nama'] = "Semua Unit kerja";
			} else {
				$data['data']['unit_nama'] = $return[0]['unit_nama'];
			}
			$this->mWorksheets['Data']->write(3, 0, 'Unit pengguna BHP : '.$data['data']['unit_nama'], $fTitleSmall);
			
			$no = 5;
			$this->mWorksheets['Data']->write($no, 0, 'No', $fTableTitle);
         $this->mWorksheets['Data']->write($no, 1, 'Tanggal', $fTableTitle);
         $this->mWorksheets['Data']->write($no, 2, 'Nomor Transaksi', $fTableTitle);
         $this->mWorksheets['Data']->write($no, 3, 'Penerima', $fTableTitle);
         $this->mWorksheets['Data']->write($no, 4, 'Unit Kerja', $fTableTitle);
         $this->mWorksheets['Data']->write($no, 5, 'Keterangan', $fTableTitle);
			
			$no = 6;
			$data = $return;
			for($i=0;$i<sizeof($data);$i++){
				$n++;
				//-- end of convert
				
				$this->mWorksheets['Data']->write($no, 0, ($i+1), $fColData);
				$this->mWorksheets['Data']->write($no, 1, $data[$i]['trans_tanggal'], $fColData);
				$this->mWorksheets['Data']->write($no, 2, $data[$i]['trans_nomor'], $fColData);
				$this->mWorksheets['Data']->write($no, 3, $data[$i]['trans_nama'], $fColData);
				$this->mWorksheets['Data']->write($no, 4, $data[$i]['unit_nama'], $fColData);
				$this->mWorksheets['Data']->write($no, 5, $data[$i]['trans_keterangan'], $fColData);
            $no++;
			}
			
			$date=date('d-m-Y');
         $date=IndonesianDate($date,'dd-mm-yyyy');
   
         $sign = $this->mrWorkbook->add_format();
         $sign->set_align('center');
			
			$no+=3;
			$this->mWorksheets['Data']->write($no, 5, GTFWConfiguration::GetValue('organization', 'city').', '.$date,$sign);
         //$no++;
         //$this->mWorksheets['Data']->write($no, 4, 'Pimpinan Unit / Sub Unit',$sign);         
         $no+=5;
         $this->mWorksheets['Data']->write($no, 5, '(...........................................)',$sign);
			
			$date=date('d-m-Y H:i:s');
			$nama = $_SESSION['username'];
         $cetak = $this->mrWorkbook->add_format();
         $cetak->set_align('left');
			$cetak->set_size(8);
			
			$no+=4;
			$this->mWorksheets['Data']->write($no, 0, "Dicetak : ".$nama.", ".$date,$cetak);
		}
   }
}
?>