br_danfe 0.11.2 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -1
  3. data/Gemfile.lock +31 -31
  4. data/br_danfe.gemspec +6 -5
  5. data/config/locales/pt-BR.yml +8 -0
  6. data/lib/br_danfe/danfe.rb +2 -2
  7. data/lib/br_danfe/danfe_lib/det_body.rb +1 -1
  8. data/lib/br_danfe/danfe_lib/document.rb +1 -1
  9. data/lib/br_danfe/danfe_lib/emit_header.rb +2 -2
  10. data/lib/br_danfe/danfe_lib/helper.rb +1 -27
  11. data/lib/br_danfe/danfe_lib/infadic.rb +1 -1
  12. data/lib/br_danfe/danfe_lib/xprod.rb +15 -15
  13. data/lib/br_danfe/danfe_nfce.rb +43 -0
  14. data/lib/br_danfe/danfe_nfce_lib/document.rb +35 -0
  15. data/lib/br_danfe/danfe_nfce_lib/footer.rb +15 -0
  16. data/lib/br_danfe/danfe_nfce_lib/header.rb +67 -0
  17. data/lib/br_danfe/danfe_nfce_lib/helper.rb +9 -0
  18. data/lib/br_danfe/danfe_nfce_lib/key.rb +18 -0
  19. data/lib/br_danfe/danfe_nfce_lib/nfce_identification.rb +20 -0
  20. data/lib/br_danfe/danfe_nfce_lib/product_list.rb +100 -0
  21. data/lib/br_danfe/danfe_nfce_lib/qr_code.rb +23 -0
  22. data/lib/br_danfe/danfe_nfce_lib/recipient.rb +72 -0
  23. data/lib/br_danfe/danfe_nfce_lib/total_list.rb +78 -0
  24. data/lib/br_danfe/helper.rb +29 -0
  25. data/lib/br_danfe/{danfe_lib/options.rb → logo_config.rb} +2 -2
  26. data/lib/br_danfe/{danfe_lib/logo_options.rb → logo_options.rb} +2 -2
  27. data/lib/br_danfe/version.rb +1 -1
  28. data/lib/br_danfe/xml.rb +36 -0
  29. data/spec/features/danfe_nfce_spec.rb +31 -0
  30. data/spec/fixtures/nfce/lib/document#render.pdf +99 -0
  31. data/spec/fixtures/nfce/lib/footer#render.pdf +74 -0
  32. data/spec/fixtures/nfce/lib/header#render-homologation.pdf +0 -0
  33. data/spec/fixtures/nfce/lib/header#render-long_name_with_logo.pdf +0 -0
  34. data/spec/fixtures/nfce/lib/header#render-long_name_without_logo.pdf +118 -0
  35. data/spec/fixtures/nfce/lib/header#render-short_name_with_logo.pdf +0 -0
  36. data/spec/fixtures/nfce/lib/header#render-short_name_without_logo.pdf +118 -0
  37. data/spec/fixtures/nfce/lib/key#render.pdf +104 -0
  38. data/spec/fixtures/nfce/lib/nfce_identification#render.pdf +118 -0
  39. data/spec/fixtures/nfce/lib/product_list#render-with_many_products.pdf +307 -0
  40. data/spec/fixtures/nfce/lib/product_list#render-with_many_products_and_long_names.pdf +335 -0
  41. data/spec/fixtures/nfce/lib/product_list#render-with_single_product.pdf +181 -0
  42. data/spec/fixtures/nfce/lib/product_list#render-with_single_product_and_long_name.pdf +195 -0
  43. data/spec/fixtures/nfce/lib/product_list_with_many_products.xml +367 -0
  44. data/spec/fixtures/nfce/lib/product_list_with_many_products_and_long_names.xml +367 -0
  45. data/spec/fixtures/nfce/lib/product_list_with_single_product.xml +238 -0
  46. data/spec/fixtures/nfce/lib/product_list_with_single_product_and_long_name.xml +238 -0
  47. data/spec/fixtures/nfce/lib/qr_code#render.pdf +0 -0
  48. data/spec/fixtures/nfce/lib/recipient#render-company.pdf +95 -0
  49. data/spec/fixtures/nfce/lib/recipient#render-consumer_without_document.pdf +88 -0
  50. data/spec/fixtures/nfce/lib/recipient#render-foreign.pdf +95 -0
  51. data/spec/fixtures/nfce/lib/recipient#render-individual.pdf +95 -0
  52. data/spec/fixtures/nfce/lib/recipient#render-unidentified_consumer.pdf +81 -0
  53. data/spec/fixtures/nfce/lib/total_list#does_not_render-payment_methods.pdf +139 -0
  54. data/spec/fixtures/nfce/lib/total_list#render-grouped_payment_methods.pdf +188 -0
  55. data/spec/fixtures/nfce/lib/total_list#render-totals.pdf +139 -0
  56. data/spec/fixtures/nfce/lib/total_list#render-without_payment.pdf +202 -0
  57. data/spec/fixtures/nfce/lib/total_list#render.pdf +202 -0
  58. data/spec/fixtures/nfce/v4.00/nfce.xml +367 -0
  59. data/spec/fixtures/nfce/v4.00/rendered_nfce.fixture.pdf +0 -0
  60. data/spec/fixtures/nfce/v4.00/saved_nfce.fixture.pdf +0 -0
  61. data/spec/lib/danfe_lib/dest_spec.rb +1 -1
  62. data/spec/lib/danfe_lib/det_body_spec.rb +1 -1
  63. data/spec/lib/danfe_lib/document_spec.rb +1 -1
  64. data/spec/lib/danfe_lib/dup_spec.rb +1 -1
  65. data/spec/lib/danfe_lib/emit_header_spec.rb +1 -1
  66. data/spec/lib/danfe_lib/helper_spec.rb +0 -54
  67. data/spec/lib/danfe_lib/icmstot_spec.rb +1 -1
  68. data/spec/lib/danfe_lib/infadic_spec.rb +1 -1
  69. data/spec/lib/danfe_lib/infadic_vol_spec.rb +1 -1
  70. data/spec/lib/danfe_lib/issqn_spec.rb +1 -1
  71. data/spec/lib/danfe_lib/ticket_spec.rb +1 -1
  72. data/spec/lib/danfe_lib/transp_spec.rb +1 -1
  73. data/spec/lib/danfe_lib/vol_spec.rb +1 -1
  74. data/spec/lib/danfe_nfce_lib/document_spec.rb +19 -0
  75. data/spec/lib/danfe_nfce_lib/footer_spec.rb +42 -0
  76. data/spec/lib/danfe_nfce_lib/header_spec.rb +117 -0
  77. data/spec/lib/danfe_nfce_lib/helper_spec.rb +28 -0
  78. data/spec/lib/danfe_nfce_lib/key_spec.rb +45 -0
  79. data/spec/lib/danfe_nfce_lib/nfce_identification_spec.rb +48 -0
  80. data/spec/lib/danfe_nfce_lib/product_list_spec.rb +66 -0
  81. data/spec/lib/danfe_nfce_lib/qr_code_spec.rb +35 -0
  82. data/spec/lib/danfe_nfce_lib/recipient_spec.rb +163 -0
  83. data/spec/lib/danfe_nfce_lib/total_list_spec.rb +188 -0
  84. data/spec/lib/helper_spec.rb +102 -0
  85. data/spec/lib/logo_config_spec.rb +21 -0
  86. data/spec/lib/{danfe_lib/logo_options_spec.rb → logo_options_spec.rb} +8 -22
  87. data/spec/lib/{danfe_lib/xml_spec.rb → xml_spec.rb} +2 -2
  88. metadata +87 -18
  89. data/lib/br_danfe/danfe_lib/xml.rb +0 -38
  90. data/spec/lib/danfe_lib/options_spec.rb +0 -17
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1de518d313ceb76285fe9d9a589c48c540bf07fe76f9bcc72692db92e8217973
4
- data.tar.gz: 54b2de6012f183a7157ade8e1deae69c2b3209eabdf908c7b81aafc9baa127b0
3
+ metadata.gz: 5cd433faef1825ca17e8d78402e1da989d49892e72117de419b1796c44dd5e1c
4
+ data.tar.gz: e6ee223222a06b5ed6ea4fceeeaa3bab2c098bc94037d30820213ada45ad2787
5
5
  SHA512:
