<?php

// ==== GET ====
$sql['get_combo_status_aset'] = "
SELECT
  statusAsetId   AS id,
  statusAsetNama AS `name`
FROM aset_ref_aset_status
";

$sql['get_combo_jenis_kib'] = "
SELECT
   golbrgId AS id,
   golbrgKibKode AS kode,
   golbrgNama AS name
FROM
   golongan_barang_ref
ORDER BY golbrgNama
";

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

$sql['get_kepemilikan'] = "
SELECT
   kepemilikanbrgId AS id,
   kepemilikanbrgNama AS name
FROM
   kepemilikan_barang_ref
ORDER BY kepemilikanbrgNama
";

$sql['get_lokasi_kampus'] = "
SELECT
   kampusId AS id,
   kampusNama AS name
FROM
   kampus_ref
ORDER BY kampusNama
";

$sql['get_kondisi'] = "
SELECT
   kondisibrgId AS id,
   kondisibrgNama AS name
FROM
   kondisi_barang_ref
ORDER BY kondisibrgNama
";

$sql['get_cbx_satuan'] = "
SELECT
   satuanbrgId AS id,
   satuanbrgNama AS name
FROM
   satuan_barang_ref
ORDER BY satuanbrgNama
";

$sql['get_cbx_pagar'] = "
SHOW COLUMNS FROM inventarisasi_detail LIKE 'invDetPagar'
";

$sql['get_cbx_identitas_barang'] = "
SHOW COLUMNS FROM inventarisasi_detail LIKE 'invDetIdentitasBarang'
";

$sql['get_cbx_penguasaan_barang'] = "
SELECT
   statuspengbrgId AS id,
   statuspengbrgNama AS name
FROM
   status_penguasaan_barang_ref
ORDER BY statuspengbrgNama
";

$sql['get_unit_pj'] = "
SELECT
   unitkerjaId AS id,
   unitkerjaNama AS name
FROM
   unit_kerja_ref
ORDER BY unitkerjaKode
";

$sql['get_data_user_by_id'] = "
SELECT
   UserId AS user_id,
   UserName AS user_name,
   RealName AS real_name,
   a.Description AS description,
   Active AS is_active,
   a.GroupId AS group_id,
   GroupName AS group_name,
   unitkerjaId AS unit_kerja_id,
   unitkerjaNama  AS unit_kerja_nama,
   userunitkerjaRoleId AS role_id
FROM
   gtfw_user a
   JOIN gtfw_group b ON b.GroupId = a.GroupId
   LEFT JOIN user_unit_kerja ON UserId = userunitkerjaUserId
   LEFT JOIN unit_kerja_ref ON unitkerjaId = userunitkerjaUnitkerjaId
WHERE
   UserId = %s
";

$sql['get_data_user_by_user_name'] = "
SELECT
   UserId AS user_id,
   UserName AS user_name,
   RealName AS real_name,
   a.Description AS description,
   Active AS is_active,
   a.GroupId AS group_id,
   GroupName AS group_name,
   unitkerjaId AS unit_kerja_id,
   unitkerjaNama  AS unit_kerja_nama,
   userunitkerjaRoleId AS role_id,
   unitkerjaKodeSistem
FROM
   gtfw_user a
   JOIN gtfw_group b ON b.GroupId = a.GroupId
   LEFT JOIN user_unit_kerja ON UserId = userunitkerjaUserId
   LEFT JOIN unit_kerja_ref ON unitkerjaId = userunitkerjaUnitkerjaId
WHERE
   UserName = %s
";

$sql['get_data_unit_by_unit_name'] = "
SELECT
   *
FROM
   unit_kerja_ref
WHERE
   unitkerjaNama = %s
";

$sql['get_list_biaya_lain'] = "
SELECT
   biayaId AS id,
   biayaName AS name
FROM
   biaya_ref
";

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

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

