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
@@ -8,15 +8,16 @@ module BrDanfe
8
8
 
9
9
  def render
10
10
  @pdf.box(height: 36) do
11
- @pdf.text I18n.t("cce.protocol"), size: 8, style: :bold
11
+ @pdf.text I18n.t('cce.protocol'), size: 8, style: :bold
12
12
  @pdf.text protocol, pad: 5
13
13
  end
14
14
  end
15
15
 
16
16
  private
17
+
17
18
  def protocol
18
- node = @xml.css("procEventoNFe > retEvento > infEvento > nProt")
19
- return node ? node.text : ""
19
+ node = @xml.css('procEventoNFe > retEvento > infEvento > nProt')
20
+ node ? node.text : ''
20
21
  end
21
22
  end
22
23
  end
@@ -10,12 +10,12 @@ module BrDanfe
10
10
  create_watermark
11
11
  end
12
12
 
13
- def save_pdf(filename, footer_info = "")
13
+ def save_pdf(filename, footer_info = '')
14
14
  generate footer_info
15
15
  @pdf.render_file filename
16
16
  end
17
17
 
18
- def render_pdf(footer_info = "")
18
+ def render_pdf(footer_info = '')
19
19
  generate footer_info
20
20
  @pdf.render
21
21
  end
@@ -23,17 +23,17 @@ module BrDanfe
23
23
  private
24
24
 
25
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
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
37
  end
38
38
  end
39
39
 
@@ -65,7 +65,7 @@ module BrDanfe
65
65
 
66
66
  @pdf.page_count.times do |i|
67
67
  page = i + 1
68
- position = page === 1 ? 3.96 : 1.85
68
+ position = page == 1 ? 3.96 : 1.85
69
69
  repeated_information page, position, emitter, footer_info
70
70
  end
71
71
  end
@@ -81,17 +81,17 @@ module BrDanfe
81
81
 
82
82
  def render_product_table_title(page)
83
83
  y_position = page == 1 ? 18.91 : 7.40
84
- @pdf.ititle 0.42, 10.00, 0.75, y_position, "det.title"
84
+ @pdf.ititle 0.42, 10.00, 0.75, y_position, 'det.title'
85
85
  end
86
86
 
87
87
  def render_footer_information(footer_info)
88
88
  if footer_info.present?
89
- @pdf.ibox 0.35, 12.45, 0.75, 30.21, "", footer_info, { size: 5, border: 0 }
89
+ @pdf.ibox 0.35, 12.45, 0.75, 30.21, '', footer_info, { size: 5, border: 0 }
90
90
  end
91
91
  end
92
92
 
93
93
  def render_no_fiscal_value
94
- @pdf.stamp("has_no_fiscal_value") if DanfeLib::Helper.has_no_fiscal_value?(@xml)
94
+ @pdf.stamp('has_no_fiscal_value') if DanfeLib::Helper.no_fiscal_value?(@xml)
95
95
  end
96
96
  end
97
97
  end
@@ -2,7 +2,7 @@ module BrDanfe
2
2
  module DanfeLib
3
3
  class Cep
4
4
  def self.format(cep)
5
- cep.sub(/(\d{2})(\d{3})(\d{3})/, "\\1.\\2-\\3")
5
+ cep.sub(/(\d{2})(\d{3})(\d{3})/, '\\1.\\2-\\3')
6
6
  end
7
7
  end
8
8
  end
@@ -5,26 +5,28 @@ module BrDanfe
5
5
  value = origin(xml)
6
6
 
7
7
  if csosn?(xml)
8
- value += xml.css("ICMS/*/CSOSN").text
8
+ value += xml.css('ICMS/*/CSOSN').text
9
9
  elsif cst?(xml)
10
- value += xml.css("ICMS/*/CST").text
10
+ value += xml.css('ICMS/*/CST').text
11
11
  end
12
12
 
13
13
  value
14
14
  end
