br_danfe 0.12.1 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (123) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +15 -25
  3. data/Gemfile.lock +1 -1
  4. data/README.md +5 -5
  5. data/lib/br_danfe.rb +0 -1
  6. data/lib/br_danfe/danfe.rb +6 -90
  7. data/lib/br_danfe/danfe_lib/base.rb +33 -0
  8. data/lib/br_danfe/danfe_lib/nfce.rb +49 -0
  9. data/lib/br_danfe/danfe_lib/nfce_lib/document.rb +37 -0
  10. data/lib/br_danfe/danfe_lib/nfce_lib/footer.rb +22 -0
  11. data/lib/br_danfe/danfe_lib/nfce_lib/header.rb +69 -0
  12. data/lib/br_danfe/danfe_lib/nfce_lib/helper.rb +11 -0
  13. data/lib/br_danfe/danfe_lib/nfce_lib/key.rb +20 -0
  14. data/lib/br_danfe/danfe_lib/nfce_lib/nfce_identification.rb +22 -0
  15. data/lib/br_danfe/danfe_lib/nfce_lib/product_list.rb +102 -0
  16. data/lib/br_danfe/danfe_lib/nfce_lib/qr_code.rb +25 -0
  17. data/lib/br_danfe/danfe_lib/nfce_lib/recipient.rb +75 -0
  18. data/lib/br_danfe/danfe_lib/nfce_lib/total_list.rb +81 -0
  19. data/lib/br_danfe/danfe_lib/nfe.rb +83 -0
  20. data/lib/br_danfe/danfe_lib/nfe_lib/cep.rb +11 -0
  21. data/lib/br_danfe/danfe_lib/nfe_lib/consts.rb +8 -0
  22. data/lib/br_danfe/danfe_lib/nfe_lib/cst.rb +34 -0
  23. data/lib/br_danfe/danfe_lib/nfe_lib/dest.rb +96 -0
  24. data/lib/br_danfe/danfe_lib/nfe_lib/det_body.rb +137 -0
  25. data/lib/br_danfe/danfe_lib/nfe_lib/document.rb +142 -0
  26. data/lib/br_danfe/danfe_lib/nfe_lib/dup.rb +55 -0
  27. data/lib/br_danfe/danfe_lib/nfe_lib/emit_header.rb +117 -0
  28. data/lib/br_danfe/danfe_lib/nfe_lib/helper.rb +55 -0
  29. data/lib/br_danfe/danfe_lib/nfe_lib/icmstot.rb +35 -0
  30. data/lib/br_danfe/danfe_lib/nfe_lib/infadic.rb +109 -0
  31. data/lib/br_danfe/danfe_lib/nfe_lib/infadic_vol.rb +103 -0
  32. data/lib/br_danfe/danfe_lib/nfe_lib/issqn.rb +37 -0
  33. data/lib/br_danfe/danfe_lib/nfe_lib/phone.rb +15 -0
  34. data/lib/br_danfe/danfe_lib/nfe_lib/plate.rb +11 -0
  35. data/lib/br_danfe/danfe_lib/nfe_lib/ticket.rb +21 -0
  36. data/lib/br_danfe/danfe_lib/nfe_lib/transp.rb +58 -0
  37. data/lib/br_danfe/danfe_lib/nfe_lib/vol.rb +44 -0
  38. data/lib/br_danfe/danfe_lib/nfe_lib/xprod.rb +109 -0
  39. data/lib/br_danfe/helper.rb +8 -0
  40. data/lib/br_danfe/version.rb +1 -1
  41. data/spec/{lib → br_danfe}/cce_lib/barcode_spec.rb +0 -0
  42. data/spec/{lib → br_danfe}/cce_lib/correction_spec.rb +0 -0
  43. data/spec/{lib → br_danfe}/cce_lib/document_spec.rb +0 -0
  44. data/spec/{lib → br_danfe}/cce_lib/footer_spec.rb +0 -0
  45. data/spec/{lib → br_danfe}/cce_lib/header_spec.rb +0 -0
  46. data/spec/{lib → br_danfe}/cce_lib/nfe_key_spec.rb +0 -0
  47. data/spec/{lib → br_danfe}/cce_lib/protocol_spec.rb +0 -0
  48. data/spec/{features → br_danfe}/cce_spec.rb +0 -0
  49. data/spec/{lib/danfe_nfce_lib → br_danfe/danfe_lib/nfce_lib}/document_spec.rb +2 -2
  50. data/spec/{lib/danfe_nfce_lib → br_danfe/danfe_lib/nfce_lib}/footer_spec.rb +2 -2
  51. data/spec/{lib/danfe_nfce_lib → br_danfe/danfe_lib/nfce_lib}/header_spec.rb +2 -2
  52. data/spec/{lib/danfe_nfce_lib → br_danfe/danfe_lib/nfce_lib}/helper_spec.rb +1 -1
  53. data/spec/{lib/danfe_nfce_lib → br_danfe/danfe_lib/nfce_lib}/key_spec.rb +2 -2
  54. data/spec/{lib/danfe_nfce_lib → br_danfe/danfe_lib/nfce_lib}/nfce_identification_spec.rb +2 -2
  55. data/spec/{lib/danfe_nfce_lib → br_danfe/danfe_lib/nfce_lib}/product_list_spec.rb +2 -2
  56. data/spec/{lib/danfe_nfce_lib → br_danfe/danfe_lib/nfce_lib}/qr_code_spec.rb +2 -2
  57. data/spec/{lib/danfe_nfce_lib → br_danfe/danfe_lib/nfce_lib}/recipient_spec.rb +7 -7
  58. data/spec/{lib/danfe_nfce_lib → br_danfe/danfe_lib/nfce_lib}/total_list_spec.rb +4 -4
  59. data/spec/br_danfe/danfe_lib/nfce_spec.rb +57 -0
  60. data/spec/{lib/danfe_lib → br_danfe/danfe_lib/nfe_lib}/cep_spec.rb +2 -2
  61. data/spec/{lib/danfe_lib → br_danfe/danfe_lib/nfe_lib}/cst_spec.rb +3 -3
  62. data/spec/{lib/danfe_lib → br_danfe/danfe_lib/nfe_lib}/dest_spec.rb +2 -2
  63. data/spec/{lib/danfe_lib → br_danfe/danfe_lib/nfe_lib}/det_body_spec.rb +2 -2
  64. data/spec/{lib/danfe_lib → br_danfe/danfe_lib/nfe_lib}/document_spec.rb +1 -1
  65. data/spec/{lib/danfe_lib → br_danfe/danfe_lib/nfe_lib}/dup_spec.rb +2 -2
  66. data/spec/{lib/danfe_lib → br_danfe/danfe_lib/nfe_lib}/emit_header_spec.rb +3 -3
  67. data/spec/{lib/danfe_lib → br_danfe/danfe_lib/nfe_lib}/helper_spec.rb +13 -87
  68. data/spec/{lib/danfe_lib → br_danfe/danfe_lib/nfe_lib}/icmstot_spec.rb +2 -2
  69. data/spec/{lib/danfe_lib → br_danfe/danfe_lib/nfe_lib}/infadic_spec.rb +2 -2
  70. data/spec/{lib/danfe_lib → br_danfe/danfe_lib/nfe_lib}/infadic_vol_spec.rb +2 -2
  71. data/spec/{lib/danfe_lib → br_danfe/danfe_lib/nfe_lib}/issqn_spec.rb +2 -2
  72. data/spec/{lib/danfe_lib → br_danfe/danfe_lib/nfe_lib}/phone_spec.rb +3 -3
  73. data/spec/{lib/danfe_lib → br_danfe/danfe_lib/nfe_lib}/plate_spec.rb +3 -3
  74. data/spec/{lib/danfe_lib → br_danfe/danfe_lib/nfe_lib}/ticket_spec.rb +2 -2
  75. data/spec/{lib/danfe_lib → br_danfe/danfe_lib/nfe_lib}/transp_spec.rb +2 -2
  76. data/spec/{lib/danfe_lib → br_danfe/danfe_lib/nfe_lib}/vol_spec.rb +2 -2
  77. data/spec/{lib/danfe_lib → br_danfe/danfe_lib/nfe_lib}/xprod_spec.rb +9 -9
  78. data/spec/{features/danfe_spec.rb → br_danfe/danfe_lib/nfe_spec.rb} +55 -47
  79. data/spec/br_danfe/danfe_spec.rb +35 -0
  80. data/spec/{lib → br_danfe}/helper_spec.rb +114 -0
  81. data/spec/{lib → br_danfe}/logo_config_spec.rb +1 -1
  82. data/spec/{lib → br_danfe}/logo_options_spec.rb +7 -7
  83. data/spec/{lib → br_danfe}/uf_spec.rb +0 -0
  84. data/spec/{lib → br_danfe}/xml_spec.rb +0 -0
  85. data/spec/fixtures/nfce/v4.00/nfce-unauthorized-hom.fixture.pdf +0 -0
  86. data/spec/fixtures/nfce/v4.00/nfce-unauthorized-hom.xml +358 -0
  87. data/spec/fixtures/nfce/v4.00/nfce-unauthorized-prod.fixture.pdf +0 -0
  88. data/spec/fixtures/nfce/v4.00/nfce-unauthorized-prod.xml +358 -0
  89. data/spec/fixtures/nfce/v4.00/nfce.xml +2 -2
  90. data/spec/fixtures/nfce/v4.00/rendered_nfce.fixture.pdf +0 -0
  91. data/spec/fixtures/nfce/v4.00/saved_nfce.fixture.pdf +0 -0
  92. metadata +82 -75
  93. data/lib/br_danfe/danfe_lib/cep.rb +0 -9
  94. data/lib/br_danfe/danfe_lib/consts.rb +0 -6
  95. data/lib/br_danfe/danfe_lib/cst.rb +0 -32
  96. data/lib/br_danfe/danfe_lib/dest.rb +0 -94
  97. data/lib/br_danfe/danfe_lib/det_body.rb +0 -135
  98. data/lib/br_danfe/danfe_lib/document.rb +0 -140
  99. data/lib/br_danfe/danfe_lib/dup.rb +0 -53
  100. data/lib/br_danfe/danfe_lib/emit_header.rb +0 -115
  101. data/lib/br_danfe/danfe_lib/helper.rb +0 -61
  102. data/lib/br_danfe/danfe_lib/icmstot.rb +0 -33
  103. data/lib/br_danfe/danfe_lib/infadic.rb +0 -107
  104. data/lib/br_danfe/danfe_lib/infadic_vol.rb +0 -101
  105. data/lib/br_danfe/danfe_lib/issqn.rb +0 -35
  106. data/lib/br_danfe/danfe_lib/phone.rb +0 -13
  107. data/lib/br_danfe/danfe_lib/plate.rb +0 -9
  108. data/lib/br_danfe/danfe_lib/ticket.rb +0 -19
  109. data/lib/br_danfe/danfe_lib/transp.rb +0 -56
  110. data/lib/br_danfe/danfe_lib/vol.rb +0 -42
  111. data/lib/br_danfe/danfe_lib/xprod.rb +0 -107
  112. data/lib/br_danfe/danfe_nfce.rb +0 -43
  113. data/lib/br_danfe/danfe_nfce_lib/document.rb +0 -35
  114. data/lib/br_danfe/danfe_nfce_lib/footer.rb +0 -20
  115. data/lib/br_danfe/danfe_nfce_lib/header.rb +0 -67
  116. data/lib/br_danfe/danfe_nfce_lib/helper.rb +0 -9
  117. data/lib/br_danfe/danfe_nfce_lib/key.rb +0 -18
  118. data/lib/br_danfe/danfe_nfce_lib/nfce_identification.rb +0 -20
  119. data/lib/br_danfe/danfe_nfce_lib/product_list.rb +0 -100
  120. data/lib/br_danfe/danfe_nfce_lib/qr_code.rb +0 -23
  121. data/lib/br_danfe/danfe_nfce_lib/recipient.rb +0 -72
  122. data/lib/br_danfe/danfe_nfce_lib/total_list.rb +0 -78
  123. data/spec/features/danfe_nfce_spec.rb +0 -31
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4797e22c4338892c66b0cd3d68be10f286afd9bb5901cbbfc75f2517a1d057b1
4
- data.tar.gz: 256d5000c34b831bf3f1ca10b4d32e1fb346f7249b9ad5484da21e19d769ebf8
3
+ metadata.gz: f55ded3c375282fe46db39e4341a44af0b269ce77e58fe981e4e20df9389a32d
4
+ data.tar.gz: 31cbea91ca7a466c0feced8157725a44914907189f046a6e0ba87f43c5a92aaa
5
5
  SHA512:
