br_danfe 0.11.1 → 0.11.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (146) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +1 -0
  3. data/.rubocop.yml +113 -0
  4. data/Gemfile.lock +40 -19
  5. data/Rakefile +3 -3
  6. data/br_danfe.gemspec +7 -7
  7. data/lib/br_danfe.rb +14 -14
  8. data/lib/br_danfe/cce.rb +1 -0
  9. data/lib/br_danfe/cce_lib/barcode.rb +3 -2
  10. data/lib/br_danfe/cce_lib/correction.rb +3 -2
  11. data/lib/br_danfe/cce_lib/document.rb +15 -5
  12. data/lib/br_danfe/cce_lib/footer.rb +1 -1
  13. data/lib/br_danfe/cce_lib/header.rb +1 -1
  14. data/lib/br_danfe/cce_lib/nfe_key.rb +4 -3
  15. data/lib/br_danfe/cce_lib/protocol.rb +4 -3
  16. data/lib/br_danfe/danfe.rb +17 -17
  17. data/lib/br_danfe/danfe_lib/cep.rb +1 -1
  18. data/lib/br_danfe/danfe_lib/cst.rb +8 -6
  19. data/lib/br_danfe/danfe_lib/dest.rb +21 -23
  20. data/lib/br_danfe/danfe_lib/det_body.rb +20 -20
  21. data/lib/br_danfe/danfe_lib/document.rb +49 -36
  22. data/lib/br_danfe/danfe_lib/dup.rb +11 -10
  23. data/lib/br_danfe/danfe_lib/emit_header.rb +38 -34
  24. data/lib/br_danfe/danfe_lib/helper.rb +23 -23
  25. data/lib/br_danfe/danfe_lib/icmstot.rb +12 -12
  26. data/lib/br_danfe/danfe_lib/infadic.rb +1 -0
  27. data/lib/br_danfe/danfe_lib/issqn.rb +6 -6
  28. data/lib/br_danfe/danfe_lib/options.rb +6 -5
  29. data/lib/br_danfe/danfe_lib/phone.rb +2 -2
  30. data/lib/br_danfe/danfe_lib/ticket.rb +6 -4
  31. data/lib/br_danfe/danfe_lib/transp.rb +27 -26
  32. data/lib/br_danfe/danfe_lib/vol.rb +9 -8
  33. data/lib/br_danfe/danfe_lib/xml.rb +6 -6
  34. data/lib/br_danfe/danfe_lib/xprod.rb +22 -23
  35. data/lib/br_danfe/uf.rb +1 -4
  36. data/lib/br_danfe/version.rb +1 -1
  37. data/spec/features/cce_spec.rb +6 -6
  38. data/spec/features/danfe_spec.rb +25 -25
  39. data/spec/fixtures/cce/lib/barcode#render.pdf +5 -1
  40. data/spec/fixtures/cce/lib/correction#render.pdf +6 -2
  41. data/spec/fixtures/cce/lib/document#box.pdf +5 -1
  42. data/spec/fixtures/cce/lib/document#box.with.block.pdf +6 -2
  43. data/spec/fixtures/cce/lib/document#text.align.pdf +6 -2
  44. data/spec/fixtures/cce/lib/document#text.pad.pdf +6 -2
  45. data/spec/fixtures/cce/lib/document#text.simple.pdf +6 -2
  46. data/spec/fixtures/cce/lib/document#text.size.pdf +6 -2
  47. data/spec/fixtures/cce/lib/document#text.style.pdf +6 -2
  48. data/spec/fixtures/cce/lib/footer#render.pdf +6 -2
  49. data/spec/fixtures/cce/lib/header#render.pdf +6 -2
  50. data/spec/fixtures/cce/lib/nfe_key#render.pdf +7 -3
  51. data/spec/fixtures/cce/lib/protocol#render.pdf +7 -3
  52. data/spec/fixtures/cce/v1.00/cce.fixture.pdf +7 -3
  53. data/spec/fixtures/nfe/lib/dest#render-v2.00.pdf +7 -3
  54. data/spec/fixtures/nfe/lib/dest#render-v3.10.pdf +7 -3
  55. data/spec/fixtures/nfe/lib/dest#render-v4.00.pdf +7 -3
  56. data/spec/fixtures/nfe/lib/dest#render-with-address-bigger.pdf +7 -3
  57. data/spec/fixtures/nfe/lib/dest#render-with_cnpj.pdf +7 -3
  58. data/spec/fixtures/nfe/lib/dest#render-with_cpf.pdf +7 -3
  59. data/spec/fixtures/nfe/lib/dest#render-with_ie.pdf +7 -3
  60. data/spec/fixtures/nfe/lib/dest#render-without-address-complement.pdf +7 -3
  61. data/spec/fixtures/nfe/lib/det_body#render-csosn.pdf +383 -379
  62. data/spec/fixtures/nfe/lib/det_body#render-cst.pdf +233 -229
  63. data/spec/fixtures/nfe/lib/det_body#render-fci.pdf +158 -154
  64. data/spec/fixtures/nfe/lib/det_body#render-icms_st.pdf +158 -154
  65. data/spec/fixtures/nfe/lib/det_body#render-quantity_with_custom_precision.pdf +158 -154
  66. data/spec/fixtures/nfe/lib/det_body#render-three_pages.pdf +3697 -3685
  67. data/spec/fixtures/nfe/lib/det_body#render-two_pages.pdf +3540 -3532
  68. data/spec/fixtures/nfe/lib/det_body#render-unit_price_with_custom_precision.pdf +158 -154
  69. data/spec/fixtures/nfe/lib/det_body#render-with_infadprod.pdf +158 -154
  70. data/spec/fixtures/nfe/lib/det_body#render-with_issqn.pdf +1665 -1657
  71. data/spec/fixtures/nfe/lib/det_body#render-without_issqn.pdf +1665 -1657
  72. data/spec/fixtures/nfe/lib/document#lcnpj-blank.pdf +6 -2
  73. data/spec/fixtures/nfe/lib/document#lcnpj-invalid.pdf +6 -2
  74. data/spec/fixtures/nfe/lib/document#lcnpj-valid.pdf +6 -2
  75. data/spec/fixtures/nfe/lib/document#lie-blank-uf-invalid.pdf +6 -2
  76. data/spec/fixtures/nfe/lib/document#lie-blank.pdf +6 -2
  77. data/spec/fixtures/nfe/lib/document#lie-invalid.pdf +6 -2
  78. data/spec/fixtures/nfe/lib/document#lie-valid.pdf +6 -2
  79. data/spec/fixtures/nfe/lib/dup#render.pdf +8 -4
  80. data/spec/fixtures/nfe/lib/emit_header#render-second_page.pdf +9 -5
  81. data/spec/fixtures/nfe/lib/emit_header#render-with_logo.pdf +9 -5
  82. data/spec/fixtures/nfe/lib/emit_header#render-without_logo.pdf +7 -3
  83. data/spec/fixtures/nfe/lib/icmstot#render.pdf +7 -3
  84. data/spec/fixtures/nfe/lib/infadic#render-all_the_informations.pdf +8 -4
  85. data/spec/fixtures/nfe/lib/infadic#render-difal.pdf +7 -3
  86. data/spec/fixtures/nfe/lib/infadic#render-extra_volume.pdf +8 -4
  87. data/spec/fixtures/nfe/lib/infadic#render-with_complementary_information.pdf +7 -3
  88. data/spec/fixtures/nfe/lib/infadic#render-with_fisco_additional_information.pdf +7 -3
  89. data/spec/fixtures/nfe/lib/infadic#render-with_street_data.pdf +7 -3
  90. data/spec/fixtures/nfe/lib/infadic#render.pdf +7 -3
  91. data/spec/fixtures/nfe/lib/infadic_vol#render-extra_volume.pdf +7 -3
  92. data/spec/fixtures/nfe/lib/issqn#render-with_issqn.pdf +7 -3
  93. data/spec/fixtures/nfe/lib/issqn#render-with_one_issqn_value.pdf +7 -3
  94. data/spec/fixtures/nfe/lib/issqn#render-without_issqn.pdf +5 -1
  95. data/spec/fixtures/nfe/lib/ticket#render.pdf +6 -2
  96. data/spec/fixtures/nfe/lib/transp#render-modfrete_0.pdf +7 -3
  97. data/spec/fixtures/nfe/lib/transp#render-modfrete_1.pdf +7 -3
  98. data/spec/fixtures/nfe/lib/transp#render-modfrete_2.pdf +7 -3
  99. data/spec/fixtures/nfe/lib/transp#render-modfrete_3.pdf +7 -3
  100. data/spec/fixtures/nfe/lib/transp#render-modfrete_4.pdf +7 -3
  101. data/spec/fixtures/nfe/lib/transp#render-modfrete_9.pdf +7 -3
  102. data/spec/fixtures/nfe/lib/transp#render.pdf +7 -3
  103. data/spec/fixtures/nfe/lib/vol#render-blank-boxes.pdf +6 -2
  104. data/spec/fixtures/nfe/lib/vol#render.pdf +6 -2
  105. data/spec/fixtures/nfe/v2.00/custom_options.fixture.pdf +317 -313
  106. data/spec/fixtures/nfe/v2.00/nfe_simples_nacional.xml.fixture.pdf +315 -311
  107. data/spec/fixtures/nfe/v2.00/nfe_with_extra_volumes.xml.fixture.pdf +1297 -1289
  108. data/spec/fixtures/nfe/v2.00/nfe_with_fci.xml.fixture.pdf +165 -161
  109. data/spec/fixtures/nfe/v2.00/nfe_with_ns.xml.fixture.pdf +1297 -1289
  110. data/spec/fixtures/nfe/v2.00/nfe_without_ns.xml.fixture.pdf +314 -310
  111. data/spec/fixtures/nfe/v3.10/nfe_simples_nacional.xml.fixture.pdf +765 -761
  112. data/spec/fixtures/nfe/v3.10/with_footer.fixture.pdf +1222 -1214
  113. data/spec/fixtures/nfe/v3.10/with_issqn.fixture.pdf +1222 -1214
  114. data/spec/fixtures/nfe/v3.10/with_three_pages.fixture.pdf +4004 -3992
  115. data/spec/fixtures/nfe/v3.10/without_issqn.fixture.pdf +1522 -1514
  116. data/spec/lib/cce_lib/barcode_spec.rb +5 -5
  117. data/spec/lib/cce_lib/correction_spec.rb +5 -5
  118. data/spec/lib/cce_lib/document_spec.rb +23 -23
  119. data/spec/lib/cce_lib/footer_spec.rb +4 -4
  120. data/spec/lib/cce_lib/header_spec.rb +4 -4
  121. data/spec/lib/cce_lib/nfe_key_spec.rb +5 -5
  122. data/spec/lib/cce_lib/protocol_spec.rb +5 -5
  123. data/spec/lib/danfe_lib/cep_spec.rb +5 -5
  124. data/spec/lib/danfe_lib/cst_spec.rb +8 -8
  125. data/spec/lib/danfe_lib/dest_spec.rb +23 -23
  126. data/spec/lib/danfe_lib/det_body_spec.rb +26 -26
  127. data/spec/lib/danfe_lib/document_spec.rb +25 -25
  128. data/spec/lib/danfe_lib/dup_spec.rb +4 -4
  129. data/spec/lib/danfe_lib/emit_header_spec.rb +13 -13
  130. data/spec/lib/danfe_lib/helper_spec.rb +74 -74
  131. data/spec/lib/danfe_lib/icmstot_spec.rb +4 -4
  132. data/spec/lib/danfe_lib/infadic_spec.rb +6 -13
  133. data/spec/lib/danfe_lib/infadic_vol_spec.rb +1 -4
  134. data/spec/lib/danfe_lib/issqn_spec.rb +11 -11
  135. data/spec/lib/danfe_lib/logo_options_spec.rb +18 -18
  136. data/spec/lib/danfe_lib/options_spec.rb +7 -7
  137. data/spec/lib/danfe_lib/phone_spec.rb +10 -10
  138. data/spec/lib/danfe_lib/plate_spec.rb +9 -9
  139. data/spec/lib/danfe_lib/ticket_spec.rb +4 -4
  140. data/spec/lib/danfe_lib/transp_spec.rb +10 -10
  141. data/spec/lib/danfe_lib/vol_spec.rb +7 -7
  142. data/spec/lib/danfe_lib/xml_spec.rb +5 -5
  143. data/spec/lib/danfe_lib/xprod_spec.rb +48 -50
  144. data/spec/lib/uf_spec.rb +12 -12
  145. data/spec/support/have_same_content_of.rb +6 -6
  146. metadata +40 -10
