<?php
//---------------------------------LAPORAN MUTASI------------------------------
$sql['get_combo_unit'] = "
	SELECT 
		unitkerjaId AS id,
		unitkerjaNama AS name
	FROM 
		unit_kerja_ref
    [FILTER_UNIT]
	ORDER BY Name
";

$sql['get_data_user_by_username'] = "
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,
   userunitkerjaUnitkerjaId AS unit_kerja_id,
   userunitkerjaRoleId AS role_id,
   unitkerjaKodeSistem,
   unitkerjaNama
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_gedung'] = "
	SELECT 
		ruangId 	AS ruang_id,
		ruangNama 	AS nama_ruang,
		gedungNama 	AS nama_gedung,
		kampusNama 	AS nama_kampus
	FROM 
		ruang
		JOIN gedung ON ruangGedungId=gedungId
		JOIN kampus_ref ON kampusId = gedungKampusId
	WHERE 
		gedungKampusId=kampusId AND ruangNama LIKE '%s'
	ORDER BY nama_ruang
	LIMIT %s, %s
";

$sql['get_data_mutasi_rtf'] = "
	SELECT 
	   mtsAsetMstTglMutasi AS tglmutasi,
	   (SELECT 
		  unitkerjaNama 
	   FROM
		  unit_kerja_ref 
	   WHERE unitkerjaId = mtsAsetMstUnitIdAsal) AS unitasal,
	   (SELECT 
		  unitkerjaNama 
	   FROM
		  unit_kerja_ref 
	   WHERE unitkerjaId = mtsAsetMstUnitIdTuj) AS unittujuan,
	   COUNT(mtsAsetDetBrgId) AS jml,
	   inventarisasi_mst.invMstLabel AS barang,
	   inventarisasi_mst.invMerek AS merk,
	   inventarisasi_mst.invSpesifikasi AS spec,
	   mtsAsetMstBAMutasi AS mutasi_berita_acara 
	FROM
	   mutasi_aset_mst 
	   LEFT JOIN mutasi_aset_det 
		  ON mtsAsetDetMstId = mtsAsetMstId 
	   LEFT JOIN inventarisasi_detail 
		  ON mtsAsetDetBrgId = invDetId 
	   LEFT JOIN inventarisasi_mst 
		  ON invDetMstId = invMstId 
	WHERE mtsAsetMstBAMutasi LIKE '%s' 
";

$sql['get_detil_mutasi'] = "	
	SELECT
		e.invDetKodeBarang   AS kode_barang,
		e.invDetTglPembelian AS tanggal,
		e.invDetMstLabel     AS nama_barang,
		c.ruangNama       AS unit_asal,
		b.unitkerjaNama   AS tujuan_asal
	FROM mutasi_aset_mst
		LEFT JOIN mutasi_aset_det
		  ON mtsAsetDetMstId = mtsAsetMstId
		LEFT JOIN inventarisasi_detail e
		  ON mtsAsetDetBrgId = invDetId
		LEFT JOIN unit_kerja_ref b
		  ON b.unitkerjaId = mtsAsetMstUnitIdTuj
		LEFT JOIN ruang c
		  ON c.ruangId = mtsAsetMstLokasiIdAsal
	WHERE mtsAsetMstId = '%s'
";

$sql['get_data_mutasi']="
	SELECT
		mtsAsetMstId        AS mutasi_id,
		mtsAsetMstTglMutasi AS mutasi_tanggal,
		CONCAT((
			SELECT unitkerjaNama 
			FROM unit_kerja_ref 
			WHERE unitkerjaId = mtsAsetMstUnitIdAsal),' &raquo; ',(
				SELECT ruangNama 
				FROM ruang 
				WHERE ruangId = mtsAsetMstLokasiIdAsal)
		) AS mutasi_unit_asal,
		CONCAT((
			SELECT unitkerjaNama 
			FROM unit_kerja_ref 
			WHERE unitkerjaId = mtsAsetMstUnitIdTuj),' &raquo; ',(
				SELECT ruangNama 
				FROM ruang 
				WHERE ruangId = mtsAsetMstLokasiIdTuj)
		) AS mutasi_unit_tujuan,
		mtsAsetMstBAMutasi  AS mutasi_berita_acara
	FROM mutasi_aset_mst
		LEFT JOIN mutasi_aset_det
		  ON mtsAsetDetMstId = mtsAsetMstId
		LEFT JOIN inventarisasi_detail
		  ON mtsAsetDetBrgId = invDetId
		LEFT JOIN inventarisasi_mst
		  ON invDetMstId = invMstId
		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
		LEFT JOIN unit_kerja_ref b
		  ON b.unitkerjaId = mtsAsetMstUnitIdTuj
		LEFT JOIN ruang d
		  ON d.ruangId = mtsAsetMstLokasiIdTuj
        LEFT JOIN unit_kerja_ref b2 ON b2.unitkerjaId = mtsAsetMstUnitIdAsal
	WHERE 
		(mtsAsetMstTglMutasi BETWEEN '%s' AND '%s')
                [SEARCH_UNIT_ASAL]
                [SEARCH_UNIT_TUJUAN]
		AND mtsAsetMstBAMutasi LIKE '%s'
        AND (b2.unitkerjaKodeSistem = '%s' OR b2.unitkerjaKodeSistem LIKE '%s')
	GROUP BY mtsAsetMstId
