br_danfe 3.2.0 → 3.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3bc7ee3b8c7c0d1b2f88af07f7c53ec27de36b84f1b082c2b6a3e653908ddc3c
4
- data.tar.gz: 25f32de99bd11182620ddfa7f08d2bd5de4cfcc7093e296a46f6e590d5f99c64
3
+ metadata.gz: a5c768ac88fe2c6a25d1127239c06e4f7bc1dbdd6b2bd2265e31612c6e300e5a
4
+ data.tar.gz: 1b4a06529ad8c8c15ef874643fe355d53c51f6792dbd18126ebc078b4d565f75
5
5
  SHA512:
6
- metadata.gz: aaa108cc8c8062f50becce7d14c1099f7a59da850c9381b96d024208ff8d79465998f2c33f7c463b057cb1b8c0acab9d90534c78b35602cbb327678c83b7bb7e
7
- data.tar.gz: 440245cab68841c83fb723fb20f7da99cd0be11757b939bce6a4737fcb0888acdef5992dadddcf87a1c355f77702689554176cd47e8319a3fe580d6ac7b7092c
6
+ metadata.gz: ee02fe9b2139f45652e81a1be6c59540e4596b05b4fbe92dab8933dda25f67d7a34c61ef3cf26b1294337778508d6388f353c2c547ded10c40df804aef1d4e00
7
+ data.tar.gz: 326c657486b139540f35250098a6d261c8e5e3c5734931fdf13bf01f98db7e54e0d1ea56f9990832d5a65cde765aa0e42e83c1a4305fdda1480f01557df0dfc7
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- br_danfe (3.2.0)
4
+ br_danfe (3.2.1)
5
5
  barby (= 0.6.9)
6
6
  br_documents (>= 0.1.3)
7
7
  i18n (>= 0.8.6)
@@ -56,6 +56,8 @@ pt-BR:
56
56
  "2": "2 - SIMPLES NACIONAL - EXCESSO"
57
57
  "3": "3 - REGIME NORMAL"
58
58
  "4": "4 - SIMPLES NACIONAL - MEI"
59
+ tpRegimeIBSCBS:
60
+ title: "TIPO DE REGIME DE APURAÇÃO DO IBS E DA CBS"
59
61
  dup:
60
62
  title: "FATURA / DUPLICATAS"
61
63
  nDup: "NRO"
@@ -84,7 +84,7 @@ module BrDanfe
84
84
  return if page == 1 && !@products_on_first_page
85
85
 
86
86
  y_position = NfeLib::Entrega.delivery_local?(xml) && page == 1 ? 3.00 : 0
87
- y_position += page == 1 ? 18.91 + NfeLib::RtcLayout.offset(xml) : 7.40
87
+ y_position += page == 1 ? 18.91 + NfeLib::RtcLayout.offset(xml) : 7.40 + NfeLib::EmitHeader.offset(xml)
88
88
  @document.ititle 0.42, 10.00, 0.75, y_position, 'det.title'
89
89
  end
90
90
 
@@ -10,10 +10,11 @@ module BrDanfe
10
10
  @xml = xml
11
11
  @xml_version_is_310_or_newer = @xml.version_is_310_or_newer?
12
12
 
13
- @ltitle = Y - 0.42
14
- @l1 = Y
15
- @l2 = Y + LINE_HEIGHT
16
- @l3 = Y + (LINE_HEIGHT * 2)
13
+ y_position = Y + EmitHeader.offset(@xml)
14
+ @ltitle = y_position - 0.42
15
+ @l1 = y_position
16
+ @l2 = y_position + LINE_HEIGHT
17
+ @l3 = y_position + (LINE_HEIGHT * 2)
17
18
  end
18
19
 
19
20
  def render
@@ -98,11 +98,11 @@ module BrDanfe
98
98
  end
99
99
 
100
100
  def table_position_on_next_pages
101
- Helper.invert(6.57.cm)
101
+ Helper.invert((6.57 + EmitHeader.offset(@xml)).cm)
102
102
  end
103
103
 
104
104
  def table_height_on_next_pages
105
- 22.58.cm
105
+ (22.58 - EmitHeader.offset(@xml)).cm
106
106
  end
107
107
  end
108
108
  end
@@ -17,6 +17,7 @@ module BrDanfe
17
17
  @xml = xml
18
18
 
19
19
  @y_position = Entrega.delivery_local?(@xml) ? Y_POSITION + 3.00 : Y_POSITION
20
+ @y_position += EmitHeader.offset(@xml)
20
21
 
21
22
  @ltitle = @y_position - 0.42
22
23
  end
@@ -5,6 +5,10 @@ module BrDanfe
5
5
  IDENTIFICATION_SIZE = 10
6
6
  DESCRIPTION_SIZE = 8
7
7
 
8
+ def self.offset(xml)
9
+ RtcLayout.applies?(xml) ? LINE_HEIGHT : 0.0
10
+ end
11
+
8
12
  def initialize(pdf, xml, logo, logo_dimensions)
