<?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 ViewLaporanRinciHeregistrasi extends HtmlResponse{
	function TemplateModule() {
		$this->SetTemplateBasedir(GTFWConfiguration::GetValue( 'application', 'docroot').'module/laporan_rinci_heregistrasi/template');
		$this->SetTemplateFile('view_laporan_rinci_heregistrasi.html');
	}
   function ProcessRequest() {
		$lapObj = new AppLaporanRinciHeregistrasi();
		
		$msg = Messenger::Instance()->Receive(__FILE__);
		$return['Pesan'] = $msg[0][1];
		$return['css'] = $msg[0][2];
		
      $dataPeriodeAktif = $lapObj->GetPeriodeAktif();
      $dataPeriode = $lapObj->GetDataPeriode();
      $dataJenjangAkademik = $lapObj->GetJenjangAkademik();
      $dataJalurMasuk = $lapObj->GetJalurMasuk();
		
		if($_POST || isset($_GET['cari'])) {
			if((isset($_POST['periode']))or(isset($_POST['jenjang']))or(isset($_POST['jalur']))or(isset($_POST['tanggal']))){
				$periode = $_POST['periode']->Raw();
				$jenjang = $_POST['jenjang']->Raw();
				$jalur = $_POST['jalur']->Raw();
				$tanggal = $_POST['tanggal']->Raw();
			} elseif((isset($_GET['periode']))or(isset($_GET['jenjang']))or(isset($_GET['jalur']))or(isset($_GET['tanggal']))) {
				$periode = Dispatcher::Instance()->Decrypt($_GET['periode']);
				$jenjang = Dispatcher::Instance()->Decrypt($_GET['jenjang']);
				$jalur = Dispatcher::Instance()->Decrypt($_GET['jalur']);
				$tanggal = Dispatcher::Instance()->Decrypt($_GET['tanggal']);
			} else {
				$periode = $dataPeriodeAktif['0']['periode_id'];
				$jenjang = '';
            $jalur = '';
				$tanggal = '';
			}
			$_SESSION['periode'] = $periode;
         $_SESSION['jenjang'] = $jenjang;
         $_SESSION['jalur'] = $jalur;
         $_SESSION['tanggal'] = $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);
      $dataComboTanggal = $lapObj->GetTanggalRinciHeregistrasiByPeriode($periode);
      
      if (isset($periode))
         $periode_selected = $periode;
      else
         $periode_selected = $return['Data']['0']['id'];
      
      if (isset($tanggal))
         $tanggal_selected = $tanggal;
      else
         $tanggal_selected = $return['Data']['0']['id'];

      for($i=0; $i<sizeof($dataComboTanggal); $i++){
         $dataComboTanggal[$i]['name'] = IndonesianDate($dataComboTanggal[$i]['name'],'YYYY-MM-DD');
      }
      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'periode',
         array('periode',$dataPeriode,$periode_selected,'true','onChange="updateComboTanggal();"'), Messenger::CurrentRequest);
      
      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'jenjang',
         array('jenjang',$dataJenjangAkademik,$jenjang,'true',''), Messenger::CurrentRequest);

      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'jalur',
            array('jalur',$dataJalurMasuk,$jalur,'true',''), Messenger::CurrentRequest);

      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'tanggal',
         array('tanggal',$dataComboTanggal,$tanggal_selected,'true',''), Messenger::CurrentRequest);
      
      $return['pesan'] = $msg[0][1];
		$return['css'] = $msg[0][2];
		$return['start'] = $startRec+1;
      
      $return['dataLaporanRinciHeregistrasi'] = $dataLaporanRinciHeregistrasi;
      $return['dataPeriodeAktif'] = $dataPeriodeAktif;
      $return['dataPeriode'] = $dataPeriode;
      $return['dataJenjangAkademik'] = $dataJenjangAkademik;
      $return['dataJalurMasuk'] = $dataJalurMasuk;
      $return['dataComboTanggal'] = $dataComboTanggal;
      
      $return['periode'] = $periode;
      $return['jenjang'] = $jenjang;
      $return['jalur'] = $jalur; 
      $return['tanggal'] = $tanggal;
      
      $return['result_pria'] = $result_pria;
      $return['result_wanita'] = $result_wanita;
      $return['total_pria'] = $total_pria;
      $return['total_wanita'] = $total_wanita;
		return $return;
   }

   function ParseTemplate($data = NULL) {
      $search = $data['search'];
      $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'];
		$dataPeriode = $data['dataPeriode'];
		$dataJenjangAkademik = $data['$dataJenjangAkademik'];
		$dataJalurMasuk = $data['dataJalurMasuk'];
      $dataComboTanggal = $data['dataComboTanggal'];
      
		$this->mrTemplate->AddVar('content', 'URL_SEARCH', 
         Dispatcher::Instance()->GetUrl('laporan_rinci_heregistrasi', 'laporanRinciHeregistrasi', 'view', 'html'));
      $this->mrTemplate->AddVar('content', 'URL_EXCEL', 
         Dispatcher::Instance()->GetUrl('laporan_rinci_heregistrasi', 'ExcelLaporanRinciHeregistrasi', 'view', 'xls')
         .'&periode='.$periode.'&jenjang='.$jenjang.'&jalur='.$jalur.'&tanggal='.$tanggal);
      $this->mrTemplate->AddVar('content', 'URL_PRINT', 
         Dispatcher::Instance()->GetUrl('laporan_rinci_heregistrasi', 'daftarLaporanRinciHeregistrasi', 'print', 'html'));

      if($data['pesan']) {
			$this->mrTemplate->SetAttribute('warning_box', 'visibility', 'visible');
			$this->mrTemplate->AddVar('warning_box', 'ISI_PESAN', $data['pesan']);
			$this->mrTemplate->AddVar('warning_box', 'CLASS_PESAN', $data['css']);
		}
		
		if($tanggal==''){
         $this->mrTemplate->AddVar('tanggal','TANGGAL', 'SEMUA');
      }else{
         $tanggal = IndonesianDate($tanggal,'YYYY-MM-DD');
         $this->mrTemplate->AddVar('tanggal','TANGGAL', $tanggal);
      }
      
      if(!empty($data['dataPeriodeAktif'])){
         $this->mrTemplate->SetAttribute('periode', 'visibility', 'visible');
         $this->mrTemplate->AddVars('periode', $data['dataPeriodeAktif'][0], '');
      }

      if (empty($data['dataLaporanRinciHeregistrasi'])) {
			$this->mrTemplate->AddVar('data_laporan_rinci_heregistrasi', 'LAPORAN_EMPTY', 'YES');
		} else {
			$decPage = Dispatcher::Instance()->Decrypt($_REQUEST['page']);
			$encPage = Dispatcher::Instance()->Encrypt($decPage);
			$this->mrTemplate->AddVar('data_laporan_rinci_heregistrasi', 'LAPORAN_EMPTY', 'NO');
			$dataLaporanRinciHeregistrasi = $data['dataLaporanRinciHeregistrasi'];

         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']+$dataLaporanRinciHeregistrasi[$i]['jml_na'];
			   $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], 'LAPORAN_');
				$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);
   }
}
?>