6
- metadata.gz: 8768877973c009a595a131be31bc03dd3cd6ce26fc6adfcc0eba600e71aea75a268b067afef2805b1aca4649990a8269942b95c8678910c7977ef7ea42608e13
7
- data.tar.gz: a8aa93af20088a6acc235cfb31045493e91243352a8314b6b3dd0e97e11bbb812002f091a139aee5fa6b7e622a19066464b6915f9b71504452ce76eb237789e1
6
+ metadata.gz: 349620dbbbe722fe92ee1564bb2112285fc5555e0baec9e3b3bc4f60ad3456e6d667003ddfb25ee8ccde382b62241b8d9671b304ad68eed8a74f2c95cf0ff55b
7
+ data.tar.gz: e650de0c73f69e2b3a78df8dc476d2f76de5307f9b2d701bf853dff974724b049b3d717fafa1805964821c30efabc7336b61e22a29604505e1a56e137b68d7dc
data/.rubocop.yml CHANGED
@@ -12,13 +12,13 @@ AllCops:
12
12
  Bundler/OrderedGems:
13
13
  Enabled: false
14
14
 
15
- Layout/HashAlignment:
15
+ Layout/AlignHash:
16
16
  Enabled: false
17
17
 
18
- Layout/ParameterAlignment:
18
+ Layout/AlignParameters:
19
19
  Enabled: false
