dtefacil_xml_builder 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
@@ -3,15 +3,17 @@ require 'xmlsimple'
|
|
3
3
|
|
4
4
|
module DtefacilXmlBuilder
|
5
5
|
class DteReader
|
6
|
-
attr_accessor :receptor, :detalles, :folio, :tipo, :folio, :
|
6
|
+
attr_accessor :receptor, :detalles, :folio, :tipo, :folio, :monto
|
7
7
|
|
8
8
|
def dte= xml
|
9
9
|
ref = XmlSimple.xml_in xml
|
10
10
|
id_doc_hash = ref['Documento'].map{ |i| i['Encabezado'].map{|f| f['IdDoc']}}.flatten
|
11
11
|
receptor_hash = ref['Documento'].map{ |i| i['Encabezado'].map{|f| f['Receptor']}}.flatten
|
12
|
+
totales_hash = ref['Documento'].map{ |i| i['Encabezado'].map{|f| f['Totales']}}.flatten
|
12
13
|
|
13
14
|
@tipo = id_doc_hash.first["TipoDTE"].first
|
14
15
|
@folio = id_doc_hash.first["Folio"].first
|
16
|
+
@monto = totales_hash.first["MntTotal"].first
|
15
17
|
|
16
18
|
r = Receptor.new
|
17
19
|
r.rut= receptor_hash.first["RUTRecep"].first
|
@@ -22,32 +24,42 @@ module DtefacilXmlBuilder
|
|
22
24
|
r.ciudad= receptor_hash.first["CiudadRecep"].first
|
23
25
|
@receptor=r
|
24
26
|
@detalles=[]
|
25
|
-
|
26
27
|
detalles_hash_array= ref['Documento'].map{ |d| d['Detalle']}.flatten
|
27
28
|
|
29
|
+
|
28
30
|
detalles_hash_array.each do |det|
|
29
31
|
d = Detalle.new
|
30
32
|
d.nombre= det["NmbItem"].first
|
31
33
|
d.numero_linea=det["NroLinDet"].first
|
32
34
|
d.cantidad=det["QtyItem"].first
|
33
35
|
d.precio_unitario=det["PrcItem"].first
|
34
|
-
d.
|
36
|
+
d.monto_total= det["MontoItem"].first
|
35
37
|
|
36
|
-
if det["DescuentoMonto"]
|
38
|
+
if det["DescuentoMonto"]
|
37
39
|
d.descuento= det["DescuentoMonto"].first
|
38
40
|
end
|
39
41
|
|
40
|
-
if det["IndExe"]
|
41
|
-
d.exento= true
|
42
|
+
if det["IndExe"]
|
43
|
+
d.exento= true
|
44
|
+
else
|
45
|
+
d.exento= false
|
42
46
|
end
|
43
47
|
|
44
|
-
if det["UnmdItem"]
|
48
|
+
if det["UnmdItem"]
|
45
49
|
d.unidad= det["UnmdItem"].first
|
46
50
|
end
|
47
51
|
|
48
52
|
@detalles[@detalles.length]=d
|
49
|
-
end
|
50
|
-
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
class DteCollectionReader
|
62
|
+
attr_accessor :collection
|
51
63
|
|
52
64
|
def collection= xml
|
53
65
|
ref = XmlSimple.xml_in xml
|
@@ -77,6 +89,5 @@ module DtefacilXmlBuilder
|
|
77
89
|
col.documentos= docs
|
78
90
|
@collection= col
|
79
91
|
end
|
80
|
-
|
81
|
-
end
|
92
|
+
end
|
82
93
|
end
|
@@ -13,13 +13,13 @@ module DtefacilXmlBuilder
|
|
13
13
|
response = RestClient.get "https://acid:WhXdrDBJ@api.dtefacil.cl/1.2/documentos/d3g3zty5qybgx3e5dcqls22iuwy"
|
14
14
|
reader = DteReader.new
|
15
15
|
reader.dte= response.body
|
16
|
+
reader.monto
|
16
17
|
end
|
17
18
|
|
18
19
|
def read_collection
|
19
20
|
response = RestClient.get "https://ptoTicket:pt0T1ck3t@api.dtefacil.cl/1.2/documentos"
|
20
|
-
reader =
|
21
|
+
reader = DteCollectionReader.new
|
21
22
|
reader.collection= response.body
|
22
23
|
end
|
23
|
-
|
24
24
|
end
|
25
25
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dtefacil_xml_builder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-08-
|
12
|
+
date: 2012-08-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: builder
|