br_danfe 3.0.0 → 3.1.1

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 (98) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/config/locales/pt-BR.yml +4 -3
  4. data/lib/br_danfe/danfe_lib/nfe_lib/consts.rb +7 -0
  5. data/lib/br_danfe/danfe_lib/nfe_lib/dest.rb +6 -6
  6. data/lib/br_danfe/danfe_lib/nfe_lib/det_body.rb +12 -4
  7. data/lib/br_danfe/danfe_lib/nfe_lib/document.rb +25 -12
  8. data/lib/br_danfe/danfe_lib/nfe_lib/dup.rb +34 -20
  9. data/lib/br_danfe/danfe_lib/nfe_lib/emit_header.rb +35 -17
  10. data/lib/br_danfe/danfe_lib/nfe_lib/entrega.rb +3 -3
  11. data/lib/br_danfe/danfe_lib/nfe_lib/helper.rb +8 -0
  12. data/lib/br_danfe/danfe_lib/nfe_lib/infadic.rb +3 -3
  13. data/lib/br_danfe/danfe_lib/nfe_lib/ticket.rb +30 -6
  14. data/lib/br_danfe/danfe_lib/nfe_lib/transp.rb +2 -2
  15. data/lib/br_danfe/danfe_lib/nfe_lib/vol.rb +1 -1
  16. data/lib/br_danfe/version.rb +1 -1
  17. data/spec/br_danfe/danfe_lib/nfe_lib/helper_spec.rb +16 -0
  18. data/spec/fixtures/nfe/lib/dest#render-v2.00.pdf +0 -0
  19. data/spec/fixtures/nfe/lib/dest#render-v3.10.pdf +0 -0
  20. data/spec/fixtures/nfe/lib/dest#render-v4.00.pdf +0 -0
  21. data/spec/fixtures/nfe/lib/dest#render-with-address-bigger.pdf +0 -0
  22. data/spec/fixtures/nfe/lib/dest#render-with_cnpj.pdf +0 -0
  23. data/spec/fixtures/nfe/lib/dest#render-with_cpf.pdf +0 -0
  24. data/spec/fixtures/nfe/lib/dest#render-with_ie.pdf +0 -0
  25. data/spec/fixtures/nfe/lib/dest#render-without-address-complement.pdf +0 -0
  26. data/spec/fixtures/nfe/lib/det_body#render-csosn.pdf +1211 -1163
  27. data/spec/fixtures/nfe/lib/det_body#render-cst.pdf +822 -727
  28. data/spec/fixtures/nfe/lib/det_body#render-fci.pdf +600 -483
  29. data/spec/fixtures/nfe/lib/det_body#render-icms_st.pdf +602 -481
  30. data/spec/fixtures/nfe/lib/det_body#render-quantity_with_custom_precision.pdf +597 -479
  31. data/spec/fixtures/nfe/lib/det_body#render-three_pages.pdf +10019 -10949
  32. data/spec/fixtures/nfe/lib/det_body#render-two_pages.pdf +9817 -10723
  33. data/spec/fixtures/nfe/lib/det_body#render-unit_price_with_custom_precision.pdf +597 -479
  34. data/spec/fixtures/nfe/lib/det_body#render-with_entrega.pdf +612 -493
  35. data/spec/fixtures/nfe/lib/det_body#render-with_infadprod.pdf +602 -486
  36. data/spec/fixtures/nfe/lib/det_body#render-with_issqn.pdf +4773 -5079
  37. data/spec/fixtures/nfe/lib/det_body#render-without_issqn.pdf +4790 -5096
  38. data/spec/fixtures/nfe/lib/document#lcnpj_cpf-blank.pdf +0 -0
  39. data/spec/fixtures/nfe/lib/document#lcnpj_cpf-invalid.pdf +0 -0
  40. data/spec/fixtures/nfe/lib/document#lcnpj_cpf-valid.pdf +0 -0
  41. data/spec/fixtures/nfe/lib/document#lie-blank-uf-invalid.pdf +0 -0
  42. data/spec/fixtures/nfe/lib/document#lie-blank.pdf +0 -0
  43. data/spec/fixtures/nfe/lib/document#lie-invalid.pdf +0 -0
  44. data/spec/fixtures/nfe/lib/document#lie-valid.pdf +0 -0
  45. data/spec/fixtures/nfe/lib/dup#render-with_entrega.pdf +0 -0
  46. data/spec/fixtures/nfe/lib/dup#render.pdf +0 -0
  47. data/spec/fixtures/nfe/lib/emit_header#render-nfe_key.pdf +191 -119
  48. data/spec/fixtures/nfe/lib/emit_header#render-second_page.pdf +191 -119
  49. data/spec/fixtures/nfe/lib/emit_header#render-with_cpf.pdf +193 -117
  50. data/spec/fixtures/nfe/lib/emit_header#render-with_logo.pdf +191 -119
  51. data/spec/fixtures/nfe/lib/emit_header#render-without_logo.pdf +176 -104
  52. data/spec/fixtures/nfe/lib/entrega#render-v2.00.pdf +0 -0
  53. data/spec/fixtures/nfe/lib/entrega#render-with-address-bigger.pdf +0 -0
  54. data/spec/fixtures/nfe/lib/entrega#render-with_cpf.pdf +0 -0
  55. data/spec/fixtures/nfe/lib/icmstot#render-with_entrega.pdf +0 -0
  56. data/spec/fixtures/nfe/lib/icmstot#render.pdf +0 -0
  57. data/spec/fixtures/nfe/lib/infadic#render-all_the_informations.pdf +0 -0
  58. data/spec/fixtures/nfe/lib/infadic#render-difal.pdf +0 -0
  59. data/spec/fixtures/nfe/lib/infadic#render-extra_volume.pdf +0 -0
  60. data/spec/fixtures/nfe/lib/infadic#render-with_complementary_information.pdf +0 -0
  61. data/spec/fixtures/nfe/lib/infadic#render-with_dup_additional_information.pdf +0 -0
  62. data/spec/fixtures/nfe/lib/infadic#render-with_fisco_additional_information.pdf +0 -0
  63. data/spec/fixtures/nfe/lib/infadic#render-with_street_data.pdf +0 -0
  64. data/spec/fixtures/nfe/lib/infadic#render-without_dup_additional_information.pdf +0 -0
  65. data/spec/fixtures/nfe/lib/infadic#render.pdf +0 -0
  66. data/spec/fixtures/nfe/lib/infadic_vol#render-extra_volume.pdf +0 -0
  67. data/spec/fixtures/nfe/lib/issqn#render-with_entrega.pdf +0 -0
  68. data/spec/fixtures/nfe/lib/issqn#render-with_issqn.pdf +0 -0
  69. data/spec/fixtures/nfe/lib/issqn#render-with_one_issqn_value.pdf +0 -0
  70. data/spec/fixtures/nfe/lib/issqn#render-without_issqn.pdf +4 -4
  71. data/spec/fixtures/nfe/lib/ticket#render.pdf +0 -0
  72. data/spec/fixtures/nfe/lib/ticket#render_with_dEmit.pdf +0 -0
  73. data/spec/fixtures/nfe/lib/ticket#render_with_dhEmit.pdf +0 -0
  74. data/spec/fixtures/nfe/lib/transp#render-modfrete_0.pdf +0 -0
  75. data/spec/fixtures/nfe/lib/transp#render-modfrete_1.pdf +0 -0
  76. data/spec/fixtures/nfe/lib/transp#render-modfrete_2.pdf +0 -0
  77. data/spec/fixtures/nfe/lib/transp#render-modfrete_3.pdf +0 -0
  78. data/spec/fixtures/nfe/lib/transp#render-modfrete_4.pdf +0 -0
  79. data/spec/fixtures/nfe/lib/transp#render-modfrete_9.pdf +0 -0
  80. data/spec/fixtures/nfe/lib/transp#render-with_entrega.pdf +0 -0
  81. data/spec/fixtures/nfe/lib/transp#render.pdf +0 -0
  82. data/spec/fixtures/nfe/lib/vol#render-blank-boxes.pdf +0 -0
  83. data/spec/fixtures/nfe/lib/vol#render-with_entrega.pdf +0 -0
  84. data/spec/fixtures/nfe/lib/vol#render.pdf +0 -0
  85. data/spec/fixtures/nfe/v2.00/custom_options.fixture.pdf +1304 -1145
  86. data/spec/fixtures/nfe/v2.00/nfe_simples_nacional.xml.fixture.pdf +1300 -1141
  87. data/spec/fixtures/nfe/v2.00/nfe_with_entrega.xml.fixture.pdf +1341 -1163
  88. data/spec/fixtures/nfe/v2.00/nfe_with_extra_volumes.xml.fixture.pdf +4372 -5800
  89. data/spec/fixtures/nfe/v2.00/nfe_with_fci.xml.fixture.pdf +883 -717
  90. data/spec/fixtures/nfe/v2.00/nfe_with_ns.xml.fixture.pdf +4301 -5743
  91. data/spec/fixtures/nfe/v2.00/nfe_without_ns.xml.fixture.pdf +1290 -1164
  92. data/spec/fixtures/nfe/v3.10/multiples.xmls.on.the.same.pdf.pdf +4877 -4906
  93. data/spec/fixtures/nfe/v3.10/nfe_simples_nacional.xml.fixture.pdf +2482 -2487
  94. data/spec/fixtures/nfe/v3.10/with_footer.fixture.pdf +3846 -4714
  95. data/spec/fixtures/nfe/v3.10/with_issqn.fixture.pdf +3483 -3598
  96. data/spec/fixtures/nfe/v3.10/with_three_pages.fixture.pdf +11579 -13213
  97. data/spec/fixtures/nfe/v3.10/without_issqn.fixture.pdf +4361 -5301
  98. metadata +7 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1dc56c9e0a8e9af673a10afd8a3a2119ec9ba30e812c0e1fb3fea3af011fdeb1
