package com.jasamedika.medifirst2000.dao;

import java.util.List;
import java.util.Map;

import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import com.jasamedika.medifirst2000.entities.MonitoringAbsen;
import com.jasamedika.medifirst2000.entities.Pegawai;

@Repository("MonitoringAbsenDao")
public interface MonitoringAbsenDao extends PagingAndSortingRepository<MonitoringAbsen, String> {

	@Query(" select monitoringAbsen.noRec" + " from MonitoringAbsen monitoringAbsen"
			+ " left join monitoringAbsen.pegawai pegawai"
			+ " where pegawai.id = :idPegawai and monitoringAbsen.tanggal = :date")
	public String findByIdPegawaiAndTanggal(@Param("idPegawai") Integer idPegawai, @Param("date") String date);

	@Query(" select new map(pegawai.nipPns as nip, pegawai.namaLengkap as nama,shift.kodeExternal as kodeShift, shift.namaShift as namaShift,"
			+ " shift.jamMasuk as jamMasuk, shift.jamPulang as jamPulang, shift.waktuIstirahat as waktuIstirahat, "
			+ " jabatanInternal.namaJabatan as jabatanInternal, ruangan.namaRuangan as namaRuangan, "
			+ " tanggal.hariKeDlmBulan as hari, tanggal.namaBulan as bulan, tanggal.tahunKalender as tahun, tanggal.hariKeDlmBulan as tgl,"
			+ " kelompokShiftKerja.id as idKelompokShiftKerja, unitKerja.name as unitKerja, "
			+ " tanggal.tanggal as tanggal, pegawai.idFinger as idFinger, shift.id as idShift,jadwalpegawai.keteranganAlasan as ket)"
			+ " from PegawaiJadwalKerja jadwalpegawai, MapPegawaiJabatanToUnitKerja mapPegawai "
			+ "left join jadwalpegawai.pegawai pegawai " + "left join pegawai.ruangan ruangan "
			+ "left join mapPegawai.subUnitKerjaPegawai subUnitKerja "
			+ "left join mapPegawai.unitKerjaPegawai unitKerja " + "left join jadwalpegawai.shift shift "
			+ "left join jadwalpegawai.tanggal tanggal " + "left join shift.kelompokShift kelompokShiftKerja "
			+ "left join mapPegawai.jabatan jabatanInternal " + "where mapPegawai.pegawaiId = pegawai.id "
			+ "and mapPegawai.isPrimary is true " + "and mapPegawai.statusEnabled is true "
			+ "and to_char(tanggal.tanggal,'yyyy-MM-dd') between :startDate and :endDate "
			+ "and pegawai.idFinger = :idFinger " + "and pegawai.statusEnabled is not false "
			+ "order by tanggal,pegawai.nama asc")
	public List<Map<String, Object>> findJadwalPegawai(@Param("idFinger") String idFinger,
			@Param("startDate") String startDate, @Param("endDate") String endDate);

	@Query("select new map(shift.kodeExternal as kodeShift, " + "shift.namaShift as namaShift, "
			+ "shift.jamMasuk as jamMasuk, " + "shift.jamPulang as jamPulang, "
			+ "shift.waktuIstirahat as waktuIstirahat, " + "kelompokShiftKerja.id as idKelompokShiftKerja, "
			+ "tanggal.tanggal as tanggal, " + "shift.id as idShift, " + "jadwalpegawai.keteranganAlasan as ket) "
			+ "from PegawaiJadwalKerja jadwalpegawai " + "left join jadwalpegawai.pegawai pegawai "
			+ "left join jadwalpegawai.shift shift " + "left join jadwalpegawai.tanggal tanggal "
			+ "left join shift.kelompokShift kelompokShiftKerja "
			+ "where to_char(tanggal.tanggal,'yyyy-MM-dd') = :tanggal " + "and pegawai.idFinger = :idFinger "
			+ "and pegawai.statusEnabled is not false " + "order by tanggal.tanggal asc")
	public Map<String, Object> findJadwalPegawai(@Param("idFinger") String idFinger, @Param("tanggal") String tanggal);

	@Query("select new map(shift.kodeExternal as kodeShift, " + "shift.namaShift as namaShift, "
			+ "shift.jamMasuk as jamMasuk, " + "shift.jamPulang as jamPulang, "
			+ "shift.waktuIstirahat as waktuIstirahat, " + "kelompokShiftKerja.id as idKelompokShiftKerja, "
			+ "tanggal.tanggal as tanggal, " + "shift.id as idShift, " + "jadwalpegawai.keteranganAlasan as ket) "
			+ "from PegawaiJadwalKerja jadwalpegawai " + "left join jadwalpegawai.pegawai pegawai "
			+ "left join jadwalpegawai.shift shift " + "left join jadwalpegawai.tanggal tanggal "
			+ "left join shift.kelompokShift kelompokShiftKerja "
			+ "where to_char(tanggal.tanggal,'yyyy-MM-dd') = :tanggal " + "and pegawai.idFinger = :idFinger "
			+ "and pegawai.statusEnabled is not false " + "order by tanggal.tanggal asc")
	public List<Map<String, Object>> getJadwalPegawai(@Param("idFinger") String idFinger,
			@Param("tanggal") String tanggal);