6
- metadata.gz: aa8a9756f5436acf1580bf6f183e742c3c2335bd8e6884200d094780d0ba12542ce42d4e2dd25641b36774a480f1eb22590fdee2f06e34511279ab99f8ece74c
7
- data.tar.gz: f92b7ea6440380459596aa37fb7e2647b36daf0a049bc0e0841343a59797d5f5de4266818dbc4fb5b3254a6ba944e2e289a74b019d36120221bfcca29245685a
6
+ metadata.gz: 60747ea771d0a2c071521cbdbdb14efea046f40d4e3913d9af9e31988debb2896bfaedca4fb68d63b5e67109bba42b348cde79a19640704c73626d72cbd89f59
7
+ data.tar.gz: fc22d61bde7c2ce878e058b304ad0d2c7f1654eb65e8fba62b7f499ee0b64d305fe477d56e3b73ea24978088e5c215241402f7ce4558e130ed5f770195d9c664
data/.gitignore CHANGED
@@ -4,4 +4,6 @@
4
4
  pkg
5
5
  output.pdf
6
6
  coverage
7
- .tool-versions
7
+ .tool-versions
8
+ .DS_Store
9
+ .byebug_history
@@ -1,20 +1,21 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- br_danfe (0.11.2)
4
+ br_danfe (0.12.0)
5
5
  barby (= 0.5.1)
