br_danfe 0.14.4 → 0.16.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (161) hide show
  1. checksums.yaml +4 -4
  2. data/.tool-versions +1 -0
  3. data/Gemfile.lock +48 -33
  4. data/Guardfile +2 -2
  5. data/README.md +39 -0
  6. data/br_danfe.gemspec +5 -4
  7. data/config/locales/pt-BR.yml +1 -0
  8. data/lib/br_danfe.rb +1 -1
  9. data/lib/br_danfe/danfe.rb +8 -5
  10. data/lib/br_danfe/danfe_lib/base.rb +2 -2
  11. data/lib/br_danfe/danfe_lib/nfce.rb +14 -12
  12. data/lib/br_danfe/danfe_lib/nfe.rb +39 -27
  13. data/lib/br_danfe/danfe_lib/nfe_lib/dest.rb +1 -1
  14. data/lib/br_danfe/danfe_lib/nfe_lib/emit_header.rb +5 -5
  15. data/lib/br_danfe/document_builder.rb +1 -1
  16. data/lib/br_danfe/helper.rb +11 -7
  17. data/lib/br_danfe/mdfe.rb +55 -0
  18. data/lib/br_danfe/mdfe_lib/authorization_protocol.rb +24 -0
  19. data/lib/br_danfe/mdfe_lib/document.rb +26 -0
  20. data/lib/br_danfe/mdfe_lib/drivers.rb +70 -0
  21. data/lib/br_danfe/mdfe_lib/fisco_control.rb +40 -0
  22. data/lib/br_danfe/mdfe_lib/header.rb +78 -0
  23. data/lib/br_danfe/mdfe_lib/mdfe_identification.rb +69 -0
  24. data/lib/br_danfe/mdfe_lib/notes.rb +94 -0
  25. data/lib/br_danfe/mdfe_lib/totalizer.rb +57 -0
  26. data/lib/br_danfe/mdfe_lib/vehicles.rb +80 -0
  27. data/lib/br_danfe/qr_code.rb +22 -0
  28. data/lib/br_danfe/version.rb +1 -1
  29. data/spec/br_danfe/danfe_lib/nfce_spec.rb +12 -1
  30. data/spec/br_danfe/danfe_lib/nfe_lib/emit_header_spec.rb +2 -2
  31. data/spec/br_danfe/danfe_lib/nfe_lib/infadic_spec.rb +3 -3
  32. data/spec/br_danfe/danfe_lib/nfe_spec.rb +17 -1
  33. data/spec/br_danfe/danfe_spec.rb +16 -0
  34. data/spec/br_danfe/helper_spec.rb +12 -0
  35. data/spec/br_danfe/mdfe_lib/authorization_protocol_spec.rb +35 -0
  36. data/spec/br_danfe/mdfe_lib/document_spec.rb +20 -0
  37. data/spec/br_danfe/mdfe_lib/drivers_spec.rb +88 -0
  38. data/spec/br_danfe/mdfe_lib/fisco_control_spec.rb +55 -0
  39. data/spec/br_danfe/mdfe_lib/header_spec.rb +126 -0
  40. data/spec/br_danfe/mdfe_lib/mdfe_identification_spec.rb +104 -0
  41. data/spec/br_danfe/mdfe_lib/notes_spec.rb +97 -0
  42. data/spec/br_danfe/mdfe_lib/totalizer_spec.rb +63 -0
  43. data/spec/br_danfe/mdfe_lib/vehicles_spec.rb +66 -0
  44. data/spec/br_danfe/mdfe_spec.rb +46 -0
  45. data/spec/br_danfe/{danfe_lib/nfce_lib/qr_code_spec.rb → qr_code_spec.rb} +10 -5
  46. data/spec/fixtures/cce/lib/barcode#render.pdf +5 -3
  47. data/spec/fixtures/cce/v1.00/cce.fixture.pdf +15 -13
  48. data/spec/fixtures/mdfe/lib/document#render.pdf +0 -0
  49. data/spec/fixtures/mdfe/lib/document#text.align.pdf +0 -0
  50. data/spec/fixtures/mdfe/lib/document#text.pad.pdf +0 -0
  51. data/spec/fixtures/mdfe/lib/document#text.simple.pdf +0 -0
  52. data/spec/fixtures/mdfe/lib/document#text.size.pdf +0 -0
  53. data/spec/fixtures/mdfe/lib/document#text.style.pdf +0 -0
  54. data/spec/fixtures/mdfe/lib/fisco_control#barcode.pdf +0 -0
  55. data/spec/fixtures/mdfe/lib/header#render-qr-code.pdf +0 -0
  56. data/spec/fixtures/mdfe/lib/header#render-with_logo.pdf +0 -0
  57. data/spec/fixtures/mdfe/lib/header#render-without_logo.pdf +0 -0
  58. data/spec/fixtures/mdfe/lib/mdfe-with-multiple-pages.pdf +1945 -0
  59. data/spec/fixtures/mdfe/lib/mdfe.fixture.pdf +1286 -0
  60. data/spec/fixtures/mdfe/lib/notes#render-big-aditional-information.pdf +1943 -0
  61. data/spec/fixtures/mdfe/lib/xml-mdfe-multiples-pages.xml +116 -0
  62. data/spec/fixtures/mdfe/lib/xml-mdfe.xml +250 -0
  63. data/spec/fixtures/nfce/lib/document#render.pdf +17 -17
  64. data/spec/fixtures/nfce/lib/footer#render-with_additional_information.pdf +12 -12
  65. data/spec/fixtures/nfce/lib/footer#render.pdf +10 -10
  66. data/spec/fixtures/nfce/lib/header#render-homologation.pdf +0 -0
  67. data/spec/fixtures/nfce/lib/header#render-long_name_with_logo.pdf +0 -0
  68. data/spec/fixtures/nfce/lib/header#render-long_name_without_logo.pdf +16 -16
  69. data/spec/fixtures/nfce/lib/header#render-short_name_with_logo.pdf +0 -0
  70. data/spec/fixtures/nfce/lib/header#render-short_name_without_logo.pdf +16 -16
  71. data/spec/fixtures/nfce/lib/key#render.pdf +14 -14
  72. data/spec/fixtures/nfce/lib/nfce_identification#render.pdf +16 -16
  73. data/spec/fixtures/nfce/lib/product_list#render-with_many_products.pdf +43 -43
  74. data/spec/fixtures/nfce/lib/product_list#render-with_many_products_and_long_names.pdf +47 -47
  75. data/spec/fixtures/nfce/lib/product_list#render-with_single_product.pdf +25 -25
  76. data/spec/fixtures/nfce/lib/product_list#render-with_single_product_and_long_name.pdf +27 -27
  77. data/spec/fixtures/nfce/lib/qr_code#render.pdf +0 -0
  78. data/spec/fixtures/nfce/lib/recipient#render-company.pdf +13 -13
  79. data/spec/fixtures/nfce/lib/recipient#render-consumer_without_document.pdf +12 -12
  80. data/spec/fixtures/nfce/lib/recipient#render-foreign.pdf +13 -13
  81. data/spec/fixtures/nfce/lib/recipient#render-individual.pdf +13 -13
  82. data/spec/fixtures/nfce/lib/recipient#render-unidentified_consumer.pdf +11 -11
  83. data/spec/fixtures/nfce/lib/total_list#does_not_render-payment_methods.pdf +19 -19
  84. data/spec/fixtures/nfce/lib/total_list#render-grouped_payment_methods.pdf +26 -26
  85. data/spec/fixtures/nfce/lib/total_list#render-totals.pdf +19 -19
  86. data/spec/fixtures/nfce/lib/total_list#render-without_payment.pdf +28 -28
  87. data/spec/fixtures/nfce/lib/total_list#render.pdf +28 -28
  88. data/spec/fixtures/nfce/v4.00/multiples_xmls_on_the_same_pdf.pdf +1229 -0
  89. data/spec/fixtures/nfce/v4.00/nfce-unauthorized-hom.fixture.pdf +0 -0
  90. data/spec/fixtures/nfce/v4.00/nfce-unauthorized-prod.fixture.pdf +0 -0
  91. data/spec/fixtures/nfce/v4.00/rendered_nfce.fixture.pdf +0 -0
  92. data/spec/fixtures/nfce/v4.00/saved_nfce.fixture.pdf +0 -0
  93. data/spec/fixtures/nfe/lib/dest#render-v2.00.pdf +0 -0
  94. data/spec/fixtures/nfe/lib/dest#render-v3.10.pdf +0 -0
  95. data/spec/fixtures/nfe/lib/dest#render-v4.00.pdf +0 -0
  96. data/spec/fixtures/nfe/lib/dest#render-with-address-bigger.pdf +0 -0
  97. data/spec/fixtures/nfe/lib/dest#render-with_cnpj.pdf +0 -0
  98. data/spec/fixtures/nfe/lib/dest#render-with_cpf.pdf +0 -0
  99. data/spec/fixtures/nfe/lib/dest#render-with_ie.pdf +0 -0
  100. data/spec/fixtures/nfe/lib/dest#render-without-address-complement.pdf +0 -0
  101. data/spec/fixtures/nfe/lib/det_body#render-csosn.pdf +662 -662
  102. data/spec/fixtures/nfe/lib/det_body#render-cst.pdf +410 -410
  103. data/spec/fixtures/nfe/lib/det_body#render-fci.pdf +272 -272
  104. data/spec/fixtures/nfe/lib/det_body#render-icms_st.pdf +272 -272
  105. data/spec/fixtures/nfe/lib/det_body#render-quantity_with_custom_precision.pdf +270 -270
  106. data/spec/fixtures/nfe/lib/det_body#render-three_pages.pdf +6213 -6213
  107. data/spec/fixtures/nfe/lib/det_body#render-two_pages.pdf +6083 -6083
  108. data/spec/fixtures/nfe/lib/det_body#render-unit_price_with_custom_precision.pdf +270 -270
  109. data/spec/fixtures/nfe/lib/det_body#render-with_infadprod.pdf +272 -272
  110. data/spec/fixtures/nfe/lib/det_body#render-with_issqn.pdf +2859 -2859
  111. data/spec/fixtures/nfe/lib/det_body#render-without_issqn.pdf +2859 -2859
  112. data/spec/fixtures/nfe/lib/document#lcnpj-blank.pdf +0 -0
  113. data/spec/fixtures/nfe/lib/document#lcnpj-invalid.pdf +0 -0
  114. data/spec/fixtures/nfe/lib/document#lcnpj-valid.pdf +0 -0
  115. data/spec/fixtures/nfe/lib/document#lie-blank-uf-invalid.pdf +0 -0
  116. data/spec/fixtures/nfe/lib/document#lie-blank.pdf +0 -0
  117. data/spec/fixtures/nfe/lib/document#lie-invalid.pdf +0 -0
  118. data/spec/fixtures/nfe/lib/document#lie-valid.pdf +0 -0
  119. data/spec/fixtures/nfe/lib/dup#render.pdf +0 -0
  120. data/spec/fixtures/nfe/lib/emit_header#render-second_page.pdf +511 -509
  121. data/spec/fixtures/nfe/lib/emit_header#render-with_logo.pdf +510 -508
  122. data/spec/fixtures/nfe/lib/emit_header#render-without_logo.pdf +507 -505
  123. data/spec/fixtures/nfe/lib/icmstot#render.pdf +0 -0
  124. data/spec/fixtures/nfe/lib/infadic#address-shipment.pdf +0 -0
  125. data/spec/fixtures/nfe/lib/infadic#render-all_the_informations.pdf +0 -0
  126. data/spec/fixtures/nfe/lib/infadic#render-difal.pdf +0 -0
  127. data/spec/fixtures/nfe/lib/infadic#render-extra_volume.pdf +0 -0
  128. data/spec/fixtures/nfe/lib/infadic#render-with_complementary_information.pdf +0 -0
  129. data/spec/fixtures/nfe/lib/infadic#render-with_fisco_additional_information.pdf +0 -0
  130. data/spec/fixtures/nfe/lib/infadic#render-with_street_data.pdf +0 -0
  131. data/spec/fixtures/nfe/lib/infadic#render.pdf +0 -0
  132. data/spec/fixtures/nfe/lib/infadic_vol#render-extra_volume.pdf +0 -0
  133. data/spec/fixtures/nfe/lib/issqn#render-with_issqn.pdf +0 -0
  134. data/spec/fixtures/nfe/lib/issqn#render-with_one_issqn_value.pdf +0 -0
  135. data/spec/fixtures/nfe/lib/ticket#render.pdf +0 -0
  136. data/spec/fixtures/nfe/lib/transp#render-modfrete_0.pdf +0 -0
  137. data/spec/fixtures/nfe/lib/transp#render-modfrete_1.pdf +0 -0
  138. data/spec/fixtures/nfe/lib/transp#render-modfrete_2.pdf +0 -0
  139. data/spec/fixtures/nfe/lib/transp#render-modfrete_3.pdf +0 -0
  140. data/spec/fixtures/nfe/lib/transp#render-modfrete_4.pdf +0 -0
  141. data/spec/fixtures/nfe/lib/transp#render-modfrete_9.pdf +0 -0
  142. data/spec/fixtures/nfe/lib/transp#render.pdf +0 -0
  143. data/spec/fixtures/nfe/lib/vol#render-blank-boxes.pdf +0 -0
  144. data/spec/fixtures/nfe/lib/vol#render.pdf +0 -0
  145. data/spec/fixtures/nfe/v2.00/custom_options.fixture.pdf +733 -733
  146. data/spec/fixtures/nfe/v2.00/nfe_simples_nacional.xml.fixture.pdf +730 -730
  147. data/spec/fixtures/nfe/v2.00/nfe_with_extra_volumes.xml.fixture.pdf +3449 -3445
  148. data/spec/fixtures/nfe/v2.00/nfe_with_fci.xml.fixture.pdf +929 -927
  149. data/spec/fixtures/nfe/v2.00/nfe_with_ns.xml.fixture.pdf +3424 -3420
  150. data/spec/fixtures/nfe/v2.00/nfe_without_ns.xml.fixture.pdf +1178 -1176
  151. data/spec/fixtures/nfe/v3.10/multiples.xmls.on.the.same.pdf.pdf +11471 -0
  152. data/spec/fixtures/nfe/v3.10/nfe_simples_nacional.xml.fixture.pdf +1495 -1495
  153. data/spec/fixtures/nfe/v3.10/with_footer.fixture.pdf +2444 -2444
  154. data/spec/fixtures/nfe/v3.10/with_issqn.fixture.pdf +2142 -2142
  155. data/spec/fixtures/nfe/v3.10/with_three_pages.fixture.pdf +7096 -7096
  156. data/spec/fixtures/nfe/v3.10/without_issqn.fixture.pdf +2811 -2811
  157. data/spec/fixtures/qr_code/qr_code#render.pdf +0 -0
  158. metadata +90 -39
  159. data/lib/br_danfe/danfe_lib/nfce_lib/qr_code.rb +0 -25
  160. data/lib/br_danfe/danfe_lib/nfe_lib/cep.rb +0 -11
  161. data/spec/br_danfe/danfe_lib/nfe_lib/cep_spec.rb +0 -10
