<?php

class AppLaporanIndukInventaris extends Database {

   protected $mSqlFile= 'module/laporan_induk_inventaris/business/laporan_induk_inventaris.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 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 GetPenguasaanBarang(){
		return $this->Open($this->mSqlQueries['get_penguasaan_barang'],array());
	}
	
	function GetKondisiBarang(){
		return $this->Open($this->mSqlQueries['get_kondisi_barang'],array());
	}
	
	# multiunit
	function GetDataIndukInventaris($data){
	   $User = $this->GetDataUserByUsername($_SESSION['username']);
//		$user1 = $User['unitkerjaId']; 
//		$user2 = $User['unitkerjaId']; 
//		$user3 = $User['role_id'];
        $kodeSistem = $User['unitkerjaKodeSistem'];
		$sql = $this->Open($this->mSqlQueries['get_dyn_query'],array());
		
		$newSql = "";
		
		for($i=0;$i<count($sql);$i++){
		   $newSql .= $sql[$i]['DYN_QUERY'];
      }
      
      $newSql .= $this->mSqlQueries['get_dyn_query_additional'];
		
		$tglAwal = $data['tanggal_awal_year'].'-'.$data['tanggal_awal_mon'].'-'.$data['tanggal_awal_day'];
		$tglAkhir = $data['tanggal_akhir_year'].'-'.$data['tanggal_akhir_mon'].'-'.$data['tanggal_akhir_day'];
		
		return $this->Open($newSql,array($data['unit'],$data['unit'],$kodeSistem,$kodeSistem.'.%',/*$user1,$user2, $user3, */$tglAwal, $tglAkhir, $data['jenis_kib'], $data['jenis_kib']));
		//echo $this->GetLastError();
	}
	
	# 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'];
	}
}
?>
