<?php

class LapMutasiBarang extends Database {

	protected $mSqlFile= 'module/lap_mutasi_barang/business/lapmutasibarang.sql.php';
	
	function __construct($connectionNumber=0) {
		parent::__construct($connectionNumber);
                #$this->setDebugOn();
	}
        
        function GetDataUserByUsername ($name)
        {
           if (isset($this->mUserByUserName[$name])) return $this->mUserByUserName[$name];
           $result = $this->Open($this->mSqlQueries['get_data_user_by_username'], array($name));
           $this->mUserByUserName[$name] = $result[0];
           return $result[0];
        }
	
	function GetDataGedung($nama='', $offset, $limit) {
		$ret = $this->Open($this->mSqlQueries['get_data_gedung'], array("%".$nama."%", $offset, $limit));
      return $ret;
	}

	function GetCountData($nama='') {
		$result = $this->Open($this->mSqlQueries['get_count_data'], array("%".$nama."%"));
		if (!$result) {
			return 0;
		} else {
			return $result[0]['total'];
		}
	}
	
	# multiunit
	function GetUnitKerja($all=false) {
			$sql = $this->mSqlQueries['get_combo_unit'];
            if ($all){
            	$user = $this->GetDataUserByUsername($_SESSION['username']);
            	$sql = str_replace('[FILTER_UNIT]', "WHERE (unitkerjaKodeSistem = '".$user['unitkerjaKodeSistem']."' OR unitkerjaKodeSistem LIKE '".$user['unitkerjaKodeSistem'].".%')", $sql);
            }else $sql = str_replace('[FILTER_UNIT]', '', $sql);
            return $this->Open($sql, array());
        }
   
   # multiunit
   function GetDataMutasi($tglAwal, $tglAkhir, $unitAsal, $unitTuj, $kodeBA){
            $user = $this->GetDataUserByUsername($_SESSION['username']);
            $sql = $this->mSqlQueries['get_data_mutasi'];
            if($unitTuj <> 'all' && $unitTuj <> '') $sql = str_replace('[SEARCH_UNIT_TUJUAN]','AND mtsAsetMstUnitIdTuj = '.$unitTuj,$sql);
            else $sql = str_replace('[SEARCH_UNIT_TUJUAN]','',$sql);
            if($unitAsal <> 'all'  && $unitAsal <> '') $sql = str_replace ('[SEARCH_UNIT_ASAL]', 'AND mtsAsetMstUnitIdAsal = '.$unitAsal, $sql);
            else $sql = str_replace ('[SEARCH_UNIT_ASAL]', '', $sql);
			
		$asdf = $this->Open($sql, array($tglAwal,$tglAkhir,'%'.$kodeBA.'%',$user['unitkerjaKodeSistem'],$user['unitkerjaKodeSistem'].".%"));
     // echo $this->GetLastError();
		return $asdf;
		
	}
	
   function GetDataMutasiRtf($kodeBA){
		$result = $this->Open($this->mSqlQueries['get_data_mutasi_rtf'], array('%'.$kodeBA.'%'));
      //echo $this->GetLastError();
		return $result;
		
	}
	
	function GetDataMutasiRtfByBA($kodeBA){
		$result = $this->Open($this->mSqlQueries['get_data_mutasi_rtf_by_ba'], array($kodeBA));
		return $result;
	}
   
   function GetDetilMutasi($MutasiId) {
      
		$return = $this->Open($this->mSqlQueries['get_detil_mutasi'], array($MutasiId));
		//echo $this->GetLastError();
		
		return $return;
   }

}
?>