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

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

   function ProcessRequest() {
   	$Obj = new AppLaporanRinciHeregistrasi();
   	$periode = Dispatcher::Instance()->Decrypt($_GET['periode']);
      $jenjang = Dispatcher::Instance()->Decrypt($_GET['jenjang']);
      $jalur = Dispatcher::Instance()->Decrypt($_GET['jalur']);
      $tanggal = Dispatcher::Instance()->Decrypt($_GET['tanggal']);
      #var_dump($jenjang);var_dump($jalur);var_dump($tanggal);
      
      $arrData = $Obj->GetDataRekapRinciHeregistrasi($periode,$jalur,$jk,$tanggal,$jenjang);
      $dataPeriodeAktif = $Obj->GetPeriodeAktif();
      $namaPeriode = $Obj->GetNamaPeriode($periode);
      $namaJenjang = $Obj->GetNamaJenjang($jenjang);
      $namaJalur = $Obj->GetNamaJalur($jalur);
      $namaTanggal = $Obj->GetNamaTanggal($tanggal);
      #print_r($arrData);
      /*
      if($tanggal=='') {
         $arrDataPria = $Obj->GetRekapRinciHeregistrasi($periode,$jalur,'L','',$jenjang);
         $arrDataWanita = $Obj->GetRekapRinciHeregistrasi($periode,$jalur,'P','',$jenjang);
         $arrDataTotalPria = $Obj->GetTotalRekapRinciHeregistrasi($periode,$jalur,'L','',$jenjang);
         $arrDataTotalWanita = $Obj->GetTotalRekapRinciHeregistrasi($periode,$jalur,'P','',$jenjang);
         #print_r($arrDataPria);
      } else { 
      	$arrDataPria = $Obj->GetRekapRinciHeregistrasi($periode,$jalur,'L',$tanggal,$jenjang);
         $arrDataWanita = $Obj->GetRekapRinciHeregistrasi($periode,$jalur,'P',$tanggal,$jenjang);
         $arrDataTotalPria = $Obj->GetTotalRekapRinciHeregistrasi($periode,$jalur,'L',$tanggal,$jenjang);
         $arrDataTotalWanita = $Obj->GetTotalRekapRinciHeregistrasi($periode,$jalur,'P',$tanggal,$jenjang);
         #print_r($arrDataWanita);
      }*/
      
      
      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');
         
         $h3 = $this->mrWorkbook->add_format();
         $h3->set_bold();
         $h3->set_size(11);
         $h3->set_align('center');
         $h3->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');

         if($periode==''){
            $periode = 'Semua';
         }else{
            $periode = $namaPeriode[0]['PERIODE'];
         }
         
         if($jenjang==''){
            $jenjang = 'Semua';
         }else{
            $jenjang = $namaJenjang[0]['JENJANG'];
         }
         
         if($jalur==''){
            $jalur = 'Semua';
         }else{
            $jalur = $namaJalur[0]['JALUR'];
         }
         
         if($tanggal==''){
            $tanggal = 'Semua';
         }else{
            $tanggal = IndonesianDate($namaTanggal[0]['TANGGAL'],'YYYY-MM-DD');
         }
         
         #set header
         $row = 0;
         $this->mWorksheets['Data']->write($row, 0, GTFWConfiguration::GetValue('organization', 'company_name'), $h1);
         $this->mWorksheets['Data']->merge_cells($row, 0, 1, 7);
         
         $row+=3;
         $this->mWorksheets['Data']->write($row, 0, 'LAPORAN REKAP RINCI HEREGISTRASI', $h2);
         $this->mWorksheets['Data']->merge_cells($row, 0, $row, 7);
         $row++;
         
         $this->mWorksheets['Data']->write($row, 0, $dataPeriodeAktif[0]['PERIODE'], $h3);
         $this->mWorksheets['Data']->merge_cells($row, 0, $row, 7);
         $row++;
         
         $row+=1;
         $this->mWorksheets['Data']->write($row, 0, 'Periode Masuk', '');
         $this->mWorksheets['Data']->merge_cells($row, 0, $row, 1);
         $this->mWorksheets['Data']->write($row, 2, ': '.$periode, '');
         $this->mWorksheets['Data']->merge_cells($row, 2, $row, 7);
         $row++;
         
         $this->mWorksheets['Data']->write($row, 0, 'Jenjang Akademik', '');
         $this->mWorksheets['Data']->merge_cells($row, 0, $row, 1);
         $this->mWorksheets['Data']->write($row, 2, ': '.$jenjang, '');
         $this->mWorksheets['Data']->merge_cells($row, 2, $row, 7);
         $row++;
         
         $this->mWorksheets['Data']->write($row, 0, 'Jalur Masuk', '');
         $this->mWorksheets['Data']->merge_cells($row, 0, $row, 1);
         $this->mWorksheets['Data']->write($row, 2, ': '.$jalur, '');
         $this->mWorksheets['Data']->merge_cells($row, 2, $row, 7);
         $row++;
         
         $this->mWorksheets['Data']->write($row, 0, 'Tanggal Registrasi', '');
         $this->mWorksheets['Data']->merge_cells($row, 0, $row, 1);
         $this->mWorksheets['Data']->write($row, 2, ': '.$tanggal, '');
         $this->mWorksheets['Data']->merge_cells($row, 2, $row, 7);
         $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, 'Program Studi', $th);
			$this->mWorksheets['Data']->merge_cells($row, 1, $row+1, 3);
			$this->mWorksheets['Data']->write($row, 4, 'Mahasiswa', $th);
			$this->mWorksheets['Data']->merge_cells($row, 4, $row, 7);
			//$this->mWorksheets['Data']->write($row, 7, 'Total Bayar', $th);
			//$this->mWorksheets['Data']->merge_cells($row, 7, $row+1, 7);
         
         $row++;
         $this->mWorksheets['Data']->write($row, 4, 'L', $th);
			$this->mWorksheets['Data']->write($row, 5, 'P', $th);
			$this->mWorksheets['Data']->write($row, 6, 'N/A', $th);
			$this->mWorksheets['Data']->write($row, 7, 'JML', $th);
			$row++;
			
         for($i=0;$i<count($arrData);$i++){
            #$jml = $arrDataPria[$i]['JML_MHS'] + $arrDataWanita[$i]['JML_JK'];
            //$arrData[$i]['total_bayar'] = number_format($arrData[$i]['total_bayar'],2,',','.');
         	$this->mWorksheets['Data']->write($row, 0, $i+1, $tdCenter);
         	$this->mWorksheets['Data']->write($row, 1, $arrData[$i]['prodi'], $td);
         	$this->mWorksheets['Data']->merge_cells($row, 1, $row, 3);
         	$this->mWorksheets['Data']->write($row, 4, $arrData[$i]['jml_lk'], $tdCenter);
         	$this->mWorksheets['Data']->write($row, 5, $arrData[$i]['jml_pr'], $tdCenter);
         	$this->mWorksheets['Data']->write($row, 6, $arrData[$i]['jml_na'], $tdCenter);
         	$this->mWorksheets['Data']->write($row, 7, $arrData[$i]['jml_lk']+$arrData[$i]['jml_pr']+$arrData[$i]['jml_na'], $tdCenter);
         	//$this->mWorksheets['Data']->write($row, 7, $arrData[$i]['total_bayar'], $tdRight);
            $total_pria+=$arrData[$i]['jml_lk'];
            $total_wanita+=$arrData[$i]['jml_pr'];
            $total_na+=$arrData[$i]['jml_na'];
         	$row++;
			}
         $total_mhs = $total_pria+ $total_wanita;
         //$total = $arrData[0]['total_bayar'] + $arrData[0]['total_bayar'];
         //$total_bayar = number_format($total, 2, ',', '.');

			$this->mWorksheets['Data']->write($row, 0, 'TOTAL', $tdCenter);
         $this->mWorksheets['Data']->merge_cells($row, 0, $row, 3);
         $this->mWorksheets['Data']->write($row, 4, $total_pria, $tdCenter);
      	$this->mWorksheets['Data']->write($row, 5, $total_wanita, $tdCenter);
      	$this->mWorksheets['Data']->write($row, 6, $total_na, $tdCenter);
      	$this->mWorksheets['Data']->write($row, 7, $total_mhs, $tdCenter);
      	//$this->mWorksheets['Data']->write($row, 7, $total_bayar, $tdRight);
         $row++;
			
			$row+=3;
			$this->mWorksheets['Data']->write($row, 4, 'Yogyakarta, '.date('d-F-Y'), $sign);
			//$this->mWorksheets['Data']->merge_cells($row, 5, $row, 7);
			$row+=1;
			
			$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', $sign);
			//$this->mWorksheets['Data']->merge_cells($row, 5, $row, 7);
			$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, 5, $row, 7);
			$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, 5, $row, 7);
      }
      
   }
}
?>
