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

class ViewPengembalianAset extends HtmlResponse
{
	function TemplateModule ()
	{
		$this->SetTemplateBasedir(GTFWConfiguration::GetValue('application','docroot').'module/'.Dispatcher::Instance()->mModule.'/template');
		$this->SetTemplateFile('view_pengembalian_aset.html');
	}
	
	function ProcessRequest ()
   {
		$Obj = new PengembalianAset;
		
		// inisialisasi messaging
		$msg = Messenger::Instance()->Receive(__FILE__);
		$this->Data = $msg[0][0];
		$this->Pesan = $msg[0][1];
		$this->css = $msg[0][2];
		
		$_POST = $_POST->AsArray();
	
		if($_POST || isset($_GET['cari'])) 
		{
			if(isset($_POST)) 
			{
				$kodeSewa = $_POST['kode_sewa'];
				//$status_isi = $_POST['status_isi'];
			} 
				elseif(isset($_GET['kode_sewa'])) 
			{
				$kodeSewa = Dispatcher::Instance()->Decrypt($_GET['kode_sewa']);
				//$status_isi = Dispatcher::Instance()->Decrypt($_GET['status_isi']);
			} 
		} else {
			$kodeSewa = '';
			//$status_isi = 'all';
		}

		//$totalData = $Obj->GetCountDataSewaAset($kodeSewa, $status_isi);
		$itemViewed = 20;
		$currPage = 1;
		$startRec = 0 ;
		
		if(isset($_GET['page'])) 
		{
			$currPage = (string)$_GET['page']->StripHtmlTags()->SqlString()->Raw();
			$startRec =($currPage-1) * $itemViewed;
		}
		/*
		$arrStatus = array(
			array(
				'id' => '1',
				'name' => 'Kadaluarsa'
			),
			array(
				'id' => '0',
				'name' => 'Disewa'
			)
		);
		
      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'status_isi', array('status_isi', $arrStatus, $status_isi, true, ''), Messenger::CurrentRequest);
		*/
		$data = $Obj->GetDataSewaAset($startRec, $itemViewed, $kodeSewa, $status_isi);
		$totalData = $Obj->GetCount();
		$url = Dispatcher::Instance()->GetUrl(Dispatcher::Instance()->mModule, Dispatcher::Instance()->mSubModule, Dispatcher::Instance()->mAction, Dispatcher::Instance()->mType . '&kodeSewa=' . Dispatcher::Instance()->Encrypt($kodeSewa)/*. '&status_isi=' . Dispatcher::Instance()->Encrypt($status_isi)*/.'&cari=' . Dispatcher::Instance()->Encrypt(1));
		Messenger::Instance()->SendToComponent('paging', 'Paging', 'view', 'html', 'paging_top', array($itemViewed, $totalData, $url, $currPage), Messenger::CurrentRequest);
      
		$return['data'] = $data;
		$return['search']['start'] = $startRec;
		$return['search']['view'] = $totalData;
		$return['search']['kodeSewa'] = $kodeSewa;
		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);
		}
		
		$search = $data['search'];
		$this->mrTemplate->AddVar('content', 'KODE_SEWA', $search['kodeSewa']);
		
		$this->mrTemplate->AddVar('content', 'URL_SEARCH', Dispatcher::Instance()->GetUrl('pengembalian_aset', 'pengembalianAset', 'view', 'html'));
		//$this->mrTemplate->AddVar('content', 'URL_RTF', Dispatcher::Instance()->GetUrl('pengembalian_aset', 'rtfSewaAset', 'print', 'html').'&start='.$search['start']."&limit=".$search['view']."&code=".$search['kodeSewa']);
			 
		if (empty($data['data']))
		{
			$this->mrTemplate->addVar('data_grid', 'IS_DATA_EMPTY', 'YES');
			return;
		}
		else 
		{	
			$this->mrTemplate->addVar('data_grid', 'IS_DATA_EMPTY', 'NO');

			$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]['sewa_id']);
				$dataTanggal = $data[$i]['sewa_tanggal_akhir'].' '.$data[$i]['sewa_waktu_akhir'];
				
				$data[$i]['display'] = 'none';	
				if($data[$i]['pengembalian']==''){
					if($data[$i]['status_isi'] == '1') $data[$i]['class_name'] = 'table-common-warning';
					$data[$i]['display'] = '';
					$data[$i]['displayd'] = 'none';	
				}
				
				$data[$i]['sewa_tanggal_awal'] = IndonesianDate($data[$i]['sewa_tanggal_awal'], 'yyyy-mm-dd');
				$data[$i]['sewa_tanggal_akhir'] = IndonesianDate($data[$i]['sewa_tanggal_akhir'], 'yyyy-mm-dd');
				$data[$i]['url_detail'] = Dispatcher::Instance()->GetUrl('pengembalian_aset','detilPengembalianAset', 'popup', 'html') . '&id=' . $idEnc;
				$data[$i]['url_cetak'] = Dispatcher::Instance()->GetUrl('pengembalian_aset','cetakPengembalianAset', 'view', 'html') . '&id=' . $idEnc;
				$data[$i]['url_edit']=Dispatcher::Instance()->GetUrl('pengembalian_aset','inputPengembalianAset', 'view', 'html').'&id='.$idEnc;
				
				$this->mrTemplate->AddVars('data_list', $data[$i], '');
				$this->mrTemplate->parseTemplate('data_list', 'a');	 
			}
		}
	}
}
?>
