<?php
require_once GTFWConfiguration::GetValue( 'application', 'docroot').
   'module/' . Dispatcher::Instance()->mModule . '/business/SewaAset.class.php';

class PopupSewaAset extends HtmlResponse
{
   
   function TemplateModule()
   {
      $this->SetTemplateBasedir(GTFWConfiguration::GetValue('application','docroot').
         'module/'.Dispatcher::Instance()->mModule.'/template');
      $this->SetTemplateFile('view_popup_aset_sewa.html');
   }
   
   function ProcessRequest()
   {
      $Obj = new SewaAset;
      
      // Inisialisasi filter
      if (count($_POST)>0)
      {
         $kode 	= $_POST['aset_kode']->Raw();
         $label 	= $_POST['aset_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->GetDataAsetSewaCount($kode, $label);
		$itemViewed = 10;
      $currPage = 1;
      if (isset($_GET['page'])) $currPage = $_GET['page']->Integer()->Raw();
      if ($currPage < 1) $currPage = 1;
      $startRec = ($currPage-1) * $itemViewed;
      
      $asetSewa = $Obj->GetDataAsetSewa($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);
		
		$dest = "popup-subcontent";
      Messenger::Instance()->SendToComponent('paging', 'paging', 'view', 'html', 'paging_top', array($itemViewed, $totalData, $url, $currPage, $dest), Messenger::CurrentRequest);
      $return['start'] = $startRec+1;
		$return['cari'] = $cari;
            
		return $return;
   }
    
	function ParseTemplate($data = NULL)
   {
		$this->mrTemplate->AddVar('content', 'URL_SEARCH', $data['url']['search']);
      
		$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');
			$i = $data['start'];
			foreach($data['data'] as $row){
				$row['number'] = $i;
				if($i%2)
				{
					$row['class_name'] = "";
				} 
					else 
				{
					$row['class_name'] = 'table-common-even';
				}
				$row['aset_harga_sewa_view'] = number_format($row['aset_harga_sewa'], 2, ',', '.');
				$this->mrTemplate->AddVars('data_item', $row, '');
				$this->mrTemplate->parseTemplate('data_item', 'a');
				$i++;
			}
		}
	}
}
?>