<?php
// mirip dengan DeliveryOrder.sql.php ['get_item_pengadaan_by_id']
//===GET===
$sql['combo_sumber_dana'] = "
	SELECT
	   sumberdanaId AS id,
	   sumberdanaNama AS name
	FROM
	   sumber_dana_ref
	ORDER BY sumberdanaNama
";

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

$sql['get_list_pengadaan_count'] = "
	SELECT 
	   COUNT(*) AS total 
	FROM
	   pengadaan_mst 
	   LEFT JOIN pengadaan_detail 
		  ON pengadaanDetPengadaanMstId = pengadaanId 
	WHERE pengadaanDetVerifikasi = 'sesuai' 
	   AND (pengadaanTahun = '%s' 
		  OR '%s') 
	   AND (
		  pengadaanSumberDanaId = '%s' 
		  OR '%s'
	   ) 
	   AND pengadaanNama LIKE '%s' 
	   AND pengadaanNoSPK LIKE '%s' 
";

$sql['get_list_pengadaan'] = "
	SELECT
	   SQL_CALC_FOUND_ROWS
	   pengadaanId,
	   pengadaanNoSPK,
	   pengadaanTglSPK,
	   pengadaanNama,
	   mitraNama,
	   jlrpengbrgNama,
	   pengadaanNominalPengadaan,
	   (SELECT SUM(pengadaanDetJmlAset) FROM pengadaan_detail WHERE pengadaanDetPengadaanMstId = pengadaanId) AS jmlPengadaan,
	   (SELECT COUNT(doDetId) FROM do_detail_new WHERE doDetMstPengadaanId = pengadaanId) AS jmlDO
	FROM
	   pengadaan_mst
	   LEFT JOIN pengadaan_detail ON pengadaanDetPengadaanMstId = pengadaanId
	   LEFT JOIN jalur_pengadaan_barang_ref ON jlrpengbrgId = pengadaanJlrPengBrgId
	   LEFT JOIN mitra_ref ON mitraId = pengadaanMitraId
	WHERE
	   (pengadaanTahun = '%s' OR '%s') AND
	   (pengadaanSumberDanaId = '%s' OR '%s') AND
	   pengadaanNama LIKE '%s' AND
	   pengadaanNoSPK LIKE '%s' AND
	   pengadaanDetVerifikasi = 'sesuai'
	GROUP BY
	   pengadaanId
	/* jika jumlah pengadaan dan do sama tidak ditampilkan */
	HAVING jmlPengadaan <> jmlDO 
	LIMIT %s, %s
";
?>