4
- data.tar.gz: 94ad7e6a029b10d402592d44641604ab70866fb475557263d4de52a90b455cf1
3
+ metadata.gz: 1ff19b20871262acd4e02135c7e7d237b5052aef8666a83d6e921cc0e3a4930b
4
+ data.tar.gz: 4410d226e4eaa0123a5180db9d2e33328caacc46105b23aff0715cb605d08e50
5
5
  SHA512:
6
- metadata.gz: 8a190a8b4d59d7d6f92c95221b238a26bf6df6bf572ad23f63c271875647fac1784c593935a7e0b85a28b122580a4f92e8c0c9945a45424701328bc2603b4388
7
- data.tar.gz: c3d07094ba6483b6380ecca1c9da357f24ae9a24b47933e6e2de6a538078691337fcc3ee1159af3320d3a8fc23e27b211c7800b5516044bcc72aae76a5743946
6
+ metadata.gz: d562723a34053ba2e2b8e541fceb2e73357995d7ac173cb73e3ccfa02fa88b127376da1b146930ba5145bed36d8909b0823146811b7662e8e66f8d4b47e612ab
7
+ data.tar.gz: a2966067515c05e32f12f464d13ec16c0184827e1175e2a3e774d9af9fa06b1768d3ba850dbfde4f78d2b0945a21ae3f793973eb07a545eb2920394d290ae7ce
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- br_danfe (3.0.0)
4
+ br_danfe (3.1.1)
5
5
  barby (= 0.6.9)
