<?php
$sql['get_data_barang_count'] ="
   SELECT 
	   COUNT(nama_barang) AS total 
	FROM
	   (SELECT 
		  invDetId AS barang_id,
		  invDetKodeBarang AS kode_barang,
		  barangNama AS nama_barang,
		  a.invDetMstLabel AS label,
		  e.kondisibrgNama AS kondisi,
		  e.kondisibrgId AS kondisi_id,
		  statusPengBrgNama AS STATUS,
		  a.invDetAsetStatusId AS statusAset 
	   FROM
		  inventarisasi_detail a 
		  LEFT JOIN inventarisasi_mst b 
			 ON invDetMstId = invMstId 
		  LEFT JOIN barang_ref c 
			 ON invBarangId = barangId 
		  LEFT JOIN inv_kondisi_history d 
			 ON invDetId = invKondisiBrgBrgDetId 
		  LEFT JOIN kondisi_barang_ref e 
			 ON invKondisiBrgKondId = kondisibrgId 
		  LEFT JOIN pengendalian_barang_det 
			 ON pengBrgInvDetId = invDetId 
		  LEFT JOIN status_peng_brg_ref 
			 ON statusPengBrgId = pengBrgStatusId 
		  LEFT JOIN aset_lelang_det 
			 ON lelangDetInvDetId = a.invDetId 
	   WHERE pengBrgStatusId = 2 
		  AND lelangDetId IS NULL 
		  AND invKondisiBrgId = 
		  (SELECT 
			 MAX(invKondisiBrgId) 
		  FROM
			 inv_kondisi_history 
		  WHERE invKondisiBrgBrgDetId = invDetId) 
	   GROUP BY barang_id) a 
	WHERE kode_barang LIKE '%s' 
	   AND nama_barang LIKE '%s' 
	   AND statusAset = 1 
";

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

$sql['get_data_barang']="
SELECT
    SQL_CALC_FOUND_ROWS
    invDetId AS barang_id,
    invDetKodeBarang AS kode_barang,
    barangNama AS nama_barang,
    invDetMstLabel AS label,
    kondisibrgNama AS kondisi,
    kondisibrgId AS kondisi_id,
    statusAsetNama AS STATUS,
    prioritasNama,
    pengBrgTgl,
    pengBrgDetId,
    pengBrgHrgJual
FROM pengendalian_barang_det
LEFT JOIN pengendalian_barang_mst ON pengBrgId = pengBrgDetMstId
LEFT JOIN inventarisasi_detail ON invDetId = pengBrgInvDetId
LEFT JOIN barang_ref ON barangId = invDetBarangId
LEFT JOIN kondisi_barang_ref ON kondisibrgId = invDetKondisiId
LEFT JOIN aset_ref_aset_status ON statusAsetId = pengBrgStatusId
LEFT JOIN prioritas_ref ON prioritasId = pengBrgPrioritasId
LEFT JOIN aset_lelang_det ON lelangDetPengendalianBrgDetId = pengBrgDetId
WHERE 
    /* filter status dilelang */
    invDetAsetStatusId = 2 AND lelangDetPengendalianBrgDetId IS NULL
HAVING kode_barang LIKE '%s' AND nama_barang LIKE '%s' 
ORDER BY pengBrgTgl DESC, prioritasId ASC
LIMIT %d, %d
";


$sql['get_data_barang_old'] = "
   SELECT 
	   * 
	FROM
	   (SELECT 
		  invDetId AS barang_id,
		  invDetKodeBarang AS kode_barang,
		  barangNama AS nama_barang,
		  a.invDetMstLabel AS label,
		  e.kondisibrgNama AS kondisi,
		  e.kondisibrgId AS kondisi_id,
		  statusPengBrgNama AS STATUS,
		  a.invDetAsetStatusId AS statusAset 
	   FROM
		  inventarisasi_detail a 
		  LEFT JOIN inventarisasi_mst b 
			 ON invDetMstId = invMstId 
		  LEFT JOIN barang_ref c 
			 ON invBarangId = barangId 
		  LEFT JOIN inv_kondisi_history d 
			 ON invDetId = invKondisiBrgBrgDetId 
		  LEFT JOIN kondisi_barang_ref e 
			 ON invKondisiBrgKondId = kondisibrgId 
		  LEFT JOIN pengendalian_barang_det 
			 ON pengBrgInvDetId = invDetId 
		  LEFT JOIN status_peng_brg_ref 
			 ON statusPengBrgId = pengBrgStatusId 
		  LEFT JOIN aset_lelang_det 
			 ON lelangDetInvDetId = a.invDetId 
	   WHERE pengBrgStatusId = 2 
		  AND lelangDetId IS NULL 
		  AND invKondisiBrgId = 
		  (SELECT 
			 MAX(invKondisiBrgId) 
		  FROM
			 inv_kondisi_history 
		  WHERE invKondisiBrgBrgDetId = invDetId) 
	   GROUP BY barang_id) a 
	WHERE kode_barang LIKE '%s' 
	   AND nama_barang LIKE '%s' 
	   AND statusAset = 1 
	LIMIT %d, %d
";
?>