@@ -11,32 +11,33 @@ module BrDanfe
11
11
  end
12
12
 
13
13
  def render
14
- @pdf.ititle 0.42, 10.00, 0.75, @ltitle, "dup.title"
14
+ @pdf.ititle 0.42, 10.00, 0.75, @ltitle, 'dup.title'
15
15
  @pdf.ibox 0.85, 19.57, 0.75, Y
16
16
 
17
17
  x = 0.75
18
18
  y = Y
19
- @xml.collect("xmlns", "dup") do |det|
19
+ @xml.collect('xmlns', 'dup') do |det|
20
20
  render_dup(det, x, y)
21
21
  x += 2.30
22
22
  end
23
23
  end
24
24
 
25
25
  private
26
+
26
27
  def render_dup(det, x, y)
27
- @pdf.ibox 0.85, 2.12, x, y, "", I18n.t("danfe.dup.nDup"), italic
28
- @pdf.ibox 0.85, 2.12, x + 0.70, y, "", det.css("nDup").text, normal
29
- @pdf.ibox 0.85, 2.12, x, y + 0.20, "", I18n.t("danfe.dup.dVenc"), italic
28
+ @pdf.ibox 0.85, 2.12, x, y, '', I18n.t('danfe.dup.nDup'), italic
29
+ @pdf.ibox 0.85, 2.12, x + 0.70, y, '', det.css('nDup').text, normal
30
+ @pdf.ibox 0.85, 2.12, x, y + 0.20, '', I18n.t('danfe.dup.dVenc'), italic
30
31
 
