br_danfe 0.7.0 → 0.7.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.
@@ -0,0 +1,271 @@
1
+ %PDF-1.3
2
+ %����
3
+ 1 0 obj
4
+ << /Creator <feff0050007200610077006e>
5
+ /Producer <feff0050007200610077006e>
6
+ >>
7
+ endobj
8
+ 2 0 obj
9
+ << /Type /Catalog
10
+ /Pages 3 0 R
11
+ >>
12
+ endobj
13
+ 3 0 obj
14
+ << /Type /Pages
15
+ /Count 1
16
+ /Kids [5 0 R]
17
+ >>
18
+ endobj
19
+ 4 0 obj
20
+ << /Length 2421
21
+ >>
22
+ stream
23
+ q
24
+ 0.3 w
25
+
26
+ BT
27
+ 21.2598 596.8667 Td
28
+ /F2.0 8 Tf
29
+ [<44455354494e> 20 <41> 95 <54> 90 <c152494f202f2052454d4554454e5445>] TJ
30
+ ET
31
+
32
+ 21.2598 571.748 335.0551 22.6772 re
33
+ S
34
+
35
+ BT
36
+ 23.2598 588.3272 Td
37
+ /F1.0 6 Tf
38
+ [<4e4f4d452f52415ac3> 55 <4f20534f4349414c>] TJ
39
+ ET
40
+
41
+
42
+ BT
43
+ 23.2598 574.5952 Td
44
+ /F1.0 10 Tf
45
+ [<5363686e656964657220456c6563747269632042726173696c204c746461>] TJ
46
+ ET
47
+
48
+ 356.315 571.748 123.874 22.6772 re
49
+ S
50
+
51
+ BT
52
+ 358.315 588.3272 Td
53
+ /F1.0 6 Tf
54
+ [<434e504a2f435046>] TJ
55
+ ET
56
+
57
+
58
+ BT
59
+ 358.315 574.5952 Td
60
+ /F1.0 10 Tf
61
+ [<38322e3734332e3238372f303030382d3830>] TJ
62
+ ET
63
+
64
+ 21.2598 549.0709 273.8268 22.6772 re
65
+ S
66
+
67
+ BT
68
+ 23.2598 565.65 Td
69
+ /F1.0 6 Tf
70
+ [<454e44455245c74f>] TJ
71
+ ET
72
+
73
+
74
+ BT
75
+ 23.2598 551.918 Td
76
+ /F1.0 10 Tf
77
+ [<41> 74 <7620646120536175646164652031313235>] TJ
78
+ ET
79
+
80
+ 295.0866 549.0709 122.7402 22.6772 re
81
+ S
82
+
83
+ BT
84
+ 297.0866 565.65 Td
85
+ /F1.0 6 Tf
86
+ [<42> 35 <41495252> 40 <4f>] TJ
87
+ ET
88
+
89
+
90
+ BT
91
+ 297.0866 551.918 Td
92
+ /F1.0 10 Tf
93
+ [<46727574616c>] TJ
94
+ ET
95
+
96
+ 417.8268 549.0709 62.3622 22.6772 re
97
+ S
98
+
99
+ BT
100
+ 419.8268 565.65 Td
101
+ /F1.0 6 Tf
102
+ [<434550>] TJ
103
+ ET
104
+
105
+
106
+ BT
107
+ 419.8268 551.918 Td
108
+ /F1.0 10 Tf
109
+ [<31332e3137312d333230>] TJ
110
+ ET
111
+
112
+ 21.2598 526.3937 187.3701 22.6772 re
113
+ S
114
+
115
+ BT
116
+ 23.2598 542.9729 Td
117
+ /F1.0 6 Tf
118
+ [<4d554e4943cd50494f>] TJ
119
+ ET
120
+
121
+
122
+ BT
123
+ 23.2598 529.2409 Td
124
+ /F1.0 10 Tf
125
+ [<53554d415245>] TJ
126
+ ET
127
+
128
+ 208.6299 526.3937 115.0866 22.6772 re
129
+ S
130
+
131
+ BT
132
+ 210.6299 542.9729 Td
133
+ /F1.0 6 Tf
134
+ [<464f4e452f46> 74 <4158>] TJ
135
+ ET
136
+
137
+
138
+ BT
139
+ 210.6299 529.2409 Td
140
+ /F1.0 10 Tf
141
+ [<2831392920323130342d36333030>] TJ
142
+ ET
143
+
144
+ 323.7165 526.3937 32.315 22.6772 re
145
+ S
146
+
147
+ BT
148
+ 325.7165 542.9729 Td
149
+ /F1.0 6 Tf
150
+ [<5546>] TJ
151
+ ET
152
+
153
+
154
+ BT
155
+ 325.7165 529.2409 Td
156
+ /F1.0 10 Tf
157
+ [<5350>] TJ
158
+ ET
159
+
160
+ 356.0315 526.3937 124.1575 22.6772 re
161
+ S
162
+
163
+ BT
164
+ 358.0315 542.9729 Td
165
+ /F1.0 6 Tf
166
+ [<494e53435249c7c3> 55 <4f20455354> 93 <414455> 40 <414c>] TJ
167
+ ET
168
+
169
+
170
+ BT
171
+ 358.0315 529.2409 Td
172
+ /F1.0 10 Tf
173
+ [<3637312e3030382e3337352e313130>] TJ
174
+ ET
175
+
176
+ 493.2283 571.748 82.7717 22.6772 re
177
+ S
178
+
179
+ BT
180
+ 495.2283 588.3272 Td
181
+ /F1.0 6 Tf
182
+ [<44> 40 <41> 111 <54> 93 <412044> 40 <4120454d495353c3> 55 <4f>] TJ
183
+ ET
184
+
185
+
186
+ BT
187
+ 528.44 574.5952 Td
188
+ /F1.0 10 Tf
189
+ [<32392f31302f32303131>] TJ
190
+ ET
191
+
192
+ 493.2283 549.0709 82.7717 22.6772 re
193
+ S
194
+
195
+ BT
196
+ 495.2283 565.65 Td
197
+ /F1.0 6 Tf
198
+ [<44> 40 <41> 111 <54> 93 <412044> 40 <4120454e54524144> 40 <412f5341cd44> 40 <41>] TJ
199
+ ET
200
+
201
+
202
+ BT
203
+ 528.44 551.918 Td
204
+ /F1.0 10 Tf
205
+ [<33302f31302f32303131>] TJ
206
+ ET
207
+
208
+ 493.2283 526.3937 82.7717 22.6772 re
209
+ S
210
+
211
+ BT
212
+ 495.2283 542.9729 Td
213
+ /F1.0 6 Tf
214
+ [<484f524120444520454e54524144> 40 <412f5341cd44> 40 <41>] TJ
215
+ ET
216
+
217
+
218
+ BT
219
+ 538.44 529.2409 Td
220
+ /F1.0 10 Tf
221
+ [<31333a33323a3435>] TJ
222
+ ET
223
+
224
+ Q
225
+
226
+ endstream
227
+ endobj
228
+ 5 0 obj
229
+ << /Type /Page
230
+ /Parent 3 0 R
231
+ /MediaBox [0 0 595.28 841.89]
232
+ /Contents 4 0 R
233
+ /Resources << /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]
234
+ /Font << /F2.0 6 0 R
235
+ /F1.0 7 0 R
236
+ >>
237
+ >>
238
+ >>
239
+ endobj
240
+ 6 0 obj
241
+ << /Type /Font
242
+ /Subtype /Type1
243
+ /BaseFont /Times-Bold
244
+ /Encoding /WinAnsiEncoding
245
+ >>
246
+ endobj
247
+ 7 0 obj
248
+ << /Type /Font
249
+ /Subtype /Type1
250
+ /BaseFont /Times-Roman
251
+ /Encoding /WinAnsiEncoding
252
+ >>
253
+ endobj
254
+ xref
255
+ 0 8
256
+ 0000000000 65535 f
257
+ 0000000015 00000 n
258
+ 0000000109 00000 n
259
+ 0000000158 00000 n
260
+ 0000000215 00000 n
261
+ 0000002688 00000 n
262
+ 0000002880 00000 n
263
+ 0000002978 00000 n
264
+ trailer
265
+ << /Size 8
266
+ /Root 2 0 R
267
+ /Info 1 0 R
268
+ >>
269
+ startxref
270
+ 3077
271
+ %%EOF
@@ -0,0 +1,104 @@
1
+ %PDF-1.3
2
+ %����
3
+ 1 0 obj
4
+ << /Creator <feff0050007200610077006e>
5
+ /Producer <feff0050007200610077006e>
6
+ >>
7
+ endobj
8
+ 2 0 obj
9
+ << /Type /Catalog
10
+ /Pages 3 0 R
11
+ >>
12
+ endobj
13
+ 3 0 obj
14
+ << /Type /Pages
15
+ /Count 1
16
+ /Kids [5 0 R]
17
+ >>
18
+ endobj
19
+ 4 0 obj
20
+ << /Length 631
21
+ >>
22
+ stream
23
+ q
24
+ 0.3 w
25
+
26
+ BT
27
+ 21.2598 98.8195 Td
28
+ /F2.0 8 Tf
29
+ [<44> 35 <41444f532041444943494f4e> 20 <414953>] TJ
30
+ ET
31
+
32
+ 21.2598 21.5433 352.9134 75.1181 re
33
+ S
34
+
35
+ BT
36
+ 23.2598 90.5634 Td
37
+ /F1.0 6 Tf
38
+ [<494e464f524d41> 40 <c7d5455320434f4d504c454d454e54> 93 <41524553>] TJ
39
+ ET
40
+
41
+
42
+ BT
43
+ 23.2598 79.5634 Td
44
+ /F1.0 6 Tf
45
+ [<556d61206f6273657276> 25 <61e7e36f202a20456e64657265e76f3a2041> 74 <7620646120536175646164652031313235202d20456d20616e65> 15 <786f20616f207375706572206d65726361646f206d61696f7220646f2062616972726f>] TJ
46
+ ET
47
+
48
+ 374.1732 21.5433 202.6772 75.1181 re
49
+ S
50
+
51
+ BT
52
+ 376.1732 90.5634 Td
53
+ /F1.0 6 Tf
54
+ [<5245534552> 80 <56> 135 <41444f2041> 55 <4f20464953434f>] TJ
55
+ ET
56
+
57
+ Q
58
+
59
+ endstream
60
+ endobj
61
+ 5 0 obj
62
+ << /Type /Page
63
+ /Parent 3 0 R
64
+ /MediaBox [0 0 595.28 841.89]
65
+ /Contents 4 0 R
66
+ /Resources << /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]
67
+ /Font << /F2.0 6 0 R
68
+ /F1.0 7 0 R
69
+ >>
70
+ >>
71
+ >>
72
+ endobj
73
+ 6 0 obj
74
+ << /Type /Font
75
+ /Subtype /Type1
76
+ /BaseFont /Times-Bold
77
+ /Encoding /WinAnsiEncoding
78
+ >>
79
+ endobj
80
+ 7 0 obj
81
+ << /Type /Font
82
+ /Subtype /Type1
83
+ /BaseFont /Times-Roman
84
+ /Encoding /WinAnsiEncoding
85
+ >>
86
+ endobj
87
+ xref
88
+ 0 8
89
+ 0000000000 65535 f
90
+ 0000000015 00000 n
91
+ 0000000109 00000 n
92
+ 0000000158 00000 n
93
+ 0000000215 00000 n
94
+ 0000000897 00000 n
95
+ 0000001089 00000 n
96
+ 0000001187 00000 n
97
+ trailer
98
+ << /Size 8
99
+ /Root 2 0 R
100
+ /Info 1 0 R
101
+ >>
102
+ startxref
103
+ 1286
104
+ %%EOF
@@ -1,7 +1,7 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe BrDanfe::DanfeLib::Dest do
4
- let(:base_dir) { "./spec/fixtures/nfe/lib/"}
4
+ let(:base_dir) { "./spec/fixtures/nfe/lib/" }
5
5
  let(:output_pdf) { "#{base_dir}output.pdf" }
