Class: Facturapi::Helpers::Dte

Inherits:
Object
  • Object
show all
Defined in:
lib/facturapi/helpers/dte.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Dte

Returns a new instance of Dte.



6
7
8
9
10
11
# File 'lib/facturapi/helpers/dte.rb', line 6

def initialize(params = {})
  @encabezado = params[:encabezado]
  self.detalle = params[:detalle]
  self.dsc_rcg_global = params[:dsc_rcg_global]
  self.referencia = params[:referencia]
end

Instance Attribute Details

#detalleObject

Returns the value of attribute detalle.



4
5
6
# File 'lib/facturapi/helpers/dte.rb', line 4

def detalle
  @detalle
end

#dsc_rcg_globalObject

Returns the value of attribute dsc_rcg_global.



4
5
6
# File 'lib/facturapi/helpers/dte.rb', line 4

def dsc_rcg_global
  @dsc_rcg_global
end

#encabezadoObject

Returns the value of attribute encabezado.



4
5
6
# File 'lib/facturapi/helpers/dte.rb', line 4

def encabezado
  @encabezado
end

#idObject

Returns the value of attribute id.



4
5
6
# File 'lib/facturapi/helpers/dte.rb', line 4

def id
  @id
end

#referenciaObject

Returns the value of attribute referencia.



4
5
6
# File 'lib/facturapi/helpers/dte.rb', line 4

def referencia
  @referencia
end

Instance Method Details

#as_nodeObject



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/facturapi/helpers/dte.rb', line 47

def as_node
  doc = XML::Document.new
  param = { 'ID' => id } unless id.blank?
  doc.root = create_node('DTE', version: '1.0') do |dte|
    dte << create_node('Documento', param) do |documento|
      documento << encabezado.as_node
      detalle.each { |d| documento << d.as_node }
      dsc_rcg_global.each { |d| documento << d.as_node } if dsc_rcg_global && dsc_rcg_global.any?
      referencia.each { |r| documento << r.as_node } if referencia && referencia.any?
    end
  end
  doc
end

#autocomplete!Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/facturapi/helpers/dte.rb', line 61

def autocomplete!
  mnt_neto = 0
  mnt_exe = 0
  monto_nf = 0
  detalle.each_with_index do |det, idx|
    det.nro_lin_det = idx + 1 if det.nro_lin_det.blank?
    det.autocomplete!
    mnt_neto += det.monto_item if det.afecto_iva?
    mnt_exe += det.monto_item if det.exento_iva?
    monto_nf += det.monto_item if det.no_fact? || det.no_fact_neg?
  end
  if dsc_rcg_global && dsc_rcg_global.any?
    dsc_rcg_global.each_with_index do |drg, idx|
      drg.nro_lin_dr = idx + 1 if drg.nro_lin_dr.blank?
      if drg.descuento?
        mnt_neto -= drg.valor_dr
      else
        mnt_neto += drg.valor_dr
      end
    end
  end
  if referencia && referencia.any?
    referencia.each_with_index do |ref, idx|
      ref.nro_lin_ref = idx + 1 if ref.nro_lin_ref.blank?
    end
  end
  totales.autocomplete!(
    is_monto_neto: encabezado.id_doc.monto_neto?,
    is_boleta: encabezado.id_doc.boleta?,
    mnt_neto: mnt_neto,
    mnt_exe: mnt_exe,
    monto_nf: monto_nf
  )
  self
end

#to_sObject



97
98
99
# File 'lib/facturapi/helpers/dte.rb', line 97

def to_s
  as_node.to_s
end

#totalesObject



43
44
45
# File 'lib/facturapi/helpers/dte.rb', line 43

def totales
  encabezado.totales
end