<?php
$sql['combo_jenis_barang'] = "
	SELECT
	  jenisbrgId   AS id,
	  jenisbrgNama AS `name`
	FROM jenis_barang_ref
";

$sql['combo_jalur_pengadaan'] = "
	SELECT
		jlrpengbrgId AS id,
		jlrpengbrgNama AS name
	FROM
		jalur_pengadaan_barang_ref
";

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

$sql['combo_mitra_kerja'] = "
	SELECT
		mitraId AS id,
		mitraNama AS name
	FROM
		mitra_ref
	ORDER BY
		mitraNama
";

$sql['get_pengadaan_barang'] = "
	SELECT
	  pengadaanBrgId    AS pengadaanId,
	  pengadaanBrgNomor AS pengadaanNomor,
	  jlrpengbrgNama    AS pengadaanJalur,
	  mitraNama         AS pengadaanMitra
	FROM aset_pb_pengadaan_brg
	  JOIN jalur_pengadaan_barang_ref
		 ON jlrpengbrgId = pengadaanBrgJalurPengadaanId
	  JOIN mitra_ref
		 ON mitraId = pengadaanBrgMitraId
	WHERE (jlrpengbrgId = '%s' or 'all' = '%s') AND pengadaanBrgNomor LIKE '%s'
	ORDER BY pengadaanBrgId DESC
	LIMIT %d, %d
";

$sql['get_pengadaan_barang_count'] = "
	SELECT
	  count(pengadaanBrgId)    AS total
	FROM aset_pb_pengadaan_brg
	  JOIN jalur_pengadaan_barang_ref
		 ON jlrpengbrgId = pengadaanBrgJalurPengadaanId
	  JOIN mitra_ref
		 ON mitraId = pengadaanBrgMitraId
	WHERE (jlrpengbrgId = '%s' or 'all' = '%s') AND pengadaanBrgNomor LIKE '%s'
";

$sql['get_pengadaan_barang_by_id'] = "
	SELECT
	  pengadaanBrgId                AS pengadaanId,
	  jenisbrgId                    AS jenis_barang,
	  jenisbrgNama                  AS namaJenisBrg,
	  pengadaanBrgMAKId             AS pengadaanMAKId,
	  pengadaanBrgMak               AS pengadaanMakNama,
	  pengadaanBrgNomor             AS nomorPengadaan,
	  pengadaanBrgTanggalPengadaan  AS pengadaanTglSPK,
	  pengadaanBrgJalurPengadaanId  AS pengadaanJlrPengBrgId,
	  jlrpengbrgNama                AS pengadaanJalur,
	  pengadaanBrgSumberDanaId      AS pengadaanSumberdanaId,
	  sumberdanaNama                AS sumberDanaNama,
	  mitraId                       AS pengadaanMitraId,
	  mitraNama                     AS pengadaanMitra,
	  pengadaanBrgPIC               AS pic,
	  pengadaanBrgDetId,
	  CONCAT(LPAD(golbrgKode, 1, '0'), '.', LPAD(bidangbrgKode, 2, '0'), '.', LPAD(kelbrgKode, 2, '0'), '.', LPAD(subkelbrgKode, 2, '0'), '.', LPAD(barangKode, 3, '0')) AS `brgKode`,
	  barangNama                    AS brgNama,
	  pengadaanBrgDetUsulanBrgDetId AS brgId,
	  pengadaanBrgDetJmlhPengadaan  AS brgNilaiSat,
	  pengadaanBrgDetNominalSatuan  AS brgNominalSat,
	  pengadaanBrgDetNominalVat     AS brgNominalVat,
	  pengadaanBrgDetProsentVat	  AS brgProsenVat
	FROM aset_pb_pengadaan_brg
	  LEFT JOIN aset_pb_pengadaan_brg_detil
		 ON pengadaanBrgDetPengadaanBrgId = pengadaanBrgId
	  LEFT JOIN aset_pb_usulan_brg_det
		 ON usulanBrgDetId = pengadaanBrgDetUsulanBrgDetId
	  JOIN jalur_pengadaan_barang_ref
		 ON jlrpengbrgId = pengadaanBrgJalurPengadaanId
	  JOIN mitra_ref
		 ON mitraId = pengadaanBrgMitraId
	  JOIN sumber_dana_ref
		 ON sumberdanaId = pengadaanBrgSumberDanaId
	  JOIN jenis_barang_ref
		 ON jenisbrgId = pengadaanBrgJnsBarangId
	  LEFT JOIN barang_ref
		 ON barangId = usulanBrgDetBrgId
	  LEFT JOIN sub_kelompok_barang_ref
		 ON subkelbrgId = barangSubkelbrgId
	  LEFT JOIN kelompok_barang_ref
		 ON kelbrgId = subkelbrgKelbrgId
	  LEFT JOIN bidang_barang_ref
		 ON bidangbrgId = kelbrgBidangbrgId
	  LEFT JOIN golongan_barang_ref
		 ON golbrgId = bidangbrgGolbrgId
	WHERE 
		pengadaanBrgId = %d
";

# sql do here
$sql['add_pengadaan_barang'] = "
	INSERT INTO 
		aset_pb_pengadaan_brg
	SET 
		pengadaanBrgNomor = '%s',
		pengadaanBrgTanggalPengadaan = '%s',
		pengadaanBrgJnsBarangId = '%s',
		pengadaanBrgMAKId = '%s',
		pengadaanBrgMak = '%s',
		pengadaanBrgJalurPengadaanId = '%s',
		pengadaanBrgSumberDanaId = '%s',
		pengadaanBrgMitraId = '%s',
		pengadaanBrgPIC = '%s',
		pengadaanBrgTgl = NOW(),
		pengadaanBrgUserId = '%d'
";

$sql['add_pengadaan_barang_detil'] = "
	INSERT INTO 
		aset_pb_pengadaan_brg_detil
	SET 
		pengadaanBrgDetPengadaanBrgId = '%s',
		pengadaanBrgDetUsulanBrgDetId = '%s',
		pengadaanBrgDetJmlhPengadaan = '%s',
		pengadaanBrgDetNominalSatuan = '%s',
		pengadaanBrgDetNominalVat = '%s',
		pengadaanBrgDetProsentVat = '%s'
";

$sql['update_pengadaan_barang'] = "
	UPDATE 
		aset_pb_pengadaan_brg
	SET 
		pengadaanBrgNomor = '%s',
		pengadaanBrgTanggalPengadaan = '%s',
		pengadaanBrgJnsBarangId = '%s',
		pengadaanBrgMAKId = '%s',
		pengadaanBrgMak = '%s',
		pengadaanBrgJalurPengadaanId = '%s',
		pengadaanBrgSumberDanaId = '%s',
		pengadaanBrgMitraId = '%s',
		pengadaanBrgPIC = '%s',
		pengadaanBrgTgl = NOW(),
		pengadaanBrgUserId = '%d'
	WHERE
		pengadaanBrgId = '%d'
";

$sql['delete_pengadaan_barang'] = "
	DELETE FROM
		aset_pb_pengadaan_brg
	WHERE
		pengadaanBrgId IN (%VALUE%)
";

$sql['delete_pengadaan_barang_detil'] = "
	DELETE FROM
		aset_pb_pengadaan_brg_detil
	WHERE
		pengadaanBrgDetPengadaanBrgId = '%d'
";
?>