Sha256: 1b5639034bbe191d717a5fb8ab9ec453d6045c586e233fe4acf5c8d438694f20

Contents?: true

Size: 1.07 KB

Versions: 16

Compression:

Stored size: 1.07 KB

Contents

module BrDanfe
  class Helper
    def self.no_fiscal_value?(xml)
      homologation?(xml) || unauthorized?(xml)
    end

    def self.homologation?(xml)
      xml.css('nfeProc/NFe/infNFe/ide/tpAmb').text == '2'
    end

    def self.unauthorized?(xml)
      xml.css('nfeProc/protNFe/infProt/dhRecbto').empty?
    end

    def self.numerify(number)
      return '' if !number || number == ''

      separated_number = number.to_s.split('.')
      integer_part = separated_number[0].reverse.gsub(/\d{3}(?=\d)/, '\&.').reverse
      decimal_part = separated_number[1] || '00'
      decimal_part += '0' if decimal_part.size < 2

      "#{integer_part},#{decimal_part}"
    end

    def self.format_datetime(xml_datetime, with_time_zone: false)
      formated = with_time_zone ? '%d/%m/%Y %H:%M:%S%:z' : '%d/%m/%Y %H:%M:%S'
      xml_datetime.present? ? Time.parse(xml_datetime).strftime(formated) : ''
    end

    def self.nfe?(xml)
      nfe_code = '55'

      xml['ide > mod'] == nfe_code
    end

    def self.format_cep(cep)
      cep.sub(/(\d{2})(\d{3})(\d{3})/, '\\1.\\2-\\3')
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
br_danfe-1.2.2 lib/br_danfe/helper.rb
br_danfe-1.2.1 lib/br_danfe/helper.rb
br_danfe-1.2.0 lib/br_danfe/helper.rb
br_danfe-1.1.0 lib/br_danfe/helper.rb
br_danfe-1.0.0 lib/br_danfe/helper.rb
br_danfe-0.20.0 lib/br_danfe/helper.rb
br_danfe-0.19.0 lib/br_danfe/helper.rb
br_danfe-0.18.0 lib/br_danfe/helper.rb
br_danfe-0.17.8 lib/br_danfe/helper.rb
br_danfe-0.17.7 lib/br_danfe/helper.rb
br_danfe-0.17.6 lib/br_danfe/helper.rb
br_danfe-0.17.5 lib/br_danfe/helper.rb
br_danfe-0.17.4 lib/br_danfe/helper.rb
br_danfe-0.17.3 lib/br_danfe/helper.rb
br_danfe-0.17.2 lib/br_danfe/helper.rb
br_danfe-0.17.1 lib/br_danfe/helper.rb