br_danfe 0.12.1 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (138) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +15 -25
  3. data/Gemfile.lock +54 -18
  4. data/Guardfile +14 -0
  5. data/README.md +5 -5
  6. data/br_danfe.gemspec +3 -1
  7. data/lib/br_danfe.rb +0 -1
  8. data/lib/br_danfe/danfe.rb +6 -90
  9. data/lib/br_danfe/danfe_lib/base.rb +33 -0
  10. data/lib/br_danfe/danfe_lib/nfce.rb +49 -0
  11. data/lib/br_danfe/danfe_lib/nfce_lib/document.rb +37 -0
  12. data/lib/br_danfe/danfe_lib/nfce_lib/footer.rb +22 -0
  13. data/lib/br_danfe/danfe_lib/nfce_lib/header.rb +69 -0
  14. data/lib/br_danfe/danfe_lib/nfce_lib/helper.rb +11 -0
  15. data/lib/br_danfe/danfe_lib/nfce_lib/key.rb +20 -0
  16. data/lib/br_danfe/danfe_lib/nfce_lib/nfce_identification.rb +22 -0
  17. data/lib/br_danfe/danfe_lib/nfce_lib/product_list.rb +102 -0
  18. data/lib/br_danfe/danfe_lib/nfce_lib/qr_code.rb +25 -0
  19. data/lib/br_danfe/danfe_lib/nfce_lib/recipient.rb +75 -0
  20. data/lib/br_danfe/danfe_lib/nfce_lib/total_list.rb +81 -0
  21. data/lib/br_danfe/danfe_lib/nfe.rb +83 -0
  22. data/lib/br_danfe/danfe_lib/nfe_lib/cep.rb +11 -0
  23. data/lib/br_danfe/danfe_lib/nfe_lib/consts.rb +8 -0
  24. data/lib/br_danfe/danfe_lib/nfe_lib/cst.rb +34 -0
  25. data/lib/br_danfe/danfe_lib/nfe_lib/dest.rb +96 -0
  26. data/lib/br_danfe/danfe_lib/nfe_lib/det_body.rb +137 -0
  27. data/lib/br_danfe/danfe_lib/nfe_lib/document.rb +142 -0
  28. data/lib/br_danfe/danfe_lib/nfe_lib/dup.rb +55 -0
  29. data/lib/br_danfe/danfe_lib/nfe_lib/emit_header.rb +117 -0
  30. data/lib/br_danfe/danfe_lib/nfe_lib/helper.rb +55 -0
  31. data/lib/br_danfe/danfe_lib/nfe_lib/icmstot.rb +35 -0
  32. data/lib/br_danfe/danfe_lib/nfe_lib/infadic.rb +125 -0
  33. data/lib/br_danfe/danfe_lib/nfe_lib/infadic_vol.rb +103 -0
  34. data/lib/br_danfe/danfe_lib/nfe_lib/issqn.rb +37 -0
  35. data/lib/br_danfe/danfe_lib/nfe_lib/phone.rb +15 -0
  36. data/lib/br_danfe/danfe_lib/nfe_lib/plate.rb +11 -0
  37. data/lib/br_danfe/danfe_lib/nfe_lib/ticket.rb +21 -0
  38. data/lib/br_danfe/danfe_lib/nfe_lib/transp.rb +58 -0
  39. data/lib/br_danfe/danfe_lib/nfe_lib/vol.rb +44 -0
  40. data/lib/br_danfe/danfe_lib/nfe_lib/xprod.rb +109 -0
  41. data/lib/br_danfe/helper.rb +8 -0
  42. data/lib/br_danfe/version.rb +1 -1
  43. data/spec/{lib → br_danfe}/cce_lib/barcode_spec.rb +0 -0
  44. data/spec/{lib → br_danfe}/cce_lib/correction_spec.rb +0 -0
  45. data/spec/{lib → br_danfe}/cce_lib/document_spec.rb +0 -0
  46. data/spec/{lib → br_danfe}/cce_lib/footer_spec.rb +0 -0
  47. data/spec/{lib → br_danfe}/cce_lib/header_spec.rb +0 -0
  48. data/spec/{lib → br_danfe}/cce_lib/nfe_key_spec.rb +0 -0
  49. data/spec/{lib → br_danfe}/cce_lib/protocol_spec.rb +0 -0
  50. data/spec/{features → br_danfe}/cce_spec.rb +0 -0
  51. data/spec/{lib/danfe_nfce_lib → br_danfe/danfe_lib/nfce_lib}/document_spec.rb +2 -2
  52. data/spec/{lib/danfe_nfce_lib → br_danfe/danfe_lib/nfce_lib}/footer_spec.rb +2 -2
  53. data/spec/{lib/danfe_nfce_lib → br_danfe/danfe_lib/nfce_lib}/header_spec.rb +2 -2
  54. data/spec/{lib/danfe_nfce_lib → br_danfe/danfe_lib/nfce_lib}/helper_spec.rb +1 -1
  55. data/spec/{lib/danfe_nfce_lib → br_danfe/danfe_lib/nfce_lib}/key_spec.rb +2 -2
  56. data/spec/{lib/danfe_nfce_lib → br_danfe/danfe_lib/nfce_lib}/nfce_identification_spec.rb +2 -2
  57. data/spec/{lib/danfe_nfce_lib → br_danfe/danfe_lib/nfce_lib}/product_list_spec.rb +2 -2
  58. data/spec/{lib/danfe_nfce_lib → br_danfe/danfe_lib/nfce_lib}/qr_code_spec.rb +2 -2
  59. data/spec/{lib/danfe_nfce_lib → br_danfe/danfe_lib/nfce_lib}/recipient_spec.rb +7 -7
  60. data/spec/{lib/danfe_nfce_lib → br_danfe/danfe_lib/nfce_lib}/total_list_spec.rb +4 -4
  61. data/spec/br_danfe/danfe_lib/nfce_spec.rb +57 -0
  62. data/spec/{lib/danfe_lib → br_danfe/danfe_lib/nfe_lib}/cep_spec.rb +2 -2
  63. data/spec/{lib/danfe_lib → br_danfe/danfe_lib/nfe_lib}/cst_spec.rb +3 -3
  64. data/spec/{lib/danfe_lib → br_danfe/danfe_lib/nfe_lib}/dest_spec.rb +2 -2
  65. data/spec/{lib/danfe_lib → br_danfe/danfe_lib/nfe_lib}/det_body_spec.rb +2 -2
  66. data/spec/{lib/danfe_lib → br_danfe/danfe_lib/nfe_lib}/document_spec.rb +1 -1
  67. data/spec/{lib/danfe_lib → br_danfe/danfe_lib/nfe_lib}/dup_spec.rb +2 -2
  68. data/spec/{lib/danfe_lib → br_danfe/danfe_lib/nfe_lib}/emit_header_spec.rb +3 -3
  69. data/spec/{lib/danfe_lib → br_danfe/danfe_lib/nfe_lib}/helper_spec.rb +13 -87
  70. data/spec/{lib/danfe_lib → br_danfe/danfe_lib/nfe_lib}/icmstot_spec.rb +2 -2
  71. data/spec/{lib/danfe_lib → br_danfe/danfe_lib/nfe_lib}/infadic_spec.rb +45 -4
  72. data/spec/{lib/danfe_lib → br_danfe/danfe_lib/nfe_lib}/infadic_vol_spec.rb +2 -2
  73. data/spec/{lib/danfe_lib → br_danfe/danfe_lib/nfe_lib}/issqn_spec.rb +2 -2
  74. data/spec/{lib/danfe_lib → br_danfe/danfe_lib/nfe_lib}/phone_spec.rb +3 -3
  75. data/spec/{lib/danfe_lib → br_danfe/danfe_lib/nfe_lib}/plate_spec.rb +3 -3
  76. data/spec/{lib/danfe_lib → br_danfe/danfe_lib/nfe_lib}/ticket_spec.rb +2 -2
  77. data/spec/{lib/danfe_lib → br_danfe/danfe_lib/nfe_lib}/transp_spec.rb +2 -2
  78. data/spec/{lib/danfe_lib → br_danfe/danfe_lib/nfe_lib}/vol_spec.rb +2 -2
  79. data/spec/{lib/danfe_lib → br_danfe/danfe_lib/nfe_lib}/xprod_spec.rb +9 -9
  80. data/spec/{features/danfe_spec.rb → br_danfe/danfe_lib/nfe_spec.rb} +55 -47
  81. data/spec/br_danfe/danfe_spec.rb +40 -0
  82. data/spec/{lib → br_danfe}/helper_spec.rb +114 -0
  83. data/spec/{lib → br_danfe}/logo_config_spec.rb +1 -1
  84. data/spec/{lib → br_danfe}/logo_options_spec.rb +7 -7
  85. data/spec/{lib → br_danfe}/uf_spec.rb +0 -0
  86. data/spec/{lib → br_danfe}/xml_spec.rb +0 -0
  87. data/spec/fixtures/nfce/v4.00/nfce-unauthorized-hom.fixture.pdf +0 -0
  88. data/spec/fixtures/nfce/v4.00/nfce-unauthorized-hom.xml +358 -0
  89. data/spec/fixtures/nfce/v4.00/nfce-unauthorized-prod.fixture.pdf +0 -0
  90. data/spec/fixtures/nfce/v4.00/nfce-unauthorized-prod.xml +358 -0
  91. data/spec/fixtures/nfce/v4.00/nfce.xml +2 -2
  92. data/spec/fixtures/nfce/v4.00/rendered_nfce.fixture.pdf +0 -0
  93. data/spec/fixtures/nfce/v4.00/saved_nfce.fixture.pdf +0 -0
  94. data/spec/fixtures/nfe/lib/infadic#address-shipment.pdf +108 -0
  95. data/spec/fixtures/nfe/lib/infadic#render-all_the_informations.pdf +7 -7
  96. data/spec/fixtures/nfe/v2.00/custom_options.fixture.pdf +10 -10
  97. data/spec/fixtures/nfe/v2.00/nfe_simples_nacional.xml.fixture.pdf +8 -8
  98. data/spec/fixtures/nfe/v2.00/nfe_with_extra_volumes.xml.fixture.pdf +10 -10
  99. data/spec/fixtures/nfe/v2.00/nfe_with_fci.xml.fixture.pdf +8 -8
  100. data/spec/fixtures/nfe/v2.00/nfe_with_ns.xml.fixture.pdf +10 -10
  101. data/spec/fixtures/nfe/v2.00/nfe_without_ns.xml.fixture.pdf +7 -7
  102. data/spec/fixtures/nfe/v3.10/nfe_simples_nacional.xml.fixture.pdf +8 -8
  103. data/spec/fixtures/nfe/v3.10/with_footer.fixture.pdf +10 -10
  104. data/spec/fixtures/nfe/v3.10/with_issqn.fixture.pdf +10 -10
  105. data/spec/fixtures/nfe/v3.10/with_three_pages.fixture.pdf +12 -12
  106. data/spec/fixtures/nfe/v3.10/without_issqn.fixture.pdf +10 -10
  107. metadata +114 -77
  108. data/lib/br_danfe/danfe_lib/cep.rb +0 -9
  109. data/lib/br_danfe/danfe_lib/consts.rb +0 -6
  110. data/lib/br_danfe/danfe_lib/cst.rb +0 -32
  111. data/lib/br_danfe/danfe_lib/dest.rb +0 -94
  112. data/lib/br_danfe/danfe_lib/det_body.rb +0 -135
  113. data/lib/br_danfe/danfe_lib/document.rb +0 -140
  114. data/lib/br_danfe/danfe_lib/dup.rb +0 -53
  115. data/lib/br_danfe/danfe_lib/emit_header.rb +0 -115
  116. data/lib/br_danfe/danfe_lib/helper.rb +0 -61
  117. data/lib/br_danfe/danfe_lib/icmstot.rb +0 -33
  118. data/lib/br_danfe/danfe_lib/infadic.rb +0 -107
  119. data/lib/br_danfe/danfe_lib/infadic_vol.rb +0 -101
  120. data/lib/br_danfe/danfe_lib/issqn.rb +0 -35
  121. data/lib/br_danfe/danfe_lib/phone.rb +0 -13
  122. data/lib/br_danfe/danfe_lib/plate.rb +0 -9
  123. data/lib/br_danfe/danfe_lib/ticket.rb +0 -19
  124. data/lib/br_danfe/danfe_lib/transp.rb +0 -56
  125. data/lib/br_danfe/danfe_lib/vol.rb +0 -42
  126. data/lib/br_danfe/danfe_lib/xprod.rb +0 -107
  127. data/lib/br_danfe/danfe_nfce.rb +0 -43
  128. data/lib/br_danfe/danfe_nfce_lib/document.rb +0 -35
  129. data/lib/br_danfe/danfe_nfce_lib/footer.rb +0 -20
  130. data/lib/br_danfe/danfe_nfce_lib/header.rb +0 -67
  131. data/lib/br_danfe/danfe_nfce_lib/helper.rb +0 -9
  132. data/lib/br_danfe/danfe_nfce_lib/key.rb +0 -18
  133. data/lib/br_danfe/danfe_nfce_lib/nfce_identification.rb +0 -20
  134. data/lib/br_danfe/danfe_nfce_lib/product_list.rb +0 -100
  135. data/lib/br_danfe/danfe_nfce_lib/qr_code.rb +0 -23
  136. data/lib/br_danfe/danfe_nfce_lib/recipient.rb +0 -72
  137. data/lib/br_danfe/danfe_nfce_lib/total_list.rb +0 -78
  138. data/spec/features/danfe_nfce_spec.rb +0 -31