20
20
 
21
- Layout/FirstArrayElementIndentation:
21
+ Layout/IndentArray:
22
22
  EnforcedStyle: consistent
23
23
 
24
24
  Layout/SpaceBeforeBlockBraces:
@@ -26,8 +26,6 @@ Layout/SpaceBeforeBlockBraces:
26
26
 
27
27
  Metrics/ClassLength:
28
28
  Max: 230
29
- Exclude:
30
- - 'app/models/invoice_product.rb'
31
29
 
32
30
  Metrics/CyclomaticComplexity:
33
31
  Max: 8
@@ -38,12 +36,8 @@ Metrics/PerceivedComplexity:
38
36
  Metrics/MethodLength:
39
37
  Max: 19
40
38
 
41
- Metrics/BlockLength:
42
- Exclude:
43
- - 'spec/**/*.rb'
44
- - 'lib/tasks/export_nfes_to_portal.rake'
45
- - 'lib/tasks/karma.rake'
46
- - 'lib/tasks/backup_restore.rake'
39
+ Style/ClassAndModuleChildren:
40
+ Enabled: false
47
41
 
48
42
  Style/DateTime:
49
43
  Enabled: false
@@ -63,22 +57,18 @@ Style/IfUnlessModifier:
63
57
  Style/SymbolArray:
