br_danfe 3.0.0 → 3.1.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 (103) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/config/locales/pt-BR.yml +4 -3
  4. data/fonts/Arimo-LICENSE.txt +118 -0
  5. data/fonts/arimo.ttf +0 -0
  6. data/fonts/arimo_bold.ttf +0 -0
  7. data/fonts/arimo_bold_italic.ttf +0 -0
  8. data/fonts/arimo_italic.ttf +0 -0
  9. data/lib/br_danfe/danfe_lib/nfe_lib/consts.rb +7 -0
  10. data/lib/br_danfe/danfe_lib/nfe_lib/dest.rb +3 -3
  11. data/lib/br_danfe/danfe_lib/nfe_lib/det_body.rb +12 -4
  12. data/lib/br_danfe/danfe_lib/nfe_lib/document.rb +27 -14
  13. data/lib/br_danfe/danfe_lib/nfe_lib/dup.rb +34 -20
  14. data/lib/br_danfe/danfe_lib/nfe_lib/emit_header.rb +34 -17
  15. data/lib/br_danfe/danfe_lib/nfe_lib/entrega.rb +3 -3
  16. data/lib/br_danfe/danfe_lib/nfe_lib/helper.rb +8 -0
  17. data/lib/br_danfe/danfe_lib/nfe_lib/infadic.rb +4 -4
  18. data/lib/br_danfe/danfe_lib/nfe_lib/ticket.rb +30 -6
  19. data/lib/br_danfe/danfe_lib/nfe_lib/transp.rb +2 -2
  20. data/lib/br_danfe/danfe_lib/nfe_lib/vol.rb +1 -1
  21. data/lib/br_danfe/document_builder.rb +7 -0
  22. data/lib/br_danfe/version.rb +1 -1
  23. data/spec/fixtures/nfe/lib/dest#render-v2.00.pdf +0 -0
  24. data/spec/fixtures/nfe/lib/dest#render-v3.10.pdf +0 -0
  25. data/spec/fixtures/nfe/lib/dest#render-v4.00.pdf +0 -0
  26. data/spec/fixtures/nfe/lib/dest#render-with-address-bigger.pdf +0 -0
  27. data/spec/fixtures/nfe/lib/dest#render-with_cnpj.pdf +0 -0
  28. data/spec/fixtures/nfe/lib/dest#render-with_cpf.pdf +0 -0
  29. data/spec/fixtures/nfe/lib/dest#render-with_ie.pdf +0 -0
  30. data/spec/fixtures/nfe/lib/dest#render-without-address-complement.pdf +0 -0
  31. data/spec/fixtures/nfe/lib/det_body#render-csosn.pdf +1234 -1223
  32. data/spec/fixtures/nfe/lib/det_body#render-cst.pdf +836 -771
  33. data/spec/fixtures/nfe/lib/det_body#render-fci.pdf +613 -527
  34. data/spec/fixtures/nfe/lib/det_body#render-icms_st.pdf +619 -534
  35. data/spec/fixtures/nfe/lib/det_body#render-quantity_with_custom_precision.pdf +609 -522
  36. data/spec/fixtures/nfe/lib/det_body#render-three_pages.pdf +10032 -11157
  37. data/spec/fixtures/nfe/lib/det_body#render-two_pages.pdf +9834 -10928
  38. data/spec/fixtures/nfe/lib/det_body#render-unit_price_with_custom_precision.pdf +609 -522
  39. data/spec/fixtures/nfe/lib/det_body#render-with_entrega.pdf +620 -527
  40. data/spec/fixtures/nfe/lib/det_body#render-with_infadprod.pdf +614 -539
  41. data/spec/fixtures/nfe/lib/det_body#render-with_issqn.pdf +4812 -5222
  42. data/spec/fixtures/nfe/lib/det_body#render-without_issqn.pdf +4454 -5414
  43. data/spec/fixtures/nfe/lib/document#lcnpj_cpf-blank.pdf +0 -0
  44. data/spec/fixtures/nfe/lib/document#lcnpj_cpf-invalid.pdf +0 -0
  45. data/spec/fixtures/nfe/lib/document#lcnpj_cpf-valid.pdf +0 -0
  46. data/spec/fixtures/nfe/lib/document#lie-blank-uf-invalid.pdf +0 -0
  47. data/spec/fixtures/nfe/lib/document#lie-blank.pdf +0 -0
  48. data/spec/fixtures/nfe/lib/document#lie-invalid.pdf +0 -0
  49. data/spec/fixtures/nfe/lib/document#lie-valid.pdf +0 -0
  50. data/spec/fixtures/nfe/lib/dup#render-with_entrega.pdf +0 -0
  51. data/spec/fixtures/nfe/lib/dup#render.pdf +0 -0
  52. data/spec/fixtures/nfe/lib/emit_header#render-nfe_key.pdf +225 -251
  53. data/spec/fixtures/nfe/lib/emit_header#render-second_page.pdf +225 -251
  54. data/spec/fixtures/nfe/lib/emit_header#render-with_cpf.pdf +222 -249
  55. data/spec/fixtures/nfe/lib/emit_header#render-with_logo.pdf +225 -251
  56. data/spec/fixtures/nfe/lib/emit_header#render-without_logo.pdf +223 -249
  57. data/spec/fixtures/nfe/lib/entrega#render-v2.00.pdf +0 -0
  58. data/spec/fixtures/nfe/lib/entrega#render-with-address-bigger.pdf +0 -0
  59. data/spec/fixtures/nfe/lib/entrega#render-with_cpf.pdf +0 -0
  60. data/spec/fixtures/nfe/lib/icmstot#render-with_entrega.pdf +0 -0
  61. data/spec/fixtures/nfe/lib/icmstot#render.pdf +0 -0
  62. data/spec/fixtures/nfe/lib/infadic#render-all_the_informations.pdf +0 -0
  63. data/spec/fixtures/nfe/lib/infadic#render-difal.pdf +0 -0
  64. data/spec/fixtures/nfe/lib/infadic#render-extra_volume.pdf +0 -0
  65. data/spec/fixtures/nfe/lib/infadic#render-with_complementary_information.pdf +0 -0
  66. data/spec/fixtures/nfe/lib/infadic#render-with_dup_additional_information.pdf +0 -0
  67. data/spec/fixtures/nfe/lib/infadic#render-with_fisco_additional_information.pdf +0 -0
  68. data/spec/fixtures/nfe/lib/infadic#render-with_street_data.pdf +0 -0
  69. data/spec/fixtures/nfe/lib/infadic#render-without_dup_additional_information.pdf +0 -0
  70. data/spec/fixtures/nfe/lib/infadic#render.pdf +0 -0
  71. data/spec/fixtures/nfe/lib/infadic_vol#render-extra_volume.pdf +0 -0
  72. data/spec/fixtures/nfe/lib/issqn#render-with_entrega.pdf +0 -0
  73. data/spec/fixtures/nfe/lib/issqn#render-with_issqn.pdf +0 -0
  74. data/spec/fixtures/nfe/lib/issqn#render-with_one_issqn_value.pdf +0 -0
  75. data/spec/fixtures/nfe/lib/issqn#render-without_issqn.pdf +4 -4
  76. data/spec/fixtures/nfe/lib/ticket#render.pdf +0 -0
  77. data/spec/fixtures/nfe/lib/ticket#render_with_dEmit.pdf +0 -0
  78. data/spec/fixtures/nfe/lib/ticket#render_with_dhEmit.pdf +0 -0
  79. data/spec/fixtures/nfe/lib/transp#render-modfrete_0.pdf +0 -0
  80. data/spec/fixtures/nfe/lib/transp#render-modfrete_1.pdf +0 -0
  81. data/spec/fixtures/nfe/lib/transp#render-modfrete_2.pdf +0 -0
  82. data/spec/fixtures/nfe/lib/transp#render-modfrete_3.pdf +0 -0
  83. data/spec/fixtures/nfe/lib/transp#render-modfrete_4.pdf +0 -0
  84. data/spec/fixtures/nfe/lib/transp#render-modfrete_9.pdf +0 -0
  85. data/spec/fixtures/nfe/lib/transp#render-with_entrega.pdf +0 -0
  86. data/spec/fixtures/nfe/lib/transp#render.pdf +0 -0
  87. data/spec/fixtures/nfe/lib/vol#render-blank-boxes.pdf +0 -0
  88. data/spec/fixtures/nfe/lib/vol#render-with_entrega.pdf +0 -0
  89. data/spec/fixtures/nfe/lib/vol#render.pdf +0 -0
  90. data/spec/fixtures/nfe/v2.00/custom_options.fixture.pdf +1484 -1417
  91. data/spec/fixtures/nfe/v2.00/nfe_simples_nacional.xml.fixture.pdf +1481 -1407
  92. data/spec/fixtures/nfe/v2.00/nfe_with_entrega.xml.fixture.pdf +1544 -1451
  93. data/spec/fixtures/nfe/v2.00/nfe_with_extra_volumes.xml.fixture.pdf +4604 -6164
  94. data/spec/fixtures/nfe/v2.00/nfe_with_fci.xml.fixture.pdf +1091 -1005
  95. data/spec/fixtures/nfe/v2.00/nfe_with_ns.xml.fixture.pdf +4657 -6185
  96. data/spec/fixtures/nfe/v2.00/nfe_without_ns.xml.fixture.pdf +1492 -1449
  97. data/spec/fixtures/nfe/v3.10/multiples.xmls.on.the.same.pdf.pdf +5190 -5309
  98. data/spec/fixtures/nfe/v3.10/nfe_simples_nacional.xml.fixture.pdf +2684 -2771
  99. data/spec/fixtures/nfe/v3.10/with_footer.fixture.pdf +4095 -5042
  100. data/spec/fixtures/nfe/v3.10/with_issqn.fixture.pdf +3704 -3901
  101. data/spec/fixtures/nfe/v3.10/with_three_pages.fixture.pdf +11692 -13493
  102. data/spec/fixtures/nfe/v3.10/without_issqn.fixture.pdf +4569 -5591
  103. metadata +12 -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: a35847dcbae6504c66476c8d5f59dd87816e0dc16b292300b18ebd2f1914ffb7
