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
@@ -1,20 +0,0 @@
1
- module BrDanfe
2
- module DanfeNfceLib
3
- class Footer
4
- def initialize(pdf, xml)
5
- @pdf = pdf
6
- @xml = xml
7
- end
8
-
9
- def render(info = '')
10
- tot_trib = @xml['ICMSTot/vTotTrib'].present? ? BrDanfe::Helper.numerify(@xml['ICMSTot/vTotTrib']) : '0,00'
11
- @pdf.text "Tributos Totais Incidentes (Lei Federal 12.741/2012): R$ #{tot_trib}", size: 5, align: :center
12
-
13
- if info.present?
14
- @pdf.render_blank_line
15
- @pdf.text info, size: 5, align: :center
16
- end
17
- end
18
- end
19
- end
20
- end
@@ -1,67 +0,0 @@
1
- module BrDanfe
2
- module DanfeNfceLib
3
- class Header
4
- def initialize(pdf, xml, logo, logo_dimensions)
5
- @pdf = pdf
6
- @xml = xml
7
- @logo = logo
8
- @logo_dimensions = logo_dimensions
9
- end
10
-
11
- def render
12
- cursor = @pdf.cursor
13
-
14
- render_company_info(cursor)
15
- render_logo(cursor) if @logo.present?
16
-
17
- render_homologation if BrDanfe::Helper.homologation?(@xml)
18
- end
19
-
20
- private
21
-
22
- def render_company_info(cursor)
23
- one_line = 1
24
-
25
- @pdf.bounding_box([x_position, cursor], width: width_box, height: 45) do
26
- @pdf.text "#{@xml['emit/xNome']}", size: 7, align: :left, style: :bold
27
- @pdf.text cnpj(@xml['emit/CNPJ']), size: 6, align: :left
28
- @pdf.text BrDanfe::DanfeNfceLib::Helper.address(@xml.css('enderEmit')), size: 6, align: :left
29
- @pdf.render_blank_line if count_name_lines(@xml['emit/xNome']) == one_line
30
- @pdf.text 'Documento Auxiliar da Nota Fiscal de Consumidor Eletrônica', size: 6, align: :left
31
- end
32
- end
33
-
34
- def x_position
35
- @logo.present? ? 1.7.cm : 0
36
- end
37
-
38
- def width_box
39
- @logo.present? ? 5.7.cm : 7.4.cm
40
- end
41
-
42
- def cnpj(info)
43
- cnpj = BrDocuments::CnpjCpf::Cnpj.new info
44
- data = "CNPJ: #{cnpj.valid? ? cnpj.formatted : ''}"
45
- data
46
- end
47
-
48
- def count_name_lines(company_name)
49
- company_name.scan(/([\s\S]{1,38}( |$)|[\s\S]{1,38})/).length
50
- end
51
-
52
- def render_logo(cursor)
53
- box_size = 45
54
- logo_options = BrDanfe::Logo::Options.new(box_size, @logo_dimensions).options
55
-
56
- @pdf.bounding_box([0, cursor], width: box_size, height: box_size) do
57
- @pdf.image @logo, logo_options
58
- end
59
- end
60
-
61
- def render_homologation
62
- @pdf.render_blank_line
63
- @pdf.text 'EMITIDA EM AMBIENTE DE HOMOLOGAÇÃO – SEM VALOR FISCAL', size: 7, align: :center, style: :bold
64
- end
65
- end
66
- end
67
- end
@@ -1,9 +0,0 @@
1
- module BrDanfe
2
- module DanfeNfceLib
3
- class Helper
4
- def self.address(ender_tag)
5
- "#{ender_tag.css('xLgr').text}, #{ender_tag.css('nro').text}, #{ender_tag.css('xBairro').text}, #{ender_tag.css('xMun').text} - #{ender_tag.css('UF').text}"
6
- end
7
- end
8
- end
9
- end
@@ -1,18 +0,0 @@
1
- module BrDanfe
2
- module DanfeNfceLib
3
- class Key
4
- def initialize(pdf, xml)
5
- @pdf = pdf
6
- @xml = xml
7
- end
8
-
9
- def render
10
- @pdf.render_blank_line
11
-
12
- @pdf.text 'Consulte pela Chave de Acesso em', size: 7, align: :center, style: :bold
13
- @pdf.text @xml['urlChave'], size: 7, align: :center
14
- @pdf.text @xml['chNFe'].gsub(/(\d)(?=(\d\d\d\d)+(?!\d))/, '\\1 '), size: 6, align: :center
15
- end
16
- end
17
- end
18
- end
@@ -1,20 +0,0 @@
1
- module BrDanfe
2
- module DanfeNfceLib
3
- class NfceIdentification
4
- def initialize(pdf, xml)
5
- @pdf = pdf
6
- @xml = xml
7
- end
8
-
9
- def render
10
- emitted_at = BrDanfe::Helper.format_datetime(@xml['ide/dhEmi'])
11
- identification = "NFC-e nº #{@xml['ide/nNF']} Série #{@xml['ide/serie']} #{emitted_at}"
12
-
13
- @pdf.render_blank_line
14
- @pdf.text identification, size: 7, align: :center, style: :bold
15
- @pdf.text "<b>Protocolo de autorização:</b> #{@xml['infProt/nProt']}", size: 7, align: :center, inline_format: true
16
- @pdf.text "<b>Data de autorização: </b> #{BrDanfe::Helper.format_datetime(@xml['infProt/dhRecbto'])}", size: 7, align: :center, inline_format: true
17
- end
18
- end
19
- end
20
- end
@@ -1,100 +0,0 @@
1
- module BrDanfe
2
- module DanfeNfceLib
3
- class ProductList
4
- def initialize(pdf, xml)
5
- @pdf = pdf
6
- @xml = xml
7
- end
8
-
9
- def render
10
- render_headers(headers)
11
- render_products(products)
12
- end
13
-
14
- private
15
-
16
- def headers
17
- [
18
- header_column('Código', :left),
19
- header_column('Descrição', :left),
20
- header_column('Qtde', :right),
21
- header_column('UN', :right),
22
- header_column('Vl Unit', :right),
23
- header_column('Vl Total', :right)
24
- ]
25
- end
26
-
27
- def header_column(title, align)
28
- { content: title, options: { align: align, size: 6, style: :bold } }
29
- end
30
-
31
- def products
32
- @xml.collect('xmlns', 'det') { |det| product(det) }
33
- end
34
-
35
- def product(det)
36
- [
37
- cell_text(det.css('prod/cProd').text),
38
- cell_text(det.css('prod/xProd').text),
39
- cell_number(BrDanfe::Helper.numerify(det.css('prod/qCom').text)),
40
- cell_text(det.css('prod/uCom').text, { align: :right }),
41
- cell_number(BrDanfe::Helper.numerify(det.css('prod/vUnCom').text)),
42
- cell_number(BrDanfe::Helper.numerify(det.css('prod/vProd').text))
43
- ]
44
- end
45
-
46
- def cell_text(text, options = {})
47
- cell = { content: text, options: { border_width: 0, size: 6 } }
48
- cell[:options].merge!(options)
49
- cell
50
- end
51
-
52
- def cell_number(text)
53
- cell_text(text, { align: :right })
54
- end
55
-
56
- def columns
57
- [
58
- { width: 0.9.cm, position: 0 },
59
- { width: 2.6.cm, position: 0.9.cm },
60
- { width: 1.1.cm, position: 3.5.cm },
61
- { width: 0.4.cm, position: 4.6.cm },
62
- { width: 1.2.cm, position: 5.cm },
63
- { width: 1.2.cm, position: 6.2.cm }
64
- ]
65
- end
66
-
67
- def render_headers(headers)
68
- 2.times { @pdf.render_blank_line }
69
- cursor = @pdf.cursor
70
- headers.each_with_index do |header, index|
71
- @pdf.bounding_box [columns[index][:position], cursor], width: columns[index][:width], height: 0.2.cm do
72
- @pdf.text header[:content], header[:options]
73
- end
74
- end
75
- end
76
-
77
- def render_products(products)
78
- @pdf.render_blank_line
79
- index_of_product_name = 1
80
- products.each do |product|
81
- box_height = box_height(product[index_of_product_name][:content])
82
- cursor = @pdf.cursor
83
-
84
- product.each_with_index do |product, index|
85
- @pdf.bounding_box [columns[index][:position], cursor], width: columns[index][:width], height: box_height do
86
- @pdf.text product[:content], product[:options]
87
- end
88
- end
89
- end
90
- end
91
-
92
- def box_height(content)
93
- line_height_base = 0.23.cm
94
-
95
- lines = content.scan(/[\s\S]{1,20}( |$)/).length
96
- line_height_base * lines
97
- end
98
- end
99
- end
100
- end
@@ -1,23 +0,0 @@
1
- module BrDanfe
2
- module DanfeNfceLib
3
- class QrCode
4
- require 'rqrcode'
5
- require 'chunky_png'
6
- require 'tempfile'
7
-
8
- def initialize(pdf, xml)
9
- @pdf = pdf
10
- @xml = xml
11
- end
12
-
13
- def render
14
- qrcode = RQRCode::QRCode.new(@xml['qrCode'])
15
- image = Tempfile.create('qrcode.png')
16
- image.write(qrcode.as_png(module_px_size: 12).to_s)
17
-
18
- box_size = 3.cm
19
- @pdf.image image, { width: box_size, height: box_size, position: :center }
20
- end
21
- end
22
- end
23
- end
@@ -1,72 +0,0 @@
1
- module BrDanfe
2
- module DanfeNfceLib
3
- class Recipient
4
- def initialize(pdf, xml)
5
- @pdf = pdf
6
- @xml = xml
7
- end
8
-
9
- def render
10
- @pdf.render_blank_line
11
-
12
- if identified_recipient?
13
- render_document
14
-
15
- @pdf.text @xml['dest/xNome'], options
16
- @pdf.text BrDanfe::DanfeNfceLib::Helper.address(@xml.css('enderDest')), options
17
- else
18
- @pdf.text 'CONSUMIDOR NÃO IDENTIFICADO', options
19
- end
20
- end
21
-
22
- private
23
-
24
- def options
25
- { size: 7, align: :center }
26
- end
27
-
28
- def identified_recipient?
29
- @xml['dest/xNome'].present?
30
- end
31
-
32
- def render_document
33
- document_text = document
34
-
35
- @pdf.text document_text, options if document_text.present?
36
- end
37
-
38
- def document
39
- return company if company?
40
- return individual if individual?
41
- return foreign if foreign?
42
- return ''
43
- end
44
-
45
- def company?
46
- @xml['dest/CNPJ'].present?
47
- end
48
-
49
- def company
50
- cnpj = BrDocuments::CnpjCpf::Cnpj.new @xml['dest/CNPJ']
51
- "CONSUMIDOR CNPJ: #{cnpj.formatted}"
52
- end
53
-
54
- def individual?
55
- @xml['dest/CPF'].present?
56
- end
57
-
58
- def individual
59
- cpf = BrDocuments::CnpjCpf::Cpf.new(@xml['dest/CPF'])
60
- "CONSUMIDOR CPF: #{cpf.formatted}"
61
- end
62
-
63
- def foreign?
64
- @xml['dest/idEstrangeiro'].present?
65
- end
66
-
67
- def foreign
68
- "CONSUMIDOR Id. Estrangeiro: #{@xml['dest/idEstrangeiro']}"
69
- end
70
- end
71
- end
72
- end
@@ -1,78 +0,0 @@
1
- module BrDanfe
2
- module DanfeNfceLib
3
- class TotalList
4
- require 'bigdecimal'
5
-
6
- def initialize(pdf, xml)
7
- @pdf = pdf
8
- @xml = xml
9
- end
10
-
11
- def render
12
- subtotal
13
- totals
14
- payment_methods
15
- end
16
-
17
- private
18
-
19
- def subtotal
20
- cursor = @pdf.cursor
21
- @pdf.bounding_box [4.8.cm, cursor], width: 1.4.cm, height: 0.2.cm do
22
- @pdf.text 'Subtotal R$', { size: 6, align: :left }
23
- end
24
- @pdf.bounding_box [6.2.cm, cursor], width: 1.2.cm, height: 0.2.cm do
25
- @pdf.text BrDanfe::Helper.numerify(@xml['ICMSTot > vProd'].to_f), { size: 6, align: :right }
26
- end
27
- end
28
-
29
- def totals
30
- @pdf.render_blank_line
31
-
32
- cursor = @pdf.cursor
33
- print_text('Qtde. total de itens', cursor, { size: 7, align: :left })
34
- print_text(@xml.css('det').count.to_s, cursor, { size: 7, align: :right })
35
-
36
- cursor = @pdf.cursor
37
- print_text('Desconto R$', cursor, { size: 7, align: :left})
38
- print_text(BrDanfe::Helper.numerify(@xml['ICMSTot > vDesc'].to_f), cursor, { size: 7, align: :right })
39
-
40
- cursor = @pdf.cursor
41
- print_text('Valor Total R$', cursor, { size: 7, align: :left, style: :bold })
42
- print_text(BrDanfe::Helper.numerify(@xml['ICMSTot > vNF'].to_f), cursor, { size: 7, align: :right, style: :bold })
43
- end
44
-
45
- def payment_methods
46
- payments = {}
47
- without_payment = '90'
48
-
49
- @xml.css('detPag').each do |detPag|
50
- next if detPag.css('tPag').text == without_payment
51
- payments[detPag.css('tPag').text] ||= BigDecimal('0')
52
- actual_payment_value = BigDecimal(detPag.css('vPag').text)
53
- payments[detPag.css('tPag').text] += actual_payment_value
54
- end
55
-
56
- if payments.present?
57
- @pdf.render_blank_line
58
-
59
- cursor = @pdf.cursor
60
- print_text('Forma de pagamento', cursor, { size: 7, align: :left, style: :bold })
61
- print_text('Valor pago R$', cursor, { size: 7, align: :right, style: :bold })
62
-
63
- payments.each do |key, value|
64
- cursor = @pdf.cursor
65
- print_text(I18n.t("nfce.payment_methods.#{key}"), cursor, { size: 7, align: :left })
66
- print_text(BrDanfe::Helper.numerify(value.to_f), cursor, { size: 7, align: :right })
67
- end
68
- end
69
- end
70
-
71
- def print_text(text, cursor, options)
72
- @pdf.bounding_box [0, cursor], width: 7.4.cm, height: 0.25.cm do
73
- @pdf.text text, options
74
- end
75
- end
76
- end
77
- end
78
- end
@@ -1,31 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe BrDanfe::DanfeNfce do
4
- let(:output_pdf) { "#{base_dir}output.pdf" }
5
- let(:base_dir) { './spec/fixtures/nfce/v4.00/' }
6
- let(:danfe) { BrDanfe::DanfeNfce.new(File.read("#{base_dir}nfce.xml")) }
7
-
8
- before do
9
- danfe.options.logo = 'spec/fixtures/logo.png'
10
- danfe.options.logo_dimensions = { width: 100, height: 100 }
11
- end
12
-
13
- describe '#render_pdf' do
14
- it 'renders the NFC-e pdf' do
15
- expected = IO.binread("#{base_dir}rendered_nfce.fixture.pdf")
16
- expect(danfe.render_pdf).to eq expected
17
- end
18
- end
19
-
20
- describe '#save_pdf' do
21
- before { File.delete(output_pdf) if File.exist?(output_pdf) }
22
- after { File.delete(output_pdf) if File.exist?(output_pdf) }
23
-
24
- it 'saves the NFC-e as pdf' do
25
- expect(File.exist?(output_pdf)).to be_falsey
26
- danfe.save_pdf output_pdf
27
-
28
- expect("#{base_dir}saved_nfce.fixture.pdf").to have_same_content_of file: output_pdf
29
- end
30
- end
31
- end