<?php
$sql['get_data_ruang_sewa'] ="
	SELECT
	  SQL_CALC_FOUND_ROWS
	  ruangId   AS label_id,
	  ruangKode AS label_kode,
	  ruangNama AS label_nama,
	  CONCAT(gedungKode,' &raquo; ',gedungNama) AS label_gedung,
	  (SELECT unitkerjaKodeSistem FROM unit_kerja_ref WHERE unitkerjaId = ruangUnitId) AS kodeSistem
	FROM ruang
	  LEFT JOIN gedung
		 ON gedungId = ruangGedungId
	WHERE ruangNama LIKE '%s'
		 AND ruangKode LIKE '%s'
		 AND ruangId NOT IN (SELECT ruangBiayaSewaRuangId FROM aset_ref_sewa_ruang)
	HAVING (kodeSistem = '%s' OR kodeSistem LIKE '%s')
	ORDER BY ruangNama ASC
	LIMIT %s, %s
";

$sql['get_count']="
SELECT FOUND_ROWS() AS total
";

$sql['get_unit_kode_sistem_by_user_id']="
SELECT unitkerjaKodeSistem
FROM unit_kerja_ref
WHERE unitkerjaId = (SELECT userunitkerjaUnitkerjaId FROM user_unit_kerja WHERE userunitkerjaUserId = '%s')
";

$sql['get_data_ruang_sewa_count'] ="
	SELECT
		COUNT(DISTINCT(ruangId))    AS total
	FROM ruang
	  LEFT JOIN gedung
		 ON gedungId = ruangGedungId
	WHERE ruangNama LIKE '%s'
		 AND ruangKode LIKE '%s'
";

$sql['get_data_biaya_sewa_aset_count'] ="
	SELECT
		COUNT(DISTINCT(ruangBiayaSewaId)) AS total
	FROM aset_ref_sewa_ruang
		  LEFT JOIN ruang
			 ON ruangId = ruangBiayaSewaRuangId
		WHERE ruangBiayaSewaKode LIKE '%s'
			 AND ruangNama LIKE '%s'
	ORDER BY b.invMstLabel ASC 
";

$sql['get_data_biaya_sewa_aset'] = "
	SELECT
	  SQL_CALC_FOUND_ROWS
	  ruangBiayaSewaId       AS biaya_sewa_id,
	  ruangBiayaSewaKode     AS biaya_sewa_kode,
	  ruangNama              AS biaya_sewa_nama,
	  ruangBiayaSewaNilai    AS biaya_sewa,
	  ruangBiayaSewaStatusId AS biaya_sewa_status,
	  (SELECT unitkerjaKodeSistem FROM unit_kerja_ref WHERE unitkerjaId = ruangUnitId) AS kodeSistem
	FROM aset_ref_sewa_ruang
	  LEFT JOIN ruang
		 ON ruangId = ruangBiayaSewaRuangId
	WHERE ruangBiayaSewaKode LIKE '%s'
		 AND ruangNama LIKE '%s'
	HAVING (kodeSistem = '%s' OR kodeSistem LIKE '%s')
	ORDER BY ruangNama ASC
	LIMIT %s, %s
";

$sql['get_data_biaya_sewa_ruang_by_id'] = "
	SELECT
	  ruangBiayaSewaId       AS biaya_sewa_id,
	  ruangBiayaSewaKode     AS biaya_sewa_kode,
	  ruangNama              AS biaya_sewa_nama,
	  ruangKode              AS biaya_sewa_kode_ruang,
	  ruangId                AS biaya_sewa_nama_id,
	  ruangBiayaSewaNilai    AS biaya_sewa,
	  ruangBiayaSewaStatusId AS biaya_sewa_status
	FROM aset_ref_sewa_ruang
	  LEFT JOIN ruang
		 ON ruangId = ruangBiayaSewaRuangId
	WHERE ruangBiayaSewaId = '%s'
";

$sql['do_delete_biaya_sewa_ruang_by_array_id'] = "
	DELETE from aset_ref_sewa_ruang
   WHERE 
     ruangBiayaSewaId IN ('%s')
";

$sql['do_delete_biaya_sewa_ruang_by_id'] = "
	DELETE from aset_ref_sewa_ruang
   WHERE 
     ruangBiayaSewaId = '%s'
";

$sql['do_add_biaya_sewa_ruang'] = "
	INSERT aset_ref_sewa_ruang
	SET ruangBiayaSewaStatusId = '%s',
	  ruangBiayaSewaRuangId = '%s',
	  ruangBiayaSewaKode = '%s',
	  ruangBiayaSewaNilai = '%s',
	  ruangBiayaSewaTgl = NOW(),
	  ruangBiayaSewaUserId = '%s'
";

$sql['do_update_biaya_sewa_ruang'] = "
	UPDATE 
		aset_ref_sewa_ruang
	SET  
	  ruangBiayaSewaStatusId = '%s',
	  ruangBiayaSewaRuangId = '%s',
	  ruangBiayaSewaKode = '%s',
	  ruangBiayaSewaNilai = '%s',
	  ruangBiayaSewaTgl = NOW(),
	  ruangBiayaSewaUserId = '%s'
	WHERE
		ruangBiayaSewaId = '%s'
";
?>