6
6
 
7
7
  let(:pdf) { BrDanfe::DanfeLib::Document.new }
@@ -32,6 +32,7 @@ describe BrDanfe::DanfeLib::Dest do
32
32
  <xLgr>Av da Saudade</xLgr>
33
33
  <nro>1125</nro>
34
34
  <xBairro>Frutal</xBairro>
35
+ <xCpl>Sala 01 e 02</xCpl>
35
36
  <cMun>3552403</cMun>
36
37
  <xMun>SUMARE</xMun>
37
38
  <UF>SP</UF>
@@ -72,6 +73,7 @@ describe BrDanfe::DanfeLib::Dest do
72
73
  <xLgr>Av da Saudade</xLgr>
73
74
  <nro>1125</nro>
74
75
  <xBairro>Frutal</xBairro>
76
+ <xCpl>Sala 01 e 02</xCpl>
75
77
  <cMun>3552403</cMun>
76
78
  <xMun>SUMARE</xMun>
77
79
  <UF>SP</UF>
@@ -164,5 +166,86 @@ describe BrDanfe::DanfeLib::Dest do
164
166
  expect("#{base_dir}dest#render-with_ie.pdf").to have_same_content_of file: output_pdf
165
167
  end
166
168
  end
169
+
170
+ context "when recipient doesn't have address complement" do
171
+ let(:xml_as_string) do
172
+ <<-eos
173
+ <NFe xmlns="http://www.portalfiscal.inf.br/nfe">
174
+ <infNFe Id="NFe25111012345678901234550020000134151000134151" versao="3.10">
175
+ <ide>
176
+ <dhEmi>2011-10-29T13:02:59+00:00</dhEmi>
177
+ <dhSaiEnt>2011-10-30T12:32:45-03:00</dhSaiEnt>
178
+ </ide>
179
+ <dest>
180
+ <CNPJ>82743287000880</CNPJ>
181
+ <xNome>Schneider Electric Brasil Ltda</xNome>
182
+ <enderDest>
183
+ <xLgr>Av da Saudade</xLgr>
184
+ <nro>1125</nro>
185
+ <xBairro>Frutal</xBairro>
186
+ <cMun>3552403</cMun>
187
+ <xMun>SUMARE</xMun>
188
+ <UF>SP</UF>
189
+ <CEP>13171320</CEP>
190
+ <cPais>1058</cPais>
191
+ <xPais>BRASIL</xPais>
192
+ <fone>1921046300</fone>
193
+ </enderDest>
194
+ <IE>671008375110</IE>
195
+ </dest>
196
+ </infNFe>
197
+ </NFe>
198
+ eos
199
+ end
200
+
201
+ it "renders xml to the pdf" do
202
+ expect(File.exist?(output_pdf)).to be_falsey
203
+
204
+ pdf.render_file output_pdf
205
+
206
+ expect("#{base_dir}dest#render-without-address-complement.pdf").to have_same_content_of file: output_pdf
207
+ end
208
+ end
209
+
210
+ context "when recipient address (xLgr + nro + xCpl) has more than 63 characters" do
211
+ let(:xml_as_string) do
212
+ <<-eos
213
+ <NFe xmlns="http://www.portalfiscal.inf.br/nfe">
214
+ <infNFe Id="NFe25111012345678901234550020000134151000134151" versao="3.10">
215
+ <ide>
216
+ <dhEmi>2011-10-29T13:02:59+00:00</dhEmi>
217
+ <dhSaiEnt>2011-10-30T12:32:45-03:00</dhSaiEnt>
218
+ </ide>
219
+ <dest>
220
+ <CNPJ>82743287000880</CNPJ>
221
+ <xNome>Schneider Electric Brasil Ltda</xNome>
222
+ <enderDest>
223
+ <xLgr>Rua do governo do estado</xLgr>
224
+ <nro>1125</nro>
225
+ <xCpl>Em anexo ao super mercado maior do bairro</xCpl>
226
+ <xBairro>Frutal</xBairro>
227
+ <cMun>3552403</cMun>
228
+ <xMun>SUMARE</xMun>
229
+ <UF>SP</UF>
230
+ <CEP>13171320</CEP>
231
+ <cPais>1058</cPais>
232
+ <xPais>BRASIL</xPais>
233
+ <fone>1921046300</fone>
234
+ </enderDest>
235
+ <IE>671008375110</IE>
236
+ </dest>
237
+ </infNFe>
238
+ </NFe>
239
+ eos
240
+ end
241
+
242
+ it "it renders xml to pdf trimming the address of after 63 characters" do
243
+ expect(File.exist?(output_pdf)).to be_falsey
244
+
245
+ pdf.render_file output_pdf
246
+
247
+ expect("#{base_dir}dest#render-with-address-bigger.pdf").to have_same_content_of file: output_pdf
248
+ end
249
+ end
167
250
  end
