Class: Cfdi40::Pago

Inherits:
Node
  • Object
show all
Defined in:
lib/cfdi40/pago.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, #initialize, #load_from_ng_node, #lock, namespaces, #set_defaults, verify_class_variables

Constructor Details

This class inherits a constructor from Cfdi40::Node

Instance Attribute Details

#folioObject

Returns the value of attribute folio.



12
13
14
# File 'lib/cfdi40/pago.rb', line 12

def folio
  @folio
end

#importe_saldo_anteriorObject

Returns the value of attribute importe_saldo_anterior.



12
13
14
# File 'lib/cfdi40/pago.rb', line 12

def importe_saldo_anterior
  @importe_saldo_anterior
end

#num_parcialidadObject

Returns the value of attribute num_parcialidad.



12
13
14
# File 'lib/cfdi40/pago.rb', line 12

def num_parcialidad
  @num_parcialidad
end

#objeto_impuestosObject

Returns the value of attribute objeto_impuestos.



12
13
14
# File 'lib/cfdi40/pago.rb', line 12

def objeto_impuestos
  @objeto_impuestos
end

#serieObject

Returns the value of attribute serie.



12
13
14
# File 'lib/cfdi40/pago.rb', line 12

def serie
  @serie
end

#uuidObject

Returns the value of attribute uuid.



12
13
14
# File 'lib/cfdi40/pago.rb', line 12

def uuid
  @uuid
end

Instance Method Details

#add_docto_relacionado(attributes = {}) ⇒ Object

Generate docto_relacionado node Data for dcto_relacionado node is obtained from de accessors

uuid, serie, folio


17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/cfdi40/pago.rb', line 17

def add_docto_relacionado(attributes = {})
  docto_relacionado = DoctoRelacionado.new
  docto_relacionado.parent_node = self
  docto_relacionado.id_documento = attributes[:uuid]
  docto_relacionado.serie = attributes[:serie]
  docto_relacionado.folio = attributes[:folio]
  docto_relacionado.num_parcialidad = attributes[:num_parcialidad]
  docto_relacionado.imp_saldo_ant = attributes[:importe_saldo_anterior].round(2)
  docto_relacionado.imp_pagado = attributes[:imp_pagado]
  docto_relacionado.calculate!
  @children_nodes << docto_relacionado
end

#add_impuestos_pObject



30
31
32
33
34
# File 'lib/cfdi40/pago.rb', line 30

def add_impuestos_p
  impuestos_p = ImpuestosP.new
  add_child_node impuestos_p
  impuestos_p.traslados_p.add_traslado_p_nodes
end

#docto_relacionadosObject



36
37
38
39
40
41
42
43
# File 'lib/cfdi40/pago.rb', line 36

def docto_relacionados
  return @docto_relacionados if defined?(@docto_relacionados)

  @docto_relacionados =
    @children_nodes.select do |child|
      child.instance_of?(::Cfdi40::DoctoRelacionado)
    end
end

#impuestos_p_nodeObject



69
70
71
# File 'lib/cfdi40/pago.rb', line 69

def impuestos_p_node
  @children_nodes.select { |child| child.instance_of?(Cfdi40::ImpuestosP) }.first
end

#load_dr(dr_node) ⇒ Object



59
60
61
62
63
64
65
66
67
# File 'lib/cfdi40/pago.rb', line 59

def load_dr(dr_node)
  dr = DoctoRelacionado.new
  dr.load_from_ng_node(dr_node)
  dr.parent_node = self
  @children_nodes << dr
  imp_dr_node = dr_node.xpath("//pago20:ImpuestosDR", Cfdi40::Pagos::NG_NAMESPACE).first
  dr.load_impuestos_dr(imp_dr_node) unless imp_dr_node.nil?
  dr
end

#load_impuestos_p(ng_node) ⇒ Object



73
74
75
76
77
78
79
80
# File 'lib/cfdi40/pago.rb', line 73

def load_impuestos_p(ng_node)
  imp_p = ImpuestosP.new
  imp_p.load_from_ng_node(ng_node)
  add_child_node imp_p
  trns_p_node = ng_node.xpath("//pago20:TrasladosP", { "pago20" => "http://www.sat.gob.mx/Pagos20" }).first
  imp_p.load_traslados_p_node(trns_p_node)
  imp_p
end

#traslados_summaryObject



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/cfdi40/pago.rb', line 45

def traslados_summary
  return @summary if defined?(@summary)

  summary = {}
  docto_relacionados.each do |docto|
    docto.traslados_summary.each do |key, data|
      summary[key] ||= { base: 0, importe: 0 }
      summary[key][:base] += data[:base]
      summary[key][:importe] += data[:importe]
    end
  end
  @summary = summary
end