Sha256: 4ea0fd4c6755575bcbd852015b2d52459ac48eeda337f4a45657d0ae5baf0ffc

Contents?: true

Size: 1.85 KB

Versions: 2

Compression:

Stored size: 1.85 KB

Contents

module BrDanfe
  class Danfe
    attr_reader :options

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

      create_watermark
    end

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

    def render_pdf
      generate
      @pdf.render
    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 DanfeLib::Helper.has_no_fiscal_value?(@xml)

      @pdf.repeat(:all) { repeat_on_each_page }

      DanfeLib::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
      DanfeLib::Ticket.new(@pdf, @xml).render
      DanfeLib::EmitHeader.new(@pdf, @xml, @options.logo_path).render
      DanfeLib::Emit.new(@pdf, @xml).render
      DanfeLib::Dest.new(@pdf, @xml).render
      DanfeLib::Dup.new(@pdf, @xml).render
      DanfeLib::Icmstot.new(@pdf, @xml).render
      DanfeLib::Transp.new(@pdf, @xml).render
      nVol = DanfeLib::Vol.new(@pdf, @xml).render
      DanfeLib::DetHeader.new(@pdf).render
      DanfeLib::Issqn.new(@pdf, @xml).render
      DanfeLib::Infadic.new(@pdf, @xml).render(nVol)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
br_danfe-0.2.1 lib/br_danfe/danfe.rb
br_danfe-0.2.0 lib/br_danfe/danfe.rb