module BrInvoicesPdf::Nfce::Renderer::PaymentForms
Constants
- PAYMENTS_TABLE_BASE_DATA
- PAYMENTS_TABLE_BASE_DATA_WITH_CASHBACK
Public Instance Methods
add_default_values(payments_data, data)
click to toggle source
# File lib/br_invoices_pdf/nfce/renderer/payment_forms.rb, line 60 def add_default_values(payments_data, data) totals = format_currency(data[:totals][:total]) if cashback?(data) payments_data.push(['TOTAL', totals, nil]) else payments_data.push(['TOTAL', totals]) end end
cashback?(data)
click to toggle source
# File lib/br_invoices_pdf/nfce/renderer/payment_forms.rb, line 20 def cashback?(data) !data[:payments].map { |payment| payment[:cashback] }.compact.empty? end
choose_table_data(data)
click to toggle source
# File lib/br_invoices_pdf/nfce/renderer/payment_forms.rb, line 16 def choose_table_data(data) cashback?(data) ? payments_table_data_with_cashback(data) : payments_table_data(data) end
execute(pdf, data)
click to toggle source
# File lib/br_invoices_pdf/nfce/renderer/payment_forms.rb, line 12 def execute(pdf, data) execute_payment_form(pdf, choose_table_data(data)) end
format_table(table, table_data)
click to toggle source
:reek: FeatureEnvy
# File lib/br_invoices_pdf/nfce/renderer/payment_forms.rb, line 32 def format_table(table, table_data) table.columns([0, 1, 2]).valign = :center table.columns(1).align = :right table_size = table_data.size table.row([0, table_size - 1]).font_style = :bold end
payments_table_data(data)
click to toggle source
# File lib/br_invoices_pdf/nfce/renderer/payment_forms.rb, line 41 def payments_table_data(data) payments_data = mount_payment_data(data) add_default_values(payments_data, data) end
payments_table_data_with_cashback(data)
click to toggle source
:reek: FeatureEnvy
# File lib/br_invoices_pdf/nfce/renderer/payment_forms.rb, line 51 def payments_table_data_with_cashback(data) payments_data = data[:payments].reduce(PAYMENTS_TABLE_BASE_DATA_WITH_CASHBACK) do |result, cur| result + [[cur[:type], format_currency(cur[:amount]), cur[:cashback]]] end add_default_values(payments_data, data) end
render_table(pdf, table_data, width)
click to toggle source
# File lib/br_invoices_pdf/nfce/renderer/payment_forms.rb, line 24 def render_table(pdf, table_data, width) pdf.table(table_data, width: width) do |table| format_table(table, table_data) end end