	@Query("select new map(shift.kodeExternal as kodeShift, " + "shift.namaShift as namaShift, "
			+ "shift.jamMasuk as jamMasuk, " + "shift.jamPulang as jamPulang, "
			+ "shift.waktuIstirahat as waktuIstirahat, " + "kelompokShiftKerja.id as idKelompokShiftKerja, "
			+ "tanggal.tanggal as tanggal, " + "shift.id as idShift, " + "jadwalpegawai.keteranganAlasan as ket) "
			+ "from PegawaiJadwalKerja jadwalpegawai " + "left join jadwalpegawai.pegawai pegawai "
			+ "left join jadwalpegawai.shift shift " + "left join jadwalpegawai.tanggal tanggal "
			+ "left join shift.kelompokShift kelompokShiftKerja "
			+ "where to_char(tanggal.tanggal,'yyyy-MM-dd') between :startDate and :endDate "
			+ "and pegawai.idFinger = :idFinger " + "and pegawai.statusEnabled is not false "
			+ "order by tanggal.tanggal asc")
	public List<Map<String, Object>> getJadwalPegawai(@Param("idFinger") String idFinger,
			@Param("startDate") String startDate, @Param("endDate") String endDate);

	@Query("select new map(tanggal.namaHari as namaHari, " + "tanggal.hariKeDlmBulan as hari, "
			+ "tanggal.namaBulan as bulan, " + "tanggal.tahunKalender as tahun, " + "tanggal.hariKeDlmBulan as tgl, "
			+ "tanggal.tanggal as tanggal,to_char(tanggal.tanggal,'yyyy-MM-dd') as tanggal2) "
			+ "from Kalender tanggal " + "where to_char(tanggal.tanggal,'yyyy-MM-dd') between :startDate and :endDate "
			+ "order by tanggal.tanggal asc")
	public List<Map<String, Object>> findKalender(@Param("startDate") String startDate,
			@Param("endDate") String endDate);

	@Query("select new Map(pegawai.nipPns as nip," + "pegawai.namaLengkap as nama," + "pegawai.idFinger as idFinger,"
			+ "pegawai.shiftKerjaId as idKelompokShiftKerja," + "jabatan.namaJabatan as jabatanInternal,"
			+ "unitKerja.name as unitKerja," + "kalender.namaHari as namaHari," + "kalender.hariKeDlmBulan as hari,"
			+ "kalender.namaBulan as bulan," + "kalender.tahunKalender as tahun," + "kalender.tanggal as tanggal,"
			+ "shiftKerja.id as idShift," + "shiftKerja.kodeExternal as kodeShift,"
			+ "shiftKerja.namaShift as namaShift," + "shiftKerja.jamMasuk as jamMasuk,"
			+ "shiftKerja.jamPulang as jamPulang," + "shiftKerja.waktuIstirahat as waktuIstirahat,"
			+ "jadwal.keteranganAlasan as ket) " + "from PegawaiJadwalKerja jadwal, "
			+ "MapPegawaiJabatanToUnitKerja mapJabatan " + "left join jadwal.pegawai pegawai "
			+ "left join jadwal.tanggal kalender " + "left join jadwal.shift shiftKerja "
			+ "left join mapJabatan.subUnitKerjaPegawai subunitKerja "
			+ "left join mapJabatan.unitKerjaPegawai unitKerja " + "left join mapJabatan.jabatan jabatan "
			+ "where mapJabatan.pegawaiId = pegawai.id " + "and mapJabatan.statusEnabled is true "
			+ "and pegawai.statusEnabled is true " + "and mapJabatan.isPrimary is true "
			+ "and pegawai.id = :idPegawai "
			+ "and to_char(kalender.tanggal,'yyyy-MM-dd') between :startDate and :endDate "
			+ "order by kalender.tanggal asc")
	public List<Map<String, Object>> getDataKomponenJadwal(@Param("idPegawai") Integer idPegawai,
			@Param("startDate") String startDate, @Param("endDate") String endDate);

	@Query(" select new map(pegawai.nipPns as nip, pegawai.namaLengkap as nama,shift.kodeExternal as kodeShift, shift.namaShift as namaShift,"
			+ " shift.jamMasuk as jamMasuk, shift.jamPulang as jamPulang, shift.waktuIstirahat as waktuIstirahat, "
			+ " jabatanInternal.namaJabatan as namaJabatanInternal, ruangan.namaRuangan as namaRuangan, "
			+ " tanggal.hariKeDlmBulan as hari, tanggal.namaBulan as bulan, tanggal.tahunKalender as tahun, tanggal.hariKeDlmBulan as tgl,"
			+ " kelompokShiftKerja.id as idKelompokShiftKerja, unitKerja.name as unitKerja, "
			+ " tanggal.tanggal as tanggal, pegawai.idFinger as idFinger, shift.id as idShift,jadwalpegawai.keteranganAlasan as ket) "
			+ "from PegawaiJadwalKerja jadwalpegawai, MapPegawaiJabatanToUnitKerja mapPegawai "
			+ "left join jadwalpegawai.pegawai pegawai " + "left join pegawai.ruangan ruangan "
			+ "left join mapPegawai.unitKerjaPegawai unitKerja " + "left join jadwalpegawai.shift shift "
			+ "left join jadwalpegawai.tanggal tanggal " + "left join shift.kelompokShift kelompokShiftKerja "
			+ "left join mapPegawai.jabatan jabatanInternal " + "where mapPegawai.pegawaiId = pegawai.id "
			+ "and mapPegawai.isPrimary is true " + "and mapPegawai.statusEnabled is true "
			+ "and to_char(tanggal.tanggal,'yyyy-MM-dd') = :date " + "and pegawai.idFinger = :idFinger "
			+ "order by tanggal, pegawai.nama asc")
	public Map<String, Object> findJadwalPegawaiToday(@Param("idFinger") String idFinger, @Param("date") String date);

