br_danfe 0.16.0 → 0.17.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +20 -8
  3. data/.github/dependabot.yml +19 -0
  4. data/.rubocop.yml +24 -11
  5. data/Gemfile.lock +41 -35
  6. data/Guardfile +3 -1
  7. data/bin/_guard-core +29 -0
  8. data/bin/guard +29 -0
  9. data/br_danfe.gemspec +7 -6
  10. data/lib/br_danfe/danfe_lib/nfce.rb +11 -9
  11. data/lib/br_danfe/danfe_lib/nfce_lib/document.rb +1 -1
  12. data/lib/br_danfe/danfe_lib/nfce_lib/footer.rb +2 -2
  13. data/lib/br_danfe/danfe_lib/nfce_lib/header.rb +30 -16
  14. data/lib/br_danfe/danfe_lib/nfce_lib/key.rb +3 -3
  15. data/lib/br_danfe/danfe_lib/nfce_lib/nfce_identification.rb +3 -3
  16. data/lib/br_danfe/danfe_lib/nfce_lib/product_list.rb +44 -53
  17. data/lib/br_danfe/danfe_lib/nfce_lib/recipient.rb +1 -1
  18. data/lib/br_danfe/danfe_lib/nfce_lib/total_list.rb +16 -15
  19. data/lib/br_danfe/danfe_lib/nfe.rb +11 -9
  20. data/lib/br_danfe/danfe_lib/nfe_lib/dup.rb +1 -2
  21. data/lib/br_danfe/danfe_lib/nfe_lib/emit_header.rb +6 -7
  22. data/lib/br_danfe/danfe_lib/nfe_lib/infadic.rb +2 -1
  23. data/lib/br_danfe/helper.rb +1 -1
  24. data/lib/br_danfe/mdfe.rb +1 -1
  25. data/lib/br_danfe/mdfe_lib/authorization_protocol.rb +1 -1
  26. data/lib/br_danfe/mdfe_lib/fisco_control.rb +6 -25
  27. data/lib/br_danfe/mdfe_lib/header.rb +7 -8
  28. data/lib/br_danfe/mdfe_lib/mdfe_identification.rb +1 -1
  29. data/lib/br_danfe/mdfe_lib/notes.rb +1 -1
  30. data/lib/br_danfe/qr_code.rb +1 -2
  31. data/lib/br_danfe/version.rb +1 -1
  32. data/lib/br_danfe.rb +2 -2
  33. data/spec/br_danfe/danfe_lib/nfce_lib/footer_spec.rb +3 -2
  34. data/spec/br_danfe/danfe_lib/nfce_lib/header_spec.rb +6 -4
  35. data/spec/br_danfe/danfe_lib/nfce_lib/helper_spec.rb +2 -2
  36. data/spec/br_danfe/danfe_lib/nfce_lib/key_spec.rb +2 -2
  37. data/spec/br_danfe/danfe_lib/nfce_lib/nfce_identification_spec.rb +2 -2
  38. data/spec/br_danfe/danfe_lib/nfce_lib/recipient_spec.rb +10 -10
  39. data/spec/br_danfe/danfe_lib/nfce_lib/total_list_spec.rb +12 -12
  40. data/spec/br_danfe/danfe_lib/nfce_spec.rb +2 -1
  41. data/spec/br_danfe/danfe_lib/nfe_lib/cst_spec.rb +4 -4
  42. data/spec/br_danfe/danfe_lib/nfe_lib/dest_spec.rb +178 -178
  43. data/spec/br_danfe/danfe_lib/nfe_lib/det_body_spec.rb +274 -274
  44. data/spec/br_danfe/danfe_lib/nfe_lib/document_spec.rb +77 -77
  45. data/spec/br_danfe/danfe_lib/nfe_lib/dup_spec.rb +23 -23
  46. data/spec/br_danfe/danfe_lib/nfe_lib/emit_header_spec.rb +55 -37
  47. data/spec/br_danfe/danfe_lib/nfe_lib/helper_spec.rb +34 -34
  48. data/spec/br_danfe/danfe_lib/nfe_lib/icmstot_spec.rb +19 -19
  49. data/spec/br_danfe/danfe_lib/nfe_lib/infadic_spec.rb +237 -237
  50. data/spec/br_danfe/danfe_lib/nfe_lib/infadic_vol_spec.rb +3 -2
  51. data/spec/br_danfe/danfe_lib/nfe_lib/issqn_spec.rb +16 -16
  52. data/spec/br_danfe/danfe_lib/nfe_lib/ticket_spec.rb +13 -13
  53. data/spec/br_danfe/danfe_lib/nfe_lib/transp_spec.rb +76 -76
  54. data/spec/br_danfe/danfe_lib/nfe_lib/vol_spec.rb +40 -40
  55. data/spec/br_danfe/danfe_lib/nfe_lib/xprod_spec.rb +118 -118
  56. data/spec/br_danfe/danfe_spec.rb +2 -2
  57. data/spec/br_danfe/helper_spec.rb +15 -15
  58. data/spec/br_danfe/mdfe_lib/document_spec.rb +2 -2
  59. data/spec/br_danfe/mdfe_lib/fisco_control_spec.rb +21 -7
  60. data/spec/br_danfe/mdfe_lib/header_spec.rb +27 -18
  61. data/spec/br_danfe/mdfe_lib/notes_spec.rb +5 -5
  62. data/spec/br_danfe/mdfe_lib/totalizer_spec.rb +1 -1
  63. data/spec/br_danfe/mdfe_spec.rb +4 -5
  64. data/spec/br_danfe/qr_code_spec.rb +4 -13
  65. data/spec/br_danfe/xml_spec.rb +6 -6
  66. data/spec/fixtures/mdfe/lib/fisco_control#without-barcode.pdf +0 -0
  67. data/spec/fixtures/mdfe/lib/header#render-without-qr-code.pdf +0 -0
  68. data/spec/fixtures/nfce/lib/document#render.pdf +12 -23
  69. data/spec/fixtures/nfce/lib/footer#render-with_additional_information.pdf +0 -0
  70. data/spec/fixtures/nfce/lib/footer#render.pdf +0 -0
  71. data/spec/fixtures/nfce/lib/header#render-homologation.pdf +0 -0
  72. data/spec/fixtures/nfce/lib/header#render-long_name_with_logo.pdf +0 -0
  73. data/spec/fixtures/nfce/lib/header#render-long_name_without_logo.pdf +0 -0
  74. data/spec/fixtures/nfce/lib/header#render-short_name_with_logo.pdf +0 -0
  75. data/spec/fixtures/nfce/lib/header#render-short_name_without_logo.pdf +0 -0
  76. data/spec/fixtures/nfce/lib/key#render.pdf +0 -0
  77. data/spec/fixtures/nfce/lib/nfce_identification#render.pdf +0 -0
  78. data/spec/fixtures/nfce/lib/product_list#render-with_many_products.pdf +0 -0
  79. data/spec/fixtures/nfce/lib/product_list#render-with_many_products_and_long_names.pdf +0 -0
  80. data/spec/fixtures/nfce/lib/product_list#render-with_single_product.pdf +0 -0
  81. data/spec/fixtures/nfce/lib/product_list#render-with_single_product_and_long_name.pdf +0 -0
  82. data/spec/fixtures/nfce/lib/product_list_with_many_products_and_long_names.xml +2 -2
  83. data/spec/fixtures/nfce/lib/product_list_with_single_product_and_long_name.xml +1 -1
  84. data/spec/fixtures/nfce/lib/recipient#render-company.pdf +0 -0
  85. data/spec/fixtures/nfce/lib/recipient#render-consumer_without_document.pdf +0 -0
  86. data/spec/fixtures/nfce/lib/recipient#render-foreign.pdf +0 -0
  87. data/spec/fixtures/nfce/lib/recipient#render-individual.pdf +0 -0
  88. data/spec/fixtures/nfce/lib/recipient#render-unidentified_consumer.pdf +0 -0
  89. data/spec/fixtures/nfce/lib/total_list#does_not_render-payment_methods.pdf +0 -0
  90. data/spec/fixtures/nfce/lib/total_list#render-grouped_payment_methods.pdf +0 -0
  91. data/spec/fixtures/nfce/lib/total_list#render-totals.pdf +0 -0
  92. data/spec/fixtures/nfce/lib/total_list#render-without_payment.pdf +0 -0
  93. data/spec/fixtures/nfce/lib/total_list#render.pdf +0 -0
  94. data/spec/fixtures/nfce/v4.00/multiples_xmls_on_the_same_pdf.pdf +568 -447
  95. data/spec/fixtures/nfce/v4.00/nfce-unauthorized-hom.fixture.pdf +0 -0
  96. data/spec/fixtures/nfce/v4.00/nfce-unauthorized-prod.fixture.pdf +0 -0
  97. data/spec/fixtures/nfce/v4.00/rendered_nfce.fixture.pdf +0 -0
  98. data/spec/fixtures/nfce/v4.00/saved_nfce.fixture.pdf +0 -0
  99. data/spec/fixtures/nfe/lib/emit_header#render-nfe_key.pdf +945 -0
  100. data/spec/spec_helper.rb +1 -1
  101. metadata +38 -16
