Boa tarde pessoal,
Estou com um problema em minha aplicação. Já procurei aqui no fórum algum tópico que pudesse me auxiliar porém não encontrei um que eu conseguisse solucionar o meu problema.
Estou desenvolvendo uma aplicação PDV e dentre de suas diversas funções, uma delas é a tela de venda. Após inserir os produtos, o operador seleciona para ir a tela de Pagamento, porém ao executar a tela de pagamento ocorre o seguinte erro:
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at br.com.intercommerce.controller.PDVExec.executar(PDVExec.java:419)
at br.com.intercommerce.controller.PDVController.processarAcao(PDVController.java:83)
at br.com.intercommerce.controller.PDVExec$5.actionPerformed(PDVExec.java:490)
at javax.swing.SwingUtilities.notifyAction(Unknown Source)
at javax.swing.JComponent.processKeyBinding(Unknown Source)
at javax.swing.KeyboardManager.fireBinding(Unknown Source)
at javax.swing.KeyboardManager.fireKeyboardAction(Unknown Source)
at javax.swing.JComponent.processKeyBindingsForAllComponents(Unknown Source)
at javax.swing.JComponent.processKeyBindings(Unknown Source)
at javax.swing.JComponent.processKeyEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.KeyboardFocusManager.redispatchEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.lang.ArrayIndexOutOfBoundsException: 0 >= 0
at java.util.Vector.elementAt(Unknown Source)
at javax.swing.table.DefaultTableModel.setValueAt(Unknown Source)
at br.com.intercommerce.bc.CupomBC.atualizarTelaPagamento(CupomBC.java:95)
… 35 more
Será que alguém saberia me auxiliar?
o código que está com erro é o seguinte.
public class CupomBC {
public static void atualizarTelaPagamento() throws Exception {
PDVController pdv = PDVController.getInstance();
JTextField tftotalAcrescimo = (JTextField)pdv.getSessao().get("tftotalAcrescimo");
JTextField tftotalDesconto = (JTextField)pdv.getSessao().get("tftotalDesconto");
JTextField tftotalVenda = (JTextField)pdv.getSessao().get("tftotalVenda");
JTextField tftotalAcumulado = (JTextField)pdv.getSessao().get("tftotalAcumulado");
JTextField tftotalSaldo = (JTextField)pdv.getSessao().get("tftotalSaldo");
JTable tbDetalhes = (JTable)pdv.getSessao().get("tbDetalhes");
BigDecimal acrescimo = BigDecimal.ZERO;
BigDecimal desconto = BigDecimal.ZERO;
BigDecimal total = BigDecimal.ZERO;
DefaultTableModel dtm = new DefaultTableModel();
dtm.setColumnIdentifiers(new String[] {"", "", ""});
ArrayList<CondPagtoVo> condicoesEscolhidas = (ArrayList<CondPagtoVo>)pdv.getSessao().get("condicoesEscolhidas");
TreeMap tree = new TreeMap();
if (condicoesEscolhidas != null) {
for (int a = 0; a < condicoesEscolhidas.size(); a++) {
CondPagtoVo cond = condicoesEscolhidas.get(a);
acrescimo = acrescimo.add(cond.getVlJuros());
desconto = desconto.add(cond.getVlDesconto());
total = total.add(cond.getVlTotal());
HashMap hashTmp = cond.getParcelas();
Iterator it = hashTmp.keySet().iterator();
while (it.hasNext()) {
Object chave = it.next();
if (tree.get(chave) == null) {
tree.put(chave, hashTmp.get(chave));
} else {
BigDecimal bd = (BigDecimal)tree.get(chave);
bd = bd.add((BigDecimal)hashTmp.get(chave));
tree.put(chave, bd);
}
}
}
}
boolean primeira = true;
if (tree.get("ENTRADA") != null) {
BigDecimal bd = (BigDecimal)tree.get("ENTRADA");
dtm.addRow(new String[] {"ENTRADA", Transformador.Double2S(bd.doubleValue()), ""});
primeira = false;
}
Iterator it = tree.keySet().iterator();
while (it.hasNext()) {
Object chave = it.next();
String data = chave.toString();
if (!data.equals("ENTRADA")) {
data = data.substring(6, 8) + "/" + data.substring(3, 5) + "/" + data.substring(0, 2);
BigDecimal bd = (BigDecimal)tree.get(chave);
primeira = false;
dtm.addRow(new String[] {data, Transformador.Double2S(bd.doubleValue()), ""});
}
}
pdv.getSessao().put("item_a_ser_pago", 0);
dtm.setValueAt("<<<", 0, 2);
tbDetalhes.setModel(dtm);
tftotalAcrescimo.setText(Transformador.Double2S(acrescimo.doubleValue()));
tftotalDesconto.setText(Transformador.Double2S(desconto.doubleValue()));
tftotalVenda.setText(Transformador.Double2S(total.doubleValue()));
tftotalAcumulado.setText(Transformador.Double2S(total.doubleValue()));
tftotalSaldo.setText(Transformador.Double2S(total.doubleValue()));
VendaVo venda = (VendaVo)pdv.getSessao().get("venda");
venda.setVlTotalAcumulado(total.doubleValue());
venda.setVlAcrescimoTotal(acrescimo.doubleValue());
venda.setVlDescontoTotal(desconto.doubleValue());
}
public static void cancelarCupomAtual() throws Exception {
PDVController pdv = PDVController.getInstance();
ParametroVo parametros = (ParametroVo)pdv.getSessao().get("parametros");
Ecf ecf = EcfFactory.getInstance(parametros.getFabricanteEcf());
ecf.cancelaCupomAtual();
CupomLocalVo cupom = (CupomLocalVo)pdv.getSessao().get("cupom");
cupom.setStatus("9");
HibernatePersistenceManager.saveOrUpdateLocal(cupom);
PosicaoLocalBC.atualizar("LIVRE");
//PosicaoOperadorBC.atualizaOperador(vendaVo);
System.out.println("cancelarCupomAtual");
}
public static void cancelarCupomAnterior() throws Exception {
PDVController pdv = PDVController.getInstance();
ParametroVo parametros = (ParametroVo)pdv.getSessao().get("parametros");
Ecf ecf = EcfFactory.getInstance(parametros.getFabricanteEcf());
int ret = ecf.cancelaCupomAnterior();
//TODO Verificar para achar cumpom anterior, pois se nao tem, esta null e ocorre erro
CupomLocalVo cupom = (CupomLocalVo)pdv.getSessao().get("cupom");
//TODO if temporario para nao ocorrer erro
if (cupom != null) {
cupom.setStatus("1");
HibernatePersistenceManager.saveOrUpdateLocal(cupom);
}
System.out.println("cancelarCupomAnterior");
}
public static boolean verificaCupomCancelar() throws Exception {
boolean ret = false;
PDVController pdv = PDVController.getInstance();
VendaVo venda = (VendaVo)pdv.getSessao().get("venda");
if (venda.getVlSubTotal() == 0 && venda.getQtdeItensCupom()!= 0){
CupomBC.cancelarCupomAtual();
ret = true;
}
return ret;
}
public static boolean verificaEncerramentoCupom() throws Exception {
boolean ret = false;
PDVController pdv = PDVController.getInstance();
// sincronização de tela
JFrame frame = (JFrame)pdv.getSessao().get("frame");
frame.update(frame.getGraphics());
VendaVo venda = (VendaVo)pdv.getSessao().get("venda");
if (venda.getVlTotalRecebido() >= venda.getVlTotalAcumulado()){
ret = true;
}
return ret;
}
public static boolean verificaCupomInicializado(String origem) throws Exception {
PDVController pdv = PDVController.getInstance();
VendaVo venda = (VendaVo)pdv.getSessao().get("venda");
System.out.println("getQtdeItensCupom->" + venda.getQtdeItensCupom());
System.out.println("getVlSubTotal(->" + venda.getVlSubTotal());
if (origem.equals("V")){
if (venda.getQtdeItensCupom() >= 1) {
return false;
} else {
return true;
}
}else{
if (venda.getVlSubTotal() == 0.00) {
return false;
} else {
return true;
}
}
}
public static void gravaCupomInicio() throws Exception {
PDVController pdv = PDVController.getInstance();
ParametroVo param = (ParametroVo)pdv.getSessao().get("parametros");
PosicaoLocalVo posicao = (PosicaoLocalVo)pdv.getSessao().get("posicao");
ControlePdvVo ctrl = ControlePdvVo.getInstance();
VendaVo venda = (VendaVo)pdv.getSessao().get("venda");
ClienteVo cliente = (ClienteVo)pdv.getSessao().get("cliente");
Date dataHoje = new Date();
CupomLocalVo cupom = new CupomLocalVo();
cupom.setIdUnn(param.getIdUnn());
cupom.setIdEmp(param.getIdEmp());
cupom.setNrPdv(posicao.getNrPdv());
cupom.setNrCupom(ctrl.getNrCupom());
cupom.setDtCupom(ctrl.getDataMovto());
cupom.setIdOpe(posicao.getIdOperador());
cupom.setIdFiscal(posicao.getIdFiscal());
cupom.setIdEntrada(posicao.getIdEntrada());
cupom.setIdPvd(venda.getIdPvd());
cupom.setIdVen(venda.getIdVendedor());
cupom.setIdPromotor(venda.getIdPromotor());
cupom.setCdTipoCupom(venda.getCdTipoCupom());
cupom.setCdMidia(venda.getCdMidia());
cupom.setIdCep(venda.getIdCep());
cupom.setIdCli(cliente.getIdCliente());
cupom.setCdModalEnt(venda.getCdModalEnt());
cupom.setVlCupom(0.00);
cupom.setNrCartao(venda.getNrCartaoFidelidade());
cupom.setNrCupInicAcum(venda.getNrCupIniAcum());
cupom.setDtInicio(dataHoje);
pdv.getSessao().put("cupom", cupom);
HibernatePersistenceManager.saveOrUpdateLocal(cupom);
}
public static void gravaCupomFim() throws Exception {
PDVController pdv = PDVController.getInstance();
VendaVo venda = (VendaVo)pdv.getSessao().get("venda");
PagamentoVo pagamento = (PagamentoVo)pdv.getSessao().get("pagamento");
Date dataHoje = new Date();
CupomLocalVo cupom = (CupomLocalVo)pdv.getSessao().get("cupom");
cupom.setDtFim(dataHoje);
cupom.setIdCpg(venda.getIdCpg());
cupom.setQtItens(venda.getQtdeItensCupom());
cupom.setQtItensCanc(venda.getQtdeItensCancelados());
cupom.setVlItensCanc(venda.getVlCancelamentoItem());
cupom.setVlCupom(venda.getVlSubTotal());
cupom.setVlTroco(pagamento.getVlTroco());
cupom.setVlDinheiro(pagamento.getVlDinheiro());
cupom.setVlCheque(pagamento.getVlCheque());
cupom.setVlChequePre(pagamento.getVlChequePre());
cupom.setVlCupomVale(pagamento.getVlCupom());
cupom.setVlCrtCredito(pagamento.getVlCrtCredito());
cupom.setVlCrtDebito(pagamento.getVlCrtDebito());
cupom.setVlCrtProprio(pagamento.getVlCrtProprio());
cupom.setVlCrtManual(pagamento.getVlCrtManual());
cupom.setVlCrediario(pagamento.getVlCrediario());
cupom.setVlPlano(pagamento.getVlPlanos());
cupom.setVlLivre1(pagamento.getVlLivre1());
cupom.setVlLivre2(pagamento.getVlLivre2());
cupom.setVlLivre3(pagamento.getVlLivre3());
cupom.setVlLivre4(pagamento.getVlLivre4());
cupom.setVlLivre5(pagamento.getVlLivre5());
cupom.setVlLivre6(pagamento.getVlLivre6());
cupom.setVlLivre7(pagamento.getVlLivre7());
cupom.setVlLivre8(pagamento.getVlLivre8());
cupom.setVlLivre9(pagamento.getVlLivre9());
cupom.setVlLivre10(pagamento.getVlLivre10());
cupom.setVlAcrescimo(venda.getVlAcrescimoTotal());
cupom.setVlDesconto(venda.getVlDescontoTotal());
cupom.setVlDescFid(venda.getVlDescontoFidelidade());
cupom.setVlDescSup(venda.getVlDescontoSupervisor());
cupom.setCdPlanosPg(venda.getCdPlanos());
//cupom.setIdDev(0);
cupom.setStatus("0");
HibernatePersistenceManager.saveOrUpdateLocal(cupom);
}
public static boolean verificarCupomCancelar(String param, String permissao) {
if (permissao.equals("S")) {
PDVController pdv = PDVController.getInstance();
VendaVo venda = (VendaVo)pdv.getSessao().get("venda");
if (param.equals("N")) {
if (venda.getQtdeItensCupom() >= 1) {
return true;
} else {
return false;
}
}
if (param.equals("A")) {
return true;
}
}
return false;
}
}
Obrigada