$sql['get_count_inventarisasi'] = "
SELECT
   COUNT(*) AS total
FROM
   inventarisasi_detail 
   LEFT JOIN inventarisasi_mst 
      ON invMstId = invDetMstId 
   LEFT JOIN unit_kerja_ref 
      ON invDetUnitKerja = unitkerjaId 
   LEFT JOIN aset_ref_aset_status 
      ON statusAsetId = invDetAsetStatusId 
WHERE
   (invDetGolId = '%s' OR '%s') AND
   ((invTglPembelian > '%s' AND invTglPembelian < '%s') OR '%s') AND
   (invSumberDana = '%s' OR '%s') AND
   (invDetKepemilikan = '%s' OR '%s') AND
   (invDetKampus = '%s' OR '%s') AND
   (invDetKondisiId = '%s' OR '%s') AND
   (unitkerjaId = '%s' OR unitkerjaParentId = (SELECT unitkerjaId FROM unit_kerja_ref WHERE unitkerjaNama = '%s') OR '' = '%s') AND
   (
      invSPMNumber LIKE '%s' OR invDetMstLabel LIKE '%s' OR
      invDetKodeBarang LIKE '%s'
   ) AND
   (invDetUnitKerja = '%s' OR unitkerjaParentId = '%s' OR '1' = '%s') AND 
	(statusAsetId = '%s' OR 1 = '%s')
";

$sql['get_inventarisasi'] = "
SELECT
   SQL_CALC_FOUND_ROWS
   invDetId AS id,
   invDetKodeBarang AS KIB,
   invDetBarangId AS id_barang,
   barangKode AS kode_barang,
   invDetMstLabel AS nama_aset,
   CONCAT(kampusNama,IF(gedungNama IS NULL,'',CONCAT('@@',gedungNama,IF(ruangNama IS NULL,'',CONCAT('@@',ruangNama))))) AS lokasi_aset,
   unitkerjaNama AS unit_pj,
   unitkerjaKodeSistem,
   LEFT(invDetTglPembelian, 4) AS thn_pengadaan,
   IF(mstPenystnNilaiPerolehan IS NOT NULL, mstPenystnNilaiPerolehan,IF(invDetNilaiPerolehanSatuan IS NULL, invTotalPerolehan, invDetNilaiPerolehanSatuan)) AS nilai_perolehan,
   IF(mstPenystnDisusutkan IS NOT NULL, mstPenystnDisusutkan,IF(invDetNilaiPerolehanSatuan IS NULL, invTotalPerolehan, invDetNilaiPerolehanSatuan)) AS nilai_buku,
   kepemilikanbrgNama AS status_kepemilikan,
   IF(statusAsetNama != 'Aktif',CONCAT(kondisibrgNama,' (',statusAsetNama,')'),kondisibrgNama) AS kondisi,
   golbrgId AS golBarang
FROM
   inventarisasi_detail 
   LEFT JOIN inventarisasi_mst ON invDetMstId = invMstId
   LEFT JOIN barang_ref ON invDetBarangId = barangId
   LEFT JOIN kampus_ref ON invDetKampus = kampusId
   LEFT JOIN unit_kerja_ref  ON invDetUnitKerja = unitkerjaId
   LEFT JOIN kepemilikan_barang_ref ON kepemilikanbrgId = invDetKepemilikan
   LEFT JOIN kondisi_barang_ref ON kondisibrgId = invDetKondisiId
   LEFT JOIN sub_kelompok_barang_ref ON invDetSubkelbrgId = subkelbrgId
   LEFT JOIN kelompok_barang_ref ON invDetKelbrgId = kelbrgId
   LEFT JOIN bidang_barang_ref ON invDetBidangbrngId = bidangbrgId
   LEFT JOIN golongan_barang_ref ON invDetGolId = golbrgId
   LEFT JOIN gedung ON invDetGedungId = gedungId
   LEFT JOIN ruang ON invDetRuanganId = ruangId
   LEFT JOIN penyusutan_brg_mst ON invDetId = mstPenystnBarangId
   LEFT JOIN aset_ref_aset_status ON statusAsetId = invDetAsetStatusId
   LEFT JOIN do_detail_new ON doDetInvDetId = invDetId