6
6
  br_documents (>= 0.1.3)
7
7
  i18n (>= 0.8.6)
@@ -18,7 +18,7 @@ pt-BR:
18
18
  infProt: "PROTOCOLO DE AUTORIZAÇÃO DE USO"
19
19
  others:
20
20
  has_no_fiscal_value: "SEM VALOR FISCAL"
21
- page: "FOLHA %{current} de %{total}"
21
+ page: "FOLHA %{current}/%{total}"
22
22
  danfe: "DOCUMENTO AUXILIAR DA NOTA FISCAL ELETRÔNICA"
23
23
  sefaz: "Consulta de autenticidade no portal nacional da NF-e www.nfe.fazenda.gov.br/portal ou no site da Sefaz Autorizadora"
24
24
  ide:
@@ -28,7 +28,8 @@ pt-BR:
28
28
  tpNF:
29
29
  entry: "ENTRADA"
30
30
  departure: "SAÍDA"
31
- document: "N°. %{nNF}\nSÉRIE %{serie}"
31
+ nNF: "Nº %{nNF}"
32
+ serie: "SÉRIE %{serie}"
32
33
  natOp: "NATUREZA DA OPERAÇÃO"
33
34
  dest:
34
35
  title: "DESTINATÁRIO / REMETENTE"
@@ -144,7 +145,7 @@ pt-BR:
144
145
  xNome: "RECEBEMOS DE %{xNome} OS PRODUTOS/SERVIÇOS CONSTANTES DA NOTA FISCAL INDICADA AO LADO"
145
146
  received_at: "DATA DE RECEBIMENTO"
146
147
  receiver: "IDENTIFICAÇÃO E ASSINATURA DO RECEBEDOR"
147
- document: "NF-e\nN°. %{nNF}\nSÉRIE %{serie}"
148
+ title: "NF-e"
148
149
  entrega:
149
150
  title: "INFORMAÇÕES DO LOCAL DE ENTREGA"
150
151
  CNPJ: "CNPJ/CPF"
@@ -3,6 +3,13 @@ module BrDanfe
3
3
  module NfeLib
4
4
  LINE_HEIGHT = 0.80
5
5
  SPACE_BETWEEN_GROUPS = 0.52
6
+ LINE_WIDTH = 0.24
7
+ CELL_PADDING = 2
8
+ TITLE_HEIGHT = 0.325
9
+ CONTENT_WIDTH = 19.56
10
+ TITLE_BACKGROUND_COLOR = 'EFEFEF'.freeze
11
+ LABEL_COLOR = '595959'.freeze
12
+ TEXT_COLOR = '000000'.freeze
6
13
  end
7
14
  end
8
15
  end
@@ -35,13 +35,13 @@ module BrDanfe
35
35
 
36
36
  def render_cnpj_cpf
37
37
  xpath = @xml['dest/CNPJ'].present? ? 'dest/CNPJ' : 'dest/CPF'
38
- @pdf.lcnpj_cpf LINE_HEIGHT, 4.37, 12.57, @l1, @xml, xpath
38
+ @pdf.lcnpj_cpf LINE_HEIGHT, 4.83, 12.57, @l1, @xml, xpath
39
39
  end
40
40
 
41
41
  def render_line2
42
42
  @pdf.i18n_lbox LINE_HEIGHT, 9.66, 0.75, @l2, 'enderDest.xLgr', address
43
43
  @pdf.lbox LINE_HEIGHT, 4.33, 10.41, @l2, @xml, 'enderDest/xBairro'
44
- @pdf.i18n_lbox LINE_HEIGHT, 2.20, 14.74, @l2, 'enderDest.CEP', cep
44
+ @pdf.i18n_lbox LINE_HEIGHT, 2.66, 14.74, @l2, 'enderDest.CEP', cep
45
45
  end
46
46
 
47
47
  def address
@@ -62,7 +62,7 @@ module BrDanfe
62
62
  @pdf.lbox LINE_HEIGHT, 6.61, 0.75, @l3, @xml, 'enderDest/xMun'
63
63
  @pdf.i18n_lbox LINE_HEIGHT, 4.06, 7.36, @l3, 'enderDest.fone', phone
64
64
  @pdf.lbox LINE_HEIGHT, 1.14, 11.42, @l3, @xml, 'enderDest/UF'
65
- @pdf.lie LINE_HEIGHT, 4.38, 12.56, @l3, @xml, 'enderDest/UF', 'dest/IE'
65
+ @pdf.lie LINE_HEIGHT, 4.84, 12.56, @l3, @xml, 'enderDest/UF', 'dest/IE'
66
66
  end
67
67
 
68
68
  def phone
@@ -74,9 +74,9 @@ module BrDanfe
74
74
  end
75
75
 
