<?php
$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,
   unitkerjaNama,
   userunitkerjaRoleId AS role_id,
   unitkerjaKodeSistem,
   unitkerjaKode
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['get_combo_gedung_old'] = "
	SELECT
		gedungId AS id,
		gedungNama AS name
	FROM 
		gedung
	LEFT JOIN unit_kerja_ref ON unitkerjaId = gedungUnitkerjaId
	WHERE
		gedungUnitkerjaId = %s OR unitkerjaParentId = %s OR '1' = %s
";

$sql['get_combo_gedung']="
SELECT
    a.gedungId AS id,
    a.gedungNama AS name
FROM (
        SELECT g1.* FROM gedung g1
   	LEFT JOIN unit_kerja_ref u1 ON u1.unitkerjaId = g1.gedungUnitkerjaId
   	WHERE (u1.unitkerjaKodeSistem = '%s' OR u1.unitkerjaKodeSistem LIKE '%s')
   	UNION
   	SELECT g2.* FROM gedung g2
   	LEFT JOIN ruang ON ruangGedungId = g2.gedungId
   	LEFT JOIN unit_kerja_ref u3 ON u3.unitkerjaId = g2.gedungUnitKerjaId
   	LEFT JOIN unit_kerja_ref u2 ON u2.unitkerjaId = ruangUnitId
   	WHERE (u3.unitkerjaKodeSistem != '%s' AND u3.unitkerjaKodeSistem NOT LIKE '%s') AND (u2.unitkerjaKodeSistem = '%s' OR u2.unitkerjaKodeSistem LIKE '%s')
    ) a          
";

$sql['get_combo_pic'] = "
	SELECT 
		ruangId AS id,
		CONCAT(ruangKode,' - ',ruangNama) AS name
	FROM ruang
        LEFT JOIN unit_kerja_ref ON unitkerjaId = ruangUnitId
	WHERE 
            ruangGedungId = '%s' AND (unitkerjaKodeSistem = '%s' OR unitkerjaKodeSistem LIKE '%s')
        
";

$sql['get_list_dir'] = "
	SELECT 
	   invDetId AS id,
	   gedungNama,
	   ruangNama,
	   unitkerjaKode,
	   unitkerjaNama,
	   CONCAT(
		  LPAD(golbrgKode, 1, '0'),
		  '.',
		  LPAD(bidangbrgKode, 2, '0'),
		  '.',
		  LPAD(kelbrgKode, 2, '0'),
		  '.',
		  LPAD(subkelbrgKode, 2, '0'),
		  '.',
		  LPAD(barangKode, 3, '0')
	   ) AS kode_barang,
	   barangNama AS nama_barang,
	   a.invMerek AS merk,
	   DATE_FORMAT(a.invTglPembelian, '%%Y') AS tahun_beli_buat,
	   COUNT(invDetId) AS jumlah_barang,
	   invDetKeteranganLain AS keterangan 
	FROM
	   inventarisasi_mst a 
	   LEFT JOIN barang_ref 
		  ON invBarangId = barangId 
	   LEFT JOIN sub_kelompok_barang_ref 
		  ON barangSubkelbrgId = subkelbrgId 
	   LEFT JOIN kelompok_barang_ref 
		  ON subkelbrgKelbrgId = kelbrgId 
	   LEFT JOIN bidang_barang_ref 
		  ON kelbrgBidangbrgId = bidangbrgId 
	   LEFT JOIN golongan_barang_ref 
		  ON bidangbrgGolbrgId = golbrgId 
	   LEFT JOIN inventarisasi_detail 
		  ON invDetMstId = invMstId 
	   INNER JOIN ruang 
		  ON invDetRuanganId = ruangId 
		  AND invDetRuanganId IS NOT NULL 
	   LEFT JOIN gedung 
		  ON ruangGedungId = gedungId 
	   LEFT JOIN unit_kerja_ref 
		  ON ruangUnitId = unitkerjaId 
	WHERE (ruangGedungId = '%s' 
		  OR 'all' = '%s') 
	   AND (invDetRuanganId = '%s' 
		  OR 'all' = '%s') 
	   AND (unitkerjaKodeSistem = '%s' OR unitkerjaKodeSistem LIKE '%s')
	   AND invDetAsetStatusId = 1 
	GROUP BY invBarangId,
	   a.invMerek,
	   tahun_beli_buat 
	ORDER BY a.invTglPembelian DESC 
";
?>
