br_danfe 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +7 -0
  3. data/.rspec +1 -0
  4. data/.travis.yml +8 -0
  5. data/Gemfile +5 -0
  6. data/README.md +116 -0
  7. data/Rakefile +39 -0
  8. data/br_danfe.gemspec +27 -0
  9. data/config/locales/pt-BR.yml +125 -0
  10. data/lib/br_danfe.rb +12 -0
  11. data/lib/br_danfe/cep.rb +7 -0
  12. data/lib/br_danfe/cnpj.rb +7 -0
  13. data/lib/br_danfe/cpf.rb +7 -0
  14. data/lib/br_danfe/cst.rb +28 -0
  15. data/lib/br_danfe/danfe_generator.rb +54 -0
  16. data/lib/br_danfe/dest.rb +21 -0
  17. data/lib/br_danfe/det.rb +69 -0
  18. data/lib/br_danfe/document.rb +103 -0
  19. data/lib/br_danfe/dup.rb +25 -0
  20. data/lib/br_danfe/emit.rb +45 -0
  21. data/lib/br_danfe/helper.rb +38 -0
  22. data/lib/br_danfe/icmstot.rb +19 -0
  23. data/lib/br_danfe/ie.rb +68 -0
  24. data/lib/br_danfe/infadic.rb +53 -0
  25. data/lib/br_danfe/issqn.rb +12 -0
  26. data/lib/br_danfe/options.rb +22 -0
  27. data/lib/br_danfe/phone.rb +11 -0
  28. data/lib/br_danfe/plate.rb +7 -0
  29. data/lib/br_danfe/ruby_danfe.rb +42 -0
  30. data/lib/br_danfe/ticket.rb +10 -0
  31. data/lib/br_danfe/transp.rb +18 -0
  32. data/lib/br_danfe/version.rb +3 -0
  33. data/lib/br_danfe/vol.rb +23 -0
  34. data/lib/br_danfe/xml.rb +32 -0
  35. data/lib/br_danfe/xprod.rb +41 -0
  36. data/spec/features/ruby_danfe_spec.rb +48 -0
  37. data/spec/fixtures/nfe_simples_nacional.xml +1 -0
  38. data/spec/fixtures/nfe_with_extra_volumes.xml +4 -0
  39. data/spec/fixtures/nfe_with_fci.xml +1 -0
  40. data/spec/fixtures/nfe_with_ns.xml +4 -0
  41. data/spec/fixtures/nfe_without_ns.xml +2 -0
  42. data/spec/lib/cep_spec.rb +10 -0
  43. data/spec/lib/cnpj_spec.rb +10 -0
  44. data/spec/lib/cpf_spec.rb +10 -0
  45. data/spec/lib/cst_spec.rb +51 -0
  46. data/spec/lib/helper_spec.rb +84 -0
  47. data/spec/lib/ie_spec.rb +230 -0
  48. data/spec/lib/options_spec.rb +13 -0
  49. data/spec/lib/phone_spec.rb +19 -0
  50. data/spec/lib/plate_spec.rb +10 -0
  51. data/spec/lib/ruby_danfe_spec.rb +40 -0
  52. data/spec/lib/xprod_spec.rb +124 -0
  53. data/spec/spec_helper.rb +17 -0
  54. data/spec/support/be_same_file_as.rb +9 -0
  55. metadata +223 -0
