br_danfe 0.0.9 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (150) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +26 -3
  3. data/br_danfe.gemspec +1 -0
  4. data/config/locales/pt-BR.yml +14 -0
  5. data/lib/br_danfe/cce.rb +28 -0
  6. data/lib/br_danfe/cce_lib/barcode.rb +24 -0
  7. data/lib/br_danfe/cce_lib/correction.rb +22 -0
  8. data/lib/br_danfe/cce_lib/document.rb +44 -0
  9. data/lib/br_danfe/cce_lib/footer.rb +15 -0
  10. data/lib/br_danfe/cce_lib/header.rb +15 -0
  11. data/lib/br_danfe/cce_lib/nfe_key.rb +23 -0
  12. data/lib/br_danfe/cce_lib/protocol.rb +23 -0
  13. data/lib/br_danfe/danfe.rb +16 -16
  14. data/lib/br_danfe/danfe_lib/cep.rb +9 -0
  15. data/lib/br_danfe/danfe_lib/consts.rb +6 -0
  16. data/lib/br_danfe/danfe_lib/cst.rb +30 -0
  17. data/lib/br_danfe/danfe_lib/dest.rb +86 -0
  18. data/lib/br_danfe/danfe_lib/det_body.rb +75 -0
  19. data/lib/br_danfe/danfe_lib/det_header.rb +40 -0
  20. data/lib/br_danfe/danfe_lib/document.rb +135 -0
  21. data/lib/br_danfe/danfe_lib/dup.rb +52 -0
  22. data/lib/br_danfe/danfe_lib/emit.rb +23 -0
  23. data/lib/br_danfe/danfe_lib/emit_header.rb +82 -0
  24. data/lib/br_danfe/danfe_lib/helper.rb +64 -0
  25. data/lib/br_danfe/danfe_lib/icmstot.rb +33 -0
  26. data/lib/br_danfe/danfe_lib/infadic.rb +80 -0
  27. data/lib/br_danfe/danfe_lib/issqn.rb +24 -0
  28. data/lib/br_danfe/danfe_lib/options.rb +24 -0
  29. data/lib/br_danfe/danfe_lib/phone.rb +13 -0
  30. data/lib/br_danfe/danfe_lib/plate.rb +9 -0
  31. data/lib/br_danfe/danfe_lib/ticket.rb +17 -0
  32. data/lib/br_danfe/danfe_lib/transp.rb +51 -0
  33. data/lib/br_danfe/danfe_lib/vol.rb +41 -0
  34. data/lib/br_danfe/danfe_lib/xml.rb +38 -0
  35. data/lib/br_danfe/danfe_lib/xprod.rb +48 -0
  36. data/lib/br_danfe/version.rb +1 -1
  37. data/lib/br_danfe.rb +1 -1
  38. data/spec/features/cce_spec.rb +28 -0
  39. data/spec/features/danfe_spec.rb +3 -3
  40. data/spec/fixtures/cce/lib/barcode#render.pdf +511 -0
  41. data/spec/fixtures/cce/lib/correction#render.pdf +100 -0
  42. data/spec/fixtures/cce/lib/document#box.pdf +55 -0
  43. data/spec/fixtures/cce/lib/document#box.with.block.pdf +72 -0
  44. data/spec/fixtures/cce/lib/document#text.align.pdf +70 -0
  45. data/spec/fixtures/cce/lib/document#text.pad.pdf +70 -0
  46. data/spec/fixtures/cce/lib/document#text.simple.pdf +70 -0
  47. data/spec/fixtures/cce/lib/document#text.size.pdf +70 -0
  48. data/spec/fixtures/cce/lib/document#text.style.pdf +70 -0
  49. data/spec/fixtures/cce/lib/footer#render.pdf +114 -0
  50. data/spec/fixtures/cce/lib/header#render.pdf +72 -0
  51. data/spec/fixtures/cce/lib/nfe_key#render.pdf +88 -0
  52. data/spec/fixtures/cce/lib/protocol#render.pdf +88 -0
  53. data/spec/fixtures/cce/v1.00/cce.fixture.pdf +659 -0
  54. data/spec/fixtures/cce/v1.00/cce.xml +1 -0
  55. data/spec/fixtures/{lib → nfe/lib}/dest#render-v2.00.pdf +0 -0
  56. data/spec/fixtures/{lib → nfe/lib}/dest#render-v3.10.pdf +0 -0
  57. data/spec/fixtures/{lib → nfe/lib}/dest#render-with_cnpj.pdf +0 -0
  58. data/spec/fixtures/{lib → nfe/lib}/dest#render-with_cpf.pdf +0 -0
  59. data/spec/fixtures/{lib → nfe/lib}/dest#render-with_ie.pdf +0 -0
  60. data/spec/fixtures/{lib → nfe/lib}/det_body#render-csosn.pdf +0 -0
  61. data/spec/fixtures/{lib → nfe/lib}/det_body#render-cst.pdf +0 -0
  62. data/spec/fixtures/{lib → nfe/lib}/det_body#render-fci.pdf +0 -0
  63. data/spec/fixtures/{lib → nfe/lib}/det_body#render-icms_st.pdf +0 -0
  64. data/spec/fixtures/{lib → nfe/lib}/det_header#render.pdf +0 -0
  65. data/spec/fixtures/{lib → nfe/lib}/document#lcnpj-blank.pdf +0 -0
  66. data/spec/fixtures/{lib → nfe/lib}/document#lcnpj-invalid.pdf +0 -0
  67. data/spec/fixtures/{lib → nfe/lib}/document#lcnpj-valid.pdf +0 -0
  68. data/spec/fixtures/{lib → nfe/lib}/document#lie-blank.pdf +0 -0
  69. data/spec/fixtures/{lib → nfe/lib}/document#lie-invalid.pdf +0 -0
  70. data/spec/fixtures/{lib → nfe/lib}/document#lie-valid.pdf +0 -0
  71. data/spec/fixtures/{lib → nfe/lib}/dup#render.pdf +0 -0
  72. data/spec/fixtures/{lib → nfe/lib}/emit#render.pdf +0 -0
  73. data/spec/fixtures/{lib → nfe/lib}/emit_header#render-with_logo.pdf +0 -0
  74. data/spec/fixtures/{lib → nfe/lib}/emit_header#render-without_logo.pdf +0 -0
  75. data/spec/fixtures/{lib → nfe/lib}/icmstot#render.pdf +0 -0
  76. data/spec/fixtures/{lib → nfe/lib}/infadic#render-extra_volume.pdf +0 -0
  77. data/spec/fixtures/{lib → nfe/lib}/infadic#render.pdf +0 -0
  78. data/spec/fixtures/{lib → nfe/lib}/issqn#render.pdf +0 -0
  79. data/spec/fixtures/{lib → nfe/lib}/ticket#render.pdf +0 -0
  80. data/spec/fixtures/{lib → nfe/lib}/transp#render-modfrete_0.pdf +0 -0
  81. data/spec/fixtures/{lib → nfe/lib}/transp#render-modfrete_1.pdf +0 -0
  82. data/spec/fixtures/{lib → nfe/lib}/transp#render-modfrete_2.pdf +0 -0
  83. data/spec/fixtures/{lib → nfe/lib}/transp#render-modfrete_9.pdf +0 -0
  84. data/spec/fixtures/{lib → nfe/lib}/transp#render.pdf +0 -0
  85. data/spec/fixtures/{lib → nfe/lib}/vol#render-blank-boxes.pdf +0 -0
  86. data/spec/fixtures/{lib → nfe/lib}/vol#render.pdf +0 -0
  87. data/spec/fixtures/{v2.00 → nfe/v2.00}/nfe_simples_nacional.xml +0 -0
  88. data/spec/fixtures/{v2.00 → nfe/v2.00}/nfe_simples_nacional.xml.fixture.pdf +0 -0
  89. data/spec/fixtures/{v2.00 → nfe/v2.00}/nfe_with_extra_volumes.xml +0 -0
  90. data/spec/fixtures/{v2.00 → nfe/v2.00}/nfe_with_extra_volumes.xml.fixture.pdf +0 -0
  91. data/spec/fixtures/{v2.00 → nfe/v2.00}/nfe_with_fci.xml +0 -0
  92. data/spec/fixtures/{v2.00 → nfe/v2.00}/nfe_with_fci.xml.fixture.pdf +0 -0
  93. data/spec/fixtures/{v2.00 → nfe/v2.00}/nfe_with_logo.xml +0 -0
  94. data/spec/fixtures/{v2.00 → nfe/v2.00}/nfe_with_ns.xml +0 -0
  95. data/spec/fixtures/{v2.00 → nfe/v2.00}/nfe_with_ns.xml.fixture.pdf +0 -0
  96. data/spec/fixtures/{v2.00 → nfe/v2.00}/nfe_without_ns.xml +0 -0
  97. data/spec/fixtures/{v2.00 → nfe/v2.00}/nfe_without_ns.xml.fixture.pdf +0 -0
  98. data/spec/fixtures/{v3.10 → nfe/v3.10}/nfe_simples_nacional.xml +0 -0
  99. data/spec/fixtures/{v3.10 → nfe/v3.10}/nfe_simples_nacional.xml.fixture.pdf +0 -0
  100. data/spec/lib/cce_lib/barcode_spec.rb +26 -0
  101. data/spec/lib/cce_lib/correction_spec.rb +26 -0
  102. data/spec/lib/cce_lib/document_spec.rb +115 -0
  103. data/spec/lib/cce_lib/footer_spec.rb +25 -0
  104. data/spec/lib/cce_lib/header_spec.rb +25 -0
  105. data/spec/lib/cce_lib/nfe_key_spec.rb +26 -0
  106. data/spec/lib/cce_lib/protocol_spec.rb +26 -0
  107. data/spec/lib/{cep_spec.rb → danfe_lib/cep_spec.rb} +2 -2
  108. data/spec/lib/{cst_spec.rb → danfe_lib/cst_spec.rb} +3 -3
  109. data/spec/lib/{dest_spec.rb → danfe_lib/dest_spec.rb} +4 -4
  110. data/spec/lib/{det_body_spec.rb → danfe_lib/det_body_spec.rb} +4 -4
  111. data/spec/lib/{det_header_spec.rb → danfe_lib/det_header_spec.rb} +4 -4
  112. data/spec/lib/{document_spec.rb → danfe_lib/document_spec.rb} +3 -3
  113. data/spec/lib/{dup_spec.rb → danfe_lib/dup_spec.rb} +4 -4
  114. data/spec/lib/{emit_header_spec.rb → danfe_lib/emit_header_spec.rb} +4 -4
  115. data/spec/lib/{emit_spec.rb → danfe_lib/emit_spec.rb} +4 -4
  116. data/spec/lib/{helper_spec.rb → danfe_lib/helper_spec.rb} +11 -11
  117. data/spec/lib/{icmstot_spec.rb → danfe_lib/icmstot_spec.rb} +4 -4
  118. data/spec/lib/{infadic_spec.rb → danfe_lib/infadic_spec.rb} +4 -4
  119. data/spec/lib/{issqn_spec.rb → danfe_lib/issqn_spec.rb} +4 -4
  120. data/spec/lib/{options_spec.rb → danfe_lib/options_spec.rb} +3 -3
  121. data/spec/lib/{phone_spec.rb → danfe_lib/phone_spec.rb} +3 -3
  122. data/spec/lib/{plate_spec.rb → danfe_lib/plate_spec.rb} +2 -2
  123. data/spec/lib/{ticket_spec.rb → danfe_lib/ticket_spec.rb} +4 -4
  124. data/spec/lib/{transp_spec.rb → danfe_lib/transp_spec.rb} +4 -4
  125. data/spec/lib/{vol_spec.rb → danfe_lib/vol_spec.rb} +4 -4
  126. data/spec/lib/{xml_spec.rb → danfe_lib/xml_spec.rb} +2 -2
  127. data/spec/lib/{xprod_spec.rb → danfe_lib/xprod_spec.rb} +5 -5
  128. metadata +242 -174
  129. data/lib/br_danfe/cep.rb +0 -7
  130. data/lib/br_danfe/consts.rb +0 -4
  131. data/lib/br_danfe/cst.rb +0 -28
  132. data/lib/br_danfe/dest.rb +0 -84
  133. data/lib/br_danfe/det_body.rb +0 -73
  134. data/lib/br_danfe/det_header.rb +0 -38
  135. data/lib/br_danfe/document.rb +0 -133
  136. data/lib/br_danfe/dup.rb +0 -50
  137. data/lib/br_danfe/emit.rb +0 -21
  138. data/lib/br_danfe/emit_header.rb +0 -80
  139. data/lib/br_danfe/helper.rb +0 -62
  140. data/lib/br_danfe/icmstot.rb +0 -31
  141. data/lib/br_danfe/infadic.rb +0 -78
  142. data/lib/br_danfe/issqn.rb +0 -22
  143. data/lib/br_danfe/options.rb +0 -22
  144. data/lib/br_danfe/phone.rb +0 -11
  145. data/lib/br_danfe/plate.rb +0 -7
  146. data/lib/br_danfe/ticket.rb +0 -15
  147. data/lib/br_danfe/transp.rb +0 -49
  148. data/lib/br_danfe/vol.rb +0 -39
  149. data/lib/br_danfe/xml.rb +0 -36
  150. data/lib/br_danfe/xprod.rb +0 -46