@@ -0,0 +1,94 @@
1
+ module BrDanfe
2
+ module MdfeLib
3
+ class Notes
4
+ MAX_CHARS_ON_LINE = 120
5
+
6
+ def initialize(pdf, xml)
7
+ @pdf = pdf
8
+ @xml = xml
9
+ end
10
+
11
+ def generate
12
+ title
13
+ aditional_information_first_page
14
+ aditional_information_taxpayer
15
+ end
16
+
17
+ private
18
+
19
+ def title
20
+ title = 'Observações'
21
+
22
+ @pdf.move_down 20
23
+ @pdf.bounding_box [0, @pdf.cursor], width: 278, height: 20 do
24
+ @pdf.stroke_color GRAY_COLOR
25
+ @pdf.stroke_horizontal_line(0, 526, at: 6)
26
+ @pdf.text(title, size: 12, align: :left, style: :bold)
27
+ end
28
+ end
29
+
30
+ def aditional_information_first_page
31
+ fisco_information = @xml['infAdic/infAdFisco']
32
+
33
+ fisco_information_title = 'INFORMAÇÕES ADICIONAIS DE INTERESSE DO FISCO'
34
+ taxpayer_information_title = 'INFORMAÇÕES ADICIONAIS DE INTERESSE DO CONTRIBUINTE'
35
+
36
+ @pdf.bounding_box([0, @pdf.cursor], width: 526) do
37
+ if fisco_information.present?
38
+ @pdf.text(fisco_information_title, size: 10)
39
+ @pdf.move_down 5
40
+ @pdf.text(fisco_information, size: 10)
41
+ @pdf.move_down 10
42
+ end
43
+
44
+ if taxpayer_information_xml.present?
45
+ @pdf.text(taxpayer_information_title, size: 10)
46
+ @pdf.move_down 5
47
+ end
48
+ end
49
+ end
50
+
51
+ def taxpayer_information_xml
52
+ @taxpayer_information_xml ||= @xml['infAdic/infCpl']
53
+ end
54
+
55
+ def aditional_information_taxpayer
56
+ first_page, next_page = fill_aditional_information_taxpayer(@pdf.cursor).values_at(:first_page, :next_page)
57
+
58
+ generate_aditional_information_taxpayer(first_page, @pdf.cursor)
59
+
60
+ if next_page.present?
61
+ @pdf.start_new_page
62
+ generate_aditional_information_taxpayer(next_page, y_position_next_pages)
63
+ end
64
+ end
65
+
66
+ def fill_aditional_information_taxpayer(height_on_first_page)
67
+ first_page = ''
68
+ next_page = ''
69
+ total_chars = 0
70
+ total_height = 0
71
+
72
+ taxpayer_information_xml.split.each do |word|
73
+ total_chars += word.split.count + 1
74
+
75
+ total_height += 10 if total_chars >= MAX_CHARS_ON_LINE
76
+
77
+ total_height <= height_on_first_page ? first_page += word + ' ' : next_page += word + ' '
78
+ end
79
+
80
+ { first_page: first_page, next_page: next_page }
81
+ end
82
+
83
+ def generate_aditional_information_taxpayer(data, position)
84
+ @pdf.bounding_box([0, position], width: 526) do
85
+ @pdf.text(data, size: 10)
86
+ end
87
+ end
88
+
89
+ def y_position_next_pages
90
+ 600
91
+ end
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,57 @@
1
+ module BrDanfe
2
+ module MdfeLib
3
+ class Totalizer
4
+ def initialize(pdf, xml)
5
+ @pdf = pdf
6
+ @xml = xml
7
+ end
8
+
9
+ def generate
10
+ generate_title
11
+ nfe_quantity
12
+ cte_quantity
13
+ total_weight
14
+ end
15
+
16
+ private
17
+
18
+ def generate_title
19
+ title = 'Modelo Rodoviário de Carga'
20
+
21
+ @pdf.text_box(title, size: 12, align: :left, style: :bold, at: [0, 600])
22
+ end
23
+
24
+ def nfe_quantity
25
+ generate_box('QTD. NFe', @xml['qNFe'], 65)
26
+ end
27
+
28
+ def generate_box(title, text, x_position, width = 60)
29
+ @pdf.move_cursor_to 580
30
+
31
+ @pdf.stroke do
32
+ @pdf.fill_color LIGHT_GRAY_COLOR
33
+ @pdf.fill_rectangle([x_position, @pdf.cursor], width, 35)
34
+ @pdf.fill_color BLACK_COLOR
35
+ end
36
+
37
+ @pdf.bounding_box([x_position, @pdf.cursor], width: width, height: 35) do
38
+ @pdf.move_down 5
39
+ @pdf.text_box(title, size: 10, at: [3, @pdf.cursor])
40
+ @pdf.move_down 15
41
+ @pdf.text_box(text, size: 12, at: [3, @pdf.cursor])
42
+ end
43
+ end
44
+
45
+ def cte_quantity
46
+ generate_box('QTD. CTe', '', 0)
47
+ end
48
+
49
+ def total_weight
50
+ weight = ActiveSupport::NumberHelper.number_to_rounded(@xml['qCarga'], precision: 2)
51
+ weight = Helper.numerify(weight)
52
+
53
+ generate_box('Peso total (Kg)', weight, 130, 90)
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,80 @@
1
+ module BrDanfe
2
+ module MdfeLib
3
+ class Vehicles
4
+ def initialize(pdf, xml)
5
+ @pdf = pdf
6
+ @xml = xml
7
+ end
8
+
9
+ def generate
10
+ @pdf.move_cursor_to 460
11
+ title
12
+ table_titles
13
+ generate_vehicles
14
+ end
15
+
16
+ private
17
+
18
+ def title
19
+ title = 'Veículo'
20
+
21
+ @pdf.text_box(title, size: 12, align: :left, style: :bold, at: [0, @pdf.cursor])
22
+ end
23
+
24
+ def table_titles
25
+ plate = 'Placa'
26
+ rntrc = 'RNTRC'
27
+
28
+ @pdf.stroke_color GRAY_COLOR
29
+ @pdf.move_down 20
30
+ @pdf.text_box(plate, size: 9, align: :left, at: [0, @pdf.cursor])
31
+ @pdf.text_box(rntrc, size: 9, align: :left, at: [100, @pdf.cursor])
32
+ @pdf.move_down 10
33
+ @pdf.stroke_horizontal_line(0, 190, at: @pdf.cursor)
34
+ end
35
+
36
+ def generate_vehicles
37
+ @pdf.move_cursor_to 425
38
+
39
+ vehicles.each_with_index do |cell, index|
40
+ @pdf.bounding_box [0, @pdf.cursor], width: 190, height: 20 do
41
+ @pdf.stroke_color GRAY_COLOR
42
+ @pdf.dash([2], phase: 6)
43
+ @pdf.stroke_horizontal_line(0, 190, at: 26) unless index.zero?
44
+ @pdf.text cell[:content], cell[:options]
45
+ @pdf.undash
46
+ @pdf.move_down 20
47
+ end
48
+ end
49
+ end
50
+
51
+ def vehicles
52
+ vehicle = []
53
+ vehicle += collect_vehicles('veicReboque')
54
+ vehicle += collect_vehicles('veicTracao')
55
+
56
+ vehicle
57
+ end
58
+
59
+ def collect_vehicles(tag)
60
+ vehicles = []
61
+ @xml.collect('xmlns', tag) { |rodo| vehicles += vehicle(rodo) }
62
+
63
+ vehicles
64
+ end
65
+
66
+ def vehicle(rodo)
67
+ [
68
+ cell_text(rodo.css('placa').text)
69
+ ]
70
+ end
71
+
72
+ def cell_text(text, options = {})
73
+ cell = { content: text, options: { size: 12 } }
74
+ cell[:options].merge!(options)
75
+
76
+ cell
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,22 @@
1
+ module BrDanfe
2
+ class QrCode
3
+ require 'rqrcode'
4
+ require 'chunky_png'
5
+ require 'tempfile'
6
+
7
+ def initialize(pdf:, xml:, qr_code_tag:, box_size:)
8
+ @pdf = pdf
9
+ @xml = xml
10
+ @qr_code_tag = qr_code_tag
11
+ @box_size = box_size
12
+ end
13
+
14
+ def render
15
+ qrcode = RQRCode::QRCode.new(@qr_code_tag)
16
+ image = Tempfile.new(%w[qrcode png], binmode: true)
17
+ image.write(qrcode.as_png(module_px_size: 12).to_s)
18
+
19
+ @pdf.image(image, width: @box_size, height: @box_size, position: :center)
20
+ end
21
+ end
22
+ end
@@ -1,3 +1,3 @@
1
1
  module BrDanfe