6
6
  br_documents (>= 0.1.3)
7
7
  i18n (>= 0.8.6)
8
8
  nokogiri (>= 1.8)
9
9
  prawn (~> 2.0)
10
10
  prawn-table (= 0.2.2)
11
+ rqrcode (~> 1.1.1)
11
12
 
12
13
  GEM
13
14
  remote: https://rubygems.org/
14
15
  specs:
15
- activemodel (6.0.2.1)
16
- activesupport (= 6.0.2.1)
17
- activesupport (6.0.2.1)
16
+ activemodel (6.0.2.2)
17
+ activesupport (= 6.0.2.2)
18
+ activesupport (6.0.2.2)
18
19
  concurrent-ruby (~> 1.0, >= 1.0.2)
19
20
  i18n (>= 0.7, < 2)
20
21
  minitest (~> 5.1)
@@ -25,19 +26,15 @@ GEM
25
26
  br_documents (0.1.3)
26
27
  activemodel (>= 4.0.0)
27
28
  i18n (>= 0.6.5)
28
- byebug (3.5.1)
29
- columnize (~> 0.8)
30
- debugger-linecache (~> 1.2)
31
- slop (~> 3.6)
32
- columnize (0.9.0)
29
+ byebug (11.1.1)
30
+ chunky_png (1.3.11)
33
31
  concurrent-ruby (1.1.6)
34
- debugger-linecache (1.2.0)
35
32
  diff-lcs (1.3)
36
33
  docile (1.3.2)
37
34
  i18n (1.8.2)
38
35
  concurrent-ruby (~> 1.0)
39
36
  jaro_winkler (1.5.4)
40
- json (2.2.0)
37
+ json (2.3.0)
41
38
  mini_portile2 (2.4.0)
42
39
  minitest (5.14.0)
43
40
  nokogiri (1.10.9)
@@ -53,20 +50,24 @@ GEM
53
50
  prawn (>= 1.3.0, < 3.0.0)
54
51
  psych (3.1.0)
55
52
  rainbow (3.0.0)