@@ -0,0 +1,21 @@
1
+ module BrDanfe
2
+ class Dest
3
+ def self.render(pdf, xml)
4
+ pdf.ititle 0.42, 10.00, 0.25, 8.16, "dest.title"
5
+
6
+ pdf.lbox 0.85, 12.32, 0.25, 8.58, xml, "dest/xNome"
7
+ pdf.ibox 0.85, 5.33, 12.57, 8.58, I18n.t("danfe.dest.CNPJ"), Cnpj.format(xml["dest/CNPJ"]) if xml["dest/CNPJ"] != ""
8
+ pdf.ibox 0.85, 5.33, 12.57, 8.58, I18n.t("danfe.dest.CPF"), Cpf.format(xml["dest/CPF"]) if xml["dest/CPF"] != ""
9
+ pdf.idate 0.85, 2.92, 17.90, 8.58, "ide.dEmi", xml["ide/dEmi"], {align: :right}
10
+ pdf.ibox 0.85, 10.16, 0.25, 9.43, I18n.t("danfe.enderDest.xLgr"), xml["enderDest/xLgr"] + " " + xml["enderDest/nro"]
11
+ pdf.lbox 0.85, 4.83, 10.41, 9.43, xml, "enderDest/xBairro"
12
+ pdf.ibox 0.85, 2.67, 15.24, 9.43, I18n.t("danfe.enderDest.CEP"), Cep.format(xml["enderDest/CEP"])
13
+ pdf.idate 0.85, 2.92, 17.90, 9.43, "ide.dSaiEnt", xml["ide/dSaiEnt"], {align: :right}
14
+ pdf.lbox 0.85, 7.11, 0.25, 10.28, xml, "enderDest/xMun"
15
+ pdf.ibox 0.85, 4.06, 7.36, 10.28, I18n.t("danfe.enderDest.fone"), Phone.format(xml["enderDest/fone"])
16
+ pdf.lbox 0.85, 1.14, 11.42, 10.28, xml, "enderDest/UF"
17
+ pdf.ibox 0.85, 5.33, 12.56, 10.28, I18n.t("danfe.dest.IE"), Ie.format(xml["dest/IE"], xml["enderDest/UF"])
18
+ pdf.idate 0.85, 2.92, 17.90, 10.28, "ide.hSaiEnt", xml["ide/dSaiEnt"], {align: :right}
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,69 @@
1
+ module BrDanfe
2
+ class Det
3
+ def self.render_header(pdf, xml)
4
+ pdf.ititle 0.42, 10.00, 0.25, 17.45, "det.title"
5
+
6
+ pdf.ibox 6.70, 2.00, 0.25, 17.87, I18n.t("danfe.det.prod.cProd")
7
+ pdf.ibox 6.70, 4.90, 2.25, 17.87, I18n.t("danfe.det.prod.xProd")
8
+ pdf.ibox 6.70, 1.30, 7.15, 17.87, I18n.t("danfe.det.prod.NCM")
9
+ pdf.ibox 6.70, 0.80, 8.45, 17.87, I18n.t("danfe.det.ICMS.CST")
10
+ pdf.ibox 6.70, 1.00, 9.25, 17.87, I18n.t("danfe.det.prod.CFOP")
11
+ pdf.ibox 6.70, 1.00, 10.25, 17.87, I18n.t("danfe.det.prod.uCom")
12
+ pdf.ibox 6.70, 1.30, 11.25, 17.87, I18n.t("danfe.det.prod.qCom")
13
+ pdf.ibox 6.70, 1.50, 12.55, 17.87, I18n.t("danfe.det.prod.vUnCom")
14
+ pdf.ibox 6.70, 1.50, 14.05, 17.87, I18n.t("danfe.det.prod.vProd")
15
+ pdf.ibox 6.70, 1.50, 15.55, 17.87, I18n.t("danfe.det.ICMS.vBC")
16
+ pdf.ibox 6.70, 1.00, 17.05, 17.87, I18n.t("danfe.det.ICMS.vICMS")
17
+ pdf.ibox 6.70, 1.00, 18.05, 17.87, I18n.t("danfe.det.IPI.vIPI")
18
+ pdf.ibox 6.70, 0.90, 19.05, 17.87, I18n.t("danfe.det.ICMS.pICMS")
19
+ pdf.ibox 6.70, 0.86, 19.95, 17.87, I18n.t("danfe.det.IPI.pIPI")
20
+
21
+ pdf.horizontal_line 0.25.cm, 20.83.cm, at: Helper.invert(18.17.cm)
22
+ end
23
+
24
+ def self.render_body(pdf, xml)
25
+ pdf.font_size(6) do
26
+ pdf.itable 6.37, 21.50, 0.25, 18.17,
27
+ xml.collect("xmlns", "det") { |det|
28
+ [
29
+ det.css("prod/cProd").text,
30
+ Xprod.generate(det),
31
+ det.css("prod/NCM").text,
32
+ Cst.to_danfe(det),
33
+ det.css("prod/CFOP").text,
34
+ det.css("prod/uCom").text,
35
+ Helper.numerify(det.css("prod/qCom").text),
36
+ Helper.numerify(det.css("prod/vUnCom").text),
37
+ Helper.numerify(det.css("prod/vProd").text),
38
+ Helper.numerify(det.css("ICMS/*/vBC").text),
39
+ Helper.numerify(det.css("ICMS/*/vICMS").text),
40
+ Helper.numerify(det.css("IPI/*/vIPI").text),
41
+ Helper.numerify(det.css("ICMS/*/pICMS").text),
42
+ Helper.numerify(det.css("IPI/*/pIPI").text)
43
+ ]
44
+ },
45
+ column_widths: {
46
+ 0 => 2.00.cm,
47
+ 1 => 4.90.cm,
48
+ 2 => 1.30.cm,
49
+ 3 => 0.80.cm,
50
+ 4 => 1.00.cm,
51
+ 5 => 1.00.cm,
52
+ 6 => 1.30.cm,
53
+ 7 => 1.50.cm,
54
+ 8 => 1.50.cm,
55
+ 9 => 1.50.cm,
56
+ 10 => 1.00.cm,
57
+ 11 => 1.00.cm,
58
+ 12 => 0.90.cm,
59
+ 13 => 0.86.cm
60
+ },
61
+ cell_style: {padding: 2, border_width: 0} do |table|
62
+ table.column(6..13).style(align: :right)
63
+ table.column(0..13).border_width = 1
64
+ table.column(0..13).borders = [:bottom]
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,103 @@
1
+ module BrDanfe
2
+ class Document
3
+ def initialize
4
+ @document = Prawn::Document.new(
5
+ page_size: "A4",
6
+ page_layout: :portrait,
7
+ left_margin: 0,
8
+ right_margin: 0,
9
+ top_margin: 0,
10
+ botton_margin: 0
11
+ )
12
+
13
+ @document.font "Times-Roman"
14
+ end
15
+
16
+ def method_missing(method_name, *args, &block)
17
+ @document.send(method_name, *args, &block)
18
+ end
19
+
20
+ def respond_to_missing?(method_name, include_private = false)
21
+ @document.respond_to?(method_name, include_private) || super
22
+ end
23
+
24
+ def ititle(h, w, x, y, i18n)
25
+ title = ""
26
+ title = I18n.t("danfe.#{i18n}") if i18n != ""
27
+
28
+ self.text_box title, size: 10, at: [x.cm, Helper.invert(y.cm) - 2], width: w.cm, height: h.cm, style: :bold
29
+ end
30
+
31
+ def ibarcode(h, w, x, y, info)
32
+ Barby::Code128C.new(info).annotate_pdf(self, x: x.cm, y: Helper.invert(y.cm), width: w.cm, height: h.cm) if info != ""
33
+ end
34
+
35
+ def ibox(h, w, x, y, title = "", info = "", options = {})
36
+ box [x.cm, Helper.invert(y.cm)], w.cm, h.cm, title, info, options
37
+ end
38
+
39
+ def lbox(h, w, x, y, xml, xpath, options = {})
40
+ i18n = xpath.sub("/", ".");
41
+ label = I18n.t("danfe.#{i18n}")
42
+ data = xml[xpath]
43
+
44
+ ibox(h, w, x, y, label, data, options)
45
+ end
46
+
47
+ def idate(h, w, x, y, i18n = "", info = "", options = {})
48
+ tt = info.split("-")
49
+ data = "#{tt[2]}/#{tt[1]}/#{tt[0]}"
50
+
51
+ label = ""
52
+ label = I18n.t("danfe.#{i18n}") if i18n != ""
53
+
54
+ ibox h, w, x, y, label, data, options
55
+ end
56
+
57
+ def lnumeric(h, w, x, y, xml, xpath, options = {})
58
+ i18n = xpath.sub("/", ".");
59
+ data = xml[xpath]
60
+
61
+ inumeric(h, w, x, y, i18n, data, options)
62
+ end
63
+
64
+ def inumeric(h, w, x, y, i18n = "", data = "", options = {})
65
+ label = ""
66
+ label = I18n.t("danfe.#{i18n}") if i18n != ""
67
+
68
+ numeric [x.cm, Helper.invert(y.cm)], w.cm, h.cm, label, data, options
69
+ end
70
+
71
+ def itable(h, w, x, y, data, options = {}, &block)
72
+ self.bounding_box [x.cm, Helper.invert(y.cm)], width: w.cm, height: h.cm do
73
+ self.table data, options do |table|
74
+ yield(table)
75
+ end
76
+ end
77
+ end
78
+
79
+ private
80
+ def numeric(at, w, h, title = "", info = "", options = {})
81
+ options = {
82
+ decimals: 2
83
+ }.merge(options)
84
+
85
+ info = Helper.numerify(info, options[:decimals]) if info != ""
86
+ box at, w, h, title, info, options.merge({align: :right})
87
+ end
88
+
89
+ def box(at, w, h, title = "", info = "", options = {})
90
+ options = {
91
+ align: :left,
92
+ size: 10,
93
+ style: nil,
94
+ valign: :top,
95
+ border: 1
96
+ }.merge(options)
97
+
98
+ self.stroke_rectangle at, w, h if options[:border] == 1
99
+ self.text_box title, size: 6, style: :italic, at: [at[0] + 2, at[1] - 2], width: w - 4, height: 8 if title != ""
100
+ 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]
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,25 @@
1
+ module BrDanfe
2
+ class Dup
3
+ def self.render(pdf, xml)
4
+ pdf.ititle 0.42, 10.00, 0.25, 11.12, "dup.title"
5
+ pdf.ibox 0.85, 20.57, 0.25, 11.51
6
+
7
+ x = 0.25
8
+ y = 11.51
9
+ xml.collect("xmlns", "dup") do |det|
10
+ normal = { size: 6, border: 0 }
11
+ italic = normal.merge({ style: :italic })
12
+
13
+ pdf.ibox 0.85, 2.12, x, y, "", I18n.t("danfe.dup.nDup"), italic
14
+ pdf.ibox 0.85, 2.12, x + 0.70, y, "", det.css("nDup").text, normal
15
+ pdf.ibox 0.85, 2.12, x, y + 0.20, "", I18n.t("danfe.dup.dVenc"), italic
16
+ dtduplicata = det.css("dVenc").text
17
+ dtduplicata = dtduplicata[8,2] + "/" + dtduplicata[5, 2] + "/" + dtduplicata[0, 4]
18
+ pdf.ibox 0.85, 2.12, x + 0.70, y + 0.20, "", dtduplicata, normal
19
+ pdf.ibox 0.85, 2.12, x, y + 0.40, "", I18n.t("danfe.dup.vDup"), italic
20
+ pdf.inumeric 0.85, 1.25, x + 0.70, y + 0.40, "", det.css("vDup").text, normal
21
+ x = x + 2.30
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,45 @@
1
+ module BrDanfe
2
+ class Emit
3
+ def self.render(pdf, xml)
4
+ if BrDanfe.options.logo_path.empty?
5
+ pdf.ibox 3.92, 8.46, 0.25, 2.80, "", xml["emit/xNome"], {size: 12, align: :center, border: 0, style: :bold}
6
+ self.render_address(pdf, xml, 2.54)
7
+ else
8
+ pdf.ibox 3.92, 8.46, 0.25, 2.54
9
+ pdf.ibox 3.92, 8.46, 0.25, 2.80, "", xml["emit/xNome"], {size: 12, align: :center, border: 0, style: :bold}
10
+ self.render_address(pdf, xml, 4)
11
+ pdf.image BrDanfe.options.logo_path, at: [0.5.cm, Helper.invert(4.cm)], width: 2.cm
12
+ end
13
+
14
+ pdf.ibox 3.92, 2.08, 8.71, 2.54
15
+
16
+ pdf.ibox 0.60, 2.08, 8.71, 2.54, "", "DANFE", {size: 12, align: :center, border: 0, style: :bold}
17
+ pdf.ibox 1.20, 2.08, 8.71, 3.14, "", I18n.t("danfe.others.danfe"), {size: 8, align: :center, border: 0}
18
+ pdf.ibox 0.60, 2.08, 8.71, 4.34, "", "#{xml['ide/tpNF']} - " + (xml["ide/tpNF"] == "0" ? I18n.t("danfe.ide.tpNF.entry") : I18n.t("danfe.ide.tpNF.departure")), {size: 8, align: :center, border: 0}
19
+
20
+ pdf.ibox 1.00, 2.08, 8.71, 4.94, "",
21
+ I18n.t("danfe.ide.document", nNF: xml["ide/nNF"], serie: xml["ide/serie"]), {size: 8, align: :center, valign: :center, border: 0, style: :bold}
22
+
23
+ pdf.ibox 2.20, 10.02, 10.79, 2.54
24
+ pdf.ibarcode 1.50, 8.00, 10.9010, 4.44, xml["chNFe"]
25
+ pdf.ibox 0.85, 10.02, 10.79, 4.74, I18n.t("danfe.chNFe"), xml["chNFe"].gsub(/(\d)(?=(\d\d\d\d)+(?!\d))/, "\\1 "), {style: :bold, align: :center}
26
+ pdf.ibox 0.85, 10.02, 10.79, 5.60 , "", I18n.t("danfe.others.sefaz"), {align: :center, size: 8}
27
+ pdf.lbox 0.85, 10.54, 0.25, 6.46, xml, "ide/natOp"
28
+ pdf.ibox 0.85, 10.02, 10.79, 6.46, I18n.t("danfe.infProt"), xml["infProt/nProt"] + " " + Helper.format_date(xml["infProt/dhRecbto"]) , {align: :center}
29
+
30
+ pdf.ibox 0.85, 6.86, 0.25, 7.31, I18n.t("danfe.emit.IE"), Ie.format(xml["emit/IE"], xml["enderEmit/UF"])
31
+ pdf.ibox 0.85, 6.86, 7.11, 7.31, I18n.t("danfe.emit.IE_ST"), Ie.format(xml["emit/IE_ST"], xml["enderEmit/UF"])
32
+ pdf.ibox 0.85, 6.84, 13.97, 7.31, I18n.t("danfe.emit.CNPJ"), Cnpj.format(xml["emit/CNPJ"])
33
+ end
34
+
35
+ private
36
+ def self.render_address(pdf, xml, y)
37
+ pdf.ibox 3.92, 8.46, 0.25, y, "",
38
+ "\n" + xml["enderEmit/xLgr"] + ", " + xml["enderEmit/nro"] + "\n" +
39
+ xml["enderEmit/xBairro"] + " - " + Cep.format(xml["enderEmit/CEP"]) + "\n" +
40
+ xml["enderEmit/xMun"] + "/" + xml["enderEmit/UF"] + "\n" +
41
+ Phone.format(xml["enderEmit/fone"]) + " " + xml["enderEmit/email"],
42
+ { align: :center, valign: :center }
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,38 @@
1
+ module BrDanfe
2
+ class Helper
3
+ def self.numerify(number, decimals = 2)
4
+ return "" if !number || number == ""
5
+ int, frac = ("%.#{decimals}f" % number).split(".")
6
+ int.gsub!(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1\.")
7
+ int + "," + frac
8
+ end
9
+
10
+ def self.invert(y)
11
+ 28.7.cm - y
12
+ end
13
+
14
+ def self.format_date(string)
15
+ formated_date = ""
16
+
17
+ if not string.empty?
18
+ date = DateTime.strptime(string, "%Y-%m-%dT%H:%M:%S")
19
+ formated_date = date.strftime("%d/%m/%Y %H:%M:%S")
20
+ end
21
+
22
+ formated_date
23
+ end
24
+
25
+ def self.without_fiscal_value?(xml)
26
+ homologation?(xml) || unauthorized?(xml)
27
+ end
28
+
29
+ private
30
+ def self.homologation?(xml)
31
+ xml.css("nfeProc/NFe/infNFe/ide/tpAmb").text == "2"
32
+ end
33
+
34
+ def self.unauthorized?(xml)
35
+ xml.css("nfeProc/protNFe/infProt/dhRecbto").empty?
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,19 @@
1
+ module BrDanfe
2
+ class Icmstot
3
+ def self.render(pdf, xml)
4
+ pdf.ititle 0.42, 5.60, 0.25, 12.36, "ICMSTot.title"
5
+
6
+ pdf.lnumeric 0.85, 4.06, 0.25, 12.78, xml, "ICMSTot/vBC"
7
+ pdf.lnumeric 0.85, 4.06, 4.31, 12.78, xml, "ICMSTot/vICMS"
8
+ pdf.lnumeric 0.85, 4.06, 8.37, 12.78, xml, "ICMSTot/vBCST"
9
+ pdf.lnumeric 0.85, 4.06, 12.43, 12.78, xml, "ICMSTot/vST"
10
+ pdf.lnumeric 0.85, 4.32, 16.49, 12.78, xml, "ICMSTot/vProd"
11
+ pdf.lnumeric 0.85, 3.46, 0.25, 13.63, xml, "ICMSTot/vFrete"
12
+ pdf.lnumeric 0.85, 3.46, 3.71, 13.63, xml, "ICMSTot/vSeg"
13
+ pdf.lnumeric 0.85, 3.46, 7.17, 13.63, xml, "ICMSTot/vDesc"
14
+ pdf.lnumeric 0.85, 3.46, 10.63, 13.63, xml, "ICMSTot/vOutro"
15
+ pdf.lnumeric 0.85, 3.46, 14.09, 13.63, xml, "ICMSTot/vIPI"
16
+ pdf.lnumeric 0.85, 3.27, 17.55, 13.63, xml, "ICMSTot/vNF", style: :bold
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,68 @@
1
+ module BrDanfe
2
+ class Ie
3
+ def self.format(ie, uf)
4
+ uf = uf.upcase
5
+
6
+ if ["AL", "AP", "MA", "ES", "MS", "PI", "TO"].include?(uf)
7
+ formated_ie = ie
8
+ end
9
+
10
+ if ["CE", "PB", "RR", "SE"].include?(uf)
11
+ formated_ie = ie.sub(/(\d{8})(\d{1})/, "\\1-\\2")
12
+ end
13
+
14
+ if ["AM", "GO"].include?(uf)
15
+ formated_ie = ie.sub(/(\d{2})(\d{3})(\d{3})(\d{1})/, "\\1.\\2.\\3-\\4")
16
+ end
17
+
18
+ case uf
19
+ when "SP"
20
+ if ie.length == 12
21
+ formated_ie = ie.sub(/(\d{3})(\d{3})(\d{3})(\d{3})/, "\\1.\\2.\\3.\\4")
22
+ else
23
+ formated_ie = ie.sub(/(\w{1})(\d{8})(\d{1})(\d{3})/, "\\1-\\2.\\3/\\4")
24
+ end
25
+ when "BA"
26
+ if ie.length == 8
27
+ formated_ie = ie.sub(/(\d{6})(\d{2})/, "\\1-\\2")
28
+ else
29
+ formated_ie = ie.sub(/(\d{7})(\d{2})/, "\\1-\\2")
30
+ end
31
+ when "RO"
32
+ if ie.length == 9
33
+ formated_ie = ie.sub(/(\d{3})(\d{5})(\d{1})/, "\\1.\\2-\\3")
34
+ else
35
+ formated_ie = ie.sub(/(\d{13})(\d{1})/, "\\1-\\2")
36
+ end
37
+ when "RN"
38
+ if ie.length == 9
39
+ formated_ie = ie.sub(/(\d{2})(\d{3})(\d{3})(\d{1})/, "\\1.\\2.\\3-\\4")
40
+ else
41
+ formated_ie = ie.sub(/(\d{2})(\d{1})(\d{3})(\d{3})(\d{1})/, "\\1.\\2.\\3.\\4-\\5")
42
+ end
43
+ when "AC"
44
+ formated_ie = ie.sub(/(\d{2})(\d{3})(\d{3})(\d{3})(\d{2})/, "\\1.\\2.\\3/\\4-\\5")
45
+ when "DF"
46
+ formated_ie = ie.sub(/(\d{11})(\d{2})/, "\\1-\\2")
47
+ when "MG"
48
+ formated_ie = ie.sub(/(\d{3})(\d{3})(\d{3})(\d{4})/, "\\1.\\2.\\3/\\4")
49
+ when "MT"
50
+ formated_ie = ie.sub(/(\d{10})(\d{1})/, "\\1-\\2")
51
+ when "RJ"
52
+ formated_ie = ie.sub(/(\d{2})(\d{3})(\d{2})(\d{1})/, "\\1.\\2.\\3-\\4")
53
+ when "PR"
54
+ formated_ie = ie.sub(/(\d{8})(\d{2})/, "\\1-\\2")
55
+ when "RS"
56
+ formated_ie = ie.sub(/(\d{3})(\d{7})/, "\\1/\\2")
57
+ when "PE"
58
+ formated_ie = ie.sub(/(\d{7})(\d{2})/, "\\1-\\2")
59
+ when "PA"
60
+ formated_ie = ie.sub(/(\d{2})(\d{6})(\d{1})/, "\\1-\\2-\\3")
61
+ when "SC"
62
+ formated_ie = ie.sub(/(\d{3})(\d{3})(\d{3})/, "\\1.\\2.\\3")
63
+ end
64
+
65
+ formated_ie
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,53 @@
1
+ module BrDanfe
2
+ class Infadic
3
+ def self.render(pdf, xml, nVol)
4
+ pdf.ititle 0.42, 10.00, 0.25, 25.91, "infAdic.title"
5
+
6
+ if nVol > 1
7
+ self.render_extra_volumes(pdf, xml)
8
+ else
9
+ pdf.ibox 3.07, 12.93, 0.25, 26.33, I18n.t("danfe.infAdic.infCpl"), xml["infAdic/infCpl"], {size: 6, valign: :top}
10
+ end
11
+
12
+ pdf.ibox 3.07, 7.62, 13.17, 26.33, I18n.t("danfe.infAdic.reserved")
13
+ end
14
+
15
+ private
16
+ def self.render_extra_volumes(pdf, xml)
17
+ pdf.ibox 3.07, 12.93, 0.25, 26.33, I18n.t("danfe.infAdic.infCpl"), "", {size: 8, valign: :top}
18
+ pdf.ibox 3.07, 12.93, 0.25, 26.60, "", I18n.t("danfe.infAdic.vol.title"), {size: 5, valign: :top, border: 0}
19
+
20
+ volumes = 0
21
+ y = 26.67
22
+ xml.collect("xmlns", "vol") do |det|
23
+ volumes += 1
24
+ if volumes > 1
25
+ self.render_extra_volume(pdf, det, y + 0.10)
26
+ y += 0.15
27
+ end
28
+ end
29
+
30
+ pdf.ibox 2.07, 12.93, 0.25, y + 0.30, "", I18n.t("danfe.infAdic.others"), { size: 6, valign: :top, border: 0 }
31
+ pdf.ibox 2.07, 12.93, 0.25, y + 0.50, "", xml["infAdic/infCpl"], { size: 5, valign: :top, border: 0 }
32
+ end
33
+
34
+ def self.render_extra_volume(pdf, xml, y)
35
+ normal = { size: 4, border: 0 }
36
+ italic = normal.merge({ style: :italic })
37
+ decimal = italic.merge({ decimals: 3 })
38
+
39
+ pdf.ibox 0.35, 0.70, 0.25, y, "", I18n.t("danfe.infAdic.vol.qVol"), normal
40
+ pdf.ibox 0.35, 0.70, 0.90, y, "", xml.css("qVol").text, italic
41
+ pdf.ibox 0.35, 0.50, 1.35, y, "", I18n.t("danfe.infAdic.vol.esp"), normal
42
+ pdf.ibox 0.35, 3.00, 1.75, y, "", xml.css("esp").text, italic
43
+ pdf.ibox 0.35, 0.70, 4.15, y, "", I18n.t("danfe.infAdic.vol.marca"), normal
44
+ pdf.ibox 0.35, 2.00, 4.75, y, "", xml.css("marca").text, italic
45
+ pdf.ibox 0.35, 1.00, 6.10, y, "", I18n.t("danfe.infAdic.vol.nVol"), normal
46
+ pdf.ibox 0.35, 1.00, 6.70, y, "", xml.css("nVol").text, italic
47
+ pdf.ibox 0.35, 1.30, 7.00, y, "", I18n.t("danfe.infAdic.vol.pesoB"), normal
48
+ pdf.inumeric 0.35, 1.30, 7.00, y, "", xml.css("pesoB").text, decimal
49
+ pdf.ibox 0.35, 0.90, 8.50, y, "", I18n.t("danfe.infAdic.vol.pesoL"), normal
50
+ pdf.inumeric 0.35, 1.50, 8.50, y, "", xml.css("pesoL").text, decimal
51
+ end
52
+ end
53
+ end