/*
 * 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.TremiE;

import java.math.BigInteger;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 * @author obper
 */
@Stateless
public class TremiEFacade extends AbstractFacade<TremiE> implements TremiEFacadeLocal {

    @PersistenceContext(unitName = "wcosmodasPersistent")
    private EntityManager em;

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

    public TremiEFacade() {
        super(TremiE.class);
    }

    @Override
    public TremiE FindTremiE(String productoCodigo, String programaCodigo, String sucursal) {

        TremiE rs = new TremiE();
        Query q = em.createNamedQuery("TremiE.findByProductoMultiple");
        q.setParameter("productoCodigo", productoCodigo);
        q.setParameter("programaCodigo", programaCodigo);
        q.setParameter("sucursalEntranteCodigo", sucursal);

        if (!q.getResultList().isEmpty()) {
            rs = (TremiE) q.getResultList().get(0);

        } else {

            rs.setCantidad(new BigInteger("0"));
        }
        return rs;
    }


}