@@ -1,9 +0,0 @@
1
- module BrDanfe
2
- module DanfeLib
3
- class Cep
4
- def self.format(cep)
5
- cep.sub(/(\d{2})(\d{3})(\d{3})/, '\\1.\\2-\\3')
6
- end
7
- end
8
- end
9
- end
@@ -1,6 +0,0 @@
1
- module BrDanfe
2
- module DanfeLib
3
- LINE_HEIGHT = 0.80
4
- SPACE_BETWEEN_GROUPS = 0.52
5
- end
6
- end
@@ -1,32 +0,0 @@
1
- module BrDanfe
2
- module DanfeLib
3
- class Cst
4
- def self.to_danfe(xml)
5
- value = origin(xml)
6
-
7
- if csosn?(xml)
8
- value += xml.css('ICMS/*/CSOSN').text
9
- elsif cst?(xml)
10
- value += xml.css('ICMS/*/CST').text
11
- end
12
-
13
- value
14
- end
15
-
16
- def self.origin(xml)
17
- xml.css('ICMS/*/orig').text
18
- end
19
- private_class_method :origin
20
-
21
- def self.cst?(xml)
22
- xml.css('ICMS/*/CST').text != ''
23
- end
24
- private_class_method :cst?
25
-
26
- def self.csosn?(xml)
27
- xml.css('ICMS/*/CSOSN').text != ''
28
- end
29
- private_class_method :csosn?
30
- end
31
- end
32
- end
@@ -1,94 +0,0 @@
1
- module BrDanfe
2
- module DanfeLib
3
- class Dest
4
- Y = 10.00
5
- MAXIMUM_SIZE_FOR_STREET = 319
6
-
7
- def initialize(pdf, xml)
8
- @pdf = pdf
9
- @xml = xml
10
- @xml_version_is_310_or_newer = @xml.version_is_310_or_newer?
11
-
12
- @ltitle = Y - 0.42
13
- @l1 = Y
14
- @l2 = Y + LINE_HEIGHT
15
- @l3 = Y + (LINE_HEIGHT * 2)
16
- end
17
-
18
- def render
19
- @pdf.ititle 0.42, 10.00, 0.75, @ltitle, 'dest.title'
20
-
21
- render_line1
22
- render_line2
23
- render_line3
24
-
25
- @xml_version_is_310_or_newer ? render_dates_for_nfe_310_or_newer : render_dates_for_older_nfes
26
- end
27
-
28
- private
29
-
30
- def render_line1
31
- @pdf.lbox LINE_HEIGHT, 11.82, 0.75, @l1, @xml, 'dest/xNome'
32
- render_cnpj_cpf
33
- end
34
-
35
- def render_cnpj_cpf
36
- if @xml['dest/CNPJ'] == ''
37
- @pdf.i18n_lbox LINE_HEIGHT, 4.37, 12.57, @l1, 'dest.CPF', cpf
38
- else
39
- @pdf.lcnpj LINE_HEIGHT, 4.37, 12.57, @l1, @xml, 'dest/CNPJ'
40
- end
41
- end
42
-
43
- def cpf
44
- cpf = BrDocuments::CnpjCpf::Cpf.new(@xml['dest/CPF'])
45
- cpf.formatted
46
- end
47
-
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
52
- end
53
-
54
- def address
55
- address = Helper.generate_address @xml
56
-
57
- if Helper.address_is_too_big(@pdf, address)
58
- address = address[0..address.length - 2] while Helper.mensure_text(@pdf, "#{address.strip}...") > MAXIMUM_SIZE_FOR_STREET && !address.empty?
59
- address = "#{address.strip}..."
60
- end
61
- address
62
- end
63
-
64
- def cep
65
- Cep.format(@xml['enderDest/CEP'])
66
- end
67
-
68
- def render_line3
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'
73
- end
74
-
75
- def phone
76
- Phone.format(@xml['enderDest/fone'])
77
- end
78
-
79
- def render_dates_for_nfe_310_or_newer
80
- render_dates 'ide/dhEmi', 'ide/dhSaiEnt', 'ide/dhSaiEnt'
81
- end
82
-
83
- def render_dates(emitted_at_date_and_hour, exited_at_date, exited_at_hour)
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 }
87
- end
88
-
89
- def render_dates_for_older_nfes
90
- render_dates 'ide/dEmi', 'ide/dSaiEnt', 'ide/hSaiEnt'
91
- end
92
- end
93
- end
94
- end
@@ -1,135 +0,0 @@
1
- module BrDanfe
2
- module DanfeLib
3
- class DetBody
4
- def initialize(pdf, xml)
5
- @pdf = pdf
6
- @xml = xml
7
- end
8
-
9
- def render(has_issqn)
10
- table_height_on_first_page = table_height_on_first_page has_issqn
11
- first_table = create_table
12
- next_table = create_table
13
-
14
- fill_tables first_table, next_table, table_height_on_first_page
15
- render_tables first_table, next_table, table_height_on_first_page
16
- end
17
-
18
- private
19
-
20
- def table_height_on_first_page(has_issqn)
21
- has_issqn ? 6.35.cm : 7.72.cm
22
- end
23
-
24
- def create_table
25
- [create_header]
26
- end
27
-
28
- def create_header
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')
35
- ]]
36
- @pdf.make_table(header, options)
37
- end
38
-
39
- def header_column(title)
40
- { content: I18n.t("danfe.det.#{title}"), align: :left, size: 6, valign: :top }
41
- end
42
-
43
- def options
44
- { column_widths: column_widths, cell_style: { padding: 2, border_width: 0.3 } }
45
- end
46
-
47
- def column_widths
48
- {
49
- 0 => 1.60.cm, 1 => 6.10.cm, 2 => 1.05.cm, 3 => 0.60.cm, 4 => 0.70.cm, 5 => 1.05.cm, 6 => 1.20.cm,
50
- 7 => 1.20.cm, 8 => 1.20.cm, 9 => 1.20.cm, 10 => 1.00.cm, 11 => 1.00.cm, 12 => 0.90.cm, 13 => 0.76.cm
51
- }
52
- end
53
-
54
- def fill_tables(first_table, next_table, first_table_height)
55
- total_height = first_table.first.height
56
-
57
- products.each do |product|
58
- row = create_row product
59
- total_height += row.height
60
- total_height <= first_table_height ? first_table << row : next_table << row
61
- end
62
- end
63
-
64
- def products
65
- @xml.collect('xmlns', 'det') { |det| product(det) }
66
- end
67
-
68
- def product(det)
69
- [
70
- cell_text(det.css('prod/cProd').text),
71
- cell_text(Xprod.new(det).render),
72
- cell_text(det.css('prod/NCM').text),
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'))
84
- ]
85
- end
86
-
87
- def cell_text(text, options = {})
88
- cell = { content: text, border_lines: [:solid], size: 6.5 }
89
- cell.merge!(options)
90
- cell
91
- end
92
-
93
- def cell_number(text)
94
- cell_text(text, { align: :right })
95
- end
96
-
97
- def numerify(det, xpath)
98
- BrDanfe::Helper.numerify(det.css(xpath.to_s).text)
99
- end
100
-
101
- def create_row(data)
102
- @pdf.make_table([data], options)
103
- end
104
-
105
- def render_tables(first_table, next_table, first_table_height)
106
- render_table first_table, table_position_on_first_page, first_table_height
107
-
108
- table_with_only_header = 1
109
- if next_table.size > table_with_only_header
110
- @pdf.start_new_page
111
- render_table next_table, table_position_on_next_pages, table_height_on_next_pages
112
- end
113
- end
114
-
115
- def render_table(data, start_position, height)
116
- @pdf.y = start_position
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 }
119
- end
120
- end
121
-
122
- def table_position_on_first_page
123
- Helper.invert(18.07.cm)
124
- end
125
-
126
- def table_position_on_next_pages
127
- Helper.invert(6.57.cm)
128
- end
129
-
130
- def table_height_on_next_pages
131
- 22.58.cm
132
- end
133
- end
134
- end
135
- end
@@ -1,140 +0,0 @@
1
- module BrDanfe
2
- module DanfeLib
3
- class Document
4
- def initialize
5
- @document = Prawn::Document.new(
6
- page_size: 'A4',
7
- page_layout: :portrait,
8
- left_margin: 0,
9
- right_margin: 0,
10
- top_margin: 0,
11
- botton_margin: 0
12
- )
13
-
14
- @document.font 'Times-Roman'
15
- @document.line_width = 0.3
16
- end
17
-
18
- def method_missing(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
28
- end
29
-
30
- def ititle(h, w, x, y, i18n)
31
- title = ''
32
- title = I18n.t("danfe.#{i18n}") if i18n != ''
33
-
34
- text_box title, size: 8, at: [x.cm, Helper.invert(y.cm) - 4], width: w.cm, height: h.cm, style: :bold
35
- end
36
-
37
- def ibarcode(h, w, x, y, 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
41
- end
42
-
43
- def ibox(h, w, x, y, title = '', info = '', options = {})
44
- box [x.cm, Helper.invert(y.cm)], w.cm, h.cm, title, info, options
45
- end
46
-
47
- def lbox(h, w, x, y, xml, xpath, options = {})
48
- i18n = xpath.tr('/', '.')
49
- label = I18n.t("danfe.#{i18n}")
50
- data = xml[xpath]
51
-
52
- ibox(h, w, x, y, label, data, options)
53
- end
54
-
55
- def ldate(h, w, x, y, i18n = '', info = '', options = {})
56
- data = Helper.format_date(info)
57
- i18n_lbox(h, w, x, y, i18n, data, options)
58
- end
59
-
60
- def ltime(h, w, x, y, i18n = '', info = '', options = {})
61
- data = Helper.format_time(info)
62
- i18n_lbox(h, w, x, y, i18n, data, options)
63
- end
64
-
65
- def lcnpj(h, w, x, y, xml, xpath, options = {})
66
- i18n = xpath.tr('/', '.')
67
-
68
- cnpj = BrDocuments::CnpjCpf::Cnpj.new(xml[xpath])
69
- data = if cnpj.valid?
70
- cnpj.formatted
71
- else
72
- ''
73
- end
74
-
75
- i18n_lbox(h, w, x, y, i18n, data, options)
76
- end
77
-
78
- def lie(h, w, x, y, xml, xpath_uf, xpath_ie, options = {})
79
- i18n = xpath_ie.tr('/', '.')
80
-
81
- data = ''
82
- if BrDanfe::Uf.include?(xml[xpath_uf])
83
- ie = BrDocuments::IE::Factory.create(xml[xpath_uf], xml[xpath_ie])
84
- data = ie.formatted if ie.valid?
85
- end
86
-
87
- i18n_lbox(h, w, x, y, i18n, data, options)
88
- end
89
-
90
- def lnumeric(h, w, x, y, xml, xpath, options = {})
91
- i18n = xpath.tr('/', '.')
92
- data = xml[xpath]
93
-
94
- inumeric(h, w, x, y, i18n, data, options)
95
- end
96
-
97
- def inumeric(h, w, x, y, i18n = '', data = '', options = {})
98
- label = i18n != '' ? I18n.t("danfe.#{i18n}") : ''
99
- numeric [x.cm, Helper.invert(y.cm)], w.cm, h.cm, label, data, options
100
- end
101
-
102
- def i18n_lbox(h, w, x, y, i18n = '', info = '', options = {})
103
- label = i18n != '' ? I18n.t("danfe.#{i18n}") : ''
104
- ibox h, w, x, y, label, info, options
105
- end
106
-
107
- private
108
-
109
- def numeric(at, w, h, title = '', info = '', options = {})
110
- info = BrDanfe::Helper.numerify(info) if info != ''
111
- box at, w, h, title, info, options.merge({ align: :right })
112
- end
113
-
114
- def box(at, w, h, title = '', info = '', options = {})
115
- options = {
116
- align: :left,
117
- size: 10,
118
- style: nil,
119
- valign: :top,
120
- border: 1
121
- }.merge(options)
122
-
123
- stroke_rectangle at, w, h if options[:border] == 1
124
-
125
- at[0] += 2
126
-
127
- if title != ''
128
- title_coord = Array.new(at)
129
- title_coord[1] -= 2
130
- text_box title, size: 6, at: title_coord, width: w - 4, height: 8
131
- end
132
-
133
- title_adjustment = title == '' ? 4 : 13
134
- at[1] -= title_adjustment
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]
137
- end
138
- end
139
- end
140
- end
@@ -1,53 +0,0 @@
1
- module BrDanfe
2
- module DanfeLib
3
- class Dup
4
- Y = 12.92
5
-
6
- def initialize(pdf, xml)
7
- @pdf = pdf
8
- @xml = xml
9
-
10
- @ltitle = Y - 0.42
11
- end
12
-
13
- def render
14
- @pdf.ititle 0.42, 10.00, 0.75, @ltitle, 'dup.title'
15
- @pdf.ibox 0.85, 19.57, 0.75, Y
16
-
17
- x = 0.75
18
- y = Y
19
- @xml.collect('xmlns', 'dup') do |det|
20
- render_dup(det, x, y)
21
- x += 2.30
22
- end
23
- end
24
-
25
- private
26
-
27
- def render_dup(det, x, y)
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
31
-
32
- @pdf.ibox 0.85, 2.12, x + 0.70, y + 0.20, '', dtduplicata(det), normal
33
-
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
36
- end
37
-
38
- def dtduplicata(det)
39
- dtduplicata = det.css('dVenc').text
40
- dtduplicata = dtduplicata[8, 2] + '/' + dtduplicata[5, 2] + '/' + dtduplicata[0, 4]
41
- dtduplicata
42
- end
43
-
44
- def normal
45
- { size: 6, border: 0 }
46
- end
47
-
48
- def italic
49
- normal.merge({ style: :italic })
50
- end
51
- end
52
- end
53
- end