Class: DtefacilXmlBuilder::DteReader

Inherits:
Object
  • Object
show all
Defined in:
lib/dtefacil_xml_builder/dte_reader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#detallesObject

Returns the value of attribute detalles.



6
7
8
# File 'lib/dtefacil_xml_builder/dte_reader.rb', line 6

def detalles
  @detalles
end

#folioObject

Returns the value of attribute folio.



6
7
8
# File 'lib/dtefacil_xml_builder/dte_reader.rb', line 6

def folio
  @folio
end

#montoObject

Returns the value of attribute monto.



6
7
8
# File 'lib/dtefacil_xml_builder/dte_reader.rb', line 6

def monto
  @monto
end

#receptorObject

Returns the value of attribute receptor.



6
7
8
# File 'lib/dtefacil_xml_builder/dte_reader.rb', line 6

def receptor
  @receptor
end

#tipoObject

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
# 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  

 	r = Receptor.new 
 	r.rut= 			receptor_hash.first["RUTRecep"].first 
 	r.razon_social= 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