@@ -14,19 +14,54 @@ module BrDanfe
14
14
 
15
15
  private
16
16
 
17
+ def render_headers(headers)
18
+ 2.times { @pdf.render_blank_line }
19
+ cursor = @pdf.cursor
20
+ headers.each_with_index do |header, index|
21
+ cursor -= 10 if index == 1
22
+ @pdf.bounding_box [columns[index][:position], cursor], width: columns[index][:width], height: 0.3.cm do
23
+ @pdf.text header[:content], header[:options]
24
+ end
25
+ end
26
+ end
27
+
17
28
  def headers
18
29
  [
19
- header_column('Código', :left),
20
- header_column('Descrição', :left),
21
- header_column('Qtde', :right),
30
+ header_column('CÓDIGO - DESCRIÇÃO', :left),
31
+ header_column('QTD', :left),
22
32
  header_column('UN', :right),
23
- header_column('Vl Unit', :right),
24
- header_column('Vl Total', :right)
33
+ header_column('VL UNIT', :right),
34
+ header_column('TOTAL', :right)
25
35
  ]
26
36
  end
27
37
 
28
38
  def header_column(title, align)
29
- { content: title, options: { align: align, size: 6, style: :bold } }
39
+ { content: title, options: { align: align, size: 9, style: :bold } }
40
+ end
41
+
42
+ def columns
43
+ [
44
+ { width: 6.7.cm, position: 0 },
45
+ { width: 1.7.cm, position: 0.cm },
46
+ { width: 1.cm, position: 1.7.cm },
47
+ { width: 1.7.cm, position: 2.7.cm },
48
+ { width: 2.3.cm, position: 4.4.cm }
49
+ ]
50
+ end
51
+
52
+ def render_products
53
+ @pdf.render_blank_line
54
+ products.each do |product|
55
+ cursor = @pdf.cursor
56
+
57
+ product.each_with_index do |cell, index|
58
+ cursor -= 10 if index == 1
59
+ @pdf.bounding_box [columns[index][:position], cursor], width: columns[index][:width], height: 0.3.cm do
60
+ options = cell[:options].merge(overflow: :truncate)
61
+ @pdf.text_box cell[:content], options
62
+ end
63
+ end
64
+ end
30
65
  end
