br_danfe 1.2.1 → 1.2.2

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 (27) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/config/locales/pt-BR.yml +3 -3
  4. data/lib/br_danfe/danfe_lib/nfe_lib/dup.rb +31 -18
  5. data/lib/br_danfe/danfe_lib/nfe_lib/infadic.rb +23 -5
  6. data/lib/br_danfe/version.rb +1 -1
  7. data/spec/br_danfe/danfe_lib/nfe_lib/dup_spec.rb +53 -3
  8. data/spec/br_danfe/danfe_lib/nfe_lib/infadic_spec.rb +234 -0
  9. data/spec/fixtures/nfe/lib/dup#render-with_entrega.pdf +0 -0
  10. data/spec/fixtures/nfe/lib/dup#render.pdf +0 -0
  11. data/spec/fixtures/nfe/lib/infadic#render-all_the_informations.pdf +0 -0
  12. data/spec/fixtures/nfe/lib/infadic#render-with_dup_additional_information.pdf +0 -0
  13. data/spec/fixtures/nfe/lib/infadic#render-without_dup_additional_information.pdf +0 -0
  14. data/spec/fixtures/nfe/v2.00/custom_options.fixture.pdf +153 -187
  15. data/spec/fixtures/nfe/v2.00/nfe_simples_nacional.xml.fixture.pdf +147 -181
  16. data/spec/fixtures/nfe/v2.00/nfe_with_entrega.xml.fixture.pdf +147 -181
  17. data/spec/fixtures/nfe/v2.00/nfe_with_extra_volumes.xml.fixture.pdf +189 -70
  18. data/spec/fixtures/nfe/v2.00/nfe_with_fci.xml.fixture.pdf +173 -123
  19. data/spec/fixtures/nfe/v2.00/nfe_with_ns.xml.fixture.pdf +179 -129
  20. data/spec/fixtures/nfe/v2.00/nfe_without_ns.xml.fixture.pdf +163 -15
  21. data/spec/fixtures/nfe/v3.10/multiples.xmls.on.the.same.pdf.pdf +296 -204
  22. data/spec/fixtures/nfe/v3.10/nfe_simples_nacional.xml.fixture.pdf +160 -152
  23. data/spec/fixtures/nfe/v3.10/with_footer.fixture.pdf +166 -158
  24. data/spec/fixtures/nfe/v3.10/with_issqn.fixture.pdf +160 -152
  25. data/spec/fixtures/nfe/v3.10/with_three_pages.fixture.pdf +171 -163
  26. data/spec/fixtures/nfe/v3.10/without_issqn.fixture.pdf +166 -158
  27. metadata +4 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8a564780ad3f4ee8fe6abc916d5c1b58065df2f574261ffd20f56159b85c2a50
4
- data.tar.gz: 0aafe038db604d6ec0263e1636affe7ea38a1d6c14f390524c462e3e276ff091
3
+ metadata.gz: 28c418d7f4785e8fcc28658e76cb02822bfecb86f958a8d1bc167af5852000e1
4
+ data.tar.gz: 1e936227f6c1b3393b4e1bfafbda8577c23ab9aabde593694648bf965ea6b609
5
5
  SHA512:
6
- metadata.gz: 35f98999dfef6f51cc1ac60ffc926fa78c53b4bd48546dc530a6c966e5e1c2a0fcaededfeccf1bf73c73dddce7828826c2c93a0ff4d9639d8f60942241131eaa
7
- data.tar.gz: 1519c813f20632f5e5a8e826ee5c7ffa4840caf23a85d748a81f7145ce93c38261044c3890dc46d0c7ccb8a4cb1b677bc60f13b574a96493629c50422b2bfd53
6
+ metadata.gz: 6c4a931f688d5e4d65c3491d4ee35cb815589a1f1e9f4a01d946122b3cdfa54dcc8468885e8d70eb23797f7950e0cdce6adff668909252d257847f5b024e507e
7
+ data.tar.gz: 56aa6e7aab5fe64836d309ceb6d8748997dbd48cd4e4b3c38197c6da16f446f554c8c4ecb5766c4c4291460d3a24640def739c522ca502a43d9afc3861796741
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- br_danfe (1.2.1)
4
+ br_danfe (1.2.2)
5
5
  barby (= 0.6.9)
6
6
  br_documents (>= 0.1.3)
7
7
  i18n (>= 0.8.6)
@@ -50,9 +50,9 @@ pt-BR:
50
50
  CNPJ: "CNPJ"
51
51
  dup:
52
52
  title: "FATURA / DUPLICATAS"