WHERE
   [CARI_GOL]
   [CARI_THN]
   [CARI_SUMBER]
   [CARI_KEPEMILIKAN]
   [CARI_KAMPUS]
   [CARI_KONDISI]
   [CARI_STATUS]
   [CARI_UNIT]
   (
      invSPMNumber LIKE '%s' OR invDetMstLabel LIKE '%s' OR
      invDetKodeBarang LIKE '%s'
   )
   /*tampilkan hasil konversi*/
   AND (/*invMstPengadaanId = 1 OR */invMstPengadaanId IS NULL
   /*tampilkan pengadaan yang sudah di DO dan diterima*/ 
   OR (/*invMstPengadaanId <> 1 AND */invMstPengadaanId IS NOT NULL AND doDetId IS NOT NULL AND doDetRuangId IS NOT NULL)) 
ORDER BY
   invDetTglPembelian DESC,invDetKodeBarang ASC 
LIMIT %s, %s
";

$sql['get_data_inventarisasi_by_id'] = "
SELECT
   inventarisasi_mst.*,
   inventarisasi_detail.*,
   golbrgId,
   invDetKodeBarang AS invKodeAset,
   barangNama AS namaAset,
   invKondisiBrgKondId,
   CONCAT(gedungNama,IF(ruangNama IS NULL,'',CONCAT(' &raquo; ',ruangNama))) AS lokasiAset,
   unitkerjaNama,
	inv_kondisi_history.invNamaFile AS namaFile,
   IF(mstPenystnNilaiPerolehan IS NULL OR mstPenystnNilaiPerolehan = mstPenystnDisusutkan, 0, 1) AS is_penyusutan
FROM
   inventarisasi_mst
   JOIN inventarisasi_detail ON invDetMstId = invMstId
   JOIN barang_ref ON invBarangId = barangId
   JOIN sub_kelompok_barang_ref ON barangSubkelbrgId = subkelbrgId
   JOIN kelompok_barang_ref ON subkelbrgKelbrgId = kelbrgId
   JOIN bidang_barang_ref ON kelbrgBidangbrgId = bidangbrgId
   JOIN golongan_barang_ref ON bidangbrgGolbrgId = golbrgId
   LEFT JOIN kampus_ref ON invDetKampus = kampusId
   LEFT JOIN gedung ON invDetGedungId = gedungId
   LEFT JOIN ruang ON invDetRuanganId = ruangId
   LEFT JOIN inv_kondisi_history ON invDetId = invKondisiBrgBrgDetId
   JOIN unit_kerja_ref ON invDetUnitKerja = unitkerjaId
   LEFT JOIN penyusutan_brg_mst ON invDetId = mstPenystnBarangId
WHERE
   invDetId = '%s'
ORDER BY
   invKondisiTglHistory DESC
LIMIT 1
";

$sql['get_inventarisasi_detail_by_id'] = "
SELECT
   inventarisasi_mst.*,
   inventarisasi_detail.*,
   invDetKodeBarang AS invKodeAset,
   golbrgNama,
   barangNama AS namaAset,
   invKondisiBrgKondId,
   CONCAT(gedungNama,IF(ruangNama IS NULL,'',CONCAT(' &raquo; ',ruangNama))) AS lokasiAset,
   unitkerjaNama,
   invDetNamaFile AS invNamaFile,
	statusAsetNama
