module BrInvoicesPdf::Nfce::Parser::EmissionDetails

Constants

EMISSION_TYPES

Public Instance Methods

check_url(xml) click to toggle source
# File lib/br_invoices_pdf/nfce/parser/emission_details.rb, line 57
def check_url(xml)
  emission_path = emission_root_path(xml)

  check_urls = Util::NfceCheckUrls::URLS[locate_element(xml, "#{emission_path}/cUF").to_sym]
  check_urls[locate_element(xml, "#{emission_path}/tpAmb").to_sym]
end
contingency_params(xml) click to toggle source
# File lib/br_invoices_pdf/nfce/parser/emission_details.rb, line 40
def contingency_params(xml)
  emission_path = emission_root_path(xml)

  hash = {
    type: EMISSION_TYPES[(locate_element(xml, "#{emission_path}/tpEmis") || '1').to_sym],
    number: locate_element(xml, "#{emission_path}/nNF"),
    serie: locate_element(xml, "#{emission_path}/serie"),
    emission_timestamp: locate_element_to_date(xml, "#{emission_path}/dhEmi"),
    check_url: check_url(xml)
  }

  node = xml.locate('infNFeSupl/qrCode').first

  hash[:qrcode_url] = node.nodes.first.value if node
  hash
end
emission_root_path(xml) click to toggle source
# File lib/br_invoices_pdf/nfce/parser/emission_details.rb, line 11
def emission_root_path(xml)
  "#{root_path(xml)}/ide"
end
execute(xml) click to toggle source
# File lib/br_invoices_pdf/nfce/parser/emission_details.rb, line 26
def execute(xml)
  locate_element(xml, 'protNFe/infProt/chNFe') ? normal_params(xml) : contingency_params(xml)
end
locate_element_to_date(xml, path) click to toggle source
# File lib/br_invoices_pdf/nfce/parser/emission_details.rb, line 65
def locate_element_to_date(xml, path)
  element = locate_element(xml, path)

  Time.parse(element).utc
rescue StandardError => _e
  Time.parse("#{element[0..18]}-03:00").utc
end
normal_params(xml) click to toggle source
# File lib/br_invoices_pdf/nfce/parser/emission_details.rb, line 30
def normal_params(xml)
  {
    **contingency_params(xml),
    qrcode_url: xml.locate('NFe/infNFeSupl/qrCode').first.nodes.first.value,
    receival_timestamp: locate_element_to_date(xml, 'protNFe/infProt/dhRecbto'),
    access_key: locate_element(xml, 'protNFe/infProt/chNFe'),
    authorization_protocol: locate_element(xml, 'protNFe/infProt/nProt')
  }
end