package com.rjconsultores.ventaboletos.dao.hibernate;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

import com.rjconsultores.ventaboletos.dao.AliquotaEstadoDestinoDAO;
import com.rjconsultores.ventaboletos.entidad.AliquotaEstadoDestino;
import com.rjconsultores.ventaboletos.entidad.EmpresaImposto;

@Repository("aliquotaEstadoDestinoDAO")
public class AliquotaEstadoDestinoHibernateDAO extends GenericHibernateDAO<AliquotaEstadoDestino, Integer> 
implements AliquotaEstadoDestinoDAO{

	@Autowired
	public AliquotaEstadoDestinoHibernateDAO(@Qualifier("sessionFactory") SessionFactory factory) {
		setSessionFactory(factory);
	}
	
	public List<AliquotaEstadoDestino> getChildrens(EmpresaImposto parent){
		
		StringBuilder sb = new StringBuilder();

		sb.append(" select als from AliquotaEstadoDestino als 			");
		sb.append(" where als.activo = 1  	");
		sb.append(" 	and als.empresaImposto.empresaImpostoId =:empresaImpostoId  ");
		sb.append(" 	order by als.aliquotaEstadoDestinoId  ");
		
		Query query = getSession().createQuery(sb.toString());
		query.setParameter("empresaImpostoId", parent.getEmpresaImpostoId());

		List<AliquotaEstadoDestino> lsAliquotaEstadoDestino = query.list();

		return lsAliquotaEstadoDestino;
	}

}