56
- rake (12.0.0)
57
- rspec (3.6.0)
58
- rspec-core (~> 3.6.0)
59
- rspec-expectations (~> 3.6.0)
60
- rspec-mocks (~> 3.6.0)
61
- rspec-core (3.6.0)
62
- rspec-support (~> 3.6.0)
63
- rspec-expectations (3.6.0)
53
+ rake (13.0.1)
54
+ rqrcode (1.1.2)
55
+ chunky_png (~> 1.0)
56
+ rqrcode_core (~> 0.1)
57
+ rqrcode_core (0.1.2)
58
+ rspec (3.9.0)
59
+ rspec-core (~> 3.9.0)
60
+ rspec-expectations (~> 3.9.0)
61
+ rspec-mocks (~> 3.9.0)
62
+ rspec-core (3.9.1)
63
+ rspec-support (~> 3.9.1)
64
+ rspec-expectations (3.9.1)
64
65
  diff-lcs (>= 1.2.0, < 2.0)
65
- rspec-support (~> 3.6.0)
66
- rspec-mocks (3.6.0)
66
+ rspec-support (~> 3.9.0)
67
+ rspec-mocks (3.9.1)
67
68
  diff-lcs (>= 1.2.0, < 2.0)
68
- rspec-support (~> 3.6.0)
69
- rspec-support (3.6.0)
69
+ rspec-support (~> 3.9.0)
70
+ rspec-support (3.9.2)
70
71
  rubocop (0.67.0)
71
72
  jaro_winkler (~> 1.5.1)
72
73
  parallel (~> 1.10)
@@ -78,12 +79,11 @@ GEM
78
79
  rubocop-performance (1.1.0)
79
80
  rubocop (>= 0.67.0)
80
81
  ruby-progressbar (1.10.1)
81
- simplecov (0.17.0)
82
+ simplecov (0.17.1)
82
83
  docile (~> 1.1)
83
84
  json (>= 1.8, < 3)
84
85
  simplecov-html (~> 0.10.0)
85
- simplecov-html (0.10.1)
86
- slop (3.6.0)
86
+ simplecov-html (0.10.2)
87
87
  thread_safe (0.3.6)
88
88
  ttfunk (1.6.2.1)
89
89
  tzinfo (1.2.6)
@@ -96,13 +96,13 @@ PLATFORMS
96
96
 
97
97
  DEPENDENCIES
98
98
  br_danfe!
99
- byebug (= 3.5.1)
100
- rake (= 12.0.0)
101
- rspec (= 3.6.0)
99
+ byebug (= 11.1.1)
100
+ rake (= 13.0.1)
101
+ rspec (= 3.9.0)
102
102
  rubocop (= 0.67.0)
103
103
  rubocop-performance (~> 1.1.0)
104
- simplecov (= 0.17.0)
105
- simplecov-html (= 0.10.1)
104
+ simplecov (= 0.17.1)
105
+ simplecov-html (= 0.10.2)
106
106
 
107
107
  BUNDLED WITH
108
108
  1.17.3
@@ -22,12 +22,13 @@ Gem::Specification.new do |spec|
22
22
  spec.add_dependency 'nokogiri', '>= 1.8'
23
23
  spec.add_dependency 'prawn', '~> 2.0'
24
24
  spec.add_dependency 'prawn-table', '0.2.2'
25
+ spec.add_dependency 'rqrcode', '~> 1.1.1'
25
26
 
26
- spec.add_development_dependency 'byebug', '3.5.1'
27
- spec.add_development_dependency 'rake', '12.0.0'
28
- spec.add_development_dependency 'rspec', '3.6.0'
27
+ spec.add_development_dependency 'byebug', '11.1.1'
28
+ spec.add_development_dependency 'rake', '13.0.1'
29
+ spec.add_development_dependency 'rspec', '3.9.0'
29
30
  spec.add_development_dependency 'rubocop', '0.67.0'
30
31
  spec.add_development_dependency 'rubocop-performance', '~> 1.1.0'
31
- spec.add_development_dependency 'simplecov', '0.17.0'
32
- spec.add_development_dependency 'simplecov-html', '0.10.1'
32
+ spec.add_development_dependency 'simplecov', '0.17.1'
33
+ spec.add_development_dependency 'simplecov-html', '0.10.2'
33
34
  end
