Sha256: 94c09e0d4c88251e79abe1c130db6ff0f1fa92a3f977b55b54b908980d06f1fc

Contents?: true

Size: 937 Bytes

Versions: 9

Compression:

Stored size: 937 Bytes

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)
      formated = ''

      unless xml_datetime.empty?
        date = DateTime.strptime(xml_datetime, '%Y-%m-%dT%H:%M:%S')
        formated = date.strftime('%d/%m/%Y %H:%M:%S')
      end

      formated
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
br_danfe-0.14.5 lib/br_danfe/helper.rb
br_danfe-0.14.4 lib/br_danfe/helper.rb
br_danfe-0.14.3 lib/br_danfe/helper.rb
br_danfe-0.14.2 lib/br_danfe/helper.rb
br_danfe-0.14.0 lib/br_danfe/helper.rb
br_danfe-0.13.3 lib/br_danfe/helper.rb
br_danfe-0.13.2 lib/br_danfe/helper.rb
br_danfe-0.13.1 lib/br_danfe/helper.rb
br_danfe-0.13.0 lib/br_danfe/helper.rb