<?php
/*
 @ClassName : View Input Mutasi Barang
 @Copyright : PT Gamatechno Indonesia
 @Analyzed By : Nanang Ruswianto <nanang@gamatechno.com>
 @Designed By : Rosyid <rosyid@gamatechno.com>
 @Author By : Dyan Galih <galih@gamatechno.com>
 @Version : 1.0
 @StartDate : Okt 20, 2008
 @LastUpdate : Okt 20, 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 ViewMutasiBarangInput extends HtmlResponse
{
	
	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 TemplateModule()
   {
      $this->SetTemplateBasedir(GTFWConfiguration::GetValue('application','docroot').
         'module/mutasi_barang/template');
      $this->SetTemplateFile('input_mutasi_barang.html');
   }
   
   function ProcessRequest()
   {
   	
   	$msg = Messenger::Instance()->Receive(__FILE__);
		$return['pesan'] = $msg[0][0];
		$return['css_pesan'] = $msg[0][1];
		
   	$obj = new AppMutasiBarang();
   	
   	$unitAsal = $_POST['unit_asal'];
   	$lokasiAsal = $_POST['lokasi_barang'];
   	$unitTujuan = $_POST['unit_tujuan'];
   	$lokasiTujuan = $_POST['lokasi_tujuan'];
   	
   	$arrGet = $_GET->AsArray();
   	
   	
   	
   	if(isset($arrGet['mutasiId'])){
   		$return['detailMutasi'] = $obj->GetMutasiDetail($arrGet['mutasiId']);
   		
   		$unitAsal = $return['detailMutasi']['0']['unit_asal_id'];
			$lokasiAsal = $return['detailMutasi']['0']['lokasi_asal_id'];
			$unitTujuan = $return['detailMutasi']['0']['unit_tujuan_id'];
			$lokasiTujuan = $return['detailMutasi']['0']['lokasi_tujuan_id'];
			$tanggal = $return['detailMutasi']['0']['tgl'];
			
			$return['mutasiId'] = $arrGet['mutasiId'];
   	} else {
			$tanggal = date("Y-m-d");
			$return['detailMutasi']['0']['ba_mutasi'] = "BA-MUT-".date("Ymdhis");
		}
   	
   	
   	
   	Messenger::Instance()->SendToComponent('tanggal', 'Tanggal', 'view', 'html', 'tanggal_mutasi', array($tanggal), Messenger::CurrentRequest);
   	
   	//set combo unit asal
   	$unitKerja = $obj->getUnitKerja();
   	Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'unit_asal', array('unit_asal', $unitKerja, $unitAsal, 'false', 'onchange="setComboLokasi(this.value);"'), Messenger::CurrentRequest);
   	
   	///get id from get
   	if(!isset($unitAsal))
   		$unitAsal = $_GET['unit_asal'];
   	//set combo lokasi barang
   	$lokasiBarang = $obj->GetLokasiBarang($unitAsal);
   	
   	Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'lokasi_barang', array('lokasi_barang', $lokasiBarang, $lokasiAsal, 'false', ''), Messenger::CurrentRequest);
		//get combo 
		
		$arrUnitTujuan = $obj->GetUnitKerjaTujuan($unitAsal);
		
   	Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'unit_tujuan', array('unit_tujuan', $arrUnitTujuan, $unitTujuan, 'false', 'onchange="setComboLokasiTujuan(this.value);"'), Messenger::CurrentRequest);
   	
   	///get id from get
   	if(!isset($unitTujuan))
   		$unitTujuan = $_GET['unit_tujuan'];
   	
   	//set combo unit kerja
   	$lokasiBarang = $obj->GetLokasiBarang($unitTujuan);
   	Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'lokasi_tujuan', array('lokasi_tujuan', $lokasiBarang, $lokasiTujuan, 'false', ''), Messenger::CurrentRequest);
   	
      return $return;
   }
   
   
	function ParseTemplate($data = NULL)
   {
   	if(isset($data['detailMutasi'])){
			$listBrg = $data['detailMutasi'];
			
			$this->mrTemplate->addVars('content',$data['detailMutasi']['0'],'');
			
			for($i=0;$i<count($listBrg);$i++){
				$arrList[$i] = $listBrg[$i]['barangId'].'|'.$listBrg[$i]['kode_aset'].'|'.$listBrg[$i]['nama_aset'].'|'.$listBrg[$i]['merk'].'|'.$listBrg[$i]['spesifikasi'];
			}
			
			$arrList = implode('$',$arrList);
			
			$this->mrTemplate->addVar('content','STR_BARANG',$arrList);
			if($listBrg[0]['barangId'] <> '') $this->mrTemplate->addVar('content','SET_BARANG','set');
			
		} 
		$this->mrTemplate->addVar('content','MUTASI_ID',$data['mutasiId']);
		
   	$urlPopUp = Dispatcher::Instance()->GetUrl('popup', 'Barang', 'popup', 'html');
      $this->mrTemplate->addVar('content','URL_POP_UP_KD_BARANG',$urlPopUp);
      
      if(!isset($data['mutasiId'])){
      	$urlAction = Dispatcher::Instance()->GetUrl('mutasi_barang', 'addMutasiBarang', 'do', 'html');
      	$this->mrTemplate->addVar('content','JUDUL','Tambah');
      }else{
      	$urlAction = Dispatcher::Instance()->GetUrl('mutasi_barang', 'updateMutasiBarang', 'do', 'html');
      	$this->mrTemplate->addVar('content','JUDUL','Edit');
		}
      	
      $this->mrTemplate->addVar('content','URL_ACTION',$urlAction);
      
      
      $this->TemplateLabeling();
   }
}
?>