168
251
  end
@@ -167,4 +167,96 @@ describe BrDanfe::DanfeLib::Helper do
167
167
  end
168
168
  end
169
169
  end
170
+
171
+ describe ".address_is_too_big" do
172
+ let(:pdf) { BrDanfe::DanfeLib::Document.new }
173
+
174
+ context "when the address is too big for the street field at DANFE" do
175
+ let(:address) { "Rua do governo do estado 1125 - Em anexo ao super mercado maior do bairro" }
176
+
177
+ it "returns true" do
178
+ expect(BrDanfe::DanfeLib::Helper.address_is_too_big(pdf, address)).to be true
179
+ end
180
+ end
181
+
182
+ context "when the address fits in the street field in DANFE" do
183
+ let(:address) { "Rua do governo do estado 1125 - Salas 1 e 2" }
184
+
185
+ it "returns false" do
186
+ expect(BrDanfe::DanfeLib::Helper.address_is_too_big(pdf, address)).to be false
187
+ end
188
+ end
189
+ end
190
+
191
+ describe ".generate_address" do
192
+ let(:xml) do
193
+ <<-eos
194
+ <enderDest>
195
+ <xLgr>Rua do governo do estado</xLgr>
196
+ <nro>1125</nro>
197
+ <xCpl>Em anexo ao super mercado maior do bairro</xCpl>
198
+ </enderDest>
199
+ eos
200
+ end
201
+
202
+ let(:xml_street) do
203
+ Nokogiri::XML(xml)
204
+ end
205
+
206
+ it "returns the address with the street, number and complement" do
207
+ expect(BrDanfe::DanfeLib::Helper.generate_address(xml_street))
208
+ .to eq "Rua do governo do estado 1125 - Em anexo ao super mercado maior do bairro"
209
+ end
210
+
211
+ context "when recipient address hasn't complement" do
212
+ let(:xml) do
213
+ <<-eos
214
+ <enderDest>
215
+ <xLgr>Rua do governo do estado</xLgr>
216
+ <nro>1125</nro>
217
+ <xCpl></xCpl>
218
+ </enderDest>
219
+ eos
220
+ end
221
+
222
+ it "returns the address with the street and number" do
223
+ expect(BrDanfe::DanfeLib::Helper.generate_address(xml_street))
224
+ .to eq "Rua do governo do estado 1125"
225
+ end
226
+ end
227
+
228
+ context "when recipient address hasn't complement and number" do
229
+ let(:xml) do
230
+ <<-eos
231
+ <enderDest>
232
+ <xLgr>Rua do governo do estado</xLgr>
233
+ <nro></nro>
234
+ <xCpl></xCpl>
235
+ </enderDest>
236
+ eos
237
+ end
238
+
239
+ it "returns the address with the street only" do
240
+ expect(BrDanfe::DanfeLib::Helper.generate_address(xml_street))
241
+ .to eq "Rua do governo do estado"
242
+ end
243
+ end
244
+
245
+ context "when recipient address hasn't number" do
246
+ let(:xml) do
247
+ <<-eos
248
+ <enderDest>
249
+ <xLgr>Rua do governo do estado</xLgr>
250
+ <nro></nro>
251
+ <xCpl>Em anexo ao super mercado maior do bairro</xCpl>
252
+ </enderDest>
253
+ eos
254
+ end
255
+
256
+ it "returns the address with the street and complement" do
257
+ expect(BrDanfe::DanfeLib::Helper.generate_address(xml_street))
258
+ .to eq "Rua do governo do estado - Em anexo ao super mercado maior do bairro"
259
+ end
260
+ end
261
+ end
170
262
  end
