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

class ViewInputPengembalianAset extends HtmlResponse 
{
	function TemplateModule() 
	{
      $this->SetTemplateBasedir(GTFWConfiguration::GetValue( 'application', 'docroot').'module/pengembalian_aset/template');
      $this->SetTemplateFile('view_input_pengembalian_aset.html');
   }
	
   function ProcessRequest() 
	{
      $obj = new PengembalianAset;
		
		$msg = Messenger::Instance()->Receive(__FILE__);
		$this->Data = $msg[0][0];
		$this->Pesan = $msg[0][1];
		$this->css = $msg[0][2];
	
      $hour = $obj->GetHour();
      $minute = $obj->GetMinute();
		
		$id = $_GET['id']->Integer()->Raw();
      $result = $obj->GetDataPengembalianAsetById($id);
      
		$data = array();
		if(is_array($this->Data))
		{
			$data = $this->Data;			
         $endDate = $data['pengembalian_year']."-".$data['pengembalian_mon']."-".$data['pengembalian_day'];
		} 
			elseif(isset($_GET['id']))
		{
         if ($result === false) 
				unset($_GET['id']);
         else 
				$data = $result[0];
				$data['pengadaanSewaList']=$result;
				$endDate = date('Y-m-d');
      }
			else
		{
         $today = date("Y-m-d");
         $endDate = $today;
			
			$data['jumlah_hari'] = 1;
		}

     
      Messenger::Instance()->SendToComponent('tanggal', 'Tanggal', 'view', 'html', 'tgl_pengembalian',array($endDate, '2000', date('Y')+1), Messenger::CurrentRequest);
      
		$return['data'] = $data;
		$return['json']['pengembalian_aset'] = json_encode($data['pengadaanSewaList']);
      unset ($return['data']['pengadaanSewaList']);
      return $return;
   }

   function ParseTemplate($data = NULL)
	{
		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);
		}
		
		$urlAsetSewaPopup = Dispatcher::Instance()->GetUrl('pengembalian_aset', 'pengembalianAset', 'popup', 'html');
		$urlAsetSewaList	= Dispatcher::Instance()->GetUrl('pengembalian_aset', 'pengembalianAset', 'view', 'html');
		$this->mrTemplate->AddVar('content', 'URL_ASET_LIST', $urlAsetSewaList);
		
		$this->mrTemplate->AddVar('content', 'URL_ASET_POPUP', $urlAsetSewaPopup);
		$this->mrTemplate->AddVars('content', $data['json'], 'JSON_' );

      if($data['data']['sewa_id']!==''){
			$urlAction = Dispatcher::Instance()->GetUrl('pengembalian_aset', 'inputPengembalianAset', 'do', 'json').'&id='.Dispatcher::Instance()->Encrypt($data['data']['sewa_id']);
		}
		
		$this->mrTemplate->AddVar('content', 'ACTION_URL', $urlAction);
      $this->mrTemplate->AddVars('content', $data['data'],'');
   }
}
?>