ruby_danfe 0.9.0 → 1.11.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +7 -0
- data/.rspec +1 -0
- data/Gemfile +4 -0
- data/README.md +122 -0
- data/Rakefile +28 -0
- data/lib/ruby_danfe.rb +1 -325
- data/lib/ruby_danfe/cst.rb +28 -0
- data/lib/ruby_danfe/dacte_generator.rb +511 -0
- data/lib/ruby_danfe/danfe_generator.rb +287 -0
- data/lib/ruby_danfe/danfe_nfce_generator.rb +237 -0
- data/lib/ruby_danfe/descricao.rb +44 -0
- data/lib/ruby_danfe/document.rb +80 -0
- data/lib/ruby_danfe/helper.rb +68 -0
- data/lib/ruby_danfe/options.rb +24 -0
- data/lib/ruby_danfe/railtie.rb +20 -0
- data/lib/ruby_danfe/ruby_danfe.rb +49 -0
- data/lib/ruby_danfe/version.rb +3 -0
- data/lib/ruby_danfe/xml.rb +58 -0
- data/ruby_danfe.gemspec +26 -11
- data/spec/features/ruby_danfe_spec.rb +59 -0
- data/spec/fixtures/4_decimals_nfe_simples_nacional.xml +1 -0
- data/spec/fixtures/cte.xml +1 -0
- data/spec/fixtures/nfe_date_format_infoadprod_infoadfisco_issues.xml +42 -0
- data/spec/fixtures/nfe_simples_nacional.xml +1 -0
- data/spec/fixtures/nfe_with_fci.xml +1 -0
- data/spec/fixtures/nfe_with_ns.xml +4 -0
- data/spec/fixtures/nfe_without_ns.xml +2 -0
- data/spec/lib/cst_spec.rb +51 -0
- data/spec/lib/descricao_spec.rb +129 -0
- data/spec/lib/helper_spec.rb +88 -0
- data/spec/lib/options_spec.rb +13 -0
- data/spec/lib/ruby_danfe_spec.rb +43 -0
- data/spec/spec_helper.rb +21 -0
- data/spec/support/be_same_file_as.rb +9 -0
- data/test/danfe.xml +42 -0
- data/test/generate.rb +8 -0
- data/test/generate_nfce.rb +8 -0
- data/test/nfce.xml +147 -0
- data/test/nfe_simples_nacional.xml +1 -0
- data/test/nfe_with_fci.xml +1 -0
- data/test/nfe_with_ns.xml +4 -0
- data/test/nfe_without_ns.xml +2 -0
- metadata +167 -75
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color --format documentation --order rand
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
# Ruby DANFE
|
2
|
+
|
3
|
+
It generates PDF files for Brazilian DANFE (_Documento Auxiliar da Nota Fiscal Eletrônica_) from a valid NF-e XML.
|
4
|
+
|
5
|
+
It also generates Brazilian DACTE (_Documento Auxiliar do Conhecimento de Transporte Eletrônico_).
|
6
|
+
|
7
|
+
This project is inspired on [NFePHP class](http://www.assembla.com/wiki/show/nfephp/DanfeNFePHP).
|
8
|
+
|
9
|
+
## Installing
|
10
|
+
|
11
|
+
gem install ruby_danfe
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
If you have the xml saved in a file:
|
16
|
+
|
17
|
+
require "ruby_danfe"
|
18
|
+
RubyDanfe.generate("sample.pdf", "sample.xml")
|
19
|
+
|
20
|
+
If you have the xml in a variable:
|
21
|
+
|
22
|
+
xml = "string xml"
|
23
|
+
pdf = RubyDanfe.generatePDF(xml)
|
24
|
+
pdf.render_file "output.pdf"
|
25
|
+
|
26
|
+
You can use some options too! In this example, the product's field quantity will be rendered with 4 decimals after comma:
|
27
|
+
|
28
|
+
xml = "string xml"
|
29
|
+
RubyDanfe.options = {"quantity_decimals" => 4}
|
30
|
+
pdf = RubyDanfe.generatePDF(xml)
|
31
|
+
pdf.render_file "output.pdf"
|
32
|
+
|
33
|
+
If you have some especific option that is global for your project, you can create a file at config/ruby_danfe.yml, then the ruby_danfe always will load this options. Example:
|
34
|
+
|
35
|
+
project_name/config/ruby_danfe.yml
|
36
|
+
|
37
|
+
ruby_danfe:
|
38
|
+
options:
|
39
|
+
quantity_decimals: 3
|
40
|
+
numerify_prod_qcom: false
|
41
|
+
|
42
|
+
|
43
|
+
## Development
|
44
|
+
|
45
|
+
### Installing dependencies
|
46
|
+
|
47
|
+
You can install all necessaries dependencies using bunder like above:
|
48
|
+
|
49
|
+
$ bundle install
|
50
|
+
|
51
|
+
### Tests
|
52
|
+
|
53
|
+
#### Manual tests
|
54
|
+
|
55
|
+
At `test` folder you will find the `generate.rb` file. It shows how to generate a pdf file from a valid xml.
|
56
|
+
|
57
|
+
You can use it following the steps above:
|
58
|
+
|
59
|
+
$ cd test
|
60
|
+
$ ruby generate.rb nfe_with_ns.xml
|
61
|
+
|
62
|
+
You can also use an special version of irb with all classes pre-loaded. Just use:
|
63
|
+
|
64
|
+
$ rake console
|
65
|
+
RubyDanfe.generate("output.pdf", "test/nfe_with_ns.xml")
|
66
|
+
|
67
|
+
or
|
68
|
+
|
69
|
+
$ rake console
|
70
|
+
my_xml_string = ""
|
71
|
+
file = File.new("test/nfe_with_ns.xml", "r")
|
72
|
+
while (line = file.gets)
|
73
|
+
my_xml_string = my_xml_string + line
|
74
|
+
end
|
75
|
+
file.close
|
76
|
+
|
77
|
+
xml = RubyDanfe::XML.new(my_xml_string)
|
78
|
+
pdf = RubyDanfe.generatePDF(xml)
|
79
|
+
|
80
|
+
pdf.render_file "output.pdf"
|
81
|
+
|
82
|
+
#### Automated tests with RSpec
|
83
|
+
|
84
|
+
You can run all specs using:
|
85
|
+
|
86
|
+
$ rspec
|
87
|
+
|
88
|
+
In the `spec/fixtures` folder, you are going to find some xml files. Each one represent a different NF-e context.
|
89
|
+
|
90
|
+
Each xml file must have its respective pdf file.
|
91
|
+
|
92
|
+
If you did some change that caused general visual changes at output pdfs, so you have to rebuild all fixtures pdf files.
|
93
|
+
|
94
|
+
You can do this automagically running the following taks:
|
95
|
+
|
96
|
+
$ rake spec:fixtures:recreate_pdfs
|
97
|
+
|
98
|
+
#### Code coverage
|
99
|
+
|
100
|
+
Code coverage is available through of SimpleCov. Just run `rspec` and open the coverage report in your browser.
|
101
|
+
|
102
|
+
### Building and publishing
|
103
|
+
|
104
|
+
You can build using one of the above tasks
|
105
|
+
|
106
|
+
$ rake build # Build ruby_danfe-X.X.X.gem into the pkg directory
|
107
|
+
$ rake install # Build and install ruby_danfe-X.X.X.gem into system gems
|
108
|
+
$ rake release # Create tag vX.X.X and build and push ruby_danfe-X.X.X.gem to Rubygems
|
109
|
+
|
110
|
+
## Contributing
|
111
|
+
|
112
|
+
We encourage you to contribute to Ruby DANFE!
|
113
|
+
|
114
|
+
1. Fork it
|
115
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
116
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
117
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
118
|
+
5. Create new Pull Request
|
119
|
+
|
120
|
+
## License
|
121
|
+
|
122
|
+
Ruby DANFE is released under the [MIT License](http://www.opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "ruby_danfe"
|
3
|
+
|
4
|
+
desc "Open an irb session preloaded ruby_danfe classes"
|
5
|
+
task :console do
|
6
|
+
sh "irb -rubygems -I lib -r ruby_danfe.rb"
|
7
|
+
end
|
8
|
+
|
9
|
+
namespace :spec do
|
10
|
+
namespace :fixtures do
|
11
|
+
desc "Recreate all pdfs fixtures. Use this task always that output pdf format is changed."
|
12
|
+
task :recreate_pdfs do
|
13
|
+
Dir["spec/fixtures/nfe*.xml"].each do |f|
|
14
|
+
puts "Recreating #{f}.fixture.pdf"
|
15
|
+
RubyDanfe.generate("#{f}.fixture.pdf", "#{f}")
|
16
|
+
end
|
17
|
+
|
18
|
+
puts "Recreating spec/fixtures/4_decimals_nfe_simples_nacional.xml.fixture.pdf"
|
19
|
+
RubyDanfe.options = {"quantity_decimals" => 4}
|
20
|
+
RubyDanfe.generate("spec/fixtures/4_decimals_nfe_simples_nacional.xml.fixture.pdf", "spec/fixtures/4_decimals_nfe_simples_nacional.xml")
|
21
|
+
|
22
|
+
Dir["spec/fixtures/cte*.xml"].each do |f|
|
23
|
+
puts "Recreating #{f}.fixture.pdf"
|
24
|
+
RubyDanfe.generate("#{f}.fixture.pdf", "#{f}", :dacte)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/ruby_danfe.rb
CHANGED
@@ -1,325 +1 @@
|
|
1
|
-
|
2
|
-
require 'prawn'
|
3
|
-
require 'prawn/measurement_extensions'
|
4
|
-
require 'barby'
|
5
|
-
require 'barby/barcode/code_128'
|
6
|
-
require 'barby/outputter/prawn_outputter'
|
7
|
-
require 'nokogiri'
|
8
|
-
|
9
|
-
def numerify(number, decimals = 2)
|
10
|
-
return '' if !number || number == ''
|
11
|
-
int, frac = ("%.#{decimals}f" % number).split('.')
|
12
|
-
int.gsub!(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1\.")
|
13
|
-
int + "," + frac
|
14
|
-
end
|
15
|
-
|
16
|
-
def invert(y)
|
17
|
-
28.7.cm - y
|
18
|
-
end
|
19
|
-
|
20
|
-
module RubyDanfe
|
21
|
-
|
22
|
-
version = "0.9.0"
|
23
|
-
|
24
|
-
class XML
|
25
|
-
def initialize(xml)
|
26
|
-
@xml = Nokogiri::XML(xml)
|
27
|
-
end
|
28
|
-
def [](xpath)
|
29
|
-
node = @xml.css(xpath)
|
30
|
-
return node ? node.text : ''
|
31
|
-
end
|
32
|
-
def render
|
33
|
-
RubyDanfe.render @xml.to_s
|
34
|
-
end
|
35
|
-
def collect(xpath, &block)
|
36
|
-
result = []
|
37
|
-
@xml.xpath(xpath).each do |det|
|
38
|
-
result << yield(det)
|
39
|
-
end
|
40
|
-
result
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
class Document < Prawn::Document
|
45
|
-
|
46
|
-
|
47
|
-
def ititle(h, w, x, y, title)
|
48
|
-
self.text_box title, :size => 10, :at => [x.cm, invert(y.cm) - 2], :width => w.cm, :height => h.cm, :style => :bold
|
49
|
-
end
|
50
|
-
|
51
|
-
def ibarcode(h, w, x, y, info)
|
52
|
-
Barby::Code128C.new(info).annotate_pdf(self, :x => x.cm, :y => invert(y.cm), :width => w.cm, :height => h.cm) if info != ''
|
53
|
-
end
|
54
|
-
|
55
|
-
def irectangle(h, w, x, y)
|
56
|
-
self.stroke_rectangle [x.cm, invert(y.cm)], w.cm, h.cm
|
57
|
-
end
|
58
|
-
|
59
|
-
def ibox(h, w, x, y, title = '', info = '', options = {})
|
60
|
-
box [x.cm, invert(y.cm)], w.cm, h.cm, title, info, options
|
61
|
-
end
|
62
|
-
|
63
|
-
def idate(h, w, x, y, title = '', info = '', options = {})
|
64
|
-
tt = info.split('-')
|
65
|
-
ibox h, w, x, y, title, "#{tt[2]}/#{tt[1]}/#{tt[0]}", options
|
66
|
-
end
|
67
|
-
|
68
|
-
def box(at, w, h, title = '', info = '', options = {})
|
69
|
-
options = {
|
70
|
-
:align => :left,
|
71
|
-
:size => 10,
|
72
|
-
:style => nil,
|
73
|
-
:valign => :top,
|
74
|
-
:border => 1
|
75
|
-
}.merge(options)
|
76
|
-
self.stroke_rectangle at, w, h if options[:border] == 1
|
77
|
-
self.text_box title, :size => 6, :at => [at[0] + 2, at[1] - 2], :width => w - 4, :height => 8 if title != ''
|
78
|
-
self.text_box info, :size => options[:size], :at => [at[0] + 2, at[1] - (title != '' ? 14 : 4) ], :width => w - 4, :height => h - (title != '' ? 14 : 4), :align => options[:align], :style => options[:style], :valign => options[:valign]
|
79
|
-
end
|
80
|
-
|
81
|
-
def inumeric(h, w, x, y, title = '', info = '', options = {})
|
82
|
-
numeric [x.cm, invert(y.cm)], w.cm, h.cm, title, info, options
|
83
|
-
end
|
84
|
-
|
85
|
-
def numeric(at, w, h, title = '', info = '', options = {})
|
86
|
-
options = {:decimals => 2}.merge(options)
|
87
|
-
info = numerify(info, options[:decimals]) if info != ''
|
88
|
-
box at, w, h, title, info, options.merge({:align => :right})
|
89
|
-
end
|
90
|
-
|
91
|
-
def itable(h, w, x, y, data, options = {}, &block)
|
92
|
-
self.bounding_box [x.cm, invert(y.cm)], :width => w.cm, :height => h.cm do
|
93
|
-
self.table data, options do |table|
|
94
|
-
yield(table)
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
def self.generatePDF(xml)
|
101
|
-
|
102
|
-
pdf = Document.new(
|
103
|
-
:page_size => 'A4',
|
104
|
-
:page_layout => :portrait,
|
105
|
-
:left_margin => 0,
|
106
|
-
:right_margin => 0,
|
107
|
-
:top_margin => 0,
|
108
|
-
:botton_margin => 0
|
109
|
-
)
|
110
|
-
|
111
|
-
pdf.font "Times-Roman" # Official font
|
112
|
-
|
113
|
-
pdf.repeat :all do
|
114
|
-
|
115
|
-
# CANHOTO
|
116
|
-
|
117
|
-
pdf.ibox 0.85, 16.10, 0.25, 0.42, "RECEBEMOS DE " + xml['emit/xNome'] + " OS PRODUTOS CONSTANTES DA NOTA FISCAL INDICADA ABAIXO"
|
118
|
-
pdf.ibox 0.85, 4.10, 0.25, 1.27, "DATA DE RECEBIMENTO"
|
119
|
-
pdf.ibox 0.85, 12.00, 4.35, 1.27, "IDENTIFICAÇÃO E ASSINATURA DO RECEBEDOR"
|
120
|
-
|
121
|
-
pdf.ibox 1.70, 4.50, 16.35, 0.42, '',
|
122
|
-
"NF-e\n" +
|
123
|
-
"N°. " + xml['ide/nNF'] + "\n" +
|
124
|
-
"SÉRIE " + xml['ide/serie'], {:align => :center, :valign => :center}
|
125
|
-
|
126
|
-
# EMITENTE
|
127
|
-
|
128
|
-
pdf.ibox 3.92, 7.46, 0.25, 2.54, '',
|
129
|
-
xml['emit/xNome'] + "\n" +
|
130
|
-
xml['enderEmit/xLgr'] + ", " + xml['enderEmit/nro'] + "\n" +
|
131
|
-
xml['enderEmit/xBairro'] + " - " + xml['enderEmit/CEP'] + "\n" +
|
132
|
-
xml['enderEmit/xMun'] + "/" + xml['enderEmit/UF'] + "\n" +
|
133
|
-
xml['enderEmit/fone'] + " " + xml['enderEmit/email'], {:align => :center, :valign => :center}
|
134
|
-
|
135
|
-
pdf.ibox 3.92, 3.08, 7.71, 2.54
|
136
|
-
|
137
|
-
pdf.ibox 0.60, 3.08, 7.71, 2.54, '', "DANFE", {:size => 12, :align => :center, :border => 0, :style => :bold}
|
138
|
-
pdf.ibox 1.20, 3.08, 7.71, 3.14, '', "DOCUMENTO AUXILIAR DA NOTA FISCAL ELETRÔNICA", {:size => 8, :align => :center, :border => 0}
|
139
|
-
pdf.ibox 0.60, 3.08, 7.71, 4.34, '', "#{xml['ide/tpNF']} - " + (xml['ide/tpNF'] == '0' ? 'ENTRADA' : 'SAÍDA'), {:size => 8, :align => :center, :border => 0}
|
140
|
-
|
141
|
-
pdf.ibox 1.00, 3.08, 7.71, 4.94, '',
|
142
|
-
"N°. " + xml['ide/nNF'] + "\n" +
|
143
|
-
"SÉRIE " + xml['ide/serie'], {:size => 8, :align => :center, :valign => :center, :border => 0, :style => :bold}
|
144
|
-
|
145
|
-
pdf.ibox 2.20, 10.02, 10.79, 2.54
|
146
|
-
pdf.ibarcode 1.50, 8.00, 10.9010, 4.44, xml['chNFe']
|
147
|
-
pdf.ibox 0.85, 10.02, 10.79, 4.74, "CHAVE DE ACESSO", xml['chNFe'].gsub(/(\d)(?=(\d\d\d\d)+(?!\d))/, "\\1 "), {:style => :bold, :align => :center}
|
148
|
-
pdf.ibox 0.85, 10.02, 10.79, 5.60 , '', "Consulta de autenticidade no portal nacional da NF-e www.nfe.fazenda.gov.br/portal ou no site da Sefaz Autorizadora", {:align => :center, :size => 8}
|
149
|
-
pdf.ibox 0.85, 10.54, 0.25, 6.46, "NATUREZA DA OPERAÇÃO", xml['ide/natOp']
|
150
|
-
pdf.ibox 0.85, 10.02, 10.79, 6.46, "PROTOCOLO DE AUTORIZAÇÃO DE USO", xml['infProt/nProt'] + ' ' + xml['infProt/dhRecbto'], {:align => :center}
|
151
|
-
|
152
|
-
pdf.ibox 0.85, 6.86, 0.25, 7.31, "INSCRIÇÃO ESTADUAL", xml['emit/IE']
|
153
|
-
pdf.ibox 0.85, 6.86, 7.11, 7.31, "INSC.ESTADUAL DO SUBST. TRIBUTÁRIO", xml['emit/IE_ST']
|
154
|
-
pdf.ibox 0.85, 6.84, 13.97, 7.31, "CNPJ", xml['emit/CNPJ']
|
155
|
-
|
156
|
-
# TITULO
|
157
|
-
|
158
|
-
pdf.ititle 0.42, 10.00, 0.25, 8.16, "DESTINATÁRIO / REMETENTE"
|
159
|
-
|
160
|
-
pdf.ibox 0.85, 12.32, 0.25, 8.58, "NOME/RAZÃO SOCIAL", xml['dest/xNome']
|
161
|
-
pdf.ibox 0.85, 5.33, 12.57, 8.58, "CNPJ/CPF", xml['dest/CNPJ'] if xml['dest/CNPJ'] != ''
|
162
|
-
pdf.ibox 0.85, 5.33, 12.57, 8.58, "CNPJ/CPF", xml['dest/CPF'] if xml['dest/CPF'] != ''
|
163
|
-
pdf.idate 0.85, 2.92, 17.90, 8.58, "DATA DA EMISSÃO", xml['ide/dEmi'], {:align => :right}
|
164
|
-
pdf.ibox 0.85, 10.16, 0.25, 9.43, "ENDEREÇO", xml['enderDest/xLgr'] + " " + xml['enderDest/nro']
|
165
|
-
pdf.ibox 0.85, 4.83, 10.41, 9.43, "BAIRRO", xml['enderDest/xBairro']
|
166
|
-
pdf.ibox 0.85, 2.67, 15.24, 9.43, "CEP", xml['enderDest/CEP']
|
167
|
-
pdf.idate 0.85, 2.92, 17.90, 9.43, "DATA DA SAÍDA/ENTRADA", xml['ide/dSaiEnt'], {:align => :right}
|
168
|
-
pdf.ibox 0.85, 7.11, 0.25, 10.28, "MUNICÍPIO", xml['enderDest/xMun']
|
169
|
-
pdf.ibox 0.85, 4.06, 7.36, 10.28, "FONE/FAX", xml['enderDest/fone']
|
170
|
-
pdf.ibox 0.85, 1.14, 11.42, 10.28, "UF", xml['enderDest/UF']
|
171
|
-
pdf.ibox 0.85, 5.33, 12.56, 10.28, "INSCRIÇÃO ESTADUAL", xml['dest/IE']
|
172
|
-
pdf.idate 0.85, 2.92, 17.90, 10.28, "HORA DE SAÍDA", xml['ide/dSaiEnt'], {:align => :right}
|
173
|
-
|
174
|
-
# FATURAS
|
175
|
-
|
176
|
-
pdf.ititle 0.42, 10.00, 0.25, 11.12, "FATURA / DUPLICATAS"
|
177
|
-
pdf.ibox 0.85, 20.57, 0.25, 11.51
|
178
|
-
|
179
|
-
if false
|
180
|
-
pdf.box [0, 563], 63, 44, "Número"
|
181
|
-
pdf.box [63, 563], 63, 44, "Vencimento"
|
182
|
-
pdf.box [126, 563], 63, 44, "Valor"
|
183
|
-
pdf.box [189, 563], 63, 44, "Número"
|
184
|
-
pdf.box [252, 563], 63, 44, "Vencimento"
|
185
|
-
pdf.box [315, 563], 63, 44, "Valor"
|
186
|
-
pdf.box [378, 563], 63, 44, "Número"
|
187
|
-
pdf.box [441, 563], 63, 44, "Vencimento"
|
188
|
-
pdf.box [504, 563], 60, 44, "Valor"
|
189
|
-
end
|
190
|
-
|
191
|
-
pdf.ititle 0.42, 5.60, 0.25, 12.36, "CÁLCULO DO IMPOSTO"
|
192
|
-
|
193
|
-
pdf.inumeric 0.85, 4.06, 0.25, 12.78, "BASE DE CÁLCULO DO ICMS", xml['ICMSTot/vBC']
|
194
|
-
pdf.inumeric 0.85, 4.06, 4.31, 12.78, "VALOR DO ICMS", xml['ICMSTot/vICMS']
|
195
|
-
pdf.inumeric 0.85, 4.06, 8.37, 12.78, "BASE DE CÁLCULO DO ICMS ST", xml['ICMSTot/vBCST']
|
196
|
-
pdf.inumeric 0.85, 4.06, 12.43, 12.78, "VALOR DO ICMS ST", xml['ICMSTot/vST']
|
197
|
-
pdf.inumeric 0.85, 4.32, 16.49, 12.78, "VALOR TOTAL DOS PRODUTOS", xml['ICMSTot/vProd']
|
198
|
-
pdf.inumeric 0.85, 3.46, 0.25, 13.63, "VALOR DO FRETE", xml['ICMSTot/vFrete']
|
199
|
-
pdf.inumeric 0.85, 3.46, 3.71, 13.63, "VALOR DO SEGURO", xml['ICMSTot/vSeg']
|
200
|
-
pdf.inumeric 0.85, 3.46, 7.17, 13.63, "DESCONTO", xml['ICMSTot/vDesc']
|
201
|
-
pdf.inumeric 0.85, 3.46, 10.63, 13.63, "OUTRAS DESPESAS ACESSORIAS", xml['ICMSTot/vOutro']
|
202
|
-
pdf.inumeric 0.85, 3.46, 14.09, 13.63, "VALOR DO IPI", xml['ICMSTot/vIPI']
|
203
|
-
pdf.inumeric 0.85, 3.27, 17.55, 13.63, "VALOR TOTAL DA NOTA", xml['ICMSTot/vNF'], :style => :bold
|
204
|
-
|
205
|
-
pdf.ititle 0.42, 10.00, 0.25, 14.48, "TRANSPORTADOR / VOLUMES TRANSPORTADOS"
|
206
|
-
|
207
|
-
pdf.ibox 0.85, 9.02, 0.25, 14.90, "RAZÃO SOCIAL", xml['transporta/xNome']
|
208
|
-
pdf.ibox 0.85, 2.79, 9.27, 14.90, "FRETE POR CONTA", xml['transp/modFrete'] == '0' ? ' 0 - EMITENTE' : '1 - DEST.'
|
209
|
-
pdf.ibox 0.85, 1.78, 12.06, 14.90, "CODIGO ANTT", xml['veicTransp/RNTC']
|
210
|
-
pdf.ibox 0.85, 2.29, 13.84, 14.90, "PLACA DO VEÍCULO", xml['veicTransp/placa']
|
211
|
-
pdf.ibox 0.85, 0.76, 16.13, 14.90, "UF", xml['veicTransp/UF']
|
212
|
-
pdf.ibox 0.85, 3.94, 16.89, 14.90, "CNPJ/CPF", xml['transporta/CNPJ']
|
213
|
-
pdf.ibox 0.85, 9.02, 0.25, 15.75, "ENDEREÇO", xml['transporta/xEnder']
|
214
|
-
pdf.ibox 0.85, 6.86, 9.27, 15.75, "MUNICÍPIO", xml['transporta/xMun']
|
215
|
-
pdf.ibox 0.85, 0.76, 16.13, 15.75, "UF", xml['transporta/UF']
|
216
|
-
pdf.ibox 0.85, 3.94, 16.89, 15.75, "INSCRIÇÂO ESTADUAL", xml['transporta/IE']
|
217
|
-
pdf.ibox 0.85, 2.92, 0.25, 16.60, "QUANTIDADE", xml['vol/qVol']
|
218
|
-
pdf.ibox 0.85, 3.05, 3.17, 16.60, "ESPÉCIE", xml['vol/esp']
|
219
|
-
pdf.ibox 0.85, 3.05, 6.22, 16.60, "MARCA", xml['vol/marca']
|
220
|
-
pdf.ibox 0.85, 4.83, 9.27, 16.60, "NUMERAÇÃO"
|
221
|
-
pdf.inumeric 0.85, 3.43, 14.10, 16.60, "PESO BRUTO", xml['vol/pesoB'], {:decimals => 3}
|
222
|
-
pdf.inumeric 0.85, 3.30, 17.53, 16.60, "PESO LÍQUIDO", xml['vol/pesoL'], {:decimals => 3}
|
223
|
-
|
224
|
-
pdf.ititle 0.42, 10.00, 0.25, 17.45, "DADOS DO PRODUTO / SERVIÇO"
|
225
|
-
|
226
|
-
pdf.ibox 6.77, 2.00, 0.25, 17.87, "CÓDIGO"
|
227
|
-
pdf.ibox 6.77, 4.50, 2.25, 17.87, "DESCRIÇÃO"
|
228
|
-
pdf.ibox 6.77, 1.50, 6.75, 17.87, "NCM"
|
229
|
-
pdf.ibox 6.77, 0.80, 8.25, 17.87, "CST"
|
230
|
-
pdf.ibox 6.77, 1.00, 9.05, 17.87, "CFOP"
|
231
|
-
pdf.ibox 6.77, 1.00, 10.05, 17.87, "UNID"
|
232
|
-
pdf.ibox 6.77, 1.50, 11.05, 17.87, "QUANT"
|
233
|
-
pdf.ibox 6.77, 1.50, 12.55, 17.87, "VALOR UNIT"
|
234
|
-
pdf.ibox 6.77, 1.50, 14.05, 17.87, "VALOR TOT"
|
235
|
-
pdf.ibox 6.77, 1.50, 15.55, 17.87, "BASE CÁLC"
|
236
|
-
pdf.ibox 6.77, 1.00, 17.05, 17.87, "VL ICMS"
|
237
|
-
pdf.ibox 6.77, 1.00, 18.05, 17.87, "VL IPI"
|
238
|
-
pdf.ibox 6.77, 0.90, 19.05, 17.87, "% ICMS"
|
239
|
-
pdf.ibox 6.77, 0.86, 19.95, 17.87, "% IPI"
|
240
|
-
|
241
|
-
pdf.horizontal_line 0.25.cm, 21.50.cm, :at => invert(18.17.cm)
|
242
|
-
|
243
|
-
pdf.ititle 0.42, 10.00, 0.25, 24.64, "CÁLCULO DO ISSQN"
|
244
|
-
|
245
|
-
pdf.ibox 0.85, 5.08, 0.25, 25.06, "INSCRIÇÃO MUNICIPAL", xml['emit/IM']
|
246
|
-
pdf.ibox 0.85, 5.08, 5.33, 25.06, "VALOR TOTAL DOS SERVIÇOS", xml['total/vServ']
|
247
|
-
pdf.ibox 0.85, 5.08, 10.41, 25.06, "BASE DE CÁLCULO DO ISSQN", xml['total/vBCISS']
|
248
|
-
pdf.ibox 0.85, 5.28, 15.49, 25.06, "VALOR DO ISSQN", xml['total/ISSTot']
|
249
|
-
|
250
|
-
pdf.ititle 0.42, 10.00, 0.25, 25.91, "DADOS ADICIONAIS"
|
251
|
-
|
252
|
-
pdf.ibox 3.07, 12.93, 0.25, 26.33, "INFORMAÇÕES COMPLEMENTARES", xml['infAdic/infCpl'], {:size => 8, :valign => :top}
|
253
|
-
|
254
|
-
pdf.ibox 3.07, 7.62, 13.17, 26.33, "RESERVADO AO FISCO"
|
255
|
-
|
256
|
-
end
|
257
|
-
|
258
|
-
|
259
|
-
pdf.font_size(6) do
|
260
|
-
pdf.itable 6.37, 21.50, 0.25, 18.17,
|
261
|
-
xml.collect('//xmlns:det') { |det|
|
262
|
-
[
|
263
|
-
det.css('prod/cProd').text, #I02
|
264
|
-
det.css('prod/xProd').text, #I04
|
265
|
-
det.css('prod/NCM').text, #I05
|
266
|
-
det.css('ICMS/*/orig').text, #N11
|
267
|
-
det.css('prod/CFOP').text, #I08
|
268
|
-
det.css('prod/uCom').text, #I09
|
269
|
-
numerify(det.css('prod/qCom').text), #I10
|
270
|
-
numerify(det.css('prod/vUnCom').text), #I10a
|
271
|
-
numerify(det.css('prod/vProd').text), #I11
|
272
|
-
numerify(det.css('ICMS/*/vBC').text), #N15
|
273
|
-
numerify(det.css('ICMS/*/vICMS').text), #N17
|
274
|
-
numerify(det.css('IPI/*/vIPI').text), #O14
|
275
|
-
numerify(det.css('ICMS/*/pICMS').text), #N16
|
276
|
-
numerify(det.css('IPI/*/pIPI').text) #O13
|
277
|
-
]
|
278
|
-
},
|
279
|
-
:column_widths => {
|
280
|
-
0 => 2.00.cm,
|
281
|
-
1 => 4.50.cm,
|
282
|
-
2 => 1.50.cm,
|
283
|
-
3 => 0.80.cm,
|
284
|
-
4 => 1.00.cm,
|
285
|
-
5 => 1.00.cm,
|
286
|
-
6 => 1.50.cm,
|
287
|
-
7 => 1.50.cm,
|
288
|
-
8 => 1.50.cm,
|
289
|
-
9 => 1.50.cm,
|
290
|
-
10 => 1.00.cm,
|
291
|
-
11 => 1.00.cm,
|
292
|
-
12 => 0.90.cm,
|
293
|
-
13 => 0.86.cm
|
294
|
-
},
|
295
|
-
:cell_style => {:padding => 2, :border_width => 0} do |table|
|
296
|
-
pdf.dash(5);
|
297
|
-
table.column(6..13).style(:align => :right)
|
298
|
-
table.column(0..13).border_width = 1
|
299
|
-
table.column(0..13).borders = [:bottom]
|
300
|
-
end
|
301
|
-
end
|
302
|
-
|
303
|
-
pdf.page_count.times do |i|
|
304
|
-
pdf.go_to_page(i + 1)
|
305
|
-
pdf.ibox 1.00, 3.08, 7.71, 5.54, '',
|
306
|
-
"FOLHA #{i + 1} de #{pdf.page_count}", {:size => 8, :align => :center, :valign => :center, :border => 0, :style => :bold}
|
307
|
-
end
|
308
|
-
|
309
|
-
return pdf
|
310
|
-
|
311
|
-
end
|
312
|
-
|
313
|
-
def self.render(xml_string)
|
314
|
-
xml = XML.new(xml_string)
|
315
|
-
pdf = generatePDF(xml)
|
316
|
-
return pdf.render
|
317
|
-
end
|
318
|
-
|
319
|
-
def self.generate(pdf_filename, xml_filename)
|
320
|
-
xml = XML.new(File.new(xml_filename))
|
321
|
-
pdf = generatePDF(xml)
|
322
|
-
pdf.render_file pdf_filename
|
323
|
-
end
|
324
|
-
|
325
|
-
end
|
1
|
+
require_relative 'ruby_danfe/railtie.rb'
|