Skip to content

Commit 97021eb

Browse files
authored
Fix and improve duplicates (#240)
1 parent f5b5d12 commit 97021eb

23 files changed

+344
-29
lines changed

config/locales/pt-BR.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ pt-BR:
5050
CNPJ: "CNPJ"
5151
dup:
5252
title: "FATURA / DUPLICATAS"
53-
nDup: "Núm.:"
54-
vDup: "Valor: R$"
55-
dVenc: "Venc.:"
53+
nDup: "NRO"
54+
vDup: "VALOR"
55+
dVenc: "VENCTO"
5656
ICMSTot:
5757
title: "CÁLCULO DO IMPOSTO"
5858
vBC: "BASE DE CÁLCULO DO ICMS"

lib/br_danfe/danfe_lib/nfe_lib/dup.rb

+31-18
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ class Dup
55
attr_reader :y_position
66

77
Y_POSITION = 12.92
8+
DUP_MAX_QUANTITY = 12
89

910
def initialize(pdf, xml)
1011
@pdf = pdf
@@ -16,28 +17,44 @@ def initialize(pdf, xml)
1617
end
1718

1819
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-
2220
x = 0.75
2321
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
2738
end
2839
end
2940

3041
private
3142

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
3853

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
4158
end
4259

4360
def dtduplicata(det)
@@ -48,10 +65,6 @@ def dtduplicata(det)
4865
def normal
4966
{ size: 6, border: 0 }
5067
end
51-
52-
def italic
53-
normal.merge(style: :italic)
54-
end
5568
end
5669
end
5770
end

lib/br_danfe/danfe_lib/nfe_lib/infadic.rb

+23-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def render(volumes_number)
1515
render_title
1616
render_subtitle
1717
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?
1919
render_reserved_fisco
2020
end
2121

@@ -44,6 +44,7 @@ def generate_additional_data
4444
additional_data.push(address_content) if address?
4545
additional_data.push(difal_content) if difal?
4646
additional_data.push(fisco_content) if fisco?
47+
additional_data.push(dup_content) if dup_content.any?
4748
additional_data.join(' * ')
4849
end
4950

@@ -89,6 +90,27 @@ def fisco?
8990
@xml['infAdic/infAdFisco'].to_s.present?
9091
end
9192

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+
92114
def generate_y_position(volumes_number)
93115
if volumes_number > 1
94116
return Y_POSITION + 0.30 + volumes_number * 0.15 + 0.2
@@ -97,10 +119,6 @@ def generate_y_position(volumes_number)
97119
Y_POSITION + 0.30
98120
end
99121

100-
def additional_data?
101-
complementary? || address? || difal? || fisco?
102-
end
103-
104122
def render_reserved_fisco
105123
@pdf.ibox 2.65, 7.15, 13.20, @y_position, I18n.t('danfe.infAdic.reserved')
106124
end

spec/br_danfe/danfe_lib/nfe_lib/dup_spec.rb

+53-3
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,67 @@
5656
<infNFe Id="NFe25111012345678901234550020000134151000134151" versao="2.00">
5757
<cobr>
5858
<dup>
59-
<nDup>1</nDup>
59+
<nDup>001</nDup>
6060
<dVenc>2015-02-13</dVenc>
6161
<vDup>25.56</vDup>
6262
</dup>
6363
<dup>
64-
<nDup>2</nDup>
64+
<nDup>002</nDup>
6565
<dVenc>2015-03-15</dVenc>
6666
<vDup>25.56</vDup>
6767
</dup>
6868
<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>
70120
<dVenc>2015-04-14</dVenc>
71121
<vDup>25.55</vDup>
72122
</dup>

0 commit comments

Comments
 (0)