class BrDanfe::MdfeLib::Notes

Constants

MAX_CHARS_ON_LINE

Public Class Methods

new(pdf, xml) click to toggle source
# File lib/br_danfe/mdfe_lib/notes.rb, line 6
def initialize(pdf, xml)
  @pdf = pdf
  @xml = xml
end

Public Instance Methods

generate() click to toggle source
# File lib/br_danfe/mdfe_lib/notes.rb, line 11
def generate
  title
  aditional_information_first_page
  aditional_information_taxpayer
end

Private Instance Methods

aditional_information_first_page() click to toggle source
# File lib/br_danfe/mdfe_lib/notes.rb, line 30
def aditional_information_first_page
  fisco_information = @xml['infAdic/infAdFisco']

  fisco_information_title = 'INFORMAÇÕES ADICIONAIS DE INTERESSE DO FISCO'
  taxpayer_information_title = 'INFORMAÇÕES ADICIONAIS DE INTERESSE DO CONTRIBUINTE'

  @pdf.bounding_box([0, @pdf.cursor], width: 526) do
    if fisco_information.present?
      @pdf.text(fisco_information_title, size: 10)
      @pdf.move_down 5
      @pdf.text(fisco_information, size: 10)
      @pdf.move_down 10
    end

    if taxpayer_information_xml.present?
      @pdf.text(taxpayer_information_title, size: 10)
      @pdf.move_down 5
    end
  end
end
aditional_information_taxpayer() click to toggle source
# File lib/br_danfe/mdfe_lib/notes.rb, line 55
def aditional_information_taxpayer
  first_page, next_page = fill_aditional_information_taxpayer(@pdf.cursor).values_at(:first_page, :next_page)

  generate_aditional_information_taxpayer(first_page, @pdf.cursor)

  if next_page.present?
    @pdf.start_new_page
    generate_aditional_information_taxpayer(next_page, y_position_next_pages)
  end
end
fill_aditional_information_taxpayer(height_on_first_page) click to toggle source
# File lib/br_danfe/mdfe_lib/notes.rb, line 66
def fill_aditional_information_taxpayer(height_on_first_page)
  first_page = ''
  next_page = ''
  total_chars = 0
  total_height = 0

  taxpayer_information_xml.split.each do |word|
    total_chars += word.split.count + 1

    total_height += 10 if total_chars >= MAX_CHARS_ON_LINE

    total_height <= height_on_first_page ? first_page += "#{word} " : next_page += "#{word} "
  end

  { first_page: first_page, next_page: next_page }
end
generate_aditional_information_taxpayer(data, position) click to toggle source
# File lib/br_danfe/mdfe_lib/notes.rb, line 83
def generate_aditional_information_taxpayer(data, position)
  @pdf.bounding_box([0, position], width: 526) do
    @pdf.text(data, size: 10)
  end
end
taxpayer_information_xml() click to toggle source
# File lib/br_danfe/mdfe_lib/notes.rb, line 51
def taxpayer_information_xml
  @taxpayer_information_xml ||= @xml['infAdic/infCpl']
end
title() click to toggle source
# File lib/br_danfe/mdfe_lib/notes.rb, line 19
def title
  title = 'Observações'

  @pdf.move_down 20
  @pdf.bounding_box [0, @pdf.cursor], width: 278, height: 20 do
    @pdf.stroke_color GRAY_COLOR
    @pdf.stroke_horizontal_line(0, 526, at: 6)
    @pdf.text(title, size: 12, align: :left, style: :bold)
  end
end
y_position_next_pages() click to toggle source
# File lib/br_danfe/mdfe_lib/notes.rb, line 89
def y_position_next_pages
  600
end