Sha256: 1ad4fc1d5cb32fd198a4b5436be98600ca6a641d667059591aabcee3b41494b3

Contents?: true

Size: 1.68 KB

Versions: 12

Compression:

Stored size: 1.68 KB

Contents

module BrInvoicesPdf
  module Cfe
    module Renderer
      module PaymentForms
        extend BaseRenderer

        module_function

        def execute(pdf, data)
          pdf.font_size(6) do
            width = page_content_width(pdf)
            table_data = payments_table_data(data)
            render_table(pdf, table_data, width)
          end

          pdf.move_down(5)
        end

        def render_table(pdf, table_data, width)
          pdf.table(table_data, width: width) do |table|
            format_table(table, table_data)
          end
        end
        private_class_method :render_table

        # :reek:FeatureEnvy
        def format_table(table, table_data)
          table.columns([0, 1]).valign = :center
          table.columns(1).align = :right
          table_size = table_data.size
          table.row([0, table_size - 1]).font_style = :bold
          table.row([0, table_size - 2]).font_style = :bold
        end
        private_class_method :format_table

        PAYMENTS_TABLE_BASE_DATA = [['FORMA DE PAGAMENTO', 'VALOR']].freeze
        def payments_table_data(data)
          payments_data = data[:payments].reduce(PAYMENTS_TABLE_BASE_DATA) do |result, cur|
            result + [[cur[:type], format_currency(BigDecimal(cur[:amount]))]]
          end

          add_default_values(payments_data, data[:payment])
        end
        private_class_method :payments_table_data

        def add_default_values(payments_data, data)
          payments_data.push(['TROCO', format_currency(BigDecimal(data[:cashback]))])
          payments_data.push(['TOTAL', format_currency(BigDecimal(data[:paid]))])
        end
        private_class_method :add_default_values
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
br_invoices_pdf-0.2.5.alpha.17 lib/br_invoices_pdf/cfe/renderer/payment_forms.rb
br_invoices_pdf-0.2.5 lib/br_invoices_pdf/cfe/renderer/payment_forms.rb
br_invoices_pdf-0.2.5.alpha.16 lib/br_invoices_pdf/cfe/renderer/payment_forms.rb
br_invoices_pdf-0.2.4 lib/br_invoices_pdf/cfe/renderer/payment_forms.rb
br_invoices_pdf-0.2.4.alpha.15 lib/br_invoices_pdf/cfe/renderer/payment_forms.rb
br_invoices_pdf-0.2.4.alpha.14 lib/br_invoices_pdf/cfe/renderer/payment_forms.rb
br_invoices_pdf-0.2.3 lib/br_invoices_pdf/cfe/renderer/payment_forms.rb
br_invoices_pdf-0.2.2 lib/br_invoices_pdf/cfe/renderer/payment_forms.rb
br_invoices_pdf-0.2.1 lib/br_invoices_pdf/cfe/renderer/payment_forms.rb
br_invoices_pdf-0.2.0 lib/br_invoices_pdf/cfe/renderer/payment_forms.rb
br_invoices_pdf-0.2.0.alpha.13 lib/br_invoices_pdf/cfe/renderer/payment_forms.rb
br_invoices_pdf-0.2.0.alpha.12 lib/br_invoices_pdf/cfe/renderer/payment_forms.rb