<?php
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/laporan_registrasi_mhs_baru/business/AppLaporanRegistrasMhsBaru.class.php';
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'main/function/date.php';
class ViewExcelLaporanRegistrasiMhsBaru extends XlsResponse{
   var $mWorksheets = array('Data');
   
   function GetFileName() {
      // name it whatever you want
      return 'DaftarMahasiswa.xls';
   }
   function ProcessRequest(){
      $lapObj = new AppLaporanRegistrasMhsBaru();
      
      $periode= $_SESSION['periode'];
      $jenjang= $_SESSION['jenjang'];
      $jalur=$_SESSION['jalur'];
      $tanggal=$_SESSION['tanggal'];
      if($periode=='all'){
         $periode='';
      }  
      if($jenjang=='all'){
         $jenjang='';
      }
      if($jalur=='all'){
         $jalur='';
      }
      
      if($tanggal=='all'){
         $tanggal='';
      }
      $dataLaporanRegistrasi = $lapObj->GetRekapMhsBaru($periode,$jalur,$tanggal,$jenjang);
      $dataPeriodeAktif = $lapObj->GetPeriodeAktif();
      if(empty($dataLaporanRegistrasi)){
         $this->mWorksheets['Data']->write(0, 0, 'Tidak Ada Data');
      }else{
      # Start Formating WorkBook
         $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('left');
         $h2->set_align('vcenter');
         $h2->set_text_wrap();
         
         $h3 = $this->mrWorkbook->add_format();
         $h3->set_bold();
         $h3->set_size(11);
         $h3->set_align('left');
         $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');         
         $td->set_text_wrap();         
         
         $tdBold = $this->mrWorkbook->add_format();
         $tdBold->set_border(1);
         $tdBold->set_size(10);         
         $tdBold->set_align('left');         
         $tdBold->set_text_wrap();
         $tdBold->set_bold();
         
         $tdTop = $this->mrWorkbook->add_format();
         $tdTop->set_left(1);
         $tdTop->set_right(1);
         $tdTop->set_top(1);
         $tdTop->set_size(10);         
         $tdTop->set_align('left');
         $tdTop->set_text_wrap();
         
         $tdMid = $this->mrWorkbook->add_format();
         $tdMid->set_left(1);
         $tdMid->set_right(1);
         $tdMid->set_size(10);         
         $tdMid->set_align('left'); 
         
         $tdCenter = $this->mrWorkbook->add_format();
         $tdCenter->set_border(1);
         $tdCenter->set_size(10);         
         $tdCenter->set_align('center');         
         
         $tdMidCenter = $this->mrWorkbook->add_format();
         $tdMidCenter->set_left(1);
         $tdMidCenter->set_right(1);
         $tdMidCenter->set_size(10);         
         $tdMidCenter->set_align('center');         
         $tdMidCenter->set_text_wrap();  
         
         $tdBtmCenter = $this->mrWorkbook->add_format();
         $tdBtmCenter->set_left(1);
         $tdBtmCenter->set_right(1);
         $tdBtmCenter->set_bottom(1);
         $tdBtmCenter->set_size(10);         
         $tdBtmCenter->set_align('center'); 
         $tdBtmCenter->set_text_wrap();
         
         $tdTopCenter = $this->mrWorkbook->add_format();
         $tdTopCenter->set_left(1);
         $tdTopCenter->set_right(1);
         $tdTopCenter->set_top(1);
         $tdTopCenter->set_size(10);         
         $tdTopCenter->set_align('center');
         $tdTopCenter->set_text_wrap();
                 
         
         $tdRight = $this->mrWorkbook->add_format();
         $tdRight->set_border(0);
         $tdRight->set_size(10);         
         $tdRight->set_align('right');
         $tdRight->set_text_wrap();
         
         $tdValueMid = $this->mrWorkbook->add_format();
         $tdValueMid->set_left(1);
         $tdValueMid->set_right(1);
         $tdValueMid->set_size(7);         
         $tdValueMid->set_align('center');   
         
         $tdValueBtm = $this->mrWorkbook->add_format();
         $tdValueBtm->set_left(1);
         $tdValueBtm->set_right(1);
         $tdValueBtm->set_bottom(1);
         $tdValueBtm->set_size(7);         
         $tdValueBtm->set_align('center');  
         

            
         $this->mWorksheets['Data']->set_column(0, 0, 10);
         $this->mWorksheets['Data']->set_column(1, 1, 50);
         $this->mWorksheets['Data']->set_column(2, 2, 4);
         $this->mWorksheets['Data']->set_column(3, 3, 4);
         $this->mWorksheets['Data']->set_column(4, 5, 4);

      #End Formating WorkBook
      
      #Start Create Header Report
         $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, 'REKAPITULASI REGISTRASI MAHASISWA BARU ', $h2);
         $this->mWorksheets['Data']->merge_cells($row, 0, $row, 5);
         $row++;
         $this->mWorksheets['Data']->write($row, 0, 'MELALUI PPA, UJIAN TULIS DAN SNMPTN', $h2);
         $this->mWorksheets['Data']->merge_cells($row, 0, $row, 5);
         $row++;
         $periode=substr($periode,0,4);
         $periode2=$periode+1;
         $this->mWorksheets['Data']->write($row, 0,'TAHUN AKADEMIK :'.$periode .'/ '.$periode2 , $h3);
         $this->mWorksheets['Data']->merge_cells($row, 0, $row, 5);
         $row+=2;
    

      # End Create Header Report
         $tanggalInd =IndonesianDate($tanggal,'YYYY-MM-DD');
         $tanggal =empty($tanggalInd)?'Semua':$tanggalInd;
         $this->mWorksheets['Data']->write($row, 0,'Tanggal, '.$tanggal , $tdRight);
         $this->mWorksheets['Data']->merge_cells($row, 0, $row, 4);
      #Start Create Header Table
         $row+=2;
         $this->mWorksheets['Data']->write($row, 0, 'Fakultas/Jurusan/Prodi', $th);
         $this->mWorksheets['Data']->write($row, 1, '', $th);
         $this->mWorksheets['Data']->write($row+1, 0, '', $th);
         $this->mWorksheets['Data']->write($row+1, 1, '', $th);
         $this->mWorksheets['Data']->merge_cells($row, 0, $row+1, 1);

         $this->mWorksheets['Data']->write($row, 2, 'Jumlah', $th);
         $this->mWorksheets['Data']->write($row, 3, '', $th);
         $this->mWorksheets['Data']->write($row, 4, '', $th);
         $this->mWorksheets['Data']->write($row, 5, '', $th);
         $this->mWorksheets['Data']->merge_cells($row, 2, $row, 5);
         
         $this->mWorksheets['Data']->write($row+1, 2, 'L', $th);
         $this->mWorksheets['Data']->write($row+1, 3, 'P', $th);
         $this->mWorksheets['Data']->write($row+1, 4, 'N/A', $th);
         $this->mWorksheets['Data']->write($row+1, 5, 'Jml', $th);

         
      # End Create Header Table
      # Start Generate Row Data
         $no=0;
         $fakKode='';
         for($i=0;$i<sizeOf($dataLaporanRegistrasi);$i++){
            if($fakKode!=$dataLaporanRegistrasi[$i]['fak_kode']){
               $dataLaporan[$no]['fak_nama']=$dataLaporanRegistrasi[$i]['fak_nama'];
               $no++;
             $j=0;
            }
            $dataProdi[$no-1][$j]['prodi_kode']= $dataLaporanRegistrasi[$i]['prodi_kode'];
            $dataProdi[$no-1][$j]['prodi_nama']= $dataLaporanRegistrasi[$i]['prodi_nama'];
            $dataProdi[$no-1][$j]['jml_jk_lk']= $dataLaporanRegistrasi[$i]['jml_lk'];
            $dataProdi[$no-1][$j]['jml_jk_pr']= $dataLaporanRegistrasi[$i]['jml_pr'];
            $dataProdi[$no-1][$j]['jml_jk_na']= $dataLaporanRegistrasi[$i]['jml_na'];
            $dataProdi[$no-1][$j]['jml_mhs']=($dataLaporanRegistrasi[$i]['jml_lk']+$dataLaporanRegistrasi[$i]['jml_pr']+$dataLaporanRegistrasi[$i]['jml_na']);
            $dataLaporan[$no-1]['jml_lk']+=$dataLaporanRegistrasi[$i]['jml_lk'];
            $dataLaporan[$no-1]['jml_pr']+=$dataLaporanRegistrasi[$i]['jml_pr'];
            $dataLaporan[$no-1]['jml_na']+=$dataLaporanRegistrasi[$i]['jml_na'];
            $dataLaporan[$no-1]['jml_tot']+=$dataProdi[$no-1][$j]['jml_mhs'];
            $totalPr+=$dataLaporanRegistrasi[$i]['jml_pr'];
            $totalLk+=$dataLaporanRegistrasi[$i]['jml_lk'];
            $totalNA+=$dataLaporanRegistrasi[$i]['jml_na'];

            $j++;
            $fakKode=$dataLaporanRegistrasi[$i]['fak_kode'];
         }

         $row+=2;
         //print_r($dataLaporan);
         for($i=0;$i<sizeof($dataLaporan);$i++){
            $this->mWorksheets['Data']->write($row, 0, $dataLaporan[$i]['fak_nama'], $tdBold);
            $this->mWorksheets['Data']->write($row, 1, '', $td);
            $this->mWorksheets['Data']->write($row, 2, '', $td);
            $this->mWorksheets['Data']->write($row, 3, '', $td);
            $this->mWorksheets['Data']->write($row, 4, '', $td);
            $this->mWorksheets['Data']->merge_cells($row, 0, $row, 4);
            $row++;
            for($j=0;$j<sizeof($dataProdi[$i]);$j++){
               $this->mWorksheets['Data']->write($row, 0, $dataProdi[$i][$j]['prodi_kode'], $td);
               $this->mWorksheets['Data']->write($row, 1, $dataProdi[$i][$j]['prodi_nama'], $td);
               $this->mWorksheets['Data']->write($row, 2, $dataProdi[$i][$j]['jml_jk_lk'], $td);
               $this->mWorksheets['Data']->write($row, 3, $dataProdi[$i][$j]['jml_jk_pr'], $td);
               $this->mWorksheets['Data']->write($row, 4, $dataProdi[$i][$j]['jml_jk_na'], $td);
               $this->mWorksheets['Data']->write($row, 5, $dataProdi[$i][$j]['jml_mhs'], $td);
               $row++;
           }
            $this->mWorksheets['Data']->write($row, 0, 'JUMLAH', $tdBold);
            $this->mWorksheets['Data']->merge_cells($row, 0, $row, 1);
            $this->mWorksheets['Data']->write($row, 1, '', $tdBold);
            $this->mWorksheets['Data']->write($row, 2,  $dataLaporan[$i]['jml_jk_lk'], $tdBold);
            $this->mWorksheets['Data']->write($row, 3,  $dataLaporan[$i]['jml_jk_pr'], $tdBold);
            $this->mWorksheets['Data']->write($row, 4,  $dataLaporan[$i]['jml_jk_na'], $tdBold);
            $this->mWorksheets['Data']->write($row, 5,  $dataLaporan[$i]['jml_tot'], $tdBold);
            $row++;
         }
         $this->mWorksheets['Data']->write($row, 0, 'JUMLAH SELURUHNYA', $tdBold);
         $this->mWorksheets['Data']->merge_cells($row, 0, $row, 1);
         $this->mWorksheets['Data']->write($row, 1, '', $tdBold);
         $this->mWorksheets['Data']->write($row, 2, $totalPr, $tdBold);
         $this->mWorksheets['Data']->write($row, 3, $totalLk, $tdBold);
         $this->mWorksheets['Data']->write($row, 4, $totalNA, $tdBold);
         $this->mWorksheets['Data']->write($row, 5, $totalPr+$totalLk+$totalNA, $tdBold);
      # End Generate Row Data
      }
   }
}