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

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 TremiSFacade extends AbstractFacade<TremiS> implements TremiSFacadeLocal {

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

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

    public TremiSFacade() {
        super(TremiS.class);
    }

    @Override
    public TremiS FindRemiS(String productoCodigo, String sucursalCodigo, String programaCodigo) {
        Query q = em.createNamedQuery("TremiS.findMultiple");
        q.setParameter("productoCodigo", productoCodigo);
        q.setParameter("sucursalEntranteCodigo", sucursalCodigo);
        q.setParameter("programaCodigo", programaCodigo);

        TremiS rs = new TremiS();

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

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

        return rs;
    }


}