53
- nDup: "Núm.:"
54
- vDup: "Valor: R$"
55
- dVenc: "Venc.:"
53
+ nDup: "NRO"
54
+ vDup: "VALOR"
55
+ dVenc: "VENCTO"
56
56
  ICMSTot:
57
57
  title: "CÁLCULO DO IMPOSTO"
58
58
  vBC: "BASE DE CÁLCULO DO ICMS"
@@ -5,6 +5,7 @@ module BrDanfe
5
5
  attr_reader :y_position
6
6
 
7
7
  Y_POSITION = 12.92
8
+ DUP_MAX_QUANTITY = 12
8
9
 
9
10
  def initialize(pdf, xml)
10
11
  @pdf = pdf
@@ -16,28 +17,44 @@ module BrDanfe
16
17
  end
17
18
 
18
19
  def render
19
- @pdf.ititle 0.42, 10.00, 0.75, @ltitle, 'dup.title'
20
- @pdf.ibox 0.85, 19.57, 0.75, @y_position
21
-
22
20
  x = 0.75
23
21
  y = @y_position
24
- @xml.collect('xmlns', 'dup') do |det|
25
- render_dup(det, x, y)
26
- x += 2.30
22
+
23
+ @pdf.ititle 0.42, 10.00, x, @ltitle, 'dup.title'
24
+
25
+ render_titles_and_box(x, y)
26
+
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
29
+
30
+ y = if index < DUP_MAX_QUANTITY / 2
31
+ @y_position - 0.015
32
+ else
33
+ @y_position + 0.185
34
+ end
35
+
36
+ render_dup(det, x, y + 0.3)
37
+ x += 3.261666667
27
38
  end
28
39
  end
29
40
 
30
41
  private
31
42
 
32
- def render_dup(det, x, y)
33
- @pdf.ibox 0.85, 2.12, x, y, '', I18n.t('danfe.dup.nDup'), italic
34
- @pdf.ibox 0.85, 2.12, x + 0.70, y, '', det.css('nDup').text, normal
35
- @pdf.ibox 0.85, 2.12, x, y + 0.20, '', I18n.t('danfe.dup.dVenc'), italic
36
-
37
- @pdf.ibox 0.85, 2.12, x + 0.70, y + 0.20, '', dtduplicata(det), normal
43
+ 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
51
+ end
52
+ end
38
53
 
39
- @pdf.ibox 0.85, 2.12, x, y + 0.40, '', I18n.t('danfe.dup.vDup'), italic
40
- @pdf.inumeric 0.85, 1.25, x + 0.70, y + 0.40, '', det.css('vDup').text, normal
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
41
58
  end
42
59
 
43
60
  def dtduplicata(det)
@@ -48,10 +65,6 @@ module BrDanfe
48
65
  def normal
49
66
  { size: 6, border: 0 }
50
67
  end
51
-
52
- def italic
53
- normal.merge(style: :italic)
54
- end
55
68
  end
56
69
  end
57
70
  end
@@ -15,7 +15,7 @@ module BrDanfe
15
15
  render_title
16
16
  render_subtitle
17
17
  render_volumes if volumes_number > 1
18
- render_additional_data generate_y_position(volumes_number) if additional_data?
18
+ render_additional_data generate_y_position(volumes_number) if complementary? || address? || difal? || fisco? || dup_content.to_s.present?
19
19
  render_reserved_fisco
20
20
  end
21
21
 
@@ -44,6 +44,7 @@ module BrDanfe
44
44
  additional_data.push(address_content) if address?
45
45
  additional_data.push(difal_content) if difal?
46
46
  additional_data.push(fisco_content) if fisco?
47
+ additional_data.push(dup_content) if dup_content.any?
47
48
  additional_data.join(' * ')
48
49
  end
49
50
 
@@ -89,6 +90,27 @@ module BrDanfe
89
90
  @xml['infAdic/infAdFisco'].to_s.present?
90
91
  end
91
92
 
93
+ def format_dup_date(_det, dup_date)
94
+ dtduplicata = dup_date
95
+ "#{dtduplicata[8, 2]}/#{dtduplicata[5, 2]}/#{dtduplicata[0, 4]}"
96
+ end
97
+
98
+ def dup_content
99
+ value_dups = []
100
+
101
+ @xml.collect('xmlns', 'dup') { _1 }[NfeLib::Dup::DUP_MAX_QUANTITY..]&.each_with_index do |det, index|
102
+ value = "#{det.css('nDup').text} - #{format_dup_date(det, det.css('dVenc').text)} - R$ #{BrDanfe::Helper.numerify(det.css('vDup').text.to_f)}"
103
+
104
+ if index.zero?
105
+ value_dups.push("Faturas: #{value}")
106
+ elsif index.positive?
107
+ value_dups.push(value.to_s)
108
+ end
109
+ end
110
+
111
+ value_dups
112
+ end
113
+
92
114
  def generate_y_position(volumes_number)