FROM
   inventarisasi_mst
   JOIN inventarisasi_detail ON invDetMstId = invMstId
   JOIN barang_ref ON invBarangId = barangId
   JOIN sub_kelompok_barang_ref ON barangSubkelbrgId = subkelbrgId
   JOIN kelompok_barang_ref ON subkelbrgKelbrgId = kelbrgId
   JOIN bidang_barang_ref ON kelbrgBidangbrgId = bidangbrgId
   JOIN golongan_barang_ref ON bidangbrgGolbrgId = golbrgId
   LEFT JOIN gedung ON invDetGedungId = gedungId
   LEFT JOIN ruang ON invDetRuanganId = ruangId
   LEFT JOIN inv_kondisi_history ON invDetId = invKondisiBrgBrgDetId
   JOIN unit_kerja_ref ON invDetUnitKerja = unitkerjaId
	JOIN aset_ref_aset_status ON statusAsetId = invDetAsetStatusId
WHERE
   invDetId = '%s'
ORDER BY
   invKondisiTglHistory DESC
LIMIT 1
";

$sql['get_inventarisasi_id_by_filter'] = "
SELECT
   invDetId AS id
FROM
   inventarisasi_detail b
   JOIN (SELECT invKondisiBrgBrgDetId, invKondisiBrgKondId FROM inv_kondisi_history ORDER BY invKondisiBrgTglKondisi DESC) g ON g.invKondisiBrgBrgDetId = b.invDetId
WHERE
	invDetId IN ('%s')
";

$sql['get_biaya_lain_by_id'] = "
SELECT
   invDetBiayaBiayaId as biayaId,
   invDetBiayaNilai as biayaNilai
FROM
   inv_det_biaya
WHERE
   invDetBiayaInvId = %d
";

$sql['get_log_lokasi_header'] = "
SELECT
   invDetKodeBarang AS kodeBarang,
   barangNama,
   a.invDetMstLabel,
   a.invDetMerek,
   a.invDetSpesifikasi
FROM
   inventarisasi_detail a
   JOIN inventarisasi_mst b ON b.invMstId = a.invDetMstId
   JOIN barang_ref c ON invBarangId = barangId
WHERE
   a.invDetId = '%s'
";

$sql['get_log_lokasi_body'] = "
SELECT
   InvHisTanggal,
   kampusNama,
   CONCAT(gedungNama,if(ruangNama IS NULL,'',CONCAT(' &raquo; ',ruangNama))) as lokasiAset
FROM
   inventarisasi_lokasi_history a
   JOIN kampus_ref b ON kampusId = invHisKampusId
   LEFT JOIN gedung ON gedungId = invHisGedungId
   JOIN ruang ON ruangId =InvHisRuangId
WHERE
   a.invHisInvDetId = '%s'
ORDER BY InvHisTanggal DESC
";

$sql['get_log_kondisi_body'] = "
SELECT
   invKondisiBrgTglKondisi,
   kondisibrgNama
FROM
   inv_kondisi_history a
   JOIN kondisi_barang_ref b ON kondisibrgId = invKondisiBrgKondId
WHERE
   a.invKondisiBrgBrgDetId = '%s'
";

$sql['get_cetak_kib'] = "
SELECT
   invDetKodeBarang AS KIB
FROM
   inventarisasi_detail b 
WHERE
  invDetId IN (%ID%)
ORDER BY
   invDetKodeBarang
";

$sql['get_penyesuaian_data'] = "
SELECT
   invDetKodeBarang AS invKodeBarang,
   barangNama,
   a.invDetMstLabel,
   a.invDetMerek,
   a.invDetSpesifikasi,
   IFNULL(mstPenystnUmrEko, a.invDetUmurEkonomis) AS mstPenystnUmrEko,
   IFNULL(mstPenystnNilaiPerolehan, a.invDetNilaiPerolehanSatuan) AS mstPenystnNilaiPerolehan,
   IFNULL(mstPenystnNilaiResidu, a.invDetNilaiResidu) AS mstPenystnNilaiResidu,
   mstPenystnBrgId
