br_danfe 0.6.1 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +25 -25
  3. data/lib/br_danfe/danfe.rb +52 -25
  4. data/lib/br_danfe/danfe_lib/det_body.rb +105 -46
  5. data/lib/br_danfe/danfe_lib/document.rb +3 -7
  6. data/lib/br_danfe/danfe_lib/emit_header.rb +36 -20
  7. data/lib/br_danfe/danfe_lib/infadic.rb +12 -12
  8. data/lib/br_danfe/danfe_lib/issqn.rb +19 -8
  9. data/lib/br_danfe/version.rb +1 -1
  10. data/spec/features/danfe_spec.rb +45 -0
  11. data/spec/fixtures/nfe/lib/det_body#render-csosn.pdf +1932 -332
  12. data/spec/fixtures/nfe/lib/det_body#render-cst.pdf +1182 -138
  13. data/spec/fixtures/nfe/lib/det_body#render-fci.pdf +809 -43
  14. data/spec/fixtures/nfe/lib/det_body#render-icms_st.pdf +809 -43
  15. data/spec/fixtures/nfe/lib/det_body#render-quantity_with_custom_precision.pdf +807 -41
  16. data/spec/fixtures/nfe/lib/det_body#render-three_pages.pdf +22414 -0
  17. data/spec/fixtures/nfe/lib/det_body#render-two_pages.pdf +21442 -0
  18. data/spec/fixtures/nfe/lib/det_body#render-unit_price_with_custom_precision.pdf +807 -41
  19. data/spec/fixtures/nfe/lib/det_body#render-with_infadprod.pdf +1012 -0
  20. data/spec/fixtures/nfe/lib/det_body#render-with_issqn.pdf +10124 -0
  21. data/spec/fixtures/nfe/lib/det_body#render-without_issqn.pdf +10124 -0
  22. data/spec/fixtures/nfe/lib/emit_header#render-second_page.pdf +792 -0
  23. data/spec/fixtures/nfe/lib/emit_header#render-with_logo.pdf +88 -8
  24. data/spec/fixtures/nfe/lib/emit_header#render-without_logo.pdf +85 -5
  25. data/spec/fixtures/nfe/lib/infadic#render-footer_information.pdf +111 -0
  26. data/spec/fixtures/nfe/lib/{issqn#render.pdf → issqn#render-with_issqn.pdf} +0 -0
  27. data/spec/fixtures/nfe/lib/issqn#render-with_one_issqn_value.pdf +129 -0
  28. data/spec/fixtures/nfe/lib/issqn#render-without_issqn.pdf +54 -0
  29. data/spec/fixtures/nfe/v2.00/custom_options.fixture.pdf +2190 -1067
  30. data/spec/fixtures/nfe/v2.00/nfe_simples_nacional.xml.fixture.pdf +2183 -1059
  31. data/spec/fixtures/nfe/v2.00/nfe_with_extra_volumes.xml.fixture.pdf +8803 -3208
  32. data/spec/fixtures/nfe/v2.00/nfe_with_fci.xml.fixture.pdf +1825 -1258
  33. data/spec/fixtures/nfe/v2.00/nfe_with_ns.xml.fixture.pdf +8609 -3014
  34. data/spec/fixtures/nfe/v2.00/nfe_without_ns.xml.fixture.pdf +2664 -1541
  35. data/spec/fixtures/nfe/v3.10/nfe_simples_nacional.xml.fixture.pdf +4701 -1909
  36. data/spec/fixtures/nfe/v3.10/with_footer.fixture.pdf +8660 -0
  37. data/spec/fixtures/nfe/v3.10/with_footer.xml +621 -0
  38. data/spec/fixtures/nfe/v3.10/with_issqn.fixture.pdf +8646 -0
  39. data/spec/fixtures/nfe/v3.10/with_issqn.xml +621 -0
  40. data/spec/fixtures/nfe/v3.10/with_three_pages.fixture.pdf +25420 -0
  41. data/spec/fixtures/nfe/v3.10/with_three_pages.xml +1281 -0
  42. data/spec/fixtures/nfe/v3.10/withot_issqn.fixture.pdf +10338 -0
  43. data/spec/fixtures/nfe/v3.10/withot_issqn.xml +688 -0
  44. data/spec/lib/danfe_lib/det_body_spec.rb +350 -264
  45. data/spec/lib/danfe_lib/emit_header_spec.rb +42 -18
  46. data/spec/lib/danfe_lib/issqn_spec.rb +39 -7
  47. metadata +38 -14
  48. data/lib/br_danfe/danfe_lib/det_header.rb +0 -40
  49. data/lib/br_danfe/danfe_lib/emit.rb +0 -23
  50. data/spec/fixtures/nfe/lib/det_header#render.pdf +0 -207
  51. data/spec/fixtures/nfe/lib/emit#render.pdf +0 -143
  52. data/spec/lib/danfe_lib/det_header_spec.rb +0 -26
  53. data/spec/lib/danfe_lib/emit_spec.rb +0 -60
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f1033989799c07866763f69b6a90e5ab582e7f84
4
- data.tar.gz: f7d4bf7dbdfb38cb263d6975d13c436fda9c4fd5
3
+ metadata.gz: 276ea31f2d3b21b2183aa5ea35e67f639822f0b1
4
+ data.tar.gz: 4cdfea1190a2dba3b7525e91c04dcb6273be0bf6
5
5
  SHA512:
6
- metadata.gz: 0224b05d141117d8f5a03aebeee1371b31f31a6ecd3789abff021d5f82aa98adb254d2261d745ff609a1595749a9b17e560443dab8cedb8ac950e0950e983d81
7
- data.tar.gz: 8943a9c5e02e9847f30860b6e8a840e48b3c73b3d471767c1298946beae9845d799296323a8069a05a9e2e7cb3540c874dc7db816ab1ab79d04f4ef7e80a4f74
6
+ metadata.gz: b6a5b46f1680a691414ed2145be1ee559a5f42e2f51eafb4fefc3683bd6f67df9eb991ab403cc21afc013290f8c01bb4f64afeeb91af08fe732c1494ba4641fe
7
+ data.tar.gz: 8e800c08ee1eb190f98aae50ba10d2e5c854cc85a8e3ee7f516af7d15e5e2f3c7c927b5cefc9e4b59486d2619b6b260dee90293e81bbcfca5a2abe6a22d37123
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- br_danfe (0.6.1)
4
+ br_danfe (0.7.0)
5
5
  barby (= 0.5.1)
6
6
  br_documents (>= 0.0.8)
7
7
  i18n
@@ -12,33 +12,33 @@ PATH
12
12
  GEM
13
13
  remote: https://rubygems.org/
14
14
  specs:
15
- activemodel (5.0.1)
16
- activesupport (= 5.0.1)
17
- activesupport (5.0.1)
15
+ activemodel (5.1.1)
16
+ activesupport (= 5.1.1)
17
+ activesupport (5.1.1)
18
18
  concurrent-ruby (~> 1.0, >= 1.0.2)
19
19
  i18n (~> 0.7)
20
20
  minitest (~> 5.1)
21
21
  tzinfo (~> 1.1)
22
22
  barby (0.5.1)
23
- br_documents (0.0.12)
23
+ br_documents (0.0.13)
24
24
  activemodel (>= 4.0.0)
25
25
  i18n (>= 0.6.5)
26
26
  byebug (3.5.1)
27
27
  columnize (~> 0.8)
28
28
  debugger-linecache (~> 1.2)
29
29
  slop (~> 3.6)
30
- codeclimate-test-reporter (1.0.5)
31
- simplecov
30
+ codeclimate-test-reporter (1.0.8)
31
+ simplecov (<= 0.13)
32
32
  columnize (0.9.0)
33
- concurrent-ruby (1.0.4)
33
+ concurrent-ruby (1.0.5)
34
34
  debugger-linecache (1.2.0)
35
35
  diff-lcs (1.3)
36
36
  docile (1.1.5)
37
- i18n (0.8.0)
37
+ i18n (0.8.1)
38
38
  json (1.8.6)
39
39
  mini_portile2 (2.1.0)
40
- minitest (5.10.1)
41
- nokogiri (1.7.0.1)
40
+ minitest (5.10.2)
41
+ nokogiri (1.7.2)
42
42
  mini_portile2 (~> 2.1.0)
43
43
  pdf-core (0.6.1)
44
44
  prawn (2.1.0)
@@ -47,28 +47,28 @@ GEM
47
47
  prawn-table (0.2.2)
48
48
  prawn (>= 1.3.0, < 3.0.0)
49
49
  rake (12.0.0)
50
- rspec (3.5.0)
51
- rspec-core (~> 3.5.0)
52
- rspec-expectations (~> 3.5.0)
53
- rspec-mocks (~> 3.5.0)
54
- rspec-core (3.5.4)
55
- rspec-support (~> 3.5.0)
56
- rspec-expectations (3.5.0)
50
+ rspec (3.6.0)
51
+ rspec-core (~> 3.6.0)
52
+ rspec-expectations (~> 3.6.0)
53
+ rspec-mocks (~> 3.6.0)
54
+ rspec-core (3.6.0)
55
+ rspec-support (~> 3.6.0)
56
+ rspec-expectations (3.6.0)
57
57
  diff-lcs (>= 1.2.0, < 2.0)
58
- rspec-support (~> 3.5.0)
59
- rspec-mocks (3.5.0)
58
+ rspec-support (~> 3.6.0)
59
+ rspec-mocks (3.6.0)
60
60
  diff-lcs (>= 1.2.0, < 2.0)
61
- rspec-support (~> 3.5.0)
62
- rspec-support (3.5.0)
61
+ rspec-support (~> 3.6.0)
62
+ rspec-support (3.6.0)
63
63
  simplecov (0.11.1)
64
64
  docile (~> 1.1.0)
65
65
  json (~> 1.8)
66
66
  simplecov-html (~> 0.10.0)
67
- simplecov-html (0.10.0)
67
+ simplecov-html (0.10.1)
68
68
  slop (3.6.0)
69
- thread_safe (0.3.5)
69
+ thread_safe (0.3.6)
70
70
  ttfunk (1.4.0)
71
- tzinfo (1.2.2)
71
+ tzinfo (1.2.3)
72
72
  thread_safe (~> 0.1)
73
73
 
74
74
  PLATFORMS
@@ -10,17 +10,18 @@ module BrDanfe
10
10
  create_watermark
11
11
  end
12
12
 
13
- def save_pdf(filename)
14
- generate
13
+ def save_pdf(filename, footer_info = "")
14
+ generate footer_info
15
15
  @pdf.render_file filename
16
16
  end
17
17
 
18
- def render_pdf
19
- generate
18
+ def render_pdf(footer_info = "")
19
+ generate footer_info
20
20
  @pdf.render
21
21
  end
22
22
 
23
23
  private
24
+
24
25
  def create_watermark
25
26
  @pdf.create_stamp("has_no_fiscal_value") do
26
27
  @pdf.fill_color "7d7d7d"
@@ -36,35 +37,61 @@ module BrDanfe
36
37
  end
37
38
  end
38
39
 
39
- def generate
40
- @pdf.stamp("has_no_fiscal_value") if DanfeLib::Helper.has_no_fiscal_value?(@xml)
41
-
42
- @pdf.repeat(:all) { repeat_on_each_page }
43
-
44
- DanfeLib::DetBody.new(@pdf, @xml).render
45
-
46
- @pdf.page_count.times do |i|
47
- @pdf.go_to_page(i + 1)
48
- @pdf.ibox 1.00, 2.08, 8.21, 6.96, "",
49
- I18n.t("danfe.others.page", current: i+1, total: @pdf.page_count),
50
- { size: 8, align: :center, valign: :center, border: 0, style: :bold }
51
- end
52
-
40
+ def generate(footer_info)
41
+ render_on_first_page
42
+ render_on_each_page footer_info
53
43
  @pdf
54
44
  end
55
45
 
56
- def repeat_on_each_page
46
+ def render_on_first_page
57
47
  DanfeLib::Ticket.new(@pdf, @xml).render
58
- DanfeLib::EmitHeader.new(@pdf, @xml, @options.logo, @options.logo_dimensions).render
59
- DanfeLib::Emit.new(@pdf, @xml).render
60
48
  DanfeLib::Dest.new(@pdf, @xml).render
61
49
  DanfeLib::Dup.new(@pdf, @xml).render
62
50
  DanfeLib::Icmstot.new(@pdf, @xml).render
63
51
  DanfeLib::Transp.new(@pdf, @xml).render
64
- nVol = DanfeLib::Vol.new(@pdf, @xml).render
65
- DanfeLib::DetHeader.new(@pdf).render
66
- DanfeLib::Issqn.new(@pdf, @xml).render
67
- DanfeLib::Infadic.new(@pdf, @xml).render(nVol)
52
+ n_vol = DanfeLib::Vol.new(@pdf, @xml).render
53
+ has_issqn = DanfeLib::Issqn.new(@pdf, @xml).render
54
+ DanfeLib::Infadic.new(@pdf, @xml).render(n_vol)
55
+
56
+ render_products has_issqn
57
+ end
58
+
59
+ def render_products(has_issqn)
60
+ DanfeLib::DetBody.new(@pdf, @xml).render(has_issqn)
61
+ end
62
+
63
+ def render_on_each_page(footer_info)
64
+ emitter = DanfeLib::EmitHeader.new(@pdf, @xml, @options.logo, @options.logo_dimensions)
65
+
66
+ @pdf.page_count.times do |i|
67
+ page = i + 1
68
+ position = page === 1 ? 3.96 : 1.85
69
+ repeated_information page, position, emitter, footer_info
70
+ end
71
+ end
72
+
73
+ def repeated_information(page, y_position, emitter, footer_info)
74
+ @pdf.go_to_page(page)
75
+
76
+ emitter.render page, y_position
77
+ render_product_table_title page
78
+ render_footer_information footer_info
79
+ render_no_fiscal_value
80
+ end
81
+
82
+ def render_product_table_title(page)
83
+ y_position = page == 1 ? 18.91 : 7.40
84
+ @pdf.ititle 0.42, 10.00, 0.75, y_position, "det.title"
85
+ end
86
+
87
+ def render_footer_information(footer_info)
88
+ if footer_info.present?
89
+ @pdf.ibox 0.35, 12.45, 0.75, 30.21, "", footer_info, { size: 5, border: 0 }
90
+ end
91
+ end
92
+
93
+ def render_no_fiscal_value
94
+ @pdf.stamp("has_no_fiscal_value") if DanfeLib::Helper.has_no_fiscal_value?(@xml)
68
95
  end
69
96
  end
70
97
  end
@@ -6,70 +6,129 @@ module BrDanfe
6
6
  @xml = xml
7
7
  end
8
8
 
9
- def render
10
- options = {
11
- column_widths: column_widths,
12
- cell_style: { padding: 2, border_width: 0 }
13
- }
9
+ def render(has_issqn)
10
+ table_height_on_first_page = table_height_on_first_page has_issqn
11
+ first_table = create_table
12
+ next_table = create_table
14
13
 
15
- @pdf.font_size(6.5) do
16
- @pdf.bounding_box [0.75.cm, Helper.invert(19.59.cm)], width: 19.57.cm, height: 6.07.cm do
17
- @pdf.table products, options do |table|
18
- table.column(6..13).style(align: :right)
19
- table.column(0..13).border_width = 0.3
20
- table.column(0..13).border_lines = [:solid]
21
- table.column(0..13).borders = [:bottom]
22
- end
23
- end
24
- end
14
+ fill_tables first_table, next_table, table_height_on_first_page
15
+ render_tables first_table, next_table, table_height_on_first_page
25
16
  end
26
17
 
27
18
  private
28
19
 
20
+ def table_height_on_first_page(has_issqn)
21
+ has_issqn ? 6.35.cm : 7.72.cm
22
+ end
23
+
24
+ def create_table
25
+ [create_header]
26
+ end
27
+
28
+ def create_header
29
+ header = [[
30
+ header_column("prod.cProd"), header_column("prod.xProd"), header_column("prod.NCM"),
31
+ header_column("ICMS.CST"), header_column("prod.CFOP"), header_column("prod.uCom"),
32
+ header_column("prod.qCom"), header_column("prod.vUnCom"), header_column("prod.vProd"),
33
+ header_column("ICMS.vBC"), header_column("ICMS.vICMS"), header_column("IPI.vIPI"),
34
+ header_column("ICMS.pICMS"), header_column("IPI.pIPI")
35
+ ]]
36
+ @pdf.make_table(header, options)
37
+ end
38
+
39
+ def header_column(title)
40
+ { content: I18n.t("danfe.det.#{title}"), align: :left, size: 6, valign: :top }
41
+ end
42
+
43
+ def options
44
+ { column_widths: column_widths, cell_style: { padding: 2, border_width: 0.3 } }
45
+ end
46
+
47
+ def column_widths
48
+ {
49
+ 0 => 1.60.cm, 1 => 6.10.cm, 2 => 1.05.cm, 3 => 0.60.cm, 4 => 0.70.cm, 5 => 1.05.cm, 6 => 1.20.cm,
50
+ 7 => 1.20.cm, 8 => 1.20.cm, 9 => 1.20.cm, 10 => 1.00.cm, 11 => 1.00.cm, 12 => 0.90.cm, 13 => 0.76.cm
51
+ }
52
+ end
53
+
54
+ def fill_tables(first_table, next_table, first_table_height)
55
+ total_height = first_table.first.height
56
+
57
+ products.each do |product|
58
+ row = create_row product
59
+ total_height += row.height
60
+ total_height <= first_table_height ? first_table << row : next_table << row
61
+ end
62
+ end
63
+
29
64
  def products
30
65
  @xml.collect("xmlns", "det") { |det| product(det) }
31
66
  end
32
67
 
33
68
  def product(det)
34
69
  [
35
- det.css("prod/cProd").text,
36
- Xprod.new(det).render,
37
- det.css("prod/NCM").text,
38
- Cst.to_danfe(det),
39
- det.css("prod/CFOP").text,
40
- det.css("prod/uCom").text,
41
- numerify(det, "prod/qCom"),
42
- numerify(det, "prod/vUnCom"),
43
- numerify(det, "prod/vProd"),
44
- numerify(det, "ICMS/*/vBC"),
45
- numerify(det, "ICMS/*/vICMS"),
46
- numerify(det, "IPI/*/vIPI"),
47
- numerify(det, "ICMS/*/pICMS"),
48
- numerify(det, "IPI/*/pIPI")
70
+ cell_text(det.css("prod/cProd").text),
71
+ cell_text(Xprod.new(det).render),
72
+ cell_text(det.css("prod/NCM").text),
73
+ cell_text(Cst.to_danfe(det)),
74
+ cell_text(det.css("prod/CFOP").text),
75
+ cell_text(det.css("prod/uCom").text),
76
+ cell_number(numerify(det, "prod/qCom")),
77
+ cell_number(numerify(det, "prod/vUnCom")),
78
+ cell_number(numerify(det, "prod/vProd")),
79
+ cell_number(numerify(det, "ICMS/*/vBC")),
80
+ cell_number(numerify(det, "ICMS/*/vICMS")),
81
+ cell_number(numerify(det, "IPI/*/vIPI")),
82
+ cell_number(numerify(det, "ICMS/*/pICMS")),
83
+ cell_number(numerify(det, "IPI/*/pIPI"))
49
84
  ]
50
85
  end
51
86
 
87
+ def cell_text(text, options = {})
88
+ cell = { content: text, border_lines: [:solid], size: 6.5 }
89
+ cell.merge!(options)
90
+ cell
91
+ end
92
+
93
+ def cell_number(text)
94
+ cell_text(text, { align: :right })
95
+ end
96
+
52
97
  def numerify(det, xpath)
53
98
  Helper.numerify(det.css("#{xpath}").text)
54
99
  end
55
100
 
56
- def column_widths
57
- {
58
- 0 => 1.60.cm,
59
- 1 => 6.10.cm,
60
- 2 => 1.05.cm,
61
- 3 => 0.60.cm,
62
- 4 => 0.70.cm,
63
- 5 => 1.05.cm,
64
- 6 => 1.20.cm,
65
- 7 => 1.20.cm,
66
- 8 => 1.20.cm,
67
- 9 => 1.20.cm,
68
- 10 => 1.00.cm,
69
- 11 => 1.00.cm,
70
- 12 => 0.90.cm,
71
- 13 => 0.76.cm
72
- }
101
+ def create_row(data)
102
+ @pdf.make_table([data], options)
103
+ end
104
+
105
+ def render_tables(first_table, next_table, first_table_height)
106
+ render_table first_table, table_position_on_first_page, first_table_height
107
+
108
+ table_with_only_header = 1
109
+ if next_table.size > table_with_only_header
110
+ @pdf.start_new_page
111
+ render_table next_table, table_position_on_next_pages, table_height_on_next_pages
112
+ end
113
+ end
114
+
115
+ def render_table(data, start_position, height)
116
+ @pdf.y = start_position
117
+ @pdf.bounding_box [0.75.cm, @pdf.cursor], width: 19.56.cm, height: height do
118
+ @pdf.table data.map{ |item| [item] }, { header: true }
119
+ end
120
+ end
121
+
122
+ def table_position_on_first_page
123
+ Helper.invert(18.07.cm)
124
+ end
125
+
126
+ def table_position_on_next_pages
127
+ Helper.invert(6.57.cm)
128
+ end
129
+
130
+ def table_height_on_next_pages
131
+ 22.58.cm
73
132
  end
74
133
  end
75
134
  end
@@ -77,23 +77,19 @@ module BrDanfe
77
77
  end
78
78
 
79
79
  def lnumeric(h, w, x, y, xml, xpath, options = {})
80
- i18n = xpath.gsub("/", ".");
80
+ i18n = xpath.tr("/", ".")
81
81
  data = xml[xpath]
82
82
 
83
83
  inumeric(h, w, x, y, i18n, data, options)
84
84
  end
85
85
 
86
86
  def inumeric(h, w, x, y, i18n = "", data = "", options = {})
87
- label = ""
88
- label = I18n.t("danfe.#{i18n}") if i18n != ""
89
-
87
+ label = i18n != "" ? I18n.t("danfe.#{i18n}") : ""
90
88
  numeric [x.cm, Helper.invert(y.cm)], w.cm, h.cm, label, data, options
91
89
  end
92
90
 
93
91
  def i18n_lbox(h, w, x, y, i18n = "", info = "", options = {})
94
- label = ""
95
- label = I18n.t("danfe.#{i18n}") if i18n != ""
96
-
92
+ label = i18n != "" ? I18n.t("danfe.#{i18n}") : ""
97
93
  ibox h, w, x, y, label, info, options
98
94
  end
99
95
 
@@ -8,19 +8,20 @@ module BrDanfe
8
8
  @logo_dimensions = logo_dimensions
9
9
  end
10
10
 
11
- def render
11
+ def render(page, y_position)
12
+ @y_position = y_position
12
13
  company_box
13
- danfe_box
14
+ danfe_box page
14
15
  access_key_box
15
16
  sefaz_box
17
+ render_emit y_position
16
18
  end
17
19
 
18
20
  private
19
21
 
20
22
  def company_box
21
- @pdf.ibox 3.92, 7.46, 0.75, 3.96
22
-
23
- @pdf.ibox 3.92, 7.46, 0.75, 3.96, "", @xml["emit/xNome"],
23
+ @pdf.ibox 3.92, 7.46, 0.75, @y_position
24
+ @pdf.ibox 3.92, 7.46, 0.75, @y_position, "", @xml["emit/xNome"],
24
25
  { size: 12, align: :center, border: 0, style: :bold }
25
26
 
26
27
  address_company
@@ -28,9 +29,9 @@ module BrDanfe
28
29
 
29
30
  def address_company
30
31
  if @logo.blank?
31
- @pdf.ibox 3.92, 7.46, 1.25, 5.42, "", address, { align: :left, border: 0 }
32
+ @pdf.ibox 3.92, 7.46, 1.25, @y_position + 1.46, "", address, { align: :left, border: 0 }
32
33
  else
33
- @pdf.ibox 3.92, 7.46, 3.60, 5.42, "", address, { size: 8, align: :left, border: 0 }
34
+ @pdf.ibox 3.92, 7.46, 3.60, @y_position + 1.46, "", address, { size: 8, align: :left, border: 0 }
34
35
  logo
35
36
  end
36
37
  end
@@ -40,7 +41,6 @@ module BrDanfe
40
41
  formatted += @xml["enderEmit/xBairro"] + " - " + cep + "\n"
41
42
  formatted += @xml["enderEmit/xMun"] + "/" + @xml["enderEmit/UF"] + "\n"
42
43
  formatted += phone + " " + @xml["enderEmit/email"]
43
-
44
44
  formatted
45
45
  end
46
46
 
@@ -56,40 +56,56 @@ module BrDanfe
56
56
  bounding_box_size = 80
57
57
  logo_options = BrDanfe::DanfeLib::LogoOptions.new(bounding_box_size, @logo_dimensions).options
58
58
 
59
- @pdf.move_down 105
60
- @pdf.bounding_box([0.83.cm, @pdf.cursor], width: bounding_box_size, height: bounding_box_size) do
59
+ @pdf.bounding_box([0.83.cm, Helper.invert(@y_position.cm + 1.02.cm)], width: bounding_box_size, height: bounding_box_size) do
61
60
  @pdf.image @logo, logo_options
62
61
  end
63
62
  end
64
63
 
65
- def danfe_box
66
- @pdf.ibox 3.92, 2.08, 8.21, 3.96
64
+ def danfe_box(page)
65
+ @pdf.ibox 3.92, 2.08, 8.21, @y_position
67
66
 
68
- @pdf.ibox 0.60, 2.08, 8.21, 3.96, "", "DANFE",
67
+ @pdf.ibox 0.60, 2.08, 8.21, @y_position, "", "DANFE",
69
68
  { size: 12, align: :center, border: 0, style: :bold }
70
69
 
71
- @pdf.ibox 1.20, 2.08, 8.21, 4.56, "", I18n.t("danfe.others.danfe"),
70
+ @pdf.ibox 1.20, 2.08, 8.21, @y_position + 0.60, "", I18n.t("danfe.others.danfe"),
72
71
  { size: 8, align: :center, border: 0 }
73
72
 
74
- @pdf.ibox 0.60, 2.08, 8.21, 5.76, "", "#{@xml['ide/tpNF']} - " + (@xml["ide/tpNF"] == "0" ? I18n.t("danfe.ide.tpNF.entry") : I18n.t("danfe.ide.tpNF.departure")),
73
+ @pdf.ibox 0.60, 2.08, 8.21, @y_position + 1.80, "", "#{@xml['ide/tpNF']} - " + (@xml["ide/tpNF"] == "0" ? I18n.t("danfe.ide.tpNF.entry") : I18n.t("danfe.ide.tpNF.departure")),
75
74
  { size: 8, align: :center, border: 0 }
76
75
 
77
- @pdf.ibox 1.00, 2.08, 8.21, 6.36, "",
76
+ @pdf.ibox 1.00, 2.08, 8.21, @y_position + 2.40, "",
78
77
  I18n.t("danfe.ide.document", nNF: @xml["ide/nNF"], serie: @xml["ide/serie"]),
79
78
  { size: 8, align: :center, valign: :center, border: 0, style: :bold }
79
+
80
+ @pdf.ibox 1.00, 2.08, 8.21, @y_position + 3.00, "",
81
+ I18n.t("danfe.others.page", current: page, total: @pdf.page_count),
82
+ { size: 8, align: :center, valign: :center, border: 0, style: :bold }
80
83
  end
81
84
 
82
85
  def access_key_box
83
- @pdf.ibox 2.22, 10.02, 10.29, 3.96
84
- @pdf.ibarcode 1.50, 8.00, 10.4010, 5.86, @xml["chNFe"]
85
- @pdf.ibox 0.85, 10.02, 10.29, 6.18, I18n.t("danfe.chNFe"), @xml["chNFe"].gsub(/(\d)(?=(\d\d\d\d)+(?!\d))/, "\\1 "),
86
+ @pdf.ibox 2.22, 10.02, 10.29, @y_position
87
+ @pdf.ibarcode 1.50, 8.00, 10.4010, @y_position + 1.90, @xml["chNFe"]
88
+ @pdf.ibox 0.85, 10.02, 10.29, @y_position + 2.22, I18n.t("danfe.chNFe"), @xml["chNFe"].gsub(/(\d)(?=(\d\d\d\d)+(?!\d))/, "\\1 "),
86
89
  { style: :bold, align: :center }
87
90
  end
88
91
 
89
92
  def sefaz_box
90
- @pdf.ibox 0.85, 10.02, 10.29, 7.03, "", I18n.t("danfe.others.sefaz"),
93
+ @pdf.ibox 0.85, 10.02, 10.29, @y_position + 3.07, "", I18n.t("danfe.others.sefaz"),
91
94
  { align: :center, size: 8 }
92
95
  end
96
+
97
+ def render_emit(y_position)
98
+ y_first_line = y_position + 3.92
99
+ y_second_line = y_first_line + LINE_HEIGHT
100
+
101
+ @pdf.lbox LINE_HEIGHT, 10.04, 0.75, y_first_line, @xml, "ide/natOp"
102
+ @pdf.ibox LINE_HEIGHT, 9.52, 10.79, y_first_line, I18n.t("danfe.infProt"),
103
+ "#{@xml["infProt/nProt"]} #{Helper.format_datetime(@xml["infProt/dhRecbto"])}", { align: :center }
104
+
105
+ @pdf.lie LINE_HEIGHT, 6.36, 0.75, y_second_line, @xml, "enderEmit/UF", "emit/IE"
106
+ @pdf.lie LINE_HEIGHT, 6.86, 7.11, y_second_line, @xml, "enderDest/UF", "emit/IEST"
107
+ @pdf.lcnpj LINE_HEIGHT, 6.34, 13.97, y_second_line, @xml, "emit/CNPJ"
108
+ end
93
109
  end
94
110
  end
95
111
  end
@@ -1,36 +1,36 @@
1
1
  module BrDanfe
2
2
  module DanfeLib
3
3
  class Infadic
4
- Y = 27.04 + SPACE_BETWEEN_GROUPS
4
+ Y_POSITION = 27.04 + SPACE_BETWEEN_GROUPS
5
5
 
6
6
  def initialize(pdf, xml)
7
7
  @pdf = pdf
8
8
  @xml = xml
9
9
 
10
- @ltitle = Y - 0.41
11
- @l1 = Y
10
+ @title = Y_POSITION - 0.41
11
+ @y_position = Y_POSITION
12
12
  end
13
13
 
14
- def render(nVol)
15
- @pdf.ititle 0.42, 10.00, 0.75, @ltitle, "infAdic.title"
14
+ def render(n_vol)
15
+ @pdf.ititle 0.42, 10.00, 0.75, @title, "infAdic.title"
16
16
 
17
- if nVol > 1
17
+ if n_vol > 1
18
18
  render_extra_volumes
19
19
  elsif difal?
20
20
  render_difal
21
21
  else
22
- @pdf.ibox 2.65, 12.45, 0.75, @l1, I18n.t("danfe.infAdic.infCpl"), @xml["infAdic/infCpl"], { size: 6, valign: :top }
22
+ @pdf.ibox 2.65, 12.45, 0.75, @y_position, I18n.t("danfe.infAdic.infCpl"), @xml["infAdic/infCpl"], { size: 6, valign: :top }
23
23
  end
24
24
 
25
- @pdf.ibox 2.65, 7.15, 13.20, @l1, I18n.t("danfe.infAdic.reserved")
25
+ @pdf.ibox 2.65, 7.15, 13.20, @y_position, I18n.t("danfe.infAdic.reserved")
26
26
  end
27
27
 
28
28
  private
29
29
 
30
30
  def render_extra_volumes
31
- @pdf.ibox 2.65, 12.45, 0.75, @l1, I18n.t("danfe.infAdic.infCpl"), "", { size: 8, valign: :top }
31
+ @pdf.ibox 2.65, 12.45, 0.75, @y_position, I18n.t("danfe.infAdic.infCpl"), "", { size: 8, valign: :top }
32
32
 
33
- y = Y + 0.20
33
+ y = Y_POSITION + 0.20
34
34
 
35
35
  if difal?
36
36
  @pdf.ibox 1.65, 12.45, 0.75, y, "", difal_content, { size: 5, valign: :top, border: 0 }
@@ -110,9 +110,9 @@ module BrDanfe
110
110
  end
111
111
 
112
112
  def render_difal
113
- @pdf.ibox 2.65, 12.45, 0.75, @l1, I18n.t("danfe.infAdic.infCpl"), "", { size: 8, valign: :top }
113
+ @pdf.ibox 2.65, 12.45, 0.75, @y_position, I18n.t("danfe.infAdic.infCpl"), "", { size: 8, valign: :top }
114
114
 
115
- y = Y + 0.20
115
+ y = Y_POSITION + 0.20
116
116
  @pdf.ibox 1.65, 12.45, 0.75, y, "", difal_content, { size: 5, valign: :top, border: 0 }
117
117
 
118
118
  y += 0.10
@@ -1,23 +1,34 @@
1
1
  module BrDanfe
2
2
  module DanfeLib
3
3
  class Issqn
4
- Y = 25.72 + SPACE_BETWEEN_GROUPS
4
+ Y_POSITION = 25.72 + SPACE_BETWEEN_GROUPS
5
5
 
6
6
  def initialize(pdf, xml)
7
7
  @pdf = pdf
8
8
  @xml = xml
9
9
 
10
- @ltitle = Y - 0.42
11
- @l1 = Y
10
+ @title = Y_POSITION - 0.42
11
+ @y_position = Y_POSITION
12
+
13
+ @serv = "total/ISSQNtot/vServ"
14
+ @bc = "total/ISSQNtot/vBC"
15
+ @iss = "total/ISSQNtot/vISS"
12
16
  end
13
17
 
14
18
  def render
15
- @pdf.ititle 0.42, 10.00, 0.75, @ltitle, "issqn.title"
19
+ if can_render?
20
+ @pdf.ititle 0.42, 10.00, 0.75, @title, "issqn.title"
21
+ @pdf.lbox LINE_HEIGHT, 4.64, 0.75, @y_position, @xml, "emit/IM"
22
+ @pdf.lnumeric LINE_HEIGHT, 5.14, 5.39, @y_position, @xml, @serv
23
+ @pdf.lnumeric LINE_HEIGHT, 5.14, 10.53, @y_position, @xml, @bc
24
+ @pdf.lnumeric LINE_HEIGHT, 4.64, 15.67, @y_position, @xml, @iss
25
+ end
26
+ end
27
+
28
+ private
16
29
 
17
- @pdf.lbox LINE_HEIGHT, 4.64, 0.75, @l1, @xml, "emit/IM"
18
- @pdf.lnumeric LINE_HEIGHT, 5.14, 5.39, @l1, @xml, "total/ISSQNtot/vServ"
19
- @pdf.lnumeric LINE_HEIGHT, 5.14, 10.53, @l1, @xml, "total/ISSQNtot/vBC"
20
- @pdf.lnumeric LINE_HEIGHT, 4.64, 15.67, @l1, @xml, "total/ISSQNtot/vISS"
30
+ def can_render?
31
+ (@xml[@serv].to_i > 0) || (@xml[@bc].to_i > 0) || (@xml[@iss].to_i > 0)
21
32
  end
22
33
  end
23
34
  end
@@ -1,3 +1,3 @@
1
1
  module BrDanfe
2
- VERSION = "0.6.1"
2
+ VERSION = "0.7.0"
3
3
  end