93
115
  if volumes_number > 1
94
116
  return Y_POSITION + 0.30 + volumes_number * 0.15 + 0.2
@@ -97,10 +119,6 @@ module BrDanfe
97
119
  Y_POSITION + 0.30
98
120
  end
99
121
 
100
- def additional_data?
101
- complementary? || address? || difal? || fisco?
102
- end
103
-
104
122
  def render_reserved_fisco
105
123
  @pdf.ibox 2.65, 7.15, 13.20, @y_position, I18n.t('danfe.infAdic.reserved')
106
124
  end
@@ -1,3 +1,3 @@
1
1
  module BrDanfe
2
- VERSION = '1.2.1'.freeze
2
+ VERSION = '1.2.2'.freeze
3
3
  end
@@ -56,17 +56,67 @@ describe BrDanfe::DanfeLib::NfeLib::Dup do
56
56
  <infNFe Id="NFe25111012345678901234550020000134151000134151" versao="2.00">
57
57
  <cobr>
58
58
  <dup>
59
- <nDup>1</nDup>
59
+ <nDup>001</nDup>
60
60
  <dVenc>2015-02-13</dVenc>
61
61
  <vDup>25.56</vDup>
62
62
  </dup>
63
63
  <dup>
64
- <nDup>2</nDup>
64
+ <nDup>002</nDup>
65
65
  <dVenc>2015-03-15</dVenc>
66
66
  <vDup>25.56</vDup>
67
67
  </dup>
68
68
  <dup>
69
- <nDup>3</nDup>
69
+ <nDup>003</nDup>
70
+ <dVenc>2015-04-14</dVenc>
71
+ <vDup>25.55</vDup>
72
+ </dup>
73
+ <dup>
74
+ <nDup>004</nDup>
75
+ <dVenc>2015-02-13</dVenc>
76
+ <vDup>25.56</vDup>
77
+ </dup>
78
+ <dup>
79
+ <nDup>005</nDup>
80
+ <dVenc>2015-03-15</dVenc>
81
+ <vDup>25.56</vDup>
82
+ </dup>
83
+ <dup>
84
+ <nDup>006</nDup>
85
+ <dVenc>2015-04-14</dVenc>
86
+ <vDup>25.55</vDup>
87
+ </dup>
88
+ <dup>
89
+ <nDup>007</nDup>
90
+ <dVenc>2015-02-13</dVenc>
91
+ <vDup>25.56</vDup>
92
+ </dup>
93
+ <dup>
94
+ <nDup>008</nDup>
95
+ <dVenc>2015-03-15</dVenc>
96
+ <vDup>25.56</vDup>
97
+ </dup>
98
+ <dup>
99
+ <nDup>009</nDup>
100
+ <dVenc>2015-04-14</dVenc>
101
+ <vDup>25.55</vDup>
102
+ </dup>
103
+ <dup>
104
+ <nDup>010</nDup>
105
+ <dVenc>2015-02-13</dVenc>
106
+ <vDup>25.56</vDup>
107
+ </dup>
108
+ <dup>
109
+ <nDup>011</nDup>
110
+ <dVenc>2015-03-15</dVenc>
111
+ <vDup>25.56</vDup>
112
+ </dup>
113
+ <dup>
114
+ <nDup>012</nDup>
115
+ <dVenc>2015-04-14</dVenc>
116
+ <vDup>25.55</vDup>
117
+ </dup>
118
+ <dup>
119
+ <nDup>013</nDup>
70
120
  <dVenc>2015-04-14</dVenc>
71
121
  <vDup>25.55</vDup>
72
122
  </dup>
@@ -262,6 +262,168 @@ describe BrDanfe::DanfeLib::NfeLib::Infadic do
262
262
  end
263
263
  end
264
264
 