64
58
  EnforcedStyle: brackets
65
59
 
66
- Style/HashEachMethods:
67
- Enabled: true
68
-
69
- Style/HashTransformKeys:
70
- Enabled: true
71
-
72
- Style/HashTransformValues:
73
- Enabled: true
74
-
75
- Layout/LineLength:
76
- Max: 150
60
+ Metrics/LineLength:
61
+ Max: 200
77
62
 
78
63
  Lint/AmbiguousBlockAssociation:
79
64
  Exclude:
80
65
  - 'spec/**/*'
81
66
 
67
+ Metrics/BlockLength:
68
+ Exclude:
69
+ - 'spec/**/*'
70
+ - 'br_danfe.gemspec'
71
+
82
72
  Metrics/ModuleLength:
83
73
  Max: 118
84
74
 
@@ -97,7 +87,7 @@ Naming/HeredocDelimiterNaming:
97
87
  Naming/HeredocDelimiterCase:
98
88
  Enabled: false
99
89
 
100
- Naming/MethodParameterName:
90
+ Naming/UncommunicativeMethodParamName:
101
91
  Enabled: false
102
92
 
103
93
  Naming/MethodName:
@@ -106,8 +96,8 @@ Naming/MethodName:
106
96
  Naming/VariableName:
107
97
  Enabled: false