	@Query("select pegawai.id  " + "from MapPegawaiJabatanToUnitKerja mapPegawai "
			+ "left join mapPegawai.pegawai pegawai " + "left join pegawai.shiftKerja shiftKerja "
			+ "left join mapPegawai.subUnitKerjaPegawai subUnitKerja "
			+ "left join mapPegawai.unitKerjaPegawai unitKerja " + "where pegawai.statusEnabled is true "
			+ "and subUnitKerja.id = :idUnitKerja " + "and mapPegawai.isPrimary is true "
			+ "and mapPegawai.statusEnabled is true " + "order by pegawai.nama asc")
	public List<Integer> findPegawaiaAktifDanKaryawanByRuangan(@Param("idUnitKerja") Integer idUnitKerja);

	@Query("select new Map(pegawai.id as idPegawai," + "pegawai.namaLengkap as nama," + "pegawai.nipPns as nipPns,"
			+ "golongan.golonganPegawai as namaGolongan," + "jabatanInternal.namaJabatan as jabatanInternal,"
			+ "unitKerja.name as unitKerja," + "shiftKerja.id as idKelompokShiftKerja,"
			+ "shiftKerja.name as shiftKerja," + "shiftKerja.operatorFactorRate as headOperatorFactorRate,"
			+ "shiftKerja.factorRate as headFactorRate) " + "from MapPegawaiJabatanToUnitKerja mapPegawai "
			+ "left join mapPegawai.pegawai pegawai " + "left join pegawai.shiftKerja shiftKerja "
			+ "left join pegawai.golonganPegawai golongan " + "left join mappegawai.jabatan jabatanInternal "
			+ "left join mapPegawai.subUnitKerjaPegawai subUnitKerja "
			+ "left join mapPegawai.unitKerjaPegawai unitKerja " + "where pegawai.statusEnabled is true "
			+ "and mapPegawai.isPrimary is true " + "and mapPegawai.statusEnabled is true "
			+ "and subUnitKerja.id = :idUnitKerja " + "order by pegawai.nama asc")
	public List<Map<String, Object>> getDataPegawaiaAktifDanKaryawanByRuangan(
			@Param("idUnitKerja") Integer idUnitKerja);

	@Query("select new Map(pegawai.id as id, pegawai.idFinger as idFinger) "
			+ "from MapPegawaiJabatanToUnitKerja mapPegawai " + "left join mapPegawai.pegawai pegawai "
			+ "left join pegawai.shiftKerja shiftKerja " + "left join mapPegawai.subUnitKerjaPegawai subUnitKerja "
			+ "left join mapPegawai.unitKerjaPegawai unitKerja " + "where pegawai.statusEnabled is true "
			+ "and subUnitKerja.id = :idUnitKerja " + "and mapPegawai.isPrimary is true "
			+ "and mapPegawai.statusEnabled is true " + "order by pegawai.nama asc")
	public List<Map<String, Object>> findPegawaiDanIdFingeraAktifDanKaryawanByRuangan(
			@Param("idUnitKerja") Integer idUnitKerja);

	@Query("select new map(pegawai.id as pegawaiId," + "pegawai.nipPns as nip, " + "pegawai.namaLengkap as nama, "
			+ "jabatanInternal.namaJabatan as jabatanInternal, " + "ruangan.namaRuangan as namaRuangan, "
			+ "unitKerja.name as unitKerja, " + "pegawai.idFinger as fingerId) "
			+ "from Pegawai pegawai, MapPegawaiJabatanToUnitKerja mapPegawai " + "left join pegawai.ruangan ruangan "
			+ "left join mapPegawai.subUnitKerjaPegawai subUnitKerja "
			+ "left join mapPegawai.unitKerjaPegawai unitKerja " + "left join mapPegawai.jabatan jabatanInternal "
			+ "where pegawai.id = mapPegawai.pegawaiId " + "and mapPegawai.isPrimary is true "
			+ "and mapPegawai.statusEnabled is true " + "and pegawai.id = :pegawaiId "
			+ "and pegawai.statusEnabled is true " + "order by pegawai.nama asc")
	public List<Map<String, Object>> findPegawaiAktifDanKaryawan(@Param("pegawaiId") Integer idPegawai);

	@Query("select pegawai.id  " + "from MapPegawaiJabatanToUnitKerja mapPegawai "
			+ "left join mapPegawai.pegawai pegawai " + "left join pegawai.shiftKerja shiftKerja "
			+ "left join mapPegawai.subUnitKerjaPegawai subUnitKerja "
			+ "left join mapPegawai.unitKerjaPegawai unitKerja " + "where mapPegawai.statusEnabled is true "
			+ "and unitKerja.id = :idUnitKerja " + "and pegawai.statusEnabled is not false "
			+ "and pegawai.idFinger is not null " + "order by pegawai.nama asc")
	public List<Integer> findPegawaiAktifDanKaryawanByUnitKerja(@Param("idUnitKerja") Integer idUnitKerja);