31
66
 
32
67
  def products
@@ -35,9 +70,8 @@ module BrDanfe
35
70
 
36
71
  def product(det)
37
72
  [
38
- cell_text(det.css('prod/cProd').text),
39
- cell_text(det.css('prod/xProd').text),
40
- cell_number(BrDanfe::Helper.numerify(det.css('prod/qCom').text)),
73
+ cell_text("#{det.css('prod/cProd').text} - #{det.css('prod/xProd').text}"),
74
+ cell_text(BrDanfe::Helper.numerify(det.css('prod/qCom').text), align: :left),
41
75
  cell_text(det.css('prod/uCom').text, align: :right),
42
76
  cell_number(BrDanfe::Helper.numerify(det.css('prod/vUnCom').text)),
43
77
  cell_number(BrDanfe::Helper.numerify(det.css('prod/vProd').text))
@@ -45,7 +79,7 @@ module BrDanfe
45
79
  end
46
80
 
47
81
  def cell_text(text, options = {})
48
- cell = { content: text, options: { border_width: 0, size: 6 } }
82
+ cell = { content: text, options: { border_width: 0, size: 9 } }
49
83
  cell[:options].merge!(options)
50
84
  cell
51
85
  end
@@ -53,49 +87,6 @@ module BrDanfe
53
87
  def cell_number(text)
54
88
  cell_text(text, align: :right)
55
89
  end
56
-
57
- def columns
58
- [
59
- { width: 0.9.cm, position: 0 },
60
- { width: 2.6.cm, position: 0.9.cm },
61
- { width: 1.1.cm, position: 3.5.cm },
62
- { width: 0.4.cm, position: 4.6.cm },
63
- { width: 1.2.cm, position: 5.cm },
64
- { width: 1.2.cm, position: 6.2.cm }
65
- ]
66
- end
67
-
68
- def render_headers(headers)
69
- 2.times { @pdf.render_blank_line }
70
- cursor = @pdf.cursor
71
- headers.each_with_index do |header, index|
72
- @pdf.bounding_box [columns[index][:position], cursor], width: columns[index][:width], height: 0.2.cm do
73
- @pdf.text header[:content], header[:options]
74
- end
75
- end
76
- end
77
-
78
- def render_products
79
- @pdf.render_blank_line
80
- index_of_product_name = 1
81
- products.each do |product|
82
- box_height = box_height(product[index_of_product_name][:content])
83
- cursor = @pdf.cursor
84
-
85
- product.each_with_index do |cell, index|
86
- @pdf.bounding_box [columns[index][:position], cursor], width: columns[index][:width], height: box_height do
87
- @pdf.text cell[:content], cell[:options]
88
- end
89
- end
90
- end
91
- end
92
-
93
- def box_height(content)
94
- line_height_base = 0.23.cm
95
-
96
- lines = content.scan(/[\s\S]{1,20}( |$)/).length
97
- line_height_base * lines
98
- end
99
90
  end
100
91
  end
101
92
  end
@@ -23,7 +23,7 @@ module BrDanfe
23
23
  private
24
24
 
25
25
  def options
26
- { size: 7, align: :center }
26
+ { size: 9, align: :center }
27
27
  end
28
28
 
29
29
  def identified_recipient?
@@ -18,12 +18,13 @@ module BrDanfe
18
18
  private
19
19
 
20
20
  def subtotal
21
+ @pdf.render_blank_line
21
22
  cursor = @pdf.cursor
22
- @pdf.bounding_box [4.8.cm, cursor], width: 1.4.cm, height: 0.2.cm do
23
- @pdf.text 'Subtotal R$', size: 6, align: :left
23
+ @pdf.bounding_box [3.5.cm, cursor], width: 1.6.cm, height: 0.4.cm do
24
+ @pdf.text 'Subtotal R$', size: 9, align: :left
24
25
  end
25
- @pdf.bounding_box [6.2.cm, cursor], width: 1.2.cm, height: 0.2.cm do
26
- @pdf.text BrDanfe::Helper.numerify(@xml['ICMSTot > vProd'].to_f), size: 6, align: :right
26
+ @pdf.bounding_box [5.1.cm, cursor], width: 1.6.cm, height: 0.4.cm do
27
+ @pdf.text BrDanfe::Helper.numerify(@xml['ICMSTot > vProd'].to_f), size: 9, align: :right
27
28
  end
28
29
  end
29
30
 
@@ -31,16 +32,16 @@ module BrDanfe
31
32
  @pdf.render_blank_line
32
33
 
33
34
  cursor = @pdf.cursor
34
- print_text('Qtde. total de itens', cursor, size: 7, align: :left)
35
- print_text(@xml.css('det').count.to_s, cursor, size: 7, align: :right)
35
+ print_text('QTD. TOTAL DE ITENS', cursor, size: 10, align: :left)
36
+ print_text(@xml.css('det').count.to_s, cursor, size: 10, align: :right)
36
37
 
37
38
  cursor = @pdf.cursor
38
- print_text('Desconto R$', cursor, size: 7, align: :left)
39
- print_text(BrDanfe::Helper.numerify(@xml['ICMSTot > vDesc'].to_f), cursor, size: 7, align: :right)
39
+ print_text('DESCONTO R$', cursor, size: 10, align: :left)
40
+ print_text(BrDanfe::Helper.numerify(@xml['ICMSTot > vDesc'].to_f), cursor, size: 10, align: :right)
40
41
 
41
42
  cursor = @pdf.cursor
42
- print_text('Valor Total R$', cursor, size: 7, align: :left, style: :bold)
43
- print_text(BrDanfe::Helper.numerify(@xml['ICMSTot > vNF'].to_f), cursor, size: 7, align: :right, style: :bold)
43
+ print_text('VALOR TOTAL R$', cursor, size: 10, align: :left, style: :bold)
44
+ print_text(BrDanfe::Helper.numerify(@xml['ICMSTot > vNF'].to_f), cursor, size: 10, align: :right, style: :bold)
44
45
  end
45
46
 
46
47
  def payment_methods
@@ -59,19 +60,19 @@ module BrDanfe
59
60
  @pdf.render_blank_line
60
61
 
61
62
  cursor = @pdf.cursor
62
- print_text('Forma de pagamento', cursor, size: 7, align: :left, style: :bold)
63
- print_text('Valor pago R$', cursor, size: 7, align: :right, style: :bold)
63
+ print_text('FORMA PAGTO.', cursor, size: 9, align: :left, style: :bold)
64
+ print_text('VLR PAGO R$', cursor, size: 9, align: :right, style: :bold)
64
65
 
65
66
  payments.each do |key, value|
66
67
  cursor = @pdf.cursor
67
- print_text(I18n.t("nfce.payment_methods.#{key}"), cursor, size: 7, align: :left)
68
- print_text(BrDanfe::Helper.numerify(value.to_f), cursor, size: 7, align: :right)
68
+ print_text(I18n.t("nfce.payment_methods.#{key}"), cursor, size: 9, align: :left)
69
+ print_text(BrDanfe::Helper.numerify(value.to_f), cursor, size: 9, align: :right)
69
70
  end
70
71
  end
71
72
  end
72
73
 
73
74
  def print_text(text, cursor, options)
74
- @pdf.bounding_box [0, cursor], width: 7.4.cm, height: 0.25.cm do
75
+ @pdf.bounding_box [0, cursor], width: 6.7.cm, height: 0.35.cm do
75
76
  @pdf.text text, options
76
77
  end
77
78
  end
@@ -10,15 +10,17 @@ module BrDanfe
10
10
  def create_watermark
11
11
  @document.create_stamp('has_no_fiscal_value') do
12
12
  @document.fill_color '7d7d7d'
13
- @document.text_box I18n.t('danfe.others.has_no_fiscal_value'),
14
- size: 2.2.cm,
15
- width: @document.bounds.width,
16
- height: @document.bounds.height,
17
- align: :center,
18
- valign: :center,
19
- at: [0, @document.bounds.height],
20
- rotate: 45,
21
- rotate_around: :center
13
+ @document.text_box(
14
+ I18n.t('danfe.others.has_no_fiscal_value'),
15
+ size: 2.2.cm,
16
+ width: @document.bounds.width,
17
+ height: @document.bounds.height,
18
+ align: :center,
19
+ valign: :center,
20
+ at: [0, @document.bounds.height],
21
+ rotate: 45,
22
+ rotate_around: :center
23
+ )
22
24
  end
23
25
  end
24
26
 
@@ -38,8 +38,7 @@ module BrDanfe
38
38
 
39
39
  def dtduplicata(det)
40
40
  dtduplicata = det.css('dVenc').text
41
- dtduplicata = dtduplicata[8, 2] + '/' + dtduplicata[5, 2] + '/' + dtduplicata[0, 4]
42
- dtduplicata
41
+ "#{dtduplicata[8, 2]}/#{dtduplicata[5, 2]}/#{dtduplicata[0, 4]}"
43
42
  end
44
43
 
45
44
  def normal
@@ -38,11 +38,10 @@ module BrDanfe
38
38
  end
39
39
 
40
40
  def address
41
- formatted = @xml['enderEmit/xLgr'] + ', ' + @xml['enderEmit/nro'] + "\n"
42
- formatted += @xml['enderEmit/xBairro'] + ' - ' + cep + "\n"
43
- formatted += @xml['enderEmit/xMun'] + '/' + @xml['enderEmit/UF'] + "\n"
44
- formatted += phone + ' ' + @xml['enderEmit/email']
45
- formatted
41
+ "#{@xml['enderEmit/xLgr']}, #{@xml['enderEmit/nro']}\n" \
42
+ "#{@xml['enderEmit/xBairro']} - #{cep}\n" \
43
+ "#{@xml['enderEmit/xMun']}/#{@xml['enderEmit/UF']}\n" \
44
+ "#{phone} #{@xml['enderEmit/email']}"
46
45
  end
47
46
 
48
47
  def phone
@@ -89,9 +88,9 @@ module BrDanfe
89
88
 
90
89
  def access_key_box
91
90
  @pdf.ibox 2.22, 10.02, 10.29, @y_position
92
- @pdf.ibarcode 1.50, 8.00, 10.4010, @y_position + 1.90, @xml['chNFe']
91
+ @pdf.ibarcode 1.50, 8.00, 10.4010, @y_position + 1.90, @xml['infProt > chNFe']
93
92
  @pdf.ibox 0.85, 10.02, 10.29, @y_position + 2.22, I18n.t('danfe.chNFe'),
94
- @xml['chNFe'].gsub(/(\d)(?=(\d\d\d\d)+(?!\d))/, '\\1 '), style: :bold, align: :center
93
+ @xml['infProt > chNFe'].gsub(/(\d)(?=(\d\d\d\d)+(?!\d))/, '\\1 '), style: :bold, align: :center
95
94
  end
96
95
 
97
96
  def sefaz_box
@@ -93,7 +93,8 @@ module BrDanfe
93
93
  end
94
94
 
95
95
  def difal?
96
- @xml['ICMSTot/vICMSUFDest'].to_f != 0
96
+ value = @xml['ICMSTot/vICMSUFDest'].presence || '0.0'
97
+ BigDecimal(value).positive?
97
98
  end
98
99
 
99
100
  def fisco_content
@@ -20,7 +20,7 @@ module BrDanfe
20
20
  decimal_part = separated_number[1] || '00'
21
21
  decimal_part += '0' if decimal_part.size < 2
22
22
 
23
- integer_part + ',' + decimal_part
23
+ "#{integer_part},#{decimal_part}"
24
24
  end
25
25
 
26
26
  def self.format_datetime(xml_datetime, with_time_zone: false)
data/lib/br_danfe/mdfe.rb CHANGED
@@ -7,7 +7,7 @@ module BrDanfe
7
7
  attr_reader :logo_options
8
8
 
9
9
  def initialize(xml)
10
- @xml = xml
10
+ @xml = BrDanfe::XML.new(xml)
11
11
  @pdf = MdfeLib::Document.new
12
12
  @logo_options = BrDanfe::Logo::Config.new
13
13
  end
@@ -14,7 +14,7 @@ module BrDanfe
14
14
 
15
15
  def authorization
16
16
  title = 'Protocolo de autorização'
17
- protocol = @xml['infProt/nProt'] + ' - ' + Helper.format_datetime(@xml['infProt/dhRecbto'], with_time_zone: true)
17
+ protocol = "#{@xml['infProt/nProt']} - #{Helper.format_datetime(@xml['infProt/dhRecbto'], with_time_zone: true)}"
18
18
 
19
19
  @pdf.text_box(title, size: 9, align: :left, style: :bold, at: [0, 510])
20
20
  @pdf.text_box(protocol, size: 11, align: :left, at: [0, 500])
@@ -3,37 +3,18 @@ module BrDanfe
3
3
  class FiscoControl
4
4
  def initialize(pdf, xml)
5
5
  @pdf = pdf
6
- @xml = xml
6
+ @nfe_key = xml['mdfeProc > protMDFe > infProt > chMDFe']
7
7
  end
8
8
 
9
9
  def generate
10
- title
11
- barcode
12
- generate_nfe_key
13
- end
14
-
15
- private
16
-
17
- def title
18
- title = 'CONTROLE DO FISCO'
19
-
20
- @pdf.text_box(title, size: 9, align: :left, at: [250, 600])
21
- end
22
-
23
- def barcode
24
- barcode = Barby::Code128C.new(nfe_key)
25
- barcode.annotate_pdf(@pdf, x: 250, y: 530, height: 50)
26
- end
10
+ @pdf.text_box('CONTROLE DO FISCO', size: 9, align: :left, at: [250, 600])
27
11
 
28
- def nfe_key
29
- @xml['mdfeProc > protMDFe > infProt > chMDFe']
30
- end
12
+ return if @nfe_key.blank?
31
13
 
32
- def generate_nfe_key
33
- title = 'Chave de Acesso'
14
+ Barby::Code128C.new(@nfe_key).annotate_pdf(@pdf, x: 250, y: 530, height: 50)
34
15
 
35
- @pdf.text_box(title, size: 9, align: :left, style: :bold, at: [250, 510])
36
- @pdf.text_box(nfe_key, size: 11, align: :left, at: [250, 500])
16
+ @pdf.text_box('Chave de Acesso', size: 9, align: :left, style: :bold, at: [250, 510])
17
+ @pdf.text_box(@nfe_key, size: 11, align: :left, at: [250, 500])
37
18
  end
38
19
  end
39
20
  end
@@ -11,7 +11,7 @@ module BrDanfe
11
11
  def generate
12
12
  generate_emit
13
13
  generate_title
14
- qr_code
14
+ generate_qr_code if @xml['qrCodMDFe'].present?
15
15
  end
16
16
 
17
17
  private
@@ -34,9 +34,8 @@ module BrDanfe
34
34
  end
35
35
 
36
36
  def address
37
- formatted = @xml['enderEmit/xLgr'] + ', nº ' + @xml['enderEmit/nro'] + "\n"
38
- formatted += @xml['enderEmit/xMun'] + ' - ' + @xml['enderEmit/UF'] + ' ' + 'CEP ' + cep + "\n"
39
- formatted
37
+ "#{@xml['enderEmit/xLgr']}, nº #{@xml['enderEmit/nro']}\n" \
38
+ "#{@xml['enderEmit/xMun']} - #{@xml['enderEmit/UF']} CEP #{cep}\n"
40
39
  end
41
40
 
42
41
  def cep
@@ -44,7 +43,7 @@ module BrDanfe
44
43
  end
45
44
 
46
45
  def company_informations
47
- '<b>CNPJ: </b>' + @xml['emit/CNPJ'] + ' ' + '<b>IE: </b>' + @xml['emit/IE']
46
+ "<b>CNPJ: </b>#{@xml['emit/CNPJ']} <b>IE: </b>#{@xml['emit/IE']}"
48
47
  end
49
48
 
50
49
  def logo
@@ -65,12 +64,12 @@ module BrDanfe
65
64
  end
66
65
  end
67
66
 
68
- def qr_code
67
+ def generate_qr_code
69
68
  box_size = 40.mm
70
- security_margin = box_size + box_size / 10.0
69
+ security_margin = box_size + (box_size / 10.0)
71
70
 
72
71
  @pdf.bounding_box([414, 780], width: security_margin, height: security_margin) do
73
- BrDanfe::QrCode.new(pdf: @pdf, xml: @xml, qr_code_tag: @xml['qrCodMDFe'], box_size: box_size).render
72
+ BrDanfe::QrCode.new(pdf: @pdf, qr_code_tag: @xml['qrCodMDFe'], box_size: box_size).render
74
73
  end
75
74
  end
76
75
  end
@@ -48,7 +48,7 @@ module BrDanfe
48
48
  end
49
49
 
50
50
  def number_of_pages(page)
51
- text = page.to_s + '/' + @pdf.page_count.to_s
51
+ text = "#{page}/#{@pdf.page_count}"
52
52
  generate_box('FL', text, 125)
53
53
  end
54
54
 
@@ -74,7 +74,7 @@ module BrDanfe
74
74
 
75
75
  total_height += 10 if total_chars >= MAX_CHARS_ON_LINE
76
76
 
77
- total_height <= height_on_first_page ? first_page += word + ' ' : next_page += word + ' '
77
+ total_height <= height_on_first_page ? first_page += "#{word} " : next_page += "#{word} "
78
78
  end
79
79
 
80
80
  { first_page: first_page, next_page: next_page }
@@ -4,9 +4,8 @@ module BrDanfe
4
4
  require 'chunky_png'
5
5
  require 'tempfile'
6
6
 
7
- def initialize(pdf:, xml:, qr_code_tag:, box_size:)
7
+ def initialize(pdf:, qr_code_tag:, box_size:)
8
8
  @pdf = pdf
9
- @xml = xml
10
9
  @qr_code_tag = qr_code_tag
11
10
  @box_size = box_size
12
11
  end
@@ -1,3 +1,3 @@
1
1
  module BrDanfe
2
- VERSION = '0.16.0'.freeze
2
+ VERSION = '0.17.3'.freeze
3
3
  end
data/lib/br_danfe.rb CHANGED
@@ -10,12 +10,12 @@ require 'ostruct'
10
10
  require 'i18n'
11
11
  require 'br_documents'
12
12
 
13
- Dir[File.dirname(__FILE__) + '/**/*.rb'].sort.each { |f| require f }
13
+ Dir["#{File.dirname(__FILE__)}/**/*.rb"].sort.each { |f| require f }
14
14
  I18n.load_path << File.expand_path('../config/locales/pt-BR.yml', __dir__)
15
15
  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('..', __dir__)
20
20
  end
21
21
  end
@@ -7,7 +7,7 @@ describe BrDanfe::DanfeLib::NfceLib::Footer do
7
7
  let(:pdf) { BrDanfe::DanfeLib::NfceLib::Document.new(8.cm, 5.cm) }
8
8
 
9
9
  let(:xml_footer) do
10
- xml = <<-eos
10
+ xml = <<~XML
11
11
  <nfeProc>
12
12
  <NFe>
13
13
  <infNFe>
@@ -19,7 +19,7 @@ describe BrDanfe::DanfeLib::NfceLib::Footer do
19
19
  </infNFe>
20
20
  </NFe>
21
21
  </nfeProc>
22
- eos
22
+ XML
23
23
 
24
24
  BrDanfe::XML.new(xml)
25
25
  end
@@ -28,6 +28,7 @@ describe BrDanfe::DanfeLib::NfceLib::Footer do
28
28
 
29
29
  describe '#render' do
30
30
  before { File.delete(output_pdf) if File.exist?(output_pdf) }
31
+
31
32
  it 'renders footer to the pdf' do
32
33
  subject.render
33
34
  expect(File.exist?(output_pdf)).to be_falsey
@@ -8,7 +8,7 @@ describe BrDanfe::DanfeLib::NfceLib::Header do
8
8
  let(:environment) { 1 }
9
9
 
10
10
  let(:xml) do
11
- xml = <<-eos
11
+ xml = <<~XML
12
12
  <nfeProc>
13
13
  <NFe>
14
14
  <infNFe>
@@ -37,12 +37,12 @@ describe BrDanfe::DanfeLib::NfceLib::Header do
37
37
  </infNFe>
38
38
  </NFe>
39
39
  </nfeProc>
40
- eos
40
+ XML
41
41
 
42
42
  BrDanfe::XML.new(xml)
43
43
  end
44
44
 
45
- let(:pdf) { BrDanfe::DanfeLib::NfceLib::Document.new(8.cm, 5.cm) }
45
+ let(:pdf) { BrDanfe::DanfeLib::NfceLib::Document.new(8.cm, 6.cm) }
46
46
 
47
47
  subject { described_class.new pdf, xml, logo, logo_options }
48
48
 
@@ -52,6 +52,8 @@ describe BrDanfe::DanfeLib::NfceLib::Header do
52
52
  File.delete(output_pdf) if File.exist?(output_pdf)
53
53
  end
54
54
 
55
+ after { File.delete(output_pdf) if File.exist?(output_pdf) }
56
+
55
57
  context 'when has a short name' do
56
58
  let(:company_name) { 'Test company' }
57
59
 
@@ -81,7 +83,7 @@ describe BrDanfe::DanfeLib::NfceLib::Header do
81
83
  let(:company_name) { 'Test company with some very long name to do a line break' }
82
84
 
83
85
  context 'when has a logo' do
84
- it 'renders the header with company name line breaked' do
86
+ it 'renders the header with company name line breaked and shrinked to fit' do
85
87
  expect(File.exist?(output_pdf)).to be_falsey
86
88
  pdf.render_file output_pdf
87
89
 
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe BrDanfe::DanfeLib::NfceLib::Helper do
4
4
  let(:xml) do
5
- xml = <<-eos
5
+ xml = <<~XML
6
6
  <enderDest>
7
7
  <xLgr>Rua Tijucas</xLgr>
8
8
  <nro>99</nro>
@@ -15,7 +15,7 @@ describe BrDanfe::DanfeLib::NfceLib::Helper do
15
15
  <cPais>1058</cPais>
16
16
  <xPais>Brasil</xPais>
17
17
  </enderDest>
18
- eos
18
+ XML
19
19
 
20
20
  BrDanfe::XML.new(xml)
21
21
  end
@@ -5,7 +5,7 @@ describe BrDanfe::DanfeLib::NfceLib::Key do
5
5
  let(:output_pdf) { "#{base_dir}output.pdf" }
6
6
 
7
7
  let(:xml_key) do
8
- xml = <<-eos
8
+ xml = <<~XML
9
9
  <nfeProc>
10
10
  <NFe>
11
11
  <infNFeSupl>
@@ -19,7 +19,7 @@ describe BrDanfe::DanfeLib::NfceLib::Key do
19
19
  </infProt>
20
20
  </protNFe>
21
21
  </nfeProc>
22
- eos
22
+ XML
23
23
 
24
24
  BrDanfe::XML.new(xml)
25
25
  end
@@ -7,7 +7,7 @@ describe BrDanfe::DanfeLib::NfceLib::NfceIdentification do
7
7
  let(:pdf) { BrDanfe::DanfeLib::NfceLib::Document.new(8.cm, 5.cm) }
8
8
 
9
9
  let(:xml) do
10
- xml = <<-eos
10
+ xml = <<~XML
11
11
  <nfeProc>
12
12
  <NFe>
13
13
  <infNFe>
@@ -25,7 +25,7 @@ describe BrDanfe::DanfeLib::NfceLib::NfceIdentification do
25
25
  </infNFe>
26
26
  </NFe>
27
27
  </nfeProc>
28
- eos
28
+ XML
29
29
 
30
30
  BrDanfe::XML.new(xml)
31
31
  end