br_danfe 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +70 -0
- data/lib/br_danfe/dest.rb +10 -2
- data/lib/br_danfe/document.rb +10 -2
- data/lib/br_danfe/emit.rb +1 -1
- data/lib/br_danfe/helper.rb +30 -6
- data/lib/br_danfe/version.rb +1 -1
- data/lib/br_danfe/xml.rb +4 -0
- data/spec/features/br_danfe_spec.rb +111 -81
- data/spec/fixtures/lib/dest.pdf +279 -0
- data/spec/fixtures/{nfe_simples_nacional.xml → v2.00/nfe_simples_nacional.xml} +0 -0
- data/spec/fixtures/{nfe_simples_nacional.xml.fixture.pdf → v2.00/nfe_simples_nacional.xml.fixture.pdf} +4 -18
- data/spec/fixtures/{nfe_with_cpf.xml → v2.00/nfe_with_cpf.xml} +0 -0
- data/spec/fixtures/{nfe_with_cpf.xml.fixture.pdf → v2.00/nfe_with_cpf.xml.fixture.pdf} +4 -18
- data/spec/fixtures/{nfe_with_extra_volumes.xml → v2.00/nfe_with_extra_volumes.xml} +0 -0
- data/spec/fixtures/{nfe_with_extra_volumes.xml.fixture.pdf → v2.00/nfe_with_extra_volumes.xml.fixture.pdf} +6 -13
- data/spec/fixtures/{nfe_with_fci.xml → v2.00/nfe_with_fci.xml} +0 -0
- data/spec/fixtures/{nfe_with_fci.xml.fixture.pdf → v2.00/nfe_with_fci.xml.fixture.pdf} +4 -18
- data/spec/fixtures/{nfe_with_logo.xml → v2.00/nfe_with_logo.xml} +0 -0
- data/spec/fixtures/{nfe_with_logo.xml.fixture.pdf → v2.00/nfe_with_logo.xml.fixture.pdf} +6 -20
- data/spec/fixtures/{nfe_with_logo.xml.logo.png → v2.00/nfe_with_logo.xml.logo.png} +0 -0
- data/spec/fixtures/{nfe_with_ns.xml → v2.00/nfe_with_ns.xml} +0 -0
- data/spec/fixtures/{nfe_with_ns.xml.fixture.pdf → v2.00/nfe_with_ns.xml.fixture.pdf} +6 -13
- data/spec/fixtures/{nfe_without_ns.xml → v2.00/nfe_without_ns.xml} +0 -0
- data/spec/fixtures/{nfe_without_ns.xml.fixture.pdf → v2.00/nfe_without_ns.xml.fixture.pdf} +4 -18
- data/spec/fixtures/v3.10/nfe_simples_nacional.xml +1 -0
- data/spec/fixtures/v3.10/nfe_simples_nacional.xml.fixture.pdf +2619 -0
- data/spec/lib/dest_spec.rb +99 -0
- data/spec/lib/helper_spec.rb +46 -1
- data/spec/lib/xml_spec.rb +37 -0
- metadata +42 -32
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bfdad1f5eba72650cb7f3502c4d255378cacf217
|
4
|
+
data.tar.gz: 1652da945d3f4eca2f6f03dd7b3ef53ebef14aa1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 91a9a8b20bac8d845542f37412512d57b7ea924ef1a597630336c2677eca5ca9e198a2589f4704f3b13b1fc912caa35ba76e21b3fe032a5acbecf4bd42a23c6b
|
7
|
+
data.tar.gz: f6d94fb7f01dfaa286651136c5a4c6bfda71606f6e54c91a2a3c6929bfcd210b36dddb978a7b1079047e6d50434bd16f5b11d53e52aed13927892cae2b252ef1
|
data/README.md
CHANGED
@@ -6,6 +6,14 @@ This gem generates PDF files for Brazilian DANFE (_Documento Auxiliar da Nota Fi
|
|
6
6
|
|
7
7
|
This gem requires `ruby >= 1.9.x`.
|
8
8
|
|
9
|
+
## Supported NF-e versions
|
10
|
+
|
11
|
+
XML version | Supported?
|
12
|
+
----------- | ----------
|
13
|
+
1.00 | no
|
14
|
+
2.00 | yes
|
15
|
+
3.10 | yes
|
16
|
+
|
9
17
|
## Installing
|
10
18
|
|
11
19
|
gem install ruby_danfe
|
@@ -86,6 +94,68 @@ You can do this automagically running the following taks:
|
|
86
94
|
|
87
95
|
Code coverage is available through of SimpleCov. Just run `rspec` and open the coverage report in your browser.
|
88
96
|
|
97
|
+
#### Generating new fixtures
|
98
|
+
|
99
|
+
If you need to generate new danfes for using as fixtures, please don't use real data.
|
100
|
+
|
101
|
+
These data bellow are suggested:
|
102
|
+
|
103
|
+
**Sender:**
|
104
|
+
|
105
|
+
Field | Content
|
106
|
+
------------ | ----------------------
|
107
|
+
Name | Nome do Remetente Ltda
|
108
|
+
Trade | Nome Fantasia do Remetente Ltda
|
109
|
+
Address | Rua do Remetente
|
110
|
+
Number | 123
|
111
|
+
Complement | Casa
|
112
|
+
Neighborhood | Bairro do Remetente
|
113
|
+
CEP | 12.345-678
|
114
|
+
City | São Paulo - SP
|
115
|
+
Phone | (11) 1234-5678
|
116
|
+
CNPJ | 62.013.294/0001-43
|
117
|
+
IE | 526.926.313.553
|
118
|
+
|
119
|
+
**Recipient:**
|
120
|
+
|
121
|
+
Field | Content
|
122
|
+
------------ | -------------------------
|
123
|
+
Name | Nome do Destinatário PJ Ltda
|
124
|
+
Address | Rua do Destinatário PJ
|
125
|
+
Number | 345
|
126
|
+
Complement | SL 1 e 2
|
127
|
+
Neighborhood | Bairro do Destinatário PJ
|
128
|
+
CEP | 23.456-789
|
129
|
+
City | Sumaré - SP
|
130
|
+
Phone | (19) 2345-6789
|
131
|
+
CNPJ | 71.058.884/0001-83
|
132
|
+
IE | 671.008.375.110
|
133
|
+
|
134
|
+
Field | Content
|
135
|
+
------------ | -------------------------
|
136
|
+
Name | Nome do Destinatário PF
|
137
|
+
Address | Rua do Destinatário PF
|
138
|
+
Number | 345
|
139
|
+
Complement | 1o Andar
|
140
|
+
Neighborhood | Bairro do Destinatário PF
|
141
|
+
CEP | 98.765-432
|
142
|
+
City | Vinhedo - SP
|
143
|
+
Phone | (16) 4567-8901
|
144
|
+
CPF | 485.325.574-57
|
145
|
+
RG | 11.420.947-9
|
146
|
+
|
147
|
+
**Transporter:**
|
148
|
+
|
149
|
+
Field | Content
|
150
|
+
------------ | --------------------------
|
151
|
+
Name | Nome do Transportador Ltda
|
152
|
+
Address | Rua do Transportador, 456
|
153
|
+
City | Votorantim - SP
|
154
|
+
CNPJ | 71.434.064/0001-49
|
155
|
+
IE | 964.508.990.089
|
156
|
+
|
157
|
+
You can generate new data using [4devs generators](http://www.4devs.com.br).
|
158
|
+
|
89
159
|
### Building and publishing
|
90
160
|
|
91
161
|
You can build using one of the above tasks
|
data/lib/br_danfe/dest.rb
CHANGED
@@ -42,7 +42,11 @@ module BrDanfe
|
|
42
42
|
@pdf.ibox 0.85, 10.16, 0.25, 9.43, I18n.t("danfe.enderDest.xLgr"), street
|
43
43
|
@pdf.lbox 0.85, 4.83, 10.41, 9.43, @xml, "enderDest/xBairro"
|
44
44
|
@pdf.ibox 0.85, 2.67, 15.24, 9.43, I18n.t("danfe.enderDest.CEP"), cep
|
45
|
-
|
45
|
+
if @xml.version_310?
|
46
|
+
@pdf.idate 0.85, 2.92, 17.90, 9.43, "ide.dSaiEnt", @xml["ide/dhSaiEnt"], { align: :right }
|
47
|
+
else
|
48
|
+
@pdf.idate 0.85, 2.92, 17.90, 9.43, "ide.dSaiEnt", @xml["ide/dSaiEnt"], { align: :right }
|
49
|
+
end
|
46
50
|
end
|
47
51
|
|
48
52
|
def street
|
@@ -58,7 +62,11 @@ module BrDanfe
|
|
58
62
|
@pdf.ibox 0.85, 4.06, 7.36, 10.28, I18n.t("danfe.enderDest.fone"), phone
|
59
63
|
@pdf.lbox 0.85, 1.14, 11.42, 10.28, @xml, "enderDest/UF"
|
60
64
|
@pdf.ibox 0.85, 5.33, 12.56, 10.28, I18n.t("danfe.dest.IE"), ie
|
61
|
-
|
65
|
+
if @xml.version_310?
|
66
|
+
@pdf.itime 0.85, 2.92, 17.90, 10.28, "ide.hSaiEnt", @xml["ide/dhSaiEnt"], { align: :right }
|
67
|
+
else
|
68
|
+
@pdf.itime 0.85, 2.92, 17.90, 10.28, "ide.hSaiEnt", @xml["ide/hSaiEnt"], { align: :right }
|
69
|
+
end
|
62
70
|
end
|
63
71
|
|
64
72
|
def phone
|
data/lib/br_danfe/document.rb
CHANGED
@@ -41,8 +41,16 @@ module BrDanfe
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def idate(h, w, x, y, i18n = "", info = "", options = {})
|
44
|
-
|
45
|
-
|
44
|
+
data = BrDanfe::Helper::format_date(info)
|
45
|
+
|
46
|
+
label = ""
|
47
|
+
label = I18n.t("danfe.#{i18n}") if i18n != ""
|
48
|
+
|
49
|
+
ibox h, w, x, y, label, data, options
|
50
|
+
end
|
51
|
+
|
52
|
+
def itime(h, w, x, y, i18n = "", info = "", options = {})
|
53
|
+
data = BrDanfe::Helper::format_time(info)
|
46
54
|
|
47
55
|
label = ""
|
48
56
|
label = I18n.t("danfe.#{i18n}") if i18n != ""
|
data/lib/br_danfe/emit.rb
CHANGED
@@ -87,7 +87,7 @@ module BrDanfe
|
|
87
87
|
end
|
88
88
|
|
89
89
|
def protocol_box
|
90
|
-
@pdf.ibox 0.85, 10.02, 10.79, 6.46, I18n.t("danfe.infProt"), @xml["infProt/nProt"] + " " + Helper.
|
90
|
+
@pdf.ibox 0.85, 10.02, 10.79, 6.46, I18n.t("danfe.infProt"), @xml["infProt/nProt"] + " " + Helper.format_datetime(@xml["infProt/dhRecbto"]), { align: :center }
|
91
91
|
end
|
92
92
|
|
93
93
|
def ie_box
|
data/lib/br_danfe/helper.rb
CHANGED
@@ -11,15 +11,39 @@ module BrDanfe
|
|
11
11
|
28.7.cm - y
|
12
12
|
end
|
13
13
|
|
14
|
-
def self.
|
15
|
-
|
14
|
+
def self.format_datetime(xml_datetime)
|
15
|
+
formated = ""
|
16
16
|
|
17
|
-
if
|
18
|
-
date = DateTime.strptime(
|
19
|
-
|
17
|
+
if !xml_datetime.empty?
|
18
|
+
date = DateTime.strptime(xml_datetime, "%Y-%m-%dT%H:%M:%S")
|
19
|
+
formated = date.strftime("%d/%m/%Y %H:%M:%S")
|
20
20
|
end
|
21
21
|
|
22
|
-
|
22
|
+
formated
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.format_date(xml_datetime)
|
26
|
+
formated = ""
|
27
|
+
|
28
|
+
if !xml_datetime.empty?
|
29
|
+
date = DateTime.strptime(xml_datetime, "%Y-%m-%d")
|
30
|
+
formated = date.strftime("%d/%m/%Y")
|
31
|
+
end
|
32
|
+
|
33
|
+
formated
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.format_time(xml_datetime)
|
37
|
+
formated = ""
|
38
|
+
|
39
|
+
if xml_datetime.length == 8
|
40
|
+
formated = xml_datetime
|
41
|
+
elsif xml_datetime.length > 8
|
42
|
+
date = DateTime.strptime(xml_datetime, "%Y-%m-%dT%H:%M:%S %Z").to_time
|
43
|
+
formated = date.getutc.strftime("%H:%M:%S")
|
44
|
+
end
|
45
|
+
|
46
|
+
formated
|
23
47
|
end
|
24
48
|
|
25
49
|
def self.has_no_fiscal_value?(xml)
|
data/lib/br_danfe/version.rb
CHANGED
data/lib/br_danfe/xml.rb
CHANGED
@@ -1,133 +1,163 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
describe
|
4
|
-
let(:base_dir) { "./spec/fixtures/"}
|
3
|
+
describe BrDanfe::Danfe do
|
5
4
|
let(:output_pdf) { "#{base_dir}output.pdf" }
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
danfe = BrDanfe::Danfe.new(File.read("#{base_dir}nfe_with_ns.xml"))
|
6
|
+
context "when xml's version is v2.00" do
|
7
|
+
let(:base_dir) { "./spec/fixtures/v2.00/"}
|
10
8
|
|
11
|
-
|
9
|
+
describe "#render_pdf" do
|
10
|
+
it "renders a basic NF-e with namespace" do
|
11
|
+
danfe = BrDanfe::Danfe.new(File.read("#{base_dir}nfe_with_ns.xml"))
|
12
12
|
|
13
|
-
|
14
|
-
end
|
13
|
+
expected = IO.binread("#{base_dir}nfe_with_ns.xml.fixture.pdf")
|
15
14
|
|
16
|
-
|
17
|
-
|
15
|
+
expect(danfe.render_pdf).to eq expected
|
16
|
+
end
|
18
17
|
|
19
|
-
|
18
|
+
it "renders another basic NF-e without namespace" do
|
19
|
+
danfe = BrDanfe::Danfe.new(File.read("#{base_dir}nfe_without_ns.xml"))
|
20
20
|
|
21
|
-
|
22
|
-
end
|
21
|
+
expected = IO.binread("#{base_dir}nfe_without_ns.xml.fixture.pdf")
|
23
22
|
|
24
|
-
|
25
|
-
|
23
|
+
expect(danfe.render_pdf).to eq expected
|
24
|
+
end
|
26
25
|
|
27
|
-
|
26
|
+
it "renders a NF-e having FCI in its items" do
|
27
|
+
danfe = BrDanfe::Danfe.new(File.read("#{base_dir}nfe_with_fci.xml"))
|
28
28
|
|
29
|
-
|
30
|
-
end
|
29
|
+
expected = IO.binread("#{base_dir}nfe_with_fci.xml.fixture.pdf")
|
31
30
|
|
32
|
-
|
33
|
-
|
31
|
+
expect(danfe.render_pdf).to eq expected
|
32
|
+
end
|
34
33
|
|
35
|
-
|
34
|
+
it "renders a Simples Nacional NF-e using CSOSN" do
|
35
|
+
danfe = BrDanfe::Danfe.new(File.read("#{base_dir}nfe_simples_nacional.xml"))
|
36
36
|
|
37
|
-
|
38
|
-
end
|
37
|
+
expected = IO.binread("#{base_dir}nfe_simples_nacional.xml.fixture.pdf")
|
39
38
|
|
40
|
-
|
41
|
-
|
39
|
+
expect(danfe.render_pdf).to eq expected
|
40
|
+
end
|
42
41
|
|
43
|
-
|
42
|
+
it "renders a NF-e with extra volumes" do
|
43
|
+
danfe = BrDanfe::Danfe.new(File.read("#{base_dir}nfe_with_extra_volumes.xml"))
|
44
44
|
|
45
|
-
|
46
|
-
end
|
45
|
+
expected = IO.binread("#{base_dir}nfe_with_extra_volumes.xml.fixture.pdf")
|
47
46
|
|
48
|
-
|
49
|
-
|
50
|
-
danfe.options.logo_path = "./spec/fixtures/nfe_with_logo.xml.logo.png"
|
47
|
+
expect(danfe.render_pdf).to eq expected
|
48
|
+
end
|
51
49
|
|
52
|
-
|
50
|
+
it "renders a NF-e with logo" do
|
51
|
+
danfe = BrDanfe::Danfe.new(File.read("#{base_dir}nfe_with_logo.xml"))
|
52
|
+
danfe.options.logo_path = "#{base_dir}nfe_with_logo.xml.logo.png"
|
53
53
|
|
54
|
-
|
55
|
-
end
|
54
|
+
expected = IO.binread("#{base_dir}nfe_with_logo.xml.fixture.pdf")
|
56
55
|
|
57
|
-
|
58
|
-
|
56
|
+
expect(danfe.render_pdf).to eq expected
|
57
|
+
end
|
59
58
|
|
60
|
-
|
59
|
+
it "renders a NF-e with CPF" do
|
60
|
+
danfe = BrDanfe::Danfe.new(File.read("#{base_dir}nfe_with_cpf.xml"))
|
61
61
|
|
62
|
-
|
62
|
+
expected = IO.binread("#{base_dir}nfe_with_cpf.xml.fixture.pdf")
|
63
|
+
|
64
|
+
expect(danfe.render_pdf).to eq expected
|
65
|
+
end
|
63
66
|
end
|
64
|
-
end
|
65
67
|
|
66
|
-
|
67
|
-
|
68
|
+
describe "#save_pdf" do
|
69
|
+
before { File.delete(output_pdf) if File.exist?(output_pdf) }
|
68
70
|
|
69
|
-
|
70
|
-
|
71
|
+
it "renders a basic NF-e with namespace" do
|
72
|
+
expect(File.exist?(output_pdf)).to be_falsey
|
71
73
|
|
72
|
-
|
73
|
-
|
74
|
+
danfe = BrDanfe::Danfe.new(File.read("#{base_dir}nfe_with_ns.xml"))
|
75
|
+
danfe.save_pdf output_pdf
|
74
76
|
|
75
|
-
|
76
|
-
|
77
|
+
expect("#{base_dir}nfe_with_ns.xml.fixture.pdf").to be_same_file_as(output_pdf)
|
78
|
+
end
|
77
79
|
|
78
|
-
|
79
|
-
|
80
|
+
it "renders another basic NF-e without namespace" do
|
81
|
+
expect(File.exist?(output_pdf)).to be_falsey
|
80
82
|
|
81
|
-
|
82
|
-
|
83
|
+
danfe = BrDanfe::Danfe.new(File.read("#{base_dir}nfe_without_ns.xml"))
|
84
|
+
danfe.save_pdf output_pdf
|
83
85
|
|
84
|
-
|
85
|
-
|
86
|
+
expect("#{base_dir}nfe_without_ns.xml.fixture.pdf").to be_same_file_as(output_pdf)
|
87
|
+
end
|
86
88
|
|
87
|
-
|
88
|
-
|
89
|
+
it "renders a NF-e having FCI in its items" do
|
90
|
+
expect(File.exist?(output_pdf)).to be_falsey
|
89
91
|
|
90
|
-
|
91
|
-
|
92
|
+
danfe = BrDanfe::Danfe.new(File.read("#{base_dir}nfe_with_fci.xml"))
|
93
|
+
danfe.save_pdf output_pdf
|
92
94
|
|
93
|
-
|
94
|
-
|
95
|
+
expect("#{base_dir}nfe_with_fci.xml.fixture.pdf").to be_same_file_as(output_pdf)
|
96
|
+
end
|
95
97
|
|
96
|
-
|
97
|
-
|
98
|
+
it "renders a Simples Nacional NF-e using CSOSN" do
|
99
|
+
expect(File.exist?(output_pdf)).to be_falsey
|
98
100
|
|
99
|
-
|
100
|
-
|
101
|
+
danfe = BrDanfe::Danfe.new(File.read("#{base_dir}nfe_simples_nacional.xml"))
|
102
|
+
danfe.save_pdf output_pdf
|
101
103
|
|
102
|
-
|
103
|
-
|
104
|
+
expect("#{base_dir}nfe_simples_nacional.xml.fixture.pdf").to be_same_file_as(output_pdf)
|
105
|
+
end
|
106
|
+
|
107
|
+
it "renders a NF-e with extra volumes" do
|
108
|
+
expect(File.exist?(output_pdf)).to be_falsey
|
109
|
+
|
110
|
+
danfe = BrDanfe::Danfe.new(File.read("#{base_dir}nfe_with_extra_volumes.xml"))
|
111
|
+
danfe.save_pdf output_pdf
|
112
|
+
|
113
|
+
expect("#{base_dir}nfe_with_extra_volumes.xml.fixture.pdf").to be_same_file_as(output_pdf)
|
114
|
+
end
|
115
|
+
|
116
|
+
it "renders a NF-e with logo" do
|
117
|
+
expect(File.exist?(output_pdf)).to be_falsey
|
104
118
|
|
105
|
-
|
106
|
-
|
119
|
+
danfe = BrDanfe::Danfe.new(File.read("#{base_dir}nfe_with_logo.xml"))
|
120
|
+
danfe.options.logo_path = "#{base_dir}nfe_with_logo.xml.logo.png"
|
121
|
+
danfe.save_pdf output_pdf
|
107
122
|
|
108
|
-
|
109
|
-
|
123
|
+
expect("#{base_dir}nfe_with_logo.xml.fixture.pdf").to be_same_file_as(output_pdf)
|
124
|
+
end
|
110
125
|
|
111
|
-
|
126
|
+
it "renders a NF-e with CPF" do
|
127
|
+
expect(File.exist?(output_pdf)).to be_falsey
|
128
|
+
|
129
|
+
danfe = BrDanfe::Danfe.new(File.read("#{base_dir}nfe_with_cpf.xml"))
|
130
|
+
danfe.save_pdf output_pdf
|
131
|
+
|
132
|
+
expect("#{base_dir}nfe_with_cpf.xml.fixture.pdf").to be_same_file_as(output_pdf)
|
133
|
+
end
|
112
134
|
end
|
135
|
+
end
|
113
136
|
|
114
|
-
|
115
|
-
|
137
|
+
context "when xml's version is v3.10" do
|
138
|
+
let(:base_dir) { "./spec/fixtures/v3.10/"}
|
116
139
|
|
117
|
-
|
118
|
-
|
119
|
-
|
140
|
+
describe "#render_pdf" do
|
141
|
+
it "renders a Simples Nacional NF-e using CSOSN" do
|
142
|
+
danfe = BrDanfe::Danfe.new(File.read("#{base_dir}nfe_simples_nacional.xml"))
|
120
143
|
|
121
|
-
|
144
|
+
expected = IO.binread("#{base_dir}nfe_simples_nacional.xml.fixture.pdf")
|
145
|
+
|
146
|
+
expect(danfe.render_pdf).to eq expected
|
147
|
+
end
|
122
148
|
end
|
123
149
|
|
124
|
-
|
125
|
-
|
150
|
+
describe "#save_pdf" do
|
151
|
+
before { File.delete(output_pdf) if File.exist?(output_pdf) }
|
152
|
+
|
153
|
+
it "renders a Simples Nacional NF-e using CSOSN" do
|
154
|
+
expect(File.exist?(output_pdf)).to be_falsey
|
126
155
|
|
127
|
-
|
128
|
-
|
156
|
+
danfe = BrDanfe::Danfe.new(File.read("#{base_dir}nfe_simples_nacional.xml"))
|
157
|
+
danfe.save_pdf output_pdf
|
129
158
|
|
130
|
-
|
159
|
+
expect("#{base_dir}nfe_simples_nacional.xml.fixture.pdf").to be_same_file_as(output_pdf)
|
160
|
+
end
|
131
161
|
end
|
132
162
|
end
|
133
163
|
end
|