br_danfe 3.1.1 → 3.2.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.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/Gemfile.lock +1 -1
- data/Guardfile +1 -1
- data/config/locales/pt-BR.yml +40 -0
- data/lib/br_danfe/danfe_lib/nfe.rb +5 -2
- data/lib/br_danfe/danfe_lib/nfe_lib/det_body.rb +22 -63
- data/lib/br_danfe/danfe_lib/nfe_lib/det_row.rb +63 -0
- data/lib/br_danfe/danfe_lib/nfe_lib/emit_header.rb +19 -3
- data/lib/br_danfe/danfe_lib/nfe_lib/ibscbstot.rb +58 -0
- data/lib/br_danfe/danfe_lib/nfe_lib/icmstot.rb +39 -0
- data/lib/br_danfe/danfe_lib/nfe_lib/issqn.rb +20 -11
- data/lib/br_danfe/danfe_lib/nfe_lib/rtc_det_row.rb +145 -0
- data/lib/br_danfe/danfe_lib/nfe_lib/rtc_layout.rb +26 -0
- data/lib/br_danfe/danfe_lib/nfe_lib/transp.rb +1 -0
- data/lib/br_danfe/danfe_lib/nfe_lib/vol.rb +1 -0
- data/lib/br_danfe/qr_code.rb +1 -1
- data/lib/br_danfe/version.rb +1 -1
- data/spec/br_danfe/danfe_lib/nfe_lib/emit_header_spec.rb +42 -0
- data/spec/br_danfe/danfe_lib/nfe_lib/ibscbstot_spec.rb +125 -0
- data/spec/br_danfe/danfe_lib/nfe_lib/icmstot_spec.rb +60 -0
- data/spec/br_danfe/danfe_lib/nfe_lib/issqn_spec.rb +69 -0
- data/spec/br_danfe/danfe_lib/nfe_lib/rtc_det_row_spec.rb +121 -0
- data/spec/br_danfe/danfe_lib/nfe_lib/rtc_layout_spec.rb +113 -0
- data/spec/br_danfe/danfe_lib/nfe_spec.rb +115 -0
- data/spec/br_danfe/uf_spec.rb +3 -3
- data/spec/fixtures/nfe/lib/issqn#render-with_entrega.pdf +0 -0
- data/spec/fixtures/nfe/v4.00/rtc_regime_normal.xml +92 -0
- data/spec/fixtures/nfe/v4.00/rtc_regime_normal.xml.fixture.pdf +4283 -2
- data/spec/fixtures/nfe/v4.00/rtc_regime_normal_with_entrega_and_issqn.xml +105 -0
- data/spec/fixtures/nfe/v4.00/rtc_regime_normal_with_entrega_and_issqn.xml.fixture.pdf +5744 -2
- data/spec/fixtures/nfe/v4.00/rtc_regime_normal_with_fcp_difal_and_monophasic.xml +103 -0
- data/spec/fixtures/nfe/v4.00/rtc_regime_normal_with_fcp_difal_and_monophasic.xml.fixture.pdf +4786 -2
- data/spec/fixtures/nfe/v4.00/rtc_regime_normal_with_many_items.xml +709 -0
- data/spec/fixtures/nfe/v4.00/rtc_regime_normal_with_many_items.xml.fixture.pdf +27509 -2
- data/spec/fixtures/nfe/v4.00/rtc_simples_nacional.xml +65 -0
- data/spec/fixtures/nfe/v4.00/rtc_simples_nacional.xml.fixture.pdf +3526 -2
- data/spec/fixtures/nfe/v4.00/rtc_simples_nacional_before_start_date.xml +65 -0
- data/spec/fixtures/nfe/v4.00/rtc_simples_nacional_before_start_date.xml.fixture.pdf +3998 -2
- metadata +21 -2
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
module BrDanfe
|
|
2
|
+
module DanfeLib
|
|
3
|
+
module NfeLib
|
|
4
|
+
class RtcDetRow
|
|
5
|
+
COLUMNS = [
|
|
6
|
+
'description', 'cst_cfop', 'quantity_unit', 'unit_value', 'total_value', 'bases', 'rates', 'taxes'
|
|
7
|
+
].freeze
|
|
8
|
+
COLUMN_WIDTHS = [3.79, 1.30, 1.30, 1.45, 1.55, 2.69, 3.66, 3.82].freeze
|
|
9
|
+
LABEL_RATIOS = {
|
|
10
|
+
single: [0.50, 0.50], rates: [0.27, 0.23, 0.27, 0.23], taxes: [0.24, 0.26, 0.24, 0.26]
|
|
11
|
+
}.freeze
|
|
12
|
+
FONT_SIZE = 6
|
|
13
|
+
IBSCBS = 'imposto/IBSCBS'.freeze
|
|
14
|
+
GROUP = "#{IBSCBS}/gIBSCBS".freeze
|
|
15
|
+
private_constant :COLUMNS, :COLUMN_WIDTHS, :LABEL_RATIOS, :FONT_SIZE, :IBSCBS, :GROUP
|
|
16
|
+
|
|
17
|
+
def self.titles
|
|
18
|
+
COLUMNS.map { |column| I18n.t("danfe.det.columns.#{column}") }
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def self.column_widths
|
|
22
|
+
COLUMN_WIDTHS.map(&:cm)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def initialize(pdf, det)
|
|
26
|
+
@pdf = pdf
|
|
27
|
+
@det = det
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def render
|
|
31
|
+
[
|
|
32
|
+
description,
|
|
33
|
+
labeled(COLUMN_WIDTHS[1], [[['CST', Cst.to_danfe(@det)]], [['CFOP', text('prod/CFOP')]]], :single),
|
|
34
|
+
quantity,
|
|
35
|
+
cell(value('prod/vUnCom'), align: :right),
|
|
36
|
+
cell(value('prod/vProd'), align: :right),
|
|
37
|
+
labeled(COLUMN_WIDTHS[5], bases.map { |pair| [pair] }, :single),
|
|
38
|
+
labeled(COLUMN_WIDTHS[6], rates, :rates),
|
|
39
|
+
labeled(COLUMN_WIDTHS[7], taxes, :taxes)
|
|
40
|
+
]
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
private
|
|
44
|
+
|
|
45
|
+
def description
|
|
46
|
+
name, additional_information = Xprod.new(@det).render.split("\n", 2)
|
|
47
|
+
lines = [escape(name.to_s), gray(additional_information), gray(codes)]
|
|
48
|
+
cell(lines.compact_blank.join("\n"), inline_format: true)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def escape(content)
|
|
52
|
+
content.gsub('&', '&').gsub('<', '<').gsub('>', '>')
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def gray(content)
|
|
56
|
+
return nil if content.blank?
|
|
57
|
+
|
|
58
|
+
"<color rgb='#{LABEL_COLOR}'>#{escape(content)}</color>"
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def codes
|
|
62
|
+
[
|
|
63
|
+
"[#{I18n.t('danfe.det.code')} #{text('prod/cProd')}]",
|
|
64
|
+
("[#{I18n.t('danfe.det.prod.NCM')} #{text('prod/NCM')}]" if text('prod/NCM').present?),
|
|
65
|
+
("[cClassTrib #{text("#{IBSCBS}/cClassTrib")}]" if text("#{IBSCBS}/cClassTrib").present?)
|
|
66
|
+
].compact.join(' ')
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def text(xpath)
|
|
70
|
+
@det.css(xpath).text
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def cell(content, options = {})
|
|
74
|
+
{ content: content, size: FONT_SIZE }.merge(options)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def labeled(width, lines, ratios)
|
|
78
|
+
rows = lines.reject { |pairs| pairs.all? { |_label, content| content.blank? } }.map { |pairs| labeled_row(pairs) }
|
|
79
|
+
return cell('') if rows.empty?
|
|
80
|
+
|
|
81
|
+
@pdf.make_table(
|
|
82
|
+
rows,
|
|
83
|
+
column_widths: LABEL_RATIOS.fetch(ratios).map { |ratio| (width.cm - (DetBody::TABLE_CELL_PADDING * 2)) * ratio },
|
|
84
|
+
cell_style: { borders: [], size: FONT_SIZE }
|
|
85
|
+
)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def labeled_row(pairs)
|
|
89
|
+
pairs.each_with_index.flat_map do |(label, content), index|
|
|
90
|
+
[
|
|
91
|
+
{ content: content.blank? ? '' : label, text_color: LABEL_COLOR, padding: [0, 1, 0, index.zero? ? 0 : 3] },
|
|
92
|
+
{ content: content.to_s, align: :right, padding: [0, 1, 0, 0] }
|
|
93
|
+
]
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def quantity
|
|
98
|
+
unit = text('prod/uCom')
|
|
99
|
+
lines = [value('prod/qCom'), (gray("[#{unit}]") if unit.present?)]
|
|
100
|
+
cell(lines.compact.join("\n"), align: :center, inline_format: true)
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def value(xpath)
|
|
104
|
+
content = text(xpath)
|
|
105
|
+
content.present? ? BrDanfe::Helper.numerify(content) : ''
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def bases
|
|
109
|
+
[
|
|
110
|
+
['ICMS', value('ICMS/*/vBC')], ['IBS / CBS', value("#{GROUP}/vBC")],
|
|
111
|
+
['IS', value('imposto/IS/vBCIS')], ['IPI', value('IPI/*/vBC')]
|
|
112
|
+
]
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def rates
|
|
116
|
+
[
|
|
117
|
+
[['ICMS', percent(text('ICMS/*/pICMS'))], ['CBS', ibscbs_rate('gCBS', 'pCBS')]],
|
|
118
|
+
[['IBS UF', ibscbs_rate('gIBSUF', 'pIBSUF')], ['IPI', percent(text('IPI/*/pIPI'))]],
|
|
119
|
+
[['IBS MUN', ibscbs_rate('gIBSMun', 'pIBSMun')], ['IS', percent(text('imposto/IS/pIS'))]]
|
|
120
|
+
]
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def percent(number)
|
|
124
|
+
return '' if number.blank?
|
|
125
|
+
|
|
126
|
+
formatted = format('%.4f', BigDecimal(number)).sub(/0{1,2}\z/, '')
|
|
127
|
+
"#{formatted.tr('.', ',')}%"
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def ibscbs_rate(group, rate_tag)
|
|
131
|
+
effective_rate = text("#{GROUP}/#{group}/gRed/pAliqEfet")
|
|
132
|
+
percent(effective_rate.presence || text("#{GROUP}/#{group}/#{rate_tag}"))
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
def taxes
|
|
136
|
+
[
|
|
137
|
+
[['ICMS', value('ICMS/*/vICMS')], ['CBS', value("#{GROUP}/gCBS/vCBS")]],
|
|
138
|
+
[['IBS UF', value("#{GROUP}/gIBSUF/vIBSUF")], ['IPI', value('IPI/*/vIPI')]],
|
|
139
|
+
[['IBS MUN', value("#{GROUP}/gIBSMun/vIBSMun")], ['IS', value('imposto/IS/vIS')]]
|
|
140
|
+
]
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
module BrDanfe
|
|
2
|
+
module DanfeLib
|
|
3
|
+
module NfeLib
|
|
4
|
+
class RtcLayout
|
|
5
|
+
START_DATE = Date.new(2026, 12, 1)
|
|
6
|
+
private_constant :START_DATE
|
|
7
|
+
|
|
8
|
+
def self.applies?(xml)
|
|
9
|
+
xml['IBSCBSTot'].present? || issued_from_start_date?(xml)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def self.offset(xml)
|
|
13
|
+
Icmstot.offset(xml) + Ibscbstot.offset(xml) + Issqn.offset(xml)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def self.issued_from_start_date?(xml)
|
|
17
|
+
issued_at = xml['ide/dhEmi'].presence || xml['ide/dEmi']
|
|
18
|
+
return false if issued_at.blank?
|
|
19
|
+
|
|
20
|
+
Date.parse(issued_at[0, 10]) >= START_DATE
|
|
21
|
+
end
|
|
22
|
+
private_class_method :issued_from_start_date?
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
data/lib/br_danfe/qr_code.rb
CHANGED
|
@@ -12,7 +12,7 @@ module BrDanfe
|
|
|
12
12
|
|
|
13
13
|
def render
|
|
14
14
|
qrcode = RQRCode::QRCode.new(@qr_code_tag)
|
|
15
|
-
image = Tempfile.new(
|
|
15
|
+
image = Tempfile.new(['qrcode', 'png'], binmode: true)
|
|
16
16
|
image.write(qrcode.as_png(module_px_size: 12).to_s)
|
|
17
17
|
|
|
18
18
|
@pdf.image(image, width: @box_size, height: @box_size, position: :center)
|
data/lib/br_danfe/version.rb
CHANGED
|
@@ -178,4 +178,46 @@ describe BrDanfe::DanfeLib::NfeLib::EmitHeader do
|
|
|
178
178
|
end
|
|
179
179
|
end
|
|
180
180
|
end
|
|
181
|
+
|
|
182
|
+
describe '#render with the tax regime code' do
|
|
183
|
+
let(:pdf_text) { PDF::Inspector::Text.analyze(pdf.render).strings.join("\n") }
|
|
184
|
+
let(:issued_at) { '2026-12-02T10:00:00-03:00' }
|
|
185
|
+
let(:crt) { '3' }
|
|
186
|
+
let(:xml_as_string) do
|
|
187
|
+
<<~XML
|
|
188
|
+
<nfeProc xmlns="http://www.portalfiscal.inf.br/nfe" versao="4.00">
|
|
189
|
+
<NFe xmlns="http://www.portalfiscal.inf.br/nfe">
|
|
190
|
+
<infNFe versao="4.00">
|
|
191
|
+
<ide><dhEmi>#{issued_at}</dhEmi><tpNF>1</tpNF><nNF>1</nNF><serie>1</serie></ide>
|
|
192
|
+
<emit><xNome>Nome do Remetente Ltda</xNome><CNPJ>62013294000143</CNPJ><CRT>#{crt}</CRT></emit>
|
|
193
|
+
</infNFe>
|
|
194
|
+
</NFe>
|
|
195
|
+
</nfeProc>
|
|
196
|
+
XML
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
before { subject.render(1, 3.96, 1) }
|
|
200
|
+
|
|
201
|
+
context 'when the NF-e uses the NT 2026.010 layout' do
|
|
202
|
+
it 'renders the tax regime code' do
|
|
203
|
+
expect(pdf_text).to include("CÓDIGO DO REGIME TRIBUTÁRIO\n3 - REGIME NORMAL")
|
|
204
|
+
end
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
context 'when the tax regime code is unknown' do
|
|
208
|
+
let(:crt) { '9' }
|
|
209
|
+
|
|
210
|
+
it 'renders the code as informed' do
|
|
211
|
+
expect(pdf_text).to include("CÓDIGO DO REGIME TRIBUTÁRIO\n9")
|
|
212
|
+
end
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
context 'when the NF-e uses the current layout' do
|
|
216
|
+
let(:issued_at) { '2026-11-20T10:00:00-03:00' }
|
|
217
|
+
|
|
218
|
+
it 'does not render the tax regime code' do
|
|
219
|
+
expect(pdf_text).not_to include('CÓDIGO DO REGIME TRIBUTÁRIO')
|
|
220
|
+
end
|
|
221
|
+
end
|
|
222
|
+
end
|
|
181
223
|
end
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe BrDanfe::DanfeLib::NfeLib::Ibscbstot do
|
|
4
|
+
let(:pdf) { BrDanfe::DanfeLib::NfeLib::Document.new }
|
|
5
|
+
let(:xml) { BrDanfe::XML.new(xml_as_string) }
|
|
6
|
+
let(:pdf_text) { PDF::Inspector::Text.analyze(pdf.render).strings.join("\n") }
|
|
7
|
+
|
|
8
|
+
let(:issued_at) { '2026-12-02T10:00:00-03:00' }
|
|
9
|
+
let(:totals) { '' }
|
|
10
|
+
let(:xml_as_string) do
|
|
11
|
+
<<~XML
|
|
12
|
+
<NFe xmlns="http://www.portalfiscal.inf.br/nfe">
|
|
13
|
+
<infNFe versao="4.00">
|
|
14
|
+
<ide><dhEmi>#{issued_at}</dhEmi></ide>
|
|
15
|
+
<total>#{totals}</total>
|
|
16
|
+
</infNFe>
|
|
17
|
+
</NFe>
|
|
18
|
+
XML
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
let(:ibscbs_totals) do
|
|
22
|
+
<<~XML
|
|
23
|
+
<ISTot><vIS>18.00</vIS></ISTot>
|
|
24
|
+
<IBSCBSTot>
|
|
25
|
+
<vBCIBSCBS>3075.00</vBCIBSCBS>
|
|
26
|
+
<gIBS>
|
|
27
|
+
<gIBSUF><vIBSUF>2.22</vIBSUF></gIBSUF>
|
|
28
|
+
<gIBSMun><vIBSMun>0.00</vIBSMun></gIBSMun>
|
|
29
|
+
</gIBS>
|
|
30
|
+
<gCBS><vCBS>19.98</vCBS></gCBS>
|
|
31
|
+
</IBSCBSTot>
|
|
32
|
+
XML
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
describe '.offset' do
|
|
36
|
+
subject { described_class.offset(xml) }
|
|
37
|
+
|
|
38
|
+
let(:line_height) { 0.8 }
|
|
39
|
+
let(:space_between_blocks) { 0.52 }
|
|
40
|
+
|
|
41
|
+
context 'when the NF-e uses the new layout' do
|
|
42
|
+
it('is one line and the space before the next block') { is_expected.to eql line_height + space_between_blocks }
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
context 'when the NF-e informs the monophasic IBS/CBS group' do
|
|
46
|
+
let(:totals) do
|
|
47
|
+
'<IBSCBSTot><gMono><vIBSMono>0.00</vIBSMono><vCBSMono>0.00</vCBSMono></gMono></IBSCBSTot>'
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it('is two lines and the space before the next block') do
|
|
51
|
+
is_expected.to eql (line_height * 2) + space_between_blocks
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
context 'when the NF-e uses the current layout' do
|
|
56
|
+
let(:issued_at) { '2026-11-20T10:00:00-03:00' }
|
|
57
|
+
|
|
58
|
+
it('adds nothing') { is_expected.to eql 0.0 }
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
describe '#render' do
|
|
63
|
+
before { described_class.new(pdf, xml).render }
|
|
64
|
+
|
|
65
|
+
context 'when the NF-e has IBS, CBS and IS' do
|
|
66
|
+
let(:totals) { ibscbs_totals }
|
|
67
|
+
|
|
68
|
+
it 'renders the IBS, CBS and IS totals' do
|
|
69
|
+
expect(pdf_text).to include(
|
|
70
|
+
"TOTAL DO IBS / CBS / IS\nVALOR DA CBS\n19,98\nVALOR DO IBS UF\n2,22\nVALOR DO IBS MUNICÍPIO\n0,00\n" \
|
|
71
|
+
"VALOR DO IMPOSTO SELETIVO\n18,00"
|
|
72
|
+
)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
it 'does not render the monophasic totals' do
|
|
76
|
+
expect(pdf_text).not_to include('MONOFÁSIC')
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
context 'when the NF-e has no IBS/CBS group' do
|
|
81
|
+
it 'renders the totals in blank' do
|
|
82
|
+
expect(pdf_text).to eql "TOTAL DO IBS / CBS / IS\nVALOR DA CBS\nVALOR DO IBS UF\n" \
|
|
83
|
+
"VALOR DO IBS MUNICÍPIO\nVALOR DO IMPOSTO SELETIVO"
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
context 'when the NF-e informs the monophasic IBS/CBS group' do
|
|
88
|
+
let(:totals) do
|
|
89
|
+
'<IBSCBSTot><gMono><vIBSMono>1.00</vIBSMono><vCBSMono>9.00</vCBSMono>' \
|
|
90
|
+
'<vIBSMonoReten>0.00</vIBSMonoReten><vCBSMonoReten>0.00</vCBSMonoReten></gMono></IBSCBSTot>'
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
it 'renders the monophasic totals' do
|
|
94
|
+
expect(pdf_text).to include("VALOR DO IBS MONOFÁSICO\n1,00\nVALOR DA CBS MONOFÁSICA\n9,00")
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
it 'renders the retention totals in blank' do
|
|
98
|
+
expect(pdf_text).to end_with(
|
|
99
|
+
"VALOR DO IBS MONOFÁSICO POR RETENÇÃO\nVALOR DA CBS MONOFÁSICA POR RETENÇÃO"
|
|
100
|
+
)
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
context 'when the NF-e has monophasic IBS/CBS subject to retention' do
|
|
105
|
+
let(:totals) do
|
|
106
|
+
'<IBSCBSTot><gMono><vIBSMono>1.00</vIBSMono><vCBSMono>9.00</vCBSMono>' \
|
|
107
|
+
'<vIBSMonoReten>0.50</vIBSMonoReten><vCBSMonoReten>4.50</vCBSMonoReten></gMono></IBSCBSTot>'
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
it 'renders the retention totals' do
|
|
111
|
+
expect(pdf_text).to include(
|
|
112
|
+
"VALOR DO IBS MONOFÁSICO POR RETENÇÃO\n0,50\nVALOR DA CBS MONOFÁSICA POR RETENÇÃO\n4,50"
|
|
113
|
+
)
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
context 'when the NF-e uses the current layout' do
|
|
118
|
+
let(:issued_at) { '2026-11-20T10:00:00-03:00' }
|
|
119
|
+
|
|
120
|
+
it 'renders nothing' do
|
|
121
|
+
expect(pdf_text).to eql ''
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
end
|
|
@@ -91,4 +91,64 @@ describe BrDanfe::DanfeLib::NfeLib::Icmstot do
|
|
|
91
91
|
end
|
|
92
92
|
end
|
|
93
93
|
end
|
|
94
|
+
|
|
95
|
+
describe '.offset' do
|
|
96
|
+
subject { described_class.offset(xml) }
|
|
97
|
+
|
|
98
|
+
let(:line_height) { 0.8 }
|
|
99
|
+
|
|
100
|
+
let(:issued_at) { '2026-12-02T10:00:00-03:00' }
|
|
101
|
+
let(:icms_totals) { '<vFCP>0.00</vFCP><vFCPST>0.00</vFCPST><vICMSUFDest>0.00</vICMSUFDest><vFCPUFDest>0.00</vFCPUFDest>' }
|
|
102
|
+
let(:xml_as_string) do
|
|
103
|
+
<<~XML
|
|
104
|
+
<NFe xmlns="http://www.portalfiscal.inf.br/nfe">
|
|
105
|
+
<infNFe versao="4.00">
|
|
106
|
+
<ide><dhEmi>#{issued_at}</dhEmi></ide>
|
|
107
|
+
<total><ICMSTot>#{icms_totals}</ICMSTot></total>
|
|
108
|
+
</infNFe>
|
|
109
|
+
</NFe>
|
|
110
|
+
XML
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
context 'when the NF-e has no FCP, DIFAL or monophasic ICMS' do
|
|
114
|
+
it('adds no line') { is_expected.to eql 0.0 }
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
context 'when the NF-e has FCP' do
|
|
118
|
+
let(:icms_totals) { '<vFCP>24.00</vFCP><vFCPST>0.00</vFCPST><vICMSUFDest>0.00</vICMSUFDest><vFCPUFDest>0.00</vFCPUFDest>' }
|
|
119
|
+
|
|
120
|
+
it('adds one line') { is_expected.to eql line_height }
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
context 'when the NF-e has DIFAL' do
|
|
124
|
+
let(:icms_totals) { '<vFCP>0.00</vFCP><vFCPST>0.00</vFCPST><vICMSUFDest>45.00</vICMSUFDest><vFCPUFDest>9.00</vFCPUFDest>' }
|
|
125
|
+
|
|
126
|
+
it('adds one line') { is_expected.to eql line_height }
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
context 'when the NF-e has monophasic ICMS' do
|
|
130
|
+
let(:icms_totals) { '<vFCP>0.00</vFCP><qBCMono>100.00</qBCMono><vICMSMono>112.00</vICMSMono>' }
|
|
131
|
+
|
|
132
|
+
it('adds one line') { is_expected.to eql line_height }
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
context 'when the monophasic ICMS totals are zero' do
|
|
136
|
+
let(:icms_totals) { '<vFCP>0.00</vFCP><vICMSMono>0.00</vICMSMono><vICMSMonoReten>0.00</vICMSMonoReten>' }
|
|
137
|
+
|
|
138
|
+
it('adds no line') { is_expected.to eql 0.0 }
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
context 'when the NF-e has FCP and monophasic ICMS' do
|
|
142
|
+
let(:icms_totals) { '<vFCP>24.00</vFCP><qBCMono>100.00</qBCMono><vICMSMono>112.00</vICMSMono>' }
|
|
143
|
+
|
|
144
|
+
it('adds two lines') { is_expected.to eql line_height * 2 }
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
context 'when the NF-e uses the current layout' do
|
|
148
|
+
let(:issued_at) { '2026-11-20T10:00:00-03:00' }
|
|
149
|
+
let(:icms_totals) { '<vFCP>24.00</vFCP><qBCMono>100.00</qBCMono><vICMSMono>112.00</vICMSMono>' }
|
|
150
|
+
|
|
151
|
+
it('adds no line') { is_expected.to eql 0.0 }
|
|
152
|
+
end
|
|
153
|
+
end
|
|
94
154
|
end
|
|
@@ -121,6 +121,75 @@ describe BrDanfe::DanfeLib::NfeLib::Issqn do
|
|
|
121
121
|
|
|
122
122
|
expect("#{base_dir}issqn#render-with_entrega.pdf").to have_same_content_of file: output_pdf
|
|
123
123
|
end
|
|
124
|
+
|
|
125
|
+
it 'keeps the ISSQN above the complementary information' do
|
|
126
|
+
expect(subject.y_position).to eql 26.24
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
describe 'NT 2026.010 layout' do
|
|
132
|
+
let(:issued_at) { '2026-12-02T10:00:00-03:00' }
|
|
133
|
+
let(:entrega) { '' }
|
|
134
|
+
let(:issqn) { '<vServ>100.00</vServ><vBC>100.00</vBC><vISS>5.00</vISS>' }
|
|
135
|
+
let(:xml_as_string) do
|
|
136
|
+
<<~XML
|
|
137
|
+
<NFe xmlns="http://www.portalfiscal.inf.br/nfe">
|
|
138
|
+
<infNFe versao="4.00">
|
|
139
|
+
<ide><dhEmi>#{issued_at}</dhEmi></ide>
|
|
140
|
+
#{entrega}
|
|
141
|
+
<total><ISSQNtot>#{issqn}</ISSQNtot></total>
|
|
142
|
+
</infNFe>
|
|
143
|
+
</NFe>
|
|
144
|
+
XML
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
let(:transporter_position) { 16.41 }
|
|
148
|
+
let(:ibscbs_block) { 1.32 }
|
|
149
|
+
|
|
150
|
+
describe '#y_position' do
|
|
151
|
+
it 'is below the IBS/CBS/IS block, at the transporter position' do
|
|
152
|
+
expect(subject.y_position).to eql transporter_position + 0.0 + ibscbs_block
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
context 'with entrega' do
|
|
156
|
+
let(:entrega) { '<entrega><xLgr>Rua Entrega</xLgr></entrega>' }
|
|
157
|
+
|
|
158
|
+
it 'moves down with the delivery place' do
|
|
159
|
+
expect(subject.y_position).to eql transporter_position + 3.0 + 0.0 + ibscbs_block
|
|
160
|
+
end
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
context 'when the NF-e uses the current layout' do
|
|
164
|
+
let(:issued_at) { '2026-11-20T10:00:00-03:00' }
|
|
165
|
+
|
|
166
|
+
it 'is above the complementary information' do
|
|
167
|
+
expect(subject.y_position).to eql 26.24
|
|
168
|
+
end
|
|
169
|
+
end
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
describe '.offset' do
|
|
173
|
+
subject { described_class.offset(xml) }
|
|
174
|
+
|
|
175
|
+
let(:line_height) { 0.8 }
|
|
176
|
+
let(:space_between_blocks) { 0.52 }
|
|
177
|
+
|
|
178
|
+
it 'is one line and the space before the next block' do
|
|
179
|
+
expect(subject).to eql line_height + space_between_blocks
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
context 'when the NF-e has no ISSQN' do
|
|
183
|
+
let(:issqn) { '<vServ>0.00</vServ><vBC>0.00</vBC><vISS>0.00</vISS>' }
|
|
184
|
+
|
|
185
|
+
it('adds nothing') { is_expected.to eql 0.0 }
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
context 'when the NF-e uses the current layout' do
|
|
189
|
+
let(:issued_at) { '2026-11-20T10:00:00-03:00' }
|
|
190
|
+
|
|
191
|
+
it('adds nothing') { is_expected.to eql 0.0 }
|
|
192
|
+
end
|
|
124
193
|
end
|
|
125
194
|
end
|
|
126
195
|
end
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe BrDanfe::DanfeLib::NfeLib::RtcDetRow do
|
|
4
|
+
let(:pdf) { BrDanfe::DanfeLib::NfeLib::Document.new }
|
|
5
|
+
let(:det) { BrDanfe::XML.new(xml_as_string).collect('xmlns', 'det') { _1 }.first }
|
|
6
|
+
let(:pdf_text) { PDF::Inspector::Text.analyze(pdf.render).strings.join("\n") }
|
|
7
|
+
|
|
8
|
+
let(:product) do
|
|
9
|
+
<<~XML
|
|
10
|
+
<prod>
|
|
11
|
+
<cProd>TIJ-001</cProd><xProd>TIJOLO CERAMICO</xProd><NCM>69041000</NCM><CFOP>5101</CFOP>
|
|
12
|
+
<uCom>UN</uCom><qCom>1000.00</qCom><vUnCom>1.20</vUnCom><vProd>1200.00</vProd>
|
|
13
|
+
</prod>
|
|
14
|
+
XML
|
|
15
|
+
end
|
|
16
|
+
let(:icms) { '<ICMS><ICMS00><orig>0</orig><CST>00</CST><vBC>1200.00</vBC><pICMS>17.00</pICMS><vICMS>204.00</vICMS></ICMS00></ICMS>' }
|
|
17
|
+
let(:ibscbs) do
|
|
18
|
+
<<~XML
|
|
19
|
+
<IBSCBS><CST>000</CST><cClassTrib>000001</cClassTrib>
|
|
20
|
+
<gIBSCBS><vBC>1200.00</vBC>
|
|
21
|
+
<gIBSUF><pIBSUF>0.1234</pIBSUF><vIBSUF>1.48</vIBSUF></gIBSUF>
|
|
22
|
+
<gIBSMun><pIBSMun>12.5000</pIBSMun><vIBSMun>150.00</vIBSMun></gIBSMun>
|
|
23
|
+
<gCBS><pCBS>0.9000</pCBS><vCBS>10.80</vCBS></gCBS>
|
|
24
|
+
</gIBSCBS>
|
|
25
|
+
</IBSCBS>
|
|
26
|
+
XML
|
|
27
|
+
end
|
|
28
|
+
let(:xml_as_string) do
|
|
29
|
+
<<~XML
|
|
30
|
+
<NFe xmlns="http://www.portalfiscal.inf.br/nfe">
|
|
31
|
+
<infNFe versao="4.00">
|
|
32
|
+
<det nItem="1">#{product}<imposto>#{icms}#{ibscbs}</imposto></det>
|
|
33
|
+
</infNFe>
|
|
34
|
+
</NFe>
|
|
35
|
+
XML
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
before do
|
|
39
|
+
pdf.table([described_class.new(pdf, det).render], column_widths: described_class.column_widths)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
describe '#render' do
|
|
43
|
+
it 'renders the description with the product code, the NCM and the tax classification' do
|
|
44
|
+
expect(pdf_text).to include("TIJOLO CERAMICO\n[CÓD TIJ-001] [NCM 69041000]", '[cClassTrib 000001]')
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it 'renders the CST and the CFOP' do
|
|
48
|
+
expect(pdf_text).to include("CST\n000\nCFOP\n5101")
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it 'renders the quantity with the unit' do
|
|
52
|
+
expect(pdf_text).to include("1.000,00\n[UN]")
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
it 'renders the bases of ICMS and IBS/CBS' do
|
|
56
|
+
expect(pdf_text).to include("ICMS\n1.200,00\nIBS / CBS\n1.200,00")
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it 'renders the rates with two to four decimal places' do
|
|
60
|
+
expect(pdf_text).to include("ICMS\n17,00%\nCBS\n0,90%\nIBS UF\n0,1234%\nIBS MUN\n12,50%")
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it 'renders the tax values' do
|
|
64
|
+
expect(pdf_text).to include("ICMS\n204,00\nCBS\n10,80\nIBS UF\n1,48\nIBS MUN\n150,00")
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
context 'when the IBS/CBS rates are reduced' do
|
|
68
|
+
let(:ibscbs) do
|
|
69
|
+
<<~XML
|
|
70
|
+
<IBSCBS><CST>200</CST><cClassTrib>200003</cClassTrib>
|
|
71
|
+
<gIBSCBS><vBC>1200.00</vBC>
|
|
72
|
+
<gIBSUF><pIBSUF>0.1000</pIBSUF><gRed><pRedAliq>60.0000</pRedAliq><pAliqEfet>0.0400</pAliqEfet></gRed><vIBSUF>0.48</vIBSUF></gIBSUF>
|
|
73
|
+
<gIBSMun><pIBSMun>0.0000</pIBSMun><vIBSMun>0.00</vIBSMun></gIBSMun>
|
|
74
|
+
<gCBS><pCBS>0.9000</pCBS><gRed><pRedAliq>60.0000</pRedAliq><pAliqEfet>0.3600</pAliqEfet></gRed><vCBS>4.32</vCBS></gCBS>
|
|
75
|
+
</gIBSCBS>
|
|
76
|
+
</IBSCBS>
|
|
77
|
+
XML
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
it 'renders the effective rates' do
|
|
81
|
+
expect(pdf_text).to include("CBS\n0,36%\nIBS UF\n0,04%\nIBS MUN\n0,00%")
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
context 'when the item has the selective tax' do
|
|
86
|
+
let(:icms) { '<IS><vBCIS>450.00</vBCIS><pIS>4.0000</pIS><vIS>18.00</vIS></IS>' }
|
|
87
|
+
|
|
88
|
+
it 'renders the base, the rate and the value of the selective tax' do
|
|
89
|
+
expect(pdf_text).to include("IS\n450,00", "IS\n4,00%", "IS\n18,00")
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
context 'when the description has markup characters' do
|
|
94
|
+
let(:product) do
|
|
95
|
+
<<~XML
|
|
96
|
+
<prod>
|
|
97
|
+
<cProd>A&B<1></cProd><xProd>PARAFUSO <M6> & PORCA</xProd><CFOP>5101</CFOP>
|
|
98
|
+
<uCom>UN</uCom><qCom>1.00</qCom><vUnCom>1.00</vUnCom><vProd>1.00</vProd>
|
|
99
|
+
</prod>
|
|
100
|
+
XML
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
it 'renders the characters as text' do
|
|
104
|
+
expect(pdf_text).to include("PARAFUSO <M6> & PORCA\n[CÓD A&B<1>]")
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
context 'when a Simples Nacional item has no IBS/CBS' do
|
|
109
|
+
let(:icms) { '<ICMS><ICMSSN102><orig>0</orig><CSOSN>102</CSOSN></ICMSSN102></ICMS>' }
|
|
110
|
+
let(:ibscbs) { '' }
|
|
111
|
+
|
|
112
|
+
it 'renders the description without the tax classification' do
|
|
113
|
+
expect(pdf_text).to include("TIJOLO CERAMICO\n[CÓD TIJ-001] [NCM 69041000]\nCST\n0102")
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
it 'renders the bases, rates and tax values in blank' do
|
|
117
|
+
expect(pdf_text).not_to include('ICMS', 'IBS', 'CBS')
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
end
|