br_danfe 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,41 +1,46 @@
1
1
  module BrDanfe
2
2
  class Xprod
3
- def self.generate(det)
4
- xprod = "#{det.css('prod/xProd').text}"
5
-
6
- if has_infAdProd?(det)
7
- xprod += "\n"
8
- xprod += det.css("infAdProd").text
9
- end
10
-
11
- if has_fci?(det)
12
- xprod += "\n"
13
- xprod += I18n.t("danfe.det.prod.xProdFCI", nFCI: det.css('prod/nFCI').text)
14
- end
15
-
16
- if has_st?(det)
17
- xprod += "\n"
18
- xprod += I18n.t("danfe.det.prod.xProdST",
19
- pMVAST: det.css('ICMS/*/pMVAST').text,
20
- pICMSST: det.css('ICMS/*/pICMSST').text,
21
- vBCST: det.css('ICMS/*/vBCST').text,
22
- vICMSST: det.css('ICMS/*/vICMSST').text)
23
- end
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?
24
13
 
25
14
  xprod
26
15
  end
27
16
 
28
17
  private
29
- def self.has_infAdProd?(det)
30
- !det.css("infAdProd").text.empty?
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
31
32
  end
32
33
 
33
- def self.has_fci?(det)
34
- !det.css("prod/nFCI").text.empty?
34
+ def fci
35
+ "\n" + I18n.t("danfe.det.prod.xProdFCI", nFCI: @det.css('prod/nFCI').text)
35
36
  end
36
37
 
37
- def self.has_st?(det)
38
- det.css("ICMS/*/vBCST").text.to_i > 0
38
+ def st
39
+ "\n" + I18n.t("danfe.det.prod.xProdST",
40
+ pMVAST: @det.css('ICMS/*/pMVAST').text,
41
+ pICMSST: @det.css('ICMS/*/pICMSST').text,
42
+ vBCST: @det.css('ICMS/*/vBCST').text,
43
+ vICMSST: @det.css('ICMS/*/vICMSST').text)
39
44
  end
40
45
  end
41
46
  end
@@ -9,7 +9,8 @@ describe "BrDanfe generated pdf files" do
9
9
  it "renders a basic NF-e with namespace" do
10
10
  expect(File.exist?(output_pdf)).to be_false
11
11
 
12
- BrDanfe.generate(output_pdf, "#{base_dir}nfe_with_ns.xml")
12
+ danfe = BrDanfe::Danfe.new(File.read("#{base_dir}nfe_with_ns.xml"))
13
+ danfe.save_pdf output_pdf
13
14
 
14
15
  expect("#{base_dir}nfe_with_ns.xml.fixture.pdf").to be_same_file_as(output_pdf)
15
16
  end
@@ -17,7 +18,8 @@ describe "BrDanfe generated pdf files" do
17
18
  it "renders another basic NF-e without namespace" do
18
19
  expect(File.exist?(output_pdf)).to be_false
19
20
 
20
- BrDanfe.generate(output_pdf, "#{base_dir}nfe_without_ns.xml")
21
+ danfe = BrDanfe::Danfe.new(File.read("#{base_dir}nfe_without_ns.xml"))
22
+ danfe.save_pdf output_pdf
21
23
 
22
24
  expect("#{base_dir}nfe_without_ns.xml.fixture.pdf").to be_same_file_as(output_pdf)
23
25
  end
@@ -25,7 +27,8 @@ describe "BrDanfe generated pdf files" do
25
27
  it "renders a NF-e having FCI in its items" do
26
28
  expect(File.exist?(output_pdf)).to be_false
27
29
 
28
- BrDanfe.generate(output_pdf, "#{base_dir}nfe_with_fci.xml")
30
+ danfe = BrDanfe::Danfe.new(File.read("#{base_dir}nfe_with_fci.xml"))
31
+ danfe.save_pdf output_pdf
29
32
 
30
33
  expect("#{base_dir}nfe_with_fci.xml.fixture.pdf").to be_same_file_as(output_pdf)
31
34
  end
@@ -33,7 +36,8 @@ describe "BrDanfe generated pdf files" do
33
36
  it "renders a Simples Nacional NF-e using CSOSN" do
34
37
  expect(File.exist?(output_pdf)).to be_false
35
38
 
36
- BrDanfe.generate(output_pdf, "#{base_dir}nfe_simples_nacional.xml")
39
+ danfe = BrDanfe::Danfe.new(File.read("#{base_dir}nfe_simples_nacional.xml"))
40
+ danfe.save_pdf output_pdf
37
41
 