4
+ data.tar.gz: 2b00c692e871d8c0aa4007d08e5e388d6ca1201aafc52a965402046ea5126661
5
5
  SHA512:
6
- metadata.gz: 8a190a8b4d59d7d6f92c95221b238a26bf6df6bf572ad23f63c271875647fac1784c593935a7e0b85a28b122580a4f92e8c0c9945a45424701328bc2603b4388
7
- data.tar.gz: c3d07094ba6483b6380ecca1c9da357f24ae9a24b47933e6e2de6a538078691337fcc3ee1159af3320d3a8fc23e27b211c7800b5516044bcc72aae76a5743946
6
+ metadata.gz: 45acd64522683cf03b6d12cb5e590bd1dd4e6c9fff12719e14a066985e3304ada0b21e69f052cced74d855f2471b724b72af024d8d5e2e3a27a701a1642b6612
7
+ data.tar.gz: 76889322d06ca78f1913e8a1883f97a71ca8720895b004aee58806c7b002aee40389d03e6d66500a641acfb4774777fda3dc7a4610b573e603e72dc0a9dc2148
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.0)
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"
@@ -0,0 +1,118 @@
1
+ Copyright 2010-2020 Google Inc. / Google LLC.
2
+
3
+ This Font Software is licensed under the SIL Open Font License, Version 1.1.
4
+
5
+ PREAMBLE
6
+
7
+ The goals of the Open Font License (OFL) are to stimulate
8
+ worldwide development of collaborative font projects,
9
+ to support the font creation efforts
10
+ of academic and linguistic communities,
11
+ and to provide a free and open framework
12
+ in which fonts may be shared and improved
13
+ in partnership with others.
14
+
15
+ The OFL allows the licensed fonts to be used, studied,
16
+ modified and redistributed freely
17
+ as long as they are not sold by themselves.
18
+ The fonts, including any derivative works,
19
+ can be bundled, embedded,
20
+ redistributed and/or sold with any software
21
+ provided that any reserved names are not used
22
+ by derivative works.
23
+ The fonts and derivatives, however,
24
+ cannot be released under any other type of license.
25
+ The requirement for fonts to remain under this license
26
+ does not apply to any document
27
+ created using the fonts or their derivatives.
28
+
29
+ DEFINITIONS
30
+
31
+ "Font Software" refers to the set of files
32
+ released by the Copyright Holder(s) under this license
33
+ and clearly marked as such.
34
+ This may include source files, build scripts and documentation.
35
+
36
+ "Reserved Font Name" refers to any names specified as such
37
+ after the copyright statement(s).
38
+
39
+ "Original Version" refers to the collection
40
+ of Font Software components
41
+ as distributed by the Copyright Holder(s).
42
+
43
+ "Modified Version" refers to any derivative
44
+ made by adding to, deleting, or substituting --
45
+ in part or in whole --
46
+ any of the components of the Original Version,
47
+ by changing formats
48
+ or by porting the Font Software to a new environment.
49
+
50
+ "Author" refers to any designer, engineer, programmer,
51
+ technical writer or other person
52
+ who contributed to the Font Software.
53
+
54
+ PERMISSION & CONDITIONS
55
+
56
+ Permission is hereby granted, free of charge,
57
+ to any person obtaining a copy of the Font Software,
58
+ to use, study, copy, merge, embed, modify, redistribute,
59
+ and sell modified and unmodified copies of the Font Software,
60
+ subject to the following conditions:
61
+
62
+ 1) Neither the Font Software nor any of its individual components,
63
+ in Original or Modified Versions,
64
+ may be sold by itself.
65
+
66
+ 2) Original or Modified Versions of the Font Software
67
+ may be bundled, redistributed and/or sold with any software,
68
+ provided that each copy contains the above copyright notice
69
+ and this license.
70
+ These can be included either as stand-alone text files,
71
+ human-readable headers or in the appropriate
72
+ machine-readable metadata fields within text or binary files
73
+ as long as those fields can be easily viewed by the user.
74
+
75
+ 3) No Modified Version of the Font Software may use
76
+ the Reserved Font Name(s)
77
+ unless explicit written permission is granted
78
+ by the corresponding Copyright Holder.
79
+ This restriction only applies to the primary font name
80
+ as presented to the users.
81
+
82
+ 4) The name(s) of the Copyright Holder(s)
83
+ or the Author(s) of the Font Software
84
+ shall not be used to promote,
85
+ endorse or advertise any Modified Version,
86
+ except to acknowledge the contribution(s)
87
+ of the Copyright Holder(s) and the Author(s)
88
+ or with their explicit written permission.
89
+
90
+ 5) The Font Software,
91
+ modified or unmodified, in part or in whole,
92
+ must be distributed entirely under this license,
93
+ and must not be distributed under any other license.
94
+ The requirement for fonts to remain under this license
95
+ does not apply to any document
96
+ created using the Font Software.
97
+
98
+ TERMINATION
99
+
100
+ This license becomes null and void
101
+ if any of the above conditions are not met.
102
+
103
+ DISCLAIMER
104
+
105
+ THE FONT SOFTWARE IS PROVIDED "AS IS",
106
+ WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
107
+ INCLUDING BUT NOT LIMITED TO
108
+ ANY WARRANTIES OF MERCHANTABILITY,
109
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
110
+ OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT.
111
+ IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE
112
+ FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
113
+ INCLUDING ANY GENERAL, SPECIAL, INDIRECT,
114
+ INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
115
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
116
+ ARISING FROM, OUT OF THE USE OR INABILITY TO USE
117
+ THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE FONT SOFTWARE.
118
+
data/fonts/arimo.ttf ADDED
Binary file
Binary file
Binary file
Binary file
@@ -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 = 3
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
@@ -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: 5 }
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
 