2
- VERSION = '0.14.4'.freeze
2
+ VERSION = '0.16.0'.freeze
3
3
  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
 
@@ -361,11 +361,11 @@ describe BrDanfe::DanfeLib::NfeLib::Infadic do
361
361
  end
362
362
 
363
363
  it 'renders title with box, subtitle, fisco box and address shipment information on the pdf' do
364
- expect(File.exist?(output_pdf)).to be_falsey
364
+ expect(File.exist?(output_pdf)).to be_falsey
365
365
 
366
- pdf.render_file output_pdf
366
+ pdf.render_file output_pdf
367
367
 
368
- expect("#{base_dir}infadic#address-shipment.pdf").to have_same_content_of file: output_pdf
368
+ expect("#{base_dir}infadic#address-shipment.pdf").to have_same_content_of file: output_pdf
369
369
  end
370
370
  end
371
371
 
@@ -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
 
@@ -212,5 +212,17 @@ describe BrDanfe::Helper do
212
212
  expect(described_class.format_datetime('')).to eql ''
213
213
  end
214
214
  end
215
+
216
+ describe 'when has timezone' do
217
+ it'returns the formated string with the timezone' do
218
+ expect(described_class.format_datetime('2013-10-18T13:54:04-03:00', with_time_zone: true)).to eql '18/10/2013 13:54:04-03:00'
219
+ end
220
+ end
221
+ end
222
+
223
+ describe '.format_cep' do
224
+ it 'returns a formatted CEP' do
225
+ expect(described_class.format_cep('12345678')).to eql '12.345-678'
226
+ end
215
227
  end
