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.
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
@@ -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
@@ -1,11 +0,0 @@
1
- module BrDanfe
2
- class Phone
3
- def self.format(phone)
4
- if phone.length == 10
5
- phone.sub(/(\d{2})(\d{4})(\d{4})/, "(\\1) \\2-\\3")
6
- else
7
- phone.sub(/(\d{2})(\d{5})(\d{4})/, "(\\1) \\2-\\3")
8
- end
9
- end
10
- end
11
- end
@@ -1,7 +0,0 @@
1
- module BrDanfe
2
- class Plate
3
- def self.format(plate)
4
- plate.sub(/(\w{2})(\d{4})/, "\\1-\\2")
5
- end
6
- end
7
- end
@@ -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
@@ -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
@@ -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