@@ -144,3 +144,11 @@ pt-BR:
144
144
  received_at: "DATA DE RECEBIMENTO"
145
145
  receiver: "IDENTIFICAÇÃO E ASSINATURA DO RECEBEDOR"
146
146
  document: "NF-e\nN°. %{nNF}\nSÉRIE %{serie}"
147
+ nfce:
148
+ payment_methods:
149
+ '01': "Dinheiro"
150
+ '02': "Cheque"
151
+ '03': "Cartão de Crédito"
152
+ '04': "Cartão de Débito"
153
+ '05': "Crédito Loja"
154
+ '99': "Outros"
@@ -3,9 +3,9 @@ module BrDanfe
3
3
  attr_reader :options
4
4
 
5
5
  def initialize(xml)
6
- @xml = DanfeLib::XML.new(xml)
6
+ @xml = BrDanfe::XML.new(xml)
7
7
  @pdf = DanfeLib::Document.new
8
- @options = DanfeLib::Options.new
8
+ @options = BrDanfe::Logo::Config.new
9
9
 
10
10
  create_watermark
11
11
  end
@@ -95,7 +95,7 @@ module BrDanfe
95
95
  end
96
96
 
97
97
  def numerify(det, xpath)
98
- Helper.numerify(det.css(xpath.to_s).text)
98
+ BrDanfe::Helper.numerify(det.css(xpath.to_s).text)
99
99
  end
100
100
 
101
101
  def create_row(data)
@@ -107,7 +107,7 @@ module BrDanfe
107
107
  private
108
108
 
109
109
  def numeric(at, w, h, title = '', info = '', options = {})
110
- info = Helper.numerify(info) if info != ''
110
+ info = BrDanfe::Helper.numerify(info) if info != ''
111
111
  box at, w, h, title, info, options.merge({ align: :right })
112
112
  end
113
113
 
@@ -54,7 +54,7 @@ module BrDanfe
54
54
 
55
55
  def logo
56
56
  bounding_box_size = 80
57
- logo_options = BrDanfe::DanfeLib::LogoOptions.new(bounding_box_size, @logo_dimensions).options
57
+ logo_options = BrDanfe::Logo::Options.new(bounding_box_size, @logo_dimensions).options
58
58
 
