package com.jasamedika.medifirst2000.dao.custom.impl;

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

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.springframework.stereotype.Repository;

import com.jasamedika.medifirst2000.dao.custom.PelatihanBiayaDiklatDaoCustom;

/**
 * Repository Custom class
 * 
 * @author Roberto
 */

@Repository("PelatihanBiayaDiklatDaoCustom")
public class PelatihanBiayaDiklatDaoCustomImpl  implements PelatihanBiayaDiklatDaoCustom {

	@PersistenceContext
	protected EntityManager em;

	@Override
	public List<Map<String, Object>> listBiayaDiklat(int rowStart, int rowEnd, String sort, String dir) {

		StringBuffer buffer = new StringBuffer();
		buffer.append(" select new map( p.id as id,komponen.namaProduk as komponen,kelas.namaKelas as kelas,asalProduk.asalProduk as asal,jenisTarif.jenisTarif as jenisTarif ,p.tglBerlakuAwal as tanggalAwal,p.tglBerlakuAkhir as tanggalAhir,");
		buffer.append(" p.hargaSatuan as hargaSatuan,p.persenDiscount as persenDiskon) from HargaNettoProdukByKelas p ");
		buffer.append(" left join p.produk komponen ");
		buffer.append(" left join p.kelas kelas ");
		buffer.append(" left join p.asalProduk asalProduk ");
		buffer.append(" left join p.jenisTarif jenisTarif left join komponen.detailJenisProduk djp  where djp.id=1335 order by p.id desc  ");

		
		Query query = em.createQuery(buffer.toString());


		List<Map<String, Object>> list = query.getResultList();

		return list;

	}

	@Override
	public List<Map<String, Object>> daftarKomponen() {
		StringBuffer buffer = new StringBuffer();
		buffer.append(" select new map(p.id as id,p.namaProduk as namaProduk) from Produk p left join p.detailJenisProduk djp where djp.id=1335 ");

		Query query = em.createQuery(buffer.toString());

		List<Map<String, Object>> list = query.getResultList();

		return list;

	}


	
}
