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.CrudRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import com.jasamedika.medifirst2000.entities.PegawaiSKPajak;

@Repository("PegawaiSKPajakDao")
public interface PegawaiSKPajakDao extends CrudRepository<PegawaiSKPajak, Integer> {

	// Potongan Pajak (ID=42)
	/*
	@Query("select new Map(pj.id AS ID, p.nipPns AS NIP, p.namaLengkap AS NamaLengkap, g.name AS Golongan, pdk.namaPendidikan AS Pendidikan, "
		+ "EXTRACT(year FROM (current_date)) - EXTRACT(year FROM (p.tglMasuk)) AS MasaKerja, jf.namaJabatan AS Jabatan, 'PotonganPajak' AS KomponenHarga, pj.persenPajak AS Harga) "
		+ "from PegawaiSKPajak pj " 
		+ "left join pj.pegawai p " 
		+ "left join p.detailKategoryPegawai dkp "
		+ "left join p.Golongan g " 
		+ "left join p.pendidikan pdk " 
		+ "left join p.jabatanFungsional jf "
		+ "where dkp.detailKategoryPegawai.id=:idDetailKategoriPegawai "
		+ "and pj.golonganPegawai and p.golonganPegawai")
	List<Map<String, Object>> findPotonganPajak(@Param("idDetailKategoriPegawai") Integer idDetailKategoriPegawai);
	*/

	@Query("select new Map(model.id as pegawaiSkPajakId, "
			+"suratkeputusan.id as suratKeputusanId, "
			+"suratkeputusan.noSK as noSuratKeputusan, "
			+"suratkeputusan.namaSK as namaSuratKeputusan, "
			+"to_char(suratkeputusan.tglBerlakuAwal,'dd-mm-yyyy') as tglBerlakuAwal, "
			+"to_char(suratkeputusan.tglBerlakuAkhir,'dd-mm-yyyy') as tglBerlakuAkhir, "
			+"ruangan.id as ruanganId, "
			+"ruangan.namaRuangan as namaRuangan, "
			+"golonganpegawai.id as golonganPegawaiId, "
			+"golonganpegawai.golonganPegawai as golonganPegawai, "
			+"objekpajak.id as objekpajakId, "
			+"objekpajak.objekPajak as objekPajak, "
			+"model.persenPajak as persenPajak, "
			+"model.statusEnabled as statusEnabled "
			+") from PegawaiSKPajak model  "
			+"left join model.noSK suratkeputusan " 
			+"left join suratkeputusan.ruangan ruangan " 
			+"left join model.golonganPegawai golonganpegawai " 
			+"left join model.objekPajak objekpajak "
			+"left join model.range range "
			+ "where model.id =:idPegawaiSkPajak")
	Map<String,Object> get(@Param("idPegawaiSkPajak") Integer idPegawaiSkPajak);
	
	@Query("select new Map(model.id as pegawaiSkPajakId, "
		+"suratkeputusan.id as suratKeputusanId, "
		+"suratkeputusan.noSK as noSuratKeputusan, "
		+"suratkeputusan.namaSK as namaSuratKeputusan, "
		+"to_char(suratkeputusan.tglBerlakuAwal,'dd-MM-yyyy') as tglBerlakuAwal, "
		+"to_char(suratkeputusan.tglBerlakuAkhir,'dd-MM-yyyy') as tglBerlakuAkhir, "
		+"ruangan.id as ruanganId, "
		+"ruangan.namaRuangan as namaRuangan, "
		+"golonganpegawai.id as golonganPegawaiId, "
		+"golonganpegawai.golonganPegawai as golonganPegawai, "
		+"objekpajak.id as objekpajakId, "
		+"objekpajak.objekPajak as objekPajak, "
		+"model.persenPajak as persenPajak,"
		+ "model.statusEnabled as statusEnabled "
		+") from PegawaiSKPajak model  "
		+"left join model.noSK suratkeputusan " 
		+"left join suratkeputusan.ruangan ruangan " 
		+"left join model.golonganPegawai golonganpegawai " 
		+"left join model.objekPajak objekpajak "
		+"left join model.range range")
	List<Map<String,Object>> getAll();	
	
	@Query("select model from PegawaiSKPajak model where model.golonganPegawaiId =:golonganId  ")
	PegawaiSKPajak findPersenPajakByGolongan(@Param("golonganId") Integer golonganId);
}
