package com.jasamedika.medifirst2000.dao;

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

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.OrderPelayanan;
import com.jasamedika.medifirst2000.entities.StrukKirim;

@Repository("StrukKirimDao")
public interface StrukKirimDao extends PagingAndSortingRepository<StrukKirim, String> , JpaSpecificationExecutor<StrukKirim>{

	@Query("select new Map(	kirimProdukAset.noRec as noRecKirimProduk,registrasiAset.noRec as noRecRegistrasiAset,registrasiAset.noRegisterAset as noRegisterAset,produk.namaProduk as namaProduk,asalProduk.asalProduk as asalProduk,kirimProdukAset.qtyProduk as qtyProduk ) from KirimProdukAset kirimProdukAset "
			+ "left join kirimProdukAset.noKirim strukKirim "
			+ "left join kirimProdukAset.noRegisterAset registrasiAset "
			+ "left join registrasiAset.produk produk "
			+ "left join registrasiAset.strukPelayananDetail strukPelayananDetail "
			+ "left join strukPelayananDetail.kdasalproduk asalProduk where strukKirim.noRec=:noRec")
	List<Map<String,Object>> findDetail(@Param("noRec") String noRec);

	@Query("select new map(strukKirim.noRec as noRec,strukKirim.nokirim as noKirim,strukOrder.tglOrder as tglOrder,strukOrder.noOrder as noOrder,ruanganAsal.namaRuangan as namaRuangan,ruanganTujuan.namaRuangan as ruanganTujuan ) from StrukKirim strukKirim left join strukKirim.noorder strukOrder "
			+ "left join strukOrder.ruangan ruanganAsal "
			+ "left join strukOrder.ruanganTujuan ruanganTujuan where strukKirim.noRec=:noRec ")
	Map<String,Object> findHeader(@Param("noRec") String noRec);
	
	
	@Query("select model from StrukKirim model where model.noRec = :noRec ")
	StrukKirim findByNoRec(@Param("noRec") String noRec);

	@Query("select model from OrderPelayanan model where model.strukOrderId = :noRec ")
	List<OrderPelayanan> findOrderPelayananByParent(@Param("noRec") String noRec);


}
