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

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

/**
 * @author obper
 */
@Stateless
public class CreditoFiscalFacade extends AbstractFacade<CreditoFiscal> implements CreditoFiscalFacadeLocal {

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

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

    public CreditoFiscalFacade() {
        super(CreditoFiscal.class);
    }

    @Override
    public void actualizaValorCredito(String facturaCodigo, String facturaSerie, String valorActua) {

        em.createNativeQuery("{CALL actualiza_topagar(?,?,?)}")
                .setParameter(1, facturaCodigo)
                .setParameter(2, facturaSerie)
                .setParameter(3, valorActua).executeUpdate();
    }

    @Override
    public void insertaCreditoFiscal(CreditoFiscal cred) {
     /*   em.createNativeQuery("{call ingresa_credito_fiscal(?,?,?,?)}")
                .setParameter(1, cred.getCreditoFiscalPK().getFacturaCodigo())
                .setParameter(2, cred.getConsultorCodigo())
                .setParameter(3, cred.getPercepcion())
                .setParameter(4, cred.getCreditoFiscalPK().getSerie()).executeUpdate();*/

        em.persist(cred);
    }

}
