<?php

//===GET===
$sql['combo_sumber_dana'] = "
SELECT
   sumberdanaId AS id,
   sumberdanaNama AS name
FROM
   sumber_dana_ref
ORDER BY sumberdanaNama
";

$sql['get_list_pengadaan_count'] = "
SELECT
   COUNT(*) as total
FROM
   pengadaan_mst
WHERE
   (pengadaanTahun = %s OR %s) AND
   pengadaanMAK LIKE %s AND
   (pengadaanSumberDanaId = %s OR %s) AND
   pengadaanNama LIKE %s AND
   pengadaanNoSPK LIKE %s AND
   pengadaanNominalPengadaan = (SELECT SUM(pengadaanDetTotalPerolehan) FROM pengadaan_detail WHERE pengadaanDetPengadaanMstId = pengadaanId GROUP BY pengadaanDetPengadaanMstId)
";

$sql['get_list_pengadaan'] = "
SELECT 
pengadaanId, pengadaanBAVerifikasi, pengadaanTglVerifikasi, pengadaanMAK, pengadaanNominalPengadaan, pengadaanNoSPK, pengadaanNama, mitraNama, jlrpengbrgNama,
CASE WHEN sum(status)/count(status)!= 1 AND sum(status)/count(status) != 3 THEN 2
WHEN sum(status)/count(status)= 1 THEN 1 
WHEN sum(status)/count(status)= 3 THEN 3 END AS `status`
FROM(
SELECT 
   pengadaanTglSPK, pengadaanSumberDanaId, pengadaanTahun, pengadaanId, pengadaanBAVerifikasi, pengadaanTglVerifikasi, pengadaanMAK, pengadaanNominalPengadaan, pengadaanNoSPK, pengadaanNama, mitraNama, jlrpengbrgNama,
   CASE WHEN pengadaanDetVerifikasi = 'Belum diperiksa' THEN 1
   WHEN pengadaanDetVerifikasi = 'sesuai' THEN 3
   WHEN pengadaanDetVerifikasi = 'tidak sesuai' THEN 2 END AS status
FROM pengadaan_mst 
   JOIN pengadaan_detail ON pengadaanId = pengadaanDetPengadaanMstId 
   LEFT JOIN jalur_pengadaan_barang_ref ON jlrpengbrgId = pengadaanJlrPengBrgId 
   LEFT JOIN mitra_ref ON mitraId = pengadaanMitraId 
) a 
WHERE
   (pengadaanTahun = %s OR %s) AND
   pengadaanMAK LIKE %s AND
   (pengadaanSumberDanaId = %s OR %s) AND
   pengadaanNama LIKE %s AND
   pengadaanNoSPK LIKE %s 
   -- AND pengadaanNominalPengadaan = (SELECT SUM(pengadaanDetTotalPerolehan) FROM pengadaan_detail WHERE pengadaanDetPengadaanMstId = pengadaanId GROUP BY pengadaanDetPengadaanMstId)
GROUP BY pengadaanId
ORDER BY
   status ASC,
   pengadaanTglSPK DESC
LIMIT %s, %s";
?>
