<?php
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/laporan_jml_mhs_baru_asal_sekolah/business/AppLaporanJmlMhsBaruAsalSekolah.class.php';
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'main/function/date.php';
class ViewExcelLaporanJmlMhsBaruAsalSekolah extends XlsResponse{
   var $mWorksheets = array('Data');
   
   function GetFileName() {
      // name it whatever you want
      return 'DaftarMahasiswa.xls';
   }
   function ProcessRequest(){
      $lapObj = new AppLaporanJmlMhsBaruAsalSekolah();
      
      $tahunMasuk=$_SESSION['tahunMasuk'];
      $semsMasuk=$_SESSION['semsMasuk'];
      $jenjang=$_SESSION['jenjang'];
      $jalurMasuk=$_SESSION['jalurMasuk'];
      
      if($tahunMasuk=='all'){
         $tahunMasuk='';
      }       
      
      if($semsMasuk=='all'){
         $semsMasuk='';
      }      
      
      if($jenjang=='all'){
         $jenjang='';
      }  
      
      if($jalurMasuk=='all'){
         $jalurMasuk='';
      }   
      
      $dataLaporanJmlMhsBaru = $lapObj->GetRekapMhsBaru($tahunMasuk,$semsMasuk,$jalur,$jenjang);
      
      $dataPeriodeAktif = $lapObj->GetPeriodeAktif();
      if(empty($dataLaporanJmlMhsBaru)){
         $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, 8);
         $this->mWorksheets['Data']->set_column(3, 3, 8);
         $this->mWorksheets['Data']->set_column(4, 5, 8);

      #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 JUMLAH MAHASISWA BARU', $h2);
         $this->mWorksheets['Data']->merge_cells($row, 0, $row, 5);
         $row++;
         $periode=$tahunMasuk;
         $periode2=$tahunMasuk+1;
         
         if ($tahunMasuk == '')
            $thn_lengkap = 'Semua Tahun';
         else
            $thn_lengkap = $periode.'/'.$periode2.' ';
         
         if ($semsMasuk=='')
            $sem_lengkap = 'Semua Semester ';
         else
            $sem_lengkap = $semsMasuk.' ';
         
         $this->mWorksheets['Data']->write($row, 0,'TAHUN AKADEMIK :'. $sem_lengkap.$thn_lengkap, $h3);
         $this->mWorksheets['Data']->merge_cells($row, 0, $row, 5);
         $row++;;
         $this->mWorksheets['Data']->write($row, 0,'(Menurut Asal Sekolah)', $h3);
$row+=1;

      # End Create Header Report

      #Start Create Header Table
         $row+=2;
         $this->mWorksheets['Data']->write($row, 0, 'Program Studi', $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, 'Asal Sekolah', $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, 'Agama', $th);
         $this->mWorksheets['Data']->write($row+1, 3, 'Umum', $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($dataLaporanJmlMhsBaru);$i++){
            if($fakKode!=$dataLaporanJmlMhsBaru[$i]['fak_kode']){
               $dataLaporan[$no]['fak_nama']=strtoupper(''. $dataLaporanJmlMhsBaru[$i]['fak_nama']);
               $no++;
               $j=0;
            }
            $dataProdi[$no-1][$j]['no'] = $j+1;
            $dataProdi[$no-1][$j]['prodi_kode']= $dataLaporanJmlMhsBaru[$i]['prodi_kode'];
            $dataProdi[$no-1][$j]['prodi_nama']= $dataLaporanJmlMhsBaru[$i]['prodi_nama'];
            $dataProdi[$no-1][$j]['jml_skl_agama']= $dataLaporanJmlMhsBaru[$i]['jml_skl_agama'];
            $dataProdi[$no-1][$j]['jml_skl_non_agama']= $dataLaporanJmlMhsBaru[$i]['jml_skl_non_agama'];
            $dataProdi[$no-1][$j]['jml_skl_na']= $dataLaporanJmlMhsBaru[$i]['jml_skl_na'];
            $dataProdi[$no-1][$j]['jml_mhs']= $dataLaporanJmlMhsBaru[$i]['jml_mhs'];
            $dataLaporan[$no-1]['jml_agama']+=$dataLaporanJmlMhsBaru[$i]['jml_skl_agama'];
            $dataLaporan[$no-1]['jml_non_agama']+=$dataLaporanJmlMhsBaru[$i]['jml_skl_non_agama'];
            $dataLaporan[$no-1]['jml_na']+=$dataLaporanJmlMhsBaru[$i]['jml_skl_na'];
            $dataLaporan[$no-1]['jml_tot']+=$dataLaporanJmlMhsBaru[$i]['jml_mhs'];
            $totalAgama+=$dataLaporanJmlMhsBaru[$i]['jml_skl_agama'];
            $totalNonAgama+=$dataLaporanJmlMhsBaru[$i]['jml_skl_non_agama'];
            $totalN_A+=$dataLaporanJmlMhsBaru[$i]['jml_skl_na'];
            $totalMhs+=$dataLaporanJmlMhsBaru[$i]['jml_mhs'];
            $j++;
            $fakKode=$dataLaporanJmlMhsBaru[$i]['fak_kode'];
         }
         $row+=2;
         //print_r($dataLaporan);
         for($i=0;$i<sizeof($dataLaporan);$i++){
            $this->mWorksheets['Data']->write($row, 0, 'Fakultas '.$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]['no'], $td);
               $this->mWorksheets['Data']->write($row, 1, $dataProdi[$i][$j]['prodi_nama'], $td);
               $this->mWorksheets['Data']->write($row, 2, $dataProdi[$i][$j]['jml_skl_agama'], $td);
               $this->mWorksheets['Data']->write($row, 3, $dataProdi[$i][$j]['jml_skl_non_agama'], $td);
               $this->mWorksheets['Data']->write($row, 4, $dataProdi[$i][$j]['jml_skl_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_agama'], $tdBold);
            $this->mWorksheets['Data']->write($row, 3,  $dataLaporan[$i]['jml_non_agama'], $tdBold);
            $this->mWorksheets['Data']->write($row, 4,  $dataLaporan[$i]['jml_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, $totalAgama, $tdBold);
         $this->mWorksheets['Data']->write($row, 3, $totalNonAgama, $tdBold);
         $this->mWorksheets['Data']->write($row, 4, $totalN_A, $tdBold);
         $this->mWorksheets['Data']->write($row, 5, $totalMhs, $tdBold);
      # End Generate Row Data
      }
   }
}