265
+ context 'when has too much dups' do
266
+ let(:xml_as_string) do
267
+ <<~XML
268
+ <NFe xmlns="http://www.portalfiscal.inf.br/nfe">
269
+ <infNFe Id="NFe25111012345678901234550020000134151000134151" versao="2.00">
270
+ <cobr>
271
+ <dup>
272
+ <nDup>001</nDup>
273
+ <dVenc>2015-02-13</dVenc>
274
+ <vDup>25.56</vDup>
275
+ </dup>
276
+ <dup>
277
+ <nDup>002</nDup>
278
+ <dVenc>2015-03-15</dVenc>
279
+ <vDup>25.56</vDup>
280
+ </dup>
281
+ <dup>
282
+ <nDup>003</nDup>
283
+ <dVenc>2015-04-14</dVenc>
284
+ <vDup>25.55</vDup>
285
+ </dup>
286
+ <dup>
287
+ <nDup>004</nDup>
288
+ <dVenc>2015-04-14</dVenc>
289
+ <vDup>25.55</vDup>
290
+ </dup>
291
+ <dup>
292
+ <nDup>005</nDup>
293
+ <dVenc>2015-02-13</dVenc>
294
+ <vDup>25.56</vDup>
295
+ </dup>
296
+ <dup>
297
+ <nDup>006</nDup>
298
+ <dVenc>2015-03-15</dVenc>
299
+ <vDup>25.56</vDup>
300
+ </dup>
301
+ <dup>
302
+ <nDup>007</nDup>
303
+ <dVenc>2015-04-14</dVenc>
304
+ <vDup>25.55</vDup>
305
+ </dup>
306
+ <dup>
307
+ <nDup>008</nDup>
308
+ <dVenc>2015-04-14</dVenc>
309
+ <vDup>25.55</vDup>
310
+ </dup>
311
+ <dup>
312
+ <nDup>009</nDup>
313
+ <dVenc>2015-02-13</dVenc>
314
+ <vDup>25.56</vDup>
315
+ </dup>
316
+ <dup>
317
+ <nDup>010</nDup>
318
+ <dVenc>2015-03-15</dVenc>
319
+ <vDup>25.56</vDup>
320
+ </dup>
321
+ <dup>
322
+ <nDup>011</nDup>
323
+ <dVenc>2015-04-14</dVenc>
324
+ <vDup>25.55</vDup>
325
+ </dup>
326
+ <dup>
327
+ <nDup>012</nDup>
328
+ <dVenc>2015-04-14</dVenc>
329
+ <vDup>25.55</vDup>
330
+ </dup>
331
+ <dup>
332
+ <nDup>013</nDup>
333
+ <dVenc>2015-04-14</dVenc>
334
+ <vDup>25.55</vDup>
335
+ </dup>
336
+ <dup>
337
+ <nDup>014</nDup>
338
+ <dVenc>2015-04-14</dVenc>
339
+ <vDup>25.55</vDup>
340
+ </dup>
341
+ </cobr>
342
+ </infNFe>
343
+ </NFe>
344
+ XML
345
+ end
346
+
347
+ it 'renders title with box, subtitle, dup box and additional information about dup on the pdf' do
348
+ expect(File.exist?(output_pdf)).to be_falsey
349
+
350
+ pdf.render_file output_pdf
351
+
352
+ expect("#{base_dir}infadic#render-with_dup_additional_information.pdf").to have_same_content_of file: output_pdf
353
+ end
354
+ end
355
+
356
+ context 'when has less than NfeLib::Dup::DUP_MAX_QUANTITY dups' do
357
+ let(:xml_as_string) do
358
+ <<~XML
359
+ <NFe xmlns="http://www.portalfiscal.inf.br/nfe">
360
+ <infNFe Id="NFe25111012345678901234550020000134151000134151" versao="2.00">
361
+ <cobr>
362
+ <dup>
363
+ <nDup>001</nDup>
364
+ <dVenc>2015-02-13</dVenc>
365
+ <vDup>25.56</vDup>
366
+ </dup>
367
+ <dup>
368
+ <nDup>002</nDup>
369
+ <dVenc>2015-03-15</dVenc>
370
+ <vDup>25.56</vDup>
371
+ </dup>
372
+ <dup>
373
+ <nDup>003</nDup>
374
+ <dVenc>2015-04-14</dVenc>
375
+ <vDup>25.55</vDup>
376
+ </dup>
377
+ <dup>
378
+ <nDup>004</nDup>
379
+ <dVenc>2015-04-14</dVenc>
380
+ <vDup>25.55</vDup>
381
+ </dup>
382
+ <dup>
383
+ <nDup>005</nDup>
384
+ <dVenc>2015-02-13</dVenc>
385
+ <vDup>25.56</vDup>
386
+ </dup>
387
+ <dup>
388
+ <nDup>006</nDup>
389
+ <dVenc>2015-03-15</dVenc>
390
+ <vDup>25.56</vDup>
391
+ </dup>
392
+ <dup>
393
+ <nDup>007</nDup>
394
+ <dVenc>2015-04-14</dVenc>
395
+ <vDup>25.55</vDup>
396
+ </dup>
397
+ <dup>
398
+ <nDup>008</nDup>
399
+ <dVenc>2015-04-14</dVenc>
400
+ <vDup>25.55</vDup>
401
+ </dup>
402
+ <dup>
403
+ <nDup>009</nDup>
404
+ <dVenc>2015-02-13</dVenc>
405
+ <vDup>25.56</vDup>
406
+ </dup>
407
+ <dup>
408
+ <nDup>010</nDup>
409
+ <dVenc>2015-03-15</dVenc>
410
+ <vDup>25.56</vDup>
411
+ </dup>
412
+ </cobr>
413
+ </infNFe>
414
+ </NFe>
415
+ XML
416
+ end
417
+
418
+ it 'renders title with box, subtitle and additional information without dup on the pdf' do
419
+ expect(File.exist?(output_pdf)).to be_falsey
420
+
421
+ pdf.render_file output_pdf
422
+
423
+ expect("#{base_dir}infadic#render-without_dup_additional_information.pdf").to have_same_content_of file: output_pdf
424
+ end
425
+ end
426
+
265
427
  context 'when has extra volume' do
