br_danfe 0.14.0 → 0.15.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +35 -34
  3. data/README.md +16 -0
  4. data/br_danfe.gemspec +1 -1
  5. data/config/locales/pt-BR.yml +1 -0
  6. data/fonts/Tinos-LICENSE.txt +202 -0
  7. data/fonts/tinos.ttf +0 -0
  8. data/fonts/tinos_bold.ttf +0 -0
  9. data/fonts/tinos_bold_italic.ttf +0 -0
  10. data/fonts/tinos_italic.ttf +0 -0
  11. data/lib/br_danfe.rb +6 -0
  12. data/lib/br_danfe/cce_lib/document.rb +2 -2
  13. data/lib/br_danfe/danfe.rb +8 -5
  14. data/lib/br_danfe/danfe_lib/base.rb +2 -2
  15. data/lib/br_danfe/danfe_lib/nfce.rb +14 -12
  16. data/lib/br_danfe/danfe_lib/nfce_lib/document.rb +1 -1
  17. data/lib/br_danfe/danfe_lib/nfe.rb +39 -27
  18. data/lib/br_danfe/danfe_lib/nfe_lib/document.rb +3 -2
  19. data/lib/br_danfe/danfe_lib/nfe_lib/emit_header.rb +4 -4
  20. data/lib/br_danfe/danfe_lib/nfe_lib/issqn.rb +1 -1
  21. data/lib/br_danfe/danfe_lib/nfe_lib/xprod.rb +5 -5
  22. data/lib/br_danfe/document_builder.rb +16 -0
  23. data/lib/br_danfe/helper.rb +6 -0
  24. data/lib/br_danfe/version.rb +1 -1
  25. data/lib/prawn/font.rb +7 -0
  26. data/lib/prawn/font_metric_cache.rb +33 -0
  27. data/spec/br_danfe/danfe_lib/nfce_spec.rb +12 -1
  28. data/spec/br_danfe/danfe_lib/nfe_lib/emit_header_spec.rb +2 -2
  29. data/spec/br_danfe/danfe_lib/nfe_lib/infadic_spec.rb +0 -1
  30. data/spec/br_danfe/danfe_lib/nfe_lib/xprod_spec.rb +2 -2
  31. data/spec/br_danfe/danfe_lib/nfe_spec.rb +17 -1
  32. data/spec/br_danfe/danfe_spec.rb +16 -0
  33. data/spec/fixtures/cce/lib/correction#render.pdf +0 -0
  34. data/spec/fixtures/cce/lib/document#box.with.block.pdf +0 -0
  35. data/spec/fixtures/cce/lib/document#text.align.pdf +0 -0
  36. data/spec/fixtures/cce/lib/document#text.pad.pdf +0 -0
  37. data/spec/fixtures/cce/lib/document#text.simple.pdf +0 -0
  38. data/spec/fixtures/cce/lib/document#text.size.pdf +0 -0
  39. data/spec/fixtures/cce/lib/document#text.style.pdf +0 -0
  40. data/spec/fixtures/cce/lib/footer#render.pdf +0 -0
  41. data/spec/fixtures/cce/lib/header#render.pdf +0 -0
  42. data/spec/fixtures/cce/lib/nfe_key#render.pdf +0 -0
  43. data/spec/fixtures/cce/lib/protocol#render.pdf +0 -0
  44. data/spec/fixtures/cce/v1.00/cce.fixture.pdf +211 -48
  45. data/spec/fixtures/nfce/v4.00/multiples_xmls_on_the_same_pdf.pdf +1229 -0
  46. data/spec/fixtures/nfe/lib/dest#render-v2.00.pdf +0 -0
  47. data/spec/fixtures/nfe/lib/dest#render-v3.10.pdf +0 -0
  48. data/spec/fixtures/nfe/lib/dest#render-v4.00.pdf +0 -0
  49. data/spec/fixtures/nfe/lib/dest#render-with-address-bigger.pdf +0 -0
  50. data/spec/fixtures/nfe/lib/dest#render-with_cnpj.pdf +0 -0
  51. data/spec/fixtures/nfe/lib/dest#render-with_cpf.pdf +0 -0
  52. data/spec/fixtures/nfe/lib/dest#render-with_ie.pdf +0 -0
  53. data/spec/fixtures/nfe/lib/dest#render-without-address-complement.pdf +0 -0
  54. data/spec/fixtures/nfe/lib/det_body#render-csosn.pdf +739 -658
  55. data/spec/fixtures/nfe/lib/det_body#render-cst.pdf +476 -393
  56. data/spec/fixtures/nfe/lib/det_body#render-fci.pdf +323 -238
  57. data/spec/fixtures/nfe/lib/det_body#render-icms_st.pdf +327 -237
  58. data/spec/fixtures/nfe/lib/det_body#render-quantity_with_custom_precision.pdf +319 -233
  59. data/spec/fixtures/nfe/lib/det_body#render-three_pages.pdf +6619 -7057
  60. data/spec/fixtures/nfe/lib/det_body#render-two_pages.pdf +6474 -6396
  61. data/spec/fixtures/nfe/lib/det_body#render-unit_price_with_custom_precision.pdf +319 -233
  62. data/spec/fixtures/nfe/lib/det_body#render-with_infadprod.pdf +315 -237
  63. data/spec/fixtures/nfe/lib/det_body#render-with_issqn.pdf +3026 -2948
  64. data/spec/fixtures/nfe/lib/det_body#render-without_issqn.pdf +3026 -2948
  65. data/spec/fixtures/nfe/lib/document#lcnpj-blank.pdf +0 -0
  66. data/spec/fixtures/nfe/lib/document#lcnpj-invalid.pdf +0 -0
  67. data/spec/fixtures/nfe/lib/document#lcnpj-valid.pdf +0 -0
  68. data/spec/fixtures/nfe/lib/document#lie-blank-uf-invalid.pdf +0 -0
  69. data/spec/fixtures/nfe/lib/document#lie-blank.pdf +0 -0
  70. data/spec/fixtures/nfe/lib/document#lie-invalid.pdf +0 -0
  71. data/spec/fixtures/nfe/lib/document#lie-valid.pdf +0 -0
  72. data/spec/fixtures/nfe/lib/dup#render.pdf +0 -0
  73. data/spec/fixtures/nfe/lib/emit_header#render-second_page.pdf +214 -67
  74. data/spec/fixtures/nfe/lib/emit_header#render-with_logo.pdf +214 -67
  75. data/spec/fixtures/nfe/lib/emit_header#render-without_logo.pdf +212 -65
  76. data/spec/fixtures/nfe/lib/icmstot#render.pdf +0 -0
  77. data/spec/fixtures/nfe/lib/infadic#address-shipment.pdf +0 -0
  78. data/spec/fixtures/nfe/lib/infadic#render-all_the_informations.pdf +0 -0
  79. data/spec/fixtures/nfe/lib/infadic#render-difal.pdf +0 -0
  80. data/spec/fixtures/nfe/lib/infadic#render-extra_volume.pdf +0 -0
  81. data/spec/fixtures/nfe/lib/infadic#render-with_complementary_information.pdf +0 -0
  82. data/spec/fixtures/nfe/lib/infadic#render-with_fisco_additional_information.pdf +0 -0
  83. data/spec/fixtures/nfe/lib/infadic#render-with_street_data.pdf +0 -0
  84. data/spec/fixtures/nfe/lib/infadic#render.pdf +0 -0
  85. data/spec/fixtures/nfe/lib/infadic_vol#render-extra_volume.pdf +0 -0
  86. data/spec/fixtures/nfe/lib/issqn#render-with_issqn.pdf +0 -0
  87. data/spec/fixtures/nfe/lib/issqn#render-with_one_issqn_value.pdf +0 -0
  88. data/spec/fixtures/nfe/lib/ticket#render.pdf +0 -0
  89. data/spec/fixtures/nfe/lib/transp#render-modfrete_0.pdf +0 -0
  90. data/spec/fixtures/nfe/lib/transp#render-modfrete_1.pdf +0 -0
  91. data/spec/fixtures/nfe/lib/transp#render-modfrete_2.pdf +0 -0
  92. data/spec/fixtures/nfe/lib/transp#render-modfrete_3.pdf +0 -0
  93. data/spec/fixtures/nfe/lib/transp#render-modfrete_4.pdf +0 -0
  94. data/spec/fixtures/nfe/lib/transp#render-modfrete_9.pdf +0 -0
  95. data/spec/fixtures/nfe/lib/transp#render.pdf +0 -0
  96. data/spec/fixtures/nfe/lib/vol#render-blank-boxes.pdf +0 -0
  97. data/spec/fixtures/nfe/lib/vol#render.pdf +0 -0
  98. data/spec/fixtures/nfe/v2.00/custom_options.fixture.pdf +1037 -793
  99. data/spec/fixtures/nfe/v2.00/nfe_simples_nacional.xml.fixture.pdf +1035 -791
  100. data/spec/fixtures/nfe/v2.00/nfe_with_extra_volumes.xml.fixture.pdf +2963 -2738
  101. data/spec/fixtures/nfe/v2.00/nfe_with_fci.xml.fixture.pdf +731 -504
  102. data/spec/fixtures/nfe/v2.00/nfe_with_ns.xml.fixture.pdf +2909 -2688
  103. data/spec/fixtures/nfe/v2.00/nfe_without_ns.xml.fixture.pdf +938 -768
  104. data/spec/fixtures/nfe/v3.10/multiples.xmls.on.the.same.pdf.pdf +11471 -0
  105. data/spec/fixtures/nfe/v3.10/nfe_simples_nacional.xml.fixture.pdf +1823 -1601
  106. data/spec/fixtures/nfe/v3.10/with_footer.fixture.pdf +3110 -2436
  107. data/spec/fixtures/nfe/v3.10/with_footer.xml +18 -0
  108. data/spec/fixtures/nfe/v3.10/with_issqn.fixture.pdf +2564 -3072
  109. data/spec/fixtures/nfe/v3.10/with_three_pages.fixture.pdf +8404 -8187
  110. data/spec/fixtures/nfe/v3.10/without_issqn.fixture.pdf +3167 -2951
  111. data/spec/spec_helper.rb +2 -0
  112. metadata +15 -6