@@ -12,9 +12,9 @@ module BrDanfe
12
12
  botton_margin: 0
13
13
  )
14
14
 
15
- @document.font 'tinos'
15
+ @document.font 'arimo'
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)
@@ -116,26 +122,33 @@ module BrDanfe
116
122
  def box(at, w, h, title = '', info = '', options = {})
117
123
  options = {
118
124
  align: :left,
119
- size: 10,
125
+ size: 6,
120
126
  style: nil,
121
127
  valign: :top,
122
- border: 1
128
+ border: 1,
129
+ label_size: 5.5,
130
+ label_offset: 1.9,
131
+ value_offset: 11.2,
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: 7
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: 5.5, border: 0 }
81
+ end
68
82
  end
69
83
  end
70
84
  end
@@ -2,6 +2,8 @@ module BrDanfe
2
2
  module DanfeLib
3
3
  module NfeLib
4
4
  class EmitHeader
5
+ OPERATION_TYPE_BOX_LINE_WIDTH = 0.75
6
+
5
7
  def initialize(pdf, xml, logo, logo_dimensions)
6
8
  @pdf = pdf
7
9
  @xml = xml
@@ -23,16 +25,16 @@ module BrDanfe
23
25
  def company_box
24
26
  @pdf.ibox 3.92, 7.46, 0.75, @y_position
