<?php

//==========GET DATA ======================================
$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,
   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_pengelolaan']="
SELECT 
   SQL_CALC_FOUND_ROWS
   MONTH(transAtkMstTgl) AS bulan,
   YEAR(transAtkMstTgl) AS tahun,
   kd.kode,
   IF(invAtkDetMerk = '',invAtkDetLabel,CONCAT(invAtkDetLabel,' - ',invAtkDetMerk)) AS nama_brg,
   unitkerjaNama AS unit,
   SUM(transAtkDetJmlAtk) AS total
FROM aset_transaksi_atk_detil
LEFT JOIN inv_atk_det ON invAtkDetId = transAtkDetAtkId
LEFT JOIN inv_atk_master ON invAtkMstId = invAtkDetMstId
LEFT JOIN
(SELECT invAtkJenisRefId, CONCAT(LPAD(`golbrgKode`,1,0),'.',LPAD(`bidangbrgKode`,2,0),'.',LPAD(`kelbrgKode`,2,0),'.',LPAD(`subkelbrgKode`,2,0),'.',LPAD(`barangKode`,3,0),'.',invAtkKode) AS `kode`
FROM inv_atk_jenis_ref
LEFT JOIN barang_ref ON barangId = invAtkJenisBarangRefId
LEFT JOIN sub_kelompok_barang_ref ON subkelbrgId = barangSubkelbrgId
LEFT JOIN kelompok_barang_ref ON kelbrgId = subkelbrgKelbrgId
LEFT JOIN bidang_barang_ref ON bidangbrgId = kelbrgBidangbrgId
LEFT JOIN golongan_barang_ref ON golbrgId = bidangbrgGolbrgId) kd ON kd.invAtkJenisRefId = invAtkMstJenisPersediaanId
LEFT JOIN aset_transaksi_atk ON transAtkMstId = transAtkDetTransMstId
LEFT JOIN unit_kerja_ref ON unitkerjaId = transAtkMstUnitKerjaId
WHERE (unitkerjaKodeSistem = '%s' OR unitkerjaKodeSistem LIKE '%s')
[SEARCH_MONTH][SEARCH_YEAR][SEARCH_UNIT]
GROUP BY transAtkDetAtkId,transAtkMstUnitKerjaId, MONTH(transAtkMstTgl)
HAVING kd.kode LIKE '%s'
ORDER BY transAtkMstTgl DESC, unit
LIMIT %s,%s
";

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