FROM
   inventarisasi_detail a
   JOIN inventarisasi_mst ON invMstId = invDetMstId
   JOIN barang_ref ON barangId = invBarangId
   LEFT JOIN penyusutan_brg_mst ON mstPenystnBarangId = InvDetId
WHERE
   invDetId = '%s'
LIMIT 1
";

$sql['get_extra_field_id']="

";

/*********
Do Query
*********/
$sql['add_inv_mst'] = "
INSERT INTO
   inventarisasi_mst
   (
		invBarangId,
		invKodeAset,
		invBarcode,
		invMstLabel,
		invMerek,
		invSpesifikasi,
		invTglPembelian,
		invSumberDana,
		invJumlahAset,
		invSatuanBarang,
		invLuasTanah,
		invNilaiPerolehanSatuan,
		invNilaiFaktur,
		invTotalPerolehan,
		invSPMNumber,
		invTglUbah,
		invUserId
   )
VALUES
(
   %s,
   %s,
   %s,
   %s,
   %s,
   %s,
   %s,
   %s,
   %s,
   %s,
   %s,
   %s,
   %s,
   %s,
	%s,
   NOW(),
   (SELECT UserId FROM `gtfw_user` WHERE UserName = '%s')
)
";

$sql['add_inv_detail'] = "
INSERT INTO
	inventarisasi_detail
SET
	invDetMstId=(SELECT MAX(invMstId) as a FROM inventarisasi_mst),
   invDetKodeBarang=(SELECT * FROM
   	(SELECT 
		   CONCAT(
		      LPAD(golbrgKode, 1, '0'),
		      '.',
		      LPAD(bidangbrgKode, 2, '0'),
		      '.',
		      LPAD(kelbrgKode, 2, '0'),
		      '.',
		      LPAD(subkelbrgKode, 2, '0'),
		      '.',
		      LPAD(barangKode, 3, '0'),
		      '.',
		      LPAD((
					IFNULL(
		      (SELECT 
		         MAX(
		            SUBSTRING_INDEX(invDetKodeBarang, '.', - 1)
		         ) + 1 AS a 
		      FROM
		         inventarisasi_detail 
		         JOIN inventarisasi_mst 
		            ON invMstId = invDetMstId 
		      WHERE invBarangId = '%s'),
		      1
		   )
		      ), 4, '0')
		   ) AS kode_barang
		FROM
		   inventarisasi_mst 
		   LEFT JOIN barang_ref 
		      ON invBarangId = barangId 
		   LEFT JOIN sub_kelompok_barang_ref 
		      ON barangSubkelbrgId = subkelbrgId 
		   LEFT JOIN kelompok_barang_ref 
		      ON subkelbrgKelbrgId = kelbrgId 
		   LEFT JOIN bidang_barang_ref 
		      ON kelbrgBidangbrgId = bidangbrgId 
		   LEFT JOIN golongan_barang_ref 
		      ON bidangbrgGolbrgId = golbrgId 
		WHERE invMstId = (SELECT MAX(invMstId) FROM inventarisasi_mst) 
   ) kode),
   invDetBarcode='%s',
   invDetMstLabel='%s',
   invDetMerek=IFNULL(%s,''),
   invDetSpesifikasi='%s',
   invDetTglPembelian='%s',
   invDetNilaiResidu='%s',
   invDetTipe='%s',
   invDetSumberDana='%s',
   invDetSatuanBarang='%s',
   invDetNilaiPerolehanSatuan='%s',
   invDetNJOP='%s',
   invDetUmurEkonomis='%s',
   invDetLokasi='%s',
   invDetKegunaan='%s',
   invDetSertifikat='%s',
   invDetAkta='%s',
   invDetBPKB='%s',
   invDetSTNK='%s',
   invDetNoMesin='%s',
   invDetNoRangka='%s',
   invDetNoPolisi='%s',
   invDetNoLain='%s',
   invDetWarna='%s',
   invDetPagar='%s',
   invDetBatasUtara='%s',
   invDetBatasTimur='%s',
   invDetBatasSelatan='%s',
   invDetBatasBarat='%s',
   invDetKepemilikan='%s',
   invDetPenguasaanBarang='%s',
   invDetKeteranganLain='%s',
   invDetKampus='%s',
   invDetGedungId='%s',
   invDetRuanganId='%s',
   invDetUnitKerja='%s',
	invDetKondisiId=IFNULL(%s,1),
	invDetNamaFile='%s',
   invDetTglUbah=NOW(),
   invDetUserId=(SELECT UserId FROM `gtfw_user` WHERE UserName = '%s'),
	invDetAsetStatusId=IFNULL(%s,1),
	invDetIdentitasBarang=%s