25
27
  @pdf.ibox 3.92, 7.46, 0.75, @y_position, '', @xml['emit/xNome'],
26
- size: 12, align: :center, border: 0, style: :bold
28
+ size: 8, align: :center, border: 0, style: :bold
27
29
 
28
30
  address_company
29
31
  end
30
32
 
31
33
  def address_company
32
34
  if @logo.blank?
33
- @pdf.ibox 3.92, 7.46, 1.25, @y_position + 1.46, '', address, align: :left, border: 0
35
+ @pdf.ibox 3.92, 7.46, 0.75, @y_position + 1.46, '', address, align: :center, border: 0, leading: 2
34
36
  else
35
- @pdf.ibox 3.92, 4.7, 3.65, @y_position + 1.46, '', address, size: 8, align: :left, border: 0
37
+ @pdf.ibox 3.92, 4.7, 3.65, @y_position + 1.46, '', address, align: :left, border: 0, leading: 2
36
38
  logo
37
39
  end
38
40
  end
@@ -67,35 +69,50 @@ module BrDanfe
67
69
  @pdf.ibox 3.92, 2.08, 8.21, @y_position
68
70
 
69
71
  @pdf.ibox 0.60, 2.08, 8.21, @y_position, '', 'DANFE',
70
- size: 12, align: :center, border: 0, style: :bold
72
+ size: 8, align: :center, border: 0, style: :bold
71
73
 