@@ -3,8 +3,8 @@ module BrDanfe
3
3
  class Base
4
4
  attr_reader :options
5
5
 
6
- def initialize(xml)
7
- @xml = xml
6
+ def initialize(xmls)
7
+ @xmls = xmls
8
8
  @document = document
9
9
  @options = BrDanfe::Logo::Config.new
10
10
 
@@ -24,21 +24,23 @@ module BrDanfe
24
24
  end
25
25
 
26
26
  def generate(footer_info)
27
- NfceLib::Header.new(@document, @xml, @options.logo, @options.logo_dimensions).render
28
- NfceLib::ProductList.new(@document, @xml).render
29
- NfceLib::TotalList.new(@document, @xml).render
30
- NfceLib::Key.new(@document, @xml).render
31
- NfceLib::Recipient.new(@document, @xml).render
32
- NfceLib::NfceIdentification.new(@document, @xml).render
33
- NfceLib::QrCode.new(@document, @xml).render
34
- NfceLib::Footer.new(@document, @xml).render(footer_info)
27
+ @xmls.each do |xml|
28
+ NfceLib::Header.new(@document, xml, @options.logo, @options.logo_dimensions).render
29
+ NfceLib::ProductList.new(@document, xml).render
30
+ NfceLib::TotalList.new(@document, xml).render
31
+ NfceLib::Key.new(@document, xml).render
32
+ NfceLib::Recipient.new(@document, xml).render
33
+ NfceLib::NfceIdentification.new(@document, xml).render
34
+ NfceLib::QrCode.new(@document, xml).render
35
+ NfceLib::Footer.new(@document, xml).render(footer_info)
35
36
 