266
428
  let(:xml_as_string) do
267
429
  <<~XML
@@ -388,6 +550,78 @@ describe BrDanfe::DanfeLib::NfeLib::Infadic do
388
550
  <pesoB>3300.000</pesoB>
389
551
  </vol>
390
552
  </transp>
553
+ <cobr>
554
+ <dup>
555
+ <nDup>001</nDup>
556
+ <dVenc>2015-02-13</dVenc>
557
+ <vDup>25.56</vDup>
558
+ </dup>
559
+ <dup>
560
+ <nDup>002</nDup>
561
+ <dVenc>2015-03-15</dVenc>
562
+ <vDup>25.56</vDup>
563
+ </dup>
564
+ <dup>
565
+ <nDup>003</nDup>
566
+ <dVenc>2015-04-14</dVenc>
567
+ <vDup>25.55</vDup>
568
+ </dup>
569
+ <dup>
570
+ <nDup>004</nDup>
571
+ <dVenc>2015-04-14</dVenc>
572
+ <vDup>25.55</vDup>
573
+ </dup>
574
+ <dup>
575
+ <nDup>005</nDup>
576
+ <dVenc>2015-02-13</dVenc>
577
+ <vDup>25.56</vDup>
578
+ </dup>
579
+ <dup>
580
+ <nDup>006</nDup>
581
+ <dVenc>2015-03-15</dVenc>
582
+ <vDup>25.56</vDup>
583
+ </dup>
584
+ <dup>
585
+ <nDup>007</nDup>
586
+ <dVenc>2015-04-14</dVenc>
587
+ <vDup>25.55</vDup>
588
+ </dup>
589
+ <dup>
590
+ <nDup>008</nDup>
591
+ <dVenc>2015-04-14</dVenc>
592
+ <vDup>25.55</vDup>
593
+ </dup>
594
+ <dup>
595
+ <nDup>009</nDup>
596
+ <dVenc>2015-02-13</dVenc>
597
+ <vDup>25.56</vDup>
598
+ </dup>
599
+ <dup>
600
+ <nDup>010</nDup>
601
+ <dVenc>2015-03-15</dVenc>
602
+ <vDup>25.56</vDup>
603
+ </dup>
604
+ <dup>
605
+ <nDup>011</nDup>
606
+ <dVenc>2015-04-14</dVenc>
607
+ <vDup>25.55</vDup>
608
+ </dup>
609
+ <dup>
610
+ <nDup>012</nDup>
611
+ <dVenc>2015-04-14</dVenc>
612
+ <vDup>25.55</vDup>
613
+ </dup>
614
+ <dup>
615
+ <nDup>013</nDup>
616
+ <dVenc>2015-04-14</dVenc>
617
+ <vDup>25.55</vDup>
618
+ </dup>
619
+ <dup>
620
+ <nDup>014</nDup>
621
+ <dVenc>2015-04-14</dVenc>
622
+ <vDup>25.55</vDup>
623
+ </dup>
624
+ </cobr>
391
625
  <infAdic>
392
626
  <infCpl>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec congue in dolor sed sagittis.</infCpl>
393
627
  <infAdFisco>Total de FCP-ST: 348,96</infAdFisco>
Binary file