Class: Cfdi40::Concepto

Inherits:
Node
  • Object
show all
Defined in:
lib/cfdi40/concepto.rb

Instance Attribute Summary collapse

Attributes inherited from Node

#children_nodes, #element_name, #parent_node, #readonly, #xml_document, #xml_parent

Instance Method Summary collapse

Methods inherited from Node

#add_attributes_to, #add_child_node, #add_children_to, #add_namespaces_to, #attibute_is_null?, attributes, #clean_cached_xml, #create_xml_node, #current_namespace, default_values, define_attribute, define_element_name, define_namespace, define_reader, define_writer, #delete_child, element_name, #expanded_element_name, formats, #formatted_value, #load_from_ng_node, #lock, namespaces, #set_defaults, verify_class_variables

Constructor Details

#initializeConcepto

Returns a new instance of Concepto.



27
28
29
30
31
# File 'lib/cfdi40/concepto.rb', line 27

def initialize
  @tasa_iva = 0.16
  @tasa_ieps = nil
  super
end

Instance Attribute Details

#base_ivaObject (readonly)

Returns the value of attribute base_iva.



22
23
24
# File 'lib/cfdi40/concepto.rb', line 22

def base_iva
  @base_iva
end

#iedu_aut_rvoeObject

accesors for instEducativas



25
26
27
# File 'lib/cfdi40/concepto.rb', line 25

def iedu_aut_rvoe
  @iedu_aut_rvoe
end

#iedu_curpObject

accesors for instEducativas



25
26
27
# File 'lib/cfdi40/concepto.rb', line 25

def iedu_curp
  @iedu_curp
end

#iedu_nivel_educativoObject

accesors for instEducativas



25
26
27
# File 'lib/cfdi40/concepto.rb', line 25

def iedu_nivel_educativo
  @iedu_nivel_educativo
end

#iedu_nombre_alumnoObject

accesors for instEducativas



25
26
27
# File 'lib/cfdi40/concepto.rb', line 25

def iedu_nombre_alumno
  @iedu_nombre_alumno
end

#iedu_rfc_pagoObject

accesors for instEducativas



25
26
27
# File 'lib/cfdi40/concepto.rb', line 25

def iedu_rfc_pago
  @iedu_rfc_pago
end

#iepsObject (readonly)

Returns the value of attribute ieps.



22
23
24
# File 'lib/cfdi40/concepto.rb', line 22

def ieps
  @ieps
end

#importe_brutoObject (readonly)

Returns the value of attribute importe_bruto.



22
23
24
# File 'lib/cfdi40/concepto.rb', line 22

def importe_bruto
  @importe_bruto
end

#importe_netoObject (readonly)

Returns the value of attribute importe_neto.



22
23
24
# File 'lib/cfdi40/concepto.rb', line 22

def importe_neto
  @importe_neto
end

#ivaObject (readonly)

Returns the value of attribute iva.



22
23
24
# File 'lib/cfdi40/concepto.rb', line 22

def iva
  @iva
end

#precio_brutoObject

Returns the value of attribute precio_bruto.



21
22
23
# File 'lib/cfdi40/concepto.rb', line 21

def precio_bruto
  @precio_bruto
end

#precio_netoObject

Returns the value of attribute precio_neto.



21
22
23
# File 'lib/cfdi40/concepto.rb', line 21

def precio_neto
  @precio_neto
end

#tasa_iepsObject

Returns the value of attribute tasa_ieps.



21
22
23
# File 'lib/cfdi40/concepto.rb', line 21

def tasa_ieps
  @tasa_ieps
end

#tasa_ivaObject

Returns the value of attribute tasa_iva.



21
22
23
# File 'lib/cfdi40/concepto.rb', line 21

def tasa_iva
  @tasa_iva
end

Instance Method Details

#calculate!Object

Calculate taxes, amounts from gross price or net price



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/cfdi40/concepto.rb', line 49

def calculate!
  set_defaults
  assign_objeto_imp
  # TODO: accept discount
  if defined?(@precio_neto) && !@precio_neto.nil?
    calculate_from_net_price
  elsif defined?(@precio_bruto) && !@precio_bruto.nil?
    calculate_from_gross_price
  elsif !valor_unitario.nil?
    @precio_bruto = valor_unitario
    calculate_from_gross_price
  end
  add_info_to_traslado_iva
  # TODO: add_info_to_traslado_ieps if @ieps > 0
  add_inst_educativas
  true
end

#descripcion=(desc) ⇒ Object



88
89
90
# File 'lib/cfdi40/concepto.rb', line 88

def descripcion=(desc)
  @descripcion = desc.to_s[0..999]
end

#load_traslado_iva(ng_node) ⇒ Object



83
84
85
86
# File 'lib/cfdi40/concepto.rb', line 83

def load_traslado_iva(ng_node)
  traslado_iva_node.load_from_ng_node(ng_node)
  calculate_from_gross_price
end

#objeto_impuestos?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/cfdi40/concepto.rb', line 67

def objeto_impuestos?
  objeto_impuestos == "02"
end

#traslado_iva_nodeObject



77
78
79
80
81
# File 'lib/cfdi40/concepto.rb', line 77

def traslado_iva_node
  return nil unless impuestos_node.is_a?(ConceptoImpuestos)

  impuestos_node.traslado_iva
end

#traslado_nodesObject



71
72
73
74
75
# File 'lib/cfdi40/concepto.rb', line 71

def traslado_nodes
  return [] if impuestos_node.nil?

  impuestos_node.traslado_nodes
end

#update(attributes = {}) ⇒ Object

Ver Comprobante#add_concepto



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/cfdi40/concepto.rb', line 34

def update(attributes = {})
  attributes.each do |key, value|
    method_name = "#{key}=".to_sym
    raise Error, ":#{key} no se puede asignar al concepto" unless respond_to?(method_name)

    public_send(method_name, value)
  end

  calculate!
  parent_node.parent_node.calculate!
  true
end