<?php
$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_barang_sewa'] ="
	SELECT
	   SQL_CALC_FOUND_ROWS 
	   invDetId AS label_id,
	   invDetKodeBarang AS label_kode,
	   invDetMstLabel AS label_nama,
	   CONCAT(
		  kampusNama,
		  IF(
			 gedungNama IS NULL,
			 '',
			 CONCAT(
				'<br/>&raquo;',
				gedungNama,
				IF(
				   ruangNama IS NULL,
				   '',
				   CONCAT('<br/>&raquo;', ruangNama)
				)
			 )
		  )
	   ) AS label_lokasi,
	   kepemilikanbrgNama AS label_pemilik,
	   kondisibrgNama AS label_kondisi ,
	   (SELECT unitkerjaKodeSistem FROM unit_kerja_ref WHERE unitkerjaId = invDetUnitKerja) AS kodeSistem
	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 kepemilikan_barang_ref f 
		  ON f.kepemilikanbrgId = b.invDetKepemilikan 
	   JOIN kondisi_barang_ref h 
		  ON h.kondisibrgId = b.invDetKondisiId 
	   LEFT JOIN gedung 
		  ON invDetGedungId = gedungId 
	   LEFT JOIN ruang 
		  ON invDetRuanganId = ruangId 
	WHERE invDetMstLabel LIKE '%s'
	   AND invDetKondisiId NOT IN ('3', '4')
	   AND invDetKodeBarang LIKE '%s' 
	   AND invDetAsetStatusId = 1 
	   AND invDetId NOT IN (SELECT invBiayaSewaInvId FROM aset_ref_biaya_sewa)
	HAVING (kodeSistem = '%s' OR kodeSistem LIKE '%s')
	LIMIT %s, %s
";

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

$sql['get_data_barang_sewa_count'] ="
	SELECT 
	   COUNT(*) AS total 
	FROM
	   inventarisasi_detail 
	   LEFT JOIN inventarisasi_mst 
		  ON invMstId = invDetMstId 
	WHERE invDetMstLabel LIKE '%s' 
	   AND invDetKondisiId NOT IN ('3', '4') 
	   AND invDetKodeBarang LIKE '%s' 
	   AND invDetAsetStatusId = 1 
";

$sql['get_data_biaya_sewa_aset_count'] ="
	SELECT 
	   COUNT(*) AS total 
	FROM
	   aset_ref_biaya_sewa s 
	   LEFT JOIN inventarisasi_detail b 
		  ON b.invDetId = s.invBiayaSewaInvId 
	WHERE invBiayaSewaKode LIKE '%s' 
	   AND invDetMstLabel LIKE '%s'  
";

$sql['get_data_biaya_sewa_aset'] = "
	SELECT
	   SQL_CALC_FOUND_ROWS 
	   invBiayaSewaId AS biaya_sewa_id,
	   invBiayaSewaKode AS biaya_sewa_kode,
	   invDetKodeBarang AS biaya_sewa_kode_aset,
	   invDetMstLabel AS biaya_sewa_label,
	   invBiayaSewaNilai AS biaya_sewa,
	   invBiayaSewaTerlambat AS biaya_sewa_terlambat,
	   invBiayaSewaRusak AS biaya_sewa_rusak,
	   invBiayaSewaGanti AS biaya_sewa_denda,
	   (SELECT unitkerjaKodeSistem FROM unit_kerja_ref WHERE unitkerjaId = b.invDetUnitKerja) AS kodeSistem 
	FROM
	   aset_ref_biaya_sewa s 
	   LEFT JOIN inventarisasi_detail b 
		  ON b.invDetId = s.invBiayaSewaInvId 
	WHERE invBiayaSewaKode LIKE '%s' 
	   AND b.invDetMstLabel LIKE '%s' 
	HAVING (kodeSistem = '%s' OR kodeSistem LIKE '%s')
	ORDER BY b.invDetMstLabel ASC  
	LIMIT %s, %s
";

$sql['get_data_biaya_sewa_aset_by_id'] = "
	SELECT 
	   invBiayaSewaId AS biaya_sewa_id,
	   invBiayaSewaKode AS biaya_sewa_kode,
	   invDetKodeBarang AS biaya_sewa_kode_aset,
	   invDetMstLabel AS biaya_sewa_label,
	   invBiayaSewaInvId AS biaya_sewa_label_id,
	   invBiayaSewaNilai AS biaya_sewa,
	   invBiayaSewaTerlambat AS biaya_sewa_terlambat,
	   invBiayaSewaRusak AS biaya_sewa_rusak,
	   invBiayaSewaGanti AS biaya_sewa_denda 
	FROM
	   aset_ref_biaya_sewa s 
	   LEFT JOIN inventarisasi_detail b 
		  ON b.invDetId = s.invBiayaSewaInvId 
	WHERE invBiayaSewaId = '%s' 
";

$sql['do_delete_biaya_sewa_aset_by_array_id'] = "
	DELETE from aset_ref_biaya_sewa
   WHERE 
     invBiayaSewaId IN ('%s')
";

$sql['do_delete_biaya_sewa_aset_by_id'] = "
	DELETE from aset_ref_biaya_sewa
   WHERE 
     invBiayaSewaId = '%s'
";

$sql['do_add_biaya_sewa_aset'] = "
	INSERT INTO aset_ref_biaya_sewa (
		invBiayaSewaInvId,
        invBiayaSewaKode,
        invBiayaSewaNilai,
        invBiayaSewaTerlambat,
		invBiayaSewaRusak,
		invBiayaSewaGanti,
		invBiayaSewaTgl,
		invBiayaSewaUserId
	) VALUES (
      '%s',
      '%s',
      '%s',
      '%s',
      '%s',
      '%s',
      NOW(),
      '%s'
	)
";

$sql['do_update_biaya_sewa_aset'] = "
	UPDATE 
		aset_ref_biaya_sewa 
	SET  
		invBiayaSewaInvId = '%s',
        invBiayaSewaKode = '%s',
        invBiayaSewaNilai = '%s',
        invBiayaSewaTerlambat = '%s',
		invBiayaSewaRusak = '%s',
		invBiayaSewaGanti = '%s',
		invBiayaSewaTgl = NOW(),
		invBiayaSewaUserId = '%s'
	WHERE
		invBiayaSewaId = '%s'
";
?>
