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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8da84a67d90f50f225fec5e94551d20645078771493cc7ab409ba5b5c9ad1520
4
- data.tar.gz: 388ea2d3244d90339dc310c53a538f21773fc99b268948c0a890924bcdda9bd5
3
+ metadata.gz: 447b593d2df30cc919fbc59e6453d794c1a60319a256357f650023e51bc6f369
4
+ data.tar.gz: a1d696214eeb03ef958c001870427cada4d826fabeb09cb24b1174a3ff19107e
5
5
  SHA512:
6
- metadata.gz: a4235e4eba637692a822496f4872f8589f12d16d93ffaa9ec38a25cded168fef9244b4cc0bb79cfc6e99b8fa5dc975e3bfb977bf7ce069769387742f496e6f89
7
- data.tar.gz: 389bb382836e781d5d72e3892dd2e051e6b2349de0757eaa09c0aa47ec7da3243478198425ded15bcc3631a198ac34364ae0e62992fa068adfb34c9d57296121
6
+ metadata.gz: b7ca6b73178f85c69d8e40334cfdffe2a1840de6c4910c1a40d09f97df05624226a1c5e8e285b5774fcceac78646e32194ce372456a038a66f52f67cb6202f83
7
+ data.tar.gz: 480fbe9dedac710566471b56a87ec05598bde90232b49fce063462739f249be6084944f397b8424661a2201ce086c77b8ae76c0ceb3315c2b7bf12c0757dfd30
data/.tool-versions ADDED
@@ -0,0 +1 @@
1
+ ruby 2.7.4
data/Gemfile.lock CHANGED
@@ -1,39 +1,41 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- br_danfe (0.14.4)
5
- barby (= 0.5.1)
4
+ br_danfe (0.16.0)
5
+ barby (= 0.6.8)
6
6
  br_documents (>= 0.1.3)
7
7
  i18n (>= 0.8.6)
8
8
  nokogiri (>= 1.8)
9
- prawn (~> 2.0)
9
+ prawn (~> 2.4.0)
10
10
  prawn-table (= 0.2.2)
11
11
  rqrcode (~> 1.1.1)
12
12
 
13
13
  GEM
14
14
  remote: https://rubygems.org/
15
15
  specs:
16
- activemodel (6.1.0)
17
- activesupport (= 6.1.0)
18
- activesupport (6.1.0)
16
+ Ascii85 (1.1.0)
17
+ activemodel (6.1.4)
18
+ activesupport (= 6.1.4)
19
+ activesupport (6.1.4)
19
20
  concurrent-ruby (~> 1.0, >= 1.0.2)
20
21
  i18n (>= 1.6, < 2)
21
22
  minitest (>= 5.1)
22
23
  tzinfo (~> 2.0)
23
24
  zeitwerk (~> 2.3)
24
- ast (2.4.0)
25
- barby (0.5.1)
26
- br_documents (0.1.3)
25
+ afm (0.2.2)
26
+ ast (2.4.2)
27
+ barby (0.6.8)
28
+ br_documents (0.2.0)
27
29
  activemodel (>= 4.0.0)
28
30
  i18n (>= 0.6.5)
29
31
  byebug (11.1.3)
30
32
  chunky_png (1.4.0)
31
33
  coderay (1.1.3)
32
- concurrent-ruby (1.1.8)
34
+ concurrent-ruby (1.1.9)
33
35
  diff-lcs (1.4.4)
34
- docile (1.3.2)
35
- ffi (1.13.1)
36
- formatador (0.2.5)
36
+ docile (1.4.0)
37
+ ffi (1.15.3)
38
+ formatador (0.3.0)
37
39
  guard (2.16.2)
38
40
  formatador (>= 0.2.4)
39
41
  listen (>= 2.7, < 4.0)
@@ -48,39 +50,50 @@ GEM
48
50
  guard (~> 2.1)
49
51
  guard-compat (~> 1.1)
50
52
  rspec (>= 2.99.0, < 4.0)
51
- i18n (1.8.9)
53
+ hashery (2.1.2)
54
+ i18n (1.8.10)
52
55
  concurrent-ruby (~> 1.0)
53
56
  jaro_winkler (1.5.4)
54
- json (2.3.0)
55
- listen (3.2.1)
57
+ json (2.5.1)
58
+ listen (3.5.1)
56
59
  rb-fsevent (~> 0.10, >= 0.10.3)
57
60
  rb-inotify (~> 0.9, >= 0.9.10)
58
61
  lumberjack (1.2.8)
59
62
  method_source (1.0.0)
63
+ mini_portile2 (2.5.3)
60
64
  minitest (5.14.4)
61
65
  nenv (0.3.0)
62
- nokogiri (1.11.2-x86_64-linux)
66
+ nokogiri (1.11.7)
67
+ mini_portile2 (~> 2.5.0)
63
68
  racc (~> 1.4)
64
69
  notiffany (0.1.3)
65
70
  nenv (~> 0.1)
