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

class ViewExcelLaporanDir extends XlsResponse {
   var $mWorksheets = array('Data');
   
   function GetFileName() {
      // name it whatever you want
      return 'LaporanDir-'.date('Ymd-His').'.xls';
   }

   function ProcessRequest() {
   	$Obj = new AppLaporanDir();
        $user = $Obj->GetDataUserByUsername($_SESSION['username']);
   	$gedung = Dispatcher::Instance()->Decrypt($_GET['gedung']);
        $pj = Dispatcher::Instance()->Decrypt($_GET['pj']);
        $arrData = $Obj->getDataDir($gedung,$pj);
      
        if($gedung <> 'all' && $gedung <> '') $gedungInfo = $arrData[0]['gedungNama'];
        else $gedungInfo = "Semua Gedung";
        if($pj <> 'all' && $pj <> '') $ruang = $arrData[0]['ruangNama'];
        else $ruang = "Semua Ruang";
        if($gedung == 'all' || $gedung== '' || $pj == 'all' || $pj == ''){
            $unitNama = $user['unitkerjaNama'];
            $unitKode = $user['unitkerjaKode'];
        }else{
            $unitNama = $arrData[0]['unitkerjaNama'];
            $unitKode = $arrData[0]['unitkerjaKode'];
        }
   
      
      if (empty($arrData)) {
         $this->mWorksheets['Data']->write(0, 0, 'Data kosong');
      } else {
         $h1 = $this->mrWorkbook->add_format();
         $h1->set_bold();
         $h1->set_size(14);
         $h1->set_align('vcenter');
         
         $h2 = $this->mrWorkbook->add_format();
         $h2->set_bold();
         $h2->set_size(12);
         $h2->set_align('center');
         $h2->set_align('vcenter');
         
         $strong = $this->mrWorkbook->add_format();
         $strong->set_bold();
         
         $sign = $this->mrWorkbook->add_format();
         $sign->set_size(10);
         $sign->set_align('center');
         
         $left = $this->mrWorkbook->add_format();
         $left->set_size(10);
         $left->set_align('left');
         
         #set colom
         $th = $this->mrWorkbook->add_format();
         $th->set_border(1);
         $th->set_bold();
         $th->set_size(10);
         $th->set_align('center');
         $th->set_align('vcenter');
         $th->set_text_wrap();
         
         
         $td = $this->mrWorkbook->add_format();
         $td->set_border(1);
         $td->set_size(10);         
         $td->set_align('left');
         
         $tdCenter = $this->mrWorkbook->add_format();
         $tdCenter->set_border(1);
         $tdCenter->set_size(10);         
         $tdCenter->set_align('center');
         
         $tdRight = $this->mrWorkbook->add_format();
         $tdRight->set_border(1);
         $tdRight->set_size(10);         
         $tdRight->set_align('right');
         
         #set header
         $row = 0;
         $this->mWorksheets['Data']->write($row, 1, GTFWConfiguration::GetValue('organization', 'company_name'), $h1);
         $this->mWorksheets['Data']->merge_cells($row, 1, 1, 7);
         
         $row+=3;
         $this->mWorksheets['Data']->write($row, 0, 'Daftar Inventarisasi Ruang(DIR)', $h2);
         $this->mWorksheets['Data']->merge_cells($row, 0, $row+1, 7);
         
         $row+=3;
         $this->mWorksheets['Data']->write($row, 0, 'Nomor', $strong);
         $this->mWorksheets['Data']->write($row, 2, '', $strong);
         $row++;
         
         $this->mWorksheets['Data']->write($row, 0, 'Nama Gedung', $strong);
         $this->mWorksheets['Data']->write($row, 2, $gedungInfo, $strong);
         $row++;
         
         $this->mWorksheets['Data']->write($row, 0, 'Nama Ruang', $strong);
         $this->mWorksheets['Data']->write($row, 2, $ruang, $strong);
         $row++;
         
         $this->mWorksheets['Data']->write($row, 0, 'Nama UPB', $strong);
         $this->mWorksheets['Data']->write($row, 2, $unitNama, $strong);
         $row++;
         
         $this->mWorksheets['Data']->write($row, 0, 'Nomor Kode UPB', $strong);
         $this->mWorksheets['Data']->write($row, 2, $unitKode, $strong);
         $row++;
         
         
         
         
         //set header
			$row+=2;
         $this->mWorksheets['Data']->write($row, 0, 'NO', $th);
			$this->mWorksheets['Data']->merge_cells($row, 0, $row+1, 0);
			$this->mWorksheets['Data']->write($row, 1, 'Nomor Kode Barang', $th);
			$this->mWorksheets['Data']->merge_cells($row, 1, $row+1, 1);
			$this->mWorksheets['Data']->write($row, 2, 'Nama Barang', $th);
			$this->mWorksheets['Data']->merge_cells($row, 2, $row+1, 2);
			$this->mWorksheets['Data']->write($row, 3, 'Tanda Pengenal Barang', $th);
			$this->mWorksheets['Data']->merge_cells($row, 3, $row, 4);
			$this->mWorksheets['Data']->write($row, 5, 'Jumlah Barang', $th);
			$this->mWorksheets['Data']->merge_cells($row, 5, $row+1, 5);
			$this->mWorksheets['Data']->write($row, 6, 'Keterangan', $th);
			$this->mWorksheets['Data']->merge_cells($row, 6, $row+1, 6);
         
         $row++;
			$this->mWorksheets['Data']->write($row, 3, 'Merk/Type Barang', $th);
			$this->mWorksheets['Data']->write($row, 4, 'Tahun Beli/Buat', $th);
			$row++;
			
			$this->mWorksheets['Data']->write($row, 0, '1', $th);
			$this->mWorksheets['Data']->write($row, 1, '2', $th);
			$this->mWorksheets['Data']->write($row, 2, '3', $th);
			$this->mWorksheets['Data']->write($row, 3, '4', $th);
			$this->mWorksheets['Data']->write($row, 4, '5', $th);
			$this->mWorksheets['Data']->write($row, 5, '6', $th);
			$this->mWorksheets['Data']->write($row, 6, '7', $th);
			$row++;
			
         for($i=0;$i<count($arrData);$i++){
         	$this->mWorksheets['Data']->write($row, 0, $i+1, $tdCenter);
         	$this->mWorksheets['Data']->write($row, 1, $arrData[$i]['kode_barang'], $td);
         	$this->mWorksheets['Data']->write($row, 2, $arrData[$i]['nama_barang'], $td);
         	$this->mWorksheets['Data']->write($row, 3, $arrData[$i]['merk'], $td);
         	$this->mWorksheets['Data']->write($row, 4, $arrData[$i]['tahun_beli_buat'], $tdCenter);
         	$this->mWorksheets['Data']->write($row, 5, $arrData[$i]['jumlah_barang'], $tdCenter);
         	$this->mWorksheets['Data']->write($row, 6, $arrData[$i]['keterangan'], $td);
         	$row++;
			}
			$row+=2;
			$this->mWorksheets['Data']->write($row, 0, 'Tidak dibenarkan memindahkan barang-barang yang ada pada daftar ini tanpa sepengetahuan', $strong);
			$row++;
			
			$this->mWorksheets['Data']->write($row, 0, 'Kepala Bagian Tata Usaha atau Penanggung jawab ruangan ini.', $strong);
			$row+=2;
			
			$this->mWorksheets['Data']->write($row, 4, GTFWConfiguration::GetValue('organization', 'city').', '.date('d-F-Y'), $sign);
			$this->mWorksheets['Data']->merge_cells($row, 4, $row, 6);
			$row+=2;
			
			$this->mWorksheets['Data']->write($row, 0, 'Mengetahui', $sign);
			$this->mWorksheets['Data']->merge_cells($row, 0, $row, 1);
			$this->mWorksheets['Data']->write($row, 4, 'Penanggung Jawab Ruangan', $sign);
			$this->mWorksheets['Data']->merge_cells($row, 4, $row, 6);
			$row+=6;
			
			$this->mWorksheets['Data']->write($row, 0, '(.....................................)', $sign);
			$this->mWorksheets['Data']->merge_cells($row, 0, $row, 1);
			$this->mWorksheets['Data']->write($row, 4, '(....................................................)', $sign);
			$this->mWorksheets['Data']->merge_cells($row, 4, $row, 6);
			$row++;
			
			$this->mWorksheets['Data']->write($row, 0, 'Nip.', $left);
			$this->mWorksheets['Data']->merge_cells($row, 0, $row, 1);
			$this->mWorksheets['Data']->write($row, 4, 'Nip.', $left);
			$this->mWorksheets['Data']->merge_cells($row, 4, $row, 6);
      }
      
   }
}
?>
