Sha256: 821012e81831e92a4dc2bab73046e6b38f6bd1bebd867e172087ad85ae7f26f7

Contents?: true

Size: 1.36 KB

Versions: 17

Compression:

Stored size: 1.36 KB

Contents

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

      def generate
        generate_title
        nfe_quantity
        cte_quantity
        total_weight
      end

      private

      def generate_title
        title = 'Modelo Rodoviário de Carga'

        @pdf.text_box(title, size: 12, align: :left, style: :bold, at: [0, 600])
      end

      def nfe_quantity
        generate_box('QTD. NFe', @xml['qNFe'], 65)
      end

      def generate_box(title, text, x_position, width = 60)
        @pdf.move_cursor_to 580

        @pdf.stroke do
          @pdf.fill_color LIGHT_GRAY_COLOR
          @pdf.fill_rectangle([x_position, @pdf.cursor], width, 35)
          @pdf.fill_color BLACK_COLOR
        end

        @pdf.bounding_box([x_position, @pdf.cursor], width: width, height: 35) do
          @pdf.move_down 5
          @pdf.text_box(title, size: 10, at: [3, @pdf.cursor])
          @pdf.move_down 15
          @pdf.text_box(text, size: 12, at: [3, @pdf.cursor])
        end
      end

      def cte_quantity
        generate_box('QTD. CTe', '', 0)
      end

      def total_weight
        weight = ActiveSupport::NumberHelper.number_to_rounded(@xml['qCarga'], precision: 2)
        weight = Helper.numerify(weight)

        generate_box('Peso total (Kg)', weight, 130, 90)
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
br_danfe-1.2.1 lib/br_danfe/mdfe_lib/totalizer.rb
br_danfe-1.2.0 lib/br_danfe/mdfe_lib/totalizer.rb
br_danfe-1.1.0 lib/br_danfe/mdfe_lib/totalizer.rb
br_danfe-1.0.0 lib/br_danfe/mdfe_lib/totalizer.rb
br_danfe-0.20.0 lib/br_danfe/mdfe_lib/totalizer.rb
br_danfe-0.19.0 lib/br_danfe/mdfe_lib/totalizer.rb
br_danfe-0.18.0 lib/br_danfe/mdfe_lib/totalizer.rb
br_danfe-0.17.8 lib/br_danfe/mdfe_lib/totalizer.rb
br_danfe-0.17.7 lib/br_danfe/mdfe_lib/totalizer.rb
br_danfe-0.17.6 lib/br_danfe/mdfe_lib/totalizer.rb
br_danfe-0.17.5 lib/br_danfe/mdfe_lib/totalizer.rb
br_danfe-0.17.4 lib/br_danfe/mdfe_lib/totalizer.rb
br_danfe-0.17.3 lib/br_danfe/mdfe_lib/totalizer.rb
br_danfe-0.17.2 lib/br_danfe/mdfe_lib/totalizer.rb
br_danfe-0.17.1 lib/br_danfe/mdfe_lib/totalizer.rb
br_danfe-0.17.0 lib/br_danfe/mdfe_lib/totalizer.rb
br_danfe-0.16.0 lib/br_danfe/mdfe_lib/totalizer.rb