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

wmixvideo / nfe / #9221

24 Jun 2025 01:09AM UTC coverage: 51.423% (+0.6%) from 50.829%
#9221

push

web-flow
Merge 0ce3effce into bb9f583b3

14003 of 27231 relevant lines covered (51.42%)

0.51 hits per line

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

83.33
/src/main/java/com/fincatto/documentofiscal/nfe400/NotaFiscalChaveParser.java
1
package com.fincatto.documentofiscal.nfe400;
2

3
import com.fincatto.documentofiscal.DFModelo;
4
import com.fincatto.documentofiscal.DFUnidadeFederativa;
5
import com.fincatto.documentofiscal.nfe.NFTipoEmissao;
6
import com.fincatto.documentofiscal.utils.DFUtils;
7
import org.apache.commons.lang3.StringUtils;
8

9
import java.time.LocalDate;
10

11
public class NotaFiscalChaveParser {
12

13
    private final String chave;
14

15
    public NotaFiscalChaveParser(final String chave) {
1✔
16
        this.chave = StringUtils.stripToEmpty(chave).replaceAll("\\D", "");
1✔
17
        if (this.chave.length() != 44) {
1✔
18
            throw new IllegalArgumentException(String.format("A chave deve ter exatos 44 caracteres numericos: %s", chave));
1✔
19
        }
20
    }
1✔
21

22
    public String getChave() {
23
        return this.chave;
×
24
    }
25

26
    public DFUnidadeFederativa getNFUnidadeFederativa() {
27
        return DFUnidadeFederativa.valueOfCodigo(this.chave.substring(0, 2));
1✔
28
    }
29

30
    public LocalDate getDataEmissao() {
31
        return LocalDate.of(this.getDataEmissaoAno(), this.getDataEmissaoMes(), 1);
1✔
32
    }
33

34
    private int getDataEmissaoMes() {
35
        return Integer.parseInt(this.chave.substring(4, 6));
1✔
36
    }
37

38
    private int getDataEmissaoAno() {
39
        return 2000 + Integer.parseInt(this.chave.substring(2, 4));
1✔
40
    }
41

42
    public DFModelo getModelo() {
43
        return DFModelo.valueOfCodigo(this.chave.substring(20, 22));
×
44
    }
45

46
    public String getSerie() {
47
        return this.chave.substring(22, 25);
1✔
48
    }
49

50
    public String getNumero() {
51
        return this.chave.substring(25, 34);
1✔
52
    }
53

54
    public NFTipoEmissao getFormaEmissao() {
55
        return NFTipoEmissao.valueOfCodigo(this.chave.substring(34, 35));
1✔
56
    }
57

58
    public String getCodigoNumerico() {
59
        return this.chave.substring(35, 43);
1✔
60
    }
61

62
    public String getDV() {
63
        return this.chave.substring(43, 44);
1✔
64
    }
65

66
    public boolean isEmitidaContingenciaSCAN() {
67
        return this.getSerie().matches("9[0-9]{2}");
1✔
68
    }
69

70
    public boolean isEmitidaContingenciaSCVAN() {
71
        return this.chave.matches("\\d{34}6\\d{9}");
×
72
    }
73

74
    public boolean isEmitidaContingenciaSCVRS() {
75
        return this.chave.matches("\\d{34}7\\d{9}");
×
76
    }
77

78
    public String getFormatado() {
79
        return this.chave.replaceFirst("(\\d{4})(\\d{4})(\\d{4})(\\d{4})(\\d{4})(\\d{4})(\\d{4})(\\d{4})(\\d{4})(\\d{4})(\\d{4})", "$1 $2 $3 $4 $5 $6 $7 $8 $9 $10 $11");
1✔
80
    }
81

82
    /**
83
     * Indica se o emitente da chave eh pessoa fisica.
84
     * @return Se chave foi emitida por pessoa fisica.
85
     */
86
    public boolean isEmitentePessoaFisica() {
87
        return DFUtils.isCpfValido(this.chave.substring(9, 20));
1✔
88
    }
89

90
    /**
91
     * Indica se o emitente da chave eh pessoa juridica.
92
     * @return Se chave foi emitida por pessoa juridica.
93
     */
94
    public boolean isEmitentePessoaJuridica() {
95
        return DFUtils.isCnpjValido(this.chave.substring(6, 20));
1✔
96
    }
97

98
    /**
99
     * Returna o CNPJ do emitente da chave.<br>
100
     * Se nao for um CNPJ valido, retorna nulo.
101
     *
102
     * @return CNPJ do emitente ou nulo.
103
     */
104
    public String getCnpjEmitente() {
105
        return isEmitentePessoaJuridica() ? this.chave.substring(6, 20) : null;
1✔
106
    }
107

108
    /**
109
     * Returna o CPF do emitente da chave.<br>
110
     * Se nao for um CPF valido, retorna nulo.
111
     *
112
     * @return CPF do emitente ou nulo.
113
     */
114
    public String getCpfEmitente() {
115
        return isEmitentePessoaFisica() ? this.chave.substring(9, 20) : null;
1✔
116
    }
117
}
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

© 2026 Coveralls, Inc