31
- @pdf.ibox 0.85, 2.12, x + 0.70, y + 0.20, "", dtduplicata(det), normal
32
+ @pdf.ibox 0.85, 2.12, x + 0.70, y + 0.20, '', dtduplicata(det), normal
32
33
 
33
- @pdf.ibox 0.85, 2.12, x, y + 0.40, "", I18n.t("danfe.dup.vDup"), italic
34
- @pdf.inumeric 0.85, 1.25, x + 0.70, y + 0.40, "", det.css("vDup").text, normal
34
+ @pdf.ibox 0.85, 2.12, x, y + 0.40, '', I18n.t('danfe.dup.vDup'), italic
35
+ @pdf.inumeric 0.85, 1.25, x + 0.70, y + 0.40, '', det.css('vDup').text, normal
35
36
  end
36
37
 
37
38
  def dtduplicata(det)
38
- dtduplicata = det.css("dVenc").text
39
- dtduplicata = dtduplicata[8,2] + "/" + dtduplicata[5, 2] + "/" + dtduplicata[0, 4]
39
+ dtduplicata = det.css('dVenc').text
40
+ dtduplicata = dtduplicata[8, 2] + '/' + dtduplicata[5, 2] + '/' + dtduplicata[0, 4]
40
41
  dtduplicata
41
42
  end
42
43
 
@@ -21,42 +21,44 @@ module BrDanfe
21
21
 
22
22
  def company_box
23
23
  @pdf.ibox 3.92, 7.46, 0.75, @y_position
24
- @pdf.ibox 3.92, 7.46, 0.75, @y_position, "", @xml["emit/xNome"],
25
- { size: 12, align: :center, border: 0, style: :bold }
24
+ @pdf.ibox 3.92, 7.46, 0.75, @y_position, '', @xml['emit/xNome'],
25
+ { size: 12, align: :center, border: 0, style: :bold }
26
26
 
27
27
  address_company
28
28
  end
29
29
 
30
30
  def address_company
31
31
  if @logo.blank?
32
- @pdf.ibox 3.92, 7.46, 1.25, @y_position + 1.46, "", address, { align: :left, border: 0 }
32
+ @pdf.ibox 3.92, 7.46, 1.25, @y_position + 1.46, '', address, { align: :left, border: 0 }
33
33
  else
34
- @pdf.ibox 3.92, 7.46, 3.60, @y_position + 1.46, "", address, { size: 8, align: :left, border: 0 }
34
+ @pdf.ibox 3.92, 7.46, 3.60, @y_position + 1.46, '', address, { size: 8, align: :left, border: 0 }
35
35
  logo
36
36
  end
37
37
  end
38
38
 
39
39
  def address
40
- formatted = @xml["enderEmit/xLgr"] + ", " + @xml["enderEmit/nro"] + "\n"
41
- formatted += @xml["enderEmit/xBairro"] + " - " + cep + "\n"
42
- formatted += @xml["enderEmit/xMun"] + "/" + @xml["enderEmit/UF"] + "\n"
43
- formatted += phone + " " + @xml["enderEmit/email"]
40
+ formatted = @xml['enderEmit/xLgr'] + ', ' + @xml['enderEmit/nro'] + "\n"
41
+ formatted += @xml['enderEmit/xBairro'] + ' - ' + cep + "\n"
42
+ formatted += @xml['enderEmit/xMun'] + '/' + @xml['enderEmit/UF'] + "\n"
43
+ formatted += phone + ' ' + @xml['enderEmit/email']
44
44
  formatted
45
45
  end
46
46
 
47
47
  def phone
48
- Phone.format(@xml["enderEmit/fone"])
48
+ Phone.format(@xml['enderEmit/fone'])
49
49
  end
50
50
 
51
51
  def cep
52
- Cep.format(@xml["enderEmit/CEP"])
52
+ Cep.format(@xml['enderEmit/CEP'])
53
53
  end
54
54
 
55
55
  def logo
56
56
  bounding_box_size = 80
57
57
  logo_options = BrDanfe::DanfeLib::LogoOptions.new(bounding_box_size, @logo_dimensions).options
58
58
 
59
- @pdf.bounding_box([0.83.cm, Helper.invert(@y_position.cm + 1.02.cm)], width: bounding_box_size, height: bounding_box_size) do
59
+ @pdf.bounding_box(
60
+ [0.83.cm, Helper.invert(@y_position.cm + 1.02.cm)], width: bounding_box_size, height: bounding_box_size
61
+ ) do
60
62
  @pdf.image @logo, logo_options
61
63
  end
62
64
  end
@@ -64,47 +66,49 @@ module BrDanfe
64
66
  def danfe_box(page)
65
67
  @pdf.ibox 3.92, 2.08, 8.21, @y_position
66
68
 
67
- @pdf.ibox 0.60, 2.08, 8.21, @y_position, "", "DANFE",
68
- { size: 12, align: :center, border: 0, style: :bold }
69
+ @pdf.ibox 0.60, 2.08, 8.21, @y_position, '', 'DANFE',
70
+ { size: 12, align: :center, border: 0, style: :bold }
69
71
 
70
- @pdf.ibox 1.20, 2.08, 8.21, @y_position + 0.60, "", I18n.t("danfe.others.danfe"),
71
- { size: 8, align: :center, border: 0 }
72
+ @pdf.ibox 1.20, 2.08, 8.21, @y_position + 0.60, '', I18n.t('danfe.others.danfe'),
73
+ { size: 8, align: :center, border: 0 }
72
74
 
73
- @pdf.ibox 0.60, 2.08, 8.21, @y_position + 1.80, "", "#{@xml['ide/tpNF']} - " + (@xml["ide/tpNF"] == "0" ? I18n.t("danfe.ide.tpNF.entry") : I18n.t("danfe.ide.tpNF.departure")),
74
- { size: 8, align: :center, border: 0 }
75
+ @pdf.ibox 0.60, 2.08, 8.21, @y_position + 1.80, '',
76
+ "#{@xml['ide/tpNF']} - " +
77
+ (@xml['ide/tpNF'] == '0' ? I18n.t('danfe.ide.tpNF.entry') : I18n.t('danfe.ide.tpNF.departure')),
78
+ { size: 8, align: :center, border: 0 }
75
79
 
76
- @pdf.ibox 1.00, 2.08, 8.21, @y_position + 2.40, "",
77
- I18n.t("danfe.ide.document", nNF: @xml["ide/nNF"], serie: @xml["ide/serie"]),
78
- { size: 8, align: :center, valign: :center, border: 0, style: :bold }
80
+ @pdf.ibox 1.00, 2.08, 8.21, @y_position + 2.40, '',
81
+ I18n.t('danfe.ide.document', nNF: @xml['ide/nNF'], serie: @xml['ide/serie']),
82
+ { size: 8, align: :center, valign: :center, border: 0, style: :bold }
79
83
 
80
- @pdf.ibox 1.00, 2.08, 8.21, @y_position + 3.00, "",
81
- I18n.t("danfe.others.page", current: page, total: @pdf.page_count),
82
- { size: 8, align: :center, valign: :center, border: 0, style: :bold }
84
+ @pdf.ibox 1.00, 2.08, 8.21, @y_position + 3.00, '',
85
+ I18n.t('danfe.others.page', current: page, total: @pdf.page_count),
86
+ { size: 8, align: :center, valign: :center, border: 0, style: :bold }
83
87
  end
84
88
 
85
89
  def access_key_box
86
90
  @pdf.ibox 2.22, 10.02, 10.29, @y_position
87
- @pdf.ibarcode 1.50, 8.00, 10.4010, @y_position + 1.90, @xml["chNFe"]
88
- @pdf.ibox 0.85, 10.02, 10.29, @y_position + 2.22, I18n.t("danfe.chNFe"), @xml["chNFe"].gsub(/(\d)(?=(\d\d\d\d)+(?!\d))/, "\\1 "),
89
- { style: :bold, align: :center }
91
+ @pdf.ibarcode 1.50, 8.00, 10.4010, @y_position + 1.90, @xml['chNFe']
92
+ @pdf.ibox 0.85, 10.02, 10.29, @y_position + 2.22, I18n.t('danfe.chNFe'),
93
+ @xml['chNFe'].gsub(/(\d)(?=(\d\d\d\d)+(?!\d))/, '\\1 '), { style: :bold, align: :center }
90
94
  end
91
95
 
92
96
  def sefaz_box
93
- @pdf.ibox 0.85, 10.02, 10.29, @y_position + 3.07, "", I18n.t("danfe.others.sefaz"),
94
- { align: :center, size: 8 }
97
+ @pdf.ibox 0.85, 10.02, 10.29, @y_position + 3.07, '', I18n.t('danfe.others.sefaz'),
98
+ { align: :center, size: 8 }
95
99
  end
96
100
 
97
101
  def render_emit(y_position)
98
102
  y_first_line = y_position + 3.92
99
103
  y_second_line = y_first_line + LINE_HEIGHT
100
104
 
101
- @pdf.lbox LINE_HEIGHT, 10.04, 0.75, y_first_line, @xml, "ide/natOp"
102
- @pdf.ibox LINE_HEIGHT, 9.52, 10.79, y_first_line, I18n.t("danfe.infProt"),
103
- "#{@xml["infProt/nProt"]} #{Helper.format_datetime(@xml["infProt/dhRecbto"])}", { align: :center }
105
+ @pdf.lbox LINE_HEIGHT, 10.04, 0.75, y_first_line, @xml, 'ide/natOp'
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 }
104
108
 
105
- @pdf.lie LINE_HEIGHT, 6.36, 0.75, y_second_line, @xml, "enderEmit/UF", "emit/IE"
106
- @pdf.lie LINE_HEIGHT, 6.86, 7.11, y_second_line, @xml, "enderDest/UF", "emit/IEST"
107
- @pdf.lcnpj LINE_HEIGHT, 6.34, 13.97, y_second_line, @xml, "emit/CNPJ"
109
+ @pdf.lie LINE_HEIGHT, 6.36, 0.75, y_second_line, @xml, 'enderEmit/UF', 'emit/IE'
110
+ @pdf.lie LINE_HEIGHT, 6.86, 7.11, y_second_line, @xml, 'enderDest/UF', 'emit/IEST'
111
+ @pdf.lcnpj LINE_HEIGHT, 6.34, 13.97, y_second_line, @xml, 'emit/CNPJ'
108
112
  end
109
113
  end
110
114
  end
@@ -2,14 +2,14 @@ module BrDanfe
2
2
  module DanfeLib
3
3
  class Helper
4
4
  def self.numerify(number)
5
- return "" if !number || number == ""
5
+ return '' if !number || number == ''
6
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 = decimal_part + "0" if decimal_part.size < 2
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
11
 
12
- integer_part + "," + decimal_part
12
+ integer_part + ',' + decimal_part
13
13
  end
14
14
 
15
15
  def self.invert(y)
@@ -17,50 +17,50 @@ module BrDanfe
17
17
  end
18
18
 
19
19
  def self.format_datetime(xml_datetime)
20
- formated = ""
20
+ formated = ''
21
21
 
22
- if !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")
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
25
  end
26
26
 
27
27
  formated
28
28
  end
29
29
 
30
30
  def self.format_date(xml_datetime)
31
- formated = ""
31
+ formated = ''
32
32
 
33
- if !xml_datetime.empty?
34
- date = DateTime.strptime(xml_datetime, "%Y-%m-%d")
35
- formated = date.strftime("%d/%m/%Y")
33
+ unless xml_datetime.empty?
34
+ date = DateTime.strptime(xml_datetime, '%Y-%m-%d')
35
+ formated = date.strftime('%d/%m/%Y')
36
36
  end
37
37
 
38
38
  formated
39
39
  end
40
40
 
41
41
  def self.format_time(xml_datetime)
42
- formated = ""
42
+ formated = ''
43
43
 
44
44
  if xml_datetime.length == 8
45
45
  formated = xml_datetime
46
46
  elsif xml_datetime.length > 8
47
- date = DateTime.strptime(xml_datetime, "%Y-%m-%dT%H:%M:%S %Z").to_time
48
- formated = date.strftime("%H:%M:%S")
47
+ date = DateTime.strptime(xml_datetime, '%Y-%m-%dT%H:%M:%S %Z').to_time
48
+ formated = date.strftime('%H:%M:%S')
49
49
  end
50
50
 
51
51
  formated
52
52
  end
53
53
 
54
- def self.has_no_fiscal_value?(xml)
54
+ def self.no_fiscal_value?(xml)
55
55
  homologation?(xml) || unauthorized?(xml)
56
56
  end
57
57
 
58
58
  def self.homologation?(xml)
59
- xml_text(xml, "nfeProc/NFe/infNFe/ide/tpAmb") == "2"
59
+ xml_text(xml, 'nfeProc/NFe/infNFe/ide/tpAmb') == '2'
60
60
  end
61
61
 
62
62
  def self.unauthorized?(xml)
63
- xml.css("nfeProc/protNFe/infProt/dhRecbto").empty?
63
+ xml.css('nfeProc/protNFe/infProt/dhRecbto').empty?
64
64
  end
65
65
 
66
66
  def self.mensure_text(pdf, text)
@@ -72,9 +72,9 @@ module BrDanfe
72
72
  end
73
73
 
74
74
  def self.generate_address(xml)
75
- address_complement = " - #{xml_text(xml, "enderDest/xCpl")}" if xml_text(xml, "enderDest/xCpl").present?
76
- address_number = " #{xml_text(xml, "enderDest/nro")}" if xml_text(xml, "enderDest/nro").present?
77
- "#{xml_text(xml, "enderDest/xLgr")}#{address_number}#{address_complement}"
75
+ address_complement = " - #{xml_text(xml, 'enderDest/xCpl')}" if xml_text(xml, 'enderDest/xCpl').present?
76
+ address_number = " #{xml_text(xml, 'enderDest/nro')}" if xml_text(xml, 'enderDest/nro').present?
77
+ "#{xml_text(xml, 'enderDest/xLgr')}#{address_number}#{address_complement}"
78
78
  end
79
79
 
80
80
  def self.xml_text(xml, property)
@@ -13,20 +13,20 @@ module BrDanfe
13
13
  end
14
14
 
15
15
  def render
16
- @pdf.ititle 0.42, 5.60, 0.75, @ltitle, "ICMSTot.title"
16
+ @pdf.ititle 0.42, 5.60, 0.75, @ltitle, 'ICMSTot.title'
17
17
 
18
- @pdf.lnumeric LINE_HEIGHT, 3.56, 0.75, @l1, @xml, "ICMSTot/vBC"
19
- @pdf.lnumeric LINE_HEIGHT, 4.06, 4.31, @l1, @xml, "ICMSTot/vICMS"
20
- @pdf.lnumeric LINE_HEIGHT, 4.06, 8.37, @l1, @xml, "ICMSTot/vBCST"
21
- @pdf.lnumeric LINE_HEIGHT, 4.06, 12.43, @l1, @xml, "ICMSTot/vST"
22
- @pdf.lnumeric LINE_HEIGHT, 3.82, 16.49, @l1, @xml, "ICMSTot/vProd"
18
+ @pdf.lnumeric LINE_HEIGHT, 3.56, 0.75, @l1, @xml, 'ICMSTot/vBC'
19
+ @pdf.lnumeric LINE_HEIGHT, 4.06, 4.31, @l1, @xml, 'ICMSTot/vICMS'
20
+ @pdf.lnumeric LINE_HEIGHT, 4.06, 8.37, @l1, @xml, 'ICMSTot/vBCST'
21
+ @pdf.lnumeric LINE_HEIGHT, 4.06, 12.43, @l1, @xml, 'ICMSTot/vST'
22
+ @pdf.lnumeric LINE_HEIGHT, 3.82, 16.49, @l1, @xml, 'ICMSTot/vProd'
23
23
 
24
- @pdf.lnumeric LINE_HEIGHT, 2.55, 0.75, @l2, @xml, "ICMSTot/vFrete"
25
- @pdf.lnumeric LINE_HEIGHT, 3.05, 3.30, @l2, @xml, "ICMSTot/vSeg"
26
- @pdf.lnumeric LINE_HEIGHT, 3.04, 6.35, @l2, @xml, "ICMSTot/vDesc"
27
- @pdf.lnumeric LINE_HEIGHT, 3.04, 9.39, @l2, @xml, "ICMSTot/vOutro"
28
- @pdf.lnumeric LINE_HEIGHT, 4.06, 12.43, @l2, @xml, "ICMSTot/vIPI"
29
- @pdf.lnumeric LINE_HEIGHT, 3.82, 16.49, @l2, @xml, "ICMSTot/vNF", style: :bold
24
+ @pdf.lnumeric LINE_HEIGHT, 2.55, 0.75, @l2, @xml, 'ICMSTot/vFrete'
25
+ @pdf.lnumeric LINE_HEIGHT, 3.05, 3.30, @l2, @xml, 'ICMSTot/vSeg'
26
+ @pdf.lnumeric LINE_HEIGHT, 3.04, 6.35, @l2, @xml, 'ICMSTot/vDesc'
27
+ @pdf.lnumeric LINE_HEIGHT, 3.04, 9.39, @l2, @xml, 'ICMSTot/vOutro'
28
+ @pdf.lnumeric LINE_HEIGHT, 4.06, 12.43, @l2, @xml, 'ICMSTot/vIPI'
29
+ @pdf.lnumeric LINE_HEIGHT, 3.82, 16.49, @l2, @xml, 'ICMSTot/vNF', style: :bold
30
30
  end
31
31
  end
32
32
  end
@@ -91,6 +91,7 @@ module BrDanfe
91
91
  if volumes_number > 1
92
92
  return Y_POSITION + 0.30 + volumes_number * 0.15 + 0.2
93
93
  end
94
+
94
95
  Y_POSITION + 0.30
95
96
  end
96
97
 
@@ -10,15 +10,15 @@ module BrDanfe
10
10
  @title = Y_POSITION - 0.42
11
11
  @y_position = Y_POSITION
12
12
 
13
- @serv = "total/ISSQNtot/vServ"
14
- @bc = "total/ISSQNtot/vBC"
15
- @iss = "total/ISSQNtot/vISS"
13
+ @serv = 'total/ISSQNtot/vServ'
14
+ @bc = 'total/ISSQNtot/vBC'
15
+ @iss = 'total/ISSQNtot/vISS'
16
16
  end
17
17
 
18
18
  def render
19
19
  if can_render?
20
- @pdf.ititle 0.42, 10.00, 0.75, @title, "issqn.title"
21
- @pdf.lbox LINE_HEIGHT, 4.64, 0.75, @y_position, @xml, "emit/IM"
20
+ @pdf.ititle 0.42, 10.00, 0.75, @title, 'issqn.title'
21
+ @pdf.lbox LINE_HEIGHT, 4.64, 0.75, @y_position, @xml, 'emit/IM'
22
22
  @pdf.lnumeric LINE_HEIGHT, 5.14, 5.39, @y_position, @xml, @serv
23
23
  @pdf.lnumeric LINE_HEIGHT, 5.14, 10.53, @y_position, @xml, @bc
24
24
  @pdf.lnumeric LINE_HEIGHT, 4.64, 15.67, @y_position, @xml, @iss
@@ -28,7 +28,7 @@ module BrDanfe
28
28
  private
29
29
 
30
30
  def can_render?
31
- (@xml[@serv].to_i > 0) || (@xml[@bc].to_i > 0) || (@xml[@iss].to_i > 0)
31
+ @xml[@serv].to_i.positive? || @xml[@bc].to_i.positive? || @xml[@iss].to_i.positive?
32
32
  end
33
33
  end
34
34
  end
@@ -1,21 +1,22 @@
1
1
  module BrDanfe
2
2
  module DanfeLib
3
3
  class Options < OpenStruct
4
- DEFAULTOPTIONS = { logo: "", logo_dimensions: {} }
4
+ DEFAULTOPTIONS = { logo: '', logo_dimensions: {} }.freeze
5
5
 
6
- def initialize(new_options={})
6
+ def initialize(new_options = {})
7
7
  options = DEFAULTOPTIONS.merge(config_yaml_load)
8
8
  super options.merge(new_options)
9
9
  end
10
10
 
11
11
  private
12
+
12
13
  def file
13
- File.exists?("config/br_danfe.yml") ? File.open("config/br_danfe.yml").read : ""
14
+ File.exist?('config/br_danfe.yml') ? File.open('config/br_danfe.yml').read : ''
14
15
  end
15
16
 
16
17
  def config_yaml_load
17
- @file_read = YAML.load( file )
18
- @file_read ? (@file_read["br_danfe"]||{})["options"] : {}
18
+ @file_read = YAML.safe_load(file)
19
+ @file_read ? (@file_read['br_danfe'] || {})['options'] : {}
19
20
  end
20
21
  end
21
22
  end
@@ -3,9 +3,9 @@ module BrDanfe
3
3
  class Phone
4
4
  def self.format(phone)
5
5
  if phone.length == 10
6
- phone.sub(/(\d{2})(\d{4})(\d{4})/, "(\\1) \\2-\\3")
6
+ phone.sub(/(\d{2})(\d{4})(\d{4})/, '(\\1) \\2-\\3')
7
7
  else
8
- phone.sub(/(\d{2})(\d{5})(\d{4})/, "(\\1) \\2-\\3")
8
+ phone.sub(/(\d{2})(\d{5})(\d{4})/, '(\\1) \\2-\\3')
9
9
  end
10
10
  end
11
11
  end
@@ -7,10 +7,12 @@ module BrDanfe
7
7
  end
8
8
 
9
9
  def render