74
+ @pdf.fill_color LABEL_COLOR
72
75
  @pdf.ibox 1.20, 2.08, 8.21, @y_position + 0.60, '', I18n.t('danfe.others.danfe'),
73
- size: 8, align: :center, border: 0
76
+ size: 4.5, align: :center, border: 0
77
+ @pdf.fill_color TEXT_COLOR
74
78
 
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
79
+ operation_type_box
79
80
 
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
81
+ @pdf.ibox 0.32, 2.08, 8.21, @y_position + 2.55, '',
82
+ I18n.t('danfe.ide.nNF', nNF: Helper.format_number(@xml['ide/nNF'])),
83
+ size: 5.5, align: :center, border: 0
84
+ @pdf.ibox 0.32, 2.08, 8.21, @y_position + 2.80, '',
85
+ I18n.t('danfe.ide.serie', serie: Helper.format_serie(@xml['ide/serie'])),
86
+ size: 5, align: :center, border: 0
83
87
 
84
88
  @pdf.ibox 1.00, 2.08, 8.21, @y_position + 3.00, '',
85
89
  I18n.t('danfe.others.page', current: page, total: total),
86
- size: 8, align: :center, valign: :center, border: 0, style: :bold
90
+ size: 5, align: :center, valign: :center, border: 0
91
+ end
92
+
93
+ def operation_type_box
94
+ @pdf.ibox 0.60, 1.50, 8.21, @y_position + 1.80, '',
95
+ "0 - #{I18n.t('danfe.ide.tpNF.entry')}\n1 - #{I18n.t('danfe.ide.tpNF.departure')}",
96
+ size: 5, valign: :center, border: 0
97
+ @pdf.line_width OPERATION_TYPE_BOX_LINE_WIDTH
98
+ @pdf.ibox 0.55, 0.55, 9.66, @y_position + 1.83, '', @xml['ide/tpNF'],
99
+ size: 6.5, align: :center, valign: :center
100
+ @pdf.line_width LINE_WIDTH
87
101
  end
