<?php
class InventarisasiTanah extends Database {

   protected $mSqlFile= 'module/inventarisasi_tanah/business/inventarisasi_tanah.sql.php';
   
   function __construct($connectionNumber=0) {
      parent::__construct($connectionNumber);
   }
   
   public function GetComboPeruntukan(){
   	$return = $this->Open($this->mSqlQueries['get_combo_peruntukan_tanah_ref'], array());
   	return $return;
   }
   
   public function GetComboStatusPenggunaan(){
   	$return = $this->Open($this->mSqlQueries['get_combo_status_aset'], array());
   	return $return;
   }
   
   public function GenerateNumber($kode)
   {
		$gnumber = $this->Open($this->mSqlQueries['get_data_last_number'], array($kode));
		$explode = explode(".", $gnumber[0]['kode']);
		$lenght 	= strlen(intval($explode[5]+1));
		switch($lenght){
			case 1: $generate = '00000'.($explode[5]+1); break;
			case 2: $generate = '0000'.($explode[5]+1); break;
			case 3: $generate = '000'.($explode[5]+1); break;
			case 4: $generate = '00'.($explode[5]+1); break;
			case 5: $generate = '0'.($explode[5]+1); break;
			case 6: $generate = ($explode[5]+1); break;
		}
		return $generate;
   }
   
   public 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];
   }
   
   public function GetPopupInventarisasiTanah($keyword, $start, $end)
   {
   	$User = $this->GetDataUserByUsername($_SESSION['username']);
   	$arrData = array(
   		"%$keyword%", "%$keyword%", $User['unit_kerja_id'], $User['unit_kerja_id'], $User['role_id'], $start, $end
   	);
		$result = $this->Open($this->mSqlQueries['get_data_popup_tanah'], $arrData);
		return $result;
   }
   
   
   public function GetPopupInventarisasiTanahCount()
   {
		$result = $this->Open($this->mSqlQueries['get_data_popup_tanah_count'], array());
		return $result[0]['total'];
   }
   
   public function GetInventarisasiTanah($keyword, $start, $end)
   {
   	$arrData = array(
   		"%$keyword%", "%$keyword%", $start, $end
   	);
		$result = $this->Open($this->mSqlQueries['get_data_inventarisasi_tanah'], $arrData);
		return $result;
   }
   
   
   public function GetInventarisasiTanahCount()
   {
		$result = $this->Open($this->mSqlQueries['get_data_inventarisasi_tanah_count'], array());
		return $result[0]['total'];
   }
   
   public function GetInventarisasiTanahById($id)
   {
		$result = $this->Open($this->mSqlQueries['get_inventarisasi_tanah_by_id'], array($id));
		return $result[0];
   }
   
   public function AddInventarisasiTanah($data){
   	extract($data);
   	
   	$generate = $this->GenerateNumber($kode);
   	$userId = trim(Security::Instance()->mAuthentication->GetCurrentUser()->GetUserId());
   	
   	$arrData = array(
   		$invdet,
   		$generate,
   		$peruntukan,
   		$panjang,
   		$lebar,
   		$luas,
   		$penggunaan,
   		$keterangan,
   		$alamat,
   		$kodepemerintah,
   		$unitnama,
   		$sertipikat,
   		$userId	
   	);

		$result = $this->Execute($this->mSqlQueries['add_inventarisasi_tanah'], $arrData);
   	return $result;
   }
   
   public function UpdateInventarisasiTanah($data, $id){
   	extract($data);

   	$userId = trim(Security::Instance()->mAuthentication->GetCurrentUser()->GetUserId());
   	
   	$arrData = array(
   		$invdet,
   		$peruntukan,
   		$panjang,
   		$lebar,
   		$luas,
   		$penggunaan,
   		$keterangan,
   		$alamat,
   		$kodepemerintah,
   		$unitnama,
   		$sertipikat,
   		$userId,
   		$id
   	);
   	
		$result = $this->Execute($this->mSqlQueries['update_inventarisasi_tanah'], $arrData);
   	return $result;
   }
   
   public function DeleteInventarisasiTanah($id){
   	
   	$arrData = array(
   		$id
   	);
   	
		$result = $this->Execute($this->mSqlQueries['delete_inventarisasi_tanah'], $arrData);
   	return $result;
   }
}
?>