38
42
  expect("#{base_dir}nfe_simples_nacional.xml.fixture.pdf").to be_same_file_as(output_pdf)
39
43
  end
@@ -41,8 +45,28 @@ describe "BrDanfe generated pdf files" do
41
45
  it "renders a NF-e with extra volumes" do
42
46
  expect(File.exist?(output_pdf)).to be_false
43
47
 
44
- BrDanfe.generate(output_pdf, "#{base_dir}nfe_with_extra_volumes.xml")
48
+ danfe = BrDanfe::Danfe.new(File.read("#{base_dir}nfe_with_extra_volumes.xml"))
49
+ danfe.save_pdf output_pdf
45
50
 
46
51
  expect("#{base_dir}nfe_with_extra_volumes.xml.fixture.pdf").to be_same_file_as(output_pdf)
47
52
  end
53
+
54
+ it "renders a NF-e with logo" do
55
+ expect(File.exist?(output_pdf)).to be_false
56
+
57
+ danfe = BrDanfe::Danfe.new(File.read("#{base_dir}nfe_with_logo.xml"))
58
+ danfe.options.logo_path = "./spec/fixtures/nfe_with_logo.xml.logo.png"
59
+ danfe.save_pdf output_pdf
60
+
61
+ expect("#{base_dir}nfe_with_logo.xml.fixture.pdf").to be_same_file_as(output_pdf)
62
+ end
63
+
64
+ it "renders a NF-e with CPF" do
65
+ expect(File.exist?(output_pdf)).to be_false
66
+
67
+ danfe = BrDanfe::Danfe.new(File.read("#{base_dir}nfe_with_cpf.xml"))
68
+ danfe.save_pdf output_pdf
69
+
70
+ expect("#{base_dir}nfe_with_cpf.xml.fixture.pdf").to be_same_file_as(output_pdf)
71
+ end
48
72
  end
