<?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 PrintDaftarLaporanRinciHeregistrasi extends HtmlResponse{
   function TemplateModule() {
      $this->SetTemplateBasedir($this->mrConfig->mApplication['docroot'].'module/laporan_rinci_heregistrasi/template');
      $this->SetTemplateFile('print_laporan_rinci_heregistrasi.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 AppLaporanRinciHeregistrasi();
      
      $periode = $_SESSION['periode'];
      $jenjang = $_SESSION['jenjang'];
      $jalur = $_SESSION['jalur'];
      $tanggal = $_SESSION['tanggal'];
      #var_dump($tanggal);
      if($periode=='all'){
         $periode='';
      }
      
      if($jenjang=='all'){
         $jenjang='';
      }      
      
      if($jalur=='all'){
         $jalur='';
      }
      
      if($tanggal=='all'){
         $tanggal='';
      }
      /*
      if($tanggal == '') {
         $result_pria = $lapObj->GetRekapRinciHeregistrasi($periode,$jalur,'L','',$jenjang);
         $result_wanita = $lapObj->GetRekapRinciHeregistrasi($periode,$jalur,'P','',$jenjang);
         $total_pria = $lapObj->GetTotalRekapRinciHeregistrasi($periode,$jalur,'L','',$jenjang);
         $total_wanita = $lapObj->GetTotalRekapRinciHeregistrasi($periode,$jalur,'P','',$jenjang);
      } else { 
      	$result_pria = $lapObj->GetRekapRinciHeregistrasi($periode,$jalur,'L',$tanggal,$jenjang);
         $result_wanita = $lapObj->GetRekapRinciHeregistrasi($periode,$jalur,'P',$tanggal,$jenjang);
         $total_pria = $lapObj->GetTotalRekapRinciHeregistrasi($periode,$jalur,'L',$tanggal,$jenjang);
         $total_wanita = $lapObj->GetTotalRekapRinciHeregistrasi($periode,$jalur,'P',$tanggal,$jenjang);
      }*/
      
      $dataLaporanRinciHeregistrasi = $lapObj->GetDataRekapRinciHeregistrasi($periode,$jalur,$jk,$tanggal,$jenjang);
      $dataPeriodeAktif = $lapObj->GetPeriodeAktif();
      $namaPeriode = $lapObj->GetNamaPeriode($periode);
      $namaJenjang = $lapObj->GetNamaJenjang($jenjang);
      $namaJalur = $lapObj->GetNamaJalur($jalur);

      $return['dataLaporanRinciHeregistrasi'] = $dataLaporanRinciHeregistrasi;
      $return['dataPeriodeAktif'] = $dataPeriodeAktif;
      $return['namaPeriode'] = $namaPeriode; 
      $return['namaJenjang'] = $namaJenjang;
      $return['namaJalur'] = $namaJalur;
      
      $return['result_pria'] = $result_pria;
      $return['result_wanita'] = $result_wanita;
      $return['total_pria'] = $total_pria;
      $return['total_wanita'] = $total_wanita;
      
      $return['periode'] = $periode;
      $return['jenjang'] = $jenjang;
      $return['jalur'] = $jalur;
      $return['tanggal'] = $tanggal;
      return $return;
   }
   
   function ParseTemplate($data=NULL){
      $periode = $data['periode'];
      $jenjang = $data['jenjang'];
      $jalur = $data['jalur'];
      $tanggal = $data['tanggal'];
      
      $result_pria = $data['result_pria'];
      $result_wanita = $data['result_wanita'];
      $total_pria = $data['total_pria'];
      $total_wanita = $data['total_wanita'];

      $dataLaporanRinciHeregistrasi = $data['dataLaporanRinciHeregistrasi'];
      $dataPeriodeAktif = $data['dataPeriodeAktif'];
      $namaPeriode = $data['namaPeriode'];
      $namaJenjang = $data['namaJenjang'];
      $namaJalur = $data['namaJalur'];
      
      if(!empty($data['dataPeriodeAktif'])){
         $this->mrTemplate->SetAttribute('periode', 'visibility', 'visible');
         $this->mrTemplate->AddVars('periode', $data['dataPeriodeAktif'][0], '');
      }
      
      if($periode==''){
         $this->mrTemplate->AddVar('header', 'PERIODE', 'Semua');   
      }else{
         $this->mrTemplate->AddVars('header', $namaPeriode[0], '');
      }
     
      if($jenjang==''){
         $this->mrTemplate->AddVar('header', 'JENJANG', 'Semua');   
      }else{
         $this->mrTemplate->AddVars('header', $namaJenjang[0], '');
      }
      
      if($jalur==''){
         $this->mrTemplate->AddVar('header', 'JALUR', 'Semua');   
      }else{
         $this->mrTemplate->AddVars('header', $namaJalur[0], '');
      }
      
      if($tanggal==''){
         $this->mrTemplate->AddVar('header','TANGGAL', 'Semua');
      }else{
         $tanggal = IndonesianDate($tanggal,"YYYY-MM-DD");
         $this->mrTemplate->AddVar('header','TANGGAL', $tanggal);
      }
      
      if(empty($dataLaporanRinciHeregistrasi)){
         $this->mrTemplate->AddVar('data','DATA_EMPTY','YES');
         return;
      }else{
   		$this->mrTemplate->AddVar('data','DATA_EMPTY','NO');
         $no=1;
         for ($i=0; $i<sizeof($dataLaporanRinciHeregistrasi); $i++) {
				$no = $i+$data['start'];
				$dataLaporanRinciHeregistrasi[$i]['number'] = $no;
				if ($no % 2 != 0) $dataLaporanRinciRegistrasi[$i]['class_name'] = 'table-common-even';
				else $dataLaporanRinciHeregistrasi[$i]['class_name'] = '';
				
				$idEnc = Dispatcher::Instance()->Encrypt($dataLaporanRinciHeregistrasi[$i]['id']);
            
            //menampilkan jumlah jenis kelamin pada tiap prodi
            $dataLaporanRinciHeregistrasi[$i]['total_bayar'] = number_format($dataLaporanRinciHeregistrasi[$i]['total_bayar'], 2, ',', '.');
            /*$this->mrTemplate->AddVar('result','PRODI_JML_L',$result_pria[$i]['jml_jk']);
            $this->mrTemplate->AddVar('result','PRODI_JML_P',$result_wanita[$i]['jml_jk']);
            $this->mrTemplate->AddVar('result','PRODI_JML',$result_pria[$i]['jml_jk'] + $result_wanita[$i]['jml_jk']);
            */
            $dataLaporanRinciHeregistrasi[$i]['jml']=$dataLaporanRinciHeregistrasi[$i]['jml_lk']+$dataLaporanRinciHeregistrasi[$i]['jml_pr'];
			   $total_pria+=$dataLaporanRinciHeregistrasi[$i]['jml_lk'];
			   $total_wanita+=$dataLaporanRinciHeregistrasi[$i]['jml_pr'];
			   $total_na+=$dataLaporanRinciHeregistrasi[$i]['jml_na'];
			   
				if($i == 0) $this->mrTemplate->AddVar('content', 'FIRST_NUMBER', $no);				
				if($i == sizeof($dataLaporanRinciHeregistrasi)-1) $this->mrTemplate->AddVar('content', 'LAST_NUMBER', $no);
				$this->mrTemplate->AddVars('data_laporan_rinci_heregistrasi_item', $dataLaporanRinciHeregistrasi[$i], 'LAP_');
				$this->mrTemplate->parseTemplate('data_laporan_rinci_heregistrasi_item', 'a');	 
         }
      }
      //menampilkan total mhs
      $total = $total_pria + $total_wanita + $total_na;
      $total_bayar = number_format($total, 2, ',', '.');
      
      $this->mrTemplate->AddVar('total','JML_ALL_L',$total_pria);
      $this->mrTemplate->AddVar('total','JML_ALL_P',$total_wanita);
      $this->mrTemplate->AddVar('total','JML_ALL_NA',$total_na);
      $this->mrTemplate->AddVar('total','JML_ALL',$total_pria + $total_wanita + $total_na);
      $this->mrTemplate->AddVar('total','JML_TOTAL',$total_bayar);
   }
}
?>