/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cosmodas.FacadeCosmos;

import com.cosmodas.EntCosmos.EntregaPremios;

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

/**
 * @author obper
 */
@Stateless
public class EntregaPremiosFacade extends AbstractFacade<EntregaPremios> implements EntregaPremiosFacadeLocal {
    @PersistenceContext(unitName = "wcosmodasPersistent")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public EntregaPremiosFacade() {
        super(EntregaPremios.class);
    }

    @Override
    public String vereificaPremio(String consultorCodigo, String programaCodigo) {

        String rs;
        Query q = em.createNamedQuery("EntregaPremios.findByCodigoConsultorYPrograma");
        q.setParameter("codigoConsultor", consultorCodigo);
        q.setParameter("progama", programaCodigo);
        try {
            rs = ((EntregaPremios) q.getResultList().get(0)).getEntregaPremiosPK().getAutorizado();
        } catch (Exception e) {
            rs = "000000";
        }
        return rs;
    }


}