@@ -0,0 +1 @@
1
+ <NFe xmlns="http://www.portalfiscal.inf.br/nfe"><infNFe versao="2.00" Id="NFe35131260891033000109550010000000011000000016"><ide><cUF>35</cUF><cNF>00000001</cNF><natOp>6101-Venda de producao do estabelecimento</natOp><indPag>1</indPag><mod>55</mod><serie>1</serie><nNF>1</nNF><dEmi>2013-12-28</dEmi><tpNF>1</tpNF><cMunFG>3550308</cMunFG><tpImp>1</tpImp><tpEmis>1</tpEmis><cDV>6</cDV><tpAmb>1</tpAmb><finNFe>1</finNFe><procEmi>0</procEmi><verProc>1</verProc></ide><emit><CNPJ>60891033000109</CNPJ><xNome>KRON INSTRUMENTOS ELETRICOS LTDA</xNome><xFant>KRON INSTRUMENTOS ELETRICOS LTDA</xFant><enderEmit><xLgr>RUA ALEXANDRE DE GUSMAO</xLgr><nro>278</nro><xBairro>SOCORRO</xBairro><cMun>3550308</cMun><xMun>SAO PAULO</xMun><UF>SP</UF><CEP>04760020</CEP><cPais>1058</cPais><xPais>BRASIL</xPais><fone>1155252000</fone></enderEmit><IE>111393871117</IE><CRT>1</CRT></emit><dest><CPF>11144477735</CPF><xNome>Pessoa Fisica</xNome><enderDest><xLgr>Av da Saudade</xLgr><nro>1125</nro><xBairro>Frutal</xBairro><cMun>3552403</cMun><xMun>SUMARE</xMun><UF>SP</UF><CEP>13171320</CEP><cPais>1058</cPais><xPais>BRASIL</xPais><fone>1921046300</fone></enderDest></dest><det nItem="1"><prod><cProd>1</cProd><cEAN/><xProd>Tijolo Macico Tipo A</xProd><NCM>69041000</NCM><EXTIPI>00</EXTIPI><CFOP>6101</CFOP><uCom>MI</uCom><qCom>2.0000</qCom><vUnCom>10.0000000000</vUnCom><vProd>20.00</vProd><cEANTrib/><uTrib>MI</uTrib><qTrib>2.0000</qTrib><vUnTrib>10.0000000000</vUnTrib><indTot>1</indTot></prod><imposto><vTotTrib>5.35</vTotTrib><ICMS><ICMSSN102><orig>0</orig><CSOSN>102</CSOSN></ICMSSN102></ICMS><PIS><PISOutr><CST>99</CST><vBC>0.00</vBC><pPIS>0.00</pPIS><vPIS>0.00</vPIS></PISOutr></PIS><COFINS><COFINSOutr><CST>99</CST><vBC>0.00</vBC><pCOFINS>0.00</pCOFINS><vCOFINS>0.00</vCOFINS></COFINSOutr></COFINS></imposto></det><det nItem="2"><prod><cProd>2</cProd><cEAN/><xProd>Tijolo Macico Tipo B</xProd><NCM>69041000</NCM><EXTIPI>00</EXTIPI><CFOP>6101</CFOP><uCom>MI</uCom><qCom>3.0000</qCom><vUnCom>20.0000000000</vUnCom><vProd>60.00</vProd><cEANTrib/><uTrib>MI</uTrib><qTrib>3.0000</qTrib><vUnTrib>20.0000000000</vUnTrib><indTot>1</indTot></prod><imposto><vTotTrib>16.05</vTotTrib><ICMS><ICMSSN102><orig>0</orig><CSOSN>102</CSOSN></ICMSSN102></ICMS><PIS><PISOutr><CST>99</CST><vBC>0.00</vBC><pPIS>0.00</pPIS><vPIS>0.00</vPIS></PISOutr></PIS><COFINS><COFINSOutr><CST>99</CST><vBC>0.00</vBC><pCOFINS>0.00</pCOFINS><vCOFINS>0.00</vCOFINS></COFINSOutr></COFINS></imposto></det><det nItem="3"><prod><cProd>3</cProd><cEAN/><xProd>Tijolo Macico Tipo C</xProd><NCM>69041000</NCM><EXTIPI>00</EXTIPI><CFOP>6101</CFOP><uCom>MI</uCom><qCom>4.0000</qCom><vUnCom>30.0000000000</vUnCom><vProd>120.00</vProd><cEANTrib/><uTrib>MI</uTrib><qTrib>4.0000</qTrib><vUnTrib>30.0000000000</vUnTrib><indTot>1</indTot></prod><imposto><vTotTrib>32.10</vTotTrib><ICMS><ICMSSN102><orig>0</orig><CSOSN>102</CSOSN></ICMSSN102></ICMS><PIS><PISOutr><CST>99</CST><vBC>0.00</vBC><pPIS>0.00</pPIS><vPIS>0.00</vPIS></PISOutr></PIS><COFINS><COFINSOutr><CST>99</CST><vBC>0.00</vBC><pCOFINS>0.00</pCOFINS><vCOFINS>0.00</vCOFINS></COFINSOutr></COFINS></imposto></det><total><ICMSTot><vBC>0.00</vBC><vICMS>0.00</vICMS><vBCST>0.00</vBCST><vST>0.00</vST><vProd>200.00</vProd><vFrete>0.00</vFrete><vSeg>0.00</vSeg><vDesc>0.00</vDesc><vII>0.00</vII><vIPI>0.00</vIPI><vPIS>0.00</vPIS><vCOFINS>0.00</vCOFINS><vOutro>0.00</vOutro><vNF>200.00</vNF><vTotTrib>53.50</vTotTrib></ICMSTot></total><transp><modFrete>0</modFrete></transp><cobr><fat><nFat>1</nFat></fat><dup><nDup>1</nDup><dVenc>2014-01-27</dVenc><vDup>40.00</vDup></dup><dup><nDup>2</nDup><dVenc>2014-02-26</dVenc><vDup>40.00</vDup></dup><dup><nDup>3</nDup><dVenc>2014-03-28</dVenc><vDup>40.00</vDup></dup><dup><nDup>4</nDup><dVenc>2014-04-27</dVenc><vDup>40.00</vDup></dup><dup><nDup>5</nDup><dVenc>2014-05-27</dVenc><vDup>40.00</vDup></dup></cobr><infAdic><infCpl>DOCUMENTO EMITIDO POR ME OU EPP OPTANTE PELO SIMPLES NACIONAL * NAO GERA DIREITO A CREDITO FISCAL DE IPI * Tributos: R$ 53,50 (26,75%)</infCpl></infAdic></infNFe></NFe>
@@ -0,0 +1 @@
1
+ <NFe xmlns="http://www.portalfiscal.inf.br/nfe"><infNFe versao="2.00" Id="NFe35131260891033000109550010000000011000000016"><ide><cUF>35</cUF><cNF>00000001</cNF><natOp>6101-Venda de producao do estabelecimento</natOp><indPag>1</indPag><mod>55</mod><serie>1</serie><nNF>1</nNF><dEmi>2013-12-28</dEmi><tpNF>1</tpNF><cMunFG>3550308</cMunFG><tpImp>1</tpImp><tpEmis>1</tpEmis><cDV>6</cDV><tpAmb>1</tpAmb><finNFe>1</finNFe><procEmi>0</procEmi><verProc>1</verProc></ide><emit><CNPJ>60891033000109</CNPJ><xNome>KRON INSTRUMENTOS ELETRICOS LTDA</xNome><xFant>KRON INSTRUMENTOS ELETRICOS LTDA</xFant><enderEmit><xLgr>RUA ALEXANDRE DE GUSMAO</xLgr><nro>278</nro><xBairro>SOCORRO</xBairro><cMun>3550308</cMun><xMun>SAO PAULO</xMun><UF>SP</UF><CEP>04760020</CEP><cPais>1058</cPais><xPais>BRASIL</xPais><fone>1155252000</fone></enderEmit><IE>111393871117</IE><CRT>1</CRT></emit><dest><CNPJ>82743287000880</CNPJ><xNome>Schneider Electric Brasil Ltda</xNome><enderDest><xLgr>Av da Saudade</xLgr><nro>1125</nro><xBairro>Frutal</xBairro><cMun>3552403</cMun><xMun>SUMARE</xMun><UF>SP</UF><CEP>13171320</CEP><cPais>1058</cPais><xPais>BRASIL</xPais><fone>1921046300</fone></enderDest><IE>671008375110</IE></dest><det nItem="1"><prod><cProd>1</cProd><cEAN/><xProd>Tijolo Macico Tipo A</xProd><NCM>69041000</NCM><EXTIPI>00</EXTIPI><CFOP>6101</CFOP><uCom>MI</uCom><qCom>2.0000</qCom><vUnCom>10.0000000000</vUnCom><vProd>20.00</vProd><cEANTrib/><uTrib>MI</uTrib><qTrib>2.0000</qTrib><vUnTrib>10.0000000000</vUnTrib><indTot>1</indTot></prod><imposto><vTotTrib>5.35</vTotTrib><ICMS><ICMSSN102><orig>0</orig><CSOSN>102</CSOSN></ICMSSN102></ICMS><PIS><PISOutr><CST>99</CST><vBC>0.00</vBC><pPIS>0.00</pPIS><vPIS>0.00</vPIS></PISOutr></PIS><COFINS><COFINSOutr><CST>99</CST><vBC>0.00</vBC><pCOFINS>0.00</pCOFINS><vCOFINS>0.00</vCOFINS></COFINSOutr></COFINS></imposto></det><det nItem="2"><prod><cProd>2</cProd><cEAN/><xProd>Tijolo Macico Tipo B</xProd><NCM>69041000</NCM><EXTIPI>00</EXTIPI><CFOP>6101</CFOP><uCom>MI</uCom><qCom>3.0000</qCom><vUnCom>20.0000000000</vUnCom><vProd>60.00</vProd><cEANTrib/><uTrib>MI</uTrib><qTrib>3.0000</qTrib><vUnTrib>20.0000000000</vUnTrib><indTot>1</indTot></prod><imposto><vTotTrib>16.05</vTotTrib><ICMS><ICMSSN102><orig>0</orig><CSOSN>102</CSOSN></ICMSSN102></ICMS><PIS><PISOutr><CST>99</CST><vBC>0.00</vBC><pPIS>0.00</pPIS><vPIS>0.00</vPIS></PISOutr></PIS><COFINS><COFINSOutr><CST>99</CST><vBC>0.00</vBC><pCOFINS>0.00</pCOFINS><vCOFINS>0.00</vCOFINS></COFINSOutr></COFINS></imposto></det><det nItem="3"><prod><cProd>3</cProd><cEAN/><xProd>Tijolo Macico Tipo C</xProd><NCM>69041000</NCM><EXTIPI>00</EXTIPI><CFOP>6101</CFOP><uCom>MI</uCom><qCom>4.0000</qCom><vUnCom>30.0000000000</vUnCom><vProd>120.00</vProd><cEANTrib/><uTrib>MI</uTrib><qTrib>4.0000</qTrib><vUnTrib>30.0000000000</vUnTrib><indTot>1</indTot></prod><imposto><vTotTrib>32.10</vTotTrib><ICMS><ICMSSN102><orig>0</orig><CSOSN>102</CSOSN></ICMSSN102></ICMS><PIS><PISOutr><CST>99</CST><vBC>0.00</vBC><pPIS>0.00</pPIS><vPIS>0.00</vPIS></PISOutr></PIS><COFINS><COFINSOutr><CST>99</CST><vBC>0.00</vBC><pCOFINS>0.00</pCOFINS><vCOFINS>0.00</vCOFINS></COFINSOutr></COFINS></imposto></det><total><ICMSTot><vBC>0.00</vBC><vICMS>0.00</vICMS><vBCST>0.00</vBCST><vST>0.00</vST><vProd>200.00</vProd><vFrete>0.00</vFrete><vSeg>0.00</vSeg><vDesc>0.00</vDesc><vII>0.00</vII><vIPI>0.00</vIPI><vPIS>0.00</vPIS><vCOFINS>0.00</vCOFINS><vOutro>0.00</vOutro><vNF>200.00</vNF><vTotTrib>53.50</vTotTrib></ICMSTot></total><transp><modFrete>0</modFrete></transp><cobr><fat><nFat>1</nFat></fat><dup><nDup>1</nDup><dVenc>2014-01-27</dVenc><vDup>40.00</vDup></dup><dup><nDup>2</nDup><dVenc>2014-02-26</dVenc><vDup>40.00</vDup></dup><dup><nDup>3</nDup><dVenc>2014-03-28</dVenc><vDup>40.00</vDup></dup><dup><nDup>4</nDup><dVenc>2014-04-27</dVenc><vDup>40.00</vDup></dup><dup><nDup>5</nDup><dVenc>2014-05-27</dVenc><vDup>40.00</vDup></dup></cobr><infAdic><infCpl>DOCUMENTO EMITIDO POR ME OU EPP OPTANTE PELO SIMPLES NACIONAL * NAO GERA DIREITO A CREDITO FISCAL DE IPI * Tributos: R$ 53,50 (26,75%)</infCpl></infAdic></infNFe></NFe>
@@ -8,7 +8,7 @@ describe BrDanfe::Helper do
8
8
  end
