module Utils
Constants
- MONTHS
Public Instance Methods
add_align(aligns, options, key)
click to toggle source
# File lib/sunat_books/pdf/utils.rb, line 32 def add_align(aligns, options, key) cell_style = options[:cell_style] aligns.map do |a| cell_style.merge!(align: a[key][0].to_sym) unless a[key].nil? end end
add_widths(column_widths, options, width)
click to toggle source
# File lib/sunat_books/pdf/utils.rb, line 39 def add_widths(column_widths, options, width) if column_widths.empty? options[:cell_style][:width] = width else options.merge!(column_widths: column_widths) end end
field_value(ticket, field)
click to toggle source
# File lib/sunat_books/pdf/utils.rb, line 63 def field_value(ticket, field) value = available_value?(ticket, field) value = formated_number(value) if value.instance_of? BigDecimal value end
formated_number(float)
click to toggle source
# File lib/sunat_books/pdf/utils.rb, line 16 def formated_number(float) number_to_currency(float, unit: "") end
get_column_widths(widths, key)
click to toggle source
# File lib/sunat_books/pdf/utils.rb, line 47 def get_column_widths(widths, key) obj = {} widths&.each do |w| obj = w[key].flatten unless w[key].nil? end obj end
get_date(year, month, day)
click to toggle source
# File lib/sunat_books/pdf/utils.rb, line 20 def get_date(year, month, day) parse_day(Date.new(year.to_i, month.to_i, day)) end
get_period(month, year)
click to toggle source
# File lib/sunat_books/pdf/utils.rb, line 24 def get_period(month, year) "#{MONTHS[month.to_i].upcase} #{year}" end
get_row_sums(tickets, counts, total_sums)
click to toggle source
# File lib/sunat_books/pdf/utils.rb, line 88 def get_row_sums(tickets, counts, total_sums) # given an array of counts and tickets get sums by each count row_counts = get_mother_counts tickets count_sums = row_counts.map { |count| Books::CountSum.new(count) } # get totals tickets.each do |ticket| count_sums.each do |count_sum| count_sum.add get_value(ticket, count_sum.count) end end # get ordered row order_data_row(counts, count_sums, total_sums) end
order_data_row(counts, count_sums, total_sums)
click to toggle source
# File lib/sunat_books/pdf/utils.rb, line 77 def order_data_row(counts, count_sums, total_sums) data = [] counts.each_with_index do |count, i| sum = sum_count(count_sums, count) value = sum ? sum.total : 0 total_sums[i].add value data << { content: formated_number(value), align: :right } end data end
parse_day(day)
click to toggle source
# File lib/sunat_books/pdf/utils.rb, line 28 def parse_day(day) day.strftime("%d-%m").to_s end
sum_count(count_sums, count)
click to toggle source
# File lib/sunat_books/pdf/utils.rb, line 69 def sum_count(count_sums, count) sum = nil count_sums.each do |count_sum| sum = count_sum if count_sum.count == count end sum end
txt(txt)
click to toggle source
# File lib/sunat_books/pdf/utils.rb, line 55 def txt(txt) text txt, size: 8 end
zero()
click to toggle source
# File lib/sunat_books/pdf/utils.rb, line 59 def zero formated_number(0) end