108
98
 
109
- Style/ClassAndModuleChildren:
99
+ Metrics/ParameterLists:
110
100
  Enabled: false
111
101
 
112
- Metrics/ParameterLists:
102
+ Naming/UncommunicativeBlockParamName:
113
103
  Enabled: false
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- br_danfe (0.12.1)
4
+ br_danfe (0.13.0)
5
5
  barby (= 0.5.1)
6
6
  br_documents (>= 0.1.3)
7
7
  i18n (>= 0.8.6)
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # BrDanfe
2
2
 
3
- [![Code Climate](https://codeclimate.com/github/asseinfo/br_danfe.png)](https://codeclimate.com/github/asseinfo/br_danfe)
3
+ [![Code Climate](https://codeclimate.com/github/asseinfo/br_danfe.png)](https://codeclimate.com/github/asseinfo/br_danfe)
4
4
 
5
5
  This gem generates PDF files for Brazilian DANFE (_Documento Auxiliar da Nota Fiscal Eletrônica_) from a valid NF-e XML. It also can generates PDF file for CC-e (_Carta de Correção Eletrônica_).
6
6
 
@@ -114,10 +114,10 @@ The following variables are necessary to be set:
114
114
 
115
115
  Environment var | Development? | Test? | CI? | Production? | Data
116
116
  ----------------------|--------------|-------|-------|-------------|-----
117
- TZ | no | no | yes | no | America/Sao_Paulo
118
- BUNDLE_PATH | no | no | yes | no | vendor/bundle
119
- CC_TEST_REPORTER_ID | no | no | yes | no | get at codeclimate
120
- RAILS_ENV | no | no | yes | no | test
117
+ TZ | no | no | yes | no | America/Sao_Paulo
118
+ BUNDLE_PATH | no | no | yes | no | vendor/bundle
119
+ CC_TEST_REPORTER_ID | no | no | yes | no | get at codeclimate
120
+ RAILS_ENV | no | no | yes | no | test
121
121
 
122
122
  ### Code coverage
123
123
 
data/lib/br_danfe.rb CHANGED
@@ -9,7 +9,6 @@ require 'yaml'
9
9
  require 'ostruct'
10
10
  require 'i18n'
11
11
  require 'br_documents'
12
- require 'br_danfe/danfe_lib/consts'
13
12
 
14
13
  Dir[File.dirname(__FILE__) + '/**/*.rb'].sort.each { |f| require f }
15
14
  I18n.load_path << File.expand_path('../config/locales/pt-BR.yml', __dir__)
@@ -1,97 +1,13 @@
1
1
  module BrDanfe
2
2
  class Danfe
3
- attr_reader :options
4
-
5
- def initialize(xml)
6
- @xml = BrDanfe::XML.new(xml)
7
- @pdf = DanfeLib::Document.new
8
- @options = BrDanfe::Logo::Config.new
9
-
10
- create_watermark
11
- end
12
-
13
- def save_pdf(filename, footer_info = '')
14
- generate footer_info
15
- @pdf.render_file filename
16
- end
17
-
18
- def render_pdf(footer_info = '')
19
- generate footer_info
20
- @pdf.render
21
- end
22
-
23
- private
24
-
25
- def create_watermark
26
- @pdf.create_stamp('has_no_fiscal_value') do
27
- @pdf.fill_color '7d7d7d'
28
- @pdf.text_box I18n.t('danfe.others.has_no_fiscal_value'),
29
- size: 2.2.cm,
30
- width: @pdf.bounds.width,
31
- height: @pdf.bounds.height,
32
- align: :center,
33
- valign: :center,
34
- at: [0, @pdf.bounds.height],
35
- rotate: 45,
36
- rotate_around: :center
37
- end
38
- end
39
-
40
- def generate(footer_info)
41
- render_on_first_page
42
- render_on_each_page footer_info
43
- @pdf
44
- end
45
-
46
- def render_on_first_page
47
- DanfeLib::Ticket.new(@pdf, @xml).render
48
- DanfeLib::Dest.new(@pdf, @xml).render
49
- DanfeLib::Dup.new(@pdf, @xml).render
50
- DanfeLib::Icmstot.new(@pdf, @xml).render
51
- DanfeLib::Transp.new(@pdf, @xml).render
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
3
+ def self.new(xml)
4
+ create_danfe BrDanfe::XML.new(xml)
91
5
  end
92
6
 
93
- def render_no_fiscal_value
94
- @pdf.stamp('has_no_fiscal_value') if DanfeLib::Helper.no_fiscal_value?(@xml)
7
+ def self.create_danfe(xml)
8
+ nfe_code = '55'
9
+ xml['mod'] == nfe_code ? DanfeLib::Nfe.new(xml) : DanfeLib::Nfce.new(xml)
95
10
  end
11
+ private_class_method :create_danfe
96
12
  end
97
13
  end
@@ -0,0 +1,33 @@
1
+ module BrDanfe
2
+ module DanfeLib
3
+ class Base
4
+ attr_reader :options
5
+
6
+ def initialize(xml)
7
+ @xml = xml
8
+ @document = document
9
+ @options = BrDanfe::Logo::Config.new
10
+
11
+ create_watermark
12
+ end
13
+
14
+ def save_pdf(filename, footer_info = '')
15
+ generate footer_info
16
+ @document.render_file filename
17
+ end
18
+
19
+ def render_pdf(footer_info = '')
20
+ generate footer_info
21
+ @document.render
22
+ end
23
+
24
+ private
25
+
26
+ def document; end
27
+
28
+ def create_watermark; end
29
+
30
+ def generate(footer_info); end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,49 @@
1
+ module BrDanfe
2
+ module DanfeLib
3
+ class Nfce < Base
4
+ PAGE_WIDTH = 8.cm
5
+ PAGE_HEIGHT = 100.cm
6
+
7
+ private
8
+
9
+ def document
10
+ NfceLib::Document.new(PAGE_WIDTH, PAGE_HEIGHT)
11
+ end
12
+
13
+ def create_watermark
14
+ @document.create_stamp('has_no_fiscal_value') do
15
+ @document.fill_color '7d7d7d'
16
+ @document.text_box I18n.t('danfe.others.has_no_fiscal_value'),
17
+ size: 0.8.cm,
18
+ width: 10.cm,
19
+ height: 1.2.cm,
20
+ at: [0, PAGE_HEIGHT - 3.8.cm],
21
+ rotate: 45,
22
+ rotate_around: :center
23
+ end
24
+ end
25
+
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)
35
+
36
+ render_no_fiscal_value
37
+ resize_page_height
38
+ end
39
+
40
+ def render_no_fiscal_value
41
+ @document.stamp('has_no_fiscal_value') if BrDanfe::Helper.unauthorized?(@xml)
42
+ end
43
+
44
+ def resize_page_height
45
+ @document.page.dictionary.data[:MediaBox] = [0, @document.y - 10, PAGE_WIDTH, PAGE_HEIGHT]
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,37 @@
1
+ module BrDanfe
2
+ module DanfeLib
3
+ module NfceLib
4
+ class Document
5
+ def initialize(page_width, page_height)
6
+ @document = Prawn::Document.new(
7
+ page_size: [page_width, page_height],
8
+ page_layout: :portrait,
9
+ left_margin: 0.3.cm,
10
+ right_margin: 0.3.cm,
11
+ top_margin: 0.3.cm,
12
+ botton_margin: 0
13
+ )
14
+
15
+ @document.font 'Courier'
16
+ @document.line_width = 0.3
17
+ end
18
+
19
+ def render_blank_line(font_size = 6)
20
+ @document.text ' ', size: font_size
21
+ end
22
+
23
+ def method_missing(method_name, *args, &block)
24
+ if @document.respond_to? method_name
25
+ @document.send method_name, *args, &block
26
+ else
27
+ super
28
+ end
29
+ end
30
+
31
+ def respond_to_missing?(method_name, include_private = false)
32
+ @document.respond_to?(method_name, include_private) || super
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,22 @@
1
+ module BrDanfe
2
+ module DanfeLib
3
+ module NfceLib
4
+ class Footer
5
+ def initialize(pdf, xml)
6
+ @pdf = pdf
7
+ @xml = xml
8
+ end
9
+
10
+ def render(info = '')
11
+ tot_trib = @xml['ICMSTot/vTotTrib'].present? ? BrDanfe::Helper.numerify(@xml['ICMSTot/vTotTrib']) : '0,00'
12
+ @pdf.text "Tributos Totais Incidentes (Lei Federal 12.741/2012): R$ #{tot_trib}", size: 5, align: :center
13
+
14
+ if info.present?
15
+ @pdf.render_blank_line
16
+ @pdf.text info, size: 5, align: :center
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,69 @@
1
+ module BrDanfe
2
+ module DanfeLib
3
+ module NfceLib
4
+ class Header
5
+ def initialize(pdf, xml, logo, logo_dimensions)
6
+ @pdf = pdf
7
+ @xml = xml
8
+ @logo = logo
9
+ @logo_dimensions = logo_dimensions
10
+ end
11
+
12
+ def render
13
+ cursor = @pdf.cursor
14
+
15
+ render_company_info(cursor)
16
+ render_logo(cursor) if @logo.present?
17
+
18
+ render_homologation if BrDanfe::Helper.homologation?(@xml)
19
+ end
20
+
21
+ private
22
+
23
+ def render_company_info(cursor)
24
+ one_line = 1
25
+
26
+ @pdf.bounding_box([x_position, cursor], width: width_box, height: 45) do
27
+ @pdf.text (@xml['emit/xNome']).to_s, size: 7, align: :left, style: :bold
28
+ @pdf.text cnpj(@xml['emit/CNPJ']), size: 6, align: :left
29
+ @pdf.text BrDanfe::DanfeLib::NfceLib::Helper.address(@xml.css('enderEmit')), size: 6, align: :left
30
+ @pdf.render_blank_line if count_name_lines(@xml['emit/xNome']) == one_line
31
+ @pdf.text 'Documento Auxiliar da Nota Fiscal de Consumidor Eletrônica', size: 6, align: :left
32
+ end
33
+ end
34
+
35
+ def x_position
36
+ @logo.present? ? 1.7.cm : 0
37
+ end
38
+
39
+ def width_box
40
+ @logo.present? ? 5.7.cm : 7.4.cm
41
+ end
42
+
43
+ def cnpj(info)
44
+ cnpj = BrDocuments::CnpjCpf::Cnpj.new info
45
+ data = "CNPJ: #{cnpj.valid? ? cnpj.formatted : ''}"
46
+ data
47
+ end
48
+
49
+ def count_name_lines(company_name)
50
+ company_name.scan(/([\s\S]{1,38}( |$)|[\s\S]{1,38})/).length
51
+ end
52
+
53
+ def render_logo(cursor)
54
+ box_size = 45
55
+ logo_options = BrDanfe::Logo::Options.new(box_size, @logo_dimensions).options
56
+
57
+ @pdf.bounding_box([0, cursor], width: box_size, height: box_size) do
58
+ @pdf.image @logo, logo_options
59
+ end
60
+ end
61
+
62
+ def render_homologation
63
+ @pdf.render_blank_line
64
+ @pdf.text 'EMITIDA EM AMBIENTE DE HOMOLOGAÇÃO – SEM VALOR FISCAL', size: 7, align: :center, style: :bold
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end