C # - EFD Reinf v1_04_00 - returnEvents - nrProtEntr - Return Treatment

0

After successfully submitting the R1000 event through the questions:

I get the return on the variable and I need to treat it:

var retornoEnvioXElement = wsClient.ReceberLoteEventos(doc.Root);

? returnEnvironmentXElement

{<Reinf xmlns="http://www.reinf.esocial.gov.br/schemas/retornoLoteEventos/v1_04_00">
  <retornoLoteEventos id="IDF4EBD1BA1DDE6A0B288DD85C8DF1E535">
    <ideTransmissor>
      <IdTransmissor>01628604000140</IdTransmissor>
    </ideTransmissor>
    <status>
      <cdStatus>0</cdStatus>
      <descRetorno>SUCESSO</descRetorno>
    </status>
    <retornoEventos>
      <evento id="ID1016286040000002018121309305100001">
        <Reinf xmlns="http://www.reinf.esocial.gov.br/schemas/evtTotal/v1_04_00">
          <evtTotal id="ID-1066770329">
            <ideEvento>
              <perApur />
            </ideEvento>
            <ideContri>
              <tpInsc>1</tpInsc>
              <nrInsc>01628604</nrInsc>
            </ideContri>
            <ideRecRetorno>
              <ideStatus>
                <cdRetorno>0</cdRetorno>
                <descRetorno>SUCESSO</descRetorno>
              </ideStatus>
            </ideRecRetorno>
            <infoRecEv>
              <dhProcess>2018-12-13T09:31:39.1306938-02:00</dhProcess>
              <tpEv>1000</tpEv>
              <idEv>ID1016286040000002018121309305100001</idEv>
              <hash>dw94b8lBK83zUyVwc6p8obI8F1fc/Ag0NkU2QHWi/Og=</hash>
            </infoRecEv>
            <infoTotal>
              <nrRecArqBase>14009-04-1000-1812-14009</nrRecArqBase>
              <ideEstab>
                <tpInsc>0</tpInsc>
              </ideEstab>
            </infoTotal>
          </evtTotal>
          <Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
            <SignedInfo>
              <CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" />
              <SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256" />
              <Reference URI="#ID-1066770329">
                <Transforms>
                  <Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" />
                  <Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" />
                </Transforms>
                <DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256" />
                <DigestValue>sfY6hV4oPUQhpjcLMZa61Odj8xEQOvAdyLXJOYfvS4g=</DigestValue>
              </Reference>
            </SignedInfo>
            <SignatureValue>[...]</SignatureValue>
            <KeyInfo>
              <X509Data>
                <X509Certificate>[...]</X509Certificate>
              </X509Data>
            </KeyInfo>
          </Signature>
        </Reinf>
      </evento>
    </retornoEventos>
  </retornoLoteEventos>
</Reinf>}

I ask: Which fields should I store for subsequent queries of what was already sent?

I was expecting the nrProtEntr "Event delivery protocol number" but it did not come in this return. Is that right?

Is only <hash>dw94b8lBK83zUyVwc6p8obI8F1fc/Ag0NkU2QHWi/Og=</hash> sufficient to retrieve Delivery Receipts in the future?

    
asked by anonymous 13.12.2018 / 12:56

1 answer

1

The nrProtEntr field is only returned when the closing event R-2099 is sent (see here > how to check the return of this event), in the case of other events the field you should get is nrRecArqBase .

To handle return, this XElement object can be "de-serialized" to a class generated by the XSD tool. exe through the XSDs of the EFD-Reinf Communication Package v1.04.00 , using these functions:

// Pode ser usado para XDocument, XElement, XContainer, XNode.
public T DeserializeFromXNode<T>(XNode xNode)
{
   using (var reader = xNode.CreateReader())
   {
      var xs = new XmlSerializer(typeof(T));
      return (T)xs.Deserialize(reader);
   }
}

// Pode ser usado para XmlDocument, XmlElement, XmlNode e outros.
public T DeserializeFromXmlNode<T>(XmlNode xmlNode)
{
   using (var reader = new XmlNodeReader(xmlNode))
   {
      var xs = new XmlSerializer(typeof(T));
      return (T)xs.Deserialize(reader);
   }
}

That can be used this way:

var retornoEnvio = DeserializeFromXNode<RetornoLoteEventos.Reinf>(retornoEnvioXElement);
var eventos = retornoEnvio?.retornoLoteEventos.retornoEventos?.evento;

foreach (var retornoEvtXml in eventos)
{
   var retornoEvt = DeserializeFromXmlNode<RetornoTotalizadorEvento.Reinf>(retornoEvtXml.Any);
   if (retornoEvt.evtTotal.ideRecRetorno.ideStatus.cdRetorno != 0)
      continue;
   var nrRecibo = retornoEvt.evtTotal.infoTotal?.nrRecArqBase;
   var hash = retornoEvt.evtTotal.infoRecEv.hash;
}

About whether or not to save the hash field, the EFD-Reinf Developer Guidance Manual v1.4 says the following on page 32:

  

In order to retrieve the receipt number, the event must be forwarded to the   environment following the following assumptions:

     

a) The event should be the same one sent previously;
  b) Must have the same HASH;
  c) The same ID should be kept as was sent on the first attempt;

So it might be a good idea to store this field, yes.

    
13.12.2018 / 18:50