<?php

/*
 @ClassName : View Mutasi Barang
 @Copyright : PT Gamatechno Indosnesia
 @Analyzed By : Nanang Ruswianto <nanang@gamatechno.com>
 @Designed By : Rosyid <rosyid@gamatechno.com>
 @Author By : Dyan Galih <galih@gamatechno.com>
 @Version : 1.0
 @StartDate : Desember 17, 2008
 @LastUpdate : Desember 17, 2008
 @Description :
*/

require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/mutasi_barang/business/AppMutasi.class.php';
//set Label for module
require_once GTFWConfiguration::GetValue( 'application', 'docroot') .
'module/label/response/Label.proc.class.php';
class ViewMutasiBarang extends HtmlResponse {

   #var $Pesan;

   function TemplateModule() {
      $this->SetTemplateBasedir(GTFWConfiguration::GetValue('application','docroot').'module/mutasi_barang/template');
      $this->SetTemplateFile('view_mutasi_barang.html');
   }
   
   function TemplateLabeling(){
      $ObjLabel = new GetModuleLabel();
      $arrLabel = $ObjLabel->GetLabel();
      
      //patTemplate name yang memiliki label2 dinamic
      $arrContent=array("content");
      
      for($i=0;$i<count($arrContent);$i++){
         for($j=0;$j<count($arrLabel);$j++){
            $this->mrTemplate->AddVar($arrContent[$i],$arrLabel[$j]['labelCode'],$arrLabel[$j]['labelName']);
         }
      }
   }
   
   function ProcessRequest() {
   	
   	$_POST = $_POST->AsArray();
   	
   	$golBarang = $_POST['jenis_kib'];
   	$lokasi = $_POST['lokasi'];
   	$unit = $_POST['unit_kerja'];
   	if(empty($_POST)){
			$tglAwal = date('Y-01-01');
			$tglAkhir = date('Y-m-d');	
			$return['tgl'] = array(
				'tanggal_awal_year' => date('Y'),
				'tanggal_awal_mon' => '01',
				'tanggal_awal_day' => '01',
				'tanggal_akhir_year' => date('Y'),
				'tanggal_akhir_mon' => date('m'),
				'tanggal_akhir_day' => date('d'),
			); 
		} 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'];
   	}
   	$kodeBrg = $_POST['aset'];
		
   	$msg = Messenger::Instance()->Receive(__FILE__);
		$return['pesan'] = $msg[0][0];
		$return['css_pesan'] = $msg[0][1];