@@ -14,6 +14,29 @@ describe BrDanfe::DanfeLib::Infadic do
14
14
  <<-eos
15
15
  <NFe xmlns="http://www.portalfiscal.inf.br/nfe">
16
16
  <infNFe Id="NFe25111012345678901234550020000134151000134151" versao="2.00">
17
+ <ide>
18
+ <dEmi>2011-10-29</dEmi>
19
+ <dSaiEnt>2011-10-30</dSaiEnt>
20
+ <hSaiEnt>15:32:45</hSaiEnt>
21
+ </ide>
22
+ <dest>
23
+ <CNPJ>82743287000880</CNPJ>
24
+ <xNome>Schneider Electric Brasil Ltda</xNome>
25
+ <enderDest>
26
+ <xLgr>Av da Saudade</xLgr>
27
+ <nro>1125</nro>
28
+ <xBairro>Frutal</xBairro>
29
+ <xCpl>Sala 01 e 02</xCpl>
30
+ <cMun>3552403</cMun>
31
+ <xMun>SUMARE</xMun>
32
+ <UF>SP</UF>
33
+ <CEP>13171320</CEP>
34
+ <cPais>1058</cPais>
35
+ <xPais>BRASIL</xPais>
36
+ <fone>1921046300</fone>
37
+ </enderDest>
38
+ <IE>671008375110</IE>
39
+ </dest>
17
40
  <transp>
