<?php

class Pengelolaan extends Database {

	protected $mSqlFile;
	
	function __construct($connectionNumber=0) {
		$this->mSqlFile = 'module/'.Dispatcher::Instance()->mModule.'/business/pengelolaan.sql.php';
		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,$bulan='',$tahun='') {
		$User = $this->GetDataUserByUsername($_SESSION['username']);
		$kodeSistem = $User['unitkerjaKodeSistem']; 
		$sql = $this->mSqlQueries['get_data_pengelolaan'];
		$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($kodeSistem,$kodeSistem.'.%','%'.$notrans.'%',$offset, $limit));		
		return $result;
	}
	
	function GetCount(){
		$result = $this->Open($this->mSqlQueries['get_count'],array());
		return $result[0]['total'];
	}
}

?>