66
71
  shellany (~> 0.0)
67
- parallel (1.19.1)
68
- parser (2.7.0.4)
69
- ast (~> 2.4.0)
70
- pdf-core (0.8.1)
71
- prawn (2.3.0)
72
- pdf-core (~> 0.8.1)
73
- ttfunk (~> 1.6)
72
+ parallel (1.20.1)
73
+ parser (3.0.2.0)
74
+ ast (~> 2.4.1)
75
+ pdf-core (0.9.0)
76
+ pdf-inspector (1.3.0)
77
+ pdf-reader (>= 1.0, < 3.0.a)
78
+ pdf-reader (2.5.0)
79
+ Ascii85 (~> 1.0)
80
+ afm (~> 0.2.1)
81
+ hashery (~> 2.0)
82
+ ruby-rc4
83
+ ttfunk
84
+ prawn (2.4.0)
85
+ pdf-core (~> 0.9.0)
86
+ ttfunk (~> 1.7)
74
87
  prawn-table (0.2.2)
75
88
  prawn (>= 1.3.0, < 3.0.0)
76
- pry (0.13.1)
89
+ pry (0.14.1)
77
90
  coderay (~> 1.1)
78
91
  method_source (~> 1.0)
79
- psych (3.1.0)
92
+ psych (4.0.1)
80
93
  racc (1.5.2)
81
94
  rainbow (3.0.0)
82
95
  rake (13.0.1)
83
- rb-fsevent (0.10.4)
96
+ rb-fsevent (0.11.0)
84
97
  rb-inotify (0.10.1)
85
98
  ffi (~> 1.0)
86
99
  rqrcode (1.1.2)
@@ -91,15 +104,15 @@ GEM
91
104
  rspec-core (~> 3.10.0)
92
105
  rspec-expectations (~> 3.10.0)
93
106
  rspec-mocks (~> 3.10.0)
94
- rspec-core (3.10.0)
107
+ rspec-core (3.10.1)
95
108
  rspec-support (~> 3.10.0)
96
- rspec-expectations (3.10.0)
109
+ rspec-expectations (3.10.1)
97
110
  diff-lcs (>= 1.2.0, < 2.0)
98
111
  rspec-support (~> 3.10.0)
99
- rspec-mocks (3.10.0)
112
+ rspec-mocks (3.10.2)
100
113
  diff-lcs (>= 1.2.0, < 2.0)
101
114
  rspec-support (~> 3.10.0)
102
- rspec-support (3.10.0)
115
+ rspec-support (3.10.2)
103
116
  rubocop (0.67.0)
104
117
  jaro_winkler (~> 1.5.1)
105
118
  parallel (~> 1.10)
@@ -110,14 +123,15 @@ GEM
110
123
  unicode-display_width (>= 1.4.0, < 1.6)
111
124
  rubocop-performance (1.1.0)
112
125
  rubocop (>= 0.67.0)
113
- ruby-progressbar (1.10.1)
126
+ ruby-progressbar (1.11.0)
127
+ ruby-rc4 (0.1.5)
114
128
  shellany (0.0.1)
115
129
  simplecov (0.17.1)
116
130
  docile (~> 1.1)
117
131
  json (>= 1.8, < 3)
118
132
  simplecov-html (~> 0.10.0)
119
133
  simplecov-html (0.10.2)
120
- thor (1.0.1)
134
+ thor (1.1.0)
121
135
  ttfunk (1.7.0)
122
136
  tzinfo (2.0.4)
123
137
  concurrent-ruby (~> 1.0)
@@ -132,6 +146,7 @@ DEPENDENCIES
132
146
  byebug (= 11.1.3)
133
147
  guard (~> 2.16.2)
134
148
  guard-rspec
149
+ pdf-inspector (~> 1.3.0)
135
150
  rake (= 13.0.1)
136
151
  rspec (= 3.10.0)
137
152
  rubocop (= 0.67.0)
data/Guardfile CHANGED
@@ -1,5 +1,5 @@
1
- guard :rspec, cmd: "bundle exec rspec" do
2
- require "guard/rspec/dsl"
1
+ guard :rspec, cmd: 'bundle exec rspec' do
2
+ require 'guard/rspec/dsl'
3
3
  dsl = Guard::RSpec::Dsl.new(self)
4
4
 
5
5
  # RSpec files
data/README.md CHANGED
@@ -45,6 +45,22 @@ XML version | Supported?
45
45
  end
46
46
  end
47
47
 
48
+ #### Usage in Rails Controller with more than one xml
49
+ class DanfeController < ApplicationController
50
+ def new
51
+ invoices = Invoice.where(ids: params[:ids])
52
+ xmls_as_string = []
53
+
54
+ invoices.each do |invoice|
55
+ xmls_as_string << invoice.generate_xml # your method that generates the NF-e's xml
56
+ end
57
+
58
+ danfe = BrDanfe::Danfe.new(xmls_as_string)
59
+
60
+ send_data danfe.render_pdf, filename: "danfe.pdf", type: "application/pdf"
61
+ end
62
+ end
63
+
48
64
  ### Options