59
59
  @pdf.bounding_box(
60
60
  [0.83.cm, Helper.invert(@y_position.cm + 1.02.cm)], width: bounding_box_size, height: bounding_box_size
@@ -104,7 +104,7 @@ module BrDanfe
104
104
 
105
105
  @pdf.lbox LINE_HEIGHT, 10.04, 0.75, y_first_line, @xml, 'ide/natOp'
106
106
  @pdf.ibox LINE_HEIGHT, 9.52, 10.79, y_first_line, I18n.t('danfe.infProt'),
107
- "#{@xml['infProt/nProt']} #{Helper.format_datetime(@xml['infProt/dhRecbto'])}", { align: :center }
107
+ "#{@xml['infProt/nProt']} #{BrDanfe::Helper.format_datetime(@xml['infProt/dhRecbto'])}", { align: :center }
108
108
 
109
109
  @pdf.lie LINE_HEIGHT, 6.36, 0.75, y_second_line, @xml, 'enderEmit/UF', 'emit/IE'
110
110
  @pdf.lie LINE_HEIGHT, 6.86, 7.11, y_second_line, @xml, 'enderDest/UF', 'emit/IEST'
@@ -1,32 +1,10 @@
1
1
  module BrDanfe
2
2
  module DanfeLib
3
3
  class Helper
4
- def self.numerify(number)
5
- return '' if !number || number == ''
6
-
7
- separated_number = number.to_s.split('.')
8
- integer_part = separated_number[0].reverse.gsub(/\d{3}(?=\d)/, '\&.').reverse
9
- decimal_part = separated_number[1] || '00'
10
- decimal_part += '0' if decimal_part.size < 2
11
-
12
- integer_part + ',' + decimal_part
13
- end
14
-
15
4
  def self.invert(y)
16
5
  29.7.cm - y
17
6
  end
18
7
 
19
- def self.format_datetime(xml_datetime)
20
- formated = ''
21
-
22
- unless xml_datetime.empty?
23
- date = DateTime.strptime(xml_datetime, '%Y-%m-%dT%H:%M:%S')
24
- formated = date.strftime('%d/%m/%Y %H:%M:%S')
25
- end
26
-
27
- formated
28
- end
29
-
30
8
  def self.format_date(xml_datetime)
31
9
  formated = ''
32
10
 
@@ -52,11 +30,7 @@ module BrDanfe
52
30
  end
53
31
 
54
32
  def self.no_fiscal_value?(xml)
55
- homologation?(xml) || unauthorized?(xml)
56
- end
57
-
58
- def self.homologation?(xml)
59
- xml_text(xml, 'nfeProc/NFe/infNFe/ide/tpAmb') == '2'
33
+ BrDanfe::Helper.homologation?(xml) || unauthorized?(xml)
60
34
  end
61
35
 
62
36
  def self.unauthorized?(xml)
@@ -72,7 +72,7 @@ module BrDanfe
72
72
  end
73
73
 
74
74
  def numerify(value)
75
- Helper.numerify(value) if value != ''
75
+ BrDanfe::Helper.numerify(value) if value != ''
76
76
  end
77
77
 
78
78
  def difal?
@@ -39,10 +39,10 @@ module BrDanfe
39
39
 
40
40
  def icms_st
41
41
  "\n#{I18n.t('danfe.det.prod.xProdST',
42
- pMVAST: Helper.numerify(@det.css('ICMS/*/pMVAST').text),
43
- pICMSST: Helper.numerify(@det.css('ICMS/*/pICMSST').text),
44
- vBCST: Helper.numerify(@det.css('ICMS/*/vBCST').text),
45
- vICMSST: Helper.numerify(@det.css('ICMS/*/vICMSST').text))}"
42
+ pMVAST: BrDanfe::Helper.numerify(@det.css('ICMS/*/pMVAST').text),
43
+ pICMSST: BrDanfe::Helper.numerify(@det.css('ICMS/*/pICMSST').text),
44
+ vBCST: BrDanfe::Helper.numerify(@det.css('ICMS/*/vBCST').text),
45
+ vICMSST: BrDanfe::Helper.numerify(@det.css('ICMS/*/vICMSST').text))}"
46
46
  end
47
47
 
48
48
  def icms_st?
@@ -63,15 +63,15 @@ module BrDanfe
63
63
 
64
64
  def fcp_for_icms00
65
65
  "\n#{I18n.t('danfe.det.prod.xProdFCPICMS00',
66
- vFCP: Helper.numerify(@det.css('ICMS00/vFCP').text),
67
- pFCP: Helper.numerify(@det.css('ICMS00/pFCP').text))}"
66
+ vFCP: BrDanfe::Helper.numerify(@det.css('ICMS00/vFCP').text),
67
+ pFCP: BrDanfe::Helper.numerify(@det.css('ICMS00/pFCP').text))}"
68
68
  end
69
69
 
70
70
  def fcp_complete
71
71
  "\n#{I18n.t('danfe.det.prod.xProdFCP',
72
- vBCFCP: Helper.numerify(@det.css('ICMS/*/vBCFCP').text),
73
- vFCP: Helper.numerify(@det.css('ICMS/*/vFCP').text),
74
- pFCP: Helper.numerify(@det.css('ICMS/*/pFCP').text))}"
72
+ vBCFCP: BrDanfe::Helper.numerify(@det.css('ICMS/*/vBCFCP').text),
73
+ vFCP: BrDanfe::Helper.numerify(@det.css('ICMS/*/vFCP').text),
74
+ pFCP: BrDanfe::Helper.numerify(@det.css('ICMS/*/pFCP').text))}"
75
75
  end
76
76
 
