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

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 TnabonoFacade extends AbstractFacade<Tnabono> implements TnabonoFacadeLocal {

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

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

    public TnabonoFacade() {
        super(Tnabono.class);
    }

    @Override
    public Tnabono FindMultiple(String productoCodigo, String programaCodigo, String sucursal) {
        Query q = em.createNamedQuery("Tnabono.findMultiple");
        q.setParameter("productoCodigo", productoCodigo);
        q.setParameter("programaCodigo", programaCodigo);
        q.setParameter("sucursalCodigo", sucursal);

        Tnabono rs = new Tnabono();

        if (!q.getResultList().isEmpty()) {
            rs = (Tnabono) q.getResultList().get(0);
        } else {

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

        return rs;
    }


}