15
15
 
16
- private
17
16
  def self.origin(xml)
18
- xml.css("ICMS/*/orig").text
17
+ xml.css('ICMS/*/orig').text
19
18
  end
19
+ private_class_method :origin
20
20
 
21
21
  def self.cst?(xml)
22
- xml.css("ICMS/*/CST").text != ""
22
+ xml.css('ICMS/*/CST').text != ''
23
23
  end
24
+ private_class_method :cst?
24
25
 
25
26
  def self.csosn?(xml)
26
- xml.css("ICMS/*/CSOSN").text != ""
27
+ xml.css('ICMS/*/CSOSN').text != ''
27
28
  end
29
+ private_class_method :csosn?
28
30
  end
29
31
  end
30
32
  end
@@ -16,7 +16,7 @@ module BrDanfe
16
16
  end
17
17
 
18
18
  def render
19
- @pdf.ititle 0.42, 10.00, 0.75, @ltitle, "dest.title"
19
+ @pdf.ititle 0.42, 10.00, 0.75, @ltitle, 'dest.title'
20
20
 
21
21
  render_line1
22
22
  render_line2
@@ -28,68 +28,66 @@ module BrDanfe
28
28
  private
29
29
 
30
30
  def render_line1
31
- @pdf.lbox LINE_HEIGHT, 11.82, 0.75, @l1, @xml, "dest/xNome"
31
+ @pdf.lbox LINE_HEIGHT, 11.82, 0.75, @l1, @xml, 'dest/xNome'
32
32
  render_cnpj_cpf
33
33
  end
34
34
 
35
35
  def render_cnpj_cpf
36
- if @xml["dest/CNPJ"] == ""
37
- @pdf.i18n_lbox LINE_HEIGHT, 4.37, 12.57, @l1, "dest.CPF", cpf
36
+ if @xml['dest/CNPJ'] == ''
37
+ @pdf.i18n_lbox LINE_HEIGHT, 4.37, 12.57, @l1, 'dest.CPF', cpf
38
38
  else
39
- @pdf.lcnpj LINE_HEIGHT, 4.37, 12.57, @l1, @xml, "dest/CNPJ"
39
+ @pdf.lcnpj LINE_HEIGHT, 4.37, 12.57, @l1, @xml, 'dest/CNPJ'
40
40
  end
41
41
  end
42
42
 
43
43
  def cpf
44
- cpf = BrDocuments::CnpjCpf::Cpf.new(@xml["dest/CPF"])
44
+ cpf = BrDocuments::CnpjCpf::Cpf.new(@xml['dest/CPF'])
45
45
  cpf.formatted
46
46
  end
47
47
 
48
48
  def render_line2
49
- @pdf.i18n_lbox LINE_HEIGHT, 9.66, 0.75, @l2, "enderDest.xLgr", address
50
- @pdf.lbox LINE_HEIGHT, 4.33, 10.41, @l2, @xml, "enderDest/xBairro"
51
- @pdf.i18n_lbox LINE_HEIGHT, 2.20, 14.74, @l2, "enderDest.CEP", cep
49
+ @pdf.i18n_lbox LINE_HEIGHT, 9.66, 0.75, @l2, 'enderDest.xLgr', address
50
+ @pdf.lbox LINE_HEIGHT, 4.33, 10.41, @l2, @xml, 'enderDest/xBairro'
51
+ @pdf.i18n_lbox LINE_HEIGHT, 2.20, 14.74, @l2, 'enderDest.CEP', cep
52
52
  end
53
53
 
54
54
  def address
55
55
  address = Helper.generate_address @xml
56
56
 
57
57
  if Helper.address_is_too_big(@pdf, address)
58
- while Helper.mensure_text(@pdf, "#{address.strip}...") > MAXIMUM_SIZE_FOR_STREET && address.length > 0 do
59
- address = address[0..address.length-2]
60
- end
58
+ address = address[0..address.length - 2] while Helper.mensure_text(@pdf, "#{address.strip}...") > MAXIMUM_SIZE_FOR_STREET && !address.empty?
61
59
  address = "#{address.strip}..."