9
13
  @pdf = pdf
10
14
  @xml = xml
@@ -124,7 +128,8 @@ module BrDanfe
124
128
  @pdf.ibox LINE_HEIGHT, 9.52, 10.79, y_first_line, I18n.t('danfe.infProt'),
125
129
  "#{@xml['infProt/nProt']} #{BrDanfe::Helper.format_datetime(@xml['infProt/dhRecbto'])}", align: :right
126
130
 
127
- RtcLayout.applies?(@xml) ? render_rtc_second_line(y_second_line) : render_second_line(y_second_line)
131
+ render_second_line(y_second_line)
132
+ render_tax_regime_line(y_second_line + LINE_HEIGHT) if RtcLayout.applies?(@xml)
128
133
  end
129
134
 
130
135
  def render_second_line(y_position)
@@ -133,16 +138,14 @@ module BrDanfe
133
138
  @pdf.lcnpj_cpf LINE_HEIGHT, 6.34, 13.97, y_position, @xml, cnpj_cpf, align: :right
134
139
  end
135
140
 
136
- def render_rtc_second_line(y_position)
137
- @pdf.lie LINE_HEIGHT, 4.40, 0.75, y_position, @xml, 'enderEmit/UF', 'emit/IE'
138
- @pdf.lie LINE_HEIGHT, 4.40, 5.15, y_position, @xml, 'enderDest/UF', 'emit/IEST'
139
- @pdf.i18n_lbox LINE_HEIGHT, 6.00, 9.55, y_position, 'emit.CRT.title', crt
140
- @pdf.lcnpj_cpf LINE_HEIGHT, 4.76, 15.55, y_position, @xml, cnpj_cpf, align: :right
141
+ def render_tax_regime_line(y_position)
142
+ @pdf.i18n_lbox LINE_HEIGHT, 10.04, 0.75, y_position, 'emit.CRT.title', described_code('CRT')
143
+ @pdf.i18n_lbox LINE_HEIGHT, 9.52, 10.79, y_position, 'emit.tpRegimeIBSCBS.title', ''
141
144
  end
142
145
 
143
- def crt
144
- code = @xml['emit/CRT']
145
- code.present? ? I18n.t("danfe.emit.CRT.#{code}", default: code) : ''
146
+ def described_code(tag)
147
+ code = @xml["emit/#{tag}"]
148
+ code.present? ? I18n.t("danfe.emit.#{tag}.#{code}", default: code) : ''
146
149
  end
147
150
 
148
151
  def cnpj_cpf
@@ -9,7 +9,7 @@ module BrDanfe
9
9
  @pdf = pdf
10
10
  @xml = xml
11
11
 
12
- @y_position = Y_POSITION
12
+ @y_position = Y_POSITION + EmitHeader.offset(@xml)
13
13
  @ltitle = @y_position - 0.42
14
14
  @l1 = @y_position
15
15
  @l2 = @y_position + LINE_HEIGHT
@@ -17,7 +17,7 @@ module BrDanfe
17
17
  @pdf = pdf
18
18
  @xml = xml
19
19
  @y_position = Entrega.delivery_local?(@xml) ? Transp::Y_POSITION + 3.00 : Transp::Y_POSITION
20
- @y_position += Icmstot.offset(@xml)
20
+ @y_position += EmitHeader.offset(@xml) + Icmstot.offset(@xml)
21
21
  end
22
22
 
23
23
  def render
@@ -28,6 +28,7 @@ module BrDanfe
28
28
  @xml = xml
29
29
 
30
30
  @y_position = Entrega.delivery_local?(@xml) ? Y_POSITION + 3.00 : Y_POSITION
31
+ @y_position += EmitHeader.offset(@xml)
31
32
 
32
33
  @ltitle = @y_position - 0.42
33
34
  @l1 = @y_position
@@ -40,7 +40,7 @@ module BrDanfe
40
40
 
41
41
  def position_below_the_tax_totals
42
42
  y_position = Entrega.delivery_local?(@xml) ? Transp::Y_POSITION + 3.00 : Transp::Y_POSITION
43
- y_position + Icmstot.offset(@xml) + Ibscbstot.offset(@xml)
43
+ y_position + EmitHeader.offset(@xml) + Icmstot.offset(@xml) + Ibscbstot.offset(@xml)
44
44
  end
45
45
  end
46
46
  end
@@ -10,7 +10,7 @@ module BrDanfe
10
10
  end
11
11
 
12
12
  def self.offset(xml)
13
- Icmstot.offset(xml) + Ibscbstot.offset(xml) + Issqn.offset(xml)
13
+ EmitHeader.offset(xml) + Icmstot.offset(xml) + Ibscbstot.offset(xml) + Issqn.offset(xml)
14
14
  end
15
15
 
