<?php
$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,
		unitkerjaNama,
		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
		UserName = %s
";

$sql['get_data_kdp_pengembangan'] = "
	SELECT 
		SQL_CALC_FOUND_ROWS *
	FROM
		(SELECT 
			transKdpId AS KDP_ID,
		   transKdpNomorSppa AS NOMOR_SPPA,
		   CONCAT(
		      SUBSTRING(a.transKdpKodeBarang, 1, 1),
		      '.',
		      SUBSTRING(a.transKdpKodeBarang, 2, 2),
		      '.',
		      SUBSTRING(a.transKdpKodeBarang, 4, 2),
		      '.',
		      SUBSTRING(a.transKdpKodeBarang, 6, 2),
		      '.',
		      SUBSTRING(a.transKdpKodeBarang, 8, 3)
		   ) AS KODE_BARANG,
		   barangNama AS NAMA_BARANG,
		   transKdpNomorKontrak AS NO_KONTRAK,
		   transKdpNoUrutKdpAwal AS NO_AWAL,
		   transKdpNoUrutKdpAkhir AS NO_AKHIR,
		   transKdpTanggalPembukuan AS TGL_BUKU,
      	transKdpProsentasiPengerjaan AS PROSENTASE
		FROM
		   aset_kdp_trans_kdp a 
		   JOIN golongan_barang_ref 
		      ON golbrgKode = (
		         SUBSTRING(a.transKdpKodeBarang, 1, 1) * 1
		      ) 
		   JOIN bidang_barang_ref 
		      ON bidangbrgGolbrgId = golbrgId 
		   JOIN kelompok_barang_ref 
		      ON kelbrgBidangbrgId = bidangbrgId 
		   JOIN sub_kelompok_barang_ref 
		      ON subkelbrgKelbrgId = kelbrgId 
		   JOIN barang_ref 
		      ON barangSubkelbrgId = subkelbrgId) AS DYN_QUERY 
	WHERE (NOMOR_SPPA LIKE '%s' 
		OR KODE_BARANG LIKE '%s' 
		OR NAMA_BARANG LIKE '%s'
		)AND NO_KONTRAK != ''  
	GROUP BY NO_KONTRAK
	ORDER BY TGL_BUKU DESC
	LIMIT %d, %d 
";

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

$sql['get_data_kdp_pengembangan_by_id'] = "
	SELECT 
		transKdpId AS KDP_ID,
		transKdpNomorSppa AS NOMOR_SPPA,
		transKdpTahunAnggaran AS TAHUN,
		CONCAT(
		   SUBSTRING(a.transKdpKodeBarang, 1, 1),
		   '.',
		   SUBSTRING(a.transKdpKodeBarang, 2, 2),
		   '.',
		   SUBSTRING(a.transKdpKodeBarang, 4, 2),
		   '.',
		   SUBSTRING(a.transKdpKodeBarang, 6, 2),
		   '.',
		   SUBSTRING(a.transKdpKodeBarang, 8, 3)
		) AS KODE_BARANG,
		transKdpNoUrutKdpAwal AS NO_AWAL,
		transKdpNoUrutKdpAkhir AS NO_AKHIR,
		'' AS PROGRAM,
		transKdpCaraPembangunanId AS BANGUN_ID,
		transKdpProsentasiPengerjaan AS PROSENTASE,
		transKdpNilaiAset AS NILAI_ASET,
		transKdpTanggalPembukuan AS TGL_BUKU,
		transKdpKondisiAsetId AS KONDISI_ID,
		transKdpNomorKontrak AS NOMOR_KONTRAK,
		transKdpNamaKontraktor AS NAMA_KONTRAK,
		transKdpAlamatKontraktor AS ALAMAT_KONTRAK,
		transKdpTglMulaiKontrak AS TGL_AWAL,
		transKdpTglAkhirKontrak AS TGL_AKHIR,
		transKdpNilaiKontrak AS NILAI_RP,
		transKdpNilaiKontrakValutaAsing AS NILAI_ASING,
		transKdpSpmId AS ID,
		transKdpSpmNoSp2d AS NO_SP2D,
		transKdpSpmTglSp2d AS TGL_SP2D,
		transKdpSpmKlBelanja AS KL_BELANJA,
		transKdpSpmNilaiSpm AS NILAI_SPM,
		'' AS NILAI_KDP,
		transKdpSpmKeterangan AS KETERANGAN 
	FROM
		aset_kdp_trans_kdp a 
		JOIN aset_kdp_trans_kdp_spm 
		   ON transKdpSpmTransKdpId = a.transKdpId 
		JOIN golongan_barang_ref 
		   ON golbrgKode = (
		      SUBSTRING(a.transKdpKodeBarang, 1, 1) * 1
		   ) 
		JOIN bidang_barang_ref 
		   ON bidangbrgGolbrgId = golbrgId 
		JOIN kelompok_barang_ref 
		   ON kelbrgBidangbrgId = bidangbrgId 
		JOIN sub_kelompok_barang_ref 
		   ON subkelbrgKelbrgId = kelbrgId 
		JOIN barang_ref 
		   ON barangSubkelbrgId = subkelbrgId 
	WHERE transKdpId = '%s' 
	GROUP BY transKdpId,
		transKdpSpmId 
