bug #7500
git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Model/trunk/modelWeb@56967 d1611594-4594-4d17-8e1d-87c2c4800839master
parent
7a3c12ba1b
commit
7e85195a91
|
@ -368,8 +368,7 @@ public class FiscalHibernateDAO implements FiscalDAO {
|
|||
sql.append("'" + SituacaoTributaria.NAO_FISCAL.getValue() + "'").append(")");
|
||||
sql.append(" AND anterior.numserie20 = r2.numserie20 ");
|
||||
sql.append(" AND anterior.crz = r2.crz - 1 ");
|
||||
sql.append(" AND (SELECT MAX(fiscalr4_id) FROM fiscal_r4 r4 WHERE r4.numserie20 = r2.numserie20 ");
|
||||
sql.append(" AND r4.datamov = r2.datamov) IS NOT NULL ");
|
||||
sql.append(" AND r2.vendabrutadiaria > 0 ");
|
||||
sql.append("GROUP BY r2.datamov, ");
|
||||
sql.append(" r2.numreducoes, ");
|
||||
sql.append(" r2.crz, ");
|
||||
|
@ -390,7 +389,9 @@ public class FiscalHibernateDAO implements FiscalDAO {
|
|||
sql.append(" numserie20, ");
|
||||
sql.append(" crz, ");
|
||||
sql.append(" r2.numreducoes, ");
|
||||
sql.append(" r3.totparcial desc ");
|
||||
// TODO: No ambiente de produção a ordenação so vem correta quando declarado para vir como desc
|
||||
// contrario aos outros servidores que deve ser asc
|
||||
sql.append(" r3.totparcial asc ");
|
||||
return sql.toString();
|
||||
}
|
||||
|
||||
|
@ -562,11 +563,12 @@ public class FiscalHibernateDAO implements FiscalDAO {
|
|||
sql.append(" cs.descclase as claseServicio, ");
|
||||
sql.append(" translate(fi.numcnpj, ' / - . ', ' ') as cnpjEcf, ");
|
||||
sql.append(" ei.icms as impostoEstado, ");
|
||||
sql.append(" 'N' as status ");
|
||||
sql.append(" FROM fiscal_r4 r4 ");
|
||||
sql.append(" INNER JOIN fiscal_r5 r5 ON r4.numserie20 = r5.numserie20 AND r4.coo = r5.coo ");
|
||||
sql.append(" 'N' as status, ");
|
||||
sql.append(" r4.indcancelamento as indcancelamento ");
|
||||
sql.append(" FROM fiscal_r4 r4 ");
|
||||
sql.append(" LEFT JOIN fiscal_r5 r5 ON r4.numserie20 = r5.numserie20 AND r4.coo = r5.coo ");
|
||||
sql.append(" AND r4.datamov = r5.datamov AND r4.contador = r5.contador ");
|
||||
sql.append(" INNER JOIN fiscal_impressora fi ON fi.numserie20 = r4.numserie20 ");
|
||||
sql.append(" LEFT JOIN fiscal_impressora fi ON fi.numserie20 = r4.numserie20 ");
|
||||
sql.append(" INNER JOIN boleto b ON b.boleto_id = r4.boleto_id ");
|
||||
sql.append(" INNER JOIN clase_servicio cs ON cs.claseservicio_id = b.claseservicio_id ");
|
||||
sql.append(" LEFT JOIN alias_servico ase ON ase.origen_id = b.origen_id ");
|
||||
|
@ -578,7 +580,7 @@ public class FiscalHibernateDAO implements FiscalDAO {
|
|||
sql.append(" INNER JOIN parada d ON coalesce(ase.aliasdestino_id, b.destino_id) = d.parada_id ");
|
||||
sql.append(" INNER JOIN ciudad cd ON d.ciudad_id = cd.ciudad_id ");
|
||||
sql.append(" INNER JOIN estado ed ON ed.estado_id = cd.estado_id ");
|
||||
sql.append(" WHERE r4.datamov BETWEEN ? AND ? ");
|
||||
sql.append(" WHERE r4.datamov BETWEEN ? AND ? ");
|
||||
sql.append(" AND b.marca_id = ? ");
|
||||
sql.append(" AND (r4.indcancelamento = 'N' OR (r4.indcancelamento = 'S' AND ");
|
||||
sql.append(" (SELECT r3.numserie20 FROM fiscal_r3 r3 ");
|
||||
|
@ -611,7 +613,8 @@ public class FiscalHibernateDAO implements FiscalDAO {
|
|||
sql.append(" b.importeseguro, ");
|
||||
sql.append(" cs.descclase, ");
|
||||
sql.append(" fi.numcnpj, ");
|
||||
sql.append(" ei.icms ");
|
||||
sql.append(" ei.icms, ");
|
||||
sql.append(" r4.indcancelamento ");
|
||||
sql.append(" ORDER BY r4.datainicialemissao, ");
|
||||
sql.append(" r4.numserie20, ");
|
||||
sql.append(" r4.coo, ");
|
||||
|
@ -865,6 +868,7 @@ public class FiscalHibernateDAO implements FiscalDAO {
|
|||
item.setValorMulta(columns.contains("valormulta") ? rset.getBigDecimal("valorMulta") : null);
|
||||
item.setImpostoEstado(columns.contains("impostoestado") ? rset.getBigDecimal("impostoEstado") : null);
|
||||
item.setDesconto(columns.contains("desconto") ? rset.getBigDecimal("desconto") : null);
|
||||
item.setIndcancelamento(columns.contains("indcancelamento") ? rset.getString("indcancelamento") : null);
|
||||
|
||||
// TODO: Estes atributos foram criados, por motivo de divergencia no valorTotal com o valor unitario na tabela FISCAL_R5
|
||||
item.setValorTarifa(columns.contains("importetarifa") ? rset.getBigDecimal("importetarifa") : null);
|
||||
|
|
|
@ -11,6 +11,8 @@ public interface FiscalService {
|
|||
|
||||
public int gerarRegistroP2_F2(List<EsquemaCorrida> lsEsquemaCorrida, Date dataDe, Date dataAte);
|
||||
|
||||
public List<File> importacionFiscalECFValidaReducaoZ(Date inicio, Date fim, Empresa empresa);
|
||||
|
||||
public File importacionFiscalECF(Date inicio, Date fim, Empresa empresa);
|
||||
|
||||
public File importacionFiscalReducaoZ(Date inicio, Date fim, Empresa empresa);
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -127,18 +127,16 @@ public class StringHelper {
|
|||
}
|
||||
}
|
||||
|
||||
public static String divideEFormata(String str, int divisor) {
|
||||
public static String divideEFormata(String str) {
|
||||
|
||||
DecimalFormatSymbols symbols = new DecimalFormatSymbols();
|
||||
symbols.setDecimalSeparator(',');
|
||||
DecimalFormat formatador = new DecimalFormat("0.00", symbols);
|
||||
|
||||
String valor = "0";
|
||||
|
||||
if (str != null) {
|
||||
valor = new BigDecimal(str).divide(new BigDecimal(100)).toString();
|
||||
}
|
||||
|
||||
return formatador.format(new BigDecimal(valor));
|
||||
|
||||
}
|
||||
|
|
|
@ -6,11 +6,22 @@ import java.text.NumberFormat;
|
|||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import com.rjconsultores.ventaboletos.vo.impressaofiscal.ImportacionFiscalVO;
|
||||
|
||||
public class UtileriasFiscal {
|
||||
|
||||
private static int DECIMALS = 2;
|
||||
private static int ROUNDING_MODE = BigDecimal.ROUND_HALF_EVEN;
|
||||
|
||||
public static final String DATE_FORMAT_FISCAL = "yyyyMMdd";
|
||||
public static final BigDecimal CEM = BigDecimal.valueOf(100);
|
||||
public static final String QUEBRA_LINHA = "\r\n";
|
||||
|
||||
public static BigDecimal divideEFormata(BigDecimal valor) {
|
||||
String vlrFormatado = StringHelper.divideEFormata(valor.toString());
|
||||
return new BigDecimal(vlrFormatado);
|
||||
}
|
||||
|
||||
public static String defineCodigoProduto(Integer idOrigemCorrida, Integer idDestinoCorrida, Integer idLinha) {
|
||||
int tamanhoMaximo = 12;
|
||||
|
||||
|
@ -24,15 +35,15 @@ public class UtileriasFiscal {
|
|||
|
||||
String codProduto = codOrigem + codDestino + codLinha + "-";
|
||||
|
||||
if (codProduto.length() > tamanhoMaximo){
|
||||
codProduto = codProduto.substring(1,tamanhoMaximo+1);
|
||||
if (codProduto.length() > tamanhoMaximo) {
|
||||
codProduto = codProduto.substring(1, tamanhoMaximo + 1);
|
||||
}
|
||||
|
||||
return codProduto;
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
System.out.println(formataZeroDecimal(new BigDecimal(2d), 2, 14));
|
||||
System.out.println(formataZeroDecimal(new BigDecimal("3870.00"), 2, 14));
|
||||
}
|
||||
|
||||
public static String formataNumerico(final String valor, final int tamanho) {
|
||||
|
@ -101,4 +112,173 @@ public class UtileriasFiscal {
|
|||
return valorFommat;
|
||||
}
|
||||
|
||||
public static BigDecimal valorTotalItensECF(ImportacionFiscalVO item) {
|
||||
BigDecimal valorTotal = BigDecimal.ZERO;
|
||||
|
||||
BigDecimal valorPedagio = item.getValorPedagio() == null ? BigDecimal.ZERO : item.getValorPedagio();
|
||||
BigDecimal valorEmbarque = item.getValorEmbarque() == null ? BigDecimal.ZERO : item.getValorEmbarque();
|
||||
BigDecimal valorTarifa = item.getValorTarifa() == null ? BigDecimal.ZERO : item.getValorTarifa();
|
||||
BigDecimal valorSeguro = item.getValorSeguro() == null ? BigDecimal.ZERO : item.getValorSeguro();
|
||||
if (valorTarifa.equals(BigDecimal.ZERO))
|
||||
valorTarifa = BigDecimal.ONE.divide(CEM);
|
||||
|
||||
valorTotal = valorTotal.add(valorTarifa).add(valorPedagio).add(valorEmbarque).add(valorSeguro);
|
||||
|
||||
return valorTotal;
|
||||
}
|
||||
|
||||
public static String aberturaDeArquivo(String identificador, String data, String cnpjFilial, String brancos372,
|
||||
String sequencial) {
|
||||
|
||||
StringBuilder abertura = new StringBuilder();
|
||||
abertura.append(identificador);
|
||||
abertura.append(data);
|
||||
abertura.append(cnpjFilial);
|
||||
abertura.append(brancos372);
|
||||
abertura.append(sequencial);
|
||||
|
||||
return abertura.toString();
|
||||
}
|
||||
|
||||
public static String headerDocumentoFiscal(String identificador, String data, String cnpjImpressora, String coo,
|
||||
String serie, String especie, String codigoCliente, String filialCliente, String condicaoPagamento,
|
||||
String valorTotalDocumanto, String valorItens, String aliquota, String imposto, String valorPIS,
|
||||
String valorCofins, String valorCSLL, String totalICMSIsento, String totalICMSNaotributado, String origenUf,
|
||||
String origen, String destinoUf, String destino, String subSerie, String aidf, String status,
|
||||
String motivocancelacion, String valorMulta, String brancos, String claseServicio, String sequencial) {
|
||||
|
||||
StringBuilder header = new StringBuilder();
|
||||
header.append(identificador);
|
||||
header.append(data);
|
||||
header.append(cnpjImpressora);
|
||||
header.append(coo);
|
||||
header.append(serie);
|
||||
header.append(especie);
|
||||
header.append(codigoCliente);
|
||||
header.append(filialCliente);
|
||||
header.append(condicaoPagamento);
|
||||
header.append(valorTotalDocumanto);
|
||||
header.append(valorItens);
|
||||
header.append(aliquota);
|
||||
header.append(imposto);
|
||||
header.append(valorPIS);
|
||||
header.append(valorCofins);
|
||||
header.append(valorCSLL);
|
||||
header.append(totalICMSIsento);
|
||||
header.append(totalICMSNaotributado);
|
||||
header.append(origenUf);
|
||||
header.append(origen);
|
||||
header.append(destinoUf);
|
||||
header.append(destino);
|
||||
header.append(subSerie == null ? "" : subSerie);
|
||||
header.append(aidf == null ? "" : aidf);
|
||||
header.append(status);
|
||||
header.append(motivocancelacion == null ? "" : motivocancelacion);
|
||||
header.append(valorMulta == null ? "" : valorMulta);
|
||||
header.append(brancos);
|
||||
header.replace(226, 256, claseServicio);
|
||||
|
||||
header.append(sequencial);
|
||||
|
||||
return header.toString();
|
||||
}
|
||||
|
||||
public static String itensDocumentoFiscal(String identificador, String numItem, String cfop, String codigoTES,
|
||||
String codProduto, String unidade, String quantidade, String valorUnitario, String valorTotal,
|
||||
String aliquotaItem, String impostoItem, String valorPIS, String aliquotaPIS, String aliquotaCofins,
|
||||
String valorCofins, String aliquotaCSLL, String valorCSLL, String aliquotaISS, String valorISS,
|
||||
String totalICMSIsentoItem, String totalICMSNaotributadoItem, String numeroPDV, String numeroSeriePDV,
|
||||
String modeloImpressora, String numCaixa, String status, String coo, String serie,
|
||||
String brancos, String sequencial) {
|
||||
|
||||
StringBuilder item = new StringBuilder();
|
||||
item.append(identificador);
|
||||
item.append(numItem);
|
||||
item.append(cfop);
|
||||
item.append(codigoTES);
|
||||
item.append(codProduto);
|
||||
item.append(unidade);
|
||||
item.append(quantidade);
|
||||
item.append(valorUnitario);
|
||||
item.append(valorTotal);
|
||||
item.append(aliquotaItem);
|
||||
item.append(impostoItem);
|
||||
item.append(aliquotaPIS);
|
||||
item.append(valorPIS);
|
||||
item.append(aliquotaCofins);
|
||||
item.append(valorCofins);
|
||||
item.append(aliquotaCSLL);
|
||||
item.append(valorCSLL);
|
||||
item.append(aliquotaISS);
|
||||
item.append(valorISS);
|
||||
item.append(totalICMSIsentoItem);
|
||||
item.append(totalICMSNaotributadoItem);
|
||||
item.append(numeroPDV == null ? "" : numeroPDV);
|
||||
item.append(numeroSeriePDV == null ? "" : numeroSeriePDV);
|
||||
item.append(modeloImpressora);
|
||||
item.append(numCaixa);
|
||||
item.append(status);
|
||||
item.append(coo == null ? "" : coo);
|
||||
item.append(serie == null ? "" : serie);
|
||||
item.append(brancos);
|
||||
item.append(sequencial);
|
||||
|
||||
return item.toString();
|
||||
}
|
||||
|
||||
public static String fechamentoDeArquivo(String identificador, String qtdeDocGerados, String qtdeItensDocGerados,
|
||||
String brancos, String sequencial) {
|
||||
|
||||
StringBuilder fechamento = new StringBuilder();
|
||||
fechamento.append(identificador);
|
||||
fechamento.append(qtdeDocGerados == null ? "" : qtdeDocGerados);
|
||||
fechamento.append(qtdeItensDocGerados == null ? "" : qtdeItensDocGerados);
|
||||
fechamento.append(brancos);
|
||||
fechamento.append(sequencial);
|
||||
|
||||
return fechamento.toString();
|
||||
}
|
||||
|
||||
public static String reducaoZ(String identificador, String dataMovimento, String cnpj, String numRelatorio, String numPDV,
|
||||
String numSeriePDV, String numReducaoZ, String gtInicial, String gtFinal, String docFiscalInic,
|
||||
String docFiscalFinal, String valorCancel, String valorContabil, String subtributaria, String descontos,
|
||||
String isento, String naoTributado, String aliquota, String aliquota2, String aliquota3, String aliquota4,
|
||||
String coo, String outrosRecebimentos, String impostoDebitado, String dataReducaoZ, String horaReducaoZ,
|
||||
String valorDocFiscal, String status, String brancos, String sequencial) {
|
||||
|
||||
StringBuilder reducaoZ = new StringBuilder();
|
||||
reducaoZ.append(identificador);
|
||||
reducaoZ.append(dataMovimento);
|
||||
reducaoZ.append(cnpj);
|
||||
reducaoZ.append(numRelatorio);
|
||||
reducaoZ.append(numPDV);
|
||||
reducaoZ.append(numSeriePDV);
|
||||
reducaoZ.append(numReducaoZ);
|
||||
reducaoZ.append(gtInicial);
|
||||
reducaoZ.append(gtFinal);
|
||||
reducaoZ.append(docFiscalInic);
|
||||
reducaoZ.append(docFiscalFinal);
|
||||
reducaoZ.append(valorCancel);
|
||||
reducaoZ.append(valorContabil);
|
||||
reducaoZ.append(subtributaria);
|
||||
reducaoZ.append(descontos);
|
||||
reducaoZ.append(isento);
|
||||
reducaoZ.append(naoTributado);
|
||||
reducaoZ.append(aliquota);
|
||||
reducaoZ.append(aliquota2);
|
||||
reducaoZ.append(aliquota3);
|
||||
reducaoZ.append(aliquota4);
|
||||
reducaoZ.append(coo);
|
||||
reducaoZ.append(outrosRecebimentos);
|
||||
reducaoZ.append(impostoDebitado);
|
||||
reducaoZ.append(dataReducaoZ);
|
||||
reducaoZ.append(horaReducaoZ);
|
||||
reducaoZ.append(valorDocFiscal);
|
||||
reducaoZ.append(status);
|
||||
reducaoZ.append(brancos);
|
||||
reducaoZ.append(sequencial);
|
||||
|
||||
return reducaoZ.toString();
|
||||
}
|
||||
|
||||
}
|
|
@ -4,13 +4,14 @@ import java.io.File;
|
|||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
public class ZipUtil {
|
||||
|
||||
public static void compactarArquivos(File arquivoDeSaida, File... arquivosEOuPastas) throws IOException{
|
||||
if(arquivosEOuPastas != null && arquivoDeSaida != null) {
|
||||
public static void compactarArquivos(File arquivoDeSaida, File... arquivosEOuPastas) throws IOException {
|
||||
if (arquivosEOuPastas != null && arquivoDeSaida != null) {
|
||||
byte[] buf = new byte[1024];
|
||||
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(arquivoDeSaida));
|
||||
|
||||
|
@ -27,6 +28,26 @@ public class ZipUtil {
|
|||
}
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void compactarArquivos(File arquivoDeSaida, List<File> arquivosEOuPastas) throws IOException {
|
||||
if (arquivosEOuPastas != null && arquivoDeSaida != null) {
|
||||
byte[] buf = new byte[1024];
|
||||
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(arquivoDeSaida));
|
||||
|
||||
for (File f : arquivosEOuPastas) {
|
||||
FileInputStream in = new FileInputStream(f.getPath());
|
||||
out.putNextEntry(new ZipEntry(f.getName()));
|
||||
int len;
|
||||
while ((len = in.read(buf)) > 0) {
|
||||
out.write(buf, 0, len);
|
||||
}
|
||||
out.closeEntry();
|
||||
in.close();
|
||||
f.delete();
|
||||
}
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,460 @@
|
|||
package com.rjconsultores.ventaboletos.utilerias.archivointegracion;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.PrintWriter;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.rjconsultores.ventaboletos.constantes.Constantes;
|
||||
import com.rjconsultores.ventaboletos.entidad.Empresa;
|
||||
import com.rjconsultores.ventaboletos.utilerias.DateUtil;
|
||||
import com.rjconsultores.ventaboletos.utilerias.StringHelper;
|
||||
import com.rjconsultores.ventaboletos.utilerias.UtileriasFiscal;
|
||||
import com.rjconsultores.ventaboletos.vo.impressaofiscal.ImportacionFiscalVO;
|
||||
import com.rjconsultores.ventaboletos.vo.impressaofiscal.ItemFiscalVO;
|
||||
import com.rjconsultores.ventaboletos.vo.impressaofiscal.SiglaMotivoCancelacion;
|
||||
import com.rjconsultores.ventaboletos.vo.impressaofiscal.SituacaoTributaria;
|
||||
|
||||
public class ArchivoIntegracionECF {
|
||||
|
||||
private static Logger log = Logger.getLogger(ArchivoIntegracionECF.class);
|
||||
|
||||
public File importacionFiscalECFGenerico(Date inicio, Date fim, Empresa empresa, boolean isNormal, boolean isCancelados, boolean isPendencias, List<ImportacionFiscalVO> list) {
|
||||
|
||||
try {
|
||||
String nomeArquivo = "fiscal_ecf_" + DateUtil.getStringDate(Calendar.getInstance().getTime(), "yyyyMMddhhmmss");
|
||||
if (isCancelados) {
|
||||
nomeArquivo = "fiscal_ecf_cancel_" + DateUtil.getStringDate(Calendar.getInstance().getTime(), "yyyyMMddhhmmss");
|
||||
} else if (isPendencias) {
|
||||
nomeArquivo = "fiscal_ecf_pendencias_" + DateUtil.getStringDate(Calendar.getInstance().getTime(), "yyyyMMddhhmmss");
|
||||
}
|
||||
|
||||
File arquivo = File.createTempFile(nomeArquivo, ".txt");
|
||||
|
||||
PrintWriter gravarArq = new PrintWriter(new OutputStreamWriter(new FileOutputStream(arquivo), Constantes.UTF_8));
|
||||
|
||||
Integer seq = 1;
|
||||
|
||||
String cnpjFilial = empresa.getCnpj();
|
||||
String brancos371 = StringHelper.preencherStringEspacoEsquerda(null, 371);
|
||||
String dataAgora = DateUtil.getStringDate(Calendar.getInstance().getTime(), UtileriasFiscal.DATE_FORMAT_FISCAL);
|
||||
String seqAbertura = StringHelper.preencherZeroEsquerda(seq.toString(), 6);
|
||||
|
||||
String abertura = UtileriasFiscal.aberturaDeArquivo("0", dataAgora, cnpjFilial, brancos371, seqAbertura);
|
||||
gravarArq.print(abertura + UtileriasFiscal.QUEBRA_LINHA);
|
||||
|
||||
Integer qtdDoc = 0;
|
||||
Integer qtdItens = 0;
|
||||
|
||||
String header = null;
|
||||
List<String> itensDocs = new ArrayList<String>();
|
||||
|
||||
for (ImportacionFiscalVO item : list) {
|
||||
|
||||
qtdDoc++;
|
||||
header = null;
|
||||
itensDocs = new ArrayList<String>();
|
||||
|
||||
String data = item.getDataEmissao();
|
||||
String brancos = StringHelper.preencherStringEspacoEsquerda(null, 202);
|
||||
String cnpjEcf = item.getCnpjEcf() == null ? cnpjFilial : item.getCnpjEcf();
|
||||
|
||||
String serie = item.getNumImpressora();
|
||||
if (serie.length() >= 20) {
|
||||
serie = serie.substring(17);
|
||||
serie = StringHelper.preencherStringEspacoEsquerda(serie, 3);
|
||||
} else {
|
||||
serie = StringHelper.preencherStringEspacoEsquerda(null, 3);
|
||||
}
|
||||
|
||||
String especie = StringHelper.preencherStringEspacoDireita("CF", 5);
|
||||
|
||||
String codigoCliente = StringHelper.preencherStringEsquerda(null, 6, "9");
|
||||
String filialCliente = StringHelper.preencherStringEsquerda(null, 2, "9");
|
||||
String condicaoPagamento = StringHelper.preencherStringEsquerda(null, 3, "9");
|
||||
|
||||
String valorPIS = StringHelper.preencherZeroEsquerda(null, 14);
|
||||
String valorCofins = StringHelper.preencherZeroEsquerda(null, 14);
|
||||
String valorCSLL = StringHelper.preencherZeroEsquerda(null, 14);
|
||||
|
||||
String coo = StringHelper.preencherStringEspacoDireita(item.getCoo(), 9);
|
||||
|
||||
BigDecimal valorTotal = UtileriasFiscal.arredondar(UtileriasFiscal.valorTotalItensECF(item));
|
||||
String valorTotalDocumanto = UtileriasFiscal.formataEspacosDecimalDireita(valorTotal, 14);
|
||||
String valorItens = valorTotalDocumanto;
|
||||
|
||||
HashMap<String, String> aliquotaBaseCalculo = getAliquotaBaseCalculo(item);
|
||||
String aliquota = aliquotaBaseCalculo.get("aliquota");
|
||||
String imposto = aliquotaBaseCalculo.get("imposto");
|
||||
String totalICMSIsento = aliquotaBaseCalculo.get("totalICMSIsento");
|
||||
String totalICMSNaotributado = aliquotaBaseCalculo.get("totalICMSNaotributado");
|
||||
|
||||
String origenUf = StringHelper.preencherStringEspacoEsquerda(item.getOrigenUf(), 2);
|
||||
String origen = item.getOrigenId() == null ? StringUtils.EMPTY : item.getOrigenId().toString();
|
||||
if (origen.length() > 2) {
|
||||
origen = origen.substring(2);
|
||||
origen = StringHelper.preencherStringEspacoEsquerda(origen, 5);
|
||||
} else {
|
||||
origen = StringHelper.preencherStringEspacoEsquerda(origen, 5);
|
||||
}
|
||||
|
||||
String destinoUf = StringHelper.preencherStringEspacoEsquerda(item.getDestinoUf(), 2);
|
||||
String destino = item.getDestinoId() == null ? StringUtils.EMPTY : item.getDestinoId().toString();
|
||||
if (destino.length() > 2) {
|
||||
destino = destino.substring(2);
|
||||
destino = StringHelper.preencherStringEspacoEsquerda(destino, 5);
|
||||
} else {
|
||||
destino = StringHelper.preencherStringEspacoEsquerda(destino, 5);
|
||||
}
|
||||
|
||||
String motivocancelacion = null;
|
||||
String valorMulta = null;
|
||||
if (isCancelados) {
|
||||
SiglaMotivoCancelacion sigla = SiglaMotivoCancelacion.valueOf(item.getMotivocancelacion());
|
||||
motivocancelacion = StringHelper.preencherStringEspacoEsquerda(sigla.toString(), 20);
|
||||
valorMulta = UtileriasFiscal.formataZeroDecimal(item.getValorMulta(), 15);
|
||||
brancos = StringHelper.preencherStringEspacoEsquerda(null, 167);
|
||||
}
|
||||
|
||||
seq++;
|
||||
String status = StringHelper.preencherStringEspacoEsquerda(item.getStatus(), 1);
|
||||
String claseServicio = StringHelper.preencherStringEspacoDireita(item.getClaseServicio(), 30);
|
||||
String seqHeader = StringHelper.preencherZeroEsquerda(Integer.valueOf(seq).toString(), 6);
|
||||
|
||||
header = UtileriasFiscal.headerDocumentoFiscal("1", data, cnpjEcf, coo, serie, especie, codigoCliente,
|
||||
filialCliente, condicaoPagamento, valorTotalDocumanto, valorItens, aliquota, imposto,
|
||||
valorPIS, valorCofins, valorCSLL, totalICMSIsento, totalICMSNaotributado, origenUf, origen,
|
||||
destinoUf, destino, null, null, status, motivocancelacion, valorMulta, brancos, claseServicio, seqHeader);
|
||||
|
||||
/*
|
||||
* Item da importacion Fiscal ECF
|
||||
*/
|
||||
int seqItem = 1;
|
||||
for (ItemFiscalVO subItens : item.getItensFiscais()) {
|
||||
String itemDoc = montarItensFiscais(subItens, seq++, seqItem);
|
||||
itensDocs.add(itemDoc);
|
||||
qtdItens++;
|
||||
seqItem++;
|
||||
}
|
||||
|
||||
grabarHeaderItens(gravarArq, header, itensDocs);
|
||||
|
||||
}
|
||||
|
||||
seq++;
|
||||
String qtdeDocGerados = StringHelper.preencherZeroEsquerda(qtdDoc.toString(), 6);
|
||||
String qtdeItensDocGerados = StringHelper.preencherZeroEsquerda(qtdItens.toString(), 6);
|
||||
String brancos381 = StringHelper.preencherStringEspacoEsquerda(null, 381);
|
||||
String seqFechamento = StringHelper.preencherZeroEsquerda(seq.toString(), 6);
|
||||
|
||||
String fechamento = UtileriasFiscal.fechamentoDeArquivo("3", qtdeDocGerados, qtdeItensDocGerados, brancos381, seqFechamento);
|
||||
gravarArq.print(fechamento + UtileriasFiscal.QUEBRA_LINHA);
|
||||
|
||||
gravarArq.close();
|
||||
return arquivo;
|
||||
|
||||
} catch (IOException e) {
|
||||
log.error("", e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private HashMap<String, String> getAliquotaBaseCalculo(ImportacionFiscalVO fiscal) {
|
||||
|
||||
HashMap<String, String> resp = new HashMap<String, String>();
|
||||
|
||||
String aliquota = null;
|
||||
String imposto = null;
|
||||
String totalICMSIsento = null;
|
||||
String totalICMSNaotributado = null;
|
||||
|
||||
for (ItemFiscalVO item : fiscal.getItensFiscais()) {
|
||||
|
||||
BigDecimal valorItem = BigDecimal.ZERO;
|
||||
String codProduto = StringHelper.preencherStringEspacoEsquerda(item.getCodProduto(), 15);
|
||||
// VALIDA TARIFA
|
||||
if (codProduto.indexOf("TA") >= 0) {
|
||||
valorItem = item.getValorTarifa() == null ? valorItem : item.getValorTarifa();
|
||||
if (valorItem.equals(BigDecimal.ZERO))
|
||||
valorItem = BigDecimal.ONE;
|
||||
|
||||
// TAXA DE EMBARQUE
|
||||
} else if (codProduto.indexOf("TX") >= 0) {
|
||||
valorItem = item.getValorEmbarque() == null ? valorItem : item.getValorEmbarque();
|
||||
|
||||
// PEDAGIO
|
||||
} else if (codProduto.indexOf("PE") >= 0) {
|
||||
valorItem = item.getValorPedagio() == null ? valorItem : item.getValorPedagio();
|
||||
|
||||
// SEGURO
|
||||
} else if (codProduto.indexOf("SE") >= 0) {
|
||||
valorItem = item.getValorSeguro() == null ? valorItem : item.getValorSeguro();
|
||||
}
|
||||
|
||||
valorItem = UtileriasFiscal.arredondar(valorItem);
|
||||
item.setValorItem(new BigDecimal(UtileriasFiscal.formataZeroDecimal(valorItem, 15)));
|
||||
|
||||
HashMap<String, BigDecimal> aliquotaBaseCalculo = new HashMap<String, BigDecimal>(0);
|
||||
|
||||
// Verificando se é um produto tributável. Formato: XXTYYYY (XX - Posicao / YYYY - Aliquota)
|
||||
String repTributado = item.getRepTributado() == null ? SituacaoTributaria.NAO_TRIBUTADO.getValue() : item.getRepTributado();
|
||||
if (repTributado.length() == 7 && repTributado.substring(2, 3).equals(SituacaoTributaria.TRIBUTADO.getValue())) {
|
||||
|
||||
String tipoPassagem = item.getTipoPassagem();
|
||||
|
||||
if (tipoPassagem == null) {
|
||||
tipoPassagem = "E";
|
||||
}
|
||||
|
||||
String key = tipoPassagem + item.getRepTributado().substring(3, 7);
|
||||
|
||||
if (!aliquotaBaseCalculo.containsKey(key)) {
|
||||
aliquotaBaseCalculo.put(key, BigDecimal.ZERO);
|
||||
}
|
||||
|
||||
BigDecimal soma = item.getValorItem().divide(BigDecimal.TEN.multiply(BigDecimal.TEN));
|
||||
aliquotaBaseCalculo.put(key, soma.add(aliquotaBaseCalculo.get(key)));
|
||||
|
||||
} else if (repTributado.equals(SituacaoTributaria.NAO_TRIBUTADO.getValue())) {
|
||||
|
||||
BigDecimal soma = item.getValorItem();
|
||||
totalICMSNaotributado = soma.toString();
|
||||
|
||||
if (totalICMSNaotributado.length() < 14) {
|
||||
totalICMSNaotributado = StringHelper.preencherZeroEsquerda(totalICMSNaotributado, 14);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for (String key : aliquotaBaseCalculo.keySet()) {
|
||||
aliquota = key.substring(1, 5);
|
||||
|
||||
BigDecimal aliquotaCalc = BigDecimal.valueOf(Double.valueOf(aliquota) / UtileriasFiscal.CEM.doubleValue());
|
||||
aliquotaCalc = UtileriasFiscal.arredondar(aliquotaCalc);
|
||||
|
||||
BigDecimal baseCalculo = aliquotaBaseCalculo.get(key);
|
||||
baseCalculo = UtileriasFiscal.arredondar(baseCalculo);
|
||||
|
||||
BigDecimal valorImposto = baseCalculo.multiply(aliquotaCalc.divide(UtileriasFiscal.CEM));
|
||||
valorImposto = UtileriasFiscal.arredondar(valorImposto);
|
||||
|
||||
imposto = UtileriasFiscal.formataZeroDecimal(valorImposto, 14);
|
||||
aliquota = UtileriasFiscal.formataZeroDecimal(aliquotaCalc, 14);
|
||||
}
|
||||
|
||||
boolean inconsistente = item.getInconsistencia() == null ? false : item.getInconsistencia();
|
||||
if (inconsistente) {
|
||||
if (codProduto.indexOf("TA") >= 0) {
|
||||
BigDecimal aliquotaCalc = item.getImpostoEstado() == null ? BigDecimal.ZERO : item.getImpostoEstado();
|
||||
aliquotaCalc = UtileriasFiscal.arredondar(aliquotaCalc);
|
||||
|
||||
BigDecimal baseCalculo = valorItem;
|
||||
baseCalculo = UtileriasFiscal.arredondar(baseCalculo);
|
||||
|
||||
BigDecimal valorImposto = baseCalculo.multiply(aliquotaCalc.divide(UtileriasFiscal.CEM));
|
||||
valorImposto = UtileriasFiscal.arredondar(valorImposto);
|
||||
|
||||
imposto = UtileriasFiscal.formataZeroDecimal(valorImposto, 14);
|
||||
aliquota = UtileriasFiscal.formataZeroDecimal(aliquotaCalc, 14);
|
||||
totalICMSIsento = null;
|
||||
totalICMSNaotributado = null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
if (StringUtils.isBlank(aliquota))
|
||||
aliquota = StringHelper.preencherZeroEsquerda(null, 14);
|
||||
|
||||
if (StringUtils.isBlank(imposto))
|
||||
imposto = StringHelper.preencherZeroEsquerda(null, 14);
|
||||
|
||||
if (StringUtils.isBlank(totalICMSIsento))
|
||||
totalICMSIsento = StringHelper.preencherZeroEsquerda(null, 14);
|
||||
|
||||
if (StringUtils.isBlank(totalICMSNaotributado))
|
||||
totalICMSNaotributado = StringHelper.preencherZeroEsquerda(null, 14);
|
||||
|
||||
resp.put("aliquota", aliquota);
|
||||
resp.put("imposto", imposto);
|
||||
resp.put("totalICMSIsento", totalICMSIsento);
|
||||
resp.put("totalICMSNaotributado", totalICMSNaotributado);
|
||||
|
||||
return resp;
|
||||
}
|
||||
|
||||
private String montarItensFiscais(ItemFiscalVO item, Integer seq, Integer seqItem) {
|
||||
|
||||
String tipoPassagem = null;
|
||||
|
||||
String repTributado = item.getRepTributado() == null ? SituacaoTributaria.NAO_TRIBUTADO.getValue() : item.getRepTributado();
|
||||
if (repTributado.length() == 7 && repTributado.substring(2, 3).equals(SituacaoTributaria.TRIBUTADO.getValue())) {
|
||||
tipoPassagem = item.getTipoPassagem();
|
||||
|
||||
if (tipoPassagem == null)
|
||||
tipoPassagem = "E";
|
||||
|
||||
} else {
|
||||
tipoPassagem = "E";
|
||||
}
|
||||
|
||||
String numItem = StringHelper.preencherZeroEsquerda(seqItem.toString(), 3);
|
||||
|
||||
String cfop = null;
|
||||
if (tipoPassagem.equals("E")) {
|
||||
cfop = StringHelper.preencherStringEspacoDireita("6357", 5);
|
||||
} else if (tipoPassagem.equals("M")) {
|
||||
cfop = StringHelper.preencherStringEspacoDireita("5357", 5);
|
||||
}
|
||||
|
||||
String codigoTES = StringHelper.preencherStringEsquerda(null, 3, "9");
|
||||
String codProduto = StringHelper.preencherStringEspacoEsquerda(item.getCodProduto(), 15);
|
||||
String unidade = "UN";
|
||||
String quantidade = "001";
|
||||
|
||||
// TODO: A forma de enviar o valor do item é baseada no codProduto, pelo fato da FISCAL_R5 estar gravando os registros de tarifa errado
|
||||
BigDecimal valorItem = BigDecimal.ZERO;
|
||||
// VALIDA TARIFA
|
||||
if (codProduto.indexOf("TA") >= 0) {
|
||||
valorItem = item.getValorTarifa() == null ? valorItem : item.getValorTarifa();
|
||||
if (valorItem.equals(BigDecimal.ZERO))
|
||||
valorItem = BigDecimal.ONE.divide(UtileriasFiscal.CEM);
|
||||
|
||||
// TAXA DE EMBARQUE
|
||||
} else if (codProduto.indexOf("TX") >= 0) {
|
||||
valorItem = item.getValorEmbarque() == null ? valorItem : item.getValorEmbarque();
|
||||
|
||||
// PEDAGIO
|
||||
} else if (codProduto.indexOf("PE") >= 0) {
|
||||
valorItem = item.getValorPedagio() == null ? valorItem : item.getValorPedagio();
|
||||
|
||||
// SEGURO
|
||||
} else if (codProduto.indexOf("SE") >= 0) {
|
||||
valorItem = item.getValorSeguro() == null ? valorItem : item.getValorSeguro();
|
||||
}
|
||||
|
||||
valorItem = UtileriasFiscal.arredondar(valorItem);
|
||||
String valorUnitario = UtileriasFiscal.formataZeroDecimal(valorItem, 15);
|
||||
item.setValorItem(new BigDecimal(valorUnitario));
|
||||
String valorTotal = valorUnitario;
|
||||
|
||||
String aliquotaItem = StringHelper.preencherZeroEsquerda(null, 7);
|
||||
String impostoItem = StringHelper.preencherZeroEsquerda(null, 15);
|
||||
String totalICMSIsentoItem = StringHelper.preencherZeroEsquerda(null, 15);
|
||||
String totalICMSNaotributadoItem = StringHelper.preencherZeroEsquerda(null, 15);
|
||||
|
||||
HashMap<String, BigDecimal> aliquotaItens = new HashMap<String, BigDecimal>(0);
|
||||
|
||||
// Verificando se é um produto tributável. Formato: XXTYYYY (XX - Posicao / YYYY - Aliquota)
|
||||
if (repTributado.length() == 7 && repTributado.substring(2, 3).equals(SituacaoTributaria.TRIBUTADO.getValue())) {
|
||||
|
||||
String key = tipoPassagem + item.getRepTributado().substring(3, 7);
|
||||
|
||||
if (!aliquotaItens.containsKey(key)) {
|
||||
aliquotaItens.put(key, BigDecimal.ZERO);
|
||||
}
|
||||
|
||||
BigDecimal soma = item.getValorItem().divide(BigDecimal.TEN.multiply(BigDecimal.TEN));
|
||||
aliquotaItens.put(key, soma.add(aliquotaItens.get(key)));
|
||||
|
||||
} else if (repTributado.equals(SituacaoTributaria.NAO_TRIBUTADO.getValue())) {
|
||||
|
||||
BigDecimal soma = item.getValorItem();
|
||||
totalICMSNaotributadoItem = StringHelper.preencherZeroEsquerda(soma.toString(), 15);
|
||||
}
|
||||
|
||||
for (String key : aliquotaItens.keySet()) {
|
||||
aliquotaItem = key.substring(1, 5);
|
||||
|
||||
BigDecimal aliquotaCalc = BigDecimal.valueOf(Double.valueOf(aliquotaItem) / UtileriasFiscal.CEM.doubleValue());
|
||||
aliquotaCalc = UtileriasFiscal.arredondar(aliquotaCalc);
|
||||
|
||||
BigDecimal baseCalculo = aliquotaItens.get(key);
|
||||
baseCalculo = UtileriasFiscal.arredondar(baseCalculo);
|
||||
|
||||
BigDecimal valorImposto = baseCalculo.multiply(aliquotaCalc.divide(UtileriasFiscal.CEM));
|
||||
valorImposto = UtileriasFiscal.arredondar(valorImposto);
|
||||
|
||||
impostoItem = UtileriasFiscal.formataZeroDecimal(valorImposto, 15);
|
||||
aliquotaItem = UtileriasFiscal.formataZeroDecimal(null, 7);
|
||||
}
|
||||
|
||||
boolean inconsistente = item.getInconsistencia() == null ? false : item.getInconsistencia();
|
||||
if (inconsistente) {
|
||||
if (codProduto.indexOf("TA") >= 0) {
|
||||
BigDecimal aliquotaCalc = item.getImpostoEstado() == null ? BigDecimal.ZERO : item.getImpostoEstado();
|
||||
aliquotaCalc = UtileriasFiscal.arredondar(aliquotaCalc);
|
||||
|
||||
BigDecimal baseCalculo = valorItem;
|
||||
baseCalculo = UtileriasFiscal.arredondar(baseCalculo);
|
||||
|
||||
BigDecimal valorImposto = baseCalculo.multiply(aliquotaCalc.divide(UtileriasFiscal.CEM));
|
||||
valorImposto = UtileriasFiscal.arredondar(valorImposto);
|
||||
|
||||
impostoItem = UtileriasFiscal.formataZeroDecimal(valorImposto, 15);
|
||||
aliquotaItem = UtileriasFiscal.formataZeroDecimal(null, 7);
|
||||
totalICMSNaotributadoItem = StringHelper.preencherZeroEsquerda(null, 15);
|
||||
}
|
||||
}
|
||||
|
||||
String aliquotaPIS = StringHelper.preencherZeroEsquerda(null, 7);
|
||||
String valorPIS = StringHelper.preencherZeroEsquerda(null, 15);
|
||||
String aliquotaCofins = StringHelper.preencherZeroEsquerda(null, 7);
|
||||
String valorCofins = StringHelper.preencherZeroEsquerda(null, 15);
|
||||
String aliquotaCSLL = StringHelper.preencherZeroEsquerda(null, 7);
|
||||
String valorCSLL = StringHelper.preencherZeroEsquerda(null, 15);
|
||||
String aliquotaISS = StringHelper.preencherZeroEsquerda(null, 7);
|
||||
String valorISS = StringHelper.preencherZeroEsquerda(null, 15);
|
||||
|
||||
String numeroPDV = StringHelper.preencherStringEspacoDireita(item.getNumpdv(), 10);
|
||||
String numeroSeriePDV = StringHelper.preencherStringEspacoDireita(item.getNumImpressora(), 20);
|
||||
String modeloImpressora = StringHelper.preencherStringEspacoDireita(item.getModeloImpressora(), 40);
|
||||
String numCaixa = StringHelper.preencherStringEspacoDireita(item.getNumCaixa(), 10);
|
||||
String status = StringHelper.preencherStringEspacoEsquerda(item.getStatus(), 1);
|
||||
|
||||
String coo = null;
|
||||
String serie = null;
|
||||
|
||||
coo = StringHelper.preencherStringEspacoDireita(item.getCoo(), 9);
|
||||
serie = item.getNumImpressora();
|
||||
if (serie.length() >= 20) {
|
||||
serie = serie.substring(17);
|
||||
serie = StringHelper.preencherStringEspacoEsquerda(serie, 3);
|
||||
} else {
|
||||
serie = StringHelper.preencherStringEspacoEsquerda(null, 3);
|
||||
}
|
||||
|
||||
String brancos99 = StringHelper.preencherStringEspacoEsquerda(null, 99);
|
||||
|
||||
seq++;
|
||||
String sequencial = StringHelper.preencherZeroEsquerda(seq.toString(), 6);
|
||||
|
||||
String itemDoc = UtileriasFiscal.itensDocumentoFiscal("2", numItem, cfop, codigoTES, codProduto,
|
||||
unidade, quantidade, valorUnitario, valorTotal, aliquotaItem, impostoItem,
|
||||
aliquotaPIS, valorPIS, aliquotaCofins, valorCofins, aliquotaCSLL, valorCSLL,
|
||||
aliquotaISS, valorISS, totalICMSIsentoItem, totalICMSNaotributadoItem,
|
||||
numeroPDV, numeroSeriePDV, modeloImpressora, numCaixa, status, coo, serie,
|
||||
brancos99, sequencial);
|
||||
return itemDoc;
|
||||
|
||||
}
|
||||
|
||||
private void grabarHeaderItens(PrintWriter gravarArq, String header, List<String> itensDocs) {
|
||||
gravarArq.print(header + UtileriasFiscal.QUEBRA_LINHA);
|
||||
|
||||
for (String doc : itensDocs) {
|
||||
gravarArq.print(doc + UtileriasFiscal.QUEBRA_LINHA);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,263 @@
|
|||
package com.rjconsultores.ventaboletos.utilerias.archivointegracion;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.PrintWriter;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.rjconsultores.ventaboletos.constantes.Constantes;
|
||||
import com.rjconsultores.ventaboletos.entidad.Empresa;
|
||||
import com.rjconsultores.ventaboletos.utilerias.DateUtil;
|
||||
import com.rjconsultores.ventaboletos.utilerias.StringHelper;
|
||||
import com.rjconsultores.ventaboletos.utilerias.UtileriasFiscal;
|
||||
import com.rjconsultores.ventaboletos.vo.impressaofiscal.ImportacionManualFiscalVO;
|
||||
import com.rjconsultores.ventaboletos.vo.impressaofiscal.SubItens;
|
||||
|
||||
public class ArchivoIntegracionECFManual {
|
||||
|
||||
private static Logger log = Logger.getLogger(ArchivoIntegracionECFManual.class);
|
||||
|
||||
public File importacionFiscalECFManual(Date inicio, Date fim, Empresa empresa, List<ImportacionManualFiscalVO> listManual) {
|
||||
|
||||
try {
|
||||
String nomeArquivo = "fiscal_ecf_manual_" + DateUtil.getStringDate(Calendar.getInstance().getTime(), "yyyyMMddhhmmss");
|
||||
File arquivo = File.createTempFile(nomeArquivo, ".txt");
|
||||
|
||||
PrintWriter gravarArq = new PrintWriter(new OutputStreamWriter(new FileOutputStream(arquivo), Constantes.UTF_8));
|
||||
|
||||
Integer seq = 1;
|
||||
|
||||
String cnpjFilial = empresa.getCnpj();
|
||||
String brancos371 = StringHelper.preencherStringEspacoEsquerda(null, 371);
|
||||
String dataAgora = DateUtil.getStringDate(Calendar.getInstance().getTime(), UtileriasFiscal.DATE_FORMAT_FISCAL);
|
||||
String sequencial = StringHelper.preencherZeroEsquerda(seq.toString(), 6);
|
||||
|
||||
String abertura = UtileriasFiscal.aberturaDeArquivo("0", dataAgora, cnpjFilial, brancos371, sequencial);
|
||||
gravarArq.print(abertura + UtileriasFiscal.QUEBRA_LINHA);
|
||||
|
||||
Integer qtdDoc = 0;
|
||||
Integer qtdItens = 0;
|
||||
|
||||
inicio = DateUtil.inicioFecha(inicio);
|
||||
fim = DateUtil.fimFecha(fim);
|
||||
|
||||
List<ImportacionManualFiscalVO> list = agruparItensFiscaisManual(listManual);
|
||||
for (ImportacionManualFiscalVO imf : list) {
|
||||
|
||||
qtdDoc++;
|
||||
|
||||
String data = imf.getDataEmissao();
|
||||
|
||||
String coo = StringHelper.preencherZeroEsquerda(imf.getCoo(), 9);
|
||||
String serie = StringHelper.preencherStringEspacoEsquerda(imf.getSerie(), 3);
|
||||
String especie = StringHelper.preencherStringEspacoDireita("RMD", 5);
|
||||
|
||||
String codigoCliente = StringHelper.preencherStringEsquerda(null, 6, "9");
|
||||
String filialCliente = StringHelper.preencherStringEsquerda(null, 2, "9");
|
||||
String condicaoPagamento = StringHelper.preencherStringEsquerda(null, 3, "9");
|
||||
|
||||
BigDecimal valorTotal = UtileriasFiscal.arredondar(calculaValorTotalECFManual(imf));
|
||||
String valorTotalDocumanto = UtileriasFiscal.formataEspacosDecimalDireita(valorTotal, 14);
|
||||
String valorItens = valorTotalDocumanto;
|
||||
|
||||
BigDecimal valorICMS = imf.getIcms() == null ? BigDecimal.ZERO : UtileriasFiscal.arredondar(imf.getIcms());
|
||||
String baseCalICMS = UtileriasFiscal.formataZeroDecimal(valorICMS, 14);
|
||||
|
||||
BigDecimal aliquotaCalc = imf.getIcms() == null ? BigDecimal.ZERO : UtileriasFiscal.arredondar(imf.getIcms());
|
||||
BigDecimal baseCalculo = UtileriasFiscal.arredondar(imf.getValorTotal());
|
||||
BigDecimal valorImposto = UtileriasFiscal.arredondar(baseCalculo.multiply(aliquotaCalc.divide(UtileriasFiscal.CEM)));
|
||||
String valorTotalICMS = UtileriasFiscal.formataZeroDecimal(valorImposto, 14);
|
||||
|
||||
String valorPIS = StringHelper.preencherZeroEsquerda(null, 14);
|
||||
String valorCofins = StringHelper.preencherZeroEsquerda(null, 14);
|
||||
String valorCSLL = StringHelper.preencherZeroEsquerda(null, 14);
|
||||
String totalICMSIsento = StringHelper.preencherZeroEsquerda(null, 14);
|
||||
String totalICMSNaotributado = StringHelper.preencherZeroEsquerda(null, 14);
|
||||
|
||||
String origenUf = StringHelper.preencherStringEspacoEsquerda(imf.getOrigenUf(), 2);
|
||||
String origen = imf.getOrigenId().toString();
|
||||
if (origen.length() > 2) {
|
||||
origen = origen.substring(2);
|
||||
origen = StringHelper.preencherStringEspacoEsquerda(origen, 5);
|
||||
} else {
|
||||
origen = StringHelper.preencherStringEspacoEsquerda(origen, 5);
|
||||
}
|
||||
|
||||
String destinoUf = StringHelper.preencherStringEspacoEsquerda(imf.getDestinoUf(), 2);
|
||||
String destino = imf.getDestinoId().toString();
|
||||
if (destino.length() > 2) {
|
||||
destino = destino.substring(2);
|
||||
destino = StringHelper.preencherStringEspacoEsquerda(destino, 5);
|
||||
} else {
|
||||
destino = StringHelper.preencherStringEspacoEsquerda(destino, 5);
|
||||
}
|
||||
|
||||
String subSerie = StringHelper.preencherStringEspacoEsquerda(imf.getSubSerie(), 2);
|
||||
String aidf = StringHelper.preencherStringEspacoEsquerda(imf.getAidf(), 30);
|
||||
String status = StringHelper.preencherStringEspacoEsquerda(imf.getStatus(), 1);
|
||||
String claseServicio = StringHelper.preencherStringEspacoDireita(imf.getClaseServicio(), 30);
|
||||
String brancos170 = StringHelper.preencherStringEspacoEsquerda(null, 170);
|
||||
|
||||
seq++;
|
||||
sequencial = StringHelper.preencherZeroEsquerda(seq.toString(), 6);
|
||||
|
||||
String header = UtileriasFiscal.headerDocumentoFiscal("1", data, cnpjFilial, coo, serie, especie, codigoCliente,
|
||||
filialCliente, condicaoPagamento, valorTotalDocumanto, valorItens, baseCalICMS, valorTotalICMS,
|
||||
valorPIS, valorCofins, valorCSLL, totalICMSIsento, totalICMSNaotributado, origenUf, origen,
|
||||
destinoUf, destino, subSerie,
|
||||
aidf, status, null, null, brancos170, claseServicio, sequencial);
|
||||
gravarArq.print(header + UtileriasFiscal.QUEBRA_LINHA);
|
||||
|
||||
for (String itemDoc : montarItensFiscaisManual(imf, imf.getSubItens(), seq)) {
|
||||
|
||||
qtdItens++;
|
||||
gravarArq.print(itemDoc + UtileriasFiscal.QUEBRA_LINHA);
|
||||
seq++;
|
||||
}
|
||||
}
|
||||
|
||||
seq++;
|
||||
|
||||
String qtdeDocGerados = StringHelper.preencherZeroEsquerda(qtdDoc.toString(), 6);
|
||||
String qtdeItensDocGerados = StringHelper.preencherZeroEsquerda(qtdItens.toString(), 6);
|
||||
String brancos381 = StringHelper.preencherStringEspacoEsquerda(null, 381);
|
||||
sequencial = StringHelper.preencherZeroEsquerda(seq.toString(), 6);
|
||||
|
||||
String fechamento = UtileriasFiscal.fechamentoDeArquivo("3", qtdeDocGerados, qtdeItensDocGerados, brancos381, sequencial);
|
||||
gravarArq.print(fechamento + UtileriasFiscal.QUEBRA_LINHA);
|
||||
|
||||
gravarArq.close();
|
||||
return arquivo;
|
||||
|
||||
} catch (IOException e) {
|
||||
log.error("", e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private BigDecimal calculaValorTotalECFManual(ImportacionManualFiscalVO imf) {
|
||||
BigDecimal valorTotal = BigDecimal.ZERO;
|
||||
valorTotal = valorTotal.add(imf.getValorTotal());
|
||||
valorTotal = valorTotal.add(imf.getImporteoutros() == null ? BigDecimal.ZERO : imf.getImporteoutros());
|
||||
valorTotal = valorTotal.add(imf.getImportepedagio() == null ? BigDecimal.ZERO : imf.getImportepedagio());
|
||||
valorTotal = valorTotal.add(imf.getImporteseguro() == null ? BigDecimal.ZERO : imf.getImporteseguro());
|
||||
valorTotal = valorTotal.add(imf.getImportetaxaembarque() == null ? BigDecimal.ZERO : imf.getImportetaxaembarque());
|
||||
return valorTotal;
|
||||
}
|
||||
|
||||
private List<String> montarItensFiscaisManual(ImportacionManualFiscalVO imf, List<SubItens> itensFiscais, Integer seq) {
|
||||
|
||||
List<String> itensDocs = new ArrayList<String>();
|
||||
Integer num = 0;
|
||||
|
||||
for (SubItens item : itensFiscais) {
|
||||
|
||||
num++;
|
||||
String numItem = StringHelper.preencherZeroEsquerda(num.toString(), 3);
|
||||
|
||||
String cfop = null;
|
||||
if (imf.getEstadoIdOrigen() != imf.getEstadoIdDestino()) {
|
||||
cfop = StringHelper.preencherStringEspacoDireita("6357", 5);
|
||||
} else {
|
||||
cfop = StringHelper.preencherStringEspacoDireita("5357", 5);
|
||||
}
|
||||
|
||||
String codigoTES = StringHelper.preencherStringEsquerda(null, 3, "9");
|
||||
String prod = imf.getCodProduto() == null ? item.getCodProduto() : imf.getCodProduto();
|
||||
String codProduto = StringHelper.preencherStringEspacoEsquerda(prod, 15);
|
||||
|
||||
String unidade = "UN";
|
||||
String quantidade = "001";
|
||||
|
||||
BigDecimal valorItem = UtileriasFiscal.arredondar(item.getValor());
|
||||
String valorUnitario = UtileriasFiscal.formataZeroDecimal(valorItem, 15);
|
||||
String valorTotal = UtileriasFiscal.formataZeroDecimal(valorItem, 15);
|
||||
|
||||
String aliquotaItem = UtileriasFiscal.formataZeroDecimal(null, 7);
|
||||
String impostoItem = UtileriasFiscal.formataZeroDecimal(null, 15);
|
||||
String totalICMSIsentoItem = StringHelper.preencherZeroEsquerda(null, 15);
|
||||
String totalICMSNaotributadoItem = StringHelper.preencherZeroEsquerda(null, 15);
|
||||
|
||||
if (codProduto.indexOf("TA") >= 0) {
|
||||
BigDecimal aliquotaCalc = UtileriasFiscal.arredondar(imf.getIcms() == null ? BigDecimal.ZERO : imf.getIcms());
|
||||
BigDecimal baseCalculo = UtileriasFiscal.arredondar(imf.getValorTotal() == null ? BigDecimal.ZERO : imf.getValorTotal());
|
||||
BigDecimal valorImposto = UtileriasFiscal.arredondar(baseCalculo.multiply(aliquotaCalc.divide(UtileriasFiscal.CEM)));
|
||||
impostoItem = UtileriasFiscal.formataZeroDecimal(valorImposto, 15);
|
||||
} else {
|
||||
totalICMSNaotributadoItem = StringHelper.preencherZeroEsquerda(valorTotal, 15);
|
||||
}
|
||||
|
||||
String aliquotaPIS = StringHelper.preencherZeroEsquerda(null, 7);
|
||||
String valorPIS = StringHelper.preencherZeroEsquerda(null, 15);
|
||||
String aliquotaCofins = StringHelper.preencherZeroEsquerda(null, 7);
|
||||
String valorCofins = StringHelper.preencherZeroEsquerda(null, 15);
|
||||
String aliquotaCSLL = StringHelper.preencherZeroEsquerda(null, 7);
|
||||
String valorCSLL = StringHelper.preencherZeroEsquerda(null, 15);
|
||||
String aliquotaISS = StringHelper.preencherZeroEsquerda(null, 7);
|
||||
String valorISS = StringHelper.preencherZeroEsquerda(null, 15);
|
||||
|
||||
String numeroPDV = StringHelper.preencherStringEspacoDireita(imf.getNumpdv(), 10);
|
||||
String numeroSeriePDV = StringHelper.preencherStringEspacoDireita(imf.getNumImpressora(), 20);
|
||||
String modeloImpressora = StringHelper.preencherStringEspacoDireita(imf.getModeloImpressora(), 40);
|
||||
String numCaixa = StringHelper.preencherStringEspacoDireita(imf.getNumCaixa(), 10);
|
||||
String status = StringHelper.preencherStringEspacoEsquerda(imf.getStatus(), 1);
|
||||
|
||||
seq++;
|
||||
String sequencial = StringHelper.preencherZeroEsquerda(seq.toString(), 6);
|
||||
String brancos111 = StringHelper.preencherStringEspacoDireita(null, 111);
|
||||
|
||||
String itemDoc = UtileriasFiscal.itensDocumentoFiscal("2", numItem, cfop, codigoTES, codProduto,
|
||||
unidade, quantidade, valorUnitario, valorTotal, aliquotaItem, impostoItem,
|
||||
aliquotaPIS, valorPIS, aliquotaCofins, valorCofins, aliquotaCSLL, valorCSLL,
|
||||
aliquotaISS, valorISS, totalICMSIsentoItem, totalICMSNaotributadoItem,
|
||||
numeroPDV, numeroSeriePDV, modeloImpressora, numCaixa, status, null, null,
|
||||
brancos111, sequencial);
|
||||
itensDocs.add(itemDoc);
|
||||
}
|
||||
|
||||
return itensDocs;
|
||||
}
|
||||
|
||||
private List<ImportacionManualFiscalVO> agruparItensFiscaisManual(List<ImportacionManualFiscalVO> list) {
|
||||
|
||||
List<ImportacionManualFiscalVO> aux = new ArrayList<ImportacionManualFiscalVO>();
|
||||
|
||||
for (ImportacionManualFiscalVO imf : list) {
|
||||
|
||||
List<SubItens> itens = new ArrayList<SubItens>();
|
||||
|
||||
// if (imf.getImporteoutros() != null) {
|
||||
// itens.add(new SubItens(imf.getImporteoutros(), "00000000000-OT"));
|
||||
// }
|
||||
|
||||
if (imf.getImportepedagio() != null) {
|
||||
itens.add(new SubItens(imf.getImportepedagio(), "00000000000-PE"));
|
||||
}
|
||||
|
||||
if (imf.getImporteseguro() != null) {
|
||||
itens.add(new SubItens(imf.getImporteseguro(), "00000000000-SE"));
|
||||
}
|
||||
|
||||
if (imf.getImportetaxaembarque() != null) {
|
||||
itens.add(new SubItens(imf.getImportetaxaembarque(), "00000000000-TX"));
|
||||
}
|
||||
if (imf.getValorItem() != null) {
|
||||
itens.add(new SubItens(imf.getValorTotal(), "00000000000-TA"));
|
||||
}
|
||||
|
||||
imf.setSubItens(itens);
|
||||
aux.add(imf);
|
||||
}
|
||||
|
||||
return aux;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,229 @@
|
|||
package com.rjconsultores.ventaboletos.utilerias.archivointegracion;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.rjconsultores.ventaboletos.utilerias.UtileriasFiscal;
|
||||
import com.rjconsultores.ventaboletos.vo.impressaofiscal.AgpImpressoraEcfVO;
|
||||
import com.rjconsultores.ventaboletos.vo.impressaofiscal.AgpImpressoraReducaoZVO;
|
||||
import com.rjconsultores.ventaboletos.vo.impressaofiscal.ImportacionFiscalReducaoZVO;
|
||||
import com.rjconsultores.ventaboletos.vo.impressaofiscal.ImportacionFiscalVO;
|
||||
import com.rjconsultores.ventaboletos.vo.impressaofiscal.SituacaoTributaria;
|
||||
import com.rjconsultores.ventaboletos.vo.impressaofiscal.TipoPendencia;
|
||||
|
||||
public class ArchivoIntegracionECFReducaoZ {
|
||||
|
||||
private static Logger log = Logger.getLogger(ArchivoIntegracionECFReducaoZ.class);
|
||||
|
||||
private List<AgpImpressoraEcfVO> listAgpEcf;
|
||||
private List<AgpImpressoraReducaoZVO> listAgpRedZ;
|
||||
|
||||
private List<ImportacionFiscalVO> listEcfValidos;
|
||||
private List<ImportacionFiscalReducaoZVO> listRedZValidos;
|
||||
|
||||
private List<ImportacionFiscalVO> listEcfInvalidos;
|
||||
private List<ImportacionFiscalReducaoZVO> listRedZInvalidos;
|
||||
|
||||
public ArchivoIntegracionECFReducaoZ() {
|
||||
listAgpEcf = new ArrayList<AgpImpressoraEcfVO>();
|
||||
listAgpRedZ = new ArrayList<AgpImpressoraReducaoZVO>();
|
||||
|
||||
listEcfValidos = new ArrayList<ImportacionFiscalVO>();
|
||||
listRedZValidos = new ArrayList<ImportacionFiscalReducaoZVO>();
|
||||
|
||||
listEcfInvalidos = new ArrayList<ImportacionFiscalVO>();
|
||||
listRedZInvalidos = new ArrayList<ImportacionFiscalReducaoZVO>();
|
||||
}
|
||||
|
||||
public void importacionFiscalECFValidaReducaoZ(List<ImportacionFiscalVO> listEcf, List<ImportacionFiscalReducaoZVO> listRedZ) {
|
||||
|
||||
listAgpEcf = agruparEcf(listEcf);
|
||||
listAgpRedZ = agruparReducaoZ(listRedZ);
|
||||
|
||||
for (AgpImpressoraReducaoZVO agpRedZ : listAgpRedZ) {
|
||||
|
||||
AgpImpressoraEcfVO agpEcf = buscaRegistroEcf(agpRedZ.getNumserie20(), agpRedZ.getDatamov());
|
||||
if (agpEcf == null) {
|
||||
log.info("SO EXISTE O REGISTRO DA RED Z: " + agpRedZ.getNumserie20() + " -- " + agpRedZ.getDatamov());
|
||||
|
||||
for (ImportacionFiscalReducaoZVO reZ : agpRedZ.getItens()) {
|
||||
reZ.setInconsistente(true);
|
||||
listRedZInvalidos.add(reZ);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
BigDecimal valorEcf = BigDecimal.ZERO;
|
||||
for (ImportacionFiscalVO ecf : agpEcf.getItens()) {
|
||||
BigDecimal valorBoleto = UtileriasFiscal.arredondar(UtileriasFiscal.valorTotalItensECF(ecf));
|
||||
valorEcf = valorEcf.add(valorBoleto);
|
||||
}
|
||||
|
||||
String valorFormatado = UtileriasFiscal.formataZeroDecimal(valorEcf, 0);
|
||||
valorEcf = new BigDecimal(valorFormatado);
|
||||
|
||||
BigDecimal valorRedZ = agpRedZ.getItens().get(0).getVendabrutadiaria();
|
||||
for (ImportacionFiscalReducaoZVO reZ : agpRedZ.getItens()) {
|
||||
|
||||
String tipoMovimento = reZ.getAliquota();
|
||||
if (tipoMovimento.equals(SituacaoTributaria.CANCELADO.getValue()) ||
|
||||
tipoMovimento.equals(SituacaoTributaria.DESCONTO.getValue())) {
|
||||
BigDecimal valorTrib = reZ.getImposto();
|
||||
valorRedZ = valorRedZ.subtract(valorTrib);
|
||||
}
|
||||
}
|
||||
|
||||
if (valorRedZ.compareTo(valorEcf) == 0) {
|
||||
for (ImportacionFiscalVO ecf : agpEcf.getItens()) {
|
||||
listEcfValidos.add(ecf);
|
||||
}
|
||||
|
||||
for (ImportacionFiscalReducaoZVO reZ : agpRedZ.getItens()) {
|
||||
listRedZValidos.add(reZ);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
if (valorRedZ.compareTo(valorEcf) > 0) {
|
||||
log.info("Pendencia RED Z maior que ECF:" + agpEcf.getNumImpressora() + " -- " + agpEcf.getDataEmissao());
|
||||
|
||||
for (ImportacionFiscalVO ecf : agpEcf.getItens()) {
|
||||
listEcfValidos.add(ecf);
|
||||
}
|
||||
|
||||
BigDecimal dif = valorRedZ.subtract(valorEcf);
|
||||
for (ImportacionFiscalReducaoZVO reZv : agpRedZ.getItens()) {
|
||||
BigDecimal vendabrutadiaria = reZv.getVendabrutadiaria().subtract(dif);
|
||||
reZv.setVendabrutadiaria(vendabrutadiaria);
|
||||
listRedZValidos.add(reZv);
|
||||
}
|
||||
|
||||
ImportacionFiscalReducaoZVO reZ = new ImportacionFiscalReducaoZVO(agpRedZ.getItens().get(0));
|
||||
reZ.setAliquota(TipoPendencia.DIF_RED.toString());
|
||||
reZ.setImposto(dif);
|
||||
reZ.setVendabrutadiaria(dif);
|
||||
reZ.setInconsistente(true);
|
||||
|
||||
listRedZInvalidos.add(reZ);
|
||||
|
||||
} else if (valorRedZ.compareTo(valorEcf) < 0) {
|
||||
|
||||
log.info("Pendencia ECF maior que RED Z:" + agpEcf.getNumImpressora() + " -- " + agpEcf.getDataEmissao());
|
||||
|
||||
for (ImportacionFiscalVO ecf : agpEcf.getItens()) {
|
||||
if (ecf.getIndcancelamento().equals("S")) {
|
||||
ecf.setInconsistente(true);
|
||||
listEcfInvalidos.add(ecf);
|
||||
|
||||
} else {
|
||||
listEcfValidos.add(ecf);
|
||||
}
|
||||
}
|
||||
|
||||
for (ImportacionFiscalReducaoZVO reZv : agpRedZ.getItens()) {
|
||||
listRedZValidos.add(reZv);
|
||||
}
|
||||
|
||||
BigDecimal dif = valorEcf.subtract(valorRedZ);
|
||||
ImportacionFiscalReducaoZVO reZ = new ImportacionFiscalReducaoZVO(agpRedZ.getItens().get(0));
|
||||
reZ.setAliquota(TipoPendencia.DIF_ECF.toString());
|
||||
reZ.setImposto(dif);
|
||||
reZ.setVendabrutadiaria(dif);
|
||||
reZ.setInconsistente(true);
|
||||
listRedZInvalidos.add(reZ);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private AgpImpressoraEcfVO buscaRegistroEcf(String numserie20, String datamov) {
|
||||
try {
|
||||
int index = listAgpEcf.indexOf(new AgpImpressoraEcfVO(numserie20, datamov));
|
||||
return listAgpEcf.get(index);
|
||||
} catch (ArrayIndexOutOfBoundsException e) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private List<AgpImpressoraReducaoZVO> agruparReducaoZ(List<ImportacionFiscalReducaoZVO> list) {
|
||||
|
||||
List<AgpImpressoraReducaoZVO> agps = new ArrayList<AgpImpressoraReducaoZVO>();
|
||||
|
||||
AgpImpressoraReducaoZVO atual = null;
|
||||
for (ImportacionFiscalReducaoZVO redz : list) {
|
||||
AgpImpressoraReducaoZVO novo = new AgpImpressoraReducaoZVO(redz.getNumserie20(), redz.getDatamov());
|
||||
|
||||
if (atual == null) {
|
||||
atual = novo;
|
||||
atual.getItens().add(redz);
|
||||
|
||||
} else if (atual.equals(novo)) {
|
||||
atual.getItens().add(redz);
|
||||
|
||||
} else {
|
||||
agps.add(atual);
|
||||
atual = novo;
|
||||
atual.getItens().add(redz);
|
||||
}
|
||||
}
|
||||
|
||||
agps.add(atual);
|
||||
|
||||
return agps;
|
||||
}
|
||||
|
||||
private List<AgpImpressoraEcfVO> agruparEcf(List<ImportacionFiscalVO> list) {
|
||||
|
||||
List<AgpImpressoraEcfVO> agps = new ArrayList<AgpImpressoraEcfVO>();
|
||||
|
||||
AgpImpressoraEcfVO atual = null;
|
||||
for (ImportacionFiscalVO ecf : list) {
|
||||
AgpImpressoraEcfVO novo = new AgpImpressoraEcfVO(ecf.getNumImpressora(), ecf.getDataEmissao());
|
||||
|
||||
if (atual == null) {
|
||||
atual = novo;
|
||||
atual.getItens().add(ecf);
|
||||
|
||||
} else if (atual.equals(novo)) {
|
||||
atual.getItens().add(ecf);
|
||||
|
||||
} else {
|
||||
agps.add(atual);
|
||||
atual = novo;
|
||||
atual.getItens().add(ecf);
|
||||
}
|
||||
}
|
||||
|
||||
agps.add(atual);
|
||||
|
||||
return agps;
|
||||
}
|
||||
|
||||
public List<AgpImpressoraEcfVO> getListAgpEcf() {
|
||||
return listAgpEcf;
|
||||
}
|
||||
|
||||
public List<AgpImpressoraReducaoZVO> getListAgpRedZ() {
|
||||
return listAgpRedZ;
|
||||
}
|
||||
|
||||
public List<ImportacionFiscalVO> getListEcfValidos() {
|
||||
return listEcfValidos;
|
||||
}
|
||||
|
||||
public List<ImportacionFiscalReducaoZVO> getListRedZValidos() {
|
||||
return listRedZValidos;
|
||||
}
|
||||
|
||||
public List<ImportacionFiscalVO> getListEcfInvalidos() {
|
||||
return listEcfInvalidos;
|
||||
}
|
||||
|
||||
public List<ImportacionFiscalReducaoZVO> getListRedZInvalidos() {
|
||||
return listRedZInvalidos;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,188 @@
|
|||
package com.rjconsultores.ventaboletos.utilerias.archivointegracion;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.PrintWriter;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.rjconsultores.ventaboletos.constantes.Constantes;
|
||||
import com.rjconsultores.ventaboletos.entidad.Empresa;
|
||||
import com.rjconsultores.ventaboletos.utilerias.DateUtil;
|
||||
import com.rjconsultores.ventaboletos.utilerias.StringHelper;
|
||||
import com.rjconsultores.ventaboletos.utilerias.UtileriasFiscal;
|
||||
import com.rjconsultores.ventaboletos.vo.impressaofiscal.ImportacionFiscalReducaoZVO;
|
||||
import com.rjconsultores.ventaboletos.vo.impressaofiscal.SituacaoTributaria;
|
||||
|
||||
public class ArchivoIntegracionReducaoZ {
|
||||
|
||||
private static Logger log = Logger.getLogger(ArchivoIntegracionReducaoZ.class);
|
||||
|
||||
public File importacionReducaoZ(Date inicio, Date fim, Empresa empresa, boolean isPendencias, List<ImportacionFiscalReducaoZVO> listReducao) {
|
||||
|
||||
try {
|
||||
String nomeArquivo = "fiscal_reducao_z_" + DateUtil.getStringDate(Calendar.getInstance().getTime(), "yyyyMMddhhmmss");
|
||||
if (isPendencias)
|
||||
nomeArquivo = "fiscal_pendencia_reducao_z_" + DateUtil.getStringDate(Calendar.getInstance().getTime(), "yyyyMMddhhmmss");
|
||||
|
||||
File arquivo = File.createTempFile(nomeArquivo, ".txt");
|
||||
|
||||
PrintWriter gravarArq = new PrintWriter(new OutputStreamWriter(new FileOutputStream(arquivo), Constantes.UTF_8));
|
||||
|
||||
Integer seq = 1;
|
||||
|
||||
String cnpjFilial = StringHelper.retornaSomenteNumeros(empresa.getCnpj() == null ? StringHelper.preencherStringEspacoEsquerda(null, 14) : empresa.getCnpj());
|
||||
String brancos371 = StringHelper.preencherStringEspacoEsquerda(null, 371);
|
||||
String dataAgora = DateUtil.getStringDate(Calendar.getInstance().getTime(), UtileriasFiscal.DATE_FORMAT_FISCAL);
|
||||
String sequencial = StringHelper.preencherZeroEsquerda(seq.toString(), 6);
|
||||
|
||||
String abertura = UtileriasFiscal.aberturaDeArquivo("0", dataAgora, cnpjFilial, brancos371, sequencial);
|
||||
gravarArq.print(abertura + UtileriasFiscal.QUEBRA_LINHA);
|
||||
|
||||
List<ImportacionFiscalReducaoZVO> list = null;
|
||||
if (isPendencias) {
|
||||
list = listReducao;
|
||||
} else {
|
||||
list = agruparReducaoZ(listReducao);
|
||||
}
|
||||
|
||||
for (ImportacionFiscalReducaoZVO ifrZ : list) {
|
||||
|
||||
String dataMovimento = ifrZ.getDatamov();
|
||||
String cnpj = StringHelper.retornaSomenteNumeros(ifrZ.getCnpj() == null ? StringHelper.preencherStringEspacoEsquerda(null, 14) : ifrZ.getCnpj());
|
||||
|
||||
String impAliquota = ifrZ.getAliquota() == null ? "" : ifrZ.getAliquota().substring(0, 2);
|
||||
String numRelatorio = StringHelper.preencherZeroEsquerda(impAliquota, 6);
|
||||
|
||||
String numPDV = StringHelper.preencherStringEspacoEsquerda(ifrZ.getNumpdv(), 10);
|
||||
String numSeriePDV = StringHelper.preencherStringEspacoEsquerda(ifrZ.getNumserie20(), 20);
|
||||
String numReducaoZ = StringHelper.preencherStringEspacoEsquerda(ifrZ.getCrz(), 5);
|
||||
|
||||
String gtInicial = StringHelper.preencherZeroEsquerda(ifrZ.getGtInicial().toString(), 18);
|
||||
String gtFinal = StringHelper.preencherZeroEsquerda(ifrZ.getGtFinal().toString(), 18);
|
||||
|
||||
String docFiscalInic = StringHelper.preencherStringEspacoEsquerda(ifrZ.getCooinicial(), 9);
|
||||
String docFiscalFinal = StringHelper.preencherStringEspacoEsquerda(ifrZ.getCoofinal(), 9);
|
||||
|
||||
String valorCancel = StringHelper.preencherZeroEsquerda(null, 8);
|
||||
String valorContabil = StringHelper.preencherZeroEsquerda(ifrZ.getVendabrutadiaria().toString(), 14);
|
||||
|
||||
String subtributaria = StringHelper.preencherZeroEsquerda(null, 14);
|
||||
String descontos = StringHelper.preencherZeroEsquerda(null, 14);
|
||||
String isento = StringHelper.preencherZeroEsquerda(null, 14);
|
||||
|
||||
String valorNaoTributado = ifrZ.getValorNaoTributado() == null ? "" : ifrZ.getValorNaoTributado().toString();
|
||||
String naoTributado = StringHelper.preencherZeroEsquerda(valorNaoTributado, 14);
|
||||
|
||||
String aliquota = StringHelper.preencherZeroEsquerda(null, 14);
|
||||
if (ifrZ.getAliquota().length() == 7 && ifrZ.getAliquota().substring(2, 3).equals(SituacaoTributaria.TRIBUTADO.getValue())) {
|
||||
aliquota = ifrZ.getAliquota().substring(3, 7);
|
||||
aliquota = StringHelper.preencherZeroEsquerda(aliquota, 14);
|
||||
}
|
||||
|
||||
String aliquota2 = StringHelper.preencherZeroEsquerda(null, 14);
|
||||
String aliquota3 = StringHelper.preencherZeroEsquerda(null, 14);
|
||||
String aliquota4 = StringHelper.preencherZeroEsquerda(null, 14);
|
||||
|
||||
String coo = StringHelper.preencherStringEspacoEsquerda(ifrZ.getCoo(), 6);
|
||||
String outrosRecebimentos = StringHelper.preencherZeroEsquerda(null, 14);
|
||||
|
||||
BigDecimal aliquotaCalc = BigDecimal.valueOf(Double.valueOf(aliquota) / UtileriasFiscal.CEM.doubleValue());
|
||||
aliquotaCalc = UtileriasFiscal.arredondar(aliquotaCalc);
|
||||
|
||||
BigDecimal baseCalculo = UtileriasFiscal.arredondar(ifrZ.getImposto().divide(UtileriasFiscal.CEM));
|
||||
baseCalculo = UtileriasFiscal.arredondar(baseCalculo);
|
||||
|
||||
BigDecimal valorImposto = baseCalculo.multiply(aliquotaCalc.divide(UtileriasFiscal.CEM));
|
||||
valorImposto = UtileriasFiscal.arredondar(valorImposto);
|
||||
String impostoDebitado = UtileriasFiscal.formataZeroDecimal(valorImposto, 13);
|
||||
|
||||
String dataReducaoZ = ifrZ.getDatareducao();
|
||||
String horaReducaoZ = ifrZ.getHorareducao();
|
||||
|
||||
String valorDocFiscal = StringHelper.preencherZeroEsquerda(ifrZ.getImposto().toString(), 13);
|
||||
|
||||
String brancos = StringHelper.preencherStringEspacoEsquerda(null, 81);
|
||||
String status = StringHelper.preencherStringEspacoEsquerda(null, 1);
|
||||
if (isPendencias)
|
||||
status = StringHelper.preencherStringEspacoEsquerda(ifrZ.getStatus(), 1);
|
||||
|
||||
seq++;
|
||||
sequencial = StringHelper.preencherZeroEsquerda(seq.toString(), 6);
|
||||
|
||||
String redZ = UtileriasFiscal.reducaoZ("1", dataMovimento, cnpj, numRelatorio, numPDV, numSeriePDV, numReducaoZ,
|
||||
gtInicial, gtFinal, docFiscalInic, docFiscalFinal, valorCancel, valorContabil, subtributaria,
|
||||
descontos, isento, naoTributado, aliquota, aliquota2, aliquota3, aliquota4, coo, outrosRecebimentos,
|
||||
impostoDebitado, dataReducaoZ, horaReducaoZ, valorDocFiscal, status, brancos, sequencial);
|
||||
gravarArq.print(redZ + UtileriasFiscal.QUEBRA_LINHA);
|
||||
}
|
||||
|
||||
Integer qtdeDoc = seq - 1;
|
||||
seq++;
|
||||
|
||||
String qtdeDocGerados = StringHelper.preencherZeroEsquerda(qtdeDoc.toString(), 6);
|
||||
String brancos387 = StringHelper.preencherStringEspacoEsquerda(null, 387);
|
||||
sequencial = StringHelper.preencherZeroEsquerda(seq.toString(), 6);
|
||||
|
||||
String fechamento = UtileriasFiscal.fechamentoDeArquivo("3", qtdeDocGerados, null, brancos387, sequencial);
|
||||
gravarArq.print(fechamento + UtileriasFiscal.QUEBRA_LINHA);
|
||||
|
||||
gravarArq.close();
|
||||
return arquivo;
|
||||
|
||||
} catch (IOException e) {
|
||||
log.error("", e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private List<ImportacionFiscalReducaoZVO> agruparReducaoZ(List<ImportacionFiscalReducaoZVO> list) {
|
||||
|
||||
List<ImportacionFiscalReducaoZVO> aux = new ArrayList<ImportacionFiscalReducaoZVO>();
|
||||
|
||||
BigDecimal valorNaoTributado = null;
|
||||
BigDecimal valorNaoIncluido = BigDecimal.ZERO;
|
||||
|
||||
ImportacionFiscalReducaoZVO item = null;
|
||||
|
||||
for (ImportacionFiscalReducaoZVO ifr : list) {
|
||||
|
||||
if (!ifr.equals(item)) {
|
||||
valorNaoIncluido = BigDecimal.ZERO;
|
||||
item = ifr;
|
||||
}
|
||||
|
||||
String tipoMovimento = ifr.getAliquota();
|
||||
if (tipoMovimento.equals(SituacaoTributaria.CANCELADO.getValue()) ||
|
||||
tipoMovimento.equals(SituacaoTributaria.DESCONTO.getValue())) {
|
||||
|
||||
valorNaoIncluido = valorNaoIncluido.add(ifr.getImposto());
|
||||
ifr.setValorNaoIncluido(valorNaoIncluido);
|
||||
|
||||
} else if (tipoMovimento.equals(SituacaoTributaria.NAO_TRIBUTADO.getValue())) {
|
||||
valorNaoTributado = ifr.getImposto();
|
||||
} else {
|
||||
|
||||
ifr.setValorNaoTributado(valorNaoTributado);
|
||||
ifr.setValorNaoIncluido(valorNaoIncluido);
|
||||
|
||||
BigDecimal valorReducaoZ = ifr.getVendabrutadiaria().subtract(valorNaoIncluido);
|
||||
ifr.setVendabrutadiaria(valorReducaoZ);
|
||||
|
||||
aux.add(ifr);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return aux;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
package com.rjconsultores.ventaboletos.vo.impressaofiscal;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class AgpImpressoraEcfVO {
|
||||
|
||||
private String numImpressora;
|
||||
private String dataEmissao;
|
||||
|
||||
private List<ImportacionFiscalVO> itens;
|
||||
|
||||
public AgpImpressoraEcfVO() {
|
||||
}
|
||||
|
||||
public AgpImpressoraEcfVO(String numImpressora, String dataEmissao) {
|
||||
super();
|
||||
this.numImpressora = numImpressora;
|
||||
this.dataEmissao = dataEmissao;
|
||||
this.itens = new ArrayList<ImportacionFiscalVO>();
|
||||
}
|
||||
|
||||
public String getNumImpressora() {
|
||||
return numImpressora;
|
||||
}
|
||||
|
||||
public void setNumImpressora(String numImpressora) {
|
||||
this.numImpressora = numImpressora;
|
||||
}
|
||||
|
||||
public String getDataEmissao() {
|
||||
return dataEmissao;
|
||||
}
|
||||
|
||||
public void setDataEmissao(String dataEmissao) {
|
||||
this.dataEmissao = dataEmissao;
|
||||
}
|
||||
|
||||
public List<ImportacionFiscalVO> getItens() {
|
||||
return itens;
|
||||
}
|
||||
|
||||
public void setItens(List<ImportacionFiscalVO> itens) {
|
||||
this.itens = itens;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((dataEmissao == null) ? 0 : dataEmissao.hashCode());
|
||||
result = prime * result + ((numImpressora == null) ? 0 : numImpressora.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
AgpImpressoraEcfVO other = (AgpImpressoraEcfVO) obj;
|
||||
if (dataEmissao == null) {
|
||||
if (other.dataEmissao != null)
|
||||
return false;
|
||||
} else if (!dataEmissao.equals(other.dataEmissao))
|
||||
return false;
|
||||
if (numImpressora == null) {
|
||||
if (other.numImpressora != null)
|
||||
return false;
|
||||
} else if (!numImpressora.equals(other.numImpressora))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
package com.rjconsultores.ventaboletos.vo.impressaofiscal;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class AgpImpressoraReducaoZVO {
|
||||
|
||||
private String numserie20;
|
||||
private String datamov;
|
||||
|
||||
private List<ImportacionFiscalReducaoZVO> itens;
|
||||
|
||||
public AgpImpressoraReducaoZVO() {
|
||||
}
|
||||
|
||||
public AgpImpressoraReducaoZVO(String numserie20, String datamov) {
|
||||
super();
|
||||
this.numserie20 = numserie20;
|
||||
this.datamov = datamov;
|
||||
this.itens = new ArrayList<ImportacionFiscalReducaoZVO>();
|
||||
}
|
||||
|
||||
public String getNumserie20() {
|
||||
return numserie20;
|
||||
}
|
||||
|
||||
public void setNumserie20(String numserie20) {
|
||||
this.numserie20 = numserie20;
|
||||
}
|
||||
|
||||
public String getDatamov() {
|
||||
return datamov;
|
||||
}
|
||||
|
||||
public void setDatamov(String datamov) {
|
||||
this.datamov = datamov;
|
||||
}
|
||||
|
||||
public List<ImportacionFiscalReducaoZVO> getItens() {
|
||||
return itens;
|
||||
}
|
||||
|
||||
public void setItens(List<ImportacionFiscalReducaoZVO> itens) {
|
||||
this.itens = itens;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((datamov == null) ? 0 : datamov.hashCode());
|
||||
result = prime * result + ((numserie20 == null) ? 0 : numserie20.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
AgpImpressoraReducaoZVO other = (AgpImpressoraReducaoZVO) obj;
|
||||
if (datamov == null) {
|
||||
if (other.datamov != null)
|
||||
return false;
|
||||
} else if (!datamov.equals(other.datamov))
|
||||
return false;
|
||||
if (numserie20 == null) {
|
||||
if (other.numserie20 != null)
|
||||
return false;
|
||||
} else if (!numserie20.equals(other.numserie20))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -23,6 +23,32 @@ public class ImportacionFiscalReducaoZVO {
|
|||
private BigDecimal gtInicial;
|
||||
private BigDecimal valorNaoIncluido;
|
||||
private String status;
|
||||
private boolean inconsistente;
|
||||
|
||||
public ImportacionFiscalReducaoZVO() {
|
||||
}
|
||||
|
||||
public ImportacionFiscalReducaoZVO(ImportacionFiscalReducaoZVO item) {
|
||||
this.datamov = item.getDatamov();
|
||||
this.cnpj = item.getCnpj();
|
||||
this.numreducoes = item.getNumreducoes();
|
||||
this.crz = item.getCrz();
|
||||
this.numserie20 = item.getNumserie20();
|
||||
this.coo = item.getCoo();
|
||||
this.cooinicial = item.getCooinicial();
|
||||
this.coofinal = item.getCoofinal();
|
||||
this.vendabrutadiaria = item.getVendabrutadiaria();
|
||||
this.datareducao = item.getDatareducao();
|
||||
this.horareducao = item.getHorareducao();
|
||||
this.aliquota = item.getAliquota();
|
||||
this.imposto = item.getImposto();
|
||||
this.valorNaoTributado = item.getValorNaoTributado();
|
||||
this.numpdv = item.getNumpdv();
|
||||
this.gtFinal = item.getGtFinal();
|
||||
this.gtInicial = item.getGtInicial();
|
||||
this.valorNaoIncluido = item.getValorNaoIncluido();
|
||||
this.status = item.getStatus();
|
||||
}
|
||||
|
||||
public String getDatamov() {
|
||||
return datamov;
|
||||
|
@ -225,4 +251,12 @@ public class ImportacionFiscalReducaoZVO {
|
|||
this.status = status;
|
||||
}
|
||||
|
||||
public boolean isInconsistente() {
|
||||
return inconsistente;
|
||||
}
|
||||
|
||||
public void setInconsistente(boolean inconsistente) {
|
||||
this.inconsistente = inconsistente;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -32,6 +32,8 @@ public class ImportacionFiscalVO {
|
|||
private String cnpjEcf;
|
||||
private BigDecimal impostoEstado;
|
||||
private BigDecimal desconto;
|
||||
private String indcancelamento;
|
||||
private boolean inconsistente;
|
||||
|
||||
private List<ItemFiscalVO> itensFiscais;
|
||||
|
||||
|
@ -148,43 +150,6 @@ public class ImportacionFiscalVO {
|
|||
this.numpdv = numpdv;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((boletoId == null) ? 0 : boletoId.hashCode());
|
||||
result = prime * result + ((coo == null) ? 0 : coo.hashCode());
|
||||
result = prime * result + ((numImpressora == null) ? 0 : numImpressora.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
ImportacionFiscalVO other = (ImportacionFiscalVO) obj;
|
||||
if (boletoId == null) {
|
||||
if (other.boletoId != null)
|
||||
return false;
|
||||
} else if (!boletoId.equals(other.boletoId))
|
||||
return false;
|
||||
if (coo == null) {
|
||||
if (other.coo != null)
|
||||
return false;
|
||||
} else if (!coo.equals(other.coo))
|
||||
return false;
|
||||
if (numImpressora == null) {
|
||||
if (other.numImpressora != null)
|
||||
return false;
|
||||
} else if (!numImpressora.equals(other.numImpressora))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public Integer getDestinoId() {
|
||||
return destinoId;
|
||||
}
|
||||
|
@ -321,4 +286,57 @@ public class ImportacionFiscalVO {
|
|||
this.desconto = desconto;
|
||||
}
|
||||
|
||||
public String getIndcancelamento() {
|
||||
return indcancelamento;
|
||||
}
|
||||
|
||||
public void setIndcancelamento(String indcancelamento) {
|
||||
this.indcancelamento = indcancelamento;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((boletoId == null) ? 0 : boletoId.hashCode());
|
||||
result = prime * result + ((coo == null) ? 0 : coo.hashCode());
|
||||
result = prime * result + ((numImpressora == null) ? 0 : numImpressora.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
ImportacionFiscalVO other = (ImportacionFiscalVO) obj;
|
||||
if (boletoId == null) {
|
||||
if (other.boletoId != null)
|
||||
return false;
|
||||
} else if (!boletoId.equals(other.boletoId))
|
||||
return false;
|
||||
if (coo == null) {
|
||||
if (other.coo != null)
|
||||
return false;
|
||||
} else if (!coo.equals(other.coo))
|
||||
return false;
|
||||
if (numImpressora == null) {
|
||||
if (other.numImpressora != null)
|
||||
return false;
|
||||
} else if (!numImpressora.equals(other.numImpressora))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isInconsistente() {
|
||||
return inconsistente;
|
||||
}
|
||||
|
||||
public void setInconsistente(boolean inconsistente) {
|
||||
this.inconsistente = inconsistente;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
package com.rjconsultores.ventaboletos.vo.impressaofiscal;
|
||||
|
||||
public enum TipoPendencia {
|
||||
DIF_RED, DIF_ECF
|
||||
}
|
Loading…
Reference in New Issue