• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

wmixvideo / nfe / #6582

17 Jul 2025 09:30PM UTC coverage: 51.231% (+24.2%) from 26.996%
#6582

push

web-flow
Adequação do mapeamento de infLocalCarrega e infLocalDescarrega ao xs:choice do schema MDF-e (#1054)

* Adequação do mapeamento de infLocalCarrega e infLocalDescarrega ao xs:choice do schema MDF-e

* Adequação do mapeamento de infLocalCarrega e infLocalDescarrega ao xs:choice do schema MDF-e

14006 of 27339 relevant lines covered (51.23%)

0.51 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/main/java/com/fincatto/documentofiscal/cte300/utils/CTeGeraChave.java
1
package com.fincatto.documentofiscal.cte300.utils;
2

3
import com.fincatto.documentofiscal.cte300.classes.nota.CTeNota;
4
import com.fincatto.documentofiscal.cte300.classes.os.CTeOS;
5
import org.apache.commons.lang3.StringUtils;
6

7
import java.time.ZonedDateTime;
8
import java.time.format.DateTimeFormatter;
9
import java.util.Random;
10

11
public class CTeGeraChave {
12
    
13
    private final CTeNota nota;
14
    private final CTeOS cteOS;
15

16
    public CTeGeraChave(final CTeNota nota) {
×
17
        this.nota = nota;
×
18
        this.cteOS = null;
×
19
    }
×
20

21
    public CTeGeraChave(final CTeOS cteOS) {
×
22
        this.nota = null;
×
23
        this.cteOS = cteOS;
×
24
    }
×
25
    
26
    public String geraCodigoRandomico() {
27
        long seed;
28
        if (nota != null) {
×
29
            seed = this.nota.getCteNotaInfo().getIdentificacao().getDataEmissao().toInstant().toEpochMilli();
×
30
        } else {
31
            seed = this.cteOS.getInfo().getIdentificacao().getDataEmissao().toInstant().toEpochMilli();
×
32
        }
33
        final Random random = new Random(seed);
×
34
        return StringUtils.leftPad(String.valueOf(random.nextInt(100000000)), 8, "0");
×
35
    }
36
    
37
    public String getChaveAcesso() {
38
        return String.format("%s%s", this.geraChaveAcessoSemDV(), this.getDV());
×
39
    }
40
    
41
    public Integer getDV() {
42
        final char[] valores = this.geraChaveAcessoSemDV().toCharArray();
×
43
        final int[] valoresInt = {2, 3, 4, 5, 6, 7, 8, 9};
×
44
        int indice = 0;
×
45
        int soma = 0;
×
46
        int valorTemp;
47
        int multTemp;
48
        for (int i = valores.length; i > 0; i--) {
×
49
            if (indice >= valoresInt.length) {
×
50
                indice = 0;
×
51
            }
52
    
53
            valorTemp = Integer.parseInt(String.valueOf(valores[i - 1]));
×
54
            multTemp = valoresInt[indice++];
×
55
            soma += valorTemp * multTemp;
×
56
        }
57
        final int dv = 11 - (soma % 11);
×
58
        return ((dv == 11) || (dv == 10)) ? 0 : dv;
×
59
    }
60
    
61
    private String geraChaveAcessoSemDV() {
62
        String codigoNumerico;
63
        String codigoUF;
64
        ZonedDateTime dataEmissao;
65
        String cnpj;
66
        String modelo;
67
        String serie;
68
        String numero;
69
        String tipoEmissao;
70
        if (nota != null) {
×
71
            codigoUF = this.nota.getCteNotaInfo().getIdentificacao().getCodigoUF().getCodigoIbge();
×
72
            dataEmissao = this.nota.getCteNotaInfo().getIdentificacao().getDataEmissao();
×
73
            cnpj = this.nota.getCteNotaInfo().getEmitente().getCnpj();
×
74
            modelo = this.nota.getCteNotaInfo().getIdentificacao().getModelo().getCodigo();
×
75
            serie = this.nota.getCteNotaInfo().getIdentificacao().getSerie().toString();
×
76
            numero = this.nota.getCteNotaInfo().getIdentificacao().getNumero().toString();
×
77
            tipoEmissao = this.nota.getCteNotaInfo().getIdentificacao().getTipoEmissao().getCodigo();
×
78
            codigoNumerico = this.nota.getCteNotaInfo().getIdentificacao().getCodigoNumerico();
×
79
        } else {
80
            codigoUF = this.cteOS.getInfo().getIdentificacao().getCodigoUF().getCodigoIbge();
×
81
            dataEmissao = this.cteOS.getInfo().getIdentificacao().getDataEmissao();
×
82
            cnpj = this.cteOS.getInfo().getEmitente().getCnpj();
×
83
            modelo = this.cteOS.getInfo().getIdentificacao().getModelo().getCodigo();
×
84
            serie = this.cteOS.getInfo().getIdentificacao().getSerie().toString();
×
85
            numero = this.cteOS.getInfo().getIdentificacao().getNumero().toString();
×
86
            tipoEmissao = this.cteOS.getInfo().getIdentificacao().getTipoEmissao().getCodigo();
×
87
            codigoNumerico = this.cteOS.getInfo().getIdentificacao().getCodigoNumerico();
×
88
        }
89
        if (StringUtils.isBlank(codigoNumerico)) {
×
90
            throw new IllegalStateException("Codigo numerico deve estar presente para gerar a chave de acesso");
×
91
        }
92
        return StringUtils.leftPad(codigoUF, 2, "0") + StringUtils.leftPad(DateTimeFormatter.ofPattern("yyMM").format(dataEmissao), 4, "0") + StringUtils.leftPad(cnpj, 14, "0") + StringUtils.leftPad(modelo, 2, "0") + StringUtils.leftPad(serie, 3, "0") + StringUtils.leftPad(numero, 9, "0") + StringUtils.leftPad(tipoEmissao, 1, "0") + StringUtils.leftPad(codigoNumerico, 8, "0");
×
93
    }
94
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc