private List<Dados61> getDados61() { List<Dados61> ld61 = new ArrayList<>(); // agrupando as notas por dia+serie+subserie Map<String, List<EcfNota>> grupo = new HashMap<>(); for (EcfNota nota : notas) { String chave = Util.formataData(nota.getEcfNotaData(), "ddMMyyyy") + nota.getEcfNotaSerie() + nota.getEcfNotaSubserie(); List<EcfNota> lista = grupo.get(chave); if (lista == null) { lista = new ArrayList<>(); lista.add(nota); grupo.put(chave, lista); } else { lista.add(nota); } } // soma os valores agrupados for (Entry<String, List<EcfNota>> entry : grupo.entrySet()) { Dados61 d61 = new Dados61(); for (EcfNota nota : entry.getValue()) { d61.setData(nota.getEcfNotaData()); d61.setModelo(2); d61.setSerie(nota.getEcfNotaSerie()); d61.setSubserie(nota.getEcfNotaSubserie()); if (nota.getEcfNotaNumero() < d61.getNumInicial()) { d61.setNumInicial(nota.getEcfNotaNumero()); } if (nota.getEcfNotaNumero() > d61.getNumFinal()) { d61.setNumFinal(nota.getEcfNotaNumero()); } if (!nota.isEcfNotaCancelada()) { d61.setValorTotal(d61.getValorTotal() + nota.getEcfNotaLiquido()); double base_icms = 0.00; double valor_icms = 0.00; double isento = 0.00; double aliq = 0.00; for (EcfNotaProduto np : nota.getEcfNotaProdutos()) { if (np.getProdProduto().getProdProdutoTributacao() == 'T') { base_icms += np.getEcfNotaProdutoLiquido(); valor_icms += (np.getEcfNotaProdutoLiquido() * np.getProdProduto().getProdProdutoIcms() / 100); aliq = np.getProdProduto().getProdProdutoIcms(); } else if (np.getProdProduto().getProdProdutoTributacao() == 'I' || np.getProdProduto().getProdProdutoTributacao() == 'N') { isento += np.getEcfNotaProdutoLiquido(); } } d61.setBase_icms(base_icms); d61.setValor_icms(valor_icms); d61.setValor_isento(isento); d61.setOutras(0.00); d61.setAliq_icms(aliq); } } Util.normaliza(d61); ld61.add(d61); } return ld61; }