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

@Repository("SaranaPrasaranaReportingDao")
public interface SaranaPrasaranaReportingDao extends PagingAndSortingRepository<Pasien, Integer>{

		@Query("select new map(strukPlaning.noRec as noRec, " + " strukPlaning.tglplanning as tglplanning, "
				+ " strukPlaning.keteranganlainnya as keteranganlainnya, "
				+ " planningPelayanan.tglPlanningAkhir as tglPlanningAkhir, "
				+ " planningPelayanan.qtyProdukExec as beratLinen, " + " alat.id as idMesin, alat.namaAlat as namaAlat, "
				+ " alat.kapasitasAlat as kapasitasAlat, " + " alat.satuanStandar.satuanStandar as satuanStandar, "
				+ " strukPelayanan.noRec as noRecstrukPelayanan) " + " from PlanningPelayanan planningPelayanan "
				+ " left join planningPelayanan.strukPlaning strukPlaning "
				+ " left join planningPelayanan.strukPelayanan strukPelayanan "
				+ " left join planningPelayanan.produk produk, " + " Alat alat left join alat.produkAset produkAlat "
				+ " where strukPlaning.keteranganlainnya in('Proses Pengeringan Internal') "
				+ " and produk.id=produkAlat.id and date(strukPlaning.tglplanning) between date(:startDate) and date(:endDate)")
		List<Map<String, Object>> getProsesPengeringanInternal(@Param("startDate") String startDate,
				@Param("endDate") String endDate);

		@Query("select new map(strukPelayanan.noRec as noRec, " + " strukPelayanan.keteranganlainnya as ket, "
				+ " strukPelayanan.nostruk as nostruk, " + " strukPelayanan.qtyproduk as qtyproduk, "
				+ " strukPelayanan.tglstruk as tglstruk, " + " strukPelayanan.tglterimakiriman as tglterimakiriman, "
				+ " menyerahkan.id as idMenyerahkan, " + " menyerahkan.namaExternal as namaMenyerahkan, "
				+ " pegawaiPenerima.id as idPenerima, pegawaiPenerima.namaExternal as namaPenerima) "
				+ " from StrukPelayanan strukPelayanan " + " left join strukPelayanan.kdruanganasal ruangAsal "
				+ " left join strukPelayanan.kdruangan ruangan " + " left join strukPelayanan.menyerahkan menyerahkan "
				+ " left join strukPelayanan.kdpegawaipenerima pegawaiPenerima "
				+ " where strukPelayanan.keteranganlainnya in('Order Laundry Internal') "
				+ " and strukPelayanan.noTerima is null  and date(strukPelayanan.tglstruk) between date(:startDate) and date(:endDate)")
		List<Map<String, Object>> reportOrderLaundrySebelumDiTerima(@Param("startDate") String startDate,
				@Param("endDate") String endDate);
		
		@Query("select NEW Map ("
				+ "a.noRec as noRec, "
				+ "a.noOrder as noOrder, "
				+ "d.kdProduk as kdProduk, "
				+ "d.namaProduk as namaProduk, "
				+ "a.tglPesan as tglPesan, "
				+ "e.merkProduk as merkProduk, "
				+ "f.typeProduk as typeProduk, "
				+ "c.noSeri as noSeri, "
				+ "a.keluhan as keluhan, "
				+ "b.namaLengkap as pelapor, "
				+ "h.namaRuangan as namaRuangan, "
				+ "g.statusPengerjaan as statusPengerjaan, "
				+ "g.statusRespon as statusRespon, "
				+ "g.ketStatusRespon as ketStatusRespon) "
				+ "from IpsrsPerbaikan a "
				+ "left join a.pelapor b "
				+ "left join a.registrasiAset c "
				+ "left join c.produk d "
				+ "left join c.merkProduk e "
				+ "left join c.typeProduk f "
				+ "left join a.ipsrsStatusPerbaikan g "
				+ "left join c.ruangan h "
				+ "where g.statusRespon=0 and date(a.tglPesan) between date(:startPeriode) and date(:endPeriode) "
				+ "order by a.tglPesan desc")
		List<Map<String, Object>> getReportAllPermintaanPerbaikan(@Param("startPeriode") String startPeriode,
				@Param("endPeriode") String endPeriode);
}