76
76
  def render_dates(emitted_at_date_and_hour, exited_at_date, exited_at_hour)
77
- @pdf.ldate LINE_HEIGHT, 2.92, 17.40, @l1, 'ide.dEmi', @xml[emitted_at_date_and_hour], align: :right
78
- @pdf.ldate LINE_HEIGHT, 2.92, 17.40, @l2, 'ide.dSaiEnt', @xml[exited_at_date], align: :right
79
- @pdf.ltime LINE_HEIGHT, 2.92, 17.40, @l3, 'ide.hSaiEnt', @xml[exited_at_hour], align: :right
77
+ @pdf.ldate LINE_HEIGHT, 2.91, 17.40, @l1, 'ide.dEmi', @xml[emitted_at_date_and_hour], align: :right
78
+ @pdf.ldate LINE_HEIGHT, 2.91, 17.40, @l2, 'ide.dSaiEnt', @xml[exited_at_date], align: :right
79
+ @pdf.ltime LINE_HEIGHT, 2.91, 17.40, @l3, 'ide.hSaiEnt', @xml[exited_at_hour], align: :right
80
80
  end
81
81
 
82
82
  def render_dates_for_older_nfes
@@ -2,6 +2,8 @@ module BrDanfe
2
2
  module DanfeLib
3
3
  module NfeLib
4
4
  class DetBody
5
+ TABLE_CELL_PADDING = 2
6
+
5
7
  attr_reader :y_position_with_entrega
6
8
 
7
9
  def initialize(pdf, xml)
@@ -43,11 +45,17 @@ module BrDanfe
43
45
  end
44
46
 
45
47
  def header_column(title)
46
- { content: I18n.t("danfe.det.#{title}"), align: :left, size: 6, valign: :top }
48
+ {
49
+ content: I18n.t("danfe.det.#{title}"), align: :center, size: 5, valign: :top, font_style: :bold,
50
+ background_color: TITLE_BACKGROUND_COLOR, padding: [4, TABLE_CELL_PADDING, 3.5, TABLE_CELL_PADDING]
51
+ }
47
52
  end
48
53
 
49
54
  def options
50
- { column_widths: column_widths, cell_style: { padding: 2, border_width: 0.3 } }
55
+ {
56
+ column_widths: column_widths,
57
+ cell_style: { padding: [0.5, TABLE_CELL_PADDING, 1.5, TABLE_CELL_PADDING], border_width: LINE_WIDTH }
58
+ }
51
59
  end
52
60
 
53
61
  def column_widths
@@ -91,7 +99,7 @@ module BrDanfe
91
99
  end
92
100
 
93
101
  def cell_text(text, options = {})
94
- cell = { content: text, border_lines: [:solid], size: 6.5 }
102
+ cell = { content: text, border_lines: [:solid], size: 6 }
95
103
  cell.merge!(options)
96
104
  cell
97
105
  end
@@ -121,7 +129,7 @@ module BrDanfe
121
129
  def render_table(data, start_position, height)
122
130
  @pdf.y = start_position
123
131
  @pdf.bounding_box [0.75.cm, @pdf.cursor], width: 19.56.cm, height: height do
124
- @pdf.table data.map { |item| [item] }, header: true
132
+ @pdf.table data.map { |item| [item] }, header: true, cell_style: { border_width: 0 }
125
133
  end
126
134
  end
127
135
 
@@ -14,7 +14,7 @@ module BrDanfe
14
14
 
15
15
  @document.font 'tinos'
16
16
 
17
- @document.line_width = 0.3
17
+ @document.line_width = LINE_WIDTH
18
18
  end
19
19
 
20
20
  def method_missing(method_name, ...)
@@ -33,7 +33,13 @@ module BrDanfe
33
33
  title = ''
34
34
  title = I18n.t("danfe.#{i18n}") if i18n != ''
35
35
 
36
- text_box title, size: 8, at: [x.cm, Helper.invert(y.cm) - 4], width: w.cm, height: h.cm, style: :bold
36
+ at = [x.cm, Helper.invert((y + h - TITLE_HEIGHT).cm)]
37
+ fill_color TITLE_BACKGROUND_COLOR
38
+ fill_and_stroke_rectangle at, CONTENT_WIDTH.cm, TITLE_HEIGHT.cm
39
+ fill_color TEXT_COLOR
40
+
41
+ text_box title, size: 6.5, at: [at[0] + CELL_PADDING, at[1]], width: w.cm, height: TITLE_HEIGHT.cm,
42
+ style: :bold, valign: :center
37
43
  end
38
44
 
39
45
  def ibarcode(h, w, x, y, info)
@@ -119,23 +125,30 @@ module BrDanfe
119
125
  size: 10,
120
126
  style: nil,
121
127
  valign: :top,
122
- border: 1
128
+ border: 1,
129
+ label_size: 6,
130
+ label_offset: 1.9,
131
+ value_offset: 10,
132
+ leading: 0
123
133
  }.merge(options)
124
134
 
125
135
  stroke_rectangle at, w, h if options[:border] == 1
126
136
 
127
- at[0] += 2
137
+ at[0] += CELL_PADDING
128
138
 
129
- if title != ''
130
- title_coord = Array.new(at)
131
- title_coord[1] -= 2
132
- text_box title, size: 6, at: title_coord, width: w - 4, height: 8
133
- end
139
+ label(at, w, title, options) if title != ''
134
140
 
