<?php
/*
 @ClassName : View Mutasi Barang
 @Copyright : PT Gamatechno Indosnesia
 @Analyzed By : Nanang Ruswianto <nanang@gamatechno.com>
 @Designed By : Rosyid <rosyid@gamatechno.com>
 @Author By : Dyan Galih <galih@gamatechno.com>
 @Version : 1.0
 @StartDate : Desember 17, 2008
 @LastUpdate : Desember 17, 2008
 @Description :
*/

require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/mutasi_barang/business/AppMutasi.class.php';
require_once GTFWConfiguration::GetValue('application', 'docroot') . 'main/function/date.php';

class ViewExcelMutasiBarang extends XlsResponse {
   var $mWorksheets = array('Data');
   
   function GetFileName() {
      // name it whatever you want
      return 'MutasiBarang.xls';
   }

   function ProcessRequest() {
   	$Obj = new AppMutasiBarang();
		$golBarang = Dispatcher::Instance()->Decrypt($_GET['jenis_kib']);
   	$lokasi = Dispatcher::Instance()->Decrypt($_GET['lokasi']);
   	$unit = Dispatcher::Instance()->Decrypt($_GET['unit_kerja']);
   	$tglAwal = Dispatcher::Instance()->Decrypt($_GET['tanggal_awal_year']).'-'.Dispatcher::Instance()->Decrypt($_GET['tanggal_awal_mon']).'-'.Dispatcher::Instance()->Decrypt($_GET['tanggal_awal_day']);
   	$tglAkhir = Dispatcher::Instance()->Decrypt($_GET['tanggal_akhir_year']).'-'.Dispatcher::Instance()->Decrypt($_GET['tanggal_akhir_mon']).'-'.Dispatcher::Instance()->Decrypt($_GET['tanggal_akhir_day']);
   	$kodeBrg = Dispatcher::Instance()->Decrypt($_GET['aset']);
      
      $arrData = $Obj->GetListMutasi($golBarang,$tglAwal,$tglAkhir,$kodeBrg,$kodeBrg,$unit,$lokasi);
      
      
   
      
      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, 3);
         
         $row+=3;
         $this->mWorksheets['Data']->write($row, 0, 'Mutasi Barang', $h2);
         $this->mWorksheets['Data']->merge_cells($row, 0, $row+1, 3);
         
         //set header
			$row+=2;
         $this->mWorksheets['Data']->write($row, 0, 'NO', $th);
			$this->mWorksheets['Data']->write($row, 1, 'Tanggal Mutasi', $th);
			$this->mWorksheets['Data']->write($row, 2, 'Berita Acara Mutasi', $th);
			$this->mWorksheets['Data']->write($row, 3, 'Unit Asal', $th);
			$this->mWorksheets['Data']->write($row, 4, 'Nama Barang', $th);
			$this->mWorksheets['Data']->write($row, 5, 'Unit Tujuan', $th);
			$this->mWorksheets['Data']->write($row, 6, 'PIC', $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]['tgl'], $tdCenter);
         	$this->mWorksheets['Data']->write($row, 2, $arrData[$i]['berita_acara'], $td);
         	$this->mWorksheets['Data']->write($row, 3, $arrData[$i]['unitAsal'], $td);
         	$this->mWorksheets['Data']->write($row, 4, $arrData[$i]['namaBarang'], $td);
         	$this->mWorksheets['Data']->write($row, 5, $arrData[$i]['unitTujuan'], $td);
         	$this->mWorksheets['Data']->write($row, 6, $arrData[$i]['pic'], $td);
         	$row++;
			}
      }
      
   }
}
?>
