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

class PrintLaporanFormasiCalonMhsBaru extends HtmlResponse{
   function TemplateModule() {
      $this->SetTemplateBasedir($this->mrConfig->mApplication['docroot'].'module/Laporan_formasi_calon_mhs_baru/template');
      $this->SetTemplateFile('print_laporan_formasi_calon_mhs_baru.html');
   }
   
   function TemplateBase() {
      $this->SetTemplateBasedir(GTFWConfiguration::GetValue('application', 'docroot') . 'main/template/');
      $this->SetTemplateFile('document-print.html');
      $this->SetTemplateFile('layout-common-print.html');
   }
   function ProcessRequest(){
      $lapObj= new AppLaporanFormasiCalonMhsBaru();
      
         $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);
      //print_r($dataLaporanJmlMhsBaru);
      $return['dataLaporanJmlMhsBaru'] = $dataLaporanJmlMhsBaru;
      $return['tahunMasuk'] = $tahunMasuk;
      $return['semsMasuk'] = $semsMasuk;
      return $return;
   }
   
   function ParseTemplate($data=NULL){
      $tahunMasuk=$data['tahunMasuk'];
      $semesterMasuk=$data['semsMasuk'];
      $dataLaporanJmlMhsBaru = $data['dataLaporanJmlMhsBaru'];
     // print_r($dataLaporanJmlMhsBaru);
      $periode=$tahunMasuk;
      $periode2=$tahunMasuk+1;
      if($tahunMasuk==''){
         $this->mrTemplate->AddVar('content', 'PERIODE','SEMUA');
      }else{
         $this->mrTemplate->AddVar('content', 'PERIODE',$semesterMasuk.' '.$periode.'/'.$periode2);
      }
      if (empty($dataLaporanJmlMhsBaru)) {
         $this->mrTemplate->AddVar('data_laporan_registrasi', 'LAPORAN_EMPTY', 'YES');
      } else {
         $this->mrTemplate->AddVar('data_laporan_registrasi', 'LAPORAN_EMPTY', 'NO');
         $no=0;
         $fakKode='';
         for($i=0;$i<sizeOf($dataLaporanJmlMhsBaru);$i++){
            if($fakKode!=$dataLaporanJmlMhsBaru[$i]['fak_kode']){
               $dataLaporan[$no]['fak_nama']=$dataLaporanJmlMhsBaru[$i]['fak_nama'];
               $dataLaporan[$no]['no']=$no+1;
               $no++;
             $j=0;
            }
            $dataProdi[$no-1][$j]['prodi_kode']= $dataLaporanJmlMhsBaru[$i]['prodi_kode'];
            $dataProdi[$no-1][$j]['prodi_nama']= $dataLaporanJmlMhsBaru[$i]['prodi_nama'];
            $dataProdi[$no-1][$j]['mhs_lulus_ppa']= $dataLaporanJmlMhsBaru[$i]['lulus_ppa'];
            $dataProdi[$no-1][$j]['mhs_reg_ppa']= $dataLaporanJmlMhsBaru[$i]['reg_ppa'];
            $dataProdi[$no-1][$j]['mhs_lulus_snmptn']= $dataLaporanJmlMhsBaru[$i]['lulus_snmptn'];
            $dataProdi[$no-1][$j]['mhs_reg_snmptn']= $dataLaporanJmlMhsBaru[$i]['reg_snmptn'];
            $dataProdi[$no-1][$j]['mhs_lulus_utl']= $dataLaporanJmlMhsBaru[$i]['lulus_utl'];
            $dataProdi[$no-1][$j]['mhs_reg_utl']= $dataLaporanJmlMhsBaru[$i]['reg_utl'];
            $dataProdi[$no-1][$j]['jml_mhs_baru']= $dataProdi[$no-1][$j]['mhs_lulus_ppa']+
                                                   $dataProdi[$no-1][$j]['mhs_reg_ppa']+
                                                   $dataProdi[$no-1][$j]['mhs_lulus_snmptn']+
                                                   $dataProdi[$no-1][$j]['mhs_reg_snmptn']+
                                                   $dataProdi[$no-1][$j]['mhs_lulus_utl']+
                                                   $dataProdi[$no-1][$j]['mhs_reg_utl'];
                                                   
            $totalLulusPPA+=$dataLaporanJmlMhsBaru[$i]['lulus_ppa'];
            $totalRegPPA+=$dataLaporanJmlMhsBaru[$i]['reg_ppa'];
            $totalLulusSNMPTN+=$dataLaporanJmlMhsBaru[$i]['lulus_snmptn'];
            $totalRegSNMPTN+=$dataLaporanJmlMhsBaru[$i]['reg_snmptn'];
            $totalLulusUTL+=$dataLaporanJmlMhsBaru[$i]['lulus_utl'];
            $totalRegUtl+=$dataLaporanJmlMhsBaru[$i]['reg_utl'];
            $totalMhsBaru+=$dataLaporanJmlMhsBaru[$i]['jml_mhs_baru'];
            $j++;
            $fakKode=$dataLaporanJmlMhsBaru[$i]['fak_kode'];
         }
#
         for($i=0;$i<sizeof($dataLaporan);$i++){
            $this->mrTemplate->clearTemplate('data_prodi_item');
            for($j=0;$j<sizeof($dataProdi[$i]);$j++){
               if ($j % 2 != 0)  $dataProdi[$i][$j]['class_name'] = '';
               else $dataProdi[$i][$j]['class_name'] = 'table-common-even';
               $this->mrTemplate->AddVars('data_prodi_item', $dataProdi[$i][$j], 'P_');
               $this->mrTemplate->parseTemplate('data_prodi_item', 'a');
           }
            $this->mrTemplate->AddVars('data_laporan_registrasi_item', $dataLaporan[$i], '');
            $this->mrTemplate->parseTemplate('data_laporan_registrasi_item', 'a'); 
         }
         $this->mrTemplate->AddVar('content', 'TOTAL_L_PPA',$totalLulusPPA); 
         $this->mrTemplate->AddVar('content', 'TOTAL_R_PPA',$totalRegPPA); 
         $this->mrTemplate->AddVar('content', 'TOTAL_L_SNMPTN',$totalLulusSNMPTN); 
         $this->mrTemplate->AddVar('content', 'TOTAL_R_SNMPTN',$totalRegSNMPTN); 
         $this->mrTemplate->AddVar('content', 'TOTAL_L_UTL',$totalLulusUTL); 
         $this->mrTemplate->AddVar('content', 'TOTAL_R_UTL',$totalRegUtl); 
         $this->mrTemplate->AddVar('content', 'TOTAL_MHS_BARU',$totalLulusPPA+$totalRegPPA+$totalLulusSNMPTN+$totalRegSNMPTN+$totalLulusUTL+$totalLulusUTL); 
        
        }
    }
}
?>