Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1 | espaco | 1 | package nfe; |
| 2 | |||
| 3 | import java.rmi.RemoteException; |
||
| 4 | |||
| 5 | import javax.xml.bind.JAXBException; |
||
| 6 | import javax.xml.stream.XMLStreamException; |
||
| 7 | |||
| 8 | import org.apache.axiom.om.OMElement; |
||
| 9 | import org.apache.axiom.om.util.AXIOMUtil; |
||
| 10 | import org.apache.axis2.transport.http.HTTPConstants; |
||
| 11 | |||
| 12 | import br.inf.portalfiscal.nfe.schema_4.inutNFe.TInutNFe; |
||
| 13 | import br.inf.portalfiscal.nfe.schema_4.inutNFe.TRetInutNFe; |
||
| 14 | import br.inf.portalfiscal.www.nfe_400.wsdl.NFeInutilizacao.NFeInutilizacao4Stub; |
||
| 15 | import nfe.dom.ConfiguracoesIniciaisNfe; |
||
| 16 | import nfe.exception.NfeException; |
||
| 17 | import nfe.exception.NfeValidacaoException; |
||
| 18 | import nfe.util.CertificadoUtil; |
||
| 19 | import nfe.util.ConstantesUtil; |
||
| 20 | import nfe.util.ObjetoUtil; |
||
| 21 | import nfe.util.WebServiceUtil; |
||
| 22 | import nfe.util.XmlUtil; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * Classe Responsavel por inutilizar uma Faixa de numeracao da Nfe. |
||
| 26 | * |
||
| 27 | * @author Samuel Oliveira - samuk.exe@hotmail.com - www.samuelweb.com.br |
||
| 28 | */ |
||
| 29 | class Inutilizar { |
||
| 30 | |||
| 31 | static TInutNFe criaObjetoInutiliza(String id, String motivo, String tipo) throws NfeException { |
||
| 32 | ConfiguracoesIniciaisNfe config = ConfiguracoesIniciaisNfe.getInstance(); |
||
| 33 | |||
| 34 | TInutNFe inutNFe = new TInutNFe(); |
||
| 35 | inutNFe.setVersao(ConstantesUtil.VERSAO.INUTILIZACAO); |
||
| 36 | |||
| 37 | TInutNFe.InfInut infInut = new TInutNFe.InfInut(); |
||
| 38 | infInut.setId(id); |
||
| 39 | infInut.setTpAmb(config.getAmbiente()); |
||
| 40 | infInut.setXServ("INUTILIZAR"); |
||
| 41 | infInut.setCUF(id.substring(2,4)); |
||
| 42 | infInut.setAno(id.substring(4,6)); |
||
| 43 | |||
| 44 | infInut.setCNPJ(id.substring(6,20)); |
||
| 45 | infInut.setMod(tipo.equals(ConstantesUtil.NFE) ? "55" : "65"); |
||
| 46 | infInut.setSerie(Integer.valueOf(id.substring(22,25)).toString()); |
||
| 47 | |||
| 48 | infInut.setNNFIni(Integer.valueOf(id.substring(25,34)).toString()); |
||
| 49 | infInut.setNNFFin(Integer.valueOf(id.substring(34,43)).toString()); |
||
| 50 | |||
| 51 | infInut.setXJust(motivo); |
||
| 52 | inutNFe.setInfInut(infInut); |
||
| 53 | |||
| 54 | return inutNFe; |
||
| 55 | } |
||
| 56 | |||
| 57 | static TRetInutNFe inutiliza(String id, String motivo, String tipo) throws NfeException { |
||
| 58 | |||
| 59 | try { |
||
| 60 | |||
| 61 | ConfiguracoesIniciaisNfe config = CertificadoUtil.iniciaConfiguracoes(); |
||
| 62 | |||
| 63 | TInutNFe inutNFe = criaObjetoInutiliza(id, motivo,tipo); |
||
| 64 | |||
| 65 | String xml = XmlUtil.objectToXml(inutNFe); |
||
| 66 | xml = xml.replaceAll(" xmlns:ns2=\"http://www.w3.org/2000/09/xmldsig#\"", ""); |
||
| 67 | |||
| 68 | xml = Assinar.assinaNfe(xml, Assinar.INFINUT); |
||
| 69 | |||
| 70 | String erros = Validar.validaXml(xml, Validar.INUTILIZACAO); |
||
| 71 | if (!ObjetoUtil.isEmpty(erros)) { |
||
| 72 | throw new NfeValidacaoException("Erro Na Validação do Xml: " + erros); |
||
| 73 | } |
||
| 74 | |||
| 75 | if (config.isLog()) { |
||
| 76 | System.out.println("Xml Inutilizar: " + xml); |
||
| 77 | } |
||
| 78 | OMElement ome = AXIOMUtil.stringToOM(xml); |
||
| 79 | |||
| 80 | NFeInutilizacao4Stub.NfeDadosMsg dadosMsg = new NFeInutilizacao4Stub.NfeDadosMsg(); |
||
| 81 | dadosMsg.setExtraElement(ome); |
||
| 82 | |||
| 83 | NFeInutilizacao4Stub stub = new NFeInutilizacao4Stub(WebServiceUtil.getUrl(tipo, ConstantesUtil.SERVICOS.INUTILIZACAO)); |
||
| 84 | |||
| 85 | //Timeout |
||
| 86 | if (!ObjetoUtil.isEmpty(config.getTimeout())) { |
||
| 87 | stub._getServiceClient().getOptions().setProperty( |
||
| 88 | HTTPConstants.SO_TIMEOUT, config.getTimeout()); |
||
| 89 | stub._getServiceClient().getOptions().setProperty( |
||
| 90 | HTTPConstants.CONNECTION_TIMEOUT, config.getTimeout()); |
||
| 91 | } |
||
| 92 | |||
| 93 | NFeInutilizacao4Stub.NfeResultMsg result = stub.nfeInutilizacaoNF(dadosMsg); |
||
| 94 | |||
| 95 | return XmlUtil.xmlToObject(result.getExtraElement().toString(), TRetInutNFe.class); |
||
| 96 | } catch (RemoteException | XMLStreamException | JAXBException e) { |
||
| 97 | throw new NfeException(e.getMessage()); |
||
| 98 | } |
||
| 99 | |||
| 100 | } |
||
| 101 | |||
| 102 | } |