135
- title_adjustment = title == '' ? 4 : 13
141
+ title_adjustment = title == '' ? 2 : options[:value_offset]
136
142
  at[1] -= title_adjustment
137
- text_box info, size: options[:size], at: at, width: w - 4, height: h - title_adjustment, align: options[:align],
138
- style: options[:style], valign: options[:valign]
143
+ text_box info, size: options[:size], at: at, width: w - (CELL_PADDING * 2), height: h - title_adjustment,
144
+ align: options[:align], style: options[:style], valign: options[:valign], leading: options[:leading]
145
+ end
146
+
147
+ def label(at, w, title, options)
148
+ fill_color LABEL_COLOR
149
+ text_box title, size: options[:label_size], at: [at[0], at[1] - options[:label_offset]],
150
+ width: w - (CELL_PADDING * 2), height: 8
151
+ fill_color TEXT_COLOR
139
152
  end
140
153
  end
141
154
  end
@@ -6,6 +6,11 @@ module BrDanfe
6
6
 
7
7
  Y_POSITION = 12.92
8
8
  DUP_MAX_QUANTITY = 12
9
+ DUPS_PER_ROW = DUP_MAX_QUANTITY / 2
10
+ LABEL_ROW_HEIGHT = 0.30
11
+ VALUE_ROW_HEIGHT = 0.60
12
+ DUP_WIDTH = CONTENT_WIDTH / DUPS_PER_ROW
13
+ UNTITLED_TEXT_OFFSET = 0.07
9
14
 
10
15
  def initialize(pdf, xml)
11
16
  @pdf = pdf
@@ -24,37 +29,42 @@ module BrDanfe
24
29
 
25
30
  render_titles_and_box(x, y)
26
31
 
27
- @xml.collect('xmlns', 'dup') { _1 }[..(DUP_MAX_QUANTITY - 1)].each_with_index do |det, index|
28
- x = 0.75 unless index != DUP_MAX_QUANTITY / 2
32
+ dups = @xml.collect('xmlns', 'dup') { _1 }[..(DUP_MAX_QUANTITY - 1)]
33
+ line_height = VALUE_ROW_HEIGHT / dups.each_slice(DUPS_PER_ROW).count
29
34
 
30
- y = if index < DUP_MAX_QUANTITY / 2
31
- @y_position - 0.015
32
- else
33
- @y_position + 0.185
34
- end
35
+ dups.each_with_index do |det, index|
36
+ x = 0.75 if index == DUPS_PER_ROW
35
37
 
36
- render_dup(det, x, y + 0.3)
37
- x += 3.261666667
38
+ line = index / DUPS_PER_ROW
39
+ render_dup(det, x, y + LABEL_ROW_HEIGHT + (line * line_height), line_height)
40
+ x += DUP_WIDTH
38
41
  end
39
42
  end
40
43
 
41
44
  private
42
45
 
43
46
  def render_titles_and_box(x, y)
44
- (DUP_MAX_QUANTITY / 2).times do
45
- @pdf.ibox 0.30, 3.261666667, x, y
46
- @pdf.ibox 0.60, 3.261666667, x, y + 0.30
47
- @pdf.ibox 0.85, 1.80, x, y - 0.05, '', I18n.t('danfe.dup.nDup'), normal
48
- @pdf.ibox 0.85, 1.80, x + 0.87, y - 0.05, '', I18n.t('danfe.dup.dVenc'), normal
49
- @pdf.ibox 0.85, 1.80, x + 2.35, y - 0.05, '', I18n.t('danfe.dup.vDup'), normal
50
- x += 3.261666667
47
+ DUPS_PER_ROW.times do
48
+ @pdf.ibox LABEL_ROW_HEIGHT, DUP_WIDTH, x, y
49
+ @pdf.ibox VALUE_ROW_HEIGHT, DUP_WIDTH, x, y + LABEL_ROW_HEIGHT
50
+ @pdf.fill_color LABEL_COLOR
51
+ centered_text LABEL_ROW_HEIGHT, 1.80, x, y, I18n.t('danfe.dup.nDup'), label
52
+ centered_text LABEL_ROW_HEIGHT, 1.80, x + 0.87, y, I18n.t('danfe.dup.dVenc'), label
53
+ centered_text LABEL_ROW_HEIGHT, 1.80, x + 2.35, y, I18n.t('danfe.dup.vDup'), label
54
+ @pdf.fill_color TEXT_COLOR
55
+ x += DUP_WIDTH
51
56
  end
52
57
  end
53
58
 
54
- def render_dup(det, x, y)
55
- @pdf.ibox 0.85, 2.12, x + 0.1, y, '', det.css('nDup').text, normal
56
- @pdf.ibox 0.85, 2.12, x + 0.75, y, '', dtduplicata(det), normal
57
- @pdf.inumeric 0.85, 2.12, x + 1.1, y, '', det.css('vDup').text, normal
59
+ def render_dup(det, x, y, height)
60
+ centered_text height, 2.12, x + 0.1, y, det.css('nDup').text, normal
61
+ centered_text height, 2.12, x + 0.75, y, dtduplicata(det), normal
62
+ centered_text height, 2.12, x + 1.1, y, BrDanfe::Helper.numerify(det.css('vDup').text), normal.merge(align: :right)
63
+ end
64
+
65
+ def centered_text(height, width, x, y, text, style)
66
+ @pdf.ibox height + UNTITLED_TEXT_OFFSET, width, x, y - UNTITLED_TEXT_OFFSET, '', text,
67
+ style.merge(valign: :center)
58
68
  end