88
102
 
89
103
  def access_key_box
90
104
  @pdf.ibox 2.22, 10.02, 10.29, @y_position
91
105
  @pdf.ibarcode 1.50, 8.00, 10.4010, @y_position + 1.90, @xml['infProt > chNFe']
92
106
  @pdf.ibox 0.85, 10.02, 10.29, @y_position + 2.22, I18n.t('danfe.chNFe'),
93
- @xml['infProt > chNFe'].gsub(/(\d)(?=(\d\d\d\d)+(?!\d))/, '\\1 '), style: :bold, align: :center
107
+ @xml['infProt > chNFe'].gsub(/(\d)(?=(\d\d\d\d)+(?!\d))/, '\\1 '), size: 6.5, style: :bold,
108
+ align: :center
94
109
  end
95
110
 
96
111
  def sefaz_box
112
+ @pdf.fill_color LABEL_COLOR
97
113
  @pdf.ibox 0.85, 10.02, 10.29, @y_position + 3.07, '', I18n.t('danfe.others.sefaz'),
98
- align: :center, size: 8
114
+ valign: :center, size: 4.5
115
+ @pdf.fill_color TEXT_COLOR
99
116
  end
100
117
 
101
118
  def render_emit(y_position)
@@ -104,11 +121,11 @@ module BrDanfe
104
121
 
105
122
  @pdf.lbox LINE_HEIGHT, 10.04, 0.75, y_first_line, @xml, 'ide/natOp'
106
123
  @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
124
+ "#{@xml['infProt/nProt']} #{BrDanfe::Helper.format_datetime(@xml['infProt/dhRecbto'])}", align: :right
108
125
 
109
126
  @pdf.lie LINE_HEIGHT, 6.36, 0.75, y_second_line, @xml, 'enderEmit/UF', 'emit/IE'
110
127
  @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
128
+ @pdf.lcnpj_cpf LINE_HEIGHT, 6.34, 13.97, y_second_line, @xml, cnpj_cpf, align: :right
112
129
  end
113
130
 
114
131
  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_s.rjust(9, '0').scan(/\d{3}/).join('.')
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'), '', label_size: 4.5
30
30
  end
31
31
 
32
32
  def render_volumes
@@ -35,7 +35,7 @@ module BrDanfe
35
35
 
36
36
  def render_additional_data(y_position)
37
37
  data = generate_additional_data
38
- @pdf.ibox 2.65, 12.45, 0.75, y_position, '', data, size: 6, valign: :top, border: 0
38
+ @pdf.ibox 2.65, 12.45, 0.75, y_position, '', data, size: 5, valign: :top, border: 0
39
39
  end
40
40
 
41
41
  def generate_additional_data
@@ -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'), '', label_size: 4.5
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'), '', label_size: 5
17
+ @pdf.ibox 0.85, 11.75, 4.60, 2.7, I18n.t('danfe.ticket.receiver'), '', label_size: 5
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: 5.5, 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.40, 3.96, 16.35, 2.30, '', I18n.t('danfe.ticket.title'),
30
+ size: 8, align: :center, border: 0, style: :bold
31
+ @pdf.ibox 0.32, 3.96, 16.35, 2.68, '', I18n.t('danfe.ide.nNF', nNF: Helper.format_number(@xml['ide/nNF'])),
32
+ size: 5.5, align: :center, border: 0
33
+ @pdf.ibox 0.32, 3.96, 16.35, 2.90, '', I18n.t('danfe.ide.serie', serie: Helper.format_serie(@xml['ide/serie'])),
34
+ size: 5.5, align: :center, border: 0
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