br_danfe 0.12.1 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -0,0 +1,34 @@
1
+ module BrDanfe
2
+ module DanfeLib
3
+ module NfeLib
4
+ class Cst
5
+ def self.to_danfe(xml)
6
+ value = origin(xml)
7
+
8
+ if csosn?(xml)
9
+ value += xml.css('ICMS/*/CSOSN').text
10
+ elsif cst?(xml)
11
+ value += xml.css('ICMS/*/CST').text
12
+ end
13
+
14
+ value
15
+ end
16
+
17
+ def self.origin(xml)
18
+ xml.css('ICMS/*/orig').text
19
+ end
20
+ private_class_method :origin
21
+
22
+ def self.cst?(xml)
23
+ xml.css('ICMS/*/CST').text != ''
24
+ end
25
+ private_class_method :cst?
26
+
27
+ def self.csosn?(xml)
28
+ xml.css('ICMS/*/CSOSN').text != ''
29
+ end
30
+ private_class_method :csosn?
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,96 @@
1
+ module BrDanfe
2
+ module DanfeLib
3
+ module NfeLib
4
+ class Dest
5
+ Y = 10.00
6
+ MAXIMUM_SIZE_FOR_STREET = 319
7
+
8
+ def initialize(pdf, xml)
9
+ @pdf = pdf
10
+ @xml = xml
11
+ @xml_version_is_310_or_newer = @xml.version_is_310_or_newer?
12
+
13
+ @ltitle = Y - 0.42
14
+ @l1 = Y
15
+ @l2 = Y + LINE_HEIGHT
16
+ @l3 = Y + (LINE_HEIGHT * 2)
17
+ end
18
+
19
+ def render
20
+ @pdf.ititle 0.42, 10.00, 0.75, @ltitle, 'dest.title'
21
+
22
+ render_line1
23
+ render_line2
24
+ render_line3
25
+
26
+ @xml_version_is_310_or_newer ? render_dates_for_nfe_310_or_newer : render_dates_for_older_nfes
27
+ end
28
+
29
+ private
30
+
31
+ def render_line1
32
+ @pdf.lbox LINE_HEIGHT, 11.82, 0.75, @l1, @xml, 'dest/xNome'
33
+ render_cnpj_cpf
34
+ end
35
+
36
+ def render_cnpj_cpf
37
+ if @xml['dest/CNPJ'] == ''
38
+ @pdf.i18n_lbox LINE_HEIGHT, 4.37, 12.57, @l1, 'dest.CPF', cpf
39
+ else
40
+ @pdf.lcnpj LINE_HEIGHT, 4.37, 12.57, @l1, @xml, 'dest/CNPJ'
41
+ end
42
+ end
43
+
44
+ def cpf
45
+ cpf = BrDocuments::CnpjCpf::Cpf.new(@xml['dest/CPF'])
46
+ cpf.formatted
47
+ end
48
+
49
+ def render_line2
50
+ @pdf.i18n_lbox LINE_HEIGHT, 9.66, 0.75, @l2, 'enderDest.xLgr', address
51
+ @pdf.lbox LINE_HEIGHT, 4.33, 10.41, @l2, @xml, 'enderDest/xBairro'
52
+ @pdf.i18n_lbox LINE_HEIGHT, 2.20, 14.74, @l2, 'enderDest.CEP', cep
53
+ end
54
+
55
+ def address
56
+ address = Helper.generate_address @xml
57
+
58
+ if Helper.address_is_too_big(@pdf, address)
59
+ address = address[0..address.length - 2] while Helper.mensure_text(@pdf, "#{address.strip}...") > MAXIMUM_SIZE_FOR_STREET && !address.empty?
60
+ address = "#{address.strip}..."
61
+ end
62
+ address
63
+ end
64
+
65
+ def cep
66
+ Cep.format(@xml['enderDest/CEP'])
67
+ end
68
+
69
+ def render_line3
70
+ @pdf.lbox LINE_HEIGHT, 6.61, 0.75, @l3, @xml, 'enderDest/xMun'
71
+ @pdf.i18n_lbox LINE_HEIGHT, 4.06, 7.36, @l3, 'enderDest.fone', phone
72
+ @pdf.lbox LINE_HEIGHT, 1.14, 11.42, @l3, @xml, 'enderDest/UF'
73
+ @pdf.lie LINE_HEIGHT, 4.38, 12.56, @l3, @xml, 'enderDest/UF', 'dest/IE'
74
+ end
75
+
76
+ def phone
77
+ Phone.format(@xml['enderDest/fone'])
78
+ end
79
+
80
+ def render_dates_for_nfe_310_or_newer
81
+ render_dates 'ide/dhEmi', 'ide/dhSaiEnt', 'ide/dhSaiEnt'
82
+ end
83
+
84
+ def render_dates(emitted_at_date_and_hour, exited_at_date, exited_at_hour)
85
+ @pdf.ldate LINE_HEIGHT, 2.92, 17.40, @l1, 'ide.dEmi', @xml[emitted_at_date_and_hour], align: :right
86
+ @pdf.ldate LINE_HEIGHT, 2.92, 17.40, @l2, 'ide.dSaiEnt', @xml[exited_at_date], align: :right
87
+ @pdf.ltime LINE_HEIGHT, 2.92, 17.40, @l3, 'ide.hSaiEnt', @xml[exited_at_hour], align: :right
88
+ end
89
+
90
+ def render_dates_for_older_nfes
91
+ render_dates 'ide/dEmi', 'ide/dSaiEnt', 'ide/hSaiEnt'
92
+ end
93
+ end
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,137 @@
1
+ module BrDanfe
2
+ module DanfeLib
3
+ module NfeLib
4
+ class DetBody
5
+ def initialize(pdf, xml)
6
+ @pdf = pdf
7
+ @xml = xml
8
+ end
9
+
10
+ def render(has_issqn)
11
+ table_height_on_first_page = table_height_on_first_page has_issqn
12
+ first_table = create_table
13
+ next_table = create_table
14
+
15
+ fill_tables first_table, next_table, table_height_on_first_page
16
+ render_tables first_table, next_table, table_height_on_first_page
17
+ end
18
+
19
+ private
20
+
21
+ def table_height_on_first_page(has_issqn)
22
+ has_issqn ? 6.35.cm : 7.72.cm
23
+ end
24
+
25
+ def create_table
26
+ [create_header]
27
+ end
28
+
29
+ def create_header
30
+ header = [[
31
+ header_column('prod.cProd'), header_column('prod.xProd'), header_column('prod.NCM'),
32
+ header_column('ICMS.CST'), header_column('prod.CFOP'), header_column('prod.uCom'),
33
+ header_column('prod.qCom'), header_column('prod.vUnCom'), header_column('prod.vProd'),
34
+ header_column('ICMS.vBC'), header_column('ICMS.vICMS'), header_column('IPI.vIPI'),
35
+ header_column('ICMS.pICMS'), header_column('IPI.pIPI')
36
+ ]]
37
+ @pdf.make_table(header, options)
38
+ end
39
+
40
+ def header_column(title)
41
+ { content: I18n.t("danfe.det.#{title}"), align: :left, size: 6, valign: :top }
42
+ end
43
+
44
+ def options
45
+ { column_widths: column_widths, cell_style: { padding: 2, border_width: 0.3 } }
46
+ end
47
+
48
+ def column_widths
49
+ {
50
+ 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,
51
+ 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
52
+ }
53
+ end
54
+
55
+ def fill_tables(first_table, next_table, first_table_height)
56
+ total_height = first_table.first.height
57
+
58
+ products.each do |product|
59
+ row = create_row product
60
+ total_height += row.height
61
+ total_height <= first_table_height ? first_table << row : next_table << row
62
+ end
63
+ end
64
+
65
+ def products
66
+ @xml.collect('xmlns', 'det') { |det| product(det) }
67
+ end
68
+
69
+ def product(det)
70
+ [
71
+ cell_text(det.css('prod/cProd').text),
72
+ cell_text(Xprod.new(det).render),
73
+ cell_text(det.css('prod/NCM').text),
74
+ cell_text(Cst.to_danfe(det)),
75
+ cell_text(det.css('prod/CFOP').text),
76
+ cell_text(det.css('prod/uCom').text),
77
+ cell_number(numerify(det, 'prod/qCom')),
78
+ cell_number(numerify(det, 'prod/vUnCom')),
79
+ cell_number(numerify(det, 'prod/vProd')),
80
+ cell_number(numerify(det, 'ICMS/*/vBC')),
81
+ cell_number(numerify(det, 'ICMS/*/vICMS')),
82
+ cell_number(numerify(det, 'IPI/*/vIPI')),
83
+ cell_number(numerify(det, 'ICMS/*/pICMS')),
84
+ cell_number(numerify(det, 'IPI/*/pIPI'))
85
+ ]
86
+ end
87
+
88
+ def cell_text(text, options = {})
89
+ cell = { content: text, border_lines: [:solid], size: 6.5 }
90
+ cell.merge!(options)
91
+ cell
92
+ end
93
+
94
+ def cell_number(text)
95
+ cell_text(text, align: :right)
96
+ end
97
+
98
+ def numerify(det, xpath)
99
+ BrDanfe::Helper.numerify(det.css(xpath.to_s).text)
100
+ end
101
+
102
+ def create_row(data)
103
+ @pdf.make_table([data], options)
104
+ end
105
+
106
+ def render_tables(first_table, next_table, first_table_height)
107
+ render_table first_table, table_position_on_first_page, first_table_height
108
+
109
+ table_with_only_header = 1
110
+ if next_table.size > table_with_only_header
111
+ @pdf.start_new_page
112
+ render_table next_table, table_position_on_next_pages, table_height_on_next_pages
113
+ end
114
+ end
115
+
116
+ def render_table(data, start_position, height)
117
+ @pdf.y = start_position
118
+ @pdf.bounding_box [0.75.cm, @pdf.cursor], width: 19.56.cm, height: height do
119
+ @pdf.table data.map { |item| [item] }, header: true
120
+ end
121
+ end
122
+
123
+ def table_position_on_first_page
124
+ Helper.invert(18.07.cm)
125
+ end
126
+
127
+ def table_position_on_next_pages
128
+ Helper.invert(6.57.cm)
129
+ end
130
+
131
+ def table_height_on_next_pages
132
+ 22.58.cm
133
+ end
134
+ end
135
+ end
136
+ end
137
+ end
@@ -0,0 +1,142 @@
1
+ module BrDanfe
2
+ module DanfeLib
3
+ module NfeLib
4
+ class Document
5
+ def initialize
6
+ @document = Prawn::Document.new(
7
+ page_size: 'A4',
8
+ page_layout: :portrait,
9
+ left_margin: 0,
10
+ right_margin: 0,
11
+ top_margin: 0,
12
+ botton_margin: 0
13
+ )
14
+
15
+ @document.font 'Times-Roman'
16
+ @document.line_width = 0.3
17
+ end
18
+
19
+ def method_missing(method_name, *args, &block)
20
+ if @document.respond_to? method_name
21
+ @document.send method_name, *args, &block
22
+ else
23
+ super
24
+ end
25
+ end
26
+
27
+ def respond_to_missing?(method_name, include_private = false)
28
+ @document.respond_to?(method_name, include_private) || super
29
+ end
30
+
31
+ def ititle(h, w, x, y, i18n)
32
+ title = ''
33
+ title = I18n.t("danfe.#{i18n}") if i18n != ''
34
+
35
+ text_box title, size: 8, at: [x.cm, Helper.invert(y.cm) - 4], width: w.cm, height: h.cm, style: :bold
36
+ end
37
+
38
+ def ibarcode(h, w, x, y, info)
39
+ if info != ''
40
+ Barby::Code128C.new(info).annotate_pdf(self, x: x.cm, y: Helper.invert(y.cm), width: w.cm, height: h.cm)
41
+ end
42
+ end
43
+
44
+ def ibox(h, w, x, y, title = '', info = '', options = {})
45
+ box [x.cm, Helper.invert(y.cm)], w.cm, h.cm, title, info, options
46
+ end
47
+
48
+ def lbox(h, w, x, y, xml, xpath, options = {})
49
+ i18n = xpath.tr('/', '.')
50
+ label = I18n.t("danfe.#{i18n}")
51
+ data = xml[xpath]
52
+
53
+ ibox(h, w, x, y, label, data, options)
54
+ end
55
+
56
+ def ldate(h, w, x, y, i18n = '', info = '', options = {})
57
+ data = Helper.format_date(info)
58
+ i18n_lbox(h, w, x, y, i18n, data, options)
59
+ end
60
+
61
+ def ltime(h, w, x, y, i18n = '', info = '', options = {})
62
+ data = Helper.format_time(info)
63
+ i18n_lbox(h, w, x, y, i18n, data, options)
64
+ end
65
+
66
+ def lcnpj(h, w, x, y, xml, xpath, options = {})
67
+ i18n = xpath.tr('/', '.')
68
+
69
+ cnpj = BrDocuments::CnpjCpf::Cnpj.new(xml[xpath])
70
+ data = if cnpj.valid?
71
+ cnpj.formatted
72
+ else
73
+ ''
74
+ end
75
+
76
+ i18n_lbox(h, w, x, y, i18n, data, options)
77
+ end
78
+
79
+ def lie(h, w, x, y, xml, xpath_uf, xpath_ie, options = {})
80
+ i18n = xpath_ie.tr('/', '.')
81
+
82
+ data = ''
83
+ if BrDanfe::Uf.include?(xml[xpath_uf])
84
+ ie = BrDocuments::IE::Factory.create(xml[xpath_uf], xml[xpath_ie])
85
+ data = ie.formatted if ie.valid?
86
+ end
87
+
88
+ i18n_lbox(h, w, x, y, i18n, data, options)
89
+ end
90
+
91
+ def lnumeric(h, w, x, y, xml, xpath, options = {})
92
+ i18n = xpath.tr('/', '.')
93
+ data = xml[xpath]
94
+
95
+ inumeric(h, w, x, y, i18n, data, options)
96
+ end
97
+
98
+ def inumeric(h, w, x, y, i18n = '', data = '', options = {})
99
+ label = i18n != '' ? I18n.t("danfe.#{i18n}") : ''
100
+ numeric [x.cm, Helper.invert(y.cm)], w.cm, h.cm, label, data, options
101
+ end
102
+
103
+ def i18n_lbox(h, w, x, y, i18n = '', info = '', options = {})
104
+ label = i18n != '' ? I18n.t("danfe.#{i18n}") : ''
105
+ ibox h, w, x, y, label, info, options
106
+ end
107
+
108
+ private
109
+
110
+ def numeric(at, w, h, title = '', info = '', options = {})
111
+ info = BrDanfe::Helper.numerify(info) if info != ''
112
+ box at, w, h, title, info, options.merge(align: :right)
113
+ end
114
+
115
+ def box(at, w, h, title = '', info = '', options = {})
116
+ options = {
117
+ align: :left,
118
+ size: 10,
119
+ style: nil,
120
+ valign: :top,
121
+ border: 1
122
+ }.merge(options)
123
+
124
+ stroke_rectangle at, w, h if options[:border] == 1
125
+
126
+ at[0] += 2
127
+
128
+ if title != ''
129
+ title_coord = Array.new(at)
130
+ title_coord[1] -= 2
131
+ text_box title, size: 6, at: title_coord, width: w - 4, height: 8
132
+ end
133
+
134
+ title_adjustment = title == '' ? 4 : 13
135
+ at[1] -= title_adjustment
136
+ text_box info, size: options[:size], at: at, width: w - 4, height: h - title_adjustment, align: options[:align],
137
+ style: options[:style], valign: options[:valign]
138
+ end
139
+ end
140
+ end
141
+ end
142
+ end
@@ -0,0 +1,55 @@
1
+ module BrDanfe
2
+ module DanfeLib
3
+ module NfeLib
4
+ class Dup
5
+ Y = 12.92
6
+
7
+ def initialize(pdf, xml)
8
+ @pdf = pdf
9
+ @xml = xml
10
+
11
+ @ltitle = Y - 0.42
12
+ end
13
+
14
+ def render
15
+ @pdf.ititle 0.42, 10.00, 0.75, @ltitle, 'dup.title'
16
+ @pdf.ibox 0.85, 19.57, 0.75, Y
17
+
18
+ x = 0.75
19
+ y = Y
20
+ @xml.collect('xmlns', 'dup') do |det|
21
+ render_dup(det, x, y)
22
+ x += 2.30
23
+ end
24
+ end
25
+
26
+ private
27
+
28
+ def render_dup(det, x, y)
29
+ @pdf.ibox 0.85, 2.12, x, y, '', I18n.t('danfe.dup.nDup'), italic
30
+ @pdf.ibox 0.85, 2.12, x + 0.70, y, '', det.css('nDup').text, normal
31
+ @pdf.ibox 0.85, 2.12, x, y + 0.20, '', I18n.t('danfe.dup.dVenc'), italic
32
+
33
+ @pdf.ibox 0.85, 2.12, x + 0.70, y + 0.20, '', dtduplicata(det), normal
34
+
35
+ @pdf.ibox 0.85, 2.12, x, y + 0.40, '', I18n.t('danfe.dup.vDup'), italic
36
+ @pdf.inumeric 0.85, 1.25, x + 0.70, y + 0.40, '', det.css('vDup').text, normal
37
+ end
38
+
39
+ def dtduplicata(det)
40
+ dtduplicata = det.css('dVenc').text
41
+ dtduplicata = dtduplicata[8, 2] + '/' + dtduplicata[5, 2] + '/' + dtduplicata[0, 4]
42
+ dtduplicata
43
+ end
44
+
45
+ def normal
46
+ { size: 6, border: 0 }
47
+ end
48
+
49
+ def italic
50
+ normal.merge(style: :italic)
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end