	@Query("select pegawai.id  " + "from MapPegawaiJabatanToUnitKerja mapPegawai "
			+ "left join mapPegawai.pegawai pegawai " + "left join pegawai.shiftKerja shiftKerja "
			+ "left join mapPegawai.subUnitKerjaPegawai subUnitKerja "
			+ "left join mapPegawai.unitKerjaPegawai unitKerja " + "where unitKerja.id = :idUnitKerja "
			+ "and subUnitKerja.id = :idSubUnitKerja " + "and mapPegawai.statusEnabled is true "
			+ "and pegawai.idFinger is not null " + "and pegawai.statusEnabled is true " + "order by pegawai.nama asc")
	public List<Integer> findPegawaiAktifDanKaryawanByUnitKerjaAndSubUnitKerja(
			@Param("idUnitKerja") Integer idUnitKerja, @Param("idSubUnitKerja") Integer idSubUnitKerja);

	@Query(" select pegawai.id" + " from Pegawai pegawai" + " left join pegawai.ruangan ruangan"
			+ " where ruangan.id = :ruanganId order by pegawai.nama asc ")
	public List<Integer> findByIdPegawaiByRuangan(@Param("ruanganId") Integer ruanganId);

	@Query("select new map(shiftKerja.id as idShiftKerja, " + "shiftKerja.namaShift as namaShift, "
			+ "komponenIndex.factorRate as factorRate, " + "komponenIndex.komponenIndex as namaKomponenIndex, "
			+ "kelompokShift.id as idKelompokShift, " + "kelompokShift.name as nama, "
			+ "komponenIndex.operatorFactorRate as operatorFactorRate, "
			+ "kelompokShift.operatorFactorRate as headOperatorFactorRate, "
			+ "kelompokShift.factorRate as headFactorRate, " + "komponenIndex.id as idKomponenIndex) "
			+ "from ShiftKerja shiftKerja " + "left join shiftKerja.kelompokShift kelompokShift "
			+ "left join shiftKerja.komponenIndex komponenIndex " + "where kelompokShift.id = :idKelompokShift")
	public List<Map<String, Object>> findShiftpegawai(@Param("idKelompokShift") Integer idKelompokShift);

	@Query("select new map(kelompokShift.id as idKelompokShift, " + "kelompokShift.name as nama, "
			+ "kelompokShift.operatorFactorRate as headOperatorFactorRate, "
			+ "kelompokShift.factorRate as headFactorRate) " + "from KelompokShift kelompokShift "
			+ "where kelompokShift.id = :idKelompokShift")
	public Map<String, Object> findKelompokShiftpegawai(@Param("idKelompokShift") Integer idKelompokShift);

	@Query("select new map(shiftKerja.id as idShiftKerja, " + "shiftKerja.namaShift as namaShift, "
			+ "shiftKerja.factorRate as factorRate, " + "komponenIndex.komponenIndex as namaKomponenIndex, "
			+ "kelompokShift.id as idKelompokShift, " + "kelompokShift.name as nama, "
			+ "komponenIndex.operatorFactorRate as operatorFactorRate, "
			+ "kelompokShift.operatorFactorRate as headOperatorFactorRate, "
			+ "kelompokShift.factorRate as headFactorRate, " + "komponenIndex.id as idKomponenIndex) "
			+ "from ShiftKerja shiftKerja " + "left join shiftKerja.kelompokShift kelompokShift "
			+ "left join shiftKerja.komponenIndex komponenIndex "
			+ "where kelompokShift.id = :idKelompokShift and shiftKerja.id =:idShift")
	public Map<String, Object> findShiftpegawaiDetail(@Param("idKelompokShift") Integer idKelompokShift,
			@Param("idShift") Integer idShift);

	@Query("select new map(shiftKerja.jamMasuk as jamMasuk, " + "shiftKerja.jamPulang as jamPulang, "
			+ "shiftKerja.jamBreakAkhir as jamBreakAkhir, " + "shiftKerja.jamBreakAwal as jamBreakAwal, "
			+ "shiftKerja.factorRate as factorRate, " + "shiftKerja.operatorFactorRate as operatorFactorRate, "
			+ "shiftKerja.komponenIndexId as komponenIndexId, " + "shiftKerja.waktuIstirahat as waktuIstirahat) "
			+ "from ShiftKerja shiftKerja " + "left join shiftKerja.kelompokShift kelompokShift "
			+ "left join shiftKerja.komponenIndex komponenIndex " + "where kelompokShift.id = :idKelompokShift "
			+ "and shiftKerja.namaShift = :namaShift " + "and shiftKerja.kodeExternal = :kodeExternal")
	public Map<String, Object> findShiftPMDetail(@Param("idKelompokShift") Integer idKelompokShift,
			@Param("namaShift") String namaShift, @Param("kodeExternal") String kodeExternal);

