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

class ViewExcelLapMutasiBarang extends XlsxResponse
{
   public $Excel;
   
   public function ProcessRequest()
   {
      $barangObj 		= new LapMutasiBarang();
	  
      $tglAwal 		= $_GET['tglAwal']->Raw();
		$tglAkhir 		= $_GET['tglAkhir']->Raw();
		$unitAsal 		= $_GET['unitAsal']->Raw();
		$unitTuj 		= $_GET['unitTuj']->Raw();
		$kodeBA 			= $_GET['kodeba']->Raw();
			
		$alamat 			= GTFWConfiguration::GetValue('organization', 'city');
		$instansi		= GTFWConfiguration::GetValue('organization', 'company_name');
		$namacetak	 	= $_SESSION['username'];
		$tglcetak		= IndonesianDate(date('Y-m-d'), 'YYYY-MM-DD');
		$judul			= "Laporan Mutasi Barang";
		
		$data				= $barangObj->GetDataMutasi($tglAwal,$tglAkhir,$unitAsal,$unitTuj, $kodeBA);
		
      // set file name
      $filename   = 'laporan_mutasi_barang_'.date('dmY').'.xls';
      $this->SetFileName($filename);
      
      // set sheet
      $sheet      = $this->Excel->getActiveSheet(0);
      
      // set metadata properties data excel
      $metadata   = $this->Excel->getProperties();
      
      // set default font setting for document
      $sheet->getDefaultStyle()->getFont()->setName('Arial')->setSize('10');
      
      // setting paging
      $sheet->getPageSetup()->setOrientation(PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE);
      $sheet->getPageSetup()->setFitToWidth(1);
      $sheet->getPageSetup()->setFitToHeight(0);
      $sheet->getPageSetup()->setHorizontalCentered(true);
      $sheet->getPageSetup()->setVerticalCentered(false);
      
      $metadata->setCreator("anam");
      $metadata->setLastModifiedBy("anam");
      $metadata->setTitle("Laporan Mutasi Barang");
      $metadata->setSubject("Mutasi");
      $metadata->setDescription("Laporan Mutasi Barang printed on ".date('Y-m-d H:i:s', time()));
      $metadata->setKeywords("Mutasi");
      $metadata->setCategory("gtAset");
      
      // set worksheet name
      $sheet->setTitle('mutasi_barang');
      $sheet->setShowGridlines(false);
      
      // generate value
      if(empty($data)){
         $sheet->setCellValue('A1','Data Tidak Ditemukan');
      }else{
      
         // set height n width
         $sheet->getRowDimension('1')->setRowHeight('40');
         $sheet->getRowDimension('5')->setRowHeight('25');
         # $sheet->getRowDimension('13')->setRowHeight('40');
         
         // set coloum
         $sheet->getColumnDimension('A')->setWidth('10');
         $sheet->getColumnDimension('B')->setWidth('15');
         $sheet->getColumnDimension('C')->setWidth('50');
         $sheet->getColumnDimension('D')->setWidth('50');
         $sheet->getColumnDimension('E')->setWidth('30');
         
         // set table header
         $headerStyledArray = array(
         	'font' => array(
               'bold' => true, 
               'size' => '14'
            ), 
            'alignment' => array(
               'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER, 
               'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER
            )
         );
         
         $subHeaderStyledArray   = array(
            'font' => array(
               'bold' => true, 
               'size' => '12'
            ), 
            'alignment' => array(
               'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_LEFT, 
               'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER
            )
         );
            
         $styledTableHeaderArray = array(
            'borders' => array(
               'allborders' => array(
                  'style' => PHPExcel_Style_Border::BORDER_THICK, 
                  'color' => array('argb' => 'ff000000')
               )
            ), 
            'fill' => array(
               'type' => PHPExcel_Style_Fill::FILL_SOLID,  
               'startcolor' => array(
                  'argb' => 'ffcccccc'
               )
            ), 
            'font' => array(
               'bold' => true, 
               'color' => array(
                  'rgb' => '000000'
               )
            ), 
            'alignment' => array(
               'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER, 
               'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER
            )
         );
         
         $tableCellStyledArray   = array(
            'borders' => array(
               'allborders' => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN, 
                  'color' => array('argb' => 'ff000000')
               )
            )
         );
         
         $tableCellAlignCenterStyledArr   = array(
            'alignment' => array(
               'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER
            )
         );
         
         $sheet->getStyle('A5:E5')->applyFromArray($styledTableHeaderArray);
         
         // header excel print
         $sheet->SetCellValue('A1', $instansi);
         $sheet->mergeCells('A1:E1');
         $sheet->getStyle('A1:E1')->applyFromArray($headerStyledArray);
         
         // sub header
         $sheet->SetCellValue('A3', $judul);
         $sheet->mergeCells('A3:C3');
         $sheet->getStyle('A3:C3')->applyFromArray($subHeaderStyledArray);
         
         // set Header Data Table
         $sheet->SetCellValue('A5','Nomor');
         $sheet->SetCellValue('B5','Tanggal');
         $sheet->SetCellValue('C5','Unit Asal');
         $sheet->SetCellValue('D5','Unit Tujuan');
         $sheet->SetCellValue('E5','Berita Acara');
         
         // get select data
         $setFirstColumn   = '6';
         for($i=0;$i<sizeof($data);$i++){
         	$data[$i]['no']		= ($i+1);
         	$sheet->setCellValueByColumnAndRow(0, $setFirstColumn+$i, $data[$i]['no']);
         	$date = date_create($data[$i]['mutasi_tanggal']);
            $sheet->setCellValueByColumnAndRow(1, $setFirstColumn+$i, date_format($date, 'd-m-Y'));
            $sheet->setCellValueByColumnAndRow(2, $setFirstColumn+$i, $data[$i]['mutasi_unit_asal']);
				$sheet->setCellValueByColumnAndRow(3, $setFirstColumn+$i, $data[$i]['mutasi_unit_tujuan']);
            $sheet->setCellValueByColumnAndRow(4, $setFirstColumn+$i, $data[$i]['mutasi_berita_acara']);
			}
			
         // bottom text
         $last_row   = $setFirstColumn+(count($data))-1;
         $sheet->getStyle('A5:E'.$last_row)->applyFromArray($tableCellStyledArray);
         
         $sheet->SetCellValue('D'.($last_row+4), $alamat.', '.$tglcetak);
         $sheet->mergeCells('D'.($last_row+4).':E'.($last_row+4));
         
         $sheet->SetCellValue('D'.($last_row+5), 'Mengetahui,');
         $sheet->mergeCells('D'.($last_row+5).':E'.($last_row+5));         
         
         $sheet->SetCellValue('D'.($last_row+12), '...............................');
         $sheet->mergeCells('D'. ($last_row+12).':E'.($last_row+12));
      }
  
      // save data
      $this->Save();
   }
   
   

}
?>
