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

class ViewBiayaSewaRuang extends HtmlResponse
{
   function TemplateModule()
   {
      $this->SetTemplateBasedir(GTFWConfiguration::GetValue('application','docroot').
         'module/biaya_sewa_ruang/template');
      $this->SetTemplateFile('view_biaya_ruang_sewa.html');
   }
   
   function ProcessRequest()
   {
      $Obj = new BiayaSewa;
      
		// inisialisasi messaging
		$msg = Messenger::Instance()->Receive(__FILE__);
		$this->Data = $msg[0][0];
		$this->Pesan = $msg[0][1];
		$this->css = $msg[0][2];
		
      // Inisialisasi filter
      if (count($_POST)>0)
      {
         $kode 	= $_POST['ruang_kode']->Raw();
         $label 	= $_POST['ruang_label']->Raw();
      }
			elseif (isset($_GET['cari']))
      {
         list($kode, $label) = explode('|', Dispatcher::Instance()->Decrypt($_GET['cari']));
      }
			else
      {
         $kode = '';
         $label = '';
      }
		
		$cari = Dispatcher::Instance()->Encrypt("$kode|$label");
        
      $return['url']['search'] = Dispatcher::Instance()->GetUrl(Dispatcher::Instance()->mModule, Dispatcher::Instance()->mSubModule, Dispatcher::Instance()->mAction, Dispatcher::Instance()->mType);
  
      #$totalData = $Obj->GetDataBiayaSewaRuangCount($kode, $label);
		$itemViewed = 20;
      $currPage = 1;
      if (isset($_GET['page'])) $currPage = $_GET['page']->Integer()->Raw();
      if ($currPage < 1) $currPage = 1;
      $startRec = ($currPage-1) * $itemViewed;
      
      $asetSewa = $Obj->GetDataBiayaSewaRuang($kode, $label, $startRec, $itemViewed);
      $return['data'] = $asetSewa;
      $totalData = $Obj->GetCount();
      $url = Dispatcher::Instance()->GetUrl(Dispatcher::Instance()->mModule, Dispatcher::Instance()->mSubModule, Dispatcher::Instance()->mAction, Dispatcher::Instance()->mType) . '&cari=' . Dispatcher::Instance()->Encrypt($cari);
		
      Messenger::Instance()->SendToComponent('paging', 'paging', 'view', 'html', 'paging_top', array($itemViewed, $totalData, $url, $currPage), Messenger::CurrentRequest);
      $return['start'] = $startRec+1;
		$return['cari'] = $cari;
           
		return $return;
   }
    
	function ParseTemplate($data = NULL)
   {
		// render message box
		if($this->Pesan) 
		{
			$this->mrTemplate->SetAttribute('warning_box', 'visibility', 'visible');
			$this->mrTemplate->AddVar('warning_box', 'ISI_PESAN', $this->Pesan);
			$this->mrTemplate->AddVar('warning_box', 'NOTEBOX', $this->css);
		}
			
		$this->mrTemplate->AddVar('content', 'URL_SEARCH', $data['url']['search']);
      $this->mrTemplate->AddVar('content', 'URL_ADD', Dispatcher::Instance()->GetUrl('biaya_sewa_ruang', 'inputBiayaSewaRuang', 'view', 'html'));
			
		$exp = explode('|', $data['cari']);
      $this->mrTemplate->AddVar('content', 'KODE', $exp[0]);
      $this->mrTemplate->AddVar('content', 'LABEL', $exp[1]);
		
		if (count($data['data']) == 0)
		{
			$this->mrTemplate->AddVar('data', 'DATA_EMPTY', 'YES');
			return;
		}
			else 
		{
			$this->mrTemplate->AddVar('data', 'DATA_EMPTY', 'NO');
			
			//mulai bikin tombol delete
			$label = "Manajemen Biaya Sewa Ruang";
			$urlDelete = Dispatcher::Instance()->GetUrl('biaya_sewa_ruang', 'deleteBiayaSewaRuang', 'do', 'html');
			$urlReturn = Dispatcher::Instance()->GetUrl('biaya_sewa_ruang', 'biayaSewaRuang', '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'));
			//selesai bikin tombol delete
			
			$data = $data['data'];
			
			for ($i=0; $i<sizeof($data); $i++) 
			{
				$no = $i+1;
				$data[$i]['number'] = $no;
				if ($no % 2 != 0) $data[$i]['class_name'] = 'table-common-even';
				else $data[$i]['class_name'] = '';
				
				if($i == 0) $this->mrTemplate->AddVar('content', 'FIRST_NUMBER', $no);				
				if($i == sizeof($data)-1) $this->mrTemplate->AddVar('content', 'LAST_NUMBER', $no);
				
				$idEnc = Dispatcher::Instance()->Encrypt($data[$i]['biaya_sewa_id']);
				
				$data[$i]['url_edit']=Dispatcher::Instance()->GetUrl('biaya_sewa_ruang','inputBiayaSewaRuang', 'view', 'html').'&id='.$idEnc;
				
				$data[$i]['biaya_sewa'] = number_format($data[$i]['biaya_sewa'], 2, ',', '.');
				if($data[$i]['biaya_sewa_status']=='Y'){
					$data[$i]['biaya_sewa_status'] = 'Aktif';
				} else {
					$data[$i]['biaya_sewa_status'] = 'Non-Aktif';
				}
				
				$this->mrTemplate->AddVars('data_item', $data[$i], '');
				$this->mrTemplate->parseTemplate('data_item', 'a');
			}
		}
	}
}
?>