	@Query("select distinct new map(pegawaiHistoriRekapIndex.nilaiIndex as nilaiIndex, "
			+ "pegawaiHistoriRekapIndex.nilaiIndexTotal as nilaiIndexTotal,  "
			+ "komponenIndex.komponenIndex as namaKomponenIndex,  " + "komponenIndex.id as idKomponenIndex,  "
			+ "komponenIndex.factorRate as factorRate,  " + "strukHistory.tglHistori as tglHistori,  "
			+ "strukHistory.tglAhir as tglAkhir,  " + "strukHistory.tglAwal as tglAwal)  "
			+ "from PegawaiHistoriRekapIndex pegawaiHistoriRekapIndex, PlanningPegawaiStatus planning "
			+ "left join pegawaiHistoriRekapIndex.komponenIndex komponenIndex   "
			+ "left join pegawaiHistoriRekapIndex.strukHistory strukHistory  "
			+ "left join pegawaiHistoriRekapIndex.pegawai pegawai  " + "left join planning.listTanggal listTanggal "
			+ "where planning.noRec = pegawaiHistoriRekapIndex.noRecPlanningPerubahanStatus and  "
			+ "to_char(listTanggal.tgl, 'yyyy-MM-dd')between :tglAwal and :tglAkhir  "
			+ "and pegawai.id =:idPegawai and listTanggal.approvalStatus is true ")
	public List<Map<String, Object>> findKomponenIndex(@Param("tglAwal") String tglAwal,
			@Param("tglAkhir") String tglAkhir, @Param("idPegawai") Integer idPegawai);

	@Query("select distinct new map(count(listTanggal.tgl) as nilaiIndex, "
			+ "pegawaiHistoriRekapIndex.nilaiIndex as nilaiIndexPembanding, "
			+ "pegawaiHistoriRekapIndex.nilaiIndexTotal as nilaiIndexTotal,  "
			+ "komponenIndex.komponenIndex as namaKomponenIndex,  " + "komponenIndex.id as idKomponenIndex,  "
			+ "komponenIndex.factorRate as factorRate,  " + "strukHistory.tglHistori as tglHistori,  "
			+ "strukHistory.tglAhir as tglAkhir,  " + "strukHistory.tglAwal as tglAwal,  "
			+ "statusPegawai.statusPegawai as statusPegawai)  "
			+ "from PegawaiHistoriRekapIndex pegawaiHistoriRekapIndex, PlanningPegawaiStatus planning "
			+ "left join pegawaiHistoriRekapIndex.komponenIndex komponenIndex   "
			+ "left join pegawaiHistoriRekapIndex.strukHistory strukHistory  "
			+ "left join pegawaiHistoriRekapIndex.pegawai pegawai  " + "left join planning.listTanggal listTanggal "
			+ "left join planning.statusPegawaiExec statusPegawai "
			+ "where planning.noRec = pegawaiHistoriRekapIndex.noRecPlanningPerubahanStatus and  "
			+ "to_char(listTanggal.tgl, 'yyyy-MM-dd')between :tglAwal and :tglAkhir  "
			+ "and pegawai.id =:idPegawai and listTanggal.approvalStatus is true "
			+ "group by pegawaiHistoriRekapIndex.nilaiIndex, pegawaiHistoriRekapIndex.nilaiIndexTotal, "
			+ "komponenIndex.komponenIndex, komponenIndex.id, " + "komponenIndex.factorRate, strukHistory.tglHistori, "
			+ "strukHistory.tglAhir, strukHistory.tglAwal, statusPegawai.statusPegawai")
	public List<Map<String, Object>> countKomponenIndex(@Param("tglAwal") String tglAwal,
			@Param("tglAkhir") String tglAkhir, @Param("idPegawai") Integer idPegawai);

	@Query("select new map(pegawaiHistoriRekapIndex.nilaiIndex as nilaiIndex, "
			+ "pegawaiHistoriRekapIndex.nilaiIndexTotal as nilaiIndexTotal, "
			+ "komponenIndex.komponenIndex as namaKomponenIndex, " + "komponenIndex.id as idKomponenIndex, "
			+ "komponenIndex.factorRate as factorRate, " + "strukHistory.tglHistori as tglHistori, "
			+ "strukHistory.tglAhir as tglAkhir, " + "strukHistory.tglAwal as tglAwal) "
			+ "from PegawaiHistoriRekapIndex pegawaiHistoriRekapIndex "
			+ "left join pegawaiHistoriRekapIndex.komponenIndex komponenIndex  "
			+ "left join pegawaiHistoriRekapIndex.strukHistory strukHistory "
			+ "left join pegawaiHistoriRekapIndex.pegawai pegawai "
			+ "where to_char(strukHistory.tglAwal, 'yyyy') = :tahun "
			+ "and pegawai.id =:idPegawai and komponenIndex.id =17")
	public List<Map<String, Object>> findKomponenIndexIjin(@Param("idPegawai") Integer idPegawai,
			@Param("tahun") String tahun);

	@Query("select distinct verifSDM.keteranganlainnya " + "from MonitoringAbsen monitoring "
			+ "join monitoring.strukVerifikasiSdm verifSDM " + "left join monitoring.pegawai pegawai "
			+ "where pegawai.id = :idPegawai and monitoring.tanggal = :tgl ")
	public String findLemburVerifiedbySDM(@Param("idPegawai") Integer idPegawai, @Param("tgl") String tgl);

	//
	@Query("select new map(kelompokShift.name as name, " + "kelompokShift.id as id, "
			+ "factoRateKelompokShift.noRec as noRec, " + "factoRateKelompokShift.factorRate as factorRate, "
			+ "factoRateKelompokShift.hari as hari, " + "factoRateKelompokShift.periode as periode) "
			+ "from FactoRateKelompokShift factoRateKelompokShift "
			+ "left join factoRateKelompokShift.kelompokShift kelompokShift "
			+ "where factoRateKelompokShift.factorRate is not null and factoRateKelompokShift.periode = :periode")
	public List<Map<String, Object>> findFactorRateIndekkehadiran(@Param("periode") String periode);

