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

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 TajusteEFacade extends AbstractFacade<TajusteE> implements TajusteEFacadeLocal {

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

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

    public TajusteEFacade() {
        super(TajusteE.class);
    }

    @Override
    public TajusteE FindTajusEn(String productoCodigo, String programaCodigo, String sucursalCodigo) {
        Query q = em.createNamedQuery("TajusteE.findByMultiple");
        q.setParameter("productoCodigo", productoCodigo);
        q.setParameter("programaCodigo", productoCodigo);
        q.setParameter("sucursalCodigo", sucursalCodigo);

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

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


}
