<?php
	$sql['get_combo_peruntukan_tanah_ref'] ="
		SELECT 
			peruntukanTanahId AS id,
			peruntukanTanahNama AS `name` 
		FROM
			peruntukan_tanah_ref 
	";
	
	$sql['get_combo_status_aset'] = "
		SELECT
		  statusAsetId   AS id,
		  statusAsetNama AS `name`
		FROM 
			aset_ref_aset_status
		WHERE statusAsetIsAktif = 'Y'
	";
	
	$sql['get_data_last_number'] ="
		SELECT 
		   CONCAT(
			  invDetKodeBarang,
			  '.',
			  invPeruntukanTnhKode
		   ) AS kode 
		FROM
		   inventarisasi_mst a 
		   LEFT JOIN inventarisasi_detail b 
			  ON a.invMstId = b.invDetMstId 
		   LEFT JOIN barang_ref c 
			  ON a.invBarangId = barangId 
		   JOIN sub_kelompok_barang_ref i 
			  ON barangSubkelbrgId = subkelbrgId 
		   JOIN kelompok_barang_ref j 
			  ON subkelbrgKelbrgId = kelbrgId 
		   JOIN bidang_barang_ref k 
			  ON kelbrgBidangbrgId = bidangbrgId 
		   JOIN golongan_barang_ref l 
			  ON bidangbrgGolbrgId = golbrgId 
		   JOIN inv_peruntukan_tanah 
			  ON invPeruntukanTnhInvDetId = invDetId 
		WHERE (l.golbrgKibKode = 'a') 
		   AND (
			  invDetKodeBarang
			  = '%s'
		   ) 
		ORDER BY `kode` DESC 
		LIMIT 1 
   ";
   
   $sql['get_data_inventarisasi_tanah'] ="
		SELECT 
		   SQL_CALC_FOUND_ROWS invPeruntukanTnhId AS idTanah,
		   invPeruntukanTnhInvDetId AS invdet,
		   b.invDetMstLabel AS nama_aset,
		   invPeruntukanTnhKode AS kodeinv,
		   peruntukanTanahNama AS peruntukan,
		   invPeruntukanTnhPanjang AS panjang,
		   invPeruntukanTnhLebar AS lebar,
		   invPeruntukanTnhLuas AS luas,
		   statusAsetNama AS penggunaan,
		   CONCAT(
			  invDetKodeBarang,
			  '.',
			  invPeruntukanTnhKode
		   ) AS kode 
		FROM
		   inventarisasi_mst a 
		   LEFT JOIN inventarisasi_detail b 
			  ON a.invMstId = b.invDetMstId 
		   LEFT JOIN barang_ref c 
			  ON a.invBarangId = barangId 
		   JOIN sub_kelompok_barang_ref i 
			  ON barangSubkelbrgId = subkelbrgId 
		   JOIN kelompok_barang_ref j 
			  ON subkelbrgKelbrgId = kelbrgId 
		   JOIN bidang_barang_ref k 
			  ON kelbrgBidangbrgId = bidangbrgId 
		   JOIN golongan_barang_ref l 
			  ON bidangbrgGolbrgId = golbrgId 
		   JOIN inv_peruntukan_tanah 
			  ON invPeruntukanTnhInvDetId = invDetId 
		   JOIN peruntukan_tanah_ref 
			  ON invPeruntukanTnhPrtknTnhId = peruntukanTanahId 
		   JOIN aset_ref_aset_status 
			  ON statusAsetId = invPeruntukanTnhStatusAsetId 
		WHERE (l.golbrgKibKode = 'a') 
		   AND (
			  b.invDetMstLabel LIKE '%s' 
			  OR CONCAT(
					invDetKodeBarang,
				 '.',
				 invPeruntukanTnhKode
			  ) LIKE '%s'
		   ) 
		ORDER BY kode 
		LIMIT %s, %s
		
   ";
   
   $sql['get_data_inventarisasi_tanah_count'] = "
		SELECT FOUND_ROWS() AS total
	";
   
   $sql['get_inventarisasi_tanah_by_id'] ="
		SELECT 
		   invPeruntukanTnhInvDetId AS invdet,
		   b.invDetMstLabel AS nama_aset,
		   invPeruntukanTnhKode AS kodeinv,
		   invPeruntukanTnhPrtknTnhId AS peruntukan,
		   invPeruntukanTnhPanjang AS panjang,
		   invPeruntukanTnhLebar AS lebar,
		   invPeruntukanTnhLuas AS luas,
		   invPeruntukanTnhStatusAsetId AS penggunaan,
		   invPeruntukanTnhKeterangan AS keterangan,
		   invDetKodeBarang AS kode,
		   a.invLuasTanah AS luasHidden,
		   invPeruntukanTnhAlamat AS alamat,
		   invPeruntukanTnhKodePemerintah AS kodepemerintah,
		   invPeruntukanTnhPj AS unitnama,
		   invPeruntukanTnhNoSertipikat AS sertipikat 
		FROM
		   inventarisasi_mst a 
		   LEFT JOIN inventarisasi_detail b 
			  ON a.invMstId = b.invDetMstId 
		   LEFT JOIN barang_ref c 
			  ON a.invBarangId = barangId 
		   JOIN sub_kelompok_barang_ref i 
			  ON barangSubkelbrgId = subkelbrgId 
		   JOIN kelompok_barang_ref j 
			  ON subkelbrgKelbrgId = kelbrgId 
		   JOIN bidang_barang_ref k 
			  ON kelbrgBidangbrgId = bidangbrgId 
		   JOIN golongan_barang_ref l 
			  ON bidangbrgGolbrgId = golbrgId 
		   JOIN inv_peruntukan_tanah 
			  ON invPeruntukanTnhInvDetId = invDetId 
		WHERE (l.golbrgKibKode = 'a') 
		   AND invPeruntukanTnhId = '%s' 
		LIMIT 1
   ";
   
	$sql['get_data_popup_tanah'] = "
		SELECT 
		   SQL_CALC_FOUND_ROWS b.invDetId AS id,
		   invDetKodeBarang AS KIB,
		   a.invBarangId AS id_barang,
		   c.barangKode AS kode_barang,
		   b.invDetMstLabel AS nama_aset,
		   CONCAT(
			  kampusNama,
			  IF(
				 gedungNama IS NULL,
				 '',
				 CONCAT(
					'@@',
					gedungNama,
					IF(
					   ruangNama IS NULL,
					   '',
					   CONCAT('@@', ruangNama)
					)
				 )
			  )
		   ) AS lokasi_aset,
		   e.unitkerjaNama AS unit_pj,
		   LEFT(b.invDetTglPembelian, 4) AS thn_pengadaan,
		   IF(
			  mstPenystnNilaiPerolehan IS NOT NULL,
			  mstPenystnNilaiPerolehan,
			  IF(
				 b.invDetNilaiPerolehanSatuan IS NULL,
				 a.invTotalPerolehan,
				 b.invDetNilaiPerolehanSatuan
			  )
		   ) AS nilai_perolehan,
		   IF(
			  mstPenystnDisusutkan IS NOT NULL,
			  mstPenystnDisusutkan,
			  IF(
				 b.invDetNilaiPerolehanSatuan IS NULL,
				 a.invTotalPerolehan,
				 b.invDetNilaiPerolehanSatuan
			  )
		   ) AS nilai_buku,
		   f.kepemilikanbrgNama AS status_kepemilikan,
		   h.kondisibrgNama AS kondisi,
		   golbrgId AS golBarang,
		   invLuasTanah AS luas,
		   invDetKeteranganLain AS keterangan,
		   invDetAsetStatusId AS penggunaan 
		FROM
		   inventarisasi_mst a 
		   LEFT JOIN inventarisasi_detail b 
			  ON a.invMstId = b.invDetMstId 
		   LEFT JOIN barang_ref c 
			  ON a.invBarangId = barangId 
		   LEFT JOIN kampus_ref d 
			  ON b.invDetKampus = d.kampusId 
		   LEFT JOIN unit_kerja_ref e 
			  ON b.invDetUnitKerja = e.unitkerjaId 
		   LEFT JOIN kepemilikan_barang_ref f 
			  ON f.kepemilikanbrgId = b.invDetKepemilikan 
		   LEFT JOIN kondisi_barang_ref h 
			  ON h.kondisibrgId = b.invDetKondisiId 
		   JOIN sub_kelompok_barang_ref i 
			  ON barangSubkelbrgId = subkelbrgId 
		   JOIN kelompok_barang_ref j 
			  ON subkelbrgKelbrgId = kelbrgId 
		   JOIN bidang_barang_ref k 
			  ON kelbrgBidangbrgId = bidangbrgId 
		   JOIN golongan_barang_ref l 
			  ON bidangbrgGolbrgId = golbrgId 
		   LEFT JOIN gedung 
			  ON invDetGedungId = gedungId 
		   LEFT JOIN ruang 
			  ON invDetRuanganId = ruangId 
		   LEFT JOIN penyusutan_brg_mst 
			  ON invDetId = mstPenystnBarangId 
		   JOIN aset_ref_aset_status 
			  ON statusAsetId = b.invDetAsetStatusId 
		WHERE (l.golbrgKibKode = 'a') 
		   AND (
			  b.invDetMstLabel LIKE '%s' 
			  OR invDetKodeBarang
			   LIKE '%s'
		   ) 
		   AND (
			  invDetUnitKerja = '%s' 
			  OR e.unitkerjaParentId = '%s' 
			  OR '1' = '%s'
		   ) 
		ORDER BY b.invDetTglPembelian DESC 
		LIMIT %s, %s
	";
	
	$sql['get_data_popup_tanah_count'] = "
		SELECT FOUND_ROWS() AS total
	";
	
	$sql['get_data_user_by_user_name'] = "
		SELECT
			UserId AS user_id,
			UserName AS user_name,
			RealName AS real_name,
			a.Description AS description,
			Active AS is_active,
			a.GroupId AS group_id,
			GroupName AS group_name,
			unitkerjaId AS unit_kerja_id,
			unitkerjaNama  AS unit_kerja_nama,
			userunitkerjaRoleId AS role_id
		FROM
			gtfw_user a
			JOIN gtfw_group b ON b.GroupId = a.GroupId
			LEFT JOIN user_unit_kerja ON UserId = userunitkerjaUserId
			LEFT JOIN unit_kerja_ref ON unitkerjaId = userunitkerjaUnitkerjaId
		WHERE
			UserName = %s
	";

	$sql['add_inventarisasi_tanah'] = "
		INSERT INTO
			inv_peruntukan_tanah
		SET
			invPeruntukanTnhInvDetId = '%s',
			invPeruntukanTnhKode = '%s',
			invPeruntukanTnhPrtknTnhId = '%s',
			invPeruntukanTnhPanjang = '%s',
			invPeruntukanTnhLebar = '%s',
			invPeruntukanTnhLuas = '%s',
			invPeruntukanTnhStatusAsetId = '%s',
			invPeruntukanTnhKeterangan = '%s',
			invPeruntukanTnhAlamat = '%s',
			invPeruntukanTnhKodePemerintah = '%s',
			invPeruntukanTnhPj = '%s',
			invPeruntukanTnhNoSertipikat = '%s',
			invPeruntukanTnhUserId = '%s',
			invPeruntukanTnhTglUbah = NOW()
	";
	
	$sql['update_inventarisasi_tanah'] = "
		UPDATE
			inv_peruntukan_tanah
		SET
			invPeruntukanTnhInvDetId = '%s',
			invPeruntukanTnhPrtknTnhId = '%s',
			invPeruntukanTnhPanjang = '%s',
			invPeruntukanTnhLebar = '%s',
			invPeruntukanTnhLuas = '%s',
			invPeruntukanTnhStatusAsetId = '%s',
			invPeruntukanTnhKeterangan = '%s',
			invPeruntukanTnhAlamat = '%s',
			invPeruntukanTnhKodePemerintah = '%s',
			invPeruntukanTnhPj = '%s',
			invPeruntukanTnhNoSertipikat = '%s',
			invPeruntukanTnhUserId = '%s',
			invPeruntukanTnhTglUbah = NOW()
		WHERE 
			invPeruntukanTnhId = '%s'		
	";
	
	$sql['delete_inventarisasi_tanah'] = "
		DELETE FROM inv_peruntukan_tanah WHERE invPeruntukanTnhId = '%s'		
	";
?>
