<?php

class LaporanSp2d extends Database {

   protected $mSqlFile= 'module/laporan_sp2d/business/laporan_sp2d.sql.php';
   
   function __construct($connectionNumber=0) {
      parent::__construct($connectionNumber);
   }
   
	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 GetComboUnit(){
		$User = $this->GetDataUserByUsername($_SESSION['username']);		
		$array = array(
			$User['unitkerjaId'], $User['unitkerjaId'], $User['role_id']
		);
		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());
	}
	
	function GetDataInventaris($unitId,$barangId){
		$User = $this->GetDataUserByUsername($_SESSION['username']);
		$user1 = $User['unitkerjaId']; 
		$user2 = $User['unitkerjaId']; 
		$user3 = $User['role_id'];
	   $sql = $this->Open($this->mSqlQueries['get_dyn_query'],array());
		
		if($barangId=='')
		   $barangId='all';
		
		$newSql = "";
		
		for($i=0;$i<count($sql);$i++){
		   $newSql .= $sql[$i]['DYN_QUERY'];
      }
      
      $newSql .= $this->mSqlQueries['get_dyn_query_additional'];
		
		
	   return $this->Open($newSql,array($unitId,$unitId,$barangId,$barangId,$user1,$user2, $user3));
	}
}
?>