";

$sql['update_detil']="
	UPDATE 
	inventarisasi_detail,
	inventarisasi_mst,
	barang_ref,
	sub_kelompok_barang_ref,
	kelompok_barang_ref,
	bidang_barang_ref,
	golongan_barang_ref
	SET
	   `invDetGolId`=golbrgId,
	   `invDetBidangbrngId`=`bidangbrgId`,
	   `invDetKelbrgId`=`kelbrgId`,
	   `invDetSubkelbrgId`=`subkelbrgId`,
	   `invDetBarangId`=`barangId`
	WHERE 
	invDetMstId =invMstId
	AND
	invBarangId = barangId
	AND 
	barangSubkelbrgId = subkelbrgId
	AND 
	subkelbrgKelbrgId=kelbrgId
	AND 
	kelbrgBidangbrgId = bidangbrgId
	AND 
	bidangbrgGolbrgId=golbrgId
	AND 
	invDetId=(SELECT * FROM (SELECT MAX(invDetId) FROM inventarisasi_detail) a)
";

$sql['add_detail_biaya_by_id'] = "
INSERT INTO
   inv_det_biaya (invDetBiayaInvId, invDetBiayaBiayaId, invDetBiayaNilai)
VALUES
   ((SELECT MAX(invMstId) as a FROM inventarisasi_mst), %s, %s)
";

$sql['add_kondisi_history'] = "
INSERT INTO
   inv_kondisi_history
   (
      invKondisiBrgBrgDetId,
      invKondisiBrgKondId,
      invKondisiBrgTglKondisi,
      invKondisiTglHistory,
	  invNamaFile,
      invKondisiUserId
   )
VALUES
(
   %s,
   IFNULL(%s,1),
   NOW(),
   NOW(),
	%s,
   (SELECT UserId FROM `gtfw_user` WHERE UserName = '%s')
)
";

$sql['add_lokasi_history'] = "
INSERT INTO
   inventarisasi_lokasi_history
   (
      invHisInvDetId,
      InvHisKampusId,
      invHisGedungId,
      InvHisRuangId,
      InvHisTanggal,
      InvHisUserId
   )
VALUES
(
   (SELECT MAX(invDetId) FROM inventarisasi_detail),
   %s,
   %s,
   %s,
   NOW(),
   (SELECT UserId FROM `gtfw_user` WHERE UserName = '%s')
)
";

$sql['add_penyusutan'] = "
INSERT INTO
   penyusutan_brg_mst
   (
      mstPenystnBarangId,
      mstPenystnNilaiPerolehan,
      mstPenystnNilaiResidu,
      mstPenystnUmrEko,
      mstPenystnDisusutkan,
      mstPenystnNilaiPenyusutan,
      mstPenystnTglPerubahan
   )
