<?php

class Pengelolaan extends Database {

	protected $mSqlFile= 'module/laporan_pengelolaan_bhp/business/pengelolaan.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_user_name'], array($name));  
      $this->mUserByUserName[$name] = $result[0];
      
		return $result[0];
   }
	
    # multiunit
	function GetDataPengelolaan ($offset, $limit, $notrans, $id, $setting='',$bulan='',$tahun='') {
		$User = $this->GetDataUserByUsername($_SESSION['username']);
		$kodeSistem = $User['unitkerjaKodeSistem']; 
		$sql = $this->mSqlQueries['get_data_lelang_barang'];
		$sql = ($id <> '') ? str_replace('[SEARCH_UNIT]',"AND unitkerjaId = $id ",$sql) : str_replace('[SEARCH_UNIT]',"",$sql) ;
		$sql = ($bulan <> '') ? str_replace('[SEARCH_MONTH]', ' AND MONTH(transAtkMstTglEntry) = '.$bulan, $sql) : str_replace('[SEARCH_MONTH]',"",$sql);
		$sql = ($tahun <> '') ? str_replace('[SEARCH_YEAR]', ' AND YEAR(transAtkMstTglEntry) = '.$tahun, $sql) : str_replace('[SEARCH_YEAR]',"",$sql);
		$result = $this->Open($sql, array('%'.$notrans.'%', $kodeSistem,$kodeSistem.'.%',$setting, $offset, $limit));		
		return $result;
	}
	
	function GetCountDataPengelolaan($notrans, $id, $setting='') {
		$User = $this->GetDataUserByUsername($_SESSION['username']);
		$user1 = $User['unitkerjaId']; 
		$user2 = $User['unitkerjaId']; 
		$user3 = $User['role_id'];
		$result = $this->Open($this->mSqlQueries['get_count_data_lelang_barang'], array('%'.$notrans.'%', $user1, $user2, $user3, $id, $id, $setting));
		
		if (!$result) 
		{
			return 0;
		} 
			else 
		{
			return $result[0]['total'];
		}
	}
	
	function GetDataPengelolaanById ($id) {
		$result = $this->Open($this->mSqlQueries['get_data_pengelolaan_by_id'], array($id));
		
		return $result;
	}
}
?>