Olá pessoal, boa tarde ! Alguém consegue me auxiliar ? Eu estou com uma demanda, onde existirá um dashboard com dois botões de ação, 1 para confirmar os pedidos pendentes ali, e outro para faturar eles. Eu estou com dificuldades para conseguir faturar o pedido via botão por conta que dar um erro de já existe transação em andamento, eu já alguns topicos aqui na comunidade, mas não consegui entender muito bem. Aqui estar o código onde tento faturar o pedido, alguém consegue identificar o que estar causando esse erro ?
`public void doAction(ContextoAcao ctx) throws Exception {
// TODO Auto-generated method stub
BigDecimal numnota = BigDecimal.valueOf(((Integer) ctx.getParam("AD_NUMNOTA")).intValue());
String serie = "1";
if(numnota !=null) {
faturarNotaFiscal(numnota, BigDecimal.valueOf(3206),serie);
}
}
public void faturarNotaFiscal(BigDecimal nunota, BigDecimal codTipOperacao, String serie) throws Exception {
ServiceContext ctx = new ServiceContext(null);
ctx.setAutentication(AuthenticationInfo.getCurrent());
ctx.makeCurrent();
SPBeanUtils.setupContext(ctx);
JapeSession.SessionHandle hnd = null ;
try {
hnd =JapeSession.open() ;
hnd.setCanTimeout(false);
hnd.setPriorityLevel(JapeSession.LOW_PRIORITY);
CentralFaturamento.ConfiguracaoFaturamento cfg = getConfiguracaoFaturamento(codTipOperacao, serie);
Collection<BigDecimal> notasSelecao = new ArrayList<BigDecimal>();
notasSelecao.add(nunota);
Map<BigDecimal, BigDecimal> notaMoedaMap = new HashMap<>();
FaturamentoHelper.faturar(ctx,hnd, cfg, notasSelecao,notaMoedaMap);
} catch (Exception e) {
e.printStackTrace();
throw new Exception("Erro ao faturar pedido: " + e);
} finally {
JapeSession.close(hnd);
}
}
public static CentralFaturamento.ConfiguracaoFaturamento getConfiguracaoFaturamento(BigDecimal codTipOperacao, String serie) {
CentralFaturamento.ConfiguracaoFaturamento cfg = new CentralFaturamento.ConfiguracaoFaturamento();
cfg.setCodTipOper(codTipOperacao);
cfg.setSerie(serie);
cfg.setDtFaturamento(TimeUtils.getNow());
cfg.setDtEntSai(TimeUtils.getNow());
cfg.setValidarData(true);
cfg.setFaturamentoNormal(true);
cfg.setUmaNota(false);
cfg.setEhWizardFaturamento(true);
cfg.setNfeDevolucaoViaRecusa(false);
// cfg.setFatDanfeSeguranca(false);
cfg.setConfirmarNota(false);
return cfg;
}
}` Alguém consegue me auxiliar ? aqui estar o erro