      $Obj = new AppMutasiBarang();

      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);
      
      //set combo kib
      $arrJenisKIB = $Obj->GetJenisKIB();
      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'jenis_kib', array('jenis_kib', $arrJenisKIB, $_POST['jenis_kib'], true, ''), Messenger::CurrentRequest);
		
		//set combo lokasi
		$arrLokasi = $Obj->GetLokasi();
		Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'lokasi', array('lokasi', $arrLokasi, $lokasi, true, ''), Messenger::CurrentRequest);
      
      
      //set unit kerja
      $unitKerja = $Obj->GetUnitKerja();
      
   	Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'unit_kerja', array('unit_kerja', $unitKerja, $unit, true, ''), Messenger::CurrentRequest);

   	$return['data'] = $Obj->GetListMutasi($golBarang,$tglAwal,$tglAkhir,$kodeBrg,$kodeBrg,$unit,$lokasi);
   	return $return;  
   }
   
   function ParseTemplate($data = NULL) {
   	//url tambah
		if(empty($_POST))$_POST = $data['tgl'];
   	$urlTambah = Dispatcher::Instance()->GetUrl('mutasi_barang', 'mutasiBarangInput', 'view', 'html');
      $this->mrTemplate->addVar('content','URL_TAMBAH',$urlTambah);
      //url search
      $urlSearch = Dispatcher::Instance()->GetUrl('mutasi_barang', 'mutasiBarang', 'view', 'html');
      $this->mrTemplate->addVar('content','URL_SEARCH',$urlSearch);
      $this->mrTemplate->addVar('content','ASET',$_POST['aset']);
      //url export excel
      $urlExcel = Dispatcher::Instance()->GetUrl('mutasi_barang', 'excelMutasiBarang', 'view', 'xls')
      .'&jenis_kib='.Dispatcher::Instance()->Encrypt($_POST['jenis_kib'])
      .'&lokasi='.Dispatcher::Instance()->Encrypt($_POST['lokasi'])
      .'&unit_kerja='.Dispatcher::Instance()->Encrypt($_POST['unit_kerja'])
      .'&tanggal_awal_year='.Dispatcher::Instance()->Encrypt($_POST['tanggal_awal_year'])
      .'&tanggal_awal_mon='.Dispatcher::Instance()->Encrypt($_POST['tanggal_awal_mon'])
      .'&tanggal_awal_day='.Dispatcher::Instance()->Encrypt($_POST['tanggal_awal_day'])
      .'&tanggal_akhir_year='.Dispatcher::Instance()->Encrypt($_POST['tanggal_akhir_year'])
      .'&tanggal_akhir_mon='.Dispatcher::Instance()->Encrypt($_POST['tanggal_akhir_mon'])
      .'&tanggal_akhir_day='.Dispatcher::Instance()->Encrypt($_POST['tanggal_akhir_day'])
      .'&aset='.Dispatcher::Instance()->Encrypt($_POST['aset'])
      ;
      $this->mrTemplate->addVar('content','URL_EXCEL',$urlExcel);
      
      $urlPrint = Dispatcher::Instance()->GetUrl('mutasi_barang', 'mutasiBarang', 'print', 'html')
      .'&jenis_kib='.Dispatcher::Instance()->Encrypt($_POST['jenis_kib'])
      .'&lokasi='.Dispatcher::Instance()->Encrypt($_POST['lokasi'])
      .'&unit_kerja='.Dispatcher::Instance()->Encrypt($_POST['unit_kerja'])
      .'&tanggal_awal_year='.Dispatcher::Instance()->Encrypt($_POST['tanggal_awal_year'])
      .'&tanggal_awal_mon='.Dispatcher::Instance()->Encrypt($_POST['tanggal_awal_mon'])
      .'&tanggal_awal_day='.Dispatcher::Instance()->Encrypt($_POST['tanggal_awal_day'])
      .'&tanggal_akhir_year='.Dispatcher::Instance()->Encrypt($_POST['tanggal_akhir_year'])
      .'&tanggal_akhir_mon='.Dispatcher::Instance()->Encrypt($_POST['tanggal_akhir_mon'])
      .'&tanggal_akhir_day='.Dispatcher::Instance()->Encrypt($_POST['tanggal_akhir_day'])
      .'&aset='.Dispatcher::Instance()->Encrypt($_POST['aset'])
      ;
      $this->mrTemplate->addVar('content','URL_CETAK',$urlPrint);
      $this->mrTemplate->addVar('content','COMBO_LOKASI_JSON',$data['combo_lokasi_json']);
      
      $urlDelete = Dispatcher::Instance()->GetUrl('confirm', 'confirmDelete', 'do', 'html').
         "&urlReturn=".Dispatcher::Instance()->Encrypt('mutasi_barang|mutasiBarang|view|html').
         "&label=".Dispatcher::Instance()->Encrypt('Mutasi Barang');

      //set Label
      $this->TemplateLabeling();
      
      if($data['pesan']){
			$this->mrTemplate->SetAttribute('warning_box', 'visibility', 'visible');
			$this->mrTemplate->AddVar('warning_box', 'ISI_PESAN', $data['pesan']);
			$this->mrTemplate->AddVar('warning_box', 'CLASS_PESAN', $data['css_pesan']);
		}
      
      if(empty($data['data'])){
      	$this->mrTemplate->AddVar('data','DATA_EMPTY','YES');      	
      	return;
		}else
			$this->mrTemplate->AddVar('data','DATA_EMPTY','NO');
			
			$gridList = $data['data'];
			
		$no = 1;
		#print_r($gridList);
		for($i=0;$i<count($gridList);$i++){
			$gridList[$i]['NO'] = $no;
			$cantDel = strpos($gridList[$i]['cantDelete'], '1');
			if($cantDel === false){
				$gridList[$i]['URL_DELETE'] = $urlDelete.
				"&urlDelete=".Dispatcher::Instance()->Encrypt('mutasi_barang|deleteMutasiBarang|do|html').
				"&id=".Dispatcher::Instance()->Encrypt($gridList[$i]['id']).
				"&dataName=".Dispatcher::Instance()->Encrypt($gridList[$i]['berita_acara']);
			}else{
				$gridList[$i]['URL_DELETE_DISPLAY'] = 'none';
			}
			$gridList[$i]['URL_DETIL'] = Dispatcher::Instance()->GetUrl('mutasi_barang', 'detailMutasiBarang', 'view', 'html').'&mutasiId='.$gridList[$i]['id'];
			
			$gridList[$i]['URL_EDIT'] = Dispatcher::Instance()->GetUrl('mutasi_barang', 'mutasiBarangInput', 'view', 'html').'&mutasiId='.$gridList[$i]['id'];
			
			$gridList[$i]['URL_RTF'] = Dispatcher::Instance()->GetUrl('mutasi_barang', 'CetakMutasiBarang', 'view', 'html').'&mutasiId='.$gridList[$i]['id'];
			
			$this->mrTemplate->AddVars('data_item',$gridList[$i],'MUTASI_');
			$this->mrTemplate->parseTemplate('data_item','a');
			$no++;
		}

   }
}
?>