10
- @pdf.ibox 0.85, 15.60, 0.75, 1.85, I18n.t("danfe.ticket.xNome", xNome: @xml["emit/xNome"])
11
- @pdf.ibox 0.85, 3.85, 0.75, 2.7, I18n.t("danfe.ticket.received_at")
12
- @pdf.ibox 0.85, 11.75, 4.60, 2.7, I18n.t("danfe.ticket.receiver")
13
- @pdf.ibox 1.70, 4.00, 16.35, 1.85, "", I18n.t("danfe.ticket.document", nNF: @xml["ide/nNF"], serie: @xml["ide/serie"]), {align: :center, valign: :center}
10
+ @pdf.ibox 0.85, 15.60, 0.75, 1.85, I18n.t('danfe.ticket.xNome', xNome: @xml['emit/xNome'])
11
+ @pdf.ibox 0.85, 3.85, 0.75, 2.7, I18n.t('danfe.ticket.received_at')
12
+ @pdf.ibox 0.85, 11.75, 4.60, 2.7, I18n.t('danfe.ticket.receiver')
13
+ @pdf.ibox 1.70, 4.00, 16.35, 1.85, '',
14
+ I18n.t('danfe.ticket.document', nNF: @xml['ide/nNF'], serie: @xml['ide/serie']),
15
+ { align: :center, valign: :center }
14
16
  end
15
17
  end
16
18
  end
@@ -13,39 +13,40 @@ module BrDanfe
13
13
  end
14
14
 
15
15
  def render
16
- @pdf.ititle 0.42, 10.00, 0.75, @ltitle, "transporta.title"
17
-
18
- @pdf.lbox LINE_HEIGHT, 8.52, 0.75, @l1, @xml, "transporta/xNome"
19
- @pdf.i18n_lbox LINE_HEIGHT, 2.79, 9.27, @l1, "transp.modFrete.title", mod_frete
20
- @pdf.lbox LINE_HEIGHT, 1.78, 12.06, @l1, @xml, "veicTransp/RNTC"
21
- @pdf.i18n_lbox LINE_HEIGHT, 2.29, 13.84, @l1, "veicTransp.placa", plate
22
- @pdf.lbox LINE_HEIGHT, 0.76, 16.13, @l1, @xml, "veicTransp/UF"
23
- @pdf.lcnpj LINE_HEIGHT, 3.44, 16.89, @l1, @xml, "transporta/CNPJ"
24
- @pdf.lbox LINE_HEIGHT, 8.52, 0.75, @l2, @xml, "transporta/xEnder"
25
- @pdf.lbox LINE_HEIGHT, 6.86, 9.27, @l2, @xml, "transporta/xMun"
26
- @pdf.lbox LINE_HEIGHT, 0.76, 16.13, @l2, @xml, "transporta/UF"
27
- @pdf.lie LINE_HEIGHT, 3.44, 16.89, @l2, @xml, "transporta/UF", "transporta/IE"
16
+ @pdf.ititle 0.42, 10.00, 0.75, @ltitle, 'transporta.title'
17
+
18
+ @pdf.lbox LINE_HEIGHT, 8.52, 0.75, @l1, @xml, 'transporta/xNome'
19
+ @pdf.i18n_lbox LINE_HEIGHT, 2.79, 9.27, @l1, 'transp.modFrete.title', mod_frete
20
+ @pdf.lbox LINE_HEIGHT, 1.78, 12.06, @l1, @xml, 'veicTransp/RNTC'
21
+ @pdf.i18n_lbox LINE_HEIGHT, 2.29, 13.84, @l1, 'veicTransp.placa', plate
22
+ @pdf.lbox LINE_HEIGHT, 0.76, 16.13, @l1, @xml, 'veicTransp/UF'
23
+ @pdf.lcnpj LINE_HEIGHT, 3.44, 16.89, @l1, @xml, 'transporta/CNPJ'
24
+ @pdf.lbox LINE_HEIGHT, 8.52, 0.75, @l2, @xml, 'transporta/xEnder'
25
+ @pdf.lbox LINE_HEIGHT, 6.86, 9.27, @l2, @xml, 'transporta/xMun'
26
+ @pdf.lbox LINE_HEIGHT, 0.76, 16.13, @l2, @xml, 'transporta/UF'
27
+ @pdf.lie LINE_HEIGHT, 3.44, 16.89, @l2, @xml, 'transporta/UF', 'transporta/IE'
28
28
  end
29
29
 
30
30
  private
31
+
31
32
  def plate
32
- Plate.format(@xml["veicTransp/placa"])
33
+ Plate.format(@xml['veicTransp/placa'])
33
34
  end
34
35
 
35
36
  def mod_frete
36
- case @xml["transp/modFrete"]
37
- when "0"
38
- modality = "emitter"
39
- when "1"
40
- modality = "recipient"
41
- when "2"
42
- modality = "third_party"
43
- when "3"
44
- modality = "own_emitter"
45
- when "4"
46
- modality = "own_recipient"
47
- when "9"
48
- modality = "no_freight"
37
+ case @xml['transp/modFrete']
38
+ when '0'
39
+ modality = 'emitter'
40
+ when '1'
41
+ modality = 'recipient'
42
+ when '2'
43
+ modality = 'third_party'
44
+ when '3'
45
+ modality = 'own_emitter'
46
+ when '4'
47
+ modality = 'own_recipient'
48
+ when '9'
49
+ modality = 'no_freight'
49
50
  end
50
51
 
51
52
  I18n.t("danfe.transp.modFrete.#{modality}")