49
65
 
50
66
  * `logo_path`: Path of sender's logo image.
@@ -72,6 +88,29 @@ XML version | Supported?
72
88
  end
73
89
  end
74
90
 
91
+ ### DAMDFE - _Documento Auxiliar do Manifesto Eletrônico de Documentos Fiscais_
92
+
93
+ #### Usage in Ruby
94
+
95
+ xml = File.read("mdfe.xml")
96
+
97
+ mdfe = BrDanfe::Mdfe.new(xml)
98
+ mdfe.save_pdf("mdfe.pdf")
99
+
100
+ #### Usage in Rails Controller
101
+
102
+ class MdfeController < ApplicationController
103
+ def new
104
+ mdfe = Mdfe.find(params[:id])
105
+ xml_as_string = mdfe.generate_xml # your method that generates the MDF-e's xml
106
+
107
+ mdfe = BrDanfe::Mdfe.new(xml_as_string)
108
+
109
+ send_data mdfe.render_pdf, filename: "mdfe.pdf", type: "application/pdf"
110
+ end
111
+ end
112
+
113
+
75
114
  ## I18n
76
115
 
77
116
  By default, your rails application must be configured to `pt-Br`.
data/br_danfe.gemspec CHANGED
@@ -16,21 +16,22 @@ Gem::Specification.new do |spec|
16
16
  spec.require_paths = ['lib']
17
17
  spec.required_ruby_version = '>= 2.5.1'
18
18
 
19
- spec.add_dependency 'barby', '0.5.1'
19
+ spec.add_dependency 'barby', '0.6.8'
20
20
  spec.add_dependency 'br_documents', '>= 0.1.3'
21
21
  spec.add_dependency 'i18n', '>= 0.8.6'
22
22
  spec.add_dependency 'nokogiri', '>= 1.8'
23
- spec.add_dependency 'prawn', '~> 2.0'
23
+ spec.add_dependency 'prawn', '~> 2.4.0'
24
24
  spec.add_dependency 'prawn-table', '0.2.2'
25
25
  spec.add_dependency 'rqrcode', '~> 1.1.1'
26
26
 
27
27
  spec.add_development_dependency 'byebug', '11.1.3'
28
+ spec.add_development_dependency 'guard', '~> 2.16.2'
29
+ spec.add_development_dependency 'guard-rspec'
30
+ spec.add_development_dependency 'pdf-inspector', '~> 1.3.0'
28
31
  spec.add_development_dependency 'rake', '13.0.1'
29
32
  spec.add_development_dependency 'rspec', '3.10.0'
30
33
  spec.add_development_dependency 'rubocop', '0.67.0'
31
34
  spec.add_development_dependency 'rubocop-performance', '~> 1.1.0'
32
35
  spec.add_development_dependency 'simplecov', '0.17.1'
33
36
  spec.add_development_dependency 'simplecov-html', '0.10.2'
34
- spec.add_development_dependency 'guard', '~> 2.16.2'
35
- spec.add_development_dependency 'guard-rspec'
36
37
  end
@@ -151,4 +151,5 @@ pt-BR:
151
151
  '03': "Cartão de Crédito"
152
152
  '04': "Cartão de Débito"
153
153
  '05': "Crédito Loja"
154
+ '15': "Boleto"
154
155
  '99': "Outros"
data/lib/br_danfe.rb CHANGED
@@ -16,6 +16,6 @@ Prawn::Font::AFM.hide_m17n_warning = true
16
16
 
17
17
  module BrDanfe
18
18
  def self.root_path
19
- File.expand_path('../..',__FILE__)
19
+ File.expand_path('../..', __FILE__)
20
20
  end
21
21
  end
@@ -1,12 +1,15 @@
1
1
  module BrDanfe
2
2
  class Danfe
3
- def self.new(xml)
4
- create_danfe BrDanfe::XML.new(xml)
3
+ def self.new(xmls)
4
+ xmls = [xmls] unless xmls.is_a?(Array)
5
+
6
+ parsed_xmls = xmls.map { |xml| BrDanfe::XML.new(xml) }
7
+
8
+ create_danfe(parsed_xmls)
5
9
  end
6
10
 
7
- def self.create_danfe(xml)
8
- nfe_code = '55'
9
- xml['ide > mod'] == nfe_code ? DanfeLib::Nfe.new(xml) : DanfeLib::Nfce.new(xml)
11
+ def self.create_danfe(xmls)
12
+ BrDanfe::Helper.nfe?(xmls.first) ? DanfeLib::Nfe.new(xmls) : DanfeLib::Nfce.new(xmls)
10
13
  end
11
14
  private_class_method :create_danfe
12
15
  end
@@ -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
+ BrDanfe::QrCode.new(pdf: @document, xml: xml, qr_code_tag: xml['qrCode'], box_size: 3.cm).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
@@ -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