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
data/lib/br_danfe/options.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
module BrDanfe
|
2
|
-
class Options < OpenStruct
|
3
|
-
DEFAULTOPTIONS = {
|
4
|
-
logo_path: ""
|
5
|
-
}
|
6
|
-
|
7
|
-
def initialize(new_options={})
|
8
|
-
options = DEFAULTOPTIONS.merge(config_yaml_load)
|
9
|
-
super options.merge(new_options)
|
10
|
-
end
|
11
|
-
|
12
|
-
private
|
13
|
-
def file
|
14
|
-
File.exists?("config/br_danfe.yml") ? File.open("config/br_danfe.yml").read : ""
|
15
|
-
end
|
16
|
-
|
17
|
-
def config_yaml_load
|
18
|
-
@file_read = YAML.load( file )
|
19
|
-
@file_read ? (@file_read["br_danfe"]||{})["options"] : {}
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
data/lib/br_danfe/phone.rb
DELETED
data/lib/br_danfe/plate.rb
DELETED
data/lib/br_danfe/ticket.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
module BrDanfe
|
2
|
-
class Ticket
|
3
|
-
def initialize(pdf, xml)
|
4
|
-
@pdf = pdf
|
5
|
-
@xml = xml
|
6
|
-
end
|
7
|
-
|
8
|
-
def render
|
9
|
-
@pdf.ibox 0.85, 16.10, 0.25, 0.42, I18n.t("danfe.ticket.xNome", xNome: @xml["emit/xNome"])
|
10
|
-
@pdf.ibox 0.85, 4.10, 0.25, 1.27, I18n.t("danfe.ticket.received_at")
|
11
|
-
@pdf.ibox 0.85, 12.00, 4.35, 1.27, I18n.t("danfe.ticket.receiver")
|
12
|
-
@pdf.ibox 1.70, 4.50, 16.35, 0.42, "", I18n.t("danfe.ticket.document", nNF: @xml["ide/nNF"], serie: @xml["ide/serie"]), {align: :center, valign: :center}
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
data/lib/br_danfe/transp.rb
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
module BrDanfe
|
2
|
-
class Transp
|
3
|
-
Y = 14.47 + SPACE_BETWEEN_GROUPS
|
4
|
-
|
5
|
-
def initialize(pdf, xml)
|
6
|
-
@pdf = pdf
|
7
|
-
@xml = xml
|
8
|
-
|
9
|
-
@ltitle = Y - 0.42
|
10
|
-
@l1 = Y
|
11
|
-
@l2 = Y + LINE_HEIGHT
|
12
|
-
end
|
13
|
-
|
14
|
-
def render
|
15
|
-
@pdf.ititle 0.42, 10.00, 0.25, @ltitle, "transporta.title"
|
16
|
-
|
17
|
-
@pdf.lbox LINE_HEIGHT, 9.02, 0.25, @l1, @xml, "transporta/xNome"
|
18
|
-
@pdf.i18n_lbox LINE_HEIGHT, 2.79, 9.27, @l1, "transp.modFrete.title", mod_frete
|
19
|
-
@pdf.lbox LINE_HEIGHT, 1.78, 12.06, @l1, @xml, "veicTransp/RNTC"
|
20
|
-
@pdf.i18n_lbox LINE_HEIGHT, 2.29, 13.84, @l1, "veicTransp.placa", plate
|
21
|
-
@pdf.lbox LINE_HEIGHT, 0.76, 16.13, @l1, @xml, "veicTransp/UF"
|
22
|
-
@pdf.lcnpj LINE_HEIGHT, 3.94, 16.89, @l1, @xml, "transporta/CNPJ"
|
23
|
-
@pdf.lbox LINE_HEIGHT, 9.02, 0.25, @l2, @xml, "transporta/xEnder"
|
24
|
-
@pdf.lbox LINE_HEIGHT, 6.86, 9.27, @l2, @xml, "transporta/xMun"
|
25
|
-
@pdf.lbox LINE_HEIGHT, 0.76, 16.13, @l2, @xml, "transporta/UF"
|
26
|
-
@pdf.lie LINE_HEIGHT, 3.94, 16.89, @l2, @xml, "transporta/UF", "transporta/IE"
|
27
|
-
end
|
28
|
-
|
29
|
-
private
|
30
|
-
def plate
|
31
|
-
Plate.format(@xml["veicTransp/placa"])
|
32
|
-
end
|
33
|
-
|
34
|
-
def mod_frete
|
35
|
-
case @xml["transp/modFrete"]
|
36
|
-
when "0"
|
37
|
-
modality = "emitter"
|
38
|
-
when "1"
|
39
|
-
modality = "recipient"
|
40
|
-
when "2"
|
41
|
-
modality = "third_party"
|
42
|
-
when "9"
|
43
|
-
modality = "no_freight"
|
44
|
-
end
|
45
|
-
|
46
|
-
I18n.t("danfe.transp.modFrete.#{modality}")
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
data/lib/br_danfe/vol.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
module BrDanfe
|
2
|
-
class Vol
|
3
|
-
Y = 16.59
|
4
|
-
|
5
|
-
def initialize(pdf, xml)
|
6
|
-
@pdf = pdf
|
7
|
-
@xml = xml
|
8
|
-
|
9
|
-
@l1 = Y
|
10
|
-
end
|
11
|
-
|
12
|
-
def render
|
13
|
-
nVol = 0
|
14
|
-
|
15
|
-
@xml.collect("xmlns", "vol") do |det|
|
16
|
-
nVol += 1
|
17
|
-
render_vol(det) if nVol < 2
|
18
|
-
end
|
19
|
-
|
20
|
-
render_blank_boxes if nVol == 0
|
21
|
-
|
22
|
-
nVol
|
23
|
-
end
|
24
|
-
|
25
|
-
private
|
26
|
-
def render_vol(det)
|
27
|
-
@pdf.ibox 0.85, 2.92, 0.25, @l1, I18n.t("danfe.vol.qVol"), det.css("qVol").text
|
28
|
-
@pdf.ibox 0.85, 3.05, 3.17, @l1, I18n.t("danfe.vol.esp"), det.css("esp").text
|
29
|
-
@pdf.ibox 0.85, 3.05, 6.22, @l1, I18n.t("danfe.vol.marca"), det.css("marca").text
|
30
|
-
@pdf.ibox 0.85, 4.83, 9.27, @l1, I18n.t("danfe.vol.nVol")
|
31
|
-
@pdf.inumeric 0.85, 3.43, 14.10, @l1, "vol.pesoB", det.css("pesoB").text, { decimals: 3 }
|
32
|
-
@pdf.inumeric 0.85, 3.30, 17.53, @l1, "vol.pesoL", det.css("pesoL").text, { decimals: 3 }
|
33
|
-
end
|
34
|
-
|
35
|
-
def render_blank_boxes
|
36
|
-
render_vol(@xml)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
data/lib/br_danfe/xml.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
module BrDanfe
|
2
|
-
class XML
|
3
|
-
def css(xpath)
|
4
|
-
@xml.css(xpath)
|
5
|
-
end
|
6
|
-
|
7
|
-
def initialize(xml)
|
8
|
-
@xml = Nokogiri::XML(xml)
|
9
|
-
end
|
10
|
-
|
11
|
-
def [](xpath)
|
12
|
-
node = @xml.css(xpath)
|
13
|
-
return node ? node.text : ""
|
14
|
-
end
|
15
|
-
|
16
|
-
def collect(ns, tag, &block)
|
17
|
-
result = []
|
18
|
-
# Tenta primeiro com uso de namespace
|
19
|
-
begin
|
20
|
-
@xml.xpath("//#{ns}:#{tag}").each do |det|
|
21
|
-
result << yield(det)
|
22
|
-
end
|
23
|
-
rescue
|
24
|
-
# Caso dê erro, tenta sem
|
25
|
-
@xml.xpath("//#{tag}").each do |det|
|
26
|
-
result << yield(det)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
result
|
30
|
-
end
|
31
|
-
|
32
|
-
def version_310?
|
33
|
-
@xml.css("infNFe").attr("versao").to_s == "3.10"
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
data/lib/br_danfe/xprod.rb
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
module BrDanfe
|
2
|
-
class Xprod
|
3
|
-
def initialize(det)
|
4
|
-
@det = det
|
5
|
-
end
|
6
|
-
|
7
|
-
def render
|
8
|
-
xprod = "#{@det.css('prod/xProd').text}"
|
9
|
-
|
10
|
-
xprod += infAdProd if has_infAdProd?
|
11
|
-
xprod += fci if has_fci?
|
12
|
-
xprod += st if has_st?
|
13
|
-
|
14
|
-
xprod
|
15
|
-
end
|
16
|
-
|
17
|
-
private
|
18
|
-
def has_infAdProd?
|
19
|
-
!@det.css("infAdProd").text.empty?
|
20
|
-
end
|
21
|
-
|
22
|
-
def has_fci?
|
23
|
-
!@det.css("prod/nFCI").text.empty?
|
24
|
-
end
|
25
|
-
|
26
|
-
def has_st?
|
27
|
-
@det.css("ICMS/*/vBCST").text.to_i > 0
|
28
|
-
end
|
29
|
-
|
30
|
-
def infAdProd
|
31
|
-
"\n" + @det.css("infAdProd").text
|
32
|
-
end
|
33
|
-
|
34
|
-
def fci
|
35
|
-
"\n" + I18n.t("danfe.det.prod.xProdFCI", nFCI: @det.css('prod/nFCI').text)
|
36
|
-
end
|
37
|
-
|
38
|
-
def st
|
39
|
-
"\n" + I18n.t("danfe.det.prod.xProdST",
|
40
|
-
pMVAST: Helper.numerify(@det.css('ICMS/*/pMVAST').text, 2),
|
41
|
-
pICMSST: Helper.numerify(@det.css('ICMS/*/pICMSST').text, 2),
|
42
|
-
vBCST: Helper.numerify(@det.css('ICMS/*/vBCST').text, 2),
|
43
|
-
vICMSST: Helper.numerify(@det.css('ICMS/*/vICMSST').text, 2))
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|