Sha256: e158e537929a497a2b087ff0e02b985c62ea1a7ea657bce8ae121884d857ebb4

Contents?: true

Size: 1.19 KB

Versions: 14

Compression:

Stored size: 1.19 KB

Contents

module BrInvoicesPdf
  module Cfe
    module Parser
      module Payments
        extend BaseParser

        module_function

        PAYMENT_TYPES = {
          '01' => 'Dinheiro',
          '02' => 'Cheque',
          '03' => 'Cartão de Crédito',
          '04' => 'Cartão de Débito',
          '05' => 'Crédito Loja',
          '10' => 'Vale Alimentação',
          '11' => 'Vale Refeição',
          '12' => 'Vale Presente',
          '13' => 'Vale Combustível',
          '99' => 'Outros'
        }.freeze

        def execute(xml)
          node_payments = xml.locate('infCFe/pgto')

          payments_by_nodes(node_payments) if node_payments && node_payments.any?
        end

        def payments_by_nodes(node_payments)
          node_payments.first.nodes
                       .select { |element| element.value == 'MP' }
                       .map { |element| payment_by(element) }
        end
        private_class_method :payments_by_nodes

        def payment_by(element)
          {
            type: PAYMENT_TYPES[locate_element(element, 'cMP')],
            amount: locate_element(element, 'vMP')
          }
        end
        private_class_method :payment_by
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
br_invoices_pdf-0.2.6 lib/br_invoices_pdf/cfe/parser/payments.rb
br_invoices_pdf-0.2.6.alpha.18 lib/br_invoices_pdf/cfe/parser/payments.rb
br_invoices_pdf-0.2.5.alpha.17 lib/br_invoices_pdf/cfe/parser/payments.rb
br_invoices_pdf-0.2.5 lib/br_invoices_pdf/cfe/parser/payments.rb
br_invoices_pdf-0.2.5.alpha.16 lib/br_invoices_pdf/cfe/parser/payments.rb
br_invoices_pdf-0.2.4 lib/br_invoices_pdf/cfe/parser/payments.rb
br_invoices_pdf-0.2.4.alpha.15 lib/br_invoices_pdf/cfe/parser/payments.rb
br_invoices_pdf-0.2.4.alpha.14 lib/br_invoices_pdf/cfe/parser/payments.rb
br_invoices_pdf-0.2.3 lib/br_invoices_pdf/cfe/parser/payments.rb
br_invoices_pdf-0.2.2 lib/br_invoices_pdf/cfe/parser/payments.rb
br_invoices_pdf-0.2.1 lib/br_invoices_pdf/cfe/parser/payments.rb
br_invoices_pdf-0.2.0 lib/br_invoices_pdf/cfe/parser/payments.rb
br_invoices_pdf-0.2.0.alpha.13 lib/br_invoices_pdf/cfe/parser/payments.rb
br_invoices_pdf-0.2.0.alpha.12 lib/br_invoices_pdf/cfe/parser/payments.rb