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

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

   function ProcessRequest() {
   	$Obj = new AppLaporanMahasiswa();
   	$periode = Dispatcher::Instance()->Decrypt($_GET['periode']);
      $jenjang = Dispatcher::Instance()->Decrypt($_GET['jenjang']);
      $jalur = Dispatcher::Instance()->Decrypt($_GET['jalur']);
      $prodi = Dispatcher::Instance()->Decrypt($_GET['prodi']);
      $status_reg = Dispatcher::Instance()->Decrypt($_GET['status_reg']);
      
      if ($status_reg == 'B')
         $status_reg = 'Belum';
      if ($status_reg == 'S')
         $status_reg = 'Sudah';
      
      $arrData = $Obj->GetExcelDataMahasiswa($periode,$jenjang,$jalur,$prodi,$status_reg);
      $dataPeriodeAktif = $Obj->GetPeriodeAktif();
      $namaPeriode = $Obj->GetNamaPeriode($periode);
      $namaJenjang = $Obj->GetNamaJenjang($jenjang);
      $namaJalur = $Obj->GetNamaJalur($jalur);
      $namaProdi = $Obj->GetNamaProdi($prodi);
      #print_r($jalur);

      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($prodi==''){
            $prodi = 'Semua';
         }else{
            $prodi = $namaProdi[0]['PRODI'];
         }
         
         
         #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 DAFTAR MAHASISWA', $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, 'Tahun 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, 'Program Studi', '');
         $this->mWorksheets['Data']->merge_cells($row, 0, $row, 1);
         $this->mWorksheets['Data']->write($row, 2, ': '.$prodi, '');
         $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']->write($row, 1, 'Nim', $th);
			$this->mWorksheets['Data']->write($row, 2, 'Nama Mahasiswa', $th);
			$this->mWorksheets['Data']->write($row, 3, 'Program Studi', $th);
			$this->mWorksheets['Data']->write($row, 4, 'Periode Masuk', $th);
			$this->mWorksheets['Data']->write($row, 5, 'L/P', $th);
			//$this->mWorksheets['Data']->write($row, 6, 'Total Bayar', $th);
			$this->mWorksheets['Data']->write($row, 6, 'Status Reg.', $th);
			$row++;

         for($i=0;$i<count($arrData);$i++){
            $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]['nim'], $tdCenter);
         	$this->mWorksheets['Data']->write($row, 2, $arrData[$i]['nama'], $td);
         	$this->mWorksheets['Data']->write($row, 3, $arrData[$i]['prodi'], $td);
         	$this->mWorksheets['Data']->write($row, 4, $arrData[$i]['tahun_masuk'], $tdCenter);
         	$this->mWorksheets['Data']->write($row, 5, $arrData[$i]['jenis_kelamin'], $tdCenter);
         	//$this->mWorksheets['Data']->write($row, 6, $arrData[$i]['total_bayar'], $tdRight);
         	$this->mWorksheets['Data']->write($row, 6, $arrData[$i]['status'], $tdCenter);
         	$row++;
			}
			
			$row+=3;
			$this->mWorksheets['Data']->write($row, 4, GTFWConfiguration::GetValue('organization', 'company_city').', '.IndonesianDate(date('d-m-Y'),'DD-MM-YYYY'), $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);
      }
      
   }
}
?>
