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

class PrintDaftarLaporanHeregistrasi extends HtmlResponse{
   function TemplateModule() {
      $this->SetTemplateBasedir($this->mrConfig->mApplication['docroot'].'module/laporan_heregistrasi/template');
      $this->SetTemplateFile('print_laporan_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 AppLaporanHeregistrasi();
      
      $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->GetRekapHeregistrasi($periode,$jalur,'L','',$jenjang);
         $result_wanita = $lapObj->GetRekapHeregistrasi($periode,$jalur,'P','',$jenjang);
         $total_pria = $lapObj->GetTotalRekapHeregistrasi($periode,$jalur,'L','',$jenjang);
         $total_wanita = $lapObj->GetTotalRekapHeregistrasi($periode,$jalur,'P','',$jenjang);
      } else { 
      	$result_pria = $lapObj->GetRekapHeregistrasi($periode,$jalur,'L',$tanggal,$jenjang);
         $result_wanita = $lapObj->GetRekapHeregistrasi($periode,$jalur,'P',$tanggal,$jenjang);
         $total_pria = $lapObj->GetTotalRekapHeregistrasi($periode,$jalur,'L',$tanggal,$jenjang);
         $total_wanita = $lapObj->GetTotalRekapHeregistrasi($periode,$jalur,'P',$tanggal,$jenjang);
      }*/
      
      $dataLaporanHeregistrasi = $lapObj->GetDataRekapHeregistrasi($periode,$jalur,$jk,$tanggal,$jenjang);
      $dataPeriodeAktif = $lapObj->GetPeriodeAktif();
      $namaPeriode = $lapObj->GetNamaPeriode($periode);
      $namaJenjang = $lapObj->GetNamaJenjang($jenjang);
      $namaJalur = $lapObj->GetNamaJalur($jalur);

      $return['dataLaporanHeregistrasi'] = $dataLaporanHeregistrasi;
      $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'];

      $dataLaporanHeregistrasi = $data['dataLaporanHeregistrasi'];
      $dataPeriodeAktif = $data['dataPeriodeAktif'];
      $namaPeriode = $data['namaPeriode'];
      $namaJenjang = $data['namaJenjang'];
      $namaJalur = $data['namaJalur'];
      
      #print_r($namaPeriode);
      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($dataLaporanHeregistrasi)){
         $this->mrTemplate->AddVar('data','DATA_EMPTY','YES');
         return;
      }else
   		$this->mrTemplate->AddVar('data','DATA_EMPTY','NO');
         $no=1;
         $total_pria=0;
         $total_wanita=0;
         $total_na=0;
         for ($i=0; $i<sizeof($dataLaporanHeregistrasi); $i++) {
				$no = $i+$data['start'];
				$dataLaporanHeregistrasi[$i]['number'] = $no;
				if ($no % 2 != 0) $dataLaporanRegistrasi[$i]['class_name'] = 'table-common-even';
				else $dataLaporanHeregistrasi[$i]['class_name'] = '';
				
				$idEnc = Dispatcher::Instance()->Encrypt($dataLaporanHeregistrasi[$i]['id']);
            
            //menampilkan jumlah jenis kelamin pada tiap prodi
            /*$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']);
*/          $dataLaporanHeregistrasi[$i]['jml']=$dataLaporanHeregistrasi[$i]['jml_lk']+$dataLaporanHeregistrasi[$i]['jml_pr']+$dataLaporanHeregistrasi[$i]['jml_na'];
			  #print_r($dataLaporanHeregistrasi);
            $total_pria+=$dataLaporanHeregistrasi[$i]['jml_lk'];
			   $total_wanita+=$dataLaporanHeregistrasi[$i]['jml_pr'];
			   $total_na+=$dataLaporanHeregistrasi[$i]['jml_na'];
				if($i == 0) $this->mrTemplate->AddVar('content', 'FIRST_NUMBER', $no);				
				if($i == sizeof($dataLaporanHeregistrasi)-1) $this->mrTemplate->AddVar('content', 'LAST_NUMBER', $no);
				$this->mrTemplate->AddVars('data_item', $dataLaporanHeregistrasi[$i], 'LAP_');
				$this->mrTemplate->parseTemplate('data_item', 'a');	 
         }
      //menampilkan total mhs
      $this->mrTemplate->AddVar('total','LAP_ALL_L',$total_pria);
      $this->mrTemplate->AddVar('total','LAP_ALL_P',$total_wanita);
      $this->mrTemplate->AddVar('total','LAP_ALL_NA',$total_na);
      $this->mrTemplate->AddVar('total','LAP_ALL',$total_pria+ $total_wanita + $total_na);
   }
}
?>