Sha256: f86a1fa1d896fbd50039c923d16631683067c1c8780897b53beebbd8bf57f66b

Contents?: true

Size: 1.65 KB

Versions: 2

Compression:

Stored size: 1.65 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(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(data[:cashback])])
          payments_data.push(['TOTAL', format_currency(data[:paid])])
        end
        private_class_method :add_default_values
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
br_invoices_pdf-0.2.6 lib/br_invoices_pdf/cfe/renderer/payment_forms.rb
br_invoices_pdf-0.2.6.alpha.18 lib/br_invoices_pdf/cfe/renderer/payment_forms.rb