59
69
 
60
70
  def dtduplicata(det)
@@ -65,6 +75,10 @@ module BrDanfe
65
75
  def normal
66
76
  { size: 6, border: 0 }
67
77
  end
78
+
79
+ def label
80
+ { size: 6, border: 0 }
81
+ end
68
82
  end
69
83
  end
70
84
  end
@@ -2,6 +2,9 @@ module BrDanfe
2
2
  module DanfeLib
3
3
  module NfeLib
4
4
  class EmitHeader
5
+ IDENTIFICATION_SIZE = 10
6
+ DESCRIPTION_SIZE = 8
7
+
5
8
  def initialize(pdf, xml, logo, logo_dimensions)
6
9
  @pdf = pdf
7
10
  @xml = xml
@@ -30,13 +33,17 @@ module BrDanfe
30
33
 
31
34
  def address_company
32
35
  if @logo.blank?
33
- @pdf.ibox 3.92, 7.46, 1.25, @y_position + 1.46, '', address, align: :left, border: 0
36
+ @pdf.ibox 3.92, 7.46, 0.75, @y_position + 1.46, '', address, address_style.merge(align: :center)
34
37
  else
35
- @pdf.ibox 3.92, 4.7, 3.65, @y_position + 1.46, '', address, size: 8, align: :left, border: 0
38
+ @pdf.ibox 3.92, 4.7, 3.65, @y_position + 1.46, '', address, address_style.merge(align: :left)
36
39
  logo
37
40
  end
38
41
  end
39
42
 
43
+ def address_style
44
+ { size: DESCRIPTION_SIZE, style: :bold, border: 0, leading: 2 }
45
+ end
46
+
40
47
  def address
41
48
  "#{@xml['enderEmit/xLgr']}, #{@xml['enderEmit/nro']}\n" \
42
49
  "#{@xml['enderEmit/xBairro']} - #{cep}\n" \
@@ -69,21 +76,30 @@ module BrDanfe
69
76
  @pdf.ibox 0.60, 2.08, 8.21, @y_position, '', 'DANFE',
70
77
  size: 12, align: :center, border: 0, style: :bold
71
78
 
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
79
+ @pdf.ibox 1.40, 2.08, 8.21, @y_position + 0.52, '', I18n.t('danfe.others.danfe'),
80
+ size: DESCRIPTION_SIZE, align: :center, border: 0
81
+
82
+ operation_type_box
74
83
 
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
84
+ identification_line 2.45, I18n.t('danfe.ide.nNF', nNF: Helper.format_number(@xml['ide/nNF']))
85
+ identification_line 2.88, I18n.t('danfe.ide.serie', serie: Helper.format_serie(@xml['ide/serie']))
86
+ identification_line 3.31, I18n.t('danfe.others.page', current: page, total: total)
87
+ end
88
+
89
+ def identification_line(y_offset, text)
90
+ @pdf.ibox 0.45, 2.08, 8.21, @y_position + y_offset, '', text,
91
+ size: IDENTIFICATION_SIZE, align: :center, border: 0, style: :bold
92
+ end
79
93
 
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
94
+ def operation_type_box
95
+ operation = @xml['ide/tpNF'] == '0' ? I18n.t('danfe.ide.tpNF.entry') : I18n.t('danfe.ide.tpNF.departure')
83
96
 
84
- @pdf.ibox 1.00, 2.08, 8.21, @y_position + 3.00, '',
85
- I18n.t('danfe.others.page', current: page, total: total),
86
- size: 8, align: :center, valign: :center, border: 0, style: :bold
97
+ @pdf.formatted_text_box(
98
+ [{ text: @xml['ide/tpNF'], size: IDENTIFICATION_SIZE, styles: [:bold] },
99
+ { text: " - #{operation}", size: DESCRIPTION_SIZE }],
100
+ at: [8.21.cm, Helper.invert((@y_position + 1.92).cm)], width: 2.08.cm, height: 0.50.cm,
101
+ align: :center, valign: :center
102
+ )
87
103
  end
88
104
 
89
105
  def access_key_box
@@ -94,8 +110,10 @@ module BrDanfe
94
110
  end
95
111
 
96
112
  def sefaz_box
113
+ @pdf.fill_color LABEL_COLOR
97
114
  @pdf.ibox 0.85, 10.02, 10.29, @y_position + 3.07, '', I18n.t('danfe.others.sefaz'),
98
- align: :center, size: 8
115
+ valign: :center, size: DESCRIPTION_SIZE
116
+ @pdf.fill_color TEXT_COLOR
99
117
  end
100
118
 
101
119
  def render_emit(y_position)
@@ -104,11 +122,11 @@ module BrDanfe
104
122
 
105
123
  @pdf.lbox LINE_HEIGHT, 10.04, 0.75, y_first_line, @xml, 'ide/natOp'
106
124
  @pdf.ibox LINE_HEIGHT, 9.52, 10.79, y_first_line, I18n.t('danfe.infProt'),
107
- "#{@xml['infProt/nProt']} #{BrDanfe::Helper.format_datetime(@xml['infProt/dhRecbto'])}", align: :center
125
+ "#{@xml['infProt/nProt']} #{BrDanfe::Helper.format_datetime(@xml['infProt/dhRecbto'])}", align: :right
108
126
 