	@Query("select new map(komponenIndex.factorRate as factorRate, "
			+ "komponenIndex.operatorFactorRate as operatorFactorRate) " + "from KomponenIndex komponenIndex "
			+ "where komponenIndex.id=12")
	public Map<String, Object> findFactorRateTerlambat();

	@Query(" select monitoringAbsen" + " from MonitoringAbsen monitoringAbsen"
			+ " left join monitoringAbsen.pegawai pegawai"
			+ " where pegawai.id = :idPegawai and monitoringAbsen.tanggal = :date")
	public MonitoringAbsen findByIdPegawaiAndTanggalMonitoringAbsen(@Param("idPegawai") Integer idPegawai,
			@Param("date") String date);

	@Query(" SELECT distinct new Pegawai(pegawai.id,pegawai.namaLengkap) FROM " + " MonitoringAbsen monitoringAbsen"
			+ " LEFT JOIN monitoringAbsen.pegawai pegawai "
			+ " WHERE monitoringAbsen.verifikasiUnitKerjaFK IS NOT NULL "
			+ " AND pegawai.statusPegawai.kdStatusPegawai=2")
	public List<Pegawai> findPegawaiAktifAndVerifiedByUnitKerja();

	@Query(" SELECT new Map(count(monitoringAbsen.verifikasiUnitKerjaFK),monitoringAbsen.verifikasiSdmFK,monitoringAbsen.pegawaiId ) "
			+ " FROM MonitoringAbsen monitoringAbsen " + " WHERE  monitoringAbsen.tanggal like  :bulan"
			+ " GROUP BY monitoringAbsen.verifikasiSdmFK,monitoringAbsen.pegawaiId ")
	public List<Map<String, Object>> findLemburByPeriodApprovedBySdm(@Param("bulan") String bulan);

	@Query("SELECT new map(min(model.tanggal) as tglAwal,max(model.tanggal) as tglAkhir) from Kalender model where  model.tahunKalender=:tahun and model.namaBulan=:bulan")
	public Map<String, Object> findPeriodeKalenderS(@Param("tahun") short tahun, @Param("bulan") String bulan);

	@Query("SELECT distinct model.bulanKeDlmTahun from Kalender model where  model.tahunKalender=:tahun and model.namaBulan=:bulan")
	public Integer findBulan(@Param("tahun") short tahun, @Param("bulan") String bulan);

	@Query("select new Map(mapPegawai.isMonitoring as isMonitoring, " + "mapPegawai.isPrimary as isPrimary) "
			+ "from MapPegawaiJabatanToUnitKerja mapPegawai " + "left join mapPegawai.pegawai pegawai "
			+ "where mapPegawai.statusEnabled is true " + "and mapPegawai.unitKerjaPegawaiId = :idUnitKerja "
			+ "and mapPegawai.subUnitKerjaPegawaiId = :idSubUnitKerja " + "and mapPegawai.pegawaiId = :idPegawaiLogin "
			+ "and pegawai.kedudukanId not in (:listException) " + "order by pegawai.namaLengkap")
	public List<Map<String, Object>> checkAuthMonitoring(@Param("idUnitKerja") Integer idUnitKerja,
			@Param("idSubUnitKerja") Integer idSubUnitKerja, @Param("idPegawaiLogin") Integer idPegawaiLogin,
			@Param("listException") List<Integer> listException);

	@Query("select new Map(mapPegawai.isMonitoring as isMonitoring, " + "mapPegawai.isPrimary as isPrimary, "
			+ "jabatan.levelJabatan as levelJabatan) " + "from MapPegawaiJabatanToUnitKerja mapPegawai "
			+ "left join mapPegawai.pegawai pegawai " + "left join mapPegawai.jabatan jabatan "
			+ "where mapPegawai.statusEnabled is true " + "and mapPegawai.unitKerjaPegawaiId = :idUnitKerja "
			+ "and mapPegawai.pegawaiId = :idPegawaiLogin " + "and pegawai.kedudukanId not in (:listException) "
			+ "order by pegawai.namaLengkap")
	public List<Map<String, Object>> checkAuthMonitoring(@Param("idUnitKerja") Integer idUnitKerja,
			@Param("idPegawaiLogin") Integer idPegawaiLogin, @Param("listException") List<Integer> listException);

	@Query("select new Map(pegawai.id as id, " + "pegawai.namaLengkap as namaLengkap) "
			+ "from MapPegawaiJabatanToUnitKerja mapPegawai " + "left join mapPegawai.pegawai pegawai "
			+ "where mapPegawai.statusEnabled is true " + "and pegawai.statusEnabled is true "
			+ "and mapPegawai.unitKerjaPegawaiId = :idUnitKerja "
			+ "and mapPegawai.subUnitKerjaPegawaiId = :idSubUnitKerja " + "and mapPegawai.pegawaiId = :idPegawaiLogin "
			+ "and pegawai.kedudukanId not in (:listException) " + "order by pegawai.namaLengkap")
	public List<Map<String, Object>> getDataPegawaiRev(@Param("idUnitKerja") Integer idUnitKerja,
			@Param("idSubUnitKerja") Integer idSubUnitKerja, @Param("idPegawaiLogin") Integer idPegawaiLogin,
			@Param("listException") List<Integer> listException);

