<?php

//==========GET DATA ======================================
$sql['get_count_data_lelang_barang'] = 
   "SELECT 
      count(*) AS total
	FROM 
		aset_lelang
	LEFT JOIN mitra_ref ON mitraId = lelangMitraId
	WHERE
		lelangBA LIKE '%s' AND
		(mitraId = '%s' %OPERATOR% mitraNama LIKE '%s')
	";

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

$sql['get_data_lelang_barang']="
	SELECT
		SQL_CALC_FOUND_ROWS 
		lelangId AS id,
		lelangBA AS nomor_ba,
		lelangTglLelang AS tanggal_lelang,
		lelangTotalLelang AS total_harga,
		mitraNama AS mitra
	FROM 
		aset_lelang
	LEFT JOIN mitra_ref ON mitraId =lelangMitraId
	WHERE
		lelangBA LIKE '%s' AND
		(mitraId = '%s' %OPERATOR% mitraNama LIKE '%s')
	ORDER BY lelangId DESC
	LIMIT %s, %s
";
 
$sql['get_data_lelang_barang_by_id']=" 	
	SELECT 
   lelangId AS id,
   lelangBA AS nomorba,
   lelangTglLelang AS tanggal_lelang,
   lelangTotalLelang AS total_harga,
   mitraId AS idMitra,
   mitraNama AS namaMitra,
   lelangCatatan AS catatan,
   lelangDetNominal AS lelangBiaya,
   invDetKodeBarang AS barangKode,
   barangNama AS barangNama,
   invDetId AS barangId,
   kondisibrgNama AS barangKondisi ,
   lelangDetPengendalianBrgDetId AS pengendalianId
FROM
   aset_lelang 
   LEFT JOIN mitra_ref 
      ON mitraId = lelangMitraId 
   LEFT JOIN aset_lelang_det 
      ON lelangDetLelangId = lelangId 
   LEFT JOIN inventarisasi_detail 
      ON invDetId = lelangDetInvDetId 
   LEFT JOIN inventarisasi_mst 
      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 
WHERE lelangId IN ('%s') 
   AND invKondisiBrgId = 
   (SELECT 
      MAX(invKondisiBrgId) 
   FROM
      inv_kondisi_history 
   WHERE invKondisiBrgBrgDetId = invDetId)
	
";

//do-----------------------------------------------------
$sql['do_add_lelang_barang'] = "
	INSERT INTO 
		aset_lelang  
		(lelangBA, lelangMitraId, lelangTglLelang, lelangTotalLelang, lelangCatatan, lelangTglUbah, lelangUserId)
   VALUES 
      ('%s','%s','%s','%s','%s',NOW(),'%s')";


$sql['do_add_lelang_barang_det'] = "
	INSERT INTO aset_lelang_det 
		(lelangDetLelangId, lelangDetInvDetId, lelangDetPengendalianBrgDetId,lelangDetNominal, lelangDetTglUbah, lelangDetUserId)
	VALUES
		((SELECT MAX(lelangId) FROM aset_lelang),'%s','%s','%s',NOW(),'%s')";
		
$sql['do_update_investaris_detil'] = "
	UPDATE inventarisasi_detail
	SET invDetAsetStatusId = '%s',
	  invDetTglUbah = NOW(),
	  invDetUserId = '%s'
	WHERE invDetId = '%s'
";

//update
$sql['do_update_lelang_barang'] = 
   "UPDATE aset_lelang
	SET
		lelangBA  = '%s', 
		lelangMitraId  = '%s',
		lelangTglLelang  = '%s',
		lelangTotalLelang  = '%s',
		lelangCatatan  = '%s', 
		lelangTglUbah = NOW(),
		lelangUserId  = '%s'
	WHERE
		lelangId = '%s'
";

$sql['do_update_lelang_barang_det'] = 
   "INSERT INTO aset_lelang_det 
	(lelangDetLelangId, lelangDetInvDetId, lelangDetPengendalianBrgDetId,lelangDetNominal, lelangDetTglUbah, lelangDetUserId)
	VALUES
	('%s' ,'%s','%s','%s',NOW(),'%s')";

//delete
$sql['do_delete_lelang_barang_det'] = 
   "DELETE FROM aset_lelang_det 
	WHERE lelangDetLelangId='%s'";

$sql['do_delete_lelang_barang'] = 
   "DELETE FROM aset_lelang
	WHERE lelangId='%s'";

$sql['do_delete_lelang_barang_by_array_id'] = 
   "DELETE from aset_lelang
   WHERE 
     lelangId  IN ('%s')";
	 
//untuk popup mitra
$sql['get_mitra_view'] =
   ("
      SELECT
         mitraId as mkId,
         mitraNama as mkNama,
         mitraAlamat as mkAlamat,
         mitraTelp as mkTelepon
      FROM
         mitra_ref
         LEFT JOIN aset_mitra_bidang_usaha ON mitraId = mitrabidusahaMitraId
      WHERE
         mitrabidusahaJnsbidusahaId ='%s' %OPERATOR%
         mitraNama LIKE '%s' AND
         mitraAlamat LIKE '%s'
      GROUP BY
         mitraId
      ORDER BY
         mitraNama
      LIMIT
         %d, %d
   ");

$sql['get_count_mitra_view'] =
   ("
      SELECT
         mitraId as id
      FROM
         mitra_ref
         LEFT JOIN aset_mitra_bidang_usaha ON mitraId = mitrabidusahaMitraId
      WHERE
         mitrabidusahaJnsbidusahaId ='%s' %OPERATOR%
         mitraNama LIKE '%s' AND
         mitraAlamat LIKE '%s'
      GROUP BY
         mitraId
   ");

$sql['get_bidang_usaha_list'] =
   ("
      SELECT
         jnsbidusahaId as id,
         jnsbidusahaNama as name
      FROM
         jenis_bidang_usaha_ref
   ");
?>