109
127
  @pdf.lie LINE_HEIGHT, 6.36, 0.75, y_second_line, @xml, 'enderEmit/UF', 'emit/IE'
110
128
  @pdf.lie LINE_HEIGHT, 6.86, 7.11, y_second_line, @xml, 'enderDest/UF', 'emit/IEST'
111
- @pdf.lcnpj_cpf LINE_HEIGHT, 6.34, 13.97, y_second_line, @xml, cnpj_cpf
129
+ @pdf.lcnpj_cpf LINE_HEIGHT, 6.34, 13.97, y_second_line, @xml, cnpj_cpf, align: :right
112
130
  end
113
131
 
114
132
  def cnpj_cpf
@@ -35,7 +35,7 @@ module BrDanfe
35
35
  def render_line1
36
36
  @pdf.lbox LINE_HEIGHT, 11.82, 0.75, @l1, @xml, 'entrega/xNome'
37
37
  render_cnpj_cpf
38
- @pdf.lie LINE_HEIGHT, 2.92, 17.40, @l1, @xml, 'entrega/UF', 'entrega/IE'
38
+ @pdf.lie LINE_HEIGHT, 2.91, 17.40, @l1, @xml, 'entrega/UF', 'entrega/IE'
39
39
  end
40
40
 
41
41
  def render_cnpj_cpf
@@ -46,7 +46,7 @@ module BrDanfe
46
46
  def render_line2
47
47
  @pdf.i18n_lbox LINE_HEIGHT, 11.82, 0.75, @l2, 'entrega.xLgr', address
48
48
  @pdf.lbox LINE_HEIGHT, 4.37, 12.57, @l2, @xml, 'entrega/xBairro'
49
- @pdf.i18n_lbox LINE_HEIGHT, 2.92, 17.40, @l2, 'entrega.CEP', cep
49
+ @pdf.i18n_lbox LINE_HEIGHT, 2.91, 17.40, @l2, 'entrega.CEP', cep
50
50
  end
51
51
 
52
52
  def address
@@ -66,7 +66,7 @@ module BrDanfe
66
66
  def render_line3
67
67
  @pdf.lbox LINE_HEIGHT, 15.05, 0.75, @l3, @xml, 'entrega/xMun'
68
68
  @pdf.lbox LINE_HEIGHT, 1.14, 15.8, @l3, @xml, 'entrega/UF'
69
- @pdf.i18n_lbox LINE_HEIGHT, 2.92, 17.40, @l3, 'entrega.fone', phone
69
+ @pdf.i18n_lbox LINE_HEIGHT, 2.91, 17.40, @l3, 'entrega.fone', phone
70
70
  end
71
71
 
72
72
  def phone
@@ -6,6 +6,14 @@ module BrDanfe
6
6
  29.7.cm - y
7
7
  end
8
8
 
9
+ def self.format_number(number)
10
+ number.to_i.to_s.reverse.scan(/\d{1,3}/).join('.').reverse
11
+ end
12
+
13
+ def self.format_serie(serie)
14
+ serie.to_s.rjust(3, '0')
15
+ end
16
+
9
17
  def self.format_date(xml_datetime)
10
18
  formated = ''
11
19
 
@@ -7,7 +7,7 @@ module BrDanfe
7
7
  def initialize(pdf, xml)
8
8
  @pdf = pdf
9
9
  @xml = xml
10
- @title_position = Y_POSITION - 0.41
10
+ @title_position = Y_POSITION - 0.42
11
11
  @y_position = Y_POSITION
12
12
  end
13
13
 
@@ -26,7 +26,7 @@ module BrDanfe
26
26
  end
27
27
 
28
28
  def render_subtitle
29
- @pdf.ibox 2.65, 12.45, 0.75, @y_position, I18n.t('danfe.infAdic.infCpl'), '', size: 8, valign: :top
29
+ @pdf.ibox 2.65, 12.45, 0.75, @y_position, I18n.t('danfe.infAdic.infCpl'), ''
30
30
  end
31
31
 
32
32
  def render_volumes
@@ -120,7 +120,7 @@ module BrDanfe
120
120
  end
121
121
 
122
122
  def render_reserved_fisco
123
- @pdf.ibox 2.65, 7.15, 13.20, @y_position, I18n.t('danfe.infAdic.reserved')
123
+ @pdf.ibox 2.65, 7.11, 13.20, @y_position, I18n.t('danfe.infAdic.reserved'), ''
124
124
  end
125
125
  end
126
126
  end
@@ -7,18 +7,42 @@ module BrDanfe
7
7
  @xml = xml
8
8
  end
9
9
 
10
+ CUT_LINE_Y_POSITION = 3.75
11
+ CUT_LINE_WIDTH = 0.48
12
+ CUT_LINE_COLOR = '888888'.freeze
13
+
10
14
  def render
11
15
  render_additional_data
12
- @pdf.ibox 0.85, 3.85, 0.75, 2.7, I18n.t('danfe.ticket.received_at')
13
- @pdf.ibox 0.85, 11.75, 4.60, 2.7, I18n.t('danfe.ticket.receiver')
14
- @pdf.ibox 1.70, 4.00, 16.35, 1.85, '',
15
- I18n.t('danfe.ticket.document', nNF: @xml['ide/nNF'], serie: @xml['ide/serie']),
16
- align: :center, valign: :center
16
+ @pdf.ibox 0.85, 3.85, 0.75, 2.7, I18n.t('danfe.ticket.received_at'), ''
17
+ @pdf.ibox 0.85, 11.75, 4.60, 2.7, I18n.t('danfe.ticket.receiver'), ''
18
+ render_document
19
+ render_cut_line
17
20
  end
