Sha256: a1b552a7a8b74adb714371aabdbb177ba86d45467f0e7760f5f68acb4e3d91b6

Contents?: true

Size: 1.59 KB

Versions: 1

Compression:

Stored size: 1.59 KB

Contents

module BrDanfe
  class Danfe
    attr_reader :options

    def initialize(xml)
      @xml = XML.new(xml)
      @pdf = Document.new
      @options = Options.new

      create_watermark
    end

    def save_pdf(filename)
      generate
      @pdf.render_file filename
    end

    private
    def create_watermark
      @pdf.create_stamp("has_no_fiscal_value") do
        @pdf.fill_color "7d7d7d"
        @pdf.text_box I18n.t("danfe.others.has_no_fiscal_value"),
          size: 2.2.cm,
          width: @pdf.bounds.width,
          height: @pdf.bounds.height,
          align: :center,
          valign: :center,
          at: [0, @pdf.bounds.height],
          rotate: 45,
          rotate_around: :center
      end
    end

    def generate
      @pdf.stamp("has_no_fiscal_value") if Helper.has_no_fiscal_value?(@xml)

      @pdf.repeat(:all) { repeat_on_each_page }

      DetBody.new(@pdf, @xml).render

      @pdf.page_count.times do |i|
        @pdf.go_to_page(i + 1)
        @pdf.ibox 1.00, 2.08, 8.71, 5.54, "",
          I18n.t("danfe.others.page", current: i+1, total: @pdf.page_count),
          { size: 8, align: :center, valign: :center, border: 0, style: :bold }
      end

      @pdf
    end

    def repeat_on_each_page
      Ticket.render(@pdf, @xml)
      Emit.new(@pdf, @xml, @options.logo_path).render
      Dest.new(@pdf, @xml).render
      Dup.new(@pdf, @xml).render
      Icmstot.render(@pdf, @xml)
      Transp.render(@pdf, @xml)
      nVol = Vol.new(@pdf, @xml).render
      DetHeader.new(@pdf, @xml).render
      Issqn.render(@pdf, @xml)
      Infadic.new(@pdf, @xml).render(nVol)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
br_danfe-0.0.2 lib/br_danfe/danfe.rb