9
9
  end
10
10
 
11
- describe ".without_fiscal_value?" do
11
+ describe ".no_fiscal_value?" do
12
12
  let(:xml_homologation) do
13
13
  xml = <<-eos
14
14
  <nfeProc>
@@ -65,19 +65,19 @@ describe BrDanfe::Helper do
65
65
 
66
66
  context "when XML is unauthorized" do
67
67
  it "returns true" do
68
- expect(BrDanfe::Helper.without_fiscal_value?(xml_unauthorized)).to eq true
68
+ expect(BrDanfe::Helper.has_no_fiscal_value?(xml_unauthorized)).to eq true
69
69
  end
70
70
  end
71
71
 
72
72
  context "when XML is in homologation environment" do
73
73
  it "returns true" do
74
- expect(BrDanfe::Helper.without_fiscal_value?(xml_homologation)).to eq true
74
+ expect(BrDanfe::Helper.has_no_fiscal_value?(xml_homologation)).to eq true
75
75
  end
76
76
  end
77
77
 
78
78
  context "when XML is authorized" do
79
79
  it "returns false" do
80
- expect(BrDanfe::Helper.without_fiscal_value?(xml_authorized)).to eq false
80
+ expect(BrDanfe::Helper.has_no_fiscal_value?(xml_authorized)).to eq false
81
81
  end