62
60
  end
63
61
  address
64
62
  end
65
63
 
66
64
  def cep
67
- Cep.format(@xml["enderDest/CEP"])
65
+ Cep.format(@xml['enderDest/CEP'])
68
66
  end
69
67
 
70
68
  def render_line3
71
- @pdf.lbox LINE_HEIGHT, 6.61, 0.75, @l3, @xml, "enderDest/xMun"
72
- @pdf.i18n_lbox LINE_HEIGHT, 4.06, 7.36, @l3, "enderDest.fone", phone
73
- @pdf.lbox LINE_HEIGHT, 1.14, 11.42, @l3, @xml, "enderDest/UF"
74
- @pdf.lie LINE_HEIGHT, 4.38, 12.56, @l3, @xml, "enderDest/UF", "dest/IE"
69
+ @pdf.lbox LINE_HEIGHT, 6.61, 0.75, @l3, @xml, 'enderDest/xMun'
70
+ @pdf.i18n_lbox LINE_HEIGHT, 4.06, 7.36, @l3, 'enderDest.fone', phone
71
+ @pdf.lbox LINE_HEIGHT, 1.14, 11.42, @l3, @xml, 'enderDest/UF'
72
+ @pdf.lie LINE_HEIGHT, 4.38, 12.56, @l3, @xml, 'enderDest/UF', 'dest/IE'
75
73
  end
76
74
 
77
75
  def phone
78
- Phone.format(@xml["enderDest/fone"])
76
+ Phone.format(@xml['enderDest/fone'])
79
77
  end
80
78
 
81
79
  def render_dates_for_nfe_310_or_newer
82
- render_dates "ide/dhEmi", "ide/dhSaiEnt", "ide/dhSaiEnt"
80
+ render_dates 'ide/dhEmi', 'ide/dhSaiEnt', 'ide/dhSaiEnt'
83
81
  end
84
82
 
85
83
  def render_dates(emitted_at_date_and_hour, exited_at_date, exited_at_hour)
86
- @pdf.ldate LINE_HEIGHT, 2.92, 17.40, @l1, "ide.dEmi", @xml[emitted_at_date_and_hour], { align: :right }
87
- @pdf.ldate LINE_HEIGHT, 2.92, 17.40, @l2, "ide.dSaiEnt", @xml[exited_at_date], { align: :right }
88
- @pdf.ltime LINE_HEIGHT, 2.92, 17.40, @l3, "ide.hSaiEnt", @xml[exited_at_hour], { align: :right }
84
+ @pdf.ldate LINE_HEIGHT, 2.92, 17.40, @l1, 'ide.dEmi', @xml[emitted_at_date_and_hour], { align: :right }
85
+ @pdf.ldate LINE_HEIGHT, 2.92, 17.40, @l2, 'ide.dSaiEnt', @xml[exited_at_date], { align: :right }
86
+ @pdf.ltime LINE_HEIGHT, 2.92, 17.40, @l3, 'ide.hSaiEnt', @xml[exited_at_hour], { align: :right }
89
87
  end
90
88
 
91
89
  def render_dates_for_older_nfes
92
- render_dates "ide/dEmi", "ide/dSaiEnt", "ide/hSaiEnt"
90
+ render_dates 'ide/dEmi', 'ide/dSaiEnt', 'ide/hSaiEnt'
93
91
  end
94
92
  end
95
93
  end
@@ -27,11 +27,11 @@ module BrDanfe
27
27
 
28
28
  def create_header