77
77
  def fcp_st?
@@ -80,9 +80,9 @@ module BrDanfe
80
80
 
81
81
  def fcp_st
82
82
  "\n#{I18n.t('danfe.det.prod.xProdFCPST',
83
- vBCFCPST: Helper.numerify(@det.css('ICMS/*/vBCFCPST').text),
84
- pFCPST: Helper.numerify(@det.css('ICMS/*/pFCPST').text),
85
- vFCPST: Helper.numerify(@det.css('ICMS/*/vFCPST').text))}"
83
+ vBCFCPST: BrDanfe::Helper.numerify(@det.css('ICMS/*/vBCFCPST').text),
84
+ pFCPST: BrDanfe::Helper.numerify(@det.css('ICMS/*/pFCPST').text),
85
+ vFCPST: BrDanfe::Helper.numerify(@det.css('ICMS/*/vFCPST').text))}"
86
86
  end
87
87
 
88
88
  def add_icms_st_ret_to_product
@@ -97,9 +97,9 @@ module BrDanfe
97
97
  def icms_st_ret
98
98
  "\n#{I18n.t(
99
99
  'danfe.det.prod.xProdSTRet',
100
- vBCSTRet: Helper.numerify(@det.css('ICMS/*/vBCSTRet').text),
101
- vICMSSTRet: Helper.numerify(@det.css('ICMS/*/vICMSSTRet').text),
102
- pST: Helper.numerify(@det.css('ICMS/*/pST').text)
100
+ vBCSTRet: BrDanfe::Helper.numerify(@det.css('ICMS/*/vBCSTRet').text),
101
+ vICMSSTRet: BrDanfe::Helper.numerify(@det.css('ICMS/*/vICMSSTRet').text),
102
+ pST: BrDanfe::Helper.numerify(@det.css('ICMS/*/pST').text)
103
103
  )}"
104
104
  end
105
105
  end
