Class: DtefacilXmlBuilder::DteReader
- Inherits:
-
Object
- Object
- DtefacilXmlBuilder::DteReader
- Defined in:
- lib/dtefacil_xml_builder/dte_reader.rb
Instance Attribute Summary collapse
-
#detalles ⇒ Object
Returns the value of attribute detalles.
-
#fecha_emision ⇒ Object
Returns the value of attribute fecha_emision.
-
#folio ⇒ Object
Returns the value of attribute folio.
-
#monto ⇒ Object
Returns the value of attribute monto.
-
#receptor ⇒ Object
Returns the value of attribute receptor.
-
#tipo ⇒ Object
Returns the value of attribute tipo.
Instance Method Summary collapse
Instance Attribute Details
#detalles ⇒ Object
Returns the value of attribute detalles.
6 7 8 |
# File 'lib/dtefacil_xml_builder/dte_reader.rb', line 6 def detalles @detalles end |
#fecha_emision ⇒ Object
Returns the value of attribute fecha_emision.
6 7 8 |
# File 'lib/dtefacil_xml_builder/dte_reader.rb', line 6 def fecha_emision @fecha_emision end |
#folio ⇒ Object
Returns the value of attribute folio.
6 7 8 |
# File 'lib/dtefacil_xml_builder/dte_reader.rb', line 6 def folio @folio end |
#monto ⇒ Object
Returns the value of attribute monto.
6 7 8 |
# File 'lib/dtefacil_xml_builder/dte_reader.rb', line 6 def monto @monto end |
#receptor ⇒ Object
Returns the value of attribute receptor.
6 7 8 |
# File 'lib/dtefacil_xml_builder/dte_reader.rb', line 6 def receptor @receptor end |
#tipo ⇒ Object
Returns the value of attribute tipo.
6 7 8 |
# File 'lib/dtefacil_xml_builder/dte_reader.rb', line 6 def tipo @tipo end |
Instance Method Details
#dte=(xml) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/dtefacil_xml_builder/dte_reader.rb', line 8 def dte= xml ref = XmlSimple.xml_in xml id_doc_hash = ref['Documento'].map{ |i| i['Encabezado'].map{|f| f['IdDoc']}}.flatten receptor_hash = ref['Documento'].map{ |i| i['Encabezado'].map{|f| f['Receptor']}}.flatten totales_hash = ref['Documento'].map{ |i| i['Encabezado'].map{|f| f['Totales']}}.flatten @tipo = id_doc_hash.first["TipoDTE"].first @folio = id_doc_hash.first["Folio"].first @monto = totales_hash.first["MntTotal"].first @fecha_emision= id_doc_hash.first["FchEmis"].first r = Receptor.new r.rut= receptor_hash.first["RUTRecep"].first r.= receptor_hash.first["RznSocRecep"].first r.giro= receptor_hash.first["GiroRecep"].first r.direccion= receptor_hash.first["DirRecep"].first r.comuna= receptor_hash.first["CmnaRecep"].first r.ciudad= receptor_hash.first["CiudadRecep"].first @receptor=r @detalles=[] detalles_hash_array= ref['Documento'].map{ |d| d['Detalle']}.flatten detalles_hash_array.each do |det| d = Detalle.new d.nombre= det["NmbItem"].first d.numero_linea=det["NroLinDet"].first d.cantidad=det["QtyItem"].first d.precio_unitario=det["PrcItem"].first d.monto_total= det["MontoItem"].first if det["DescuentoMonto"] d.descuento= det["DescuentoMonto"].first end if det["IndExe"] d.exento= true else d.exento= false end if det["UnmdItem"] d.unidad= det["UnmdItem"].first end @detalles[@detalles.length]=d end end |