18
21
 
19
22
  def render_additional_data
20
23
  data = generate_additional_data
21
- @pdf.ibox 0.85, 15.60, 0.75, 1.85, '', data, size: 6
24
+ @pdf.ibox 0.85, 15.60, 0.75, 1.85, '', data, size: 6, style: :bold, valign: :center
25
+ end
26
+
27
+ def render_document
28
+ @pdf.ibox 1.70, 3.96, 16.35, 1.85
29
+ @pdf.ibox 0.55, 3.96, 16.35, 1.95, '', I18n.t('danfe.ticket.title'),
30
+ size: 12, align: :center, border: 0, style: :bold
31
+ @pdf.ibox 0.45, 3.96, 16.35, 2.45, '', I18n.t('danfe.ide.nNF', nNF: Helper.format_number(@xml['ide/nNF'])),
32
+ size: 10, align: :center, border: 0, style: :bold
33
+ @pdf.ibox 0.45, 3.96, 16.35, 2.88, '', I18n.t('danfe.ide.serie', serie: Helper.format_serie(@xml['ide/serie'])),
34
+ size: 10, align: :center, border: 0, style: :bold
35
+ end
36
+
37
+ def render_cut_line
38
+ y = Helper.invert(CUT_LINE_Y_POSITION.cm)
39
+ @pdf.line_width CUT_LINE_WIDTH
40
+ @pdf.stroke_color CUT_LINE_COLOR
41
+ @pdf.dash [1.44, 0.48]
42
+ @pdf.stroke_line [0.75.cm, y], [(0.75 + CONTENT_WIDTH).cm, y]
43
+ @pdf.undash
44
+ @pdf.stroke_color TEXT_COLOR
45
+ @pdf.line_width LINE_WIDTH
22
46
  end
23
47
 
24
48
  def generate_additional_data
@@ -25,11 +25,11 @@ module BrDanfe
25
25
  @pdf.lbox LINE_HEIGHT, 1.78, 12.06, @l1, @xml, 'veicTransp/RNTC'
26
26
  @pdf.i18n_lbox LINE_HEIGHT, 2.29, 13.84, @l1, 'veicTransp.placa', plate
27
27
  @pdf.lbox LINE_HEIGHT, 0.76, 16.13, @l1, @xml, 'veicTransp/UF'
28
- @pdf.lcnpj_cpf LINE_HEIGHT, 3.44, 16.89, @l1, @xml, 'transporta/CNPJ'
28
+ @pdf.lcnpj_cpf LINE_HEIGHT, 3.42, 16.89, @l1, @xml, 'transporta/CNPJ'
29
29
  @pdf.lbox LINE_HEIGHT, 8.52, 0.75, @l2, @xml, 'transporta/xEnder'
30
30
  @pdf.lbox LINE_HEIGHT, 6.86, 9.27, @l2, @xml, 'transporta/xMun'
31
31
  @pdf.lbox LINE_HEIGHT, 0.76, 16.13, @l2, @xml, 'transporta/UF'
32
- @pdf.lie LINE_HEIGHT, 3.44, 16.89, @l2, @xml, 'transporta/UF', 'transporta/IE'
32
+ @pdf.lie LINE_HEIGHT, 3.42, 16.89, @l2, @xml, 'transporta/UF', 'transporta/IE'
33
33
  end
34
34
 
35
35
  private
@@ -36,7 +36,7 @@ module BrDanfe
36
36
  @pdf.ibox 0.85, 3.05, 6.22, @l1, I18n.t('danfe.vol.marca'), det.css('marca').text
37
37
  @pdf.ibox 0.85, 4.83, 9.27, @l1, I18n.t('danfe.vol.nVol')
38
38
  @pdf.inumeric 0.85, 3.43, 14.10, @l1, 'vol.pesoB', det.css('pesoB').text, decimals: 3
39
- @pdf.inumeric 0.85, 2.80, 17.53, @l1, 'vol.pesoL', det.css('pesoL').text, decimals: 3
39
+ @pdf.inumeric 0.85, 2.78, 17.53, @l1, 'vol.pesoL', det.css('pesoL').text, decimals: 3
40
40
  end
41
41
 
42
42
  def render_blank_boxes
@@ -1,3 +1,3 @@
1
1
  module BrDanfe
2
- VERSION = '3.0.0'.freeze
2
+ VERSION = '3.1.1'.freeze
3
3
  end
@@ -40,6 +40,22 @@ describe BrDanfe::DanfeLib::NfeLib::Helper do
40
40
  end
41
41
  end
42
42
 
43
+ describe '.format_number' do
44
+ it 'groups the thousands with dots' do
45
+ expect(described_class.format_number('1234567')).to eq '1.234.567'
46
+ end
47
+
48
+ it 'drops the leading zeros' do
49
+ expect(described_class.format_number('000001')).to eq '1'
50
+ end
51
+ end
52
+
53
+ describe '.format_serie' do
54
+ it 'pads the serie with zeros up to three digits' do
55
+ expect(described_class.format_serie('1')).to eq '001'
56
+ end
57
+ end
58
+
43
59
  describe '.address_is_too_big' do
44
60
  let(:pdf) { BrDanfe::DanfeLib::NfeLib::Document.new }
45
61