82
82
  end
83
83
  end
@@ -3,111 +3,119 @@
3
3
  require "spec_helper"
4
4
 
5
5
  describe BrDanfe::Xprod do
6
- let(:xml_fci) do
7
- xml = <<-eos
8
- <det nItem="1">
9
- <prod>
10
- <xProd>MONITOR DE ARCO ELETRICO</xProd>
11
- <nFCI>12232531-74B2-4FDD-87A6-CF0AD3E55386</nFCI>
12
- </prod>
13
- </det>
14
- eos
15
-
16
- Nokogiri::XML(xml)
17
- end
18
-
19
- let(:xml_st) do
20
- xml = <<-eos
21
- <det nItem="1">
22
- <prod>
23
- <xProd>MONITOR DE ARCO ELETRICO</xProd>
24
- </prod>
25
- <imposto>
26
- <vTotTrib>96.73</vTotTrib>
27
- <ICMS>
28
- <ICMSSN202>
29
- <pMVAST>56.00</pMVAST>
30
- <vBCST>479.82</vBCST>
31
- <pICMSST>17.00</pICMSST>
32
- <vICMSST>29.28</vICMSST>
33
- </ICMSSN202>
34
- </ICMS>
35
- </imposto>
36
- </det>
37
- eos
38
-
39
- Nokogiri::XML(xml)
40
- end
41
-
42
- let(:xml_infAdProd) do
43
- xml = <<-eos
44
- <det nItem="1">
45
- <prod>
46
- <xProd>MONITOR DE ARCO ELETRICO</xProd>
47
- </prod>
48
- <infAdProd>Informações adicionais do produto</infAdProd>
49
- </det>
50
- eos
51
-
52
- Nokogiri::XML(xml)
53
- end
6
+ describe "#render" do
7
+ context "when have FCI" do
8
+ let(:xml_fci) do
9
+ xml = <<-eos
10
+ <det nItem="1">
11
+ <prod>
12
+ <xProd>MONITOR DE ARCO ELETRICO</xProd>
13
+ <nFCI>12232531-74B2-4FDD-87A6-CF0AD3E55386</nFCI>
14
+ </prod>
15
+ </det>
16
+ eos
17
+
18
+ Nokogiri::XML(xml)
19
+ end
54
20
 