	@Query("select distinct new Map(pegawai.id as id, " + "pegawai.namaLengkap as namaLengkap) "
			+ "from MapPegawaiJabatanToUnitKerja mapPegawai " + "left join mapPegawai.pegawai pegawai "
			+ "where mapPegawai.statusEnabled is true " + "and pegawai.statusEnabled is true "
			+ "and mapPegawai.unitKerjaPegawaiId = :idUnitKerja "
			+ "and mapPegawai.subUnitKerjaPegawaiId = :idSubUnitKerja " +
			// "and mapPegawai.isPrimary is true "+
			"and pegawai.kedudukanId not in (:listException) " + "order by namaLengkap")
	public List<Map<String, Object>> getDataPegawaiRev(@Param("idUnitKerja") Integer idUnitKerja,
			@Param("idSubUnitKerja") Integer idSubUnitKerja, @Param("listException") List<Integer> listException);

	@Query("select distinct new Map(pegawai.id as id, " + "pegawai.namaLengkap as namaLengkap) "
			+ "from MapPegawaiJabatanToUnitKerja mapPegawai " + "left join mapPegawai.pegawai pegawai "
			+ "where mapPegawai.statusEnabled is true " + "and pegawai.statusEnabled is true "
			+ "and mapPegawai.unitKerjaPegawaiId = :idUnitKerja " +
			// "and mapPegawai.subUnitKerjaPegawaiId = :idSubUnitKerja "+
			// "and mapPegawai.isPrimary is true "+
			"and pegawai.kedudukanId not in (:listException) " + "order by namaLengkap")
	public List<Map<String, Object>> getDataPegawaiRev(@Param("idUnitKerja") Integer idUnitKerja,
			@Param("listException") List<Integer> listException);

	@Query("select distinct new Map(pg.id as id,pg.namaLengkap as namaLengkap) "
			+ "from MapPegawaiJabatanToUnitKerja mp " + "left join mp.pegawai pg "
			+ "left join mp.jabatan jb with jb.statusEnabled is true "
			+ "where mp.statusEnabled is true and pg.statusEnabled is true "
			+ "and pg.kedudukanId not in (:listException) " + "and mp.unitKerjaPegawaiId = :idUnitKerja "
			+ "and jb.levelJabatan = :levelJabatan+1 " // satu_level_dibawah_pegawai_login
			+ "and jb.subLevelJabatan = :sublevelJabatan")
	public List<Map<String, Object>> getDataPegawaiDirektur(@Param("idUnitKerja") Integer idUnitKerja,
			@Param("levelJabatan") Integer levelJabatan, @Param("sublevelJabatan") Integer sublevelJabatan,
			@Param("listException") List<Integer> listException);

	String jumPresDP = "select new Map(mj.unitKerjaPegawaiId as unitKerjaId,"
			+ "mj.subUnitKerjaPegawaiId as subunitKerjaId," + "mj.pegawaiId as pegawaiId," + "pg.namaLengkap as nama,"
			+ "pg.nipPns as nip," + "pg.shiftKerjaId as kelompokShiftId," + "pg.idFinger as fingerId,"
			+ "uk.name as unitKerja) " + "from MapPegawaiJabatanToUnitKerja mj " + "left join mj.pegawai pg "
			+ "left join mj.unitKerjaPegawai uk " + "where mj.statusEnabled is true " + "and pg.statusEnabled is true "
			+ "and pg.idFinger is not null ";

	String jumPresDPUnitKerja = "and mj.unitKerjaPegawaiId = :unitKerjaId ";

	String jumPresDPSubunitKerja = "and mj.subUnitKerjaPegawaiId = :subunitKerjaId ";

	String jumPresDPPegawai = "and mj.pegawaiId = :pegawaiId ";

	String sortJumPresDP = "order by pg.nama asc";

	@Query(jumPresDP + jumPresDPUnitKerja + jumPresDPSubunitKerja + sortJumPresDP)
	public List<Map<String, Object>> getDataPegawaiPresensiSubunitKerja(@Param("unitKerjaId") Integer idUnitKerja,
			@Param("subunitKerjaId") Integer idSubunitKerja);

	@Query(jumPresDP + jumPresDPUnitKerja + sortJumPresDP)
	public List<Map<String, Object>> getDataPegawaiPresensiUnitKerja(@Param("unitKerjaId") Integer idUnitKerja);

	@Query(jumPresDP + jumPresDPPegawai + sortJumPresDP)
	public List<Map<String, Object>> getDataPegawaiPresensiPegawai(@Param("pegawaiId") Integer idPegawai);

	String jumPresDJb = "select new Map(mj.unitKerjaPegawaiId as unitKerjaId,"
			+ "mj.subUnitKerjaPegawaiId as subunitKerjaId," + "mj.pegawaiId as pegawaiId,"
			+ "jb.namaJabatan as jabatan) " + "from MapPegawaiJabatanToUnitKerja mj " + "left join mj.pegawai pg "
			+ "left join mj.jabatan jb " + "where mj.statusEnabled is true " + "and pg.statusEnabled is true "
			+ "and pg.idFinger is not null ";

	String jumPresDJbUnitKerja = "and mj.unitKerjaPegawaiId = :unitKerjaId ";

	String jumPresDJbSubunitKerja = "and mj.subUnitKerjaPegawaiId = :subunitKerjaId ";

	String jumPresDJbPegawai = "and mj.pegawaiId = :pegawaiId ";

	String sortJumPresDJb = "order by pg.nama asc";

	@Query(jumPresDJb + jumPresDJbUnitKerja + jumPresDJbSubunitKerja + sortJumPresDJb)
	public List<Map<String, Object>> getDataJabatanPresensiSubunitKerja(@Param("unitKerjaId") Integer idUnitKerja,
			@Param("subunitKerjaId") Integer idSubunitKerja);

