package com.jasamedika.medifirst2000.dao;

import java.util.List;

import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
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.DetailSpekAnggaran;

/**
 * Repository class for Departemen
 * 
 * @author Adik
 */
@Repository("DetailSpekAnggaranDao")
public interface DetailSpekAnggaranDao extends PagingAndSortingRepository<DetailSpekAnggaran, Integer>,JpaSpecificationExecutor<DetailSpekAnggaran> {
	
	@Query("select count(model.noRec) from DetailSpekAnggaran model where model.detailAnggaran.noRec=:detailAnggaranId")
	public int countSpek(@Param("detailAnggaranId") String detailAnggaranId);

	@Query("select count(model.noRec) from DetailSpekAnggaran model where model.detailAnggaran.noRec=:detailAnggaranId and model.isVerifikasi = 'VERIFIKASI_PENGENDALI'")
	public Integer countVerifikasi(@Param("detailAnggaranId") String detailAnggaranId);

	@Query("select count(model.noRec) from DetailSpekAnggaran model where model.detailAnggaran.noRec=:detailAnggaranId and model.isVerifikasi = 'UNVERIFIKASI_PENGENDALI'")
	public Integer countUnverifikasi(@Param("detailAnggaranId") String detailAnggaranId);

	@Query("select model from DetailSpekAnggaran model where model.noRec=:noRec ")
	public DetailSpekAnggaran findById(@Param("noRec") String noRec);

	@Query("select model from DetailSpekAnggaran model where model.noRec=:noRec and model.isActive=true  and model.detailSpekAnggaran is not null ")
	public List<DetailSpekAnggaran> findByNoRec(@Param("noRec") String noRec);
	
	@Query("select model from DetailSpekAnggaran model where model.detailSpekAnggaran.noRec=:noRec and model.isActive=true  and model.detailSpekAnggaran is not null")
	public List<DetailSpekAnggaran> findBySpek(@Param("noRec") String noRec);

	@Query("select model from DetailSpekAnggaran model where model.detailAnggaran.noRec=:noRec and model.isActive=true  and model.detailSpekAnggaran is not null ")
	public List<DetailSpekAnggaran> findByDetail(@Param("noRec") String noRec);

	@Query("select model from DetailSpekAnggaran model where model.detailAnggaran.kegiatanAnggaran.noRec=:noRec and model.isActive=true  and model.detailSpekAnggaran is not null ")
	public List<DetailSpekAnggaran> findByKegiatan(@Param("noRec") String noRec);
	
	@Query("select model from DetailSpekAnggaran model where model.produkId=:produkId and model.periodeAwal=date(:periodeAwal) and model.periodeAhir=date(:periodeAhir)")
	public List<DetailSpekAnggaran> findByProdukIdAndPeriode(@Param("produkId") String produkId, @Param("periodeAwal") String periodeAwal, @Param("periodeAhir") String periodeAhir);
	
}