29
29
  header = [[
30
- header_column("prod.cProd"), header_column("prod.xProd"), header_column("prod.NCM"),
31
- header_column("ICMS.CST"), header_column("prod.CFOP"), header_column("prod.uCom"),
32
- header_column("prod.qCom"), header_column("prod.vUnCom"), header_column("prod.vProd"),
33
- header_column("ICMS.vBC"), header_column("ICMS.vICMS"), header_column("IPI.vIPI"),
34
- header_column("ICMS.pICMS"), header_column("IPI.pIPI")
30
+ header_column('prod.cProd'), header_column('prod.xProd'), header_column('prod.NCM'),
31
+ header_column('ICMS.CST'), header_column('prod.CFOP'), header_column('prod.uCom'),
32
+ header_column('prod.qCom'), header_column('prod.vUnCom'), header_column('prod.vProd'),
33
+ header_column('ICMS.vBC'), header_column('ICMS.vICMS'), header_column('IPI.vIPI'),
34
+ header_column('ICMS.pICMS'), header_column('IPI.pIPI')
35
35
  ]]
36
36
  @pdf.make_table(header, options)
37
37
  end
@@ -62,25 +62,25 @@ module BrDanfe
62
62
  end
63
63
 
64
64
  def products
65
- @xml.collect("xmlns", "det") { |det| product(det) }
65
+ @xml.collect('xmlns', 'det') { |det| product(det) }
66
66
  end
67
67
 
68
68
  def product(det)
69
69
  [
70
- cell_text(det.css("prod/cProd").text),
70
+ cell_text(det.css('prod/cProd').text),
71
71
  cell_text(Xprod.new(det).render),
72
- cell_text(det.css("prod/NCM").text),
72
+ cell_text(det.css('prod/NCM').text),
73
73
  cell_text(Cst.to_danfe(det)),
74
- cell_text(det.css("prod/CFOP").text),
75
- cell_text(det.css("prod/uCom").text),
76
- cell_number(numerify(det, "prod/qCom")),
77
- cell_number(numerify(det, "prod/vUnCom")),
78
- cell_number(numerify(det, "prod/vProd")),
79
- cell_number(numerify(det, "ICMS/*/vBC")),
80
- cell_number(numerify(det, "ICMS/*/vICMS")),
81
- cell_number(numerify(det, "IPI/*/vIPI")),
82
- cell_number(numerify(det, "ICMS/*/pICMS")),
83
- cell_number(numerify(det, "IPI/*/pIPI"))
74
+ cell_text(det.css('prod/CFOP').text),
75
+ cell_text(det.css('prod/uCom').text),
76
+ cell_number(numerify(det, 'prod/qCom')),
77
+ cell_number(numerify(det, 'prod/vUnCom')),
78
+ cell_number(numerify(det, 'prod/vProd')),
79
+ cell_number(numerify(det, 'ICMS/*/vBC')),
80
+ cell_number(numerify(det, 'ICMS/*/vICMS')),
81
+ cell_number(numerify(det, 'IPI/*/vIPI')),
82
+ cell_number(numerify(det, 'ICMS/*/pICMS')),
83
+ cell_number(numerify(det, 'IPI/*/pIPI'))
84
84
  ]
85
85
  end
86
86
 
@@ -95,7 +95,7 @@ module BrDanfe
95
95
  end
96
96
 
97
97
  def numerify(det, xpath)
98
- Helper.numerify(det.css("#{xpath}").text)
98
+ Helper.numerify(det.css(xpath.to_s).text)
99
99
  end
100
100
 
101
101
  def create_row(data)
@@ -115,7 +115,7 @@ module BrDanfe
115
115
  def render_table(data, start_position, height)
116
116
  @pdf.y = start_position
117
117
  @pdf.bounding_box [0.75.cm, @pdf.cursor], width: 19.56.cm, height: height do
118
- @pdf.table data.map{ |item| [item] }, { header: true }
118
+ @pdf.table data.map { |item| [item] }, { header: true }
119
119
  end
120
120
  end
121
121
 
@@ -3,71 +3,82 @@ module BrDanfe
3
3
  class Document