SELECT
   invDetId,
   IF(invDetNilaiPerolehanSatuan > 0, invDetNilaiPerolehanSatuan, invTotalPerolehan),
   IF(invDetNilaiResidu > 0, invDetNilaiResidu, NULL),
   invDetUmurEkonomis,
   IF(invDetNilaiPerolehanSatuan > 0, invDetNilaiPerolehanSatuan, invTotalPerolehan),
   IF(((IF(invDetNilaiPerolehanSatuan > 0, invDetNilaiPerolehanSatuan, invTotalPerolehan) - invDetNilaiResidu) / invDetUmurEkonomis) > 0, ((IF(invDetNilaiPerolehanSatuan > 0, invDetNilaiPerolehanSatuan, invTotalPerolehan) - invDetNilaiResidu) / invDetUmurEkonomis), NULL),
   NOW()
FROM
   inventarisasi_detail
   JOIN (SELECT invMstId, invTotalPerolehan FROM inventarisasi_mst) a ON invMstId = invDetMstId
WHERE
   invMstId = (SELECT MAX(invMstId) FROM inventarisasi_mst)
";

$sql['update_inv_detail'] = "
UPDATE
   inventarisasi_detail
SET
   invDetBarcode = %s,
   invDetMstLabel = %s,
   invDetMerek = %s,
   invDetSpesifikasi = %s,
   invDetTglPembelian = %s,
   invDetNilaiResidu = %s,
   invDetTipe = %s,
   invDetSumberDana = %s,
   invDetSatuanBarang = %s,
   invDetNilaiPerolehanSatuan = %s,
   invDetNJOP = %s,
   invDetUmurEkonomis = %s,
   invDetLokasi = %s,
   invDetKegunaan = %s,
   invDetSertifikat = %s,
   invDetAkta = %s,
   invDetBPKB = %s,
   invDetSTNK = %s,
   invDetNoMesin = %s,
   invDetNoRangka = %s,
   invDetNoPolisi = %s,
   invDetNoLain = %s,
   invDetWarna = %s,
   invDetPagar = %s,
   invDetBatasUtara = %s,
   invDetBatasTimur = %s,
   invDetBatasSelatan = %s,
   invDetBatasBarat = %s,
   invDetKepemilikan = %s,
   invDetPenguasaanBarang = %s,
   invDetKeteranganLain = %s,
   invDetKampus = %s,
   invDetGedungId = NULLIF(%s, 0),
   invDetRuanganId = NULLIF(%s, 0),
   invDetUnitKerja = %s,
   invDetTglUbah = NOW(),
   invDetNamaFile = %s,
   invDetKondisiId = %s,
   invDetAsetStatusId = %s,
   invDetIdentitasBarang = %s,
   invDetUserId = (SELECT UserId FROM `gtfw_user` WHERE UserName = '%s')
WHERE
   invDetId = %s
";

$sql['update_kondisi_history'] = "
INSERT INTO
   inv_kondisi_history
   (
      invKondisiBrgBrgDetId,
      invKondisiBrgKondId,
      invKondisiBrgTglKondisi,
      invKondisiTglHistory,
	  invNamaFile,
      invKondisiUserId
   )
VALUES
(
   %s,
   %s,
   NOW(),
   NOW(),
	%s,
   (SELECT UserId FROM `gtfw_user` WHERE UserName = '%s')
)
";

$sql['update_lokasi_history'] = "
INSERT INTO
   inventarisasi_lokasi_history
   (
      invHisInvDetId,
      InvHisKampusId,
      invHisGedungId,
      InvHisRuangId,
      InvHisTanggal,
      InvHisUserId
   )
VALUES
(
   %s,
   %s,
   NULLIF(%s, 0),
   NULLIF(%s, 0),
   NOW(),
   (SELECT UserId FROM `gtfw_user` WHERE UserName = '%s')
)
";

$sql["update_penyesuaian_aset"] = "
UPDATE
   penyusutan_brg_mst
SET
   mstPenystnUmrEko = %s,
   mstPenystnNilaiPerolehan = %s,
   mstPenystnNilaiResidu = %s
WHERE
   mstPenystnBrgId = %s
";

$sql["do_delete_inventarisasi"] = "
	DELETE FROM inventarisasi_detail WHERE invDetId = '%d'
";
?>
