<?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
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_unit'] = "
	SELECT 
		unitkerjaId AS id,
		unitkerjaNama AS name
	FROM unit_kerja_ref
	LEFT JOIN 
			inventarisasi_detail ON invDetUnitKerja = unitkerjaId
	WHERE
		invDetUnitKerja = %s OR unitkerjaParentId = %s OR '1' = %s
	GROUP BY id
	ORDER BY name
";

$sql['get_penguasaan_barang'] = "
	SELECT
		statuspengbrgId,
		statuspengbrgNama
	FROM 
		status_penguasaan_barang_ref
	ORDER BY statuspengbrgId
";

$sql['get_kondisi_barang'] = "
	SELECT
		kondisibrgId,
		kondisibrgNama
	FROM 
		kondisi_barang_ref
	ORDER BY kondisibrgId
";

$sql['get_combo_pic'] = "
	SELECT 
		ruangId AS id,
		CONCAT(ruangKode,' - ',ruangNama) AS name
	FROM ruang
	WHERE 
		ruangGedungId = '%s'
		";

$sql['get_combo_jenis_kib'] = "
SELECT
   golbrgId AS id,
   golbrgKibKode AS kode,
   golbrgNama AS name
FROM
   golongan_barang_ref
ORDER BY golbrgNama
";
		
$sql['get_list_kdp_old'] = "
	SELECT * FROM
   (SELECT 
      transKdpKppn AS kode_akun,
      CONCAT(
         SUBSTRING(a.transKdpKodeBarang, 1, 1),'.',
         SUBSTRING(a.transKdpKodeBarang, 2, 2),'.',
         SUBSTRING(a.transKdpKodeBarang, 4, 2),'.',
         SUBSTRING(a.transKdpKodeBarang, 6, 2),'.',
         SUBSTRING(a.transKdpKodeBarang, 8, 3)
      ) AS kode_barang,
      barangNama AS nama_barang,
      RIGHT(golbrgNama, LENGTH(golbrgNama) - 7) AS nama_golongan,
      IFNULL((SELECT SUM(transKdpNilaiAset) FROM aset_kdp_trans_kdp tr WHERE a.transKdpKodeBarang = tr.transKdpKodeBarang 
     	AND YEAR(tr.transKdpTanggalPembukuan) = '%s'
      ),0) AS saldo_awal,
      '' AS penambahan,
      '' AS aset_difinitif,
      IFNULL(
         (SELECT SUM(transKdpNilaiAset) 
   		FROM aset_kdp_trans_kdp tr 
         WHERE a.transKdpKodeBarang = tr.transKdpKodeBarang 
         AND YEAR(tr.transKdpTanggalPembukuan) = '%s'),0
      )+0+0 AS saldo_akhir,
      '' AS keterangan 
   FROM
      aset_kdp_trans_kdp a 
      JOIN golongan_barang_ref 
         ON golbrgKode = (
            SUBSTRING(a.transKdpKodeBarang, 1, 1) * 1
         ) 
      JOIN bidang_barang_ref 
         ON bidangbrgGolbrgId = golbrgId 
      JOIN kelompok_barang_ref 
         ON kelbrgBidangbrgId = bidangbrgId 
      JOIN sub_kelompok_barang_ref 
         ON subkelbrgKelbrgId = kelbrgId 
      JOIN barang_ref 
         ON barangSubkelbrgId = subkelbrgId 
   WHERE YEAR(transKdpTanggalPembukuan) = '%s' 
      AND transKdpKodeBarang = CONCAT(
         LPAD(golbrgKode, 1, 0),LPAD(bidangbrgKode, 2, 0),
         LPAD(kelbrgKode, 2, 0),LPAD(subkelbrgKode, 2, 0),
         LPAD(barangKode, 3, 0)
      )
   ) AS DYN_QUERY 
	GROUP BY kode_barang 
";

$sql['get_list_kdp'] = "
SELECT * FROM
(SELECT
transKdpKppn AS kode_akun,
CONCAT(
SUBSTRING(a.transKdpKodeBarang, 1, 1),'.',
SUBSTRING(a.transKdpKodeBarang, 2, 2),'.',
SUBSTRING(a.transKdpKodeBarang, 4, 2),'.',
SUBSTRING(a.transKdpKodeBarang, 6, 2),'.',
SUBSTRING(a.transKdpKodeBarang, 8, 3)
) AS kode_barang,
barangNama AS nama_barang,
RIGHT(golbrgNama, LENGTH(golbrgNama) - 7) AS nama_golongan,
IFNULL((SELECT SUM(transKdpNilaiAset) FROM aset_kdp_trans_kdp tr WHERE a.transKdpKodeBarang = tr.transKdpKodeBarang
AND YEAR(tr.transKdpTanggalPembukuan) <= '%s'
),0) AS saldo_awal,
'' AS penambahan,
'' AS aset_difinitif,
IFNULL(
(SELECT SUM(transKdpNilaiAset)
FROM aset_kdp_trans_kdp tr
WHERE a.transKdpKodeBarang = tr.transKdpKodeBarang
AND YEAR(tr.transKdpTanggalPembukuan) > '%s' AND YEAR(tr.transKdpTanggalPembukuan) <= '%s'),0
)+0+0 AS saldo_akhir,
'' AS keterangan
FROM
aset_kdp_trans_kdp a
JOIN golongan_barang_ref
ON golbrgKode = (
SUBSTRING(a.transKdpKodeBarang, 1, 1) * 1
)
JOIN bidang_barang_ref
ON bidangbrgGolbrgId = golbrgId
JOIN kelompok_barang_ref
ON kelbrgBidangbrgId = bidangbrgId
JOIN sub_kelompok_barang_ref
ON subkelbrgKelbrgId = kelbrgId
JOIN barang_ref
ON barangSubkelbrgId = subkelbrgId
WHERE YEAR(transKdpTanggalPembukuan) > '%s' AND YEAR(transKdpTanggalPembukuan) <= '%s'
AND transKdpKodeBarang = CONCAT(
LPAD(golbrgKode, 1, 0),LPAD(bidangbrgKode, 2, 0),
LPAD(kelbrgKode, 2, 0),LPAD(subkelbrgKode, 2, 0),
LPAD(barangKode, 3, 0)
)
) AS DYN_QUERY
GROUP BY kode_barang
";
?>
