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

class ViewLapMutasiBarang extends HtmlResponse
{
	function TemplateModule ()
   {
		$this->SetTemplateBasedir(GTFWConfiguration::GetValue('application','docroot').'module/'.Dispatcher::Instance()->mModule.'/template');
		$this->SetTemplateFile('view_lap_mutasi_barang.html');
	}
	
	function ProcessRequest ()
   {
		$barangObj = new LapMutasiBarang;
		$_POST = $_POST->AsArray();
		
   	if(empty($_POST))
		{
			$tglAwal = date('Y-01-01');
			$tglAkhir = date('Y-m-d');	
			$unitAsal = 'all';
			$unitTuj = 'all';
			$kodeBA = '';
		} 
			else 
		{
			$tglAwal = $_POST['tanggal_awal_year'].'-'.$_POST['tanggal_awal_mon'].'-'.$_POST['tanggal_awal_day'];
			$tglAkhir = $_POST['tanggal_akhir_year'].'-'.$_POST['tanggal_akhir_mon'].'-'.$_POST['tanggal_akhir_day'];
			$unitAsal = $_POST['unit'];
			$unitTuj = $_POST['unit_tujuan'];
			$kodeBA = $_POST['kodeba'];
   	}
		
		Messenger::Instance()->SendToComponent('tanggal', 'Tanggal', 'view', 'html', 'tanggal_awal', array($tglAwal), Messenger::CurrentRequest);
      
      Messenger::Instance()->SendToComponent('tanggal', 'Tanggal', 'view', 'html', 'tanggal_akhir', array($tglAkhir), Messenger::CurrentRequest);
		
		$unitKerja = $barangObj->GetUnitKerja();
                $unitKerja2 = $barangObj->GetUnitKerja(TRUE);
		Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'unit', array('unit', $unitKerja2, $unitAsal, 'true', ''), Messenger::CurrentRequest);
		
		Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'unit_tujuan', array('unit_tujuan', $unitKerja, $unitTuj, 'true', ''), Messenger::CurrentRequest);
		  
		$return['dataMutasi'] = $barangObj->GetDataMutasi($tglAwal,$tglAkhir,$unitAsal,$unitTuj, $kodeBA);
		$search = array(
			'tglAwal' => $tglAwal,
			'tglAkhir' => $tglAkhir,	
			'unit' => $unitAsal,
			'unit_tujuan' => $unitTuj,
			'kodeba' => $kodeBA
		);
		$return['search'] = $search;
      return $return;
	}
	
	function ParseTemplate ($data = NULL)
   {
   	$search = $data['search'];
		$this->mrTemplate->AddVar('content', 'KODE_BA', $search['kodeba']);
		
      $this->mrTemplate->AddVar('content', 'URL_SEARCH', Dispatcher::Instance()->GetUrl('lap_mutasi_barang', 'lapMutasiBarang', 'view', 'html'));
		$tglAwal = $search['tglAwal'];
		$tglAkhir = $search['tglAkhir'];

		$this->mrTemplate->AddVar('content', 'URL_CETAK', 
		Dispatcher::Instance()->GetUrl('lap_mutasi_barang', 'CetakLapMutasiBarang', 'view', 'html') . 
		'&tglAwal=' . $tglAwal . 
		'&tglAkhir=' .$tglAkhir .
		'&unitAsal=' . $search['unit'] .
		'&unitTuj=' . $search['unit_tujuan'] .
		'&kodeba=' . $search['kodeba']);
		
		$this->mrTemplate->AddVar('content', 'URL_CETAK_XLS', 
		Dispatcher::Instance()->GetUrl('lap_mutasi_barang', 'excelLapMutasiBarang', 'view', 'xlsx') . 
		'&tglAwal=' . $tglAwal . 
		'&tglAkhir=' .$tglAkhir .
		'&unitAsal=' . $search['unit'] .
		'&unitTuj=' . $search['unit_tujuan'] .
		'&kodeba=' . $search['kodeba']);

		//print_r($data);
		if (empty($data['dataMutasi']))
      {
         $this->mrTemplate->addVar('data_grid', 'IS_DATA_EMPTY', 'YES');
         return;
      }
			else $this->mrTemplate->addVar('data_grid', 'IS_DATA_EMPTY', 'NO');
	  
	  
			$dataMutasi = $data['dataMutasi'];
			
			for ($i=0; $i<sizeof($dataMutasi); $i++) {
				$no = $i+1;
				$dataMutasi[$i]['number'] = $no;
				if ($no % 2 != 0) $dataMutasi[$i]['class_name'] = 'table-common-even';
				else $dataMutasi[$i]['class_name'] = '';
					$idEnc = Dispatcher::Instance()->Encrypt($dataMutasi[$i]['mutasi_id']);
					$ba = Dispatcher::Instance()->Encrypt($dataMutasi[$i]['mutasi_berita_acara']);

					$dataMutasi[$i]['url_detil']=Dispatcher::Instance()->GetUrl('lap_mutasi_barang','detailMutasiBarang', 'popup', 'html') . '&idMutasi=' . $idEnc;
					$dataMutasi[$i]['url_rtf']=Dispatcher::Instance()->GetUrl('lap_mutasi_barang','rtfMutasiBarang', 'view', 'rtf') . '&kodeba=' . $ba;
					
				$this->mrTemplate->AddVars('data_mutasi', $dataMutasi[$i], 'DATA_');
				$this->mrTemplate->parseTemplate('data_mutasi', 'a');	 
			}
	}
}
?>