36
- render_no_fiscal_value
37
- resize_page_height
37
+ render_no_fiscal_value(xml)
38
+ resize_page_height
39
+ end
38
40
  end
39
41
 
40
- def render_no_fiscal_value
41
- @document.stamp('has_no_fiscal_value') if BrDanfe::Helper.unauthorized?(@xml)
42
+ def render_no_fiscal_value(xml)
43
+ @document.stamp('has_no_fiscal_value') if BrDanfe::Helper.unauthorized?(xml)
42
44
  end
43
45
 
44
46
  def resize_page_height
@@ -3,7 +3,7 @@ module BrDanfe
3
3
  module NfceLib
4
4
  class Document
5
5
  def initialize(page_width, page_height)
6
- @document = Prawn::Document.new(
6
+ @document = BrDanfe::DocumentBuilder.build(
7
7
  page_size: [page_width, page_height],
8
8
  page_layout: :portrait,
9
9
  left_margin: 0.3.cm,
@@ -23,45 +23,57 @@ module BrDanfe
23
23
  end
24
24
 
25
25
  def generate(footer_info)
26
- render_on_first_page
27
- render_on_each_page footer_info
26
+ last_index = @xmls.size - 1
27
+
28
+ @xmls.each_with_index do |xml, index|
29
+ break unless BrDanfe::Helper.nfe?(xml)
30
+
31
+ initial_number_of_pages = @document.page_count
32
+ render_on_first_page(xml)
33
+ render_on_each_page(footer_info, xml, initial_number_of_pages)
34
+ @document.start_new_page unless index == last_index
35
+ end
36
+
28
37
  @document
29
38
  end
30
39
 
31
- def render_on_first_page
32
- NfeLib::Ticket.new(@document, @xml).render
33
- NfeLib::Dest.new(@document, @xml).render
34
- NfeLib::Dup.new(@document, @xml).render
35
- NfeLib::Icmstot.new(@document, @xml).render
36
- NfeLib::Transp.new(@document, @xml).render
37
- n_vol = NfeLib::Vol.new(@document, @xml).render
38
- has_issqn = NfeLib::Issqn.new(@document, @xml).render
39
- NfeLib::Infadic.new(@document, @xml).render(n_vol)
40
-
41
- render_products has_issqn
40
+ def render_on_first_page(xml)
41
+ NfeLib::Ticket.new(@document, xml).render
42
+ NfeLib::Dest.new(@document, xml).render
43
+ NfeLib::Dup.new(@document, xml).render
44
+ NfeLib::Icmstot.new(@document, xml).render
45
+ NfeLib::Transp.new(@document, xml).render
46
+ n_vol = NfeLib::Vol.new(@document, xml).render
47
+ has_issqn = NfeLib::Issqn.new(@document, xml).render
48
+ NfeLib::Infadic.new(@document, xml).render(n_vol)
49
+
50
+ render_products(has_issqn, xml)
42
51
  end
43
52
 
44
- def render_products(has_issqn)
45
- NfeLib::DetBody.new(@document, @xml).render(has_issqn)
53
+ def render_products(has_issqn, xml)
54
+ NfeLib::DetBody.new(@document, xml).render(has_issqn)
46
55
  end
47
56
 
48
- def render_on_each_page(footer_info)
49
- emitter = NfeLib::EmitHeader.new(@document, @xml, @options.logo, @options.logo_dimensions)
57
+ def render_on_each_page(footer_info, xml, initial_number_of_pages)
58
+ total_pages = @document.page_count + 1 - initial_number_of_pages
59
+
60
+ emitter = NfeLib::EmitHeader.new(@document, xml, @options.logo, @options.logo_dimensions)
61
+
62
+ total_pages.times do |page_index|
63
+ page = page_index + initial_number_of_pages
50
64
 
51
- @document.page_count.times do |i|
52
- page = i + 1
53
- position = page == 1 ? 3.96 : 1.85
54
- repeated_information page, position, emitter, footer_info
65
+ position = page_index + 1 == 1 ? 3.96 : 1.85
66
+ repeated_information(page, position, emitter, footer_info, xml, total_pages, page_index + 1)
55
67
  end
56
68
  end
57
69
 
58
- def repeated_information(page, y_position, emitter, footer_info)
70
+ def repeated_information(page, y_position, emitter, footer_info, xml, total_pages, initial_page_of_pdf)
59
71
  @document.go_to_page(page)
60
72
 
61
- emitter.render page, y_position
62
- render_product_table_title page
73
+ emitter.render(initial_page_of_pdf, y_position, total_pages)
74
+ render_product_table_title initial_page_of_pdf
63
75
  render_footer_information footer_info
64
- render_no_fiscal_value
76
+ render_no_fiscal_value(xml)
65
77
  end
66
78
 
67
79
  def render_product_table_title(page)
@@ -75,8 +87,8 @@ module BrDanfe
75
87
  end
76
88
  end
77
89
 
78
- def render_no_fiscal_value
79
- @document.stamp('has_no_fiscal_value') if BrDanfe::Helper.no_fiscal_value?(@xml)
90
+ def render_no_fiscal_value(xml)
91
+ @document.stamp('has_no_fiscal_value') if BrDanfe::Helper.no_fiscal_value?(xml)
80
92
  end
81
93
  end
82
94
  end
@@ -3,7 +3,7 @@ module BrDanfe
3
3
  module NfeLib
4
4
  class Document
5
5
  def initialize
6
- @document = Prawn::Document.new(
6
+ @document = BrDanfe::DocumentBuilder.build(
7
7
  page_size: 'A4',
8
8
  page_layout: :portrait,
9
9
  left_margin: 0,
@@ -12,7 +12,8 @@ module BrDanfe
12
12
  botton_margin: 0
13
13
  )
14
14
 
15
- @document.font 'Times-Roman'
15
+ @document.font 'tinos'
16
+
16
17
  @document.line_width = 0.3
17
18
  end
18
19
 
@@ -9,10 +9,10 @@ module BrDanfe
9
9
  @logo_dimensions = logo_dimensions
10
10
  end
11
11
 
12
- def render(page, y_position)
12
+ def render(page, y_position, total)
13
13
  @y_position = y_position
14
14
  company_box
15
- danfe_box page
15
+ danfe_box(page, total)
16
16
  access_key_box
17
17
  sefaz_box
18
18
  render_emit y_position
@@ -64,7 +64,7 @@ module BrDanfe
64
64
  end
65
65
  end
66
66
 
67
- def danfe_box(page)
67
+ def danfe_box(page, total)
68
68
  @pdf.ibox 3.92, 2.08, 8.21, @y_position
69
69
 
70
70
  @pdf.ibox 0.60, 2.08, 8.21, @y_position, '', 'DANFE',
@@ -83,7 +83,7 @@ module BrDanfe
83
83
  size: 8, align: :center, valign: :center, border: 0, style: :bold
84
84
 
85
85
  @pdf.ibox 1.00, 2.08, 8.21, @y_position + 3.00, '',
86
- I18n.t('danfe.others.page', current: page, total: @pdf.page_count),
86
+ I18n.t('danfe.others.page', current: page, total: total),
87
87
  size: 8, align: :center, valign: :center, border: 0, style: :bold
88
88
  end
89
89
 
@@ -29,7 +29,7 @@ module BrDanfe
29
29
  private
30
30
 
31
31
  def can_render?
32
- @xml[@serv].to_i.positive? || @xml[@bc].to_i.positive? || @xml[@iss].to_i.positive?
32
+ @xml[@serv].to_f.positive? || @xml[@bc].to_f.positive? || @xml[@iss].to_f.positive?
33
33
  end
34
34
  end
35
35
  end
@@ -47,11 +47,11 @@ module BrDanfe
47
47
  end
48
48
 
49
49
  def icms_st?
50
- @det.css('ICMS/*/vBCST').text.to_i.positive?
50
+ @det.css('ICMS/*/vBCST').text.to_f.positive?
51
51
  end
52
52
 
53
53
  def fcp?
54
- @det.css('ICMS/*/vFCP').text.to_i.positive?
54
+ @det.css('ICMS/*/vFCP').text.to_f.positive?
55
55
  end
56
56
 
57
57
  def fcp
@@ -76,7 +76,7 @@ module BrDanfe
76
76
  end
77
77
 
78
78
  def fcp_st?
79
- @det.css('ICMS/*/vFCPST').text.to_i.positive?
79
+ @det.css('ICMS/*/vFCPST').text.to_f.positive?
80
80
  end
81
81
 
82
82
  def fcp_st
@@ -91,8 +91,8 @@ module BrDanfe
91
91
  end
92
92
 
93
93
  def icms_st_ret?
94
- @det.css('ICMS/*/vBCSTRet').text.to_i.positive? || @det.css('ICMS/*/vICMSSTRet').text.to_i.positive? ||
95
- @det.css('ICMS/*/pST').text.to_i.positive?
94
+ @det.css('ICMS/*/vBCSTRet').text.to_f.positive? || @det.css('ICMS/*/vICMSSTRet').text.to_f.positive? ||
95
+ @det.css('ICMS/*/pST').text.to_f.positive?
96
96
  end
97
97
 
98
98
  def icms_st_ret
@@ -0,0 +1,16 @@
1
+ module BrDanfe
2
+ class DocumentBuilder
3
+ def self.build(*args, &block)
4
+ document = Prawn::Document.new(*args, &block)
5
+
6
+ document.font_families['tinos'] = {
7
+ bold: "#{BrDanfe.root_path}/fonts/tinos_bold.ttf",
8
+ italic: "#{BrDanfe.root_path}/fonts/tinos_italic.ttf",
9
+ bold_italic: "#{BrDanfe.root_path}/fonts/tinos_bold_italic.ttf",
10
+ normal: "#{BrDanfe.root_path}/fonts/tinos.ttf",
11
+ }
12
+
13
+ document
14
+ end
15
+ end
16
+ end
@@ -33,5 +33,11 @@ module BrDanfe
33
33
 
34
34
  formated
35
35
  end
36
+
37
+ def self.nfe?(xml)
38
+ nfe_code = '55'
39
+
40
+ xml['ide > mod'] == nfe_code
41
+ end
36
42
  end
37
43
  end
@@ -1,3 +1,3 @@
1
1
  module BrDanfe
2
- VERSION = '0.14.0'.freeze
2
+ VERSION = '0.15.0'.freeze
3
3
  end
data/lib/prawn/font.rb ADDED
@@ -0,0 +1,7 @@
1
+ module Prawn
2
+ class Font
3
+ def hash #:nodoc:
4
+ [self.class, name, family].hash
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,33 @@
1
+ module Prawn
2
+ # Cache used internally by Prawn::Document instances to calculate the width
3
+ # of various strings for layout purposes.
4
+ #
5
+ # @private
6
+ class FontMetricCache
7
+ CacheEntryMonkeyPatch = Struct.new(:font, :font_size, :options, :string)
8
+
9
+ def width_of(string, options)
10
+ f = if options[:style]
11
+ # override style with :style => :bold
12
+ @document.find_font(@document.font.family, style: options[:style])
13
+ else
14
+ @document.font
15
+ end
16
+
17
+ encoded_string = f.normalize_encoding(string)
18
+
19
+ key = CacheEntryMonkeyPatch.new(f, @document.font_size, options, encoded_string)
20
+
21
+ @cache[key] ||= f.compute_width_of(encoded_string, options)
22
+
23
+ length = @cache[key]
24
+
25
+ character_count = @document.font.character_count(encoded_string)
26
+ if character_count.positive?
27
+ length += @document.character_spacing * (character_count - 1)
28
+ end
29
+
30
+ length
31
+ end
32
+ end
33
+ end
@@ -5,7 +5,7 @@ describe BrDanfe::DanfeLib::Nfce do
5
5
  let(:base_dir) { './spec/fixtures/nfce/v4.00/' }
6
6
  let(:xml) { BrDanfe::XML.new(File.read("#{base_dir}nfce.xml")) }
7
7
 
8
- subject { described_class.new xml }
8
+ subject { described_class.new [xml] }
9
9
 
10
10
  before do
11
11
  subject.options.logo = 'spec/fixtures/logo.png'
@@ -53,5 +53,16 @@ describe BrDanfe::DanfeLib::Nfce do
53
53
  end
54
54
  end
55
55
  end
56
+
57
+ context 'when there is more than one xml' do
58
+ it 'renders multiple danfes on the same pdf' do
59
+ subject = described_class.new [xml, xml]
60
+
61
+ expect(File.exist?(output_pdf)).to be_falsey
62
+ subject.save_pdf output_pdf
63
+
64
+ expect("#{base_dir}multiples_xmls_on_the_same_pdf.pdf").to have_same_content_of file: output_pdf
65
+ end
66
+ end
56
67
  end
57
68
  end
@@ -53,7 +53,7 @@ describe BrDanfe::DanfeLib::NfeLib::EmitHeader do
53
53
 
54
54
  context 'render emitter on first page' do
55
55
  before do
56
- subject.render 1, 3.96
56
+ subject.render 1, 3.96, 1
57
57
  File.delete(output_pdf) if File.exist?(output_pdf)
58
58
  end
59
59
 
@@ -82,7 +82,7 @@ describe BrDanfe::DanfeLib::NfeLib::EmitHeader do
82
82
 
83
83
  context 'render emitter on second page' do
84
84
  before do
85
- subject.render 2, 1.85
85
+ subject.render 2, 1.85, 2
86
86
  File.delete(output_pdf) if File.exist?(output_pdf)
87
87
  end
88
88
 
@@ -449,7 +449,6 @@ describe BrDanfe::DanfeLib::NfeLib::Infadic do
449
449
  'complementary information, address and difal on the pdf' do
450
450
  expect(File.exist?(output_pdf)).to be_falsey
451
451
 
452
- pdf.render_file "#{base_dir}infadic#render-all_the_informations.pdf"
453
452
  pdf.render_file output_pdf
454
453
 
455
454
  expect("#{base_dir}infadic#render-all_the_informations.pdf").to have_same_content_of file: output_pdf
@@ -300,7 +300,7 @@ describe BrDanfe::DanfeLib::NfeLib::Xprod do
300
300
  <ICMS>
301
301
  <ICMS30>
302
302
  <vBCFCPST>235.50</vBCFCPST>
303
- <vFCPST>4.71</vFCPST>
303
+ <vFCPST>0.71</vFCPST>
304
304
  <pFCPST>2.00</pFCPST>
305
305
  </ICMS30>
306
306
  </ICMS>
@@ -316,7 +316,7 @@ describe BrDanfe::DanfeLib::NfeLib::Xprod do
316
316
  it 'returns product + FCP' do
317
317
  expected = 'MONITOR DE ARCO ELETRICO'
318
318
  expected += "\n"
319
- expected += 'FCP ST: Base: 235,50 * Alíq: 2,00% * Vlr: 4,71'
319
+ expected += 'FCP ST: Base: 235,50 * Alíq: 2,00% * Vlr: 0,71'
320
320
 
321
321
  expect(subject.render).to eq expected
322
322
  end
@@ -5,7 +5,7 @@ describe BrDanfe::DanfeLib::Nfe do
5
5
  let(:xml_file) {}
6
6
  let(:xml) { BrDanfe::XML.new(xml_file) }
7
7
 
8
- subject { described_class.new xml }
8
+ subject { described_class.new [xml] }
9
9
 
10
10
  describe '#render_pdf' do
11
11
  let(:base_dir) { './spec/fixtures/nfe/v3.10/' }
@@ -152,5 +152,21 @@ describe BrDanfe::DanfeLib::Nfe do
152
152
  end
153
153
  end
154
154
  end
155
+
156
+ context 'when there is more than one xml' do
157
+ let(:base_dir) { './spec/fixtures/nfe/v3.10/' }
158
+ let(:xml_file) { File.read("#{base_dir}nfe_simples_nacional.xml") }
159
+
160
+ before { File.delete(output_pdf) if File.exist?(output_pdf) }
161
+
162
+ it 'renders multiple danfes on the same pdf' do
163
+ expect(File.exist?(output_pdf)).to be_falsey
164
+ subject = described_class.new([xml, xml])
165
+
166
+ subject.save_pdf(output_pdf)
167
+
168
+ expect("#{base_dir}multiples.xmls.on.the.same.pdf.pdf").to have_same_content_of file: output_pdf
169
+ end
170
+ end
155
171
  end
156
172
  end
@@ -22,6 +22,22 @@ describe BrDanfe::Danfe do
22
22
 
23
23
  subject { described_class.new(xml) }
24
24
 
25
+ context 'xmls parameter' do
26
+ let(:mod) { 55 }
27
+
28
+ it 'accepts one xml' do
29
+ subject = described_class.new(xml)
30
+
31
+ expect(subject.class).to eq BrDanfe::DanfeLib::Nfe
32
+ end
33
+
34
+ it 'accepts an array of xmls' do
35
+ subject = described_class.new([xml, xml])
36
+
37
+ expect(subject.class).to eq BrDanfe::DanfeLib::Nfe
38
+ end
39
+ end
40
+
25
41
  context 'when the xml document type is NF-e' do
26
42
  let(:mod) { 55 }
27
43