55
- let(:xml_IFC_ST_infAdProd) do
56
- xml = <<-eos
57
- <det nItem="1">
58
- <prod>
59
- <xProd>MONITOR DE ARCO ELETRICO</xProd>
60
- <nFCI>12232531-74B2-4FDD-87A6-CF0AD3E55386</nFCI>
61
- </prod>
62
- <imposto>
63
- <vTotTrib>96.73</vTotTrib>
64
- <ICMS>
65
- <ICMSSN202>
66
- <pMVAST>56.00</pMVAST>
67
- <vBCST>479.82</vBCST>
68
- <pICMSST>17.00</pICMSST>
69
- <vICMSST>29.28</vICMSST>
70
- </ICMSSN202>
71
- </ICMS>
72
- </imposto>
73
- <infAdProd>Informações adicionais do produto</infAdProd>
74
- </det>
75
- eos
76
-
77
- Nokogiri::XML(xml)
78
- end
21
+ subject { BrDanfe::Xprod.new(xml_fci) }
79
22
 
80
- describe ".generate" do
81
- context "when have FCI" do
82
23
  it "returns product + FCI" do
83
24
  expected = "MONITOR DE ARCO ELETRICO"
84
25
  expected += "\n"
85
26
  expected +="FCI: 12232531-74B2-4FDD-87A6-CF0AD3E55386"
86
- expect(BrDanfe::Xprod.generate(xml_fci)).to eq expected
27
+ expect(subject.render).to eq expected
87
28
  end
88
29
  end
89
30
 
90
31
  context "when have ST" do
32
+ let(:xml_st) do
33
+ xml = <<-eos
34
+ <det nItem="1">
35
+ <prod>
36
+ <xProd>MONITOR DE ARCO ELETRICO</xProd>
37
+ </prod>
38
+ <imposto>
39
+ <vTotTrib>96.73</vTotTrib>
40
+ <ICMS>
41
+ <ICMSSN202>
42
+ <pMVAST>56.00</pMVAST>
43
+ <vBCST>479.82</vBCST>
44
+ <pICMSST>17.00</pICMSST>
45
+ <vICMSST>29.28</vICMSST>
46
+ </ICMSSN202>
47
+ </ICMS>
48
+ </imposto>
49
+ </det>
50
+ eos
51
+
52
+ Nokogiri::XML(xml)
53
+ end
54
+
55
+ subject { BrDanfe::Xprod.new(xml_st) }
56
+
91
57
  it "returns product + ST" do
92
58
  expected = "MONITOR DE ARCO ELETRICO"
93
59
  expected += "\n"
94
60
  expected += "ST: MVA: 56.00% * Alíq: 17.00% * BC: 479.82 * Vlr: 29.28"
95
61
 
96
- expect(BrDanfe::Xprod.generate(xml_st)).to eq expected
62
+ expect(subject.render).to eq expected
97
63
  end
98
64
  end
99
65
 
100
66
  context "when have infAdProd" do
67
+ let(:xml_infAdProd) do
68
+ xml = <<-eos
69
+ <det nItem="1">
70
+ <prod>
71
+ <xProd>MONITOR DE ARCO ELETRICO</xProd>
72
+ </prod>
73
+ <infAdProd>Informações adicionais do produto</infAdProd>
74
+ </det>
75
+ eos
76
+
77
+ Nokogiri::XML(xml)
78
+ end
79
+
80
+ subject { BrDanfe::Xprod.new(xml_infAdProd) }
81
+
101
82
  it "returns product + infAdProd" do
