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.PermohonanCutiPegawai;

/**
 * Repository class for PermohonanCutiPegawai
 * 
 * @author Generator
 */
@Repository("PermohonanCutiPegawaiDao")
public interface PermohonanCutiPegawaiDao extends PagingAndSortingRepository<PermohonanCutiPegawai, String> {
	
	@Query("select planning.noRec "
			+ "from PlanningPegawaiStatus planning "
			+ "left join planning.statusPegawaiPlan statPlan "
			+ "where planning.pegawaiId = :idPegawai "
			+ "and planning.statusEnabled is true "
			+ "and planning.approvalStatus <> 3 "
			+ "and statPlan.id in (1,6,24,25,26,27,28,29)")
	public List<String> getAllNorecPlanning(@Param("idPegawai") Integer idPegawai);
	
	@Query("select new Map(planning.noRec as noRec, planning.statusPegawaiPlanId as idStatusPegawaiPlan, listTgl.tgl as tgl) "
			+ "from PlanningPegawaiStatus planning "
			+ "left join planning.listTanggal listTgl "
			+ "where planning.statusEnabled is true "
			+ "and listTgl.statusEnabled is true "
			+ "and planning.pegawaiId = :idPegawai "
			+ "and planning.approvalStatus <> :approvalStatusId "
			+ "and planning.statusPegawaiPlanId in (:ketidakhadiranId) "
			+ "and to_char(listTgl.tgl, 'yyyy') in (:years) "
			+ "order by planning.noRec asc")
	public List<Map<String, Object>> getAllPlanning(@Param("idPegawai") Integer idPegawai, @Param("approvalStatusId") Integer approvalStatusId,
			@Param("ketidakhadiranId") List<Integer> ketidakhadiranId, @Param("years") List<String> years);
	
	@Query("select planning.noRec "
			+ "from PlanningPegawaiStatus planning "
			+ "left join planning.listTanggal listTgl "
			+ "where planning.statusEnabled is true "
			+ "and listTgl.statusEnabled is true "
			+ "and planning.pegawaiId = :idPegawai "
			+ "and planning.approvalStatus <> :approvalStatusId "
			+ "and planning.statusPegawaiPlanId in (:ketidakhadiranId) "
			+ "order by planning.noRec asc")
	public List<String> getAllNorecPlanning(@Param("idPegawai") Integer idPegawai, @Param("approvalStatusId") Integer approvalStatusId,
			@Param("ketidakhadiranId") List<Integer> ketidakhadiranId);

}
