<?php
class AppLapAset extends Database {

   protected $mSqlFile= 'module/laporan_aset_tak_berwujud/business/laporan_aset.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];
   }
	
	function GetCbxJenisKib() {
      $result = $this->Open($this->mSqlQueries['get_combo_jenis_kib'], array());
      foreach (array_keys($result) as $key)
      {
			if($result[$key]['kode'] == 'h') 
			$return[] = $result[$key];
		}
      return $return;
   }
	
	function GetComboUnit(){
            $User = $this->GetDataUserByUsername($_SESSION['username']);		
            $array = array(
            		$User['unitkerjaKodeSistem'],
                    $User['unitkerjaKodeSistem'].".%"
            );
            return $this->Open($this->mSqlQueries['get_combo_unit'], $array);
	}
	
	function GetComboPic($id){
		return $this->Open($this->mSqlQueries['get_combo_pic'],array($id));
	}
	
	function GetListAsetOld($data){
		$tahun = $data['tahun'];
		$tahunAwal = $tahun - 1;
	   $User = $this->GetDataUserByUsername($_SESSION['username']);
		$user1 = $User['unitkerjaId']; 
		$user2 = $User['unitkerjaId']; 
		$user3 = $User['role_id'];
      
      $result = $this->Open(
			$this->mSqlQueries['get_list_aset'],
				array(
					$tahunAwal, $tahunAwal, $tahunAwal, $tahunAwal, 
					$data['unit'],$data['unit'], 
					$user1,$user2, $user3, 
					$tahun, 
					$data['jenis_kib'], $data['jenis_kib']
				)
			);
			
		return $result;
	}
        
	# multiunit
        function GetListAset($data){
            $tahun = $data['tahun'];
	    //$tahunAwal = $data['tahunAwal'];
            $tahunAwal = $tahun - 1;
            $User = $this->GetDataUserByUsername($_SESSION['username']);
		
            $sql = $this->mSqlQueries['get_list_aset'];
            $sql = str_replace('[THN_AWAL]', $tahunAwal, $sql);
            $sql = str_replace('[THN_AKHIR]', $tahun, $sql);
            if($data['unit'] <> 'all' && $data['unit'] <> '') $sql = str_replace('[SEARCH_UNIT]', 'invDetUnitKerja = '.$data['unit'].' AND ', $sql);
            else $sql = str_replace('[SEARCH_UNIT]', '', $sql);
            if($data['jenis_kib'] <> 'all' && $data['jenis_kib'] <> '') $sql = str_replace('[SEARCH_GOLBRG]', 'golbrgId = '.$data['jenis_kib'].' AND', $sql);
            else $sql = str_replace('[SEARCH_GOLBRG]', '', $sql);

            $result = $this->Open($sql,array($User['unitkerjaKodeSistem'],$User['unitkerjaKodeSistem'].'.%'));

            return $result;
        }
	
	function GetCountAsetdata($data){
		$tahun = $data['tahun'];
		$tahunAwal = $tahun - 1;
	   $User = $this->GetDataUserByUsername($_SESSION['username']);
		$user1 = $User['unitkerjaId']; 
		$user2 = $User['unitkerjaId']; 
		$user3 = $User['role_id'];
      
      $resutl = $this->Open(
			$this->mSqlQueries['get_list_aset'],
				array(
					$data['unit'],$data['unit'], 
					$user1,$user2, $user3, 
					$tahun, 
					$data['jenis_kib'], $data['jenis_kib']
				)
			);
			
		return $result;
	}
	
	# multiunit
	function GetDataUnitkerja ($offset, $limit, $unitkerja='', $kode='') {
		$User = $this->GetDataUserByUsername($_SESSION['username']);
		$kodeSistem = $User['unitkerjaKodeSistem'];
		$result = $this->Open($this->mSqlQueries['get_data_unitkerja'], array('%'.$kode.'%', '%'.$kode.'%', '%'.$unitkerja.'%', '%'.$unitkerja.'%', $kodeSistem,$kodeSistem.".%", $offset, $limit));
	
		return $result;
	}
	
	function GetCount(){
		$result = $this->Open($this->mSqlQueries['get_count'],array());
		return $result[0]['total'];
	}
}
?>