102
83
  expected = "MONITOR DE ARCO ELETRICO"
103
84
  expected += "\n"
104
85
  expected += "Informações adicionais do produto"
105
86
 
106
- expect(BrDanfe::Xprod.generate(xml_infAdProd)).to eq expected
87
+ expect(subject.render).to eq expected
107
88
  end
108
89
  end
109
90
 
110
91
  context "when have FCI + ST + infAdProd" do
92
+ let(:xml_IFC_ST_infAdProd) do
93
+ xml = <<-eos
94
+ <det nItem="1">
95
+ <prod>
96
+ <xProd>MONITOR DE ARCO ELETRICO</xProd>
97
+ <nFCI>12232531-74B2-4FDD-87A6-CF0AD3E55386</nFCI>
98
+ </prod>
99
+ <imposto>
100
+ <vTotTrib>96.73</vTotTrib>
101
+ <ICMS>
102
+ <ICMSSN202>
103
+ <pMVAST>56.00</pMVAST>
104
+ <vBCST>479.82</vBCST>
105
+ <pICMSST>17.00</pICMSST>
106
+ <vICMSST>29.28</vICMSST>
107
+ </ICMSSN202>
108
+ </ICMS>
109
+ </imposto>
110
+ <infAdProd>Informações adicionais do produto</infAdProd>
111
+ </det>
112
+ eos
113
+
114
+ Nokogiri::XML(xml)
115
+ end
116
+
117
+ subject { BrDanfe::Xprod.new(xml_IFC_ST_infAdProd) }
118
+
111
119
  it "returns product + FCI + ST + infAdProd" do
112
120
  expected = "MONITOR DE ARCO ELETRICO"
113
121
  expected += "\n"
@@ -117,7 +125,7 @@ describe BrDanfe::Xprod do
117
125
  expected += "\n"
118
126
  expected += "ST: MVA: 56.00% * Alíq: 17.00% * BC: 479.82 * Vlr: 29.28"
119
127
 
120
- expect(BrDanfe::Xprod.generate(xml_IFC_ST_infAdProd)).to eq expected
128
+ expect(subject.render).to eq expected
121
129
  end
122
130
  end
123
131
  end
@@ -1,4 +1,6 @@
1
1
  require "simplecov"
2
+ require "codeclimate-test-reporter"
3
+ CodeClimate::TestReporter.start
2
4
  SimpleCov.start
3
5
 
4
6
  require "bundler/setup"
metadata CHANGED
@@ -1,111 +1,125 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: br_danfe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - ASSEINFO
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-24 00:00:00.000000000 Z
11
+ date: 2014-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>='
24
+ - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: prawn
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ! '>='
31
+ - - '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ! '>='
38
+ - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: barby
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ! '>='
45
+ - - '>='
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ! '>='
52
+ - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: i18n
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ! '>='
59
+ - - '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ! '>='
66
+ - - '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: pry
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ! '>='
73
+ - - '>='
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ! '>='
80
+ - - '>='
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rspec
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ! '>='
87
+ - - '>='
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ! '>='
94
+ - - '>='
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: simplecov
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ! '>='
101
+ - - '>='
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ! '>='
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: codeclimate-test-reporter
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
109
123
  - !ruby/object:Gem::Version
110
124
  version: '0'
111
125
  description:
@@ -127,34 +141,40 @@ files:
127
141
  - lib/br_danfe/cnpj.rb
128
142
  - lib/br_danfe/cpf.rb
129
143
  - lib/br_danfe/cst.rb
130
- - lib/br_danfe/danfe_generator.rb
144
+ - lib/br_danfe/danfe.rb
131
145
  - lib/br_danfe/dest.rb
132
- - lib/br_danfe/det.rb
146
+ - lib/br_danfe/det_body.rb
147
+ - lib/br_danfe/det_header.rb
133
148
  - lib/br_danfe/document.rb
134
149
  - lib/br_danfe/dup.rb
135
150
  - lib/br_danfe/emit.rb
136
151
  - lib/br_danfe/helper.rb
137
152
  - lib/br_danfe/icmstot.rb
138
153
  - lib/br_danfe/ie.rb
154
+ - lib/br_danfe/ie_masks.rb
139
155
  - lib/br_danfe/infadic.rb
140
156
  - lib/br_danfe/issqn.rb