";

$sql['get_data_kondisi_barang'] = "
	SELECT 
		kondisibrgId AS id,
		kondisibrgNama AS `name` 
	FROM
		kondisi_barang_ref 
";

$sql['get_data_cara_bangun'] = "
	SELECT 
		caraPembangunanId AS id,
		caraPembangunanNama AS `name` 
	FROM
	   aset_kdp_ref_pembangunan_cara 
";	

$sql['update_aset_kdp_trans_kdp'] = "
	UPDATE 
		aset_kdp_trans_kdp 
	SET
		transKdpKodeBarang = '%s',
		transKdpNoUrutKdpAwal = '%s',
		transKdpNoUrutKdpAkhir = '%s',
		transKdpCaraPembangunanId = '%s',
		transKdpProsentasiPengerjaan = '%s',
		transKdpTanggalPembukuan = '%s',
		transKdpKondisiAsetId = '%s',
		transKdpNomorKontrak = '%s',
		transKdpNamaKontraktor = '%s',
		transKdpAlamatKontraktor = '%s',
		transKdpTglMulaiKontrak = '%s',
		transKdpTglAkhirKontrak = '%s',
		transKdpNilaiKontrak = '%s',
		transKdpNilaiKontrakValutaAsing = '%s' 
	WHERE transKdpId = '%s' 
";

$sql['update_aset_kdp_trans_kdp_spm'] = "
	UPDATE 
		aset_kdp_trans_kdp_spm 
	SET
		transKdpSpmNoSp2d = '%s',
		transKdpSpmTglSp2d = '%s',
		transKdpSpmKlBelanja = '%s',
		transKdpSpmNilaiSpm = '%s',
		transKdpSpmKeterangan = '%s',
		transKdpSpmTglUbah = NOW(),
		transKdpUserId = '%s' 
	WHERE transKdpSpmId = '%s' AND transKdpSpmTransKdpId = '%s' 
";

$sql['insert_aset_kdp_trans_kdp_spm'] = "
	INSERT INTO 
		aset_kdp_trans_kdp_spm 
	SET
		transKdpSpmTransKdpId = '%s',
		transKdpSpmNoSp2d = '%s',
		transKdpSpmTglSp2d = '%s',
		transKdpSpmKlBelanja = '%s',
		transKdpSpmNilaiSpm = '%s',
		transKdpSpmKeterangan = '%s',
		transKdpSpmTglUbah = NOW(),
		transKdpUserId = '%s'
";

$sql['delete_aset_kdp_trans_kdp_spm'] = "
	DELETE FROM aset_kdp_trans_kdp_spm WHERE transKdpSpmId NOT IN('%s') AND transKdpSpmTransKdpId = '%s' 
";	

$sql['delete_aset_kdp_trans_kdp_spm_by_id'] = "
	DELETE FROM aset_kdp_trans_kdp_spm WHERE transKdpSpmTransKdpId = '%s' 
";	
?>
