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.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/config/locales/pt-BR.yml +4 -3
- data/lib/br_danfe/danfe_lib/nfe_lib/consts.rb +7 -0
- data/lib/br_danfe/danfe_lib/nfe_lib/dest.rb +6 -6
- data/lib/br_danfe/danfe_lib/nfe_lib/det_body.rb +12 -4
- data/lib/br_danfe/danfe_lib/nfe_lib/document.rb +25 -12
- data/lib/br_danfe/danfe_lib/nfe_lib/dup.rb +34 -20
- data/lib/br_danfe/danfe_lib/nfe_lib/emit_header.rb +35 -17
- data/lib/br_danfe/danfe_lib/nfe_lib/entrega.rb +3 -3
- data/lib/br_danfe/danfe_lib/nfe_lib/helper.rb +8 -0
- data/lib/br_danfe/danfe_lib/nfe_lib/infadic.rb +3 -3
- data/lib/br_danfe/danfe_lib/nfe_lib/ticket.rb +30 -6
- data/lib/br_danfe/danfe_lib/nfe_lib/transp.rb +2 -2
- data/lib/br_danfe/danfe_lib/nfe_lib/vol.rb +1 -1
- data/lib/br_danfe/version.rb +1 -1
- data/spec/br_danfe/danfe_lib/nfe_lib/helper_spec.rb +16 -0
- data/spec/fixtures/nfe/lib/dest#render-v2.00.pdf +0 -0
- data/spec/fixtures/nfe/lib/dest#render-v3.10.pdf +0 -0
- data/spec/fixtures/nfe/lib/dest#render-v4.00.pdf +0 -0
- data/spec/fixtures/nfe/lib/dest#render-with-address-bigger.pdf +0 -0
- data/spec/fixtures/nfe/lib/dest#render-with_cnpj.pdf +0 -0
- data/spec/fixtures/nfe/lib/dest#render-with_cpf.pdf +0 -0
- data/spec/fixtures/nfe/lib/dest#render-with_ie.pdf +0 -0
- data/spec/fixtures/nfe/lib/dest#render-without-address-complement.pdf +0 -0
- data/spec/fixtures/nfe/lib/det_body#render-csosn.pdf +1211 -1163
- data/spec/fixtures/nfe/lib/det_body#render-cst.pdf +822 -727
- data/spec/fixtures/nfe/lib/det_body#render-fci.pdf +600 -483
- data/spec/fixtures/nfe/lib/det_body#render-icms_st.pdf +602 -481
- data/spec/fixtures/nfe/lib/det_body#render-quantity_with_custom_precision.pdf +597 -479
- data/spec/fixtures/nfe/lib/det_body#render-three_pages.pdf +10019 -10949
- data/spec/fixtures/nfe/lib/det_body#render-two_pages.pdf +9817 -10723
- data/spec/fixtures/nfe/lib/det_body#render-unit_price_with_custom_precision.pdf +597 -479
- data/spec/fixtures/nfe/lib/det_body#render-with_entrega.pdf +612 -493
- data/spec/fixtures/nfe/lib/det_body#render-with_infadprod.pdf +602 -486
- data/spec/fixtures/nfe/lib/det_body#render-with_issqn.pdf +4773 -5079
- data/spec/fixtures/nfe/lib/det_body#render-without_issqn.pdf +4790 -5096
- data/spec/fixtures/nfe/lib/document#lcnpj_cpf-blank.pdf +0 -0
- data/spec/fixtures/nfe/lib/document#lcnpj_cpf-invalid.pdf +0 -0
- data/spec/fixtures/nfe/lib/document#lcnpj_cpf-valid.pdf +0 -0
- data/spec/fixtures/nfe/lib/document#lie-blank-uf-invalid.pdf +0 -0
- data/spec/fixtures/nfe/lib/document#lie-blank.pdf +0 -0
- data/spec/fixtures/nfe/lib/document#lie-invalid.pdf +0 -0
- data/spec/fixtures/nfe/lib/document#lie-valid.pdf +0 -0
- data/spec/fixtures/nfe/lib/dup#render-with_entrega.pdf +0 -0
- data/spec/fixtures/nfe/lib/dup#render.pdf +0 -0
- data/spec/fixtures/nfe/lib/emit_header#render-nfe_key.pdf +191 -119
- data/spec/fixtures/nfe/lib/emit_header#render-second_page.pdf +191 -119
- data/spec/fixtures/nfe/lib/emit_header#render-with_cpf.pdf +193 -117
- data/spec/fixtures/nfe/lib/emit_header#render-with_logo.pdf +191 -119
- data/spec/fixtures/nfe/lib/emit_header#render-without_logo.pdf +176 -104
- data/spec/fixtures/nfe/lib/entrega#render-v2.00.pdf +0 -0
- data/spec/fixtures/nfe/lib/entrega#render-with-address-bigger.pdf +0 -0
- data/spec/fixtures/nfe/lib/entrega#render-with_cpf.pdf +0 -0
- data/spec/fixtures/nfe/lib/icmstot#render-with_entrega.pdf +0 -0
- data/spec/fixtures/nfe/lib/icmstot#render.pdf +0 -0
- data/spec/fixtures/nfe/lib/infadic#render-all_the_informations.pdf +0 -0
- data/spec/fixtures/nfe/lib/infadic#render-difal.pdf +0 -0
- data/spec/fixtures/nfe/lib/infadic#render-extra_volume.pdf +0 -0
- data/spec/fixtures/nfe/lib/infadic#render-with_complementary_information.pdf +0 -0
- data/spec/fixtures/nfe/lib/infadic#render-with_dup_additional_information.pdf +0 -0
- data/spec/fixtures/nfe/lib/infadic#render-with_fisco_additional_information.pdf +0 -0
- data/spec/fixtures/nfe/lib/infadic#render-with_street_data.pdf +0 -0
- data/spec/fixtures/nfe/lib/infadic#render-without_dup_additional_information.pdf +0 -0
- data/spec/fixtures/nfe/lib/infadic#render.pdf +0 -0
- data/spec/fixtures/nfe/lib/infadic_vol#render-extra_volume.pdf +0 -0
- data/spec/fixtures/nfe/lib/issqn#render-with_entrega.pdf +0 -0
- data/spec/fixtures/nfe/lib/issqn#render-with_issqn.pdf +0 -0
- data/spec/fixtures/nfe/lib/issqn#render-with_one_issqn_value.pdf +0 -0
- data/spec/fixtures/nfe/lib/issqn#render-without_issqn.pdf +4 -4
- data/spec/fixtures/nfe/lib/ticket#render.pdf +0 -0
- data/spec/fixtures/nfe/lib/ticket#render_with_dEmit.pdf +0 -0
- data/spec/fixtures/nfe/lib/ticket#render_with_dhEmit.pdf +0 -0
- data/spec/fixtures/nfe/lib/transp#render-modfrete_0.pdf +0 -0
- data/spec/fixtures/nfe/lib/transp#render-modfrete_1.pdf +0 -0
- data/spec/fixtures/nfe/lib/transp#render-modfrete_2.pdf +0 -0
- data/spec/fixtures/nfe/lib/transp#render-modfrete_3.pdf +0 -0
- data/spec/fixtures/nfe/lib/transp#render-modfrete_4.pdf +0 -0
- data/spec/fixtures/nfe/lib/transp#render-modfrete_9.pdf +0 -0
- data/spec/fixtures/nfe/lib/transp#render-with_entrega.pdf +0 -0
- data/spec/fixtures/nfe/lib/transp#render.pdf +0 -0
- data/spec/fixtures/nfe/lib/vol#render-blank-boxes.pdf +0 -0
- data/spec/fixtures/nfe/lib/vol#render-with_entrega.pdf +0 -0
- data/spec/fixtures/nfe/lib/vol#render.pdf +0 -0
- data/spec/fixtures/nfe/v2.00/custom_options.fixture.pdf +1304 -1145
- data/spec/fixtures/nfe/v2.00/nfe_simples_nacional.xml.fixture.pdf +1300 -1141
- data/spec/fixtures/nfe/v2.00/nfe_with_entrega.xml.fixture.pdf +1341 -1163
- data/spec/fixtures/nfe/v2.00/nfe_with_extra_volumes.xml.fixture.pdf +4372 -5800
- data/spec/fixtures/nfe/v2.00/nfe_with_fci.xml.fixture.pdf +883 -717
- data/spec/fixtures/nfe/v2.00/nfe_with_ns.xml.fixture.pdf +4301 -5743
- data/spec/fixtures/nfe/v2.00/nfe_without_ns.xml.fixture.pdf +1290 -1164
- data/spec/fixtures/nfe/v3.10/multiples.xmls.on.the.same.pdf.pdf +4877 -4906
- data/spec/fixtures/nfe/v3.10/nfe_simples_nacional.xml.fixture.pdf +2482 -2487
- data/spec/fixtures/nfe/v3.10/with_footer.fixture.pdf +3846 -4714
- data/spec/fixtures/nfe/v3.10/with_issqn.fixture.pdf +3483 -3598
- data/spec/fixtures/nfe/v3.10/with_three_pages.fixture.pdf +11579 -13213
- data/spec/fixtures/nfe/v3.10/without_issqn.fixture.pdf +4361 -5301
- metadata +7 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1ff19b20871262acd4e02135c7e7d237b5052aef8666a83d6e921cc0e3a4930b
|
|
4
|
+
data.tar.gz: 4410d226e4eaa0123a5180db9d2e33328caacc46105b23aff0715cb605d08e50
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d562723a34053ba2e2b8e541fceb2e73357995d7ac173cb73e3ccfa02fa88b127376da1b146930ba5145bed36d8909b0823146811b7662e8e66f8d4b47e612ab
|
|
7
|
+
data.tar.gz: a2966067515c05e32f12f464d13ec16c0184827e1175e2a3e774d9af9fa06b1768d3ba850dbfde4f78d2b0945a21ae3f793973eb07a545eb2920394d290ae7ce
|
data/Gemfile.lock
CHANGED
data/config/locales/pt-BR.yml
CHANGED
|
@@ -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}
|
|
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
|
-
|
|
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
|
-
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
78
|
-
@pdf.ldate LINE_HEIGHT, 2.
|
|
79
|
-
@pdf.ltime LINE_HEIGHT, 2.
|
|
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
|
-
{
|
|
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
|
-
{
|
|
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
|
|
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 =
|
|
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
|
-
|
|
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] +=
|
|
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 == '' ?
|
|
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 -
|
|
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)]
|
|
28
|
-
|
|
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
|
-
|
|
31
|
-
|
|
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
|
-
|
|
37
|
-
x
|
|
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
|
-
|
|
45
|
-
@pdf.ibox
|
|
46
|
-
@pdf.ibox
|
|
47
|
-
@pdf.
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
x
|
|
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
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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,
|
|
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,
|
|
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.
|
|
73
|
-
size:
|
|
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
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
-
|
|
81
|
-
|
|
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.
|
|
85
|
-
|
|
86
|
-
|
|
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
|
-
|
|
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: :
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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'), ''
|
|
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.
|
|
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
|
-
|
|
15
|
-
|
|
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.
|
|
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.
|
|
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.
|
|
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
|
data/lib/br_danfe/version.rb
CHANGED
|
@@ -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
|
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|