<?php
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/jenis_pembayaran/business/AppJenisPembayaran.class.php';


class ViewJenisPembayaran extends HtmlResponse {
	function TemplateModule() {
		$this->SetTemplateBasedir(GTFWConfiguration::GetValue( 'application', 'docroot').'module/jenis_pembayaran/template');
		$this->SetTemplateFile('view_jenis_pembayaran.html');
	}
	
	function ProcessRequest() {
		$jnsObj = new AppJenisPembayaran();
      if($_POST || isset($_GET['cari'])) {
			if((isset($_POST['jns_bayar_kode']))or(isset($_POST['jns_bayar_nama']))) {
				$jnsKode = $_POST['jns_bayar_kode'];
				$jnsNama = $_POST['jns_bayar_nama'];
			} elseif((isset($_GET['jns_bayar_kode'])) or (isset($_GET['jns_bayar_nama']))) {
				$jalurKode = Dispatcher::Instance()->Decrypt($_GET['jns_bayar_kode']);
			} else {
				$jnsKode = '';
				$jnsNama = '';
			}
		}
      $totalData = $jnsObj->GetCountDataJenisPembayaran($jnsKode,$jnsNama);

		$itemViewed = 20;
		$currPage = 1;
		$startRec = 0 ;
		if(isset($_GET['page'])) {
			$currPage = (string)$_GET['page']->StripHtmlTags()->SqlString()->Raw();
			$startRec =($currPage-1) * $itemViewed;
		}
		$dataJenisBayar = $jnsObj->GetDataJenisPembayaran($startRec, $itemViewed,$jnsKode,$jnsNama);
		//print_r($dataJenisBayar);
		$url = Dispatcher::Instance()->GetUrl(Dispatcher::Instance()->mModule, Dispatcher::Instance()->mSubModule, Dispatcher::Instance()->mAction, Dispatcher::Instance()->mType . '&jns_bayar_kode=' . Dispatcher::Instance()->Encrypt($jnsKode) . '&jns_bayar_nama=' . Dispatcher::Instance()->Encrypt($jnsNama). '&cari=' . Dispatcher::Instance()->Encrypt(1));

		Messenger::Instance()->SendToComponent('paging', 'Paging', 'view', 'html', 'paging_top', array($itemViewed,$totalData, $url, $currPage), Messenger::CurrentRequest);

		$msg = Messenger::Instance()->Receive(__FILE__);
		$return['pesan'] = $msg[0][1];
		$return['css'] = $msg[0][2];

		$return['dataJenisBayar'] = $dataJenisBayar;
		$return['start'] = $startRec+1;
		//print_r($dataJenisBayar);
		$return['search']['jnsNama'] = $jnsNama;
		$return['search']['jnsKode'] = $jnsKode;
		return $return;
	}
	
	function ParseTemplate($data = NULL) {
      $search=$data['search'];
      $this->mrTemplate->AddVar('content', 'JNS_BAYAR_KODE', $search['jnsKode']);
      $this->mrTemplate->AddVar('content', 'JNS_BAYAR_NAMA', $search['jnsNama']);
		$this->mrTemplate->AddVar('content', 'URL_ADD', Dispatcher::Instance()->GetUrl('jenis_pembayaran', 'inputJenisPembayaran', 'view', 'html'));
		$this->mrTemplate->AddVar('content', 'URL_SEARCH', Dispatcher::Instance()->GetUrl('jenis_pembayaran', 'jenisPembayaran', 'view', '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']);
		}
      //print_r($data['dataJenisBayar']);
		if (empty($data['dataJenisBayar'])) {
			$this->mrTemplate->AddVar('data_jns_bayar', 'JNS_BAYAR_EMPTY', 'YES');
		} else {
			$decPage = Dispatcher::Instance()->Decrypt($_REQUEST['page']);
			$encPage = Dispatcher::Instance()->Encrypt($decPage);
			$this->mrTemplate->AddVar('data_jns_bayar', 'JNS_BAYAR_EMPTY', 'NO');
			$dataJenisBayar = $data['dataJenisBayar'];
		   // print_r($dataJenisBayar);
			//mulai bikin tombol delete
			$label = "Data Jenis Pembayaran";
			$urlDelete = Dispatcher::Instance()->GetUrl('jenis_pembayaran', 'deleteJenisPembayaran', 'do', 'html');
			$urlReturn = Dispatcher::Instance()->GetUrl('jenis_pembayaran', 'jenisPembayaran', 'view', 'html');
			Messenger::Instance()->Send('confirm', 'confirmDelete', 'do', 'html', array($label, $urlDelete, $urlReturn),Messenger::NextRequest);
			$this->mrTemplate->AddVar('content', 'URL_DELETE', Dispatcher::Instance()->GetUrl('confirm', 'confirmDelete', 'do', 'html'));

			for ($i=0; $i<sizeof($dataJenisBayar); $i++) {
				$no = $i+$data['start'];
				$dataJenisBayar[$i]['number'] = $no;
				//print_r($dataJenisBayar);
				if ($no % 2 != 0) $dataJenisBayar[$i]['class_name'] = 'table-common-even';
				else $dataJenisBayar[$i]['class_name'] = '';
				
				if($i == 0) $this->mrTemplate->AddVar('content', 'FIRST_NUMBER', $no);				
				if($i == sizeof($dataJenisBayar)-1) $this->mrTemplate->AddVar('content', 'LAST_NUMBER', $no);
				
				$idEnc = Dispatcher::Instance()->Encrypt($dataJenisBayar[$i]['KODE_JNS_BAYAR']);
            $urlAccept = 'jenis_pembayaran|deleteJenisPembayaran|do|html-cari-'.$cari;
            $urlReturn = 'jenis_pembayaran|JenisPembayaran|view|html-cari-'.$cari;
				$dataJenisBayar[$i]['url_edit'] = Dispatcher::Instance()->GetUrl('jenis_pembayaran', 'inputJenisPembayaran', 'view', 'html') . '&dataId=' . $idEnc . '&page=' . $encPage ;
            $dataJenisBayar[$i]['url_delete'] =  Dispatcher::Instance()->GetUrl('confirm', 'confirmDelete', 'do', 'html').'&urlDelete='. $urlAccept.'&urlReturn='.$urlReturn.'&id='.$dataJenisBayar[$i]['KODE_JNS_BAYAR'].'&label='.$label.'&dataName='.$dataJenisBayar[$i]['NAMA_JNS_BAYAR'];  
				
				$this->mrTemplate->AddVars('data_jns_bayar_item', $dataJenisBayar[$i], 'JNS_BAYAR_');
				$this->mrTemplate->parseTemplate('data_jns_bayar_item', 'a');	 
			}
		}
	}
}
?>