16
16
  def self.issued_from_start_date?(xml)
@@ -1,3 +1,3 @@
1
1
  module BrDanfe
2
- VERSION = '3.2.0'.freeze
2
+ VERSION = '3.2.1'.freeze
3
3
  end
@@ -183,13 +183,16 @@ describe BrDanfe::DanfeLib::NfeLib::EmitHeader do
183
183
  let(:pdf_text) { PDF::Inspector::Text.analyze(pdf.render).strings.join("\n") }
184
184
  let(:issued_at) { '2026-12-02T10:00:00-03:00' }
185
185
  let(:crt) { '3' }
186
+ let(:ibscbs_regime) { '' }
186
187
  let(:xml_as_string) do
187
188
  <<~XML
188
189
  <nfeProc xmlns="http://www.portalfiscal.inf.br/nfe" versao="4.00">
189
190
  <NFe xmlns="http://www.portalfiscal.inf.br/nfe">
190
191
  <infNFe versao="4.00">
191
192
  <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
+ <emit>
194
+ <xNome>Nome do Remetente Ltda</xNome><CNPJ>62013294000143</CNPJ><CRT>#{crt}</CRT>#{ibscbs_regime}
195
+ </emit>
193
196
  </infNFe>
194
197
  </NFe>
195
198
  </nfeProc>
@@ -218,6 +221,42 @@ describe BrDanfe::DanfeLib::NfeLib::EmitHeader do
218
221
  it 'does not render the tax regime code' do
219
222
  expect(pdf_text).not_to include('CÓDIGO DO REGIME TRIBUTÁRIO')
220
223
  end
224
+
225
+ it 'does not render the IBS/CBS regime type' do
226
+ expect(pdf_text).not_to include('TIPO DE REGIME DE APURAÇÃO DO IBS E DA CBS')
227
+ end
228
+ end
229
+
230
+ context 'when the NF-e has the IBS/CBS regime type' do
231
+ let(:crt) { '1' }
232
+ let(:ibscbs_regime) { '<tpRegimeIBSCBS>1</tpRegimeIBSCBS>' }
233
+
234
+ it 'renders only the IBS/CBS regime type title' do
235
+ expect(pdf_text).to end_with('TIPO DE REGIME DE APURAÇÃO DO IBS E DA CBS')
236
+ end
237
+ end
238
+ end
239
+
240
+ describe '.offset' do
241
+ subject { described_class.offset(xml) }
242
+
243
+ let(:issued_at) { '2026-12-02T10:00:00-03:00' }
244
+ let(:xml_as_string) do
245
+ <<~XML
246
+ <NFe xmlns="http://www.portalfiscal.inf.br/nfe">
247
+ <infNFe versao="4.00"><ide><dhEmi>#{issued_at}</dhEmi></ide></infNFe>
248
+ </NFe>
249
+ XML
250
+ end
251
+
252
+ context 'when the NF-e uses the NT 2026.010 layout' do
253
+ it('is the tax regime line') { is_expected.to eql 0.8 }
254
+ end
255
+
256
+ context 'when the NF-e uses the current layout' do
257
+ let(:issued_at) { '2026-11-20T10:00:00-03:00' }
258
+
259
+ it('adds nothing') { is_expected.to eql 0.0 }
221
260
  end
222
261
  end
223
262
  end
@@ -145,18 +145,19 @@ describe BrDanfe::DanfeLib::NfeLib::Issqn do
145
145
  end
146
146
 
147
147
  let(:transporter_position) { 16.41 }
148
+ let(:tax_regime_line) { 0.8 }
148
149
  let(:ibscbs_block) { 1.32 }
149
150
 
150
151
  describe '#y_position' do
151
152
  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
+ expect(subject.y_position).to eql transporter_position + tax_regime_line + 0.0 + ibscbs_block
153
154
  end
154
155
 
155
156
  context 'with entrega' do
156
157
  let(:entrega) { '<entrega><xLgr>Rua Entrega</xLgr></entrega>' }
157
158
 
158
159
  it 'moves down with the delivery place' do
159
- expect(subject.y_position).to eql transporter_position + 3.0 + 0.0 + ibscbs_block
160
+ expect(subject.y_position).to eql transporter_position + 3.0 + tax_regime_line + 0.0 + ibscbs_block
160
161
  end
161
162
  end
162
163
 
@@ -99,8 +99,8 @@ describe BrDanfe::DanfeLib::NfeLib::RtcLayout do
99
99
  end
100
100
 
101
101
  context 'when the NF-e uses the new layout' do
102
- it 'is the FCP line plus the IBS/CBS/IS block and the space after it' do
103
- expect(subject).to eql line_height + line_height + space_between_blocks
102
+ it 'is the tax regime line, the FCP line, the IBS/CBS/IS block and the space after it' do
103
+ expect(subject).to eql line_height + line_height + (line_height + space_between_blocks)
104
104
  end
105
105
  end
106
106