4
4
  def initialize
5
5
  @document = Prawn::Document.new(
6
- page_size: "A4",
6
+ page_size: 'A4',
7
7
  page_layout: :portrait,
8
8
  left_margin: 0,
9
9
  right_margin: 0,
10
10
  top_margin: 0,
11
- botton_margin: 0)
11
+ botton_margin: 0
12
+ )
12
13
 
13
- @document.font "Times-Roman"
14
+ @document.font 'Times-Roman'
14
15
  @document.line_width = 0.3
15
16
  end
16
17
 
17
18
  def method_missing(method_name, *args, &block)
18
- @document.send(method_name, *args, &block)
19
+ if @document.respond_to? method_name
20
+ @document.send method_name, *args, &block
21
+ else
22
+ super
23
+ end
24
+ end
25
+
26
+ def respond_to_missing?(method_name, include_private = false)
27
+ @document.respond_to?(method_name, include_private) || super
19
28
  end
20
29
 
21
30
  def ititle(h, w, x, y, i18n)
22
- title = ""
23
- title = I18n.t("danfe.#{i18n}") if i18n != ""
31
+ title = ''
32
+ title = I18n.t("danfe.#{i18n}") if i18n != ''
24
33
 
25
- self.text_box title, size: 8, at: [x.cm, Helper.invert(y.cm) - 4], width: w.cm, height: h.cm, style: :bold
34
+ text_box title, size: 8, at: [x.cm, Helper.invert(y.cm) - 4], width: w.cm, height: h.cm, style: :bold
26
35
  end
27
36
 
28
37
  def ibarcode(h, w, x, y, info)
29
- Barby::Code128C.new(info).annotate_pdf(self, x: x.cm, y: Helper.invert(y.cm), width: w.cm, height: h.cm) if info != ""
38
+ if info != ''
39
+ Barby::Code128C.new(info).annotate_pdf(self, x: x.cm, y: Helper.invert(y.cm), width: w.cm, height: h.cm)
40
+ end
30
41
  end
31
42
 
32
- def ibox(h, w, x, y, title = "", info = "", options = {})
43
+ def ibox(h, w, x, y, title = '', info = '', options = {})
33
44
  box [x.cm, Helper.invert(y.cm)], w.cm, h.cm, title, info, options
34
45
  end
35
46
 
36
47
  def lbox(h, w, x, y, xml, xpath, options = {})
37
- i18n = xpath.gsub("/", ".");
48
+ i18n = xpath.tr('/', '.')
38
49
  label = I18n.t("danfe.#{i18n}")
39
50
  data = xml[xpath]
40
51
 
41
52
  ibox(h, w, x, y, label, data, options)
42
53
  end
43
54
 
44
- def ldate(h, w, x, y, i18n = "", info = "", options = {})
45
- data = Helper::format_date(info)
55
+ def ldate(h, w, x, y, i18n = '', info = '', options = {})
56
+ data = Helper.format_date(info)
46
57
  i18n_lbox(h, w, x, y, i18n, data, options)
47
58
  end
48
59
 
49
- def ltime(h, w, x, y, i18n = "", info = "", options = {})
50
- data = Helper::format_time(info)
60
+ def ltime(h, w, x, y, i18n = '', info = '', options = {})
61
+ data = Helper.format_time(info)
51
62
  i18n_lbox(h, w, x, y, i18n, data, options)
52
63
  end
53
64
 
54
65
  def lcnpj(h, w, x, y, xml, xpath, options = {})
55
- i18n = xpath.gsub("/", ".");
66
+ i18n = xpath.tr('/', '.')
56
67
 
57
68
  cnpj = BrDocuments::CnpjCpf::Cnpj.new(xml[xpath])
58
- if cnpj.valid?
59
- data = cnpj.formatted
60
- else
61
- data = ""
62
- end
69
+ data = if cnpj.valid?
70
+ cnpj.formatted
71
+ else
72
+ ''
73
+ end
63
74
 
