dtefacil_xml_builder 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in dtefacil_xml_builder.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 vla
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # DtefacilXmlBuilder
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'dtefacil_xml_builder'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install dtefacil_xml_builder
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,18 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/dtefacil_xml_builder/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["vla"]
6
+ gem.email = ["vladimir@acid.cl"]
7
+ gem.description = %q{Facilita la construcción y manipulacion de xml necesarios para DTE Fácil 1.2}
8
+ gem.summary = %q{Construye y manipula xml para DTE Fácil 1.2}
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "dtefacil_xml_builder"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = DtefacilXmlBuilder::VERSION
17
+ gem.add_runtime_dependency 'builder'
18
+ end
@@ -0,0 +1,110 @@
1
+ module DtefacilXmlBuilder
2
+
3
+ class FacturaElectronica
4
+
5
+ def set_descuento descuento
6
+ @descuento = descuento
7
+ end
8
+
9
+ def set_actividades_economicas act
10
+ @actividades_economicas = act
11
+ end
12
+
13
+ def set_receptor receptor
14
+ @receptor = receptor
15
+ end
16
+
17
+ def set_detalles detalles
18
+ @detalles = detalles
19
+ end
20
+
21
+ def render_xml
22
+ dtebuilder = XmlBuilder::DteBuilder.new
23
+
24
+ xml = Builder::XmlMarkup.new(:target=>STDOUT, :indent=>2)
25
+ xml.instruct!(:xml, version: "1.0", encoding: "ISO-8859-1")
26
+ xml.facturaElectronica(xmlns: "http://dtefacil.cl/1.2"){
27
+ dtebuilder.create_actividades_economicas @actividades_economicas
28
+ dtebuilder.create_receptor @receptor
29
+ dtebuilder.create_detalles @detalles, @descuento
30
+ }
31
+ end
32
+ end
33
+
34
+
35
+ class NotaDeCreditoElectronica
36
+ def set_referencia referencia
37
+ @referencia = referencia
38
+ end
39
+
40
+ def set_tipo tipo
41
+ @tipo = tipo
42
+ end
43
+
44
+ def set_receptor receptor
45
+ @receptor = receptor
46
+ end
47
+
48
+ def set_detalles detalles
49
+ @detalles = detalles
50
+ end
51
+
52
+ def render_xml
53
+ dtebuilder = XmlBuilder::DteBuilder.new
54
+
55
+ xml = Builder::XmlMarkup.new(:target=>STDOUT, :indent=>2)
56
+ xml.instruct!(:xml, version: "1.0", encoding: "ISO-8859-1")
57
+ xml.notaCreditoElectronica(xmlns: "http://dtefacil.cl/1.2"){
58
+ |n|
59
+ if @tipo == "anula"
60
+ n.anulaDte(tipo: @referencia.tipo_dte, folio: @referencia.folio_dte)
61
+ end
62
+
63
+ if @receptor && @tipo == "datos"
64
+ n.corrigeReceptorDte(tipo: @referencia.tipo_dte, folio: @referencia.folio_dte){
65
+ dtebuilder.create_receptor @receptor
66
+ }
67
+ end
68
+
69
+ if @detalles && @tipo == "detalles"
70
+ n.corrigeMontosDte(tipo: @referencia.tipo_dte, folio: @referencia.folio_dte){
71
+ dtebuilder.create_detalles @detalles, @descuento
72
+ }
73
+ end
74
+ }
75
+ end
76
+ end
77
+
78
+
79
+ class FacturaExentaElectronica
80
+ def set_descuento descuento
81
+ @descuento = descuento
82
+ end
83
+
84
+ def set_actividades_economicas act
85
+ @actividades_economicas = act
86
+ end
87
+
88
+ def set_receptor receptor
89
+ @receptor = receptor
90
+ end
91
+
92
+ def set_detalles detalles
93
+ @detalles = detalles
94
+ end
95
+
96
+ def render_xml
97
+ dtebuilder = XmlBuilder::DteBuilder.new
98
+
99
+ xml = Builder::XmlMarkup.new(:target=>STDOUT, :indent=>2)
100
+ xml.instruct!(:xml, version: "1.0", encoding: "ISO-8859-1")
101
+ xml.facturaExentaElectronica(xmlns: "http://dtefacil.cl/1.2"){
102
+ dtebuilder.create_actividades_economicas @actividades_economicas
103
+ dtebuilder.create_receptor @receptor
104
+ dtebuilder.create_detalles @detalles, @descuento
105
+ }
106
+ end
107
+ end
108
+
109
+
110
+ end
@@ -0,0 +1,68 @@
1
+ module DtefacilXmlBuilder
2
+
3
+ class DteBuilder
4
+ def create_actividades_economicas actividades_economicas
5
+ builder = Builder::XmlMarkup.new(:target=>STDOUT, :indent=>2)
6
+ actividades_economicas.each do |act|
7
+ builder.actividadEconomica(act)
8
+ end
9
+ end
10
+
11
+ def create_detalles detalles, descuento
12
+ builder = Builder::XmlMarkup.new(:target=>STDOUT, :indent=>2)
13
+ builder.detalles {
14
+ |d|
15
+ if descuento
16
+ d.descuento{
17
+ |desc|
18
+ desc.porcentaje(descuento)
19
+ }
20
+ end
21
+
22
+ detalles.each do |detalle|
23
+ d.detalle{
24
+ |det|
25
+ det.nombre(detalle.nombre)
26
+ det.cantidad(detalle.cantidad)
27
+ det.precioUnitario(detalle.precio_unitario)
28
+
29
+ if detalle.unidad
30
+ det.unidad(detalle.unidad)
31
+ end
32
+
33
+ if detalle.descuento
34
+ det.descuento{
35
+ |desc_det|
36
+ desc_det.porcentaje(detalle.descuento)
37
+ }
38
+ end
39
+
40
+ if detalle.is_exento
41
+ det.observaciones{
42
+ |obs|
43
+ obs.exento
44
+ }
45
+ end
46
+ }
47
+ end
48
+ }
49
+ end
50
+
51
+ def create_receptor receptor
52
+ builder = Builder::XmlMarkup.new(:target=>STDOUT, :indent=>2)
53
+ builder.receptor {
54
+ |r|
55
+ r.rut(receptor.rut)
56
+ r.razonSocial(receptor.razon_social)
57
+ r.giro(receptor.giro)
58
+ r.ubicacion{
59
+ |u|
60
+ u.direccion(receptor.direccion)
61
+ u.comuna(receptor.comuna)
62
+ u.ciudad(receptor.ciudad)
63
+ }
64
+ }
65
+ end
66
+ end
67
+
68
+ end
@@ -0,0 +1,3 @@
1
+ module DtefacilXmlBuilder
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,12 @@
1
+ require "dtefacil_xml_builder/documentos"
2
+ require "dtefacil_xml_builder/dte_builder"
3
+ require "dtefacil_xml_builder/version"
4
+ require "builder"
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dtefacil_xml_builder
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - vla
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-30 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: builder
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: Facilita la construcción y manipulacion de xml necesarios para DTE Fácil
31
+ 1.2
32
+ email:
33
+ - vladimir@acid.cl
34
+ executables: []
35
+ extensions: []
36
+ extra_rdoc_files: []
37
+ files:
38
+ - .gitignore
39
+ - Gemfile
40
+ - LICENSE
41
+ - README.md
42
+ - Rakefile
43
+ - dtefacil_xml_builder.gemspec
44
+ - lib/dtefacil_xml_builder.rb
45
+ - lib/dtefacil_xml_builder/documentos.rb
46
+ - lib/dtefacil_xml_builder/dte_builder.rb
47
+ - lib/dtefacil_xml_builder/version.rb
48
+ homepage: ''
49
+ licenses: []
50
+ post_install_message:
51
+ rdoc_options: []
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ! '>='
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ requirements: []
67
+ rubyforge_project:
68
+ rubygems_version: 1.8.24
69
+ signing_key:
70
+ specification_version: 3
71
+ summary: Construye y manipula xml para DTE Fácil 1.2
72
+ test_files: []