	@Query(jumPresDJb + jumPresDJbUnitKerja + sortJumPresDJb)
	public List<Map<String, Object>> getDataJabatanPresensiUnitKerja(@Param("unitKerjaId") Integer idUnitKerja);

	@Query(jumPresDJb + jumPresDJbPegawai + sortJumPresDJb)
	public List<Map<String, Object>> getDataJabatanPresensiPegawai(@Param("pegawaiId") Integer idPegawai);

	String jumPresDJd = "select new Map(kl.tanggal as date," + "mj.unitKerjaPegawaiId as unitKerjaId,"
			+ "mj.subUnitKerjaPegawaiId as subunitKerjaId," + "mj.pegawaiId as pegawaiId," + "sk.id as shiftId,"
			+ "sk.kodeExternal as kodeShift," + "sk.namaShift as namaShift," + "sk.jamMasuk as jadwalMasuk,"
			+ "sk.jamPulang as jadwalPulang," + "sk.waktuIstirahat as waktuIstirahat) "
			+ "from PegawaiJadwalKerja jkp, " + "MapPegawaiJabatanToUnitKerja mj " + "left join jkp.pegawai pg "
			+ "left join jkp.tanggal kl " + "left join jkp.shift sk " + "where jkp.pegawaiId = mj.pegawaiId "
			+ "and mj.statusEnabled is true " + "and pg.statusEnabled is true " + "and pg.idFinger is not null "
			+ "and to_char(kl.tanggal,'yyyy-MM-dd') between :startDate and :endDate ";

	String jumPresDJdUnitKerja = "and mj.unitKerjaPegawaiId = :unitKerjaId ";

	String jumPresDJdSubunitKerja = "and mj.subUnitKerjaPegawaiId = :subunitKerjaId ";

	String jumPresDJdPegawai = "and mj.pegawaiId = :pegawaiId ";

	String sortJumPresDJd = "order by pg.nama, kl.tanggal asc";

	@Query(jumPresDJd + jumPresDJdUnitKerja + jumPresDJdSubunitKerja + sortJumPresDJd)
	public List<Map<String, Object>> getDataJadwalPresensiSubunitKerja(@Param("startDate") String startDate,
			@Param("endDate") String endDate, @Param("unitKerjaId") Integer idUnitKerja,
			@Param("subunitKerjaId") Integer idSubunitKerja);

	@Query(jumPresDJd + jumPresDJdUnitKerja + sortJumPresDJd)
	public List<Map<String, Object>> getDataJadwalPresensiUnitKerja(@Param("startDate") String startDate,
			@Param("endDate") String endDate, @Param("unitKerjaId") Integer idUnitKerja);

	@Query(jumPresDJd + jumPresDJdPegawai + sortJumPresDJd)
	public List<Map<String, Object>> getDataJadwalPresensiPegawai(@Param("startDate") String startDate,
			@Param("endDate") String endDate, @Param("pegawaiId") Integer idPegawai);

	String jumPresHab = "select new Map(kl.tanggal as date," + "mj.unitKerjaPegawaiId as unitKerjaId,"
			+ "mj.subUnitKerjaPegawaiId as subunitKerjaId," + "mj.pegawaiId as pegawaiId," + "hab.tr_no as trNo,"
			+ "hab.tr_time as trTime," + "hab.processtatus as procesStatus," + "hab.ip_addr as ipAddr) "
			+ "from MapPegawaiJabatanToUnitKerja mj, " + "Kalender kl, " + "Habsen hab " + "left join mj.pegawai pg "
			+ "where kl.tanggal = hab.tr_date " + "and hab.empl_code = pg.idFinger " + "and mj.statusEnabled is true "
			+ "and pg.statusEnabled is true " + "and pg.idFinger is not null " + "and hab.loc_code = '99999' "
			+ "and hab.remoteno = '99' " + "and to_char(kl.tanggal,'yyyy-MM-dd') between :startDate and :endDate ";

	String jumPresHabUnitKerja = "and mj.unitKerjaPegawaiId = :unitKerjaId ";

	String jumPresHabSubunitKerja = "and mj.subUnitKerjaPegawaiId = :subunitKerjaId ";

	String jumPresHabPegawai = "and mj.pegawaiId = :pegawaiId ";

	String sortJumPresHab = "order by pg.nama, kl.tanggal, hab.tr_time asc";

	@Query(jumPresHab + jumPresHabUnitKerja + jumPresHabSubunitKerja + sortJumPresHab)
	public List<Map<String, Object>> getDataPresensiSubunitKerja(@Param("startDate") String startDate,
			@Param("endDate") String endDate, @Param("unitKerjaId") Integer idUnitKerja,
			@Param("subunitKerjaId") Integer idSubunitKerja);

	@Query(jumPresHab + jumPresHabUnitKerja + sortJumPresHab)
	public List<Map<String, Object>> getDataPresensiUnitKerja(@Param("startDate") String startDate,
			@Param("endDate") String endDate, @Param("unitKerjaId") Integer idUnitKerja);

	@Query(jumPresHab + jumPresHabPegawai + sortJumPresHab)
	public List<Map<String, Object>> getDataPresensiPegawai(@Param("startDate") String startDate,
			@Param("endDate") String endDate, @Param("pegawaiId") Integer idPegawai);

}
