class SunatBooks::Pdf::Base
Public Instance Methods
book_header(period, ruc, name, title = nil)
click to toggle source
# File lib/sunat_books/pdf/base.rb, line 47 def book_header(period, ruc, name, title = nil) move_down 5 txt name.to_s.upcase txt "RUC: #{ruc}" book_title("#{title} - #{period}") move_down 5 end
book_title(title)
click to toggle source
# File lib/sunat_books/pdf/base.rb, line 43 def book_title(title) text title, align: :center, size: 8 end
get_counts(tickets)
click to toggle source
diary
# File lib/sunat_books/pdf/base.rb, line 106 def get_counts(tickets) tickets.map(&:uniq_counts).flatten.uniq.sort end
get_mother_counts(tickets)
click to toggle source
# File lib/sunat_books/pdf/base.rb, line 110 def get_mother_counts(tickets) tickets.map(&:uniq_mother_counts).flatten.uniq.sort end
get_value(ticket, count)
click to toggle source
# File lib/sunat_books/pdf/base.rb, line 114 def get_value(ticket, count) # active_amount = ticket.get_amount_by_position(count) # pasive_amount = ticket.get_amount_by_position(count, false) active_amount = ticket.get_amount_by_mother_count(count) pasive_amount = ticket.get_amount_by_mother_count(count, false) # if count === '401' && ticket.operation_type == 'compras' # amount = amount * (-1) # end active_amount - pasive_amount end
make_sub_table(content, width = nil)
click to toggle source
# File lib/sunat_books/pdf/base.rb, line 125 def make_sub_table(content, width = nil) options = { cell_style: { width: width, size: 5, borders: [], align: :right } } content_row = [] content.each { |c| content_row << formated_number(c) } make_table([content_row], options) end
prawn_header(title, period, company)
click to toggle source
# File lib/sunat_books/pdf/base.rb, line 55 def prawn_header(title, period, company) repeat(:all) do canvas do bounding_box([bounds.left + 10, bounds.top - 10], width: 800) do book_header period, company.ruc, company.name, title end end end end
sub_head(hash, book_name, blayout)
click to toggle source
# File lib/sunat_books/pdf/base.rb, line 15 def sub_head(hash, book_name, blayout) arr, current_key = nil hash.each do |key, value| k = I18n.t("books.#{book_name}.#{key}").mb_chars.upcase.to_s v = value.collect do |s| I18n.t("books.#{book_name}.#{s}").mb_chars.upcase.to_s end arr = [[{ content: k, colspan: value.length }], v] current_key = key end sub_head_table(blayout["widths"], arr, current_key) end
sub_head_options(column_widths)
click to toggle source
# File lib/sunat_books/pdf/base.rb, line 35 def sub_head_options(column_widths) options = { cell_style: { borders: [], size: 5, align: :center, padding: 1 } } add_widths(column_widths, options, 22) options end
sub_head_table(widths, arr, key)
click to toggle source
# File lib/sunat_books/pdf/base.rb, line 29 def sub_head_table(widths, arr, key) column_widths = get_column_widths(widths, key) options = sub_head_options(column_widths) make_table(arr, options) end
table_body(fields, ticket, widths, aligns)
click to toggle source
# File lib/sunat_books/pdf/base.rb, line 78 def table_body(fields, ticket, widths, aligns) tbody = [] fields.each do |f| if f.is_a? Hash table_hash(f, ticket, tbody, widths, aligns) else tbody << field_value(ticket, f) end end tbody end
table_hash(field, ticket, tbody, widths, aligns)
click to toggle source
# File lib/sunat_books/pdf/base.rb, line 90 def table_hash(field, ticket, tbody, widths, aligns) options = { cell_style: { borders: [], size: 5 } } field.each do |key, value| v = value.collect do |s| value = field_value(ticket, s) end column_widths = get_column_widths(widths, key) add_widths(column_widths, options, 28) add_align(aligns, options, key) unless aligns.nil? tbody << make_table([v], options) end end
table_head(fields, book_name, layout)
click to toggle source
# File lib/sunat_books/pdf/base.rb, line 65 def table_head(fields, book_name, layout) thead = [] fields.each do |h| if h.instance_of? Hash r = sub_head(h, book_name, layout) thead << r else thead << I18n.t("books.#{book_name}.#{h}").mb_chars.upcase.to_s end end thead end