64
75
  i18n_lbox(h, w, x, y, i18n, data, options)
65
76
  end
66
77
 
67
78
  def lie(h, w, x, y, xml, xpath_uf, xpath_ie, options = {})
68
- i18n = xpath_ie.gsub("/", ".");
79
+ i18n = xpath_ie.tr('/', '.')
69
80
 
70
- data = ""
81
+ data = ''
71
82
  if BrDanfe::Uf.include?(xml[xpath_uf])
72
83
  ie = BrDocuments::IE::Factory.create(xml[xpath_uf], xml[xpath_ie])
73
84
  data = ie.formatted if ie.valid?
@@ -77,29 +88,30 @@ module BrDanfe
77
88
  end
78
89
 
79
90
  def lnumeric(h, w, x, y, xml, xpath, options = {})
80
- i18n = xpath.tr("/", ".")
91
+ i18n = xpath.tr('/', '.')
81
92
  data = xml[xpath]
82
93
 
83
94
  inumeric(h, w, x, y, i18n, data, options)
84
95
  end
85
96
 
86
- def inumeric(h, w, x, y, i18n = "", data = "", options = {})
87
- label = i18n != "" ? I18n.t("danfe.#{i18n}") : ""
97
+ def inumeric(h, w, x, y, i18n = '', data = '', options = {})
98
+ label = i18n != '' ? I18n.t("danfe.#{i18n}") : ''
88
99
  numeric [x.cm, Helper.invert(y.cm)], w.cm, h.cm, label, data, options
89
100
  end
90
101
 
91
- def i18n_lbox(h, w, x, y, i18n = "", info = "", options = {})
92
- label = i18n != "" ? I18n.t("danfe.#{i18n}") : ""
102
+ def i18n_lbox(h, w, x, y, i18n = '', info = '', options = {})
103
+ label = i18n != '' ? I18n.t("danfe.#{i18n}") : ''
93
104
  ibox h, w, x, y, label, info, options
94
105
  end
95
106
 
96
107
  private
97
- def numeric(at, w, h, title = "", info = "", options = {})
98
- info = Helper.numerify(info) if info != ""
99
- box at, w, h, title, info, options.merge({align: :right})
108
+
109
+ def numeric(at, w, h, title = '', info = '', options = {})
110
+ info = Helper.numerify(info) if info != ''
111
+ box at, w, h, title, info, options.merge({ align: :right })
100
112
  end
101
113
 
102
- def box(at, w, h, title = "", info = "", options = {})
114
+ def box(at, w, h, title = '', info = '', options = {})
103
115
  options = {
104
116
  align: :left,
105
117
  size: 10,
@@ -108,19 +120,20 @@ module BrDanfe
108
120
  border: 1
109
121
  }.merge(options)
110
122
 
111
- self.stroke_rectangle at, w, h if options[:border] == 1
123
+ stroke_rectangle at, w, h if options[:border] == 1
112
124
 
113
125
  at[0] += 2
114
126
 
115
- if title != ""
127
+ if title != ''
116
128
  title_coord = Array.new(at)
117
129
  title_coord[1] -= 2
118
- self.text_box title, size: 6, at: title_coord, width: w - 4, height: 8
130
+ text_box title, size: 6, at: title_coord, width: w - 4, height: 8
119
131
  end
120
132
 
121
- title_adjustment = title == "" ? 4 : 13
133
+ title_adjustment = title == '' ? 4 : 13
122
134
  at[1] -= title_adjustment
123
- self.text_box info, size: options[:size], at: at, width: w - 4, height: h - title_adjustment, align: options[:align], style: options[:style], valign: options[:valign]
135
+ text_box info, size: options[:size], at: at, width: w - 4, height: h - title_adjustment, align: options[:align],
136
+ style: options[:style], valign: options[:valign]
124
137
  end
125
138
  end
126
139
  end