216
228
  end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe BrDanfe::MdfeLib::AuthorizationProtocol do
4
+ let(:xml_as_string) do
5
+ <<~XML
6
+ <?xml version="1.0" encoding="UTF-8"?>
7
+ <mdfeProc xmlns="http://www.portalfiscal.inf.br/mdfe" versao="3.00">
8
+ <protMDFe versao="3.00" xmlns="http://www.portalfiscal.inf.br/mdfe">
9
+ <infProt Id="MDFe932210002534081">
10
+ <dhRecbto>2021-07-01T17:39:16-03:00</dhRecbto>
11
+ <nProt>932210002534081</nProt>
12
+ </infProt>
13
+ </protMDFe>
14
+ </mdfeProc>
15
+ XML
16
+ end
17
+
18
+ let(:pdf) { BrDanfe::MdfeLib::Document.new }
19
+ let(:xml) { BrDanfe::XML.new(xml_as_string) }
20
+
21
+ subject { described_class.new(pdf, xml) }
22
+
23
+ let(:pdf_text) do
24
+ PDF::Inspector::Text.analyze(pdf.render).strings.join("\n")
25
+ end
26
+
27
+ describe '#generate' do
28
+ it 'generates the authorization protocol' do
29
+ authorization_protocol = "Protocolo de autorização\n932210002534081 - 01/07/2021 17:39:16-03:00"
30
+
31
+ subject.generate
32
+ expect(pdf_text).to include authorization_protocol
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe BrDanfe::MdfeLib::Document do
4
+ let(:base_dir) { './spec/fixtures/mdfe/lib/' }
5
+ let(:output_pdf) { "#{base_dir}output.pdf" }
6
+
7
+ describe '#method_missing' do
8
+ context 'when prawn has the method' do
9
+ it 'does not throws an error' do
10
+ expect { subject.text }.not_to raise_error NameError
11
+ end
12
+ end
13
+
14
+ context 'when prawn does not have the method' do
15
+ it 'throws an error' do
16
+ expect { subject.any_method }.to raise_error NameError
17
+ end
18
+ end
19
+ end
20
+ end