data/lib/br_danfe/dest.rb DELETED
@@ -1,84 +0,0 @@
1
- module BrDanfe
2
- class Dest
3
- Y = 8.58
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
- @l3 = Y + (LINE_HEIGHT * 2)
13
- end
14
-
15
- def render
16
- @pdf.ititle 0.42, 10.00, 0.25, @ltitle, "dest.title"
17
-
18
- render_line1
19
- render_line2
20
- render_line3
21
-
22
- render_dates_block
23
- end
24
-
25
- private
26
- def render_line1
27
- @pdf.lbox LINE_HEIGHT, 12.32, 0.25, @l1, @xml, "dest/xNome"
28
- render_cnpj_cpf
29
- end
30
-
31
- def render_cnpj_cpf
32
- if @xml["dest/CNPJ"] == ""
33
- @pdf.i18n_lbox LINE_HEIGHT, 4.87, 12.57, @l1, "dest.CPF", cpf
34
- else
35
- @pdf.lcnpj LINE_HEIGHT, 4.87, 12.57, @l1, @xml, "dest/CNPJ"
36
- end
37
- end
38
-
39
- def cpf
40
- cpf = BrDocuments::CnpjCpf::Cpf.new(@xml["dest/CPF"])
41
- cpf.formatted
42
- end
43
-
44
- def render_line2
45
- @pdf.i18n_lbox LINE_HEIGHT, 10.16, 0.25, @l2, "enderDest.xLgr", street
46
- @pdf.lbox LINE_HEIGHT, 4.83, 10.41, @l2, @xml, "enderDest/xBairro"
47
- @pdf.i18n_lbox LINE_HEIGHT, 2.20, 15.24, @l2, "enderDest.CEP", cep
48
- end
49
-
50
- def street
51
- @xml["enderDest/xLgr"] + " " + @xml["enderDest/nro"]
52
- end
53
-
54
- def cep
55
- Cep.format(@xml["enderDest/CEP"])
56
- end
57
-
58
- def render_line3
59
- @pdf.lbox LINE_HEIGHT, 7.11, 0.25, @l3, @xml, "enderDest/xMun"
60
- @pdf.i18n_lbox LINE_HEIGHT, 4.06, 7.36, @l3, "enderDest.fone", phone
61
- @pdf.lbox LINE_HEIGHT, 1.14, 11.42, @l3, @xml, "enderDest/UF"
62
- @pdf.lie LINE_HEIGHT, 4.88, 12.56, @l3, @xml, "enderDest/UF", "dest/IE"
63
- end
64
-
65
- def render_dates_block
66
- @pdf.ldate LINE_HEIGHT, 2.92, 17.90, @l1, "ide.dEmi", @xml["ide/dEmi"], { align: :right }
67
-
68
- if @xml.version_310?
69
- dSaiEnt = "ide/dhSaiEnt"
70
- hSaiEnt = "ide/dhSaiEnt"
71
- else
72
- dSaiEnt = "ide/dSaiEnt"
73
- hSaiEnt = "ide/hSaiEnt"
74
- end
75
-
76
- @pdf.ldate LINE_HEIGHT, 2.92, 17.90, @l2, "ide.dSaiEnt", @xml[dSaiEnt], { align: :right }
77
- @pdf.ltime LINE_HEIGHT, 2.92, 17.90, @l3, "ide.hSaiEnt", @xml[hSaiEnt], { align: :right }
78
- end
79
-
80
- def phone
81
- Phone.format(@xml["enderDest/fone"])
82
- end
83
- end
84
- end
@@ -1,73 +0,0 @@
1
- module BrDanfe
2
- class DetBody
3
- def initialize(pdf, xml)
4
- @pdf = pdf
5
- @xml = xml
6
- end
7
-
8
- def render
9
- options = {
10
- column_widths: column_widths,
11
- cell_style: { padding: 2, border_width: 0 }
12
- }
13
-
14
- @pdf.font_size(6) do
15
- @pdf.bounding_box [0.25.cm, Helper.invert(18.17.cm)], width: 21.50.cm, height: 6.37.cm do
16
- @pdf.table products, options do |table|
17
- table.column(6..13).style(align: :right)
18
- table.column(0..13).border_width = 0.3
19
- table.column(0..13).border_lines = [:dotted]
20
- table.column(0..13).borders = [:bottom]
21
- end
22
- end
23
- end
24
- end
25
-
26
- private
27
- def products
28
- @xml.collect("xmlns", "det") { |det| product(det) }
29
- end
30
-
31
- def product(det)
32
- [
33
- det.css("prod/cProd").text,
34
- Xprod.new(det).render,
35
- det.css("prod/NCM").text,
36
- Cst.to_danfe(det),
37
- det.css("prod/CFOP").text,
38
- det.css("prod/uCom").text,
39
- numerify(det, "prod/qCom"),
40
- numerify(det, "prod/vUnCom"),
41
- numerify(det, "prod/vProd"),
42
- numerify(det, "ICMS/*/vBC"),
43
- numerify(det, "ICMS/*/vICMS"),
44
- numerify(det, "IPI/*/vIPI"),
45
- numerify(det, "ICMS/*/pICMS"),
46
- numerify(det, "IPI/*/pIPI")
47
- ]
48
- end
49
-
50
- def numerify(det, xpath)
51
- Helper.numerify(det.css("#{xpath}").text)
52
- end
53
-
54
- def column_widths
55
- {
56
- 0 => 2.00.cm,
57
- 1 => 4.90.cm,
58
- 2 => 1.30.cm,
59
- 3 => 0.80.cm,
60
- 4 => 1.00.cm,
61
- 5 => 1.00.cm,
62
- 6 => 1.30.cm,
63
- 7 => 1.50.cm,
64
- 8 => 1.50.cm,
65
- 9 => 1.50.cm,
66
- 10 => 1.00.cm,
67
- 11 => 1.00.cm,
68
- 12 => 0.90.cm,
69
- 13 => 0.86.cm
70
- }
71
- end
72
- end
73
- end
@@ -1,38 +0,0 @@
1
- module BrDanfe
2
- Y = 17.39 + SPACE_BETWEEN_GROUPS
3
-
4
- class DetHeader
5
- def initialize(pdf)
6
- @pdf = pdf
7
-
8
- @ltitle = Y - 0.42
9
- @l1 = Y
10
- end
11
-
12
- def render
13
- @pdf.ititle 0.42, 10.00, 0.25, @ltitle, "det.title"
14
-
15
- column(2.00, 0.25, "prod.cProd")
16
- column(4.90, 2.25, "prod.xProd")
17
- column(1.30, 7.15, "prod.NCM")
18
- column(0.80, 8.45, "ICMS.CST")
19
- column(1.00, 9.25, "prod.CFOP")
20
- column(1.00, 10.25, "prod.uCom")
21
- column(1.30, 11.25, "prod.qCom")
22
- column(1.50, 12.55, "prod.vUnCom")
23
- column(1.50, 14.05, "prod.vProd")
24
- column(1.50, 15.55, "ICMS.vBC")
25
- column(1.00, 17.05, "ICMS.vICMS")
26
- column(1.00, 18.05, "IPI.vIPI")
27
- column(0.90, 19.05, "ICMS.pICMS")
28
- column(0.86, 19.95, "IPI.pIPI")
29
-
30
- @pdf.horizontal_line 0.25.cm, 20.81.cm, at: Helper.invert(18.17.cm)
31
- end
32
-
33
- private
34
- def column(w, x, title)
35
- @pdf.ibox 6.70, w, x, @l1, I18n.t("danfe.det.#{title}")
36
- end
37
- end
38
- end
@@ -1,133 +0,0 @@
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
- @document.font "Times-Roman"
13
- @document.line_width = 0.3
14
- end
15
-
16
- def method_missing(method_name, *args, &block)
17
- @document.send(method_name, *args, &block)
18
- end
19
-
20
- def ititle(h, w, x, y, i18n)
21
- title = ""
22
- title = I18n.t("danfe.#{i18n}") if i18n != ""
23
-
24
- self.text_box title, size: 8, at: [x.cm, Helper.invert(y.cm) - 4], width: w.cm, height: h.cm, style: :bold
25
- end
26
-
27
- def ibarcode(h, w, x, y, info)
28
- Barby::Code128C.new(info).annotate_pdf(self, x: x.cm, y: Helper.invert(y.cm), width: w.cm, height: h.cm) if info != ""
29
- end
30
-
31
- def ibox(h, w, x, y, title = "", info = "", options = {})
32
- box [x.cm, Helper.invert(y.cm)], w.cm, h.cm, title, info, options
33
- end
34
-
35
- def lbox(h, w, x, y, xml, xpath, options = {})
36
- i18n = xpath.gsub("/", ".");
37
- label = I18n.t("danfe.#{i18n}")
38
- data = xml[xpath]
39
-
40
- ibox(h, w, x, y, label, data, options)
41
- end
42
-
43
- def ldate(h, w, x, y, i18n = "", info = "", options = {})
44
- data = BrDanfe::Helper::format_date(info)
45
- i18n_lbox(h, w, x, y, i18n, data, options)
46
- end
47
-
48
- def ltime(h, w, x, y, i18n = "", info = "", options = {})
49
- data = BrDanfe::Helper::format_time(info)
50
- i18n_lbox(h, w, x, y, i18n, data, options)
51
- end
52
-
53
- def lcnpj(h, w, x, y, xml, xpath, options = {})
54
- i18n = xpath.gsub("/", ".");
55
-
56
- cnpj = BrDocuments::CnpjCpf::Cnpj.new(xml[xpath])
57
- if cnpj.valid?
58
- data = cnpj.formatted
59
- else
60
- data = ""
61
- end
62
-
63
- i18n_lbox(h, w, x, y, i18n, data, options)
64
- end
65
-
66
- def lie(h, w, x, y, xml, xpath_uf, xpath_ie, options = {})
67
- i18n = xpath_ie.gsub("/", ".");
68
-
69
- data = ""
70
- if xml[xpath_uf].present? #BrDocument bug - review this in the future
71
- ie = BrDocuments::IE::Factory.create(xml[xpath_uf], xml[xpath_ie])
72
- data = ie.formatted if ie.valid?
73
- end
74
-
75
- i18n_lbox(h, w, x, y, i18n, data, options)
76
- end
77
-
78
- def lnumeric(h, w, x, y, xml, xpath, options = {})
79
- i18n = xpath.gsub("/", ".");
80
- data = xml[xpath]
81
-
82
- inumeric(h, w, x, y, i18n, data, options)
83
- end
84
-
85
- def inumeric(h, w, x, y, i18n = "", data = "", options = {})
86
- label = ""
87
- label = I18n.t("danfe.#{i18n}") if i18n != ""
88
-
89
- numeric [x.cm, Helper.invert(y.cm)], w.cm, h.cm, label, data, options
90
- end
91
-
92
- def i18n_lbox(h, w, x, y, i18n = "", info = "", options = {})
93
- label = ""
94
- label = I18n.t("danfe.#{i18n}") if i18n != ""
95
-
96
- ibox h, w, x, y, label, info, options
97
- end
98
-
99
- private
100
- def numeric(at, w, h, title = "", info = "", options = {})
101
- options = {
102
- decimals: 2
103
- }.merge(options)
104
-
105
- info = Helper.numerify(info, options[:decimals]) if info != ""
106
- box at, w, h, title, info, options.merge({align: :right})
107
- end
108
-
109
- def box(at, w, h, title = "", info = "", options = {})
110
- options = {
111
- align: :left,
112
- size: 10,
113
- style: nil,
114
- valign: :top,
115
- border: 1
116
- }.merge(options)
117
-
118
- self.stroke_rectangle at, w, h if options[:border] == 1
119
-
120
- at[0] += 2
121
-
122
- if title != ""
123
- title_coord = Array.new(at)
124
- title_coord[1] -= 2
125
- self.text_box title, size: 6, at: title_coord, width: w - 4, height: 8
126
- end
127
-
128
- title_adjustment = title == "" ? 4 : 13
129
- at[1] -= title_adjustment
130
- self.text_box info, size: options[:size], at: at, width: w - 4, height: h - title_adjustment, align: options[:align], style: options[:style], valign: options[:valign]
131
- end
132
- end
133
- end
data/lib/br_danfe/dup.rb DELETED
@@ -1,50 +0,0 @@
1
- module BrDanfe
2
- class Dup
3
- Y = 11.50
4
-
5
- def initialize(pdf, xml)
6
- @pdf = pdf
7
- @xml = xml
8
-
9
- @ltitle = Y - 0.42
10
- end
11
-
12
- def render
13
- @pdf.ititle 0.42, 10.00, 0.25, @ltitle, "dup.title"
14
- @pdf.ibox 0.85, 20.57, 0.25, Y
15
-
16
- x = 0.25
17
- y = Y
18
- @xml.collect("xmlns", "dup") do |det|
19
- render_dup(det, x, y)
20
- x += 2.30
21
- end
22
- end
23
-
24
- private
25
- def render_dup(det, x, y)
26
- @pdf.ibox 0.85, 2.12, x, y, "", I18n.t("danfe.dup.nDup"), italic
27
- @pdf.ibox 0.85, 2.12, x + 0.70, y, "", det.css("nDup").text, normal
28
- @pdf.ibox 0.85, 2.12, x, y + 0.20, "", I18n.t("danfe.dup.dVenc"), italic
29
-
30
- @pdf.ibox 0.85, 2.12, x + 0.70, y + 0.20, "", dtduplicata(det), normal
31
-
32
- @pdf.ibox 0.85, 2.12, x, y + 0.40, "", I18n.t("danfe.dup.vDup"), italic
33
- @pdf.inumeric 0.85, 1.25, x + 0.70, y + 0.40, "", det.css("vDup").text, normal
34
- end
35
-
36
- def dtduplicata(det)
37
- dtduplicata = det.css("dVenc").text
38
- dtduplicata = dtduplicata[8,2] + "/" + dtduplicata[5, 2] + "/" + dtduplicata[0, 4]
39
- dtduplicata
40
- end
41
-
42
- def normal
43
- { size: 6, border: 0 }
44
- end
45
-
46
- def italic
47
- normal.merge({ style: :italic })
48
- end
49
- end
50
- end
data/lib/br_danfe/emit.rb DELETED
@@ -1,21 +0,0 @@
1
- module BrDanfe
2
- class Emit
3
- Y = 6.46
4
-
5
- def initialize(pdf, xml)
6
- @pdf = pdf
7
- @xml = xml
8
-
9
- @l1 = Y
10
- @l2 = Y + LINE_HEIGHT
11
- end
12
-
13
- def render
14
- @pdf.lbox LINE_HEIGHT, 10.54, 0.25, @l1, @xml, "ide/natOp"
15
- @pdf.ibox LINE_HEIGHT, 10.02, 10.79, @l1, I18n.t("danfe.infProt"), @xml["infProt/nProt"] + " " + Helper.format_datetime(@xml["infProt/dhRecbto"]), { align: :center }
16
- @pdf.lie LINE_HEIGHT, 6.86, 0.25, @l2, @xml, "enderEmit/UF", "emit/IE"
17
- @pdf.lie LINE_HEIGHT, 6.86, 7.11, @l2, @xml, "enderEmit/UF", "emit/IE_ST"
18
- @pdf.lcnpj LINE_HEIGHT, 6.84, 13.97, @l2, @xml, "emit/CNPJ"
19
- end
20
- end
21
- end
@@ -1,80 +0,0 @@
1
- module BrDanfe
2
- class EmitHeader
3
- def initialize(pdf, xml, logo_path)
4
- @pdf = pdf
5
- @xml = xml
6
- @logo_path = logo_path
7
- end
8
-
9
- def render
10
- address_box
11
- danfe_box
12
- access_key_box
13
- sefaz_box
14
- end
15
-
16
- private
17
- def address_box
18
- @pdf.ibox 3.92, 8.46, 0.25, 2.54
19
-
20
- @pdf.ibox 3.92, 8.46, 0.25, 2.80, "", @xml["emit/xNome"],
21
- { size: 12, align: :center, border: 0, style: :bold }
22
-
23
- if @logo_path.empty?
24
- @pdf.ibox 3.92, 8.46, 0.75, 4, "", address, { align: :left, border: 0 }
25
- else
26
- @pdf.ibox 3.92, 8.46, 2.75, 4, "", address,
27
- { size: 8, align: :left, border: 0 }
28
-
29
- @pdf.image @logo_path, at: [0.5.cm, Helper.invert(4.cm)],
30
- width: 2.cm
31
- end
32
- end
33
-
34
- def address
35
- formatted = @xml["enderEmit/xLgr"] + ", " + @xml["enderEmit/nro"] + "\n"
36
- formatted += @xml["enderEmit/xBairro"] + " - " + cep + "\n"
37
- formatted += @xml["enderEmit/xMun"] + "/" + @xml["enderEmit/UF"] + "\n"
38
- formatted += phone + " " + @xml["enderEmit/email"]
39
-
40
- formatted
41
- end
42
-
43
- def phone
44
- Phone.format(@xml["enderEmit/fone"])
45
- end
46
-
47
- def cep
48
- Cep.format(@xml["enderEmit/CEP"])
49
- end
50
-
51
- def danfe_box
52
- @pdf.ibox 3.92, 2.08, 8.71, 2.54
53
-
54
- @pdf.ibox 0.60, 2.08, 8.71, 2.54, "", "DANFE",
55
- { size: 12, align: :center, border: 0, style: :bold }
56
-
57
- @pdf.ibox 1.20, 2.08, 8.71, 3.14, "", I18n.t("danfe.others.danfe"),
58
- { size: 8, align: :center, border: 0 }
59
-
60
- @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")),
61
- { size: 8, align: :center, border: 0 }
62
-
63
- @pdf.ibox 1.00, 2.08, 8.71, 4.94, "",
64
- I18n.t("danfe.ide.document", nNF: @xml["ide/nNF"], serie: @xml["ide/serie"]),
65
- { size: 8, align: :center, valign: :center, border: 0, style: :bold }
66
- end
67
-
68
- def access_key_box
69
- @pdf.ibox 2.22, 10.02, 10.79, 2.54
70
- @pdf.ibarcode 1.50, 8.00, 10.9010, 4.44, @xml["chNFe"]
71
- @pdf.ibox 0.85, 10.02, 10.79, 4.76, I18n.t("danfe.chNFe"), @xml["chNFe"].gsub(/(\d)(?=(\d\d\d\d)+(?!\d))/, "\\1 "),
72
- { style: :bold, align: :center }
73
- end
74
-
75
- def sefaz_box
76
- @pdf.ibox 0.85, 10.02, 10.79, 5.61, "", I18n.t("danfe.others.sefaz"),
77
- { align: :center, size: 8 }
78
- end
79
- end
80
- end
@@ -1,62 +0,0 @@
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_datetime(xml_datetime)
15
- formated = ""
16
-
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
- end
21
-
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.strftime("%H:%M:%S")
44
- end
45
-
46
- formated
47
- end
48
-
49
- def self.has_no_fiscal_value?(xml)
50
- homologation?(xml) || unauthorized?(xml)
51
- end
52
-
53
- private
54
- def self.homologation?(xml)
55
- xml.css("nfeProc/NFe/infNFe/ide/tpAmb").text == "2"
56
- end
57
-
58
- def self.unauthorized?(xml)
59
- xml.css("nfeProc/protNFe/infProt/dhRecbto").empty?
60
- end
61
- end
62
- end
@@ -1,31 +0,0 @@
1
- module BrDanfe
2
- class Icmstot
3
- Y = 12.35 + 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, 5.60, 0.25, @ltitle, "ICMSTot.title"
16
-
17
- @pdf.lnumeric LINE_HEIGHT, 4.06, 0.25, @l1, @xml, "ICMSTot/vBC"
18
- @pdf.lnumeric LINE_HEIGHT, 4.06, 4.31, @l1, @xml, "ICMSTot/vICMS"
19
- @pdf.lnumeric LINE_HEIGHT, 4.06, 8.37, @l1, @xml, "ICMSTot/vBCST"
20
- @pdf.lnumeric LINE_HEIGHT, 4.06, 12.43, @l1, @xml, "ICMSTot/vST"
21
- @pdf.lnumeric LINE_HEIGHT, 4.32, 16.49, @l1, @xml, "ICMSTot/vProd"
22
-
23
- @pdf.lnumeric LINE_HEIGHT, 3.05, 0.25, @l2, @xml, "ICMSTot/vFrete"
24
- @pdf.lnumeric LINE_HEIGHT, 3.05, 3.30, @l2, @xml, "ICMSTot/vSeg"
25
- @pdf.lnumeric LINE_HEIGHT, 3.04, 6.35, @l2, @xml, "ICMSTot/vDesc"
26
- @pdf.lnumeric LINE_HEIGHT, 3.04, 9.39, @l2, @xml, "ICMSTot/vOutro"
27
- @pdf.lnumeric LINE_HEIGHT, 4.06, 12.43, @l2, @xml, "ICMSTot/vIPI"
28
- @pdf.lnumeric LINE_HEIGHT, 4.32, 16.49, @l2, @xml, "ICMSTot/vNF", style: :bold
29
- end
30
- end
31
- end
@@ -1,78 +0,0 @@
1
- module BrDanfe
2
- class Infadic
3
- Y = 25.92 + SPACE_BETWEEN_GROUPS
4
-
5
- def initialize(pdf, xml)
6
- @pdf = pdf
7
- @xml = xml
8
-
9
- @ltitle = Y - 0.41
10
- @l1 = Y
11
- end
12
-
13
- def render(nVol)
14
- @pdf.ititle 0.42, 10.00, 0.25, @ltitle, "infAdic.title"
15
-
16
- if nVol > 1
17
- render_extra_volumes
18
- else
19
- @pdf.ibox 3.07, 12.93, 0.25, @l1, I18n.t("danfe.infAdic.infCpl"), @xml["infAdic/infCpl"], { size: 6, valign: :top }
20
- end
21
-
22
- @pdf.ibox 3.07, 7.62, 13.19, @l1, I18n.t("danfe.infAdic.reserved")
23
- end
24
-
25
- private
26
- def render_extra_volumes
27
- @pdf.ibox 3.07, 12.93, 0.25, @l1, I18n.t("danfe.infAdic.infCpl"), "", { size: 8, valign: :top }
28
- @pdf.ibox 3.07, 12.93, 0.25, Y + 0.27, "", I18n.t("danfe.infAdic.vol.title"), { size: 5, valign: :top, border: 0 }
29
-
30
- volumes = 0
31
- y = Y + 0.34
32
- @xml.collect("xmlns", "vol") do |det|
33
- volumes += 1
34
- if volumes > 1
35
- render_extra_volume(det, y + 0.10)
36
- y += 0.15
37
- end
38
- end
39
-
40
- @pdf.ibox 2.07, 12.93, 0.25, y + 0.30, "", I18n.t("danfe.infAdic.others"), { size: 6, valign: :top, border: 0 }
41
- @pdf.ibox 2.07, 12.93, 0.25, y + 0.50, "", @xml["infAdic/infCpl"], { size: 5, valign: :top, border: 0 }
42
- end
43
-
44
- def render_extra_volume(det, y)
45
- render_field "qVol", det, 0.70, 0.25, 0.70, 0.90, y, :text
46
- render_field "esp", det, 0.50, 1.35, 3.00, 1.75, y, :text
47
- render_field "marca", det, 0.70, 4.15, 2.00, 4.75, y, :text
48
- render_field "nVol", det, 1.00, 6.10, 1.00, 6.70, y, :text
49
- render_field "pesoB", det, 1.30, 7.00, 1.30, 7.00, y, :numeric
50
- render_field "pesoL", det, 0.90, 8.50, 1.50, 8.50, y, :numeric
51
- end
52
-
53
- def render_field(field, det, w1, x1, w2, x2, y, kind)
54
- label = I18n.t("danfe.infAdic.vol.#{field}")
55
- value = det.css(field).text
56
-
57
- @pdf.ibox 0.35, w1, x1, y, "", label, style_normal
58
-
59
- if kind == :numeric
60
- @pdf.inumeric 0.35, w2, x2, y, "", value, style_decimal
61
- else
62
- @pdf.ibox 0.35, w2, x2, y, "", value, style_italic
63
- end
64
- end
65
-
66
- def style_normal
67
- { size: 4, border: 0 }
68
- end
69
-
70
- def style_italic
71
- style_normal.merge({ style: :italic })
72
- end
73
-
74
- def style_decimal
75
- style_italic.merge({ decimals: 3 })
76
- end
77
- end
78
- end
@@ -1,22 +0,0 @@
1
- module BrDanfe
2
- class Issqn
3
- Y = 24.60 + 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
- end
12
-
13
- def render
14
- @pdf.ititle 0.42, 10.00, 0.25, @ltitle, "issqn.title"
15
-
16
- @pdf.lbox LINE_HEIGHT, 5.14, 0.25, @l1, @xml, "emit/IM"
17
- @pdf.lnumeric LINE_HEIGHT, 5.14, 5.39, @l1, @xml, "total/ISSQNtot/vServ"
18
- @pdf.lnumeric LINE_HEIGHT, 5.14, 10.53, @l1, @xml, "total/ISSQNtot/vBC"
19
- @pdf.lnumeric LINE_HEIGHT, 5.14, 15.67, @l1, @xml, "total/ISSQNtot/vISS"
20
- end
21
- end
22
- end