@@ -0,0 +1,43 @@
1
+ module BrDanfe
2
+ class DanfeNfce
3
+ PAGE_WIDTH = 8.cm
4
+ PAGE_HEIGHT = 100.cm
5
+
6
+ attr_reader :options
7
+
8
+ def initialize(xml)
9
+ @xml = BrDanfe::XML.new(xml)
10
+ @pdf = DanfeNfceLib::Document.new(PAGE_WIDTH, PAGE_HEIGHT)
11
+ @options = BrDanfe::Logo::Config.new
12
+ end
13
+
14
+ def save_pdf(filename)
15
+ generate
16
+ @pdf.render_file filename
17
+ end
18
+
19
+ def render_pdf
20
+ generate
21
+ @pdf.render
22
+ end
23
+
24
+ private
25
+
26
+ def generate
27
+ DanfeNfceLib::Header.new(@pdf, @xml, @options.logo, @options.logo_dimensions).render
28
+ DanfeNfceLib::ProductList.new(@pdf, @xml).render
29
+ DanfeNfceLib::TotalList.new(@pdf, @xml).render
30
+ DanfeNfceLib::Key.new(@pdf, @xml).render
31
+ DanfeNfceLib::Recipient.new(@pdf, @xml).render
32
+ DanfeNfceLib::NfceIdentification.new(@pdf, @xml).render
33
+ DanfeNfceLib::QrCode.new(@pdf, @xml).render
34
+ DanfeNfceLib::Footer.new(@pdf, @xml).render
35
+
36
+ resize_page_height
37
+ end
38
+
39
+ def resize_page_height
40
+ @pdf.page.dictionary.data[:MediaBox] = [0, @pdf.y - 10, PAGE_WIDTH, PAGE_HEIGHT]
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,35 @@
1
+ module BrDanfe
2
+ module DanfeNfceLib
3
+ class Document
4
+ def initialize(page_width, page_height)
5
+ @document = Prawn::Document.new(
6
+ page_size: [page_width, page_height],
7
+ page_layout: :portrait,
8
+ left_margin: 0.3.cm,
9
+ right_margin: 0.3.cm,
10
+ top_margin: 0.3.cm,
11
+ botton_margin: 0
12
+ )
13
+
14
+ @document.font 'Courier'
15
+ @document.line_width = 0.3
16
+ end
17
+
18
+ def render_blank_line(font_size = 6)
19
+ @document.text ' ', size: font_size
20
+ end
21
+
22
+ def method_missing(method_name, *args, &block)
23
+ if @document.respond_to? method_name
24
+ @document.send method_name, *args, &block
25
+ else
26
+ super
27
+ end
28
+ end
29
+
30
+ def respond_to_missing?(method_name, include_private = false)
31
+ @document.respond_to?(method_name, include_private) || super
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,15 @@
1
+ module BrDanfe
2
+ module DanfeNfceLib
3
+ class Footer
4
+ def initialize(pdf, xml)
5
+ @pdf = pdf
6
+ @xml = xml
7
+ end
8
+
9
+ def render
10
+ tot_trib = @xml['ICMSTot/vTotTrib'].present? ? BrDanfe::Helper.numerify(@xml['ICMSTot/vTotTrib']) : '0,00'
11
+ @pdf.text "Tributos Totais Incidentes (Lei Federal 12.741/2012): R$ #{tot_trib}", size: 5, align: :center
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,67 @@
1
+ module BrDanfe
2
+ module DanfeNfceLib
3
+ class Header
4
+ def initialize(pdf, xml, logo, logo_dimensions)
5
+ @pdf = pdf
6
+ @xml = xml
7
+ @logo = logo
8
+ @logo_dimensions = logo_dimensions
9
+ end
10
+
11
+ def render
12
+ cursor = @pdf.cursor
13
+
14
+ render_company_info(cursor)
15
+ render_logo(cursor) if @logo.present?
16
+
17
+ render_homologation if BrDanfe::Helper.homologation?(@xml)
18
+ end
19
+
20
+ private
21
+
22
+ def render_company_info(cursor)
23
+ one_line = 1
24
+
25
+ @pdf.bounding_box([x_position, cursor], width: width_box, height: 45) do
26
+ @pdf.text "#{@xml['emit/xNome']}", size: 7, align: :left, style: :bold
27
+ @pdf.text cnpj(@xml['emit/CNPJ']), size: 6, align: :left
28
+ @pdf.text BrDanfe::DanfeNfceLib::Helper.address(@xml.css('enderEmit')), size: 6, align: :left
29
+ @pdf.render_blank_line if count_name_lines(@xml['emit/xNome']) == one_line
30
+ @pdf.text 'Documento Auxiliar da Nota Fiscal de Consumidor Eletrônica', size: 6, align: :left
31
+ end
32
+ end
33
+
34
+ def x_position
35
+ @logo.present? ? 1.7.cm : 0
36
+ end
37
+
38
+ def width_box
39
+ @logo.present? ? 5.7.cm : 7.4.cm
40
+ end
41
+
42
+ def cnpj(info)
43
+ cnpj = BrDocuments::CnpjCpf::Cnpj.new info
44
+ data = "CNPJ: #{cnpj.valid? ? cnpj.formatted : ''}"
45
+ data
46
+ end
47
+
48
+ def count_name_lines(company_name)
49
+ company_name.scan(/([\s\S]{1,38}( |$)|[\s\S]{1,38})/).length
50
+ end
51
+
52
+ def render_logo(cursor)
53
+ box_size = 45
54
+ logo_options = BrDanfe::Logo::Options.new(box_size, @logo_dimensions).options
55
+
56
+ @pdf.bounding_box([0, cursor], width: box_size, height: box_size) do
57
+ @pdf.image @logo, logo_options
58
+ end
59
+ end
60
+
61
+ def render_homologation
62
+ @pdf.render_blank_line
63
+ @pdf.text 'EMITIDA EM AMBIENTE DE HOMOLOGAÇÃO – SEM VALOR FISCAL', size: 7, align: :center, style: :bold
64
+ end
65
+ end
66
+ end
67
+ end