Class: FE::Document::Tax

Inherits:
Element show all
Includes:
ActiveModel::Validations
Defined in:
lib/facturacr/document/tax.rb

Constant Summary collapse

TAX_CODES =
{
  "01"=>"Impuesto al Valor Agregado",
  "02"=>"Impuesto Selectivo de Consumo",
  "03"=>"Impuesto Único a los combustibles",
  "04"=>"Impuesto específico de bebidas alcohólicas",
  "05"=>"Impuesto Específico sobre las bebidas envasadas sin contenido alcóholico y jabones de tocador",
  "06"=>"Impuesto a los Productos de Tabaco",
  "07"=>"IVA (cálculo especial)",
  "08"=>"IVA Régimen de Bienes Usados (Factor)",
  "12"=>"Impuesto específico al cemento",
  "99"=>"Otros"
}.freeze
RATE_CODES =
{
  "01"=>"Tarifa 0% (Exento)",
  "02"=>"Tarifa reducida 1%",
  "03"=>"Tarifa reducida 2%",
  "04"=>"Tarifa reducida 4%",
  "05"=>"Transitorio 0%",
  "06"=>"Transitorio 4% ",
  "07"=>"Transitorio 8% ",
  "08"=>"Tarifa general 13%"
}.freeze

Instance Attribute Summary collapse

Attributes inherited from Element

#document, #version

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Tax

validates :iva_factor, presence: true, if: ->{ }



41
42
43
44
45
46
47
48
49
50
# File 'lib/facturacr/document/tax.rb', line 41

def initialize(args={})
  @code = args[:code]
  @rate_code = args[:rate_code]
  @rate = args[:rate]
  @iva_factor = args[:iva_factor]
  @total = args[:total]
  @exoneration = args[:exoneration]
  @total_exportation = args[:total_exportation]

end

Instance Attribute Details

#codeObject

Returns the value of attribute code.



28
29
30
# File 'lib/facturacr/document/tax.rb', line 28

def code
  @code
end

#exonerationObject

Returns the value of attribute exoneration.



28
29
30
# File 'lib/facturacr/document/tax.rb', line 28

def exoneration
  @exoneration
end

#iva_factorObject

Returns the value of attribute iva_factor.



28
29
30
# File 'lib/facturacr/document/tax.rb', line 28

def iva_factor
  @iva_factor
end

#rateObject

Returns the value of attribute rate.



28
29
30
# File 'lib/facturacr/document/tax.rb', line 28

def rate
  @rate
end

#rate_codeObject

Returns the value of attribute rate_code.



28
29
30
# File 'lib/facturacr/document/tax.rb', line 28

def rate_code
  @rate_code
end

#totalObject

Returns the value of attribute total.



28
29
30
# File 'lib/facturacr/document/tax.rb', line 28

def total
  @total
end

#total_exportationObject

Returns the value of attribute total_exportation.



28
29
30
# File 'lib/facturacr/document/tax.rb', line 28

def total_exportation
  @total_exportation
end

Instance Method Details

#build_xml(node, document) ⇒ Object

Raises:



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/facturacr/document/tax.rb', line 53

def build_xml(node, document)
  @document = document
  raise FE::Error.new("tax invalid",class: self.class, messages: errors.messages) unless valid?
  node = Nokogiri::XML::Builder.new if node.nil?

  node.Impuesto do |xml|
    xml.Codigo @code
    xml.CodigoTarifa @rate_code if @rate_code.present? && document.version_43?
    xml.Tarifa @rate
    xml.FactorIva @iva_factor if @iva_factor.present? && document.version_43?
    xml.Monto @total
    xml.MontoExportacion @total_exportation if @total_exportation.present? && document.version_43?

   if exoneration.present?
     exoneration.build_xml(xml,document)
   end

  end
end