Subversion Repositories Integrator Subversion

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
695 blopes 1
package nfe.util;
2
 
3
import br.com.swconsultoria.nfe.dom.enuns.StatusEnum;
4
import br.com.swconsultoria.nfe.exception.NfeException;
5
import br.com.swconsultoria.nfe.schema.envEventoCancNFe.TRetEnvEvento;
6
import br.com.swconsultoria.nfe.schema_4.enviNFe.TRetEnviNFe;
7
import br.com.swconsultoria.nfe.schema_4.retConsReciNFe.TRetConsReciNFe;
8
 
9
/**
10
 * @author Samuel Oliveira - samuk.exe@hotmail.com
11
 * Data: 02/03/2019 - 23:05
12
 */
13
public class RetornoUtil {
14
 
15
    /**
16
     * Valida Retorno Assincrono Trasmissão de Contingencia!
17
     *
18
     * @param retorno
19
     * @throws NfeException
20
     */
21
    public static void validaSincronoTrasmissaoContingencia(TRetEnviNFe retorno) throws NfeException {
22
 
23
        if (!retorno.getCStat().equals(StatusEnum.LOTE_RECEBIDO.getCodigo()) && !retorno.getCStat().equals(StatusEnum.LOTE_PROCESSADO.getCodigo())) {
24
            throw new NfeException(retorno.getCStat() + " - " + retorno.getXMotivo());
25
        }
26
 
27
        if (!retorno.getProtNFe().getInfProt().getCStat().equals(StatusEnum.AUTORIZADO.getCodigo()) && !retorno.getProtNFe().getInfProt().getCStat().equals(StatusEnum.AUTORIZADO_FORA_PRAZO.getCodigo())) {
28
            throw new NfeException(retorno.getProtNFe().getInfProt().getCStat() + " - " + retorno.getProtNFe().getInfProt().getXMotivo());
29
        }
30
    }
31
 
32
    /**
33
     * Valida o Retorno Do Cancelamento
34
     *
35
     * @param retorno
36
     * @throws NfeException
37
     */
38
    public static void validaCancelamento(TRetEnvEvento retorno) throws NfeException {
39
        if (!StatusEnum.LOTE_EVENTO_PROCESSADO.getCodigo().equals(retorno.getCStat())) {
40
            throw new NfeException(retorno.getCStat() + " - " + retorno.getXMotivo());
41
        }
42
 
43
        final String[] erro = {""};
44
        retorno.getRetEvento().forEach( retEvento -> {
45
            if (!StatusEnum.EVENTO_VINCULADO.getCodigo().equals(retEvento.getInfEvento().getCStat()) &&
46
                    !StatusEnum.CANCELAMENTO_FORA_PRAZO.getCodigo().equals(retEvento.getInfEvento().getCStat())) {
47
                erro[0] += retEvento.getInfEvento().getChNFe() + " - " +retEvento.getInfEvento().getCStat() + " - " + retEvento.getInfEvento().getXMotivo() + System.lineSeparator();
48
            }
49
        });
50
 
51
        if(ObjetoUtil.verifica(erro[0]).isPresent()){
52
            throw new NfeException(erro[0]);
53
        }
54
    }
55
 
56
    /**
57
     * Valida o Retorno Do Cancelamento Substituicao
58
     *
59
     * @param retorno
60
     * @throws NfeException
61
     */
62
    public static void validaCancelamentoSubstituicao(br.com.swconsultoria.nfe.schema.envEventoCancSubst.TRetEnvEvento retorno) throws NfeException {
63
        if (!StatusEnum.LOTE_EVENTO_PROCESSADO.getCodigo().equals(retorno.getCStat())) {
64
            throw new NfeException(retorno.getCStat() + " - " + retorno.getXMotivo());
65
        }
66
 
67
        final String[] erro = {""};
68
        retorno.getRetEvento().forEach( retEvento -> {
69
            if (!StatusEnum.EVENTO_VINCULADO.getCodigo().equals(retEvento.getInfEvento().getCStat())) {
70
                erro[0] += retEvento.getInfEvento().getChNFe() + " - " +retEvento.getInfEvento().getCStat() + " - " + retEvento.getInfEvento().getXMotivo() + System.lineSeparator();
71
            }
72
        });
73
 
74
        if(ObjetoUtil.verifica(erro[0]).isPresent()){
75
            throw new NfeException(erro[0]);
76
        }
77
    }
78
 
79
    /**
80
     * Valida o Retorno Da Manifestação
81
     *
82
     * @param retorno
83
     * @throws NfeException
84
     */
85
    public static void validaManifestacao(br.com.swconsultoria.nfe.schema.envConfRecebto.TRetEnvEvento retorno) throws NfeException {
86
        if (!StatusEnum.LOTE_EVENTO_PROCESSADO.getCodigo().equals(retorno.getCStat())) {
87
            throw new NfeException(retorno.getCStat() + " - " + retorno.getXMotivo());
88
        }
89
 
90
        final String[] erro = {""};
91
        retorno.getRetEvento().forEach( retEvento -> {
92
            if (!StatusEnum.EVENTO_VINCULADO.getCodigo().equals(retEvento.getInfEvento().getCStat()) && !StatusEnum.EVENTO_REGISTRADO_NAO_VINCULADO.getCodigo().equals(retEvento.getInfEvento().getCStat())) {
93
                erro[0] += retEvento.getInfEvento().getChNFe() + " - " +retEvento.getInfEvento().getCStat() + " - " + retEvento.getInfEvento().getXMotivo() + System.lineSeparator();
94
            }
95
        });
96
 
97
        if(ObjetoUtil.verifica(erro[0]).isPresent()){
98
            throw new NfeException(erro[0]);
99
        }
100
 
101
    }
102
 
103
    /**
104
     * Valida o Retorno Da Carta de Correção
105
     *
106
     * @param retorno
107
     * @throws NfeException
108
     */
109
    public static void validaCartaCorrecao(br.com.swconsultoria.nfe.schema.envcce.TRetEnvEvento retorno) throws NfeException {
110
        if (!StatusEnum.LOTE_EVENTO_PROCESSADO.getCodigo().equals(retorno.getCStat())) {
111
            throw new NfeException(retorno.getCStat() + " - " + retorno.getXMotivo());
112
        }
113
        final String[] erro = {""};
114
        retorno.getRetEvento().forEach( retEvento -> {
115
            if (!StatusEnum.EVENTO_VINCULADO.getCodigo().equals(retEvento.getInfEvento().getCStat())) {
116
                erro[0] += retEvento.getInfEvento().getChNFe() + " - " +retEvento.getInfEvento().getCStat() + " - " + retEvento.getInfEvento().getXMotivo() + System.lineSeparator();
117
            }
118
        });
119
 
120
        if(ObjetoUtil.verifica(erro[0]).isPresent()){
121
            throw new NfeException(erro[0]);
122
        }
123
    }
124
 
125
    /**
126
     * Valida o Retorno Do EPEC
127
     *
128
     * @param retorno
129
     * @throws NfeException
130
     */
131
    public static void validaEpec(br.com.swconsultoria.nfe.schema.envEpec.TRetEnvEvento retorno) throws NfeException {
132
        if (!StatusEnum.LOTE_EVENTO_PROCESSADO.getCodigo().equals(retorno.getCStat())) {
133
            throw new NfeException(retorno.getCStat() + " - " + retorno.getXMotivo());
134
 
135
        }
136
 
137
        final String[] erro = {""};
138
        retorno.getRetEvento().forEach( retEvento -> {
139
            if (!StatusEnum.EVENTO_VINCULADO.getCodigo().equals(retEvento.getInfEvento().getCStat())) {
140
                erro[0] += retEvento.getInfEvento().getChNFe() + " - " +retEvento.getInfEvento().getCStat() + " - " + retEvento.getInfEvento().getXMotivo() + System.lineSeparator();
141
            }
142
        });
143
 
144
        if(ObjetoUtil.verifica(erro[0]).isPresent()){
145
            throw new NfeException(erro[0]);
146
        }
147
    }
148
 
149
    /**
150
     * Valida o Retorno Da Consulta Cadastro
151
     *
152
     * @param retorno
153
     * @throws NfeException
154
     */
155
    public static void validaConsultaCadastro(br.com.swconsultoria.nfe.schema.retConsCad.TRetConsCad retorno) throws NfeException {
156
        if (!retorno.getInfCons().getCStat().equals(StatusEnum.CADASTRO_ENCONTRADO.getCodigo())) {
157
            throw new NfeException(retorno.getInfCons().getCStat() + " - " + retorno.getInfCons().getXMotivo());
158
        }
159
    }
160
 
161
    /**
162
     * Valida o Retorno Da Inutilização
163
     *
164
     * @param retorno
165
     * @throws NfeException
166
     */
167
    public static void validaInutilizacao(br.com.swconsultoria.nfe.schema_4.inutNFe.TRetInutNFe retorno) throws NfeException {
168
        if (!retorno.getInfInut().getCStat().equals(StatusEnum.INUTILIZADO.getCodigo())) {
169
            throw new NfeException(retorno.getInfInut().getCStat() + " - " + retorno.getInfInut().getXMotivo());
170
        }
171
    }
172
 
173
    /**
174
     * Verifica se Restorno é Sincrono ou Assincrono
175
     *
176
     * @param retorno
177
     * @return
178
     */
179
    public static boolean isRetornoAssincrono(TRetEnviNFe retorno) throws NfeException {
180
        if (!retorno.getCStat().equals(StatusEnum.LOTE_RECEBIDO.getCodigo()) && !retorno.getCStat().equals(StatusEnum.LOTE_PROCESSADO.getCodigo())) {
181
            throw new NfeException(retorno.getCStat() + " - " + retorno.getXMotivo());
182
        }
183
 
184
        return retorno.getCStat().equals(StatusEnum.LOTE_RECEBIDO.getCodigo());
185
    }
186
 
187
    /**
188
     * Valida Retorno Assincrono
189
     *
190
     * @param retorno
191
     * @throws NfeException
192
     */
193
    public static void validaAssincrono(TRetConsReciNFe retorno) throws NfeException {
194
 
195
        if (!retorno.getCStat().equals(StatusEnum.LOTE_PROCESSADO.getCodigo())) {
196
            throw new NfeException(retorno.getCStat() + " - " + retorno.getXMotivo());
197
        }
198
 
199
        final String[] erro = {""};
200
        retorno.getProtNFe().forEach( protNFe -> {
201
            if (!StatusEnum.AUTORIZADO.getCodigo().equals(protNFe.getInfProt().getCStat()) && !StatusEnum.AUTORIZADO_FORA_PRAZO.getCodigo().equals(protNFe.getInfProt().getCStat())) {
202
                erro[0] += protNFe.getInfProt().getChNFe() + " - " +protNFe.getInfProt().getCStat() + " - " + protNFe.getInfProt().getXMotivo() + System.lineSeparator();
203
            }
204
        });
205
 
206
        if(ObjetoUtil.verifica(erro[0]).isPresent()){
207
            throw new NfeException(erro[0]);
208
        }
209
 
210
    }
211
 
212
    /**
213
     * Valida Retorno Assincrono
214
     *
215
     * @param retorno
216
     * @throws NfeException
217
     */
218
    public static void validaSincrono(TRetEnviNFe retorno) throws NfeException {
219
 
220
        if (!retorno.getCStat().equals(StatusEnum.LOTE_RECEBIDO.getCodigo()) && !retorno.getCStat().equals(StatusEnum.LOTE_PROCESSADO.getCodigo())) {
221
            throw new NfeException(retorno.getCStat() + " - " + retorno.getXMotivo());
222
        }
223
 
224
        if (!retorno.getProtNFe().getInfProt().getCStat().equals(StatusEnum.AUTORIZADO.getCodigo()) &&
225
                !retorno.getProtNFe().getInfProt().getCStat().equals(StatusEnum.AUTORIZADO_FORA_PRAZO.getCodigo())) {
226
            throw new NfeException(retorno.getProtNFe().getInfProt().getCStat() + " - " + retorno.getProtNFe().getInfProt().getXMotivo());
227
        }
228
    }
229
 
230
}