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

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

   function ProcessRequest() {
   	$Obj = new AppLaporanIndukInventaris();
   	$gedung = Dispatcher::Instance()->Decrypt($_GET['gedung']);
      $pj = Dispatcher::Instance()->Decrypt($_GET['pj']);
      $arrData = $Obj->getDataDir($gedung,$pj);
      
      $data['data']= $Obj->GetDataIndukInventaris(Dispatcher::Instance()->Decrypt($_GET));
      #print_r($data['data']);
      $data['penguasaan']= $Obj->GetPenguasaanBarang();
      $data['kondisi']= $Obj->GetKondisiBarang();
      
      
   
      
      if (empty($data['data'])) {
         $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');
         
         $collWidth = 16+count($data['penguasaan'])+count($data['kondisi']);
         #set header
         $row = 0;
         $this->mWorksheets['Data']->write($row, 1, GTFWConfiguration::GetValue('organization', 'company_name'), $h1);
         $this->mWorksheets['Data']->merge_cells($row, 1, 1, $collWidth);
         
         $row+=3;
         $this->mWorksheets['Data']->write($row, 0, 'Laporan Induk Inventaris', $h2);
         $this->mWorksheets['Data']->merge_cells($row, 0, $row+1, $collWidth);
         
         $row+=3;

         $this->mWorksheets['Data']->write($row, 0, 'Nama UPB : ', $strong);
         $this->mWorksheets['Data']->write($row, 2, $data['data'][0]['unitkerjaNama'], $strong);
         $row++;

         //set header
			$row+=2;
			$coll=0;
         $this->mWorksheets['Data']->write($row, $coll, 'NO', $th);
			$this->mWorksheets['Data']->merge_cells($row, $coll, $row+1, $coll);
			$coll++;
			$this->mWorksheets['Data']->write($row, $coll, 'Tanggal Pembukuan', $th);
			$this->mWorksheets['Data']->merge_cells($row, $coll, $row+1, $coll);
			$coll++;
			$this->mWorksheets['Data']->write($row, $coll, 'Nomor Kode Barang', $th);
			$this->mWorksheets['Data']->merge_cells($row, $coll, $row+1, $coll);
			$coll++;
			$this->mWorksheets['Data']->write($row, $coll, 'Nama Barang', $th);
			$this->mWorksheets['Data']->merge_cells($row, $coll, $row+1, $coll);
			$coll++;
			$collWidth = $coll+1;
			$this->mWorksheets['Data']->write($row, $coll, 'Keterangan Barang', $th);
			$this->mWorksheets['Data']->merge_cells($row, $coll, $row, $collWidth);
			$coll=$collWidth+1;
			$this->mWorksheets['Data']->write($row, $coll, 'Tahun Pembuatan', $th);
			$this->mWorksheets['Data']->merge_cells($row, $coll, $row+1, $coll);
			$coll++;
			$collWidth = $coll+1;
			$this->mWorksheets['Data']->write($row, $coll, 'Jumlah Barang', $th);
			$this->mWorksheets['Data']->merge_cells($row, $coll, $row, $collWidth);
			$coll=$collWidth+1;
			$this->mWorksheets['Data']->write($row, $coll, 'Asal Barang', $th);
			$this->mWorksheets['Data']->merge_cells($row, $coll, $row+1, $coll);
			$coll++;
			$collWidth = $coll+1;
         $this->mWorksheets['Data']->write($row, $coll, 'Harga (Rp.)', $th);
			$this->mWorksheets['Data']->merge_cells($row, $coll, $row, $collWidth);
         $coll=$collWidth+1;
         $collWidth = $coll+count($data['kondisi'])-1;
         $this->mWorksheets['Data']->write($row, $coll, 'Kondisi Barang', $th);
			$this->mWorksheets['Data']->merge_cells($row, $coll, $row, $collWidth);
         $coll=$collWidth+1;
         $collWidth = $coll+1;
         $this->mWorksheets['Data']->write($row, $coll, 'Bukti Milik', $th);
			$this->mWorksheets['Data']->merge_cells($row, $coll, $row, $collWidth);
         $coll=$collWidth+1;
         $collWidth = $coll+count($data['penguasaan'])-1;
         $this->mWorksheets['Data']->write($row, $coll, 'Penguasaan', $th);
			$this->mWorksheets['Data']->merge_cells($row, $coll, $row, $collWidth);
         $coll=$collWidth+1;
         $collWidth = $coll+1;
         $this->mWorksheets['Data']->write($row, $coll, 'KIB', $th);
			$this->mWorksheets['Data']->merge_cells($row, $coll, $row, $collWidth);
         $coll=$collWidth+1;
         $this->mWorksheets['Data']->write($row, $coll, 'Keterangan', $th);
			$this->mWorksheets['Data']->merge_cells($row, $coll, $row+1, $coll);
         
         $coll=0;
         $row++;
         $coll+=4;
			$this->mWorksheets['Data']->write($row, $coll, 'Merk/Type Barang', $th);
			$coll++;
			$this->mWorksheets['Data']->write($row, $coll, 'Tahun Beli/Buat', $th);
			$coll+=2;
			$this->mWorksheets['Data']->write($row, $coll, 'Jumlah', $th);
			$coll++;
			$this->mWorksheets['Data']->write($row, $coll, 'Satuan', $th);
			$coll+=2;
			$this->mWorksheets['Data']->write($row, $coll, 'Satuan', $th);
			$coll++;
			$this->mWorksheets['Data']->write($row, $coll, 'Jumlah', $th);
			for($i=0;$i<count($data['kondisi']);$i++){
				$coll++;
				$this->mWorksheets['Data']->write($row, $coll, $data['kondisi'][$i]['kondisibrgNama'], $th);
			}
			$coll++;
			$this->mWorksheets['Data']->write($row, $coll, 'A', $th);
			$coll++;
			$this->mWorksheets['Data']->write($row, $coll, 'TA', $th);
			
			for($i=0;$i<count($data['penguasaan']);$i++){
				$coll++;
				$this->mWorksheets['Data']->write($row, $coll, $data['penguasaan'][$i]['statuspengbrgNama'], $th);
			}
			$coll++;
			$this->mWorksheets['Data']->write($row, $coll, 'A', $th);
			$coll++;
			$this->mWorksheets['Data']->write($row, $coll, 'TA', $th);
			$row++;
			
			$dataGrid = $data['data'];
			
			for($i=0;$i<count($dataGrid);$i++){
				$coll=0;
				$this->mWorksheets['Data']->write($row, $coll, $i+1, $td);
				$coll++;
				$this->mWorksheets['Data']->write($row, $coll, $dataGrid[$i]['tanggal_pembukuan'], $td);
				$coll++;
				$this->mWorksheets['Data']->write($row, $coll, $dataGrid[$i]['kode_barang'], $td);
				$coll++;
				$this->mWorksheets['Data']->write($row, $coll, $dataGrid[$i]['nama_barang'], $td);
				$coll++;
				$this->mWorksheets['Data']->write($row, $coll, $dataGrid[$i]['merk'], $td);
				$coll++;
				$this->mWorksheets['Data']->write($row, $coll, $dataGrid[$i]['tipe'], $td);
				$coll++;
				$this->mWorksheets['Data']->write($row, $coll, $dataGrid[$i]['tahun_beli_buat'], $td);
				$coll++;
				$this->mWorksheets['Data']->write($row, $coll, $dataGrid[$i]['jumlah_barang'], $td);
				$coll++;
				$this->mWorksheets['Data']->write($row, $coll, $dataGrid[$i]['satuan'], $td);
				$coll++;
				$this->mWorksheets['Data']->write($row, $coll, $dataGrid[$i]['asal'], $td);
				$coll++;
				$this->mWorksheets['Data']->write_number($row, $coll, $dataGrid[$i]['satuan_perolehan'], $td);
				$coll++;
				$this->mWorksheets['Data']->write_number($row, $coll, $dataGrid[$i]['jumlah_perolehan'], $td);
				


				for($j=0;$j<count($data['kondisi']);$j++){
					$coll++;
					$this->mWorksheets['Data']->write($row, $coll, 0, $td);
               $this->mWorksheets['Data']->write($row, $coll, $dataGrid[$i]['kondisi_'.$data['kondisi'][$j]['kondisibrgId']], $td);
				}
				
				$coll++;
				$this->mWorksheets['Data']->write($row, $coll, $dataGrid[$i]['ada_bm'], $td);
				$coll++;
				$this->mWorksheets['Data']->write($row, $coll, $dataGrid[$i]['tidak_ada_bm'], $td);
				
				for($j=0;$j<count($data['penguasaan']);$j++){
					$coll++;
					$this->mWorksheets['Data']->write($row, $coll, 0, $td);
					
					$this->mWorksheets['Data']->write($row, $coll, $dataGrid[$i]['penguasaan_'.$data['penguasaan'][$j]['statuspengbrgId']], $td);
				}
				
				$coll++;
				$this->mWorksheets['Data']->write($row, $coll, $dataGrid[$i]['ada_kib'], $td);
				$coll++;
				$this->mWorksheets['Data']->write($row, $coll, $dataGrid[$i]['tidak_ada_kib'], $td);
				
				$coll++;
				$this->mWorksheets['Data']->write($row, $coll, $dataGrid[$i]['keterangan'], $td);
				$row++;
			}
			$this->mWorksheets['Data']->write($row+2, $col+16, GTFWConfiguration::GetValue('organization', 'city').', '.date('d M Y'));
			$this->mWorksheets['Data']->write($row+7, $col+16, '...............................');
			$this->mWorksheets['Data']->write($row+8, $col+16, 'NIP : ');
      }
      
   }
}
?>
