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

class ViewPerbaikanBarangHistory extends HtmlResponse
{
	function TemplateModule ()
	{
		$this->SetTemplateBasedir(GTFWConfiguration::GetValue('application','docroot').'module/'.Dispatcher::Instance()->mModule.'/template');
		$this->SetTemplateFile('view_perbaikanbarang_history.html');
	}
	
	function ProcessRequest ()
   {
		$PerbaikanBarangHistoryObj = new PerbaikanBarangHistory;
		
		// 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['nama'])) {
				$nama = $_POST['nama'];
			} elseif(isset($_GET['nama'])) {
				$nama = Dispatcher::Instance()->Decrypt($_GET['nama']);
			} else {
				$nama = '';	
			}
		}

		//$totalData = $PerbaikanBarangHistoryObj->GetCountDataPerbaikanBarangHistory();
		$itemViewed = 20;
		$currPage = 1;
		$startRec = 0 ;
		if(isset($_GET['page'])) {
			$currPage = (string)$_GET['page']->StripHtmlTags()->SqlString()->Raw();
			$startRec =($currPage-1) * $itemViewed;
		}
                
		$dataPerbaikanBarangHistory=$PerbaikanBarangHistoryObj->GetDataPerbaikanBarangHistory($nama, $startRec, $itemViewed);
                $totalData = $PerbaikanBarangHistoryObj->GetCount();
                        
                $url = Dispatcher::Instance()->GetUrl(Dispatcher::Instance()->mModule, Dispatcher::Instance()->mSubModule, Dispatcher::Instance()->mAction, Dispatcher::Instance()->mType.'&cari=' . Dispatcher::Instance()->Encrypt(1));
		Messenger::Instance()->SendToComponent('paging', 'Paging', 'view', 'html', 'paging_top', array($itemViewed, $totalData, $url, $currPage), Messenger::CurrentRequest);
		
		$return['dataPerbaikanBarangHistory'] = $dataPerbaikanBarangHistory;
		$return['search']['nama'] = $nama;
		
		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', 'NAMA', $search['nama']);
		
		$this->mrTemplate->AddVar('content', 'URL_SEARCH', Dispatcher::Instance()->GetUrl('perbaikan_barang_history', 'perbaikanBarangHistory', 'view', 'html'));
		
		if (empty($data['dataPerbaikanBarangHistory']))
		{
			$this->mrTemplate->addVar('data_grid', 'IS_DATA_EMPTY', 'YES');
			return;
		}
			else 
		{	
			$this->mrTemplate->addVar('data_grid', 'IS_DATA_EMPTY', 'NO');
			$dataPerbaikanBarangHistory = $data['dataPerbaikanBarangHistory'];
			
			for ($i=0; $i<sizeof($dataPerbaikanBarangHistory); $i++) {
				$no = $i+1;
				$dataPerbaikanBarangHistory[$i]['number'] = $no;
				if ($no % 2 != 0) $dataPerbaikanBarangHistory[$i]['class_name'] = 'table-common-even';
				else $dataPerbaikanBarangHistory[$i]['class_name'] = '';
				
				if($i == 0) $this->mrTemplate->AddVar('content', 'FIRST_NUMBER', $no);				
				if($i == sizeof($dataPerbaikanBarangHistory)-1) $this->mrTemplate->AddVar('content', 'LAST_NUMBER', $no);
				
				$idEnc = Dispatcher::Instance()->Encrypt($dataPerbaikanBarangHistory[$i]['barangId']);
                                
                                if($dataPerbaikanBarangHistory[$i]['isDone'] == "0")
                                    $dataPerbaikanBarangHistory[$i]['url_edit']=Dispatcher::Instance()->GetUrl('perbaikan_barang_history','inputPerbaikanBarangHistory', 'view', 'html') . '&idPerbaikanBarangHistory=' . $idEnc;                          
                                else $dataPerbaikanBarangHistory[$i]['display_edit']="none";
				
				$dataPerbaikanBarangHistory[$i]['url_cetak']=Dispatcher::Instance()->GetUrl('perbaikan_barang_history','printPerbaikanBarangHistory', 'view', 'html') . '&idPerbaikanBarangHistory=' . $idEnc;
				
				$dataPerbaikanBarangHistory[$i]['perbaikanBiaya'] = number_format($dataPerbaikanBarangHistory[$i]['perbaikanBiaya'], 2, ', ', '.');
				
				$this->mrTemplate->AddVars('data_list', $dataPerbaikanBarangHistory[$i], 'DATA_');
				$this->mrTemplate->parseTemplate('data_list', 'a');	 
			}
		}	
	}
}
?>