18
41
  <vol>
19
42
  <qVol>1</qVol>
@@ -123,6 +146,51 @@ describe BrDanfe::DanfeLib::Infadic do
123
146
  expect("#{base_dir}infadic#render-difal.pdf").to have_same_content_of file: output_pdf
124
147
  end
125
148
  end
149
+
150
+ context "with too big address" do
151
+ let(:xml_as_string) do
152
+ <<-eos
153
+ <NFe xmlns="http://www.portalfiscal.inf.br/nfe">
154
+ <infNFe Id="NFe25111012345678901234550020000134151000134151" versao="2.00">
155
+ <ide>
156
+ <dEmi>2011-10-29</dEmi>
157
+ <dSaiEnt>2011-10-30</dSaiEnt>
158
+ <hSaiEnt>15:32:45</hSaiEnt>
159
+ </ide>
160
+ <dest>
161
+ <CNPJ>82743287000880</CNPJ>
162
+ <xNome>Schneider Electric Brasil Ltda</xNome>
163
+ <enderDest>
164
+ <xLgr>Av da Saudade</xLgr>
165
+ <nro>1125</nro>
166
+ <xBairro>Frutal</xBairro>
167
+ <xCpl>Em anexo ao super mercado maior do bairro</xCpl>
168
+ <cMun>3552403</cMun>
169
+ <xMun>SUMARE</xMun>
170
+ <UF>SP</UF>
171
+ <CEP>13171320</CEP>
172
+ <cPais>1058</cPais>
173
+ <xPais>BRASIL</xPais>
174
+ <fone>1921046300</fone>
175
+ </enderDest>
176
+ <IE>671008375110</IE>
177
+ </dest>
178
+ <infAdic>
179
+ <infCpl>Uma observação</infCpl>
180
+ </infAdic>
181
+ </infNFe>
182
+ </NFe>
183
+ eos
184
+ end
185
+
186
+ it "renders xml to the pdf with street on observation" do
187
+ expect(File.exist?(output_pdf)).to be_falsey
188
+
189
+ pdf.render_file output_pdf
190
+
191
+ expect("#{base_dir}infadic-with-street-data#render.pdf").to have_same_content_of file: output_pdf
192
+ end
193
+ end
126
194
  end
127
195
 
128
196
  context "with extra volume" do