";

$sql['get_count_data'] ="
	SELECT
		COUNT(ruangId) AS total
	FROM
		ruang
		JOIN gedung ON ruangGedungId = gedungId
		JOIN kampus_ref ON kampusId = gedungKampusId
	WHERE gedungKampusId = kampusId
	AND ruangNama LIKE '%s'
";

$sql['get_data_mutasi_rtf_by_ba']="
	SELECT 
		mtsAsetMstTglMutasi AS tgl,
		mtsAsetMstBAMutasi AS ba_mutasi,
		mtsAsetDetBrgId AS barangId,
		COUNT(
			CONCAT(
				LPAD(golbrgKode, 1, '0'),
				'.',
				LPAD(bidangbrgKode, 2, '0'),
				'.',
				LPAD(kelbrgKode, 2, '0'),
				'.',
				LPAD(subkelbrgKode, 2, '0'),
				'.',
				LPAD(barangKode, 3, '0')
			)
		) AS jumlah_aset,
		CONCAT(
			LPAD(golbrgKode, 1, '0'),
			'.',
			LPAD(bidangbrgKode, 2, '0'),
			'.',
			LPAD(kelbrgKode, 2, '0'),
			'.',
			LPAD(subkelbrgKode, 2, '0'),
			'.',
			LPAD(barangKode, 3, '0')
		) AS kode_aset,
		barangNama AS nama_aset,
		IFNULL('-',e.invDetMerek) AS merk,
		e.invDetSpesifikasi AS spesifikasi,
		a.unitkerjaId AS unit_asal_id,
		a.unitkerjaNama AS unit_asal,
		b.unitkerjaNama AS unit_tujuan,
		b.unitkerjaId AS unit_tujuan_id,
		c.ruangNama AS lokasi_asal,
		c.ruangId AS lokasi_asal_id,
		d.ruangNama AS lokasi_tujuan,
		d.ruangId AS lokasi_tujuan_id,
		mtsAsetMstPIC AS pic,
		mtsAsetMstKet AS keterangan,
		satuanbrgNama AS satuan,
		r.RealName AS nama_pengirim,
		s.RealName AS nama_penerima
	FROM
		mutasi_aset_mst 
		LEFT JOIN mutasi_aset_det 
			ON mtsAsetDetMstId = mtsAsetMstId 
		LEFT JOIN inventarisasi_detail e 
			ON mtsAsetDetBrgId = invDetId 
		LEFT JOIN inventarisasi_mst 
			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 unit_kerja_ref a 
			ON a.unitkerjaId = mtsAsetMstUnitIdAsal 
		LEFT JOIN unit_kerja_ref b 
			ON b.unitkerjaId = mtsAsetMstUnitIdTuj 
		LEFT JOIN ruang c 
			ON c.ruangId = mtsAsetMstLokasiIdAsal 
		LEFT JOIN ruang d 
			ON d.ruangId = mtsAsetMstLokasiIdTuj
		JOIN satuan_barang_ref 
			ON satuanbrgId = barangSatuanbrgId
		JOIN user_unit_kerja v 
			ON v.userunitkerjaUnitkerjaId = a.unitkerjaId 
		JOIN user_unit_kerja w 
			ON w.userunitkerjaUnitkerjaId = b.unitkerjaId 
		JOIN gtfw_user r 
			ON r.UserId = v.userunitkerjaUserId 
		JOIN gtfw_user s 
			ON s.UserId = w.userunitkerjaUserId 
	WHERE mtsAsetMstBAMutasi = '%s' 
	GROUP BY CONCAT(
			LPAD(golbrgKode, 1, '0'),
			'.',
			LPAD(bidangbrgKode, 2, '0'),
			'.',
			LPAD(kelbrgKode, 2, '0'),
			'.',
			LPAD(subkelbrgKode, 2, '0'),
			'.',
			LPAD(barangKode, 3, '0'),
			'.'
		),
		merk 
";
?>
