class Nfe::Models::Taxes::PISCOFINS
Attributes
cst[RW]
qBCProd[RW]
tax[RW]
vAliqProd[RW]
vBC[RW]
value[RW]
Public Class Methods
new(type)
click to toggle source
# File lib/nfe/models/taxes/PISCOFINS.rb, line 17 def initialize(type) if type == "cofins" @type = "COFINS" else @type = "PIS" end end
Public Instance Methods
parse!(xml)
click to toggle source
# File lib/nfe/models/taxes/PISCOFINS.rb, line 30 def parse!(xml) doc = Nokogiri::XML(xml) reset_values parse_when_aliq(doc) parse_when_qtde(doc) parse_when_nt(doc) parse_when_outr(doc) end
present?()
click to toggle source
# File lib/nfe/models/taxes/PISCOFINS.rb, line 25 def present? @cst.present? || @vBC.present? || @tax.present? || @qBCProd.present? || @vAliqProd.present? || @qBCProd.present? end
to_xml()
click to toggle source
# File lib/nfe/models/taxes/PISCOFINS.rb, line 40 def to_xml xml = Builder::XmlMarkup.new to_xml_when_aliq(xml) to_xml_when_qtde(xml) to_xml_when_nt(xml) to_xml_when_outr(xml) xml.target! end
Private Instance Methods
aliq?()
click to toggle source
# File lib/nfe/models/taxes/PISCOFINS.rb, line 52 def aliq? PISCOFINSAliq.csts.include? @cst end
nt?()
click to toggle source
# File lib/nfe/models/taxes/PISCOFINS.rb, line 60 def nt? PISCOFINSNT.csts.include? @cst end
outr?()
click to toggle source
# File lib/nfe/models/taxes/PISCOFINS.rb, line 64 def outr? PISCOFINSOutr.csts.include? @cst end
parse_when_aliq(doc)
click to toggle source
# File lib/nfe/models/taxes/PISCOFINS.rb, line 78 def parse_when_aliq(doc) if doc.css("#{@type}Aliq").present? aliq = PISCOFINSAliq.new("p#{@type}", "v#{@type}") aliq.parse!(doc.css("#{@type}Aliq").to_xml) @cst = aliq.cst @vBC = aliq.vBC @tax = aliq.tax @value = aliq.value end end
parse_when_nt(doc)
click to toggle source
# File lib/nfe/models/taxes/PISCOFINS.rb, line 102 def parse_when_nt(doc) if doc.css("#{@type}NT").present? nt = PISCOFINSNT.new nt.parse!(doc.css("#{@type}NT").to_xml) @cst = nt.cst end end
parse_when_outr(doc)
click to toggle source
# File lib/nfe/models/taxes/PISCOFINS.rb, line 111 def parse_when_outr(doc) if doc.css("#{@type}Outr").present? outr = PISCOFINSOutr.new("p#{@type}", "v#{@type}") outr.parse!(doc.css("#{@type}Outr").to_xml) @cst = outr.cst @vBC = outr.vBC @tax = outr.tax @qBCProd = outr.qBCProd @vAliqProd = outr.vAliqProd @value = outr.value end end
parse_when_qtde(doc)
click to toggle source
# File lib/nfe/models/taxes/PISCOFINS.rb, line 90 def parse_when_qtde(doc) if doc.css("#{@type}Qtde").present? qtde = PISCOFINSQtde.new("v#{@type}") qtde.parse!(doc.css("#{@type}Qtde").to_xml) @cst = qtde.cst @qBCProd = qtde.qBCProd @vAliqProd = qtde.vAliqProd @value = qtde.value end end
qtde?()
click to toggle source
# File lib/nfe/models/taxes/PISCOFINS.rb, line 56 def qtde? "03" == @cst end
reset_values()
click to toggle source
# File lib/nfe/models/taxes/PISCOFINS.rb, line 68 def reset_values @cst = nil @vBC = nil @tax = nil @value = nil @qBCProd = nil @vAliqProd = nil @qBCProd = nil end
to_xml_when_aliq(xml)
click to toggle source
# File lib/nfe/models/taxes/PISCOFINS.rb, line 125 def to_xml_when_aliq(xml) if aliq? aliq = PISCOFINSAliq.new("p#{@type}", "v#{@type}") aliq.cst = @cst aliq.vBC = @vBC aliq.tax = @tax aliq.value = @value xml.tag!("#{@type}Aliq") { |node| node << aliq.to_xml } end end
to_xml_when_nt(xml)
click to toggle source
# File lib/nfe/models/taxes/PISCOFINS.rb, line 148 def to_xml_when_nt(xml) if nt? nt = PISCOFINSNT.new nt.cst = @cst xml.tag!("#{@type}NT") { |node| node << nt.to_xml } end end
to_xml_when_outr(xml)
click to toggle source
# File lib/nfe/models/taxes/PISCOFINS.rb, line 157 def to_xml_when_outr(xml) if outr? outr = PISCOFINSOutr.new("p#{@type}", "v#{@type}") outr.cst = @cst outr.vBC = @vBC outr.tax = @tax outr.qBCProd = @qBCProd outr.vAliqProd = @vAliqProd outr.value = @value xml.tag!("#{@type}Outr") { |node| node << outr.to_xml } end end
to_xml_when_qtde(xml)
click to toggle source
# File lib/nfe/models/taxes/PISCOFINS.rb, line 137 def to_xml_when_qtde(xml) if qtde? qtde = PISCOFINSQtde.new("v#{@type}") qtde.qBCProd = @qBCProd qtde.vAliqProd = @vAliqProd qtde.value = @value xml.tag!("#{@type}Qtde") { |node| node << qtde.to_xml } end end