141
157
  - lib/br_danfe/options.rb
142
158
  - lib/br_danfe/phone.rb
143
159
  - lib/br_danfe/plate.rb
144
- - lib/br_danfe/ruby_danfe.rb
145
160
  - lib/br_danfe/ticket.rb
146
161
  - lib/br_danfe/transp.rb
147
162
  - lib/br_danfe/version.rb
148
163
  - lib/br_danfe/vol.rb
149
164
  - lib/br_danfe/xml.rb
150
165
  - lib/br_danfe/xprod.rb
151
- - spec/features/ruby_danfe_spec.rb
166
+ - spec/features/br_danfe_spec.rb
152
167
  - spec/fixtures/nfe_simples_nacional.xml
153
168
  - spec/fixtures/nfe_simples_nacional.xml.fixture.pdf
169
+ - spec/fixtures/nfe_with_cpf.xml
170
+ - spec/fixtures/nfe_with_cpf.xml.fixture.pdf
154
171
  - spec/fixtures/nfe_with_extra_volumes.xml
155
172
  - spec/fixtures/nfe_with_extra_volumes.xml.fixture.pdf
156
173
  - spec/fixtures/nfe_with_fci.xml
157
174
  - spec/fixtures/nfe_with_fci.xml.fixture.pdf
175
+ - spec/fixtures/nfe_with_logo.xml
176
+ - spec/fixtures/nfe_with_logo.xml.fixture.pdf
177
+ - spec/fixtures/nfe_with_logo.xml.logo.png
158
178
  - spec/fixtures/nfe_with_ns.xml
159
179
  - spec/fixtures/nfe_with_ns.xml.fixture.pdf
160
180
  - spec/fixtures/nfe_without_ns.xml
@@ -168,7 +188,6 @@ files:
168
188
  - spec/lib/options_spec.rb
169
189
  - spec/lib/phone_spec.rb
170
190
  - spec/lib/plate_spec.rb
171
- - spec/lib/ruby_danfe_spec.rb
172
191
  - spec/lib/xprod_spec.rb
173
192
  - spec/spec_helper.rb
174
193
  - spec/support/be_same_file_as.rb
@@ -182,12 +201,12 @@ require_paths:
182
201
  - lib
183
202
  required_ruby_version: !ruby/object:Gem::Requirement
184
203
  requirements:
185
- - - ! '>='
204
+ - - '>='
186
205
  - !ruby/object:Gem::Version
187
206
  version: '0'
188
207
  required_rubygems_version: !ruby/object:Gem::Requirement
189
208
  requirements:
190
- - - ! '>='
209
+ - - '>='
191
210
  - !ruby/object:Gem::Version
192
211
  version: '0'
193
212
  requirements: []
@@ -197,13 +216,18 @@ signing_key:
197
216
  specification_version: 4
198
217
  summary: DANFE pdf generator for Brazilian invoices.
199
218
  test_files:
200
- - spec/features/ruby_danfe_spec.rb
219
+ - spec/features/br_danfe_spec.rb
201
220
  - spec/fixtures/nfe_simples_nacional.xml
202
221
  - spec/fixtures/nfe_simples_nacional.xml.fixture.pdf
222
+ - spec/fixtures/nfe_with_cpf.xml
223
+ - spec/fixtures/nfe_with_cpf.xml.fixture.pdf
203
224
  - spec/fixtures/nfe_with_extra_volumes.xml
204
225
  - spec/fixtures/nfe_with_extra_volumes.xml.fixture.pdf
205
226
  - spec/fixtures/nfe_with_fci.xml
206
227
  - spec/fixtures/nfe_with_fci.xml.fixture.pdf
228
+ - spec/fixtures/nfe_with_logo.xml
229
+ - spec/fixtures/nfe_with_logo.xml.fixture.pdf
230
+ - spec/fixtures/nfe_with_logo.xml.logo.png
207
231
  - spec/fixtures/nfe_with_ns.xml
208
232
  - spec/fixtures/nfe_with_ns.xml.fixture.pdf
209
233
  - spec/fixtures/nfe_without_ns.xml
@@ -217,7 +241,6 @@ test_files:
217
241
  - spec/lib/options_spec.rb
218
242
  - spec/lib/phone_spec.rb
219
243
  - spec/lib/plate_spec.rb
220
- - spec/lib/ruby_danfe_spec.rb
221
244
  - spec/lib/xprod_spec.rb
222
245
  - spec/spec_helper.rb
223
246
  - spec/support/be_same_file_as.rb