br_danfe 0.0.9 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +26 -3
- data/br_danfe.gemspec +1 -0
- data/config/locales/pt-BR.yml +14 -0
- data/lib/br_danfe/cce.rb +28 -0
- data/lib/br_danfe/cce_lib/barcode.rb +24 -0
- data/lib/br_danfe/cce_lib/correction.rb +22 -0
- data/lib/br_danfe/cce_lib/document.rb +44 -0
- data/lib/br_danfe/cce_lib/footer.rb +15 -0
- data/lib/br_danfe/cce_lib/header.rb +15 -0
- data/lib/br_danfe/cce_lib/nfe_key.rb +23 -0
- data/lib/br_danfe/cce_lib/protocol.rb +23 -0
- data/lib/br_danfe/danfe.rb +16 -16
- data/lib/br_danfe/danfe_lib/cep.rb +9 -0
- data/lib/br_danfe/danfe_lib/consts.rb +6 -0
- data/lib/br_danfe/danfe_lib/cst.rb +30 -0
- data/lib/br_danfe/danfe_lib/dest.rb +86 -0
- data/lib/br_danfe/danfe_lib/det_body.rb +75 -0
- data/lib/br_danfe/danfe_lib/det_header.rb +40 -0
- data/lib/br_danfe/danfe_lib/document.rb +135 -0
- data/lib/br_danfe/danfe_lib/dup.rb +52 -0
- data/lib/br_danfe/danfe_lib/emit.rb +23 -0
- data/lib/br_danfe/danfe_lib/emit_header.rb +82 -0
- data/lib/br_danfe/danfe_lib/helper.rb +64 -0
- data/lib/br_danfe/danfe_lib/icmstot.rb +33 -0
- data/lib/br_danfe/danfe_lib/infadic.rb +80 -0
- data/lib/br_danfe/danfe_lib/issqn.rb +24 -0
- data/lib/br_danfe/danfe_lib/options.rb +24 -0
- data/lib/br_danfe/danfe_lib/phone.rb +13 -0
- data/lib/br_danfe/danfe_lib/plate.rb +9 -0
- data/lib/br_danfe/danfe_lib/ticket.rb +17 -0
- data/lib/br_danfe/danfe_lib/transp.rb +51 -0
- data/lib/br_danfe/danfe_lib/vol.rb +41 -0
- data/lib/br_danfe/danfe_lib/xml.rb +38 -0
- data/lib/br_danfe/danfe_lib/xprod.rb +48 -0
- data/lib/br_danfe/version.rb +1 -1
- data/lib/br_danfe.rb +1 -1
- data/spec/features/cce_spec.rb +28 -0
- data/spec/features/danfe_spec.rb +3 -3
- data/spec/fixtures/cce/lib/barcode#render.pdf +511 -0
- data/spec/fixtures/cce/lib/correction#render.pdf +100 -0
- data/spec/fixtures/cce/lib/document#box.pdf +55 -0
- data/spec/fixtures/cce/lib/document#box.with.block.pdf +72 -0
- data/spec/fixtures/cce/lib/document#text.align.pdf +70 -0
- data/spec/fixtures/cce/lib/document#text.pad.pdf +70 -0
- data/spec/fixtures/cce/lib/document#text.simple.pdf +70 -0
- data/spec/fixtures/cce/lib/document#text.size.pdf +70 -0
- data/spec/fixtures/cce/lib/document#text.style.pdf +70 -0
- data/spec/fixtures/cce/lib/footer#render.pdf +114 -0
- data/spec/fixtures/cce/lib/header#render.pdf +72 -0
- data/spec/fixtures/cce/lib/nfe_key#render.pdf +88 -0
- data/spec/fixtures/cce/lib/protocol#render.pdf +88 -0
- data/spec/fixtures/cce/v1.00/cce.fixture.pdf +659 -0
- data/spec/fixtures/cce/v1.00/cce.xml +1 -0
- data/spec/fixtures/{lib → nfe/lib}/dest#render-v2.00.pdf +0 -0
- data/spec/fixtures/{lib → nfe/lib}/dest#render-v3.10.pdf +0 -0
- data/spec/fixtures/{lib → nfe/lib}/dest#render-with_cnpj.pdf +0 -0
- data/spec/fixtures/{lib → nfe/lib}/dest#render-with_cpf.pdf +0 -0
- data/spec/fixtures/{lib → nfe/lib}/dest#render-with_ie.pdf +0 -0
- data/spec/fixtures/{lib → nfe/lib}/det_body#render-csosn.pdf +0 -0
- data/spec/fixtures/{lib → nfe/lib}/det_body#render-cst.pdf +0 -0
- data/spec/fixtures/{lib → nfe/lib}/det_body#render-fci.pdf +0 -0
- data/spec/fixtures/{lib → nfe/lib}/det_body#render-icms_st.pdf +0 -0
- data/spec/fixtures/{lib → nfe/lib}/det_header#render.pdf +0 -0
- data/spec/fixtures/{lib → nfe/lib}/document#lcnpj-blank.pdf +0 -0
- data/spec/fixtures/{lib → nfe/lib}/document#lcnpj-invalid.pdf +0 -0
- data/spec/fixtures/{lib → nfe/lib}/document#lcnpj-valid.pdf +0 -0
- data/spec/fixtures/{lib → nfe/lib}/document#lie-blank.pdf +0 -0
- data/spec/fixtures/{lib → nfe/lib}/document#lie-invalid.pdf +0 -0
- data/spec/fixtures/{lib → nfe/lib}/document#lie-valid.pdf +0 -0
- data/spec/fixtures/{lib → nfe/lib}/dup#render.pdf +0 -0
- data/spec/fixtures/{lib → nfe/lib}/emit#render.pdf +0 -0
- data/spec/fixtures/{lib → nfe/lib}/emit_header#render-with_logo.pdf +0 -0
- data/spec/fixtures/{lib → nfe/lib}/emit_header#render-without_logo.pdf +0 -0
- data/spec/fixtures/{lib → nfe/lib}/icmstot#render.pdf +0 -0
- data/spec/fixtures/{lib → nfe/lib}/infadic#render-extra_volume.pdf +0 -0
- data/spec/fixtures/{lib → nfe/lib}/infadic#render.pdf +0 -0
- data/spec/fixtures/{lib → nfe/lib}/issqn#render.pdf +0 -0
- data/spec/fixtures/{lib → nfe/lib}/ticket#render.pdf +0 -0
- data/spec/fixtures/{lib → nfe/lib}/transp#render-modfrete_0.pdf +0 -0
- data/spec/fixtures/{lib → nfe/lib}/transp#render-modfrete_1.pdf +0 -0
- data/spec/fixtures/{lib → nfe/lib}/transp#render-modfrete_2.pdf +0 -0
- data/spec/fixtures/{lib → nfe/lib}/transp#render-modfrete_9.pdf +0 -0
- data/spec/fixtures/{lib → nfe/lib}/transp#render.pdf +0 -0
- data/spec/fixtures/{lib → nfe/lib}/vol#render-blank-boxes.pdf +0 -0
- data/spec/fixtures/{lib → nfe/lib}/vol#render.pdf +0 -0
- data/spec/fixtures/{v2.00 → nfe/v2.00}/nfe_simples_nacional.xml +0 -0
- data/spec/fixtures/{v2.00 → nfe/v2.00}/nfe_simples_nacional.xml.fixture.pdf +0 -0
- data/spec/fixtures/{v2.00 → nfe/v2.00}/nfe_with_extra_volumes.xml +0 -0
- data/spec/fixtures/{v2.00 → nfe/v2.00}/nfe_with_extra_volumes.xml.fixture.pdf +0 -0
- data/spec/fixtures/{v2.00 → nfe/v2.00}/nfe_with_fci.xml +0 -0
- data/spec/fixtures/{v2.00 → nfe/v2.00}/nfe_with_fci.xml.fixture.pdf +0 -0
- data/spec/fixtures/{v2.00 → nfe/v2.00}/nfe_with_logo.xml +0 -0
- data/spec/fixtures/{v2.00 → nfe/v2.00}/nfe_with_ns.xml +0 -0
- data/spec/fixtures/{v2.00 → nfe/v2.00}/nfe_with_ns.xml.fixture.pdf +0 -0
- data/spec/fixtures/{v2.00 → nfe/v2.00}/nfe_without_ns.xml +0 -0
- data/spec/fixtures/{v2.00 → nfe/v2.00}/nfe_without_ns.xml.fixture.pdf +0 -0
- data/spec/fixtures/{v3.10 → nfe/v3.10}/nfe_simples_nacional.xml +0 -0
- data/spec/fixtures/{v3.10 → nfe/v3.10}/nfe_simples_nacional.xml.fixture.pdf +0 -0
- data/spec/lib/cce_lib/barcode_spec.rb +26 -0
- data/spec/lib/cce_lib/correction_spec.rb +26 -0
- data/spec/lib/cce_lib/document_spec.rb +115 -0
- data/spec/lib/cce_lib/footer_spec.rb +25 -0
- data/spec/lib/cce_lib/header_spec.rb +25 -0
- data/spec/lib/cce_lib/nfe_key_spec.rb +26 -0
- data/spec/lib/cce_lib/protocol_spec.rb +26 -0
- data/spec/lib/{cep_spec.rb → danfe_lib/cep_spec.rb} +2 -2
- data/spec/lib/{cst_spec.rb → danfe_lib/cst_spec.rb} +3 -3
- data/spec/lib/{dest_spec.rb → danfe_lib/dest_spec.rb} +4 -4
- data/spec/lib/{det_body_spec.rb → danfe_lib/det_body_spec.rb} +4 -4
- data/spec/lib/{det_header_spec.rb → danfe_lib/det_header_spec.rb} +4 -4
- data/spec/lib/{document_spec.rb → danfe_lib/document_spec.rb} +3 -3
- data/spec/lib/{dup_spec.rb → danfe_lib/dup_spec.rb} +4 -4
- data/spec/lib/{emit_header_spec.rb → danfe_lib/emit_header_spec.rb} +4 -4
- data/spec/lib/{emit_spec.rb → danfe_lib/emit_spec.rb} +4 -4
- data/spec/lib/{helper_spec.rb → danfe_lib/helper_spec.rb} +11 -11
- data/spec/lib/{icmstot_spec.rb → danfe_lib/icmstot_spec.rb} +4 -4
- data/spec/lib/{infadic_spec.rb → danfe_lib/infadic_spec.rb} +4 -4
- data/spec/lib/{issqn_spec.rb → danfe_lib/issqn_spec.rb} +4 -4
- data/spec/lib/{options_spec.rb → danfe_lib/options_spec.rb} +3 -3
- data/spec/lib/{phone_spec.rb → danfe_lib/phone_spec.rb} +3 -3
- data/spec/lib/{plate_spec.rb → danfe_lib/plate_spec.rb} +2 -2
- data/spec/lib/{ticket_spec.rb → danfe_lib/ticket_spec.rb} +4 -4
- data/spec/lib/{transp_spec.rb → danfe_lib/transp_spec.rb} +4 -4
- data/spec/lib/{vol_spec.rb → danfe_lib/vol_spec.rb} +4 -4
- data/spec/lib/{xml_spec.rb → danfe_lib/xml_spec.rb} +2 -2
- data/spec/lib/{xprod_spec.rb → danfe_lib/xprod_spec.rb} +5 -5
- metadata +242 -174
- data/lib/br_danfe/cep.rb +0 -7
- data/lib/br_danfe/consts.rb +0 -4
- data/lib/br_danfe/cst.rb +0 -28
- data/lib/br_danfe/dest.rb +0 -84
- data/lib/br_danfe/det_body.rb +0 -73
- data/lib/br_danfe/det_header.rb +0 -38
- data/lib/br_danfe/document.rb +0 -133
- data/lib/br_danfe/dup.rb +0 -50
- data/lib/br_danfe/emit.rb +0 -21
- data/lib/br_danfe/emit_header.rb +0 -80
- data/lib/br_danfe/helper.rb +0 -62
- data/lib/br_danfe/icmstot.rb +0 -31
- data/lib/br_danfe/infadic.rb +0 -78
- data/lib/br_danfe/issqn.rb +0 -22
- data/lib/br_danfe/options.rb +0 -22
- data/lib/br_danfe/phone.rb +0 -11
- data/lib/br_danfe/plate.rb +0 -7
- data/lib/br_danfe/ticket.rb +0 -15
- data/lib/br_danfe/transp.rb +0 -49
- data/lib/br_danfe/vol.rb +0 -39
- data/lib/br_danfe/xml.rb +0 -36
- data/lib/br_danfe/xprod.rb +0 -46
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3aa10ea5b153e530d84292516071252c98e42cfb
|
4
|
+
data.tar.gz: 75b0d0bfbb184b14ae05423cb0b813290d6ff71e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 58441eae637e4f5f0116f4c570285ffdc48d812c95b3e0cfb55bb9dedb758795d7b87a89519e9a3273236053bc9605d50aa0e149249ce69d70bbf0b1110ef715
|
7
|
+
data.tar.gz: 79cc04952937048b9e5be375e42dc3093caef7cf5bd81af04851b38348e7027ab833c2310efa8b4fb0e4e94d832ca82a28dedf4e40e1f8fcadba0092e7261eb7
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
[![Code Climate](https://codeclimate.com/github/asseinfo/br_danfe.png)](https://codeclimate.com/github/asseinfo/br_danfe) [![Build Status](https://travis-ci.org/asseinfo/br_danfe.png?branch=master)](https://travis-ci.org/asseinfo/br_danfe)
|
4
4
|
|
5
|
-
This gem generates PDF files for Brazilian DANFE (_Documento Auxiliar da Nota Fiscal Eletrônica_) from a valid NF-e XML.
|
5
|
+
This gem generates PDF files for Brazilian DANFE (_Documento Auxiliar da Nota Fiscal Eletrônica_) from a valid NF-e XML. It also can generates PDF file for CC-e (_Carta de Correção Eletrônica_).
|
6
6
|
|
7
7
|
[See an example here.](https://github.com/asseinfo/br_danfe/blob/master/spec/fixtures/v2.00/nfe_with_logo.xml.fixture.pdf?raw=true)
|
8
8
|
|
@@ -22,7 +22,8 @@ XML version | Supported?
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
-
###
|
25
|
+
### DANFE - _Documento Auxiliar da Nota Fiscal Eletrônica_
|
26
|
+
#### Usage in Ruby
|
26
27
|
|
27
28
|
xml = File.read("nfe.xml")
|
28
29
|
|
@@ -30,7 +31,7 @@ XML version | Supported?
|
|
30
31
|
danfe.options.logo_path = "logo.png"
|
31
32
|
danfe.save_pdf("nfe.pdf")
|
32
33
|
|
33
|
-
|
34
|
+
#### Usage in Rails Controller
|
34
35
|
|
35
36
|
class DanfeController < ApplicationController
|
36
37
|
def new
|
@@ -43,6 +44,28 @@ XML version | Supported?
|
|
43
44
|
end
|
44
45
|
end
|
45
46
|
|
47
|
+
### CC-e - _Carta de Correção Eletrônica_
|
48
|
+
|
49
|
+
#### Usage in Ruby
|
50
|
+
|
51
|
+
xml = File.read("cce.xml")
|
52
|
+
|
53
|
+
cce = BrDanfe::Cce.new(xml)
|
54
|
+
cce.save_pdf("nfe.pdf")
|
55
|
+
|
56
|
+
#### Usage in Rails Controller
|
57
|
+
|
58
|
+
class CCeController < ApplicationController
|
59
|
+
def new
|
60
|
+
invoice = Invoice.find(params[:id])
|
61
|
+
xml_as_string = invoice.generate_xml # your method that generates the CC-e's xml
|
62
|
+
|
63
|
+
cce = BrDanfe::Cce.new(xml_as_string)
|
64
|
+
|
65
|
+
send_data cce.render_pdf, filename: "cce.pdf", type: "application/pdf"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
46
69
|
## I18n
|
47
70
|
|
48
71
|
By default, your rails application must be configured to `pt-Br`.
|
data/br_danfe.gemspec
CHANGED
@@ -24,6 +24,7 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.add_dependency "i18n"
|
25
25
|
spec.add_dependency "br_documents", ">= 0.0.8"
|
26
26
|
|
27
|
+
spec.add_development_dependency "byebug", "3.5.1"
|
27
28
|
spec.add_development_dependency "rspec", ">= 3.0.0"
|
28
29
|
spec.add_development_dependency "simplecov", ">= 0.9.0"
|
29
30
|
spec.add_development_dependency "codeclimate-test-reporter"
|
data/config/locales/pt-BR.yml
CHANGED
@@ -1,4 +1,18 @@
|
|
1
1
|
pt-BR:
|
2
|
+
cce:
|
3
|
+
title: "Carta de Correção Eletrônica - CCe"
|
4
|
+
protocol: "PROTOCOLO DE AUTORIZAÇÃO"
|
5
|
+
key: "CHAVE DE ACESSO"
|
6
|
+
legal_note: "A Carta de Correção é disciplinada pelo § 1o-A do art. 7o
|
7
|
+
do Convênio S/N, de 15 de dezembro de 1970 e pode ser
|
8
|
+
utilizada para regularização de erro ocorrido na emissão de
|
9
|
+
documento fiscal, desde que o erro não esteja relacionado com:\n
|
10
|
+
I. as variáveis que determinam o valor do imposto tais como:
|
11
|
+
base de cálculo, alíquota, diferença de preço, quantidade,
|
12
|
+
valor da operação ou da prestação;\n
|
13
|
+
II. a correção de dados cadastrais que implique mudança do
|
14
|
+
remetente ou do destinatário;\n
|
15
|
+
III. a data de emissão ou de saída."
|
2
16
|
danfe:
|
3
17
|
chNFe: "CHAVE DE ACESSO"
|
4
18
|
infProt: "PROTOCOLO DE AUTORIZAÇÃO DE USO"
|
data/lib/br_danfe/cce.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
module BrDanfe
|
2
|
+
class Cce
|
3
|
+
def initialize(xml)
|
4
|
+
@xml = xml
|
5
|
+
@pdf = CceLib::Document.new
|
6
|
+
end
|
7
|
+
|
8
|
+
def save_pdf(filename)
|
9
|
+
generate
|
10
|
+
@pdf.render_file filename
|
11
|
+
end
|
12
|
+
|
13
|
+
def render_pdf
|
14
|
+
generate
|
15
|
+
@pdf.render
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
def generate
|
20
|
+
CceLib::Header.new(@pdf).render
|
21
|
+
CceLib::Barcode.new(@pdf, @xml).render
|
22
|
+
CceLib::NfeKey.new(@pdf, @xml).render
|
23
|
+
CceLib::Protocol.new(@pdf, @xml).render
|
24
|
+
CceLib::Correction.new(@pdf, @xml).render
|
25
|
+
CceLib::Footer.new(@pdf).render
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module BrDanfe
|
2
|
+
module CceLib
|
3
|
+
class Barcode
|
4
|
+
def initialize(pdf, xml)
|
5
|
+
@pdf = pdf
|
6
|
+
@xml = Nokogiri::XML(xml)
|
7
|
+
end
|
8
|
+
|
9
|
+
def render
|
10
|
+
@pdf.box(height: 50) do
|
11
|
+
@pdf.move_down 40
|
12
|
+
barcode = Barby::Code128C.new(nfe_key)
|
13
|
+
barcode.annotate_pdf(@pdf, x: @pdf.cursor, y: @pdf.cursor, height: 40)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
def nfe_key
|
19
|
+
node = @xml.css("procEventoNFe > evento > infEvento > chNFe")
|
20
|
+
return node ? node.text : ""
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module BrDanfe
|
2
|
+
module CceLib
|
3
|
+
class Correction
|
4
|
+
def initialize(pdf, xml)
|
5
|
+
@pdf = pdf
|
6
|
+
@xml = Nokogiri::XML(xml)
|
7
|
+
end
|
8
|
+
|
9
|
+
def render
|
10
|
+
@pdf.box(height: 490) do
|
11
|
+
@pdf.text correction
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
def correction
|
17
|
+
node = @xml.css("procEventoNFe > evento > infEvento > detEvento > xCorrecao")
|
18
|
+
return node ? node.text : ""
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module BrDanfe
|
2
|
+
module CceLib
|
3
|
+
class Document
|
4
|
+
def initialize
|
5
|
+
@document = Prawn::Document.new(
|
6
|
+
page_size: "A4",
|
7
|
+
page_layout: :portrait,
|
8
|
+
left_margin: 30,
|
9
|
+
right_margin: 30,
|
10
|
+
top_margin: 30,
|
11
|
+
botton_margin: 30)
|
12
|
+
|
13
|
+
@document.font "Times-Roman"
|
14
|
+
@document.line_width = 0.3
|
15
|
+
end
|
16
|
+
|
17
|
+
def method_missing(method_name, *args, &block)
|
18
|
+
@document.send(method_name, *args, &block)
|
19
|
+
end
|
20
|
+
|
21
|
+
def box(height:, pad:5, &block)
|
22
|
+
bounding_box([0, cursor], width: page_width, height: height) do
|
23
|
+
pad(pad) { indent(pad) { yield if block_given? } }
|
24
|
+
stroke_bounds
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def text(text, options = {})
|
29
|
+
pad = options.delete(:pad) || 0
|
30
|
+
options = { align: :left, size: 12, style: nil }.merge(options)
|
31
|
+
|
32
|
+
pad(pad) do
|
33
|
+
@document.text text, size: options[:size], style: options[:style],
|
34
|
+
align: options[:align]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
def page_width
|
40
|
+
page.dimensions[2] - (page.margins[:left] + page.margins[:right])
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module BrDanfe
|
2
|
+
module CceLib
|
3
|
+
class NfeKey
|
4
|
+
def initialize(pdf, xml)
|
5
|
+
@pdf = pdf
|
6
|
+
@xml = Nokogiri::XML(xml)
|
7
|
+
end
|
8
|
+
|
9
|
+
def render
|
10
|
+
@pdf.box(height: 36) do
|
11
|
+
@pdf.text I18n.t("cce.key"), size: 8, style: :bold
|
12
|
+
@pdf.text nfe_key, pad: 5
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
def nfe_key
|
18
|
+
node = @xml.css("procEventoNFe > evento > infEvento > chNFe")
|
19
|
+
return node ? node.text : ""
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module BrDanfe
|
2
|
+
module CceLib
|
3
|
+
class Protocol
|
4
|
+
def initialize(pdf, xml)
|
5
|
+
@pdf = pdf
|
6
|
+
@xml = Nokogiri::XML(xml)
|
7
|
+
end
|
8
|
+
|
9
|
+
def render
|
10
|
+
@pdf.box(height: 36) do
|
11
|
+
@pdf.text I18n.t("cce.protocol"), size: 8, style: :bold
|
12
|
+
@pdf.text protocol, pad: 5
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
def protocol
|
18
|
+
node = @xml.css("procEventoNFe > retEvento > infEvento > nProt")
|
19
|
+
return node ? node.text : ""
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/br_danfe/danfe.rb
CHANGED
@@ -3,9 +3,9 @@ module BrDanfe
|
|
3
3
|
attr_reader :options
|
4
4
|
|
5
5
|
def initialize(xml)
|
6
|
-
@xml = XML.new(xml)
|
7
|
-
@pdf = Document.new
|
8
|
-
@options = Options.new
|
6
|
+
@xml = DanfeLib::XML.new(xml)
|
7
|
+
@pdf = DanfeLib::Document.new
|
8
|
+
@options = DanfeLib::Options.new
|
9
9
|
|
10
10
|
create_watermark
|
11
11
|
end
|
@@ -37,11 +37,11 @@ module BrDanfe
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def generate
|
40
|
-
@pdf.stamp("has_no_fiscal_value") if Helper.has_no_fiscal_value?(@xml)
|
40
|
+
@pdf.stamp("has_no_fiscal_value") if DanfeLib::Helper.has_no_fiscal_value?(@xml)
|
41
41
|
|
42
42
|
@pdf.repeat(:all) { repeat_on_each_page }
|
43
43
|
|
44
|
-
DetBody.new(@pdf, @xml).render
|
44
|
+
DanfeLib::DetBody.new(@pdf, @xml).render
|
45
45
|
|
46
46
|
@pdf.page_count.times do |i|
|
47
47
|
@pdf.go_to_page(i + 1)
|
@@ -54,17 +54,17 @@ module BrDanfe
|
|
54
54
|
end
|
55
55
|
|
56
56
|
def repeat_on_each_page
|
57
|
-
Ticket.new(@pdf, @xml).render
|
58
|
-
EmitHeader.new(@pdf, @xml, @options.logo_path).render
|
59
|
-
Emit.new(@pdf, @xml).render
|
60
|
-
Dest.new(@pdf, @xml).render
|
61
|
-
Dup.new(@pdf, @xml).render
|
62
|
-
Icmstot.new(@pdf, @xml).render
|
63
|
-
Transp.new(@pdf, @xml).render
|
64
|
-
nVol = Vol.new(@pdf, @xml).render
|
65
|
-
DetHeader.new(@pdf).render
|
66
|
-
Issqn.new(@pdf, @xml).render
|
67
|
-
Infadic.new(@pdf, @xml).render(nVol)
|
57
|
+
DanfeLib::Ticket.new(@pdf, @xml).render
|
58
|
+
DanfeLib::EmitHeader.new(@pdf, @xml, @options.logo_path).render
|
59
|
+
DanfeLib::Emit.new(@pdf, @xml).render
|
60
|
+
DanfeLib::Dest.new(@pdf, @xml).render
|
61
|
+
DanfeLib::Dup.new(@pdf, @xml).render
|
62
|
+
DanfeLib::Icmstot.new(@pdf, @xml).render
|
63
|
+
DanfeLib::Transp.new(@pdf, @xml).render
|
64
|
+
nVol = DanfeLib::Vol.new(@pdf, @xml).render
|
65
|
+
DanfeLib::DetHeader.new(@pdf).render
|
66
|
+
DanfeLib::Issqn.new(@pdf, @xml).render
|
67
|
+
DanfeLib::Infadic.new(@pdf, @xml).render(nVol)
|
68
68
|
end
|
69
69
|
end
|
70
70
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module BrDanfe
|
2
|
+
module DanfeLib
|
3
|
+
class Cst
|
4
|
+
def self.to_danfe(xml)
|
5
|
+
value = origin(xml)
|
6
|
+
|
7
|
+
if csosn?(xml)
|
8
|
+
value += xml.css("ICMS/*/CSOSN").text
|
9
|
+
elsif cst?(xml)
|
10
|
+
value += xml.css("ICMS/*/CST").text
|
11
|
+
end
|
12
|
+
|
13
|
+
value
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
def self.origin(xml)
|
18
|
+
xml.css("ICMS/*/orig").text
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.cst?(xml)
|
22
|
+
xml.css("ICMS/*/CST").text != ""
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.csosn?(xml)
|
26
|
+
xml.css("ICMS/*/CSOSN").text != ""
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
module BrDanfe
|
2
|
+
module DanfeLib
|
3
|
+
class Dest
|
4
|
+
Y = 8.58
|
5
|
+
|
6
|
+
def initialize(pdf, xml)
|
7
|
+
@pdf = pdf
|
8
|
+
@xml = xml
|
9
|
+
|
10
|
+
@ltitle = Y - 0.42
|
11
|
+
@l1 = Y
|
12
|
+
@l2 = Y + LINE_HEIGHT
|
13
|
+
@l3 = Y + (LINE_HEIGHT * 2)
|
14
|
+
end
|
15
|
+
|
16
|
+
def render
|
17
|
+
@pdf.ititle 0.42, 10.00, 0.25, @ltitle, "dest.title"
|
18
|
+
|
19
|
+
render_line1
|
20
|
+
render_line2
|
21
|
+
render_line3
|
22
|
+
|
23
|
+
render_dates_block
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
def render_line1
|
28
|
+
@pdf.lbox LINE_HEIGHT, 12.32, 0.25, @l1, @xml, "dest/xNome"
|
29
|
+
render_cnpj_cpf
|
30
|
+
end
|
31
|
+
|
32
|
+
def render_cnpj_cpf
|
33
|
+
if @xml["dest/CNPJ"] == ""
|
34
|
+
@pdf.i18n_lbox LINE_HEIGHT, 4.87, 12.57, @l1, "dest.CPF", cpf
|
35
|
+
else
|
36
|
+
@pdf.lcnpj LINE_HEIGHT, 4.87, 12.57, @l1, @xml, "dest/CNPJ"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def cpf
|
41
|
+
cpf = BrDocuments::CnpjCpf::Cpf.new(@xml["dest/CPF"])
|
42
|
+
cpf.formatted
|
43
|
+
end
|
44
|
+
|
45
|
+
def render_line2
|
46
|
+
@pdf.i18n_lbox LINE_HEIGHT, 10.16, 0.25, @l2, "enderDest.xLgr", street
|
47
|
+
@pdf.lbox LINE_HEIGHT, 4.83, 10.41, @l2, @xml, "enderDest/xBairro"
|
48
|
+
@pdf.i18n_lbox LINE_HEIGHT, 2.20, 15.24, @l2, "enderDest.CEP", cep
|
49
|
+
end
|
50
|
+
|
51
|
+
def street
|
52
|
+
@xml["enderDest/xLgr"] + " " + @xml["enderDest/nro"]
|
53
|
+
end
|
54
|
+
|
55
|
+
def cep
|
56
|
+
Cep.format(@xml["enderDest/CEP"])
|
57
|
+
end
|
58
|
+
|
59
|
+
def render_line3
|
60
|
+
@pdf.lbox LINE_HEIGHT, 7.11, 0.25, @l3, @xml, "enderDest/xMun"
|
61
|
+
@pdf.i18n_lbox LINE_HEIGHT, 4.06, 7.36, @l3, "enderDest.fone", phone
|
62
|
+
@pdf.lbox LINE_HEIGHT, 1.14, 11.42, @l3, @xml, "enderDest/UF"
|
63
|
+
@pdf.lie LINE_HEIGHT, 4.88, 12.56, @l3, @xml, "enderDest/UF", "dest/IE"
|
64
|
+
end
|
65
|
+
|
66
|
+
def render_dates_block
|
67
|
+
@pdf.ldate LINE_HEIGHT, 2.92, 17.90, @l1, "ide.dEmi", @xml["ide/dEmi"], { align: :right }
|
68
|
+
|
69
|
+
if @xml.version_310?
|
70
|
+
dSaiEnt = "ide/dhSaiEnt"
|
71
|
+
hSaiEnt = "ide/dhSaiEnt"
|
72
|
+
else
|
73
|
+
dSaiEnt = "ide/dSaiEnt"
|
74
|
+
hSaiEnt = "ide/hSaiEnt"
|
75
|
+
end
|
76
|
+
|
77
|
+
@pdf.ldate LINE_HEIGHT, 2.92, 17.90, @l2, "ide.dSaiEnt", @xml[dSaiEnt], { align: :right }
|
78
|
+
@pdf.ltime LINE_HEIGHT, 2.92, 17.90, @l3, "ide.hSaiEnt", @xml[hSaiEnt], { align: :right }
|
79
|
+
end
|
80
|
+
|
81
|
+
def phone
|
82
|
+
Phone.format(@xml["enderDest/fone"])
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module BrDanfe
|
2
|
+
module DanfeLib
|
3
|
+
class DetBody
|
4
|
+
def initialize(pdf, xml)
|
5
|
+
@pdf = pdf
|
6
|
+
@xml = xml
|
7
|
+
end
|
8
|
+
|
9
|
+
def render
|
10
|
+
options = {
|
11
|
+
column_widths: column_widths,
|
12
|
+
cell_style: { padding: 2, border_width: 0 }
|
13
|
+
}
|
14
|
+
|
15
|
+
@pdf.font_size(6) do
|
16
|
+
@pdf.bounding_box [0.25.cm, Helper.invert(18.17.cm)], width: 21.50.cm, height: 6.37.cm do
|
17
|
+
@pdf.table products, options do |table|
|
18
|
+
table.column(6..13).style(align: :right)
|
19
|
+
table.column(0..13).border_width = 0.3
|
20
|
+
table.column(0..13).border_lines = [:dotted]
|
21
|
+
table.column(0..13).borders = [:bottom]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
def products
|
29
|
+
@xml.collect("xmlns", "det") { |det| product(det) }
|
30
|
+
end
|
31
|
+
|
32
|
+
def product(det)
|
33
|
+
[
|
34
|
+
det.css("prod/cProd").text,
|
35
|
+
Xprod.new(det).render,
|
36
|
+
det.css("prod/NCM").text,
|
37
|
+
Cst.to_danfe(det),
|
38
|
+
det.css("prod/CFOP").text,
|
39
|
+
det.css("prod/uCom").text,
|
40
|
+
numerify(det, "prod/qCom"),
|
41
|
+
numerify(det, "prod/vUnCom"),
|
42
|
+
numerify(det, "prod/vProd"),
|
43
|
+
numerify(det, "ICMS/*/vBC"),
|
44
|
+
numerify(det, "ICMS/*/vICMS"),
|
45
|
+
numerify(det, "IPI/*/vIPI"),
|
46
|
+
numerify(det, "ICMS/*/pICMS"),
|
47
|
+
numerify(det, "IPI/*/pIPI")
|
48
|
+
]
|
49
|
+
end
|
50
|
+
|
51
|
+
def numerify(det, xpath)
|
52
|
+
Helper.numerify(det.css("#{xpath}").text)
|
53
|
+
end
|
54
|
+
|
55
|
+
def column_widths
|
56
|
+
{
|
57
|
+
0 => 2.00.cm,
|
58
|
+
1 => 4.90.cm,
|
59
|
+
2 => 1.30.cm,
|
60
|
+
3 => 0.80.cm,
|
61
|
+
4 => 1.00.cm,
|
62
|
+
5 => 1.00.cm,
|
63
|
+
6 => 1.30.cm,
|
64
|
+
7 => 1.50.cm,
|
65
|
+
8 => 1.50.cm,
|
66
|
+
9 => 1.50.cm,
|
67
|
+
10 => 1.00.cm,
|
68
|
+
11 => 1.00.cm,
|
69
|
+
12 => 0.90.cm,
|
70
|
+
13 => 0.86.cm
|
71
|
+
}
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module BrDanfe
|
2
|
+
module DanfeLib
|
3
|
+
Y = 17.39 + SPACE_BETWEEN_GROUPS
|
4
|
+
|
5
|
+
class DetHeader
|
6
|
+
def initialize(pdf)
|
7
|
+
@pdf = pdf
|
8
|
+
|
9
|
+
@ltitle = Y - 0.42
|
10
|
+
@l1 = Y
|
11
|
+
end
|
12
|
+
|
13
|
+
def render
|
14
|
+
@pdf.ititle 0.42, 10.00, 0.25, @ltitle, "det.title"
|
15
|
+
|
16
|
+
column(2.00, 0.25, "prod.cProd")
|
17
|
+
column(4.90, 2.25, "prod.xProd")
|
18
|
+
column(1.30, 7.15, "prod.NCM")
|
19
|
+
column(0.80, 8.45, "ICMS.CST")
|
20
|
+
column(1.00, 9.25, "prod.CFOP")
|
21
|
+
column(1.00, 10.25, "prod.uCom")
|
22
|
+
column(1.30, 11.25, "prod.qCom")
|
23
|
+
column(1.50, 12.55, "prod.vUnCom")
|
24
|
+
column(1.50, 14.05, "prod.vProd")
|
25
|
+
column(1.50, 15.55, "ICMS.vBC")
|
26
|
+
column(1.00, 17.05, "ICMS.vICMS")
|
27
|
+
column(1.00, 18.05, "IPI.vIPI")
|
28
|
+
column(0.90, 19.05, "ICMS.pICMS")
|
29
|
+
column(0.86, 19.95, "IPI.pIPI")
|
30
|
+
|
31
|
+
@pdf.horizontal_line 0.25.cm, 20.81.cm, at: Helper.invert(18.17.cm)
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
def column(w, x, title)
|
36
|
+
@pdf.ibox 6.70, w, x, @l1, I18n.t("danfe.det.#{title}")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|