Sha256: 36b42d8b7741ef50a1c1749b1b31dd143e7750ec9616b29699c8fb31a90d451f

Contents?: true

Size: 1.56 KB

Versions: 3

Compression:

Stored size: 1.56 KB

Contents

module BrDanfe
  class DetBody
    def initialize(pdf, xml)
      @pdf = pdf
      @xml = xml
    end

    def render
      @pdf.font_size(6) do
        @pdf.itable 6.37, 21.50, 0.25, 18.17,
          products,
          column_widths: column_widths,
          cell_style: {padding: 2, border_width: 0} do |table|
            table.column(6..13).style(align: :right)
            table.column(0..13).border_width = 1
            table.column(0..13).borders = [:bottom]
          end
      end
    end

    private
    def products
      @xml.collect("xmlns", "det") { |det| product(det) }
    end

    def product(det)
      [
        det.css("prod/cProd").text,
        Xprod.new(det).render,
        det.css("prod/NCM").text,
        Cst.to_danfe(det),
        det.css("prod/CFOP").text,
        det.css("prod/uCom").text,
        numerify(det, "prod/qCom"),
        numerify(det, "prod/vUnCom"),
        numerify(det, "prod/vProd"),
        numerify(det, "ICMS/*/vBC"),
        numerify(det, "ICMS/*/vICMS"),
        numerify(det, "IPI/*/vIPI"),
        numerify(det, "ICMS/*/pICMS"),
        numerify(det, "IPI/*/pIPI")
      ]
    end

    def numerify(det, xpath)
      Helper.numerify(det.css("#{xpath}").text)
    end

    def column_widths
      {
        0 => 2.00.cm,
        1 => 4.90.cm,
        2 => 1.30.cm,
        3 => 0.80.cm,
        4 => 1.00.cm,
        5 => 1.00.cm,
        6 => 1.30.cm,
        7 => 1.50.cm,
        8 => 1.50.cm,
        9 => 1.50.cm,
        10 => 1.00.cm,
        11 => 1.00.cm,
        12 => 0.90.cm,
        13 => 0.86.cm
      }
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
br_danfe-0.0.4 lib/br_danfe/det_body.rb
br_danfe-0.0.3 lib/br_danfe/det_body.rb
br_danfe-0.0.2 lib/br_danfe/det_body.rb