facturapi 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/facturapi.gemspec +30 -0
- data/foo.xml +119 -0
- data/lala.html +1 -0
- data/lib/facturapi.rb +6 -0
- data/lib/facturapi/client.rb +27 -0
- data/lib/facturapi/config.rb +50 -0
- data/lib/facturapi/helpers.rb +11 -0
- data/lib/facturapi/helpers/detalle.rb +39 -0
- data/lib/facturapi/helpers/dsc_rcg_global.rb +28 -0
- data/lib/facturapi/helpers/dte.rb +57 -0
- data/lib/facturapi/helpers/emisor.rb +28 -0
- data/lib/facturapi/helpers/encabezado.rb +23 -0
- data/lib/facturapi/helpers/id_doc.rb +32 -0
- data/lib/facturapi/helpers/receptor.rb +30 -0
- data/lib/facturapi/helpers/referencia.rb +21 -0
- data/lib/facturapi/helpers/totales.rb +32 -0
- data/lib/facturapi/service.rb +1 -0
- data/lib/facturapi/service/procesar.rb +24 -0
- data/lib/facturapi/version.rb +3 -0
- data/lib/facturapi/xml.rb +17 -0
- data/todo.rb +246 -0
- metadata +167 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c84c8ad9f595de425766ed65c06063b58744ae60
|
4
|
+
data.tar.gz: 25ffce29b83b617bfbfda57245ad1d73865fbd5a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: aff36a3dce1bb173b18fe55917acb3123cf76cddfac684e1aa603f8156c5a53463c7aa130890af68f0941ca46749e20ba556d20565b7cac7d81eeb1a18a6b58a
|
7
|
+
data.tar.gz: 6b9ca89f47ffddbd389e46cbe7af3b50bf5686f627c909bafd7fae3ed0d3cd70e7fc1d0800aec8a3d62f7aae787a525c985fdb7509b7bd6668bdf77e9d41d210
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
facturapi
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.3.1
|
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at alter.strife@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Alter Lagos
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# Facturapi
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/facturapi`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'facturapi'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install facturapi
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/facturapi. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "facturapi"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/facturapi.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'facturapi/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "facturapi"
|
8
|
+
spec.version = Facturapi::VERSION
|
9
|
+
spec.authors = ["Alter Lagos"]
|
10
|
+
spec.email = ["alter.strife@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Ruby integration with facturacion.cl service}
|
13
|
+
# spec.description = %q{TODO: Write a longer description or delete this line.}
|
14
|
+
# spec.homepage = ""
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
spec.add_runtime_dependency "savon", "~> 2.0"
|
24
|
+
spec.add_runtime_dependency "libxml-ruby", "~> 2.0"
|
25
|
+
spec.add_runtime_dependency "nokogiri", "~> 1.4", ">= 1.4.0"
|
26
|
+
|
27
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
28
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
29
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
30
|
+
end
|
data/foo.xml
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<DTE version="1.0">
|
3
|
+
<Documento ID="F100T39">
|
4
|
+
<Encabezado>
|
5
|
+
<IdDoc>
|
6
|
+
<TipoDTE>39</TipoDTE>
|
7
|
+
<Folio>100</Folio>
|
8
|
+
<FchEmis>2008-09-01</FchEmis>
|
9
|
+
<IndServicio>1</IndServicio>
|
10
|
+
<IndMntNeto>2</IndMntNeto>
|
11
|
+
<PeriodoDesde>2008-08-01</PeriodoDesde>
|
12
|
+
<PeriodoHasta>2008-08-31</PeriodoHasta>
|
13
|
+
<FchVenc>2008-09-20</FchVenc>
|
14
|
+
</IdDoc>
|
15
|
+
<Emisor>
|
16
|
+
<RUTEmisor>1-9</RUTEmisor>
|
17
|
+
<RznSocEmisor>EMPRESA DE PRUEBA</RznSocEmisor>
|
18
|
+
<GiroEmisor>DESARROLLO DE SISTEMAS</GiroEmisor>
|
19
|
+
<DirOrigen>Avenida del Software #11001101</DirOrigen>
|
20
|
+
<CmnaOrigen>PROVIDENCIA</CmnaOrigen>
|
21
|
+
<CiudadOrigen>SANTIAGO</CiudadOrigen>
|
22
|
+
</Emisor>
|
23
|
+
<Receptor>
|
24
|
+
<RUTRecep>11111111-1</RUTRecep>
|
25
|
+
<CdgIntRecep>1000215-220</CdgIntRecep>
|
26
|
+
<RznSocRecep>CLIENTE DE PRUEBA</RznSocRecep>
|
27
|
+
<Contacto>correo@prueba.cl</Contacto>
|
28
|
+
<DirRecep>CALLE A 50</DirRecep>
|
29
|
+
<CmnaRecep>SANTIAGO</CmnaRecep>
|
30
|
+
<CiudadRecep>SANTIAGO</CiudadRecep>
|
31
|
+
</Receptor>
|
32
|
+
<Totales>
|
33
|
+
<MntNeto>10000</MntNeto>
|
34
|
+
<MntExe>1500</MntExe>
|
35
|
+
<IVA>1900</IVA>
|
36
|
+
<MntTotal>13400</MntTotal>
|
37
|
+
<MontoNF>2000</MontoNF>
|
38
|
+
<TotalPeriodo>15400</TotalPeriodo>
|
39
|
+
<SaldoAnterior>5000</SaldoAnterior>
|
40
|
+
<VlrPagar>20400</VlrPagar>
|
41
|
+
</Totales>
|
42
|
+
</Encabezado>
|
43
|
+
<Detalle>
|
44
|
+
<NroLinDet>1</NroLinDet>
|
45
|
+
<CdgItem>
|
46
|
+
<TpoCodigo>INT1</TpoCodigo>
|
47
|
+
<VlrCodigo>WWW</VlrCodigo>
|
48
|
+
</CdgItem>
|
49
|
+
<NmbItem>Descripción de producto 1</NmbItem>
|
50
|
+
<DscItem>Serie ABC</DscItem>
|
51
|
+
<QtyItem>1</QtyItem>
|
52
|
+
<UnmdItem>M3</UnmdItem>
|
53
|
+
<PrcItem>6000</PrcItem>
|
54
|
+
<MontoItem>6000</MontoItem>
|
55
|
+
</Detalle>
|
56
|
+
<Detalle>
|
57
|
+
<NroLinDet>2</NroLinDet>
|
58
|
+
<CdgItem>
|
59
|
+
<TpoCodigo>INT1</TpoCodigo>
|
60
|
+
<VlrCodigo>WWW</VlrCodigo>
|
61
|
+
</CdgItem>
|
62
|
+
<NmbItem>Descripción de producto 1</NmbItem>
|
63
|
+
<DscItem>Serie ABC</DscItem>
|
64
|
+
<QtyItem>1</QtyItem>
|
65
|
+
<UnmdItem>M3</UnmdItem>
|
66
|
+
<PrcItem>12000</PrcItem>
|
67
|
+
<MontoItem>12000</MontoItem>
|
68
|
+
</Detalle>
|
69
|
+
<Detalle>
|
70
|
+
<NroLinDet>3</NroLinDet>
|
71
|
+
<CdgItem>
|
72
|
+
<TpoCodigo>INT1</TpoCodigo>
|
73
|
+
<VlrCodigo>WWW</VlrCodigo>
|
74
|
+
</CdgItem>
|
75
|
+
<NmbItem>Descripción de producto 1</NmbItem>
|
76
|
+
<DscItem>Serie ABC</DscItem>
|
77
|
+
<QtyItem>1</QtyItem>
|
78
|
+
<UnmdItem>M3</UnmdItem>
|
79
|
+
<PrcItem>18000</PrcItem>
|
80
|
+
<MontoItem>18000</MontoItem>
|
81
|
+
</Detalle>
|
82
|
+
<Detalle>
|
83
|
+
<NroLinDet>4</NroLinDet>
|
84
|
+
<CdgItem>
|
85
|
+
<TpoCodigo>INT1</TpoCodigo>
|
86
|
+
<VlrCodigo>WWW</VlrCodigo>
|
87
|
+
</CdgItem>
|
88
|
+
<NmbItem>Descripción de producto 1</NmbItem>
|
89
|
+
<DscItem>Serie ABC</DscItem>
|
90
|
+
<QtyItem>1</QtyItem>
|
91
|
+
<UnmdItem>M3</UnmdItem>
|
92
|
+
<PrcItem>24000</PrcItem>
|
93
|
+
<MontoItem>24000</MontoItem>
|
94
|
+
</Detalle>
|
95
|
+
<DscRcgGlobal>
|
96
|
+
<NroLinDR>1</NroLinDR>
|
97
|
+
<TpoMov>D</TpoMov>
|
98
|
+
<GlosaDR>Cobro de ventas o servicios previo</GlosaDR>
|
99
|
+
<TpoValor>$</TpoValor>
|
100
|
+
<ValorDR>2000</ValorDR>
|
101
|
+
<IndExeDR>2</IndExeDR>
|
102
|
+
</DscRcgGlobal>
|
103
|
+
<Referencia>
|
104
|
+
<NroLinRef>1</NroLinRef>
|
105
|
+
<CodRef>NROMEDIDOR</CodRef>
|
106
|
+
<RazonRef>152445596-6655215</RazonRef>
|
107
|
+
</Referencia>
|
108
|
+
<Referencia>
|
109
|
+
<NroLinRef>2</NroLinRef>
|
110
|
+
<CodRef>NROMEDIDOR</CodRef>
|
111
|
+
<RazonRef>152445596-6655215</RazonRef>
|
112
|
+
</Referencia>
|
113
|
+
<Referencia>
|
114
|
+
<NroLinRef>3</NroLinRef>
|
115
|
+
<CodRef>NROMEDIDOR</CodRef>
|
116
|
+
<RazonRef>152445596-6655215</RazonRef>
|
117
|
+
</Referencia>
|
118
|
+
</Documento>
|
119
|
+
</DTE>
|
data/lala.html
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
<?xml version="1.0"?><WSPLANO><Resultado>False</Resultado><Mensaje>Posee documentos con error.</Mensaje><Detalle><Documento><Folio>0</Folio><TipoDte>0</TipoDte><Operacion></Operacion><Fecha>2017-02-02T15:16:57</Fecha><Resultado>False</Resultado><Error>El archivo no es un XML. Tipo Formato=2 Debe ser un archivo *.xml que inicie con las etiquetas &lt;DTE&gt; o &lt;LibroCompraVenta&gt;</Error></Documento></Detalle></WSPLANO>
|
data/lib/facturapi.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'savon'
|
2
|
+
|
3
|
+
module Facturapi
|
4
|
+
class Client
|
5
|
+
attr_accessor :client
|
6
|
+
attr_reader :login
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@login = {
|
10
|
+
'Usuario' => Facturapi.config.fact_user,
|
11
|
+
'Rut' => Facturapi.config.fact_rut,
|
12
|
+
'Clave' => Facturapi.config.fact_password,
|
13
|
+
'Puerto' => Facturapi.config.fact_port
|
14
|
+
}
|
15
|
+
@client = Savon.client(
|
16
|
+
wsdl: 'http://ws1.facturacion.cl/WSDS/wsplano.asmx?wsdl'
|
17
|
+
)
|
18
|
+
end
|
19
|
+
|
20
|
+
def call(method, params = {})
|
21
|
+
params[:login] ||= login
|
22
|
+
puts params
|
23
|
+
response = @client.call(method, message: params)
|
24
|
+
response.body[:procesar_response][:procesar_result]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'base64'
|
2
|
+
|
3
|
+
module Facturapi
|
4
|
+
class Config
|
5
|
+
# Set and gets the default facturacion user
|
6
|
+
def fact_user(user = nil)
|
7
|
+
@user = user if user
|
8
|
+
Base64.strict_encode64(@user || ENV['FACTURACION_USER'])
|
9
|
+
end
|
10
|
+
|
11
|
+
# Set and gets the default facturacion rut
|
12
|
+
def fact_rut(rut = nil)
|
13
|
+
@rut = rut if rut
|
14
|
+
Base64.strict_encode64(@rut || ENV['FACTURACION_RUT'])
|
15
|
+
end
|
16
|
+
|
17
|
+
# Set and gets the default facturacion password
|
18
|
+
def fact_password(password = nil)
|
19
|
+
@password = password if password
|
20
|
+
Base64.strict_encode64(@password || ENV['FACTURACION_PASSWORD'])
|
21
|
+
end
|
22
|
+
|
23
|
+
# Set and gets the default facturacion port
|
24
|
+
def fact_port(port = nil)
|
25
|
+
@port = port if port
|
26
|
+
Base64.strict_encode64((@port || ENV['FACTURACION_PORT']).to_s)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# Returns the configuration object
|
31
|
+
# @return [Facturapi::Config] the configuration object
|
32
|
+
def self.config
|
33
|
+
@config ||= Config.new
|
34
|
+
end
|
35
|
+
|
36
|
+
# Configure the app defaults simply by doing
|
37
|
+
#
|
38
|
+
# Facturapi.configure do |config|
|
39
|
+
# config.fact_rut '1-9'
|
40
|
+
# config.fact_user 'juan'
|
41
|
+
# config.fact_password 'perez'
|
42
|
+
# config.fact_port 9350
|
43
|
+
# end
|
44
|
+
#
|
45
|
+
# @yield [Facturapi::Config] The config object
|
46
|
+
def self.configure
|
47
|
+
yield(config)
|
48
|
+
nil
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'facturapi/helpers/detalle'
|
2
|
+
require 'facturapi/helpers/dsc_rcg_global'
|
3
|
+
require 'facturapi/helpers/dte'
|
4
|
+
require 'facturapi/helpers/emisor'
|
5
|
+
require 'facturapi/helpers/encabezado'
|
6
|
+
require 'facturapi/helpers/id_doc'
|
7
|
+
require 'facturapi/helpers/receptor'
|
8
|
+
require 'facturapi/helpers/referencia'
|
9
|
+
require 'facturapi/helpers/totales'
|
10
|
+
|
11
|
+
include Facturapi::Xml
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Facturapi
|
2
|
+
module Helpers
|
3
|
+
class Detalle
|
4
|
+
attr_accessor :nro_lin_det, :tpo_codigo, :vlr_codigo, :ind_exe,
|
5
|
+
:rut_mandante, :nmb_item, :dsc_item, :qty_item, :unmd_item,
|
6
|
+
:prc_item, :monto_item
|
7
|
+
|
8
|
+
def initialize(params = {})
|
9
|
+
@nro_lin_det = params[:nro_lin_det]
|
10
|
+
@tpo_codigo = params[:tpo_codigo]
|
11
|
+
@vlr_codigo = params[:vlr_codigo]
|
12
|
+
@ind_exe = params[:ind_exe]
|
13
|
+
@rut_mandante = params[:rut_mandante]
|
14
|
+
@nmb_item = params[:nmb_item]
|
15
|
+
@dsc_item = params[:dsc_item]
|
16
|
+
@qty_item = params[:qty_item]
|
17
|
+
@unmd_item = params[:unmd_item]
|
18
|
+
@prc_item = params[:prc_item]
|
19
|
+
@monto_item = params[:monto_item]
|
20
|
+
end
|
21
|
+
|
22
|
+
def as_node
|
23
|
+
create_node('Detalle') do |detalle|
|
24
|
+
detalle << create_node('NroLinDet') { |n| n << nro_lin_det }
|
25
|
+
detalle << create_node('TpoCodigo') { |n| n << tpo_codigo }
|
26
|
+
detalle << create_node('VlrCodigo') { |n| n << vlr_codigo }
|
27
|
+
detalle << create_node('IndExe') { |n| n << ind_exe }
|
28
|
+
detalle << create_node('RUTMandante') { |n| n << rut_mandante }
|
29
|
+
detalle << create_node('NmbItem') { |n| n << nmb_item }
|
30
|
+
detalle << create_node('DscItem') { |n| n << dsc_item }
|
31
|
+
detalle << create_node('QtyItem') { |n| n << qty_item }
|
32
|
+
detalle << create_node('UnmdItem') { |n| n << unmd_item }
|
33
|
+
detalle << create_node('PrcItem') { |n| n << prc_item }
|
34
|
+
detalle << create_node('MontoItem') { |n| n << monto_item }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Facturapi
|
2
|
+
module Helpers
|
3
|
+
class DscRcgGlobal
|
4
|
+
attr_accessor :nro_lin_dr, :tpo_mov, :glosa_dr, :tpo_valor, :valor_dr,
|
5
|
+
:ind_exe_dr
|
6
|
+
|
7
|
+
def initialize(params = {})
|
8
|
+
@nro_lin_dr = params[:nro_lin_dr]
|
9
|
+
@tpo_mov = params[:tpo_mov]
|
10
|
+
@glosa_dr = params[:glosa_dr]
|
11
|
+
@tpo_valor = params[:tpo_valor]
|
12
|
+
@valor_dr = params[:valor_dr]
|
13
|
+
@ind_exe_dr = params[:ind_exe_dr]
|
14
|
+
end
|
15
|
+
|
16
|
+
def as_node
|
17
|
+
create_node('DscRcgGlobal') do |dsc_rcg_global|
|
18
|
+
dsc_rcg_global << create_node('NroLinDR') { |n| n << nro_lin_dr }
|
19
|
+
dsc_rcg_global << create_node('TpoMov') { |n| n << tpo_mov }
|
20
|
+
dsc_rcg_global << create_node('GlosaDR') { |n| n << glosa_dr }
|
21
|
+
dsc_rcg_global << create_node('TpoValor') { |n| n << tpo_valor }
|
22
|
+
dsc_rcg_global << create_node('ValorDR') { |n| n << valor_dr }
|
23
|
+
dsc_rcg_global << create_node('IndExeDR') { |n| n << ind_exe_dr }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Facturapi
|
2
|
+
module Helpers
|
3
|
+
class Dte
|
4
|
+
attr_accessor :encabezado, :detalle, :dsc_rcg_global, :referencia
|
5
|
+
|
6
|
+
def initialize(params = {})
|
7
|
+
@encabezado = params[:encabezado]
|
8
|
+
self.detalle = params[:detalle]
|
9
|
+
self.dsc_rcg_global = params[:dsc_rcg_global]
|
10
|
+
self.referencia = params[:referencia]
|
11
|
+
end
|
12
|
+
|
13
|
+
def detalle=(detalle)
|
14
|
+
@detalle = @detalle.nil? ? [] : @detalle
|
15
|
+
@detalle =
|
16
|
+
if @detalle.is_a?(Array)
|
17
|
+
@detalle.push(*detalle)
|
18
|
+
else
|
19
|
+
@detalle.push(detalle)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def dsc_rcg_global=(dsc_rcg_global)
|
24
|
+
@dsc_rcg_global = @dsc_rcg_global.nil? ? [] : @dsc_rcg_global
|
25
|
+
@dsc_rcg_global =
|
26
|
+
if @dsc_rcg_global.is_a?(Array)
|
27
|
+
@dsc_rcg_global.push(*dsc_rcg_global)
|
28
|
+
else
|
29
|
+
@dsc_rcg_global.push(dsc_rcg_global)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def referencia=(referencia)
|
34
|
+
@referencia = @referencia.nil? ? [] : @referencia
|
35
|
+
@referencia =
|
36
|
+
if @referencia.is_a?(Array)
|
37
|
+
@referencia.push(*referencia)
|
38
|
+
else
|
39
|
+
@referencia.push(referencia)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def as_node
|
44
|
+
doc = XML::Document.new
|
45
|
+
doc.root = create_node('DTE', version: '1.0') do |dte|
|
46
|
+
dte << create_node('Documento', 'ID' => 'F100T39') do |documento|
|
47
|
+
documento << encabezado.as_node
|
48
|
+
detalle.each { |d| documento << d.as_node }
|
49
|
+
dsc_rcg_global.each { |d| documento << d.as_node }
|
50
|
+
referencia.each { |r| documento << r.as_node }
|
51
|
+
end
|
52
|
+
end
|
53
|
+
doc
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Facturapi
|
2
|
+
module Helpers
|
3
|
+
class Emisor
|
4
|
+
attr_accessor :rut_emisor, :rzn_soc_emisor, :giro_emisor, :dir_origen,
|
5
|
+
:cmna_origen, :ciudad_origen
|
6
|
+
|
7
|
+
def initialize(params = {})
|
8
|
+
@rut_emisor = params[:rut_emisor]
|
9
|
+
@rzn_soc_emisor = params[:rzn_soc_emisor]
|
10
|
+
@giro_emisor = params[:giro_emisor]
|
11
|
+
@dir_origen = params[:dir_origen]
|
12
|
+
@cmna_origen = params[:cmna_origen]
|
13
|
+
@ciudad_origen = params[:ciudad_origen]
|
14
|
+
end
|
15
|
+
|
16
|
+
def as_node
|
17
|
+
create_node('Emisor') do |emisor|
|
18
|
+
emisor << create_node('RUTEmisor') { |n| n << rut_emisor }
|
19
|
+
emisor << create_node('RznSocEmisor') { |n| n << rzn_soc_emisor }
|
20
|
+
emisor << create_node('GiroEmisor') { |n| n << giro_emisor }
|
21
|
+
emisor << create_node('DirOrigen') { |n| n << dir_origen }
|
22
|
+
emisor << create_node('CmnaOrigen') { |n| n << cmna_origen }
|
23
|
+
emisor << create_node('CiudadOrigen') { |n| n << ciudad_origen }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Facturapi
|
2
|
+
module Helpers
|
3
|
+
class Encabezado
|
4
|
+
attr_accessor :id_doc, :emisor, :receptor, :totales
|
5
|
+
|
6
|
+
def initialize(params = {})
|
7
|
+
@id_doc = params[:id_doc]
|
8
|
+
@emisor = params[:emisor]
|
9
|
+
@receptor = params[:receptor]
|
10
|
+
@totales = params[:totales]
|
11
|
+
end
|
12
|
+
|
13
|
+
def as_node
|
14
|
+
create_node('Encabezado') do |encabezado|
|
15
|
+
encabezado << id_doc.as_node
|
16
|
+
encabezado << emisor.as_node
|
17
|
+
encabezado << receptor.as_node
|
18
|
+
encabezado << totales.as_node
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Facturapi
|
2
|
+
module Helpers
|
3
|
+
class IdDoc
|
4
|
+
attr_accessor :tipo_dte, :folio, :fch_emis, :ind_servicio, :ind_mnt_neto,
|
5
|
+
:periodo_desde, :periodo_hasta, :fch_venc
|
6
|
+
|
7
|
+
def initialize(params = {})
|
8
|
+
@tipo_dte = params[:tipo_dte]
|
9
|
+
@folio = params[:folio]
|
10
|
+
@fch_emis = params[:fch_emis]
|
11
|
+
@ind_servicio = params[:ind_servicio]
|
12
|
+
@ind_mnt_neto = params[:ind_mnt_neto]
|
13
|
+
@periodo_desde = params[:periodo_desde]
|
14
|
+
@periodo_hasta = params[:periodo_hasta]
|
15
|
+
@fch_venc = params[:fch_venc]
|
16
|
+
end
|
17
|
+
|
18
|
+
def as_node
|
19
|
+
create_node('IdDoc') do |id_doc|
|
20
|
+
id_doc << create_node('TipoDTE') { |n| n << tipo_dte }
|
21
|
+
id_doc << create_node('Folio') { |n| n << folio }
|
22
|
+
id_doc << create_node('FchEmis') { |n| n << fch_emis }
|
23
|
+
id_doc << create_node('IndServicio') { |n| n << ind_servicio }
|
24
|
+
id_doc << create_node('IndMntNeto') { |n| n << ind_mnt_neto }
|
25
|
+
id_doc << create_node('PeriodoDesde') { |n| n << periodo_desde }
|
26
|
+
id_doc << create_node('PeriodoHasta') { |n| n << periodo_hasta }
|
27
|
+
id_doc << create_node('FchVenc') { |n| n << fch_venc }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Facturapi
|
2
|
+
module Helpers
|
3
|
+
class Receptor
|
4
|
+
attr_accessor :rut_recep, :cdg_int_recep, :rzn_soc_recep, :contacto,
|
5
|
+
:dir_recep, :cmna_recep, :ciudad_recep
|
6
|
+
|
7
|
+
def initialize(params = {})
|
8
|
+
@rut_recep = params[:rut_recep]
|
9
|
+
@cdg_int_recep = params[:cdg_int_recep]
|
10
|
+
@rzn_soc_recep = params[:rzn_soc_recep]
|
11
|
+
@contacto = params[:contacto]
|
12
|
+
@dir_recep = params[:dir_recep]
|
13
|
+
@cmna_recep = params[:cmna_recep]
|
14
|
+
@ciudad_recep = params[:ciudad_recep]
|
15
|
+
end
|
16
|
+
|
17
|
+
def as_node
|
18
|
+
create_node('Receptor') do |receptor|
|
19
|
+
receptor << create_node('RUTRecep') { |n| n << rut_recep }
|
20
|
+
receptor << create_node('CdgIntRecep') { |n| n << cdg_int_recep }
|
21
|
+
receptor << create_node('RznSocRecep') { |n| n << rzn_soc_recep }
|
22
|
+
receptor << create_node('Contacto') { |n| n << contacto }
|
23
|
+
receptor << create_node('DirRecep') { |n| n << dir_recep }
|
24
|
+
receptor << create_node('CmnaRecep') { |n| n << cmna_recep }
|
25
|
+
receptor << create_node('CiudadRecep') { |n| n << ciudad_recep }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Facturapi
|
2
|
+
module Helpers
|
3
|
+
class Referencia
|
4
|
+
attr_accessor :nro_lin_ref, :cod_ref, :razon_ref
|
5
|
+
|
6
|
+
def initialize(params = {})
|
7
|
+
@nro_lin_ref = params[:nro_lin_ref]
|
8
|
+
@cod_ref = params[:cod_ref]
|
9
|
+
@razon_ref = params[:razon_ref]
|
10
|
+
end
|
11
|
+
|
12
|
+
def as_node
|
13
|
+
create_node('Referencia') do |referencia|
|
14
|
+
referencia << create_node('NroLinRef') { |n| n << nro_lin_ref }
|
15
|
+
referencia << create_node('CodRef') { |n| n << cod_ref }
|
16
|
+
referencia << create_node('RazonRef') { |n| n << razon_ref }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Facturapi
|
2
|
+
module Helpers
|
3
|
+
class Totales
|
4
|
+
attr_accessor :mnt_neto, :mnt_exe, :iva, :mnt_total, :monto_nf,
|
5
|
+
:total_periodo, :saldo_anterior, :vlr_pagar
|
6
|
+
|
7
|
+
def initialize(params = {})
|
8
|
+
@mnt_neto = params[:mnt_neto]
|
9
|
+
@mnt_exe = params[:mnt_exe]
|
10
|
+
@iva = params[:iva]
|
11
|
+
@mnt_total = params[:mnt_total]
|
12
|
+
@monto_nf = params[:monto_nf]
|
13
|
+
@total_periodo = params[:total_periodo]
|
14
|
+
@saldo_anterior = params[:saldo_anterior]
|
15
|
+
@vlr_pagar = params[:vlr_pagar]
|
16
|
+
end
|
17
|
+
|
18
|
+
def as_node
|
19
|
+
create_node('Totales') do |totales|
|
20
|
+
totales << create_node('MntNeto') { |n| n << mnt_neto }
|
21
|
+
totales << create_node('MntExe') { |n| n << mnt_exe }
|
22
|
+
totales << create_node('IVA') { |n| n << iva }
|
23
|
+
totales << create_node('MntTotal') { |n| n << mnt_total }
|
24
|
+
totales << create_node('MontoNF') { |n| n << monto_nf }
|
25
|
+
totales << create_node('TotalPeriodo') { |n| n << total_periodo }
|
26
|
+
totales << create_node('SaldoAnterior') { |n| n << saldo_anterior }
|
27
|
+
totales << create_node('VlrPagar') { |n| n << vlr_pagar }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'facturapi/service/procesar'
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Facturapi
|
2
|
+
module Service
|
3
|
+
class Procesar
|
4
|
+
attr_accessor :dte
|
5
|
+
attr_reader :client
|
6
|
+
|
7
|
+
def initialize(dte)
|
8
|
+
@dte = dte
|
9
|
+
@client = Facturapi::Client.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def send
|
13
|
+
file = Base64.strict_encode64(dte.as_node.to_s)
|
14
|
+
params = { file: file, formato: 2 }
|
15
|
+
response = client.call(:procesar, params)
|
16
|
+
Nokogiri::XML(response)
|
17
|
+
# doc = Nokogiri::XML(response)
|
18
|
+
# ok = doc.css('WSPLANO>Resultado').text
|
19
|
+
# mensaje = doc.css('WSPLANO>Mensaje').text
|
20
|
+
# error = doc.css('Documento>Error').text
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'xml'
|
2
|
+
|
3
|
+
module Facturapi
|
4
|
+
module Xml
|
5
|
+
def create_node(name, attributes = nil)
|
6
|
+
node = XML::Node.new(name)
|
7
|
+
|
8
|
+
if attributes
|
9
|
+
attributes.each do |k, v|
|
10
|
+
XML::Attr.new(node, k.to_s, v)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
yield(node) if block_given?
|
14
|
+
node
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/todo.rb
ADDED
@@ -0,0 +1,246 @@
|
|
1
|
+
# 3 feb
|
2
|
+
# 1:18-1:55
|
3
|
+
# 14:10-14:59
|
4
|
+
|
5
|
+
# http://ws1.facturacion.cl/WSDS/wsplano.asmx
|
6
|
+
|
7
|
+
|
8
|
+
# Enlace: https://www.facturacion.cl/plano/
|
9
|
+
# Usuario: MELONCARGO
|
10
|
+
# Clave: 87ac1e2ccf
|
11
|
+
|
12
|
+
|
13
|
+
# RUT Empresa: 1-9
|
14
|
+
# Clave: plano91098
|
15
|
+
# Usuario: MELONCARGO
|
16
|
+
# Puerto: 9350
|
17
|
+
|
18
|
+
# Agregar opcion de IncluyeLink en config
|
19
|
+
|
20
|
+
require 'savon'
|
21
|
+
require 'xml'
|
22
|
+
require 'base64'
|
23
|
+
|
24
|
+
|
25
|
+
doc = XML::Document.new
|
26
|
+
|
27
|
+
doc.root = create_node('DTE', version: '1.0') do |dte|
|
28
|
+
dte << create_node('Documento', 'ID' => 'F100T39') do |documento|
|
29
|
+
documento << create_node('Encabezado') do |encabezado|
|
30
|
+
encabezado << create_node('IdDoc') do |id_doc|
|
31
|
+
id_doc << create_node('TipoDTE') { |n| n << 39 }
|
32
|
+
id_doc << create_node('Folio') { |n| n << 100 }
|
33
|
+
id_doc << create_node('FchEmis') { |n| n << '2008-09-01' }
|
34
|
+
id_doc << create_node('IndServicio') { |n| n << 1 }
|
35
|
+
id_doc << create_node('IndMntNeto') { |n| n << 2 }
|
36
|
+
id_doc << create_node('PeriodoDesde') { |n| n << '2008-08-01' }
|
37
|
+
id_doc << create_node('PeriodoHasta') { |n| n << '2008-08-31' }
|
38
|
+
id_doc << create_node('FchVenc') { |n| n << '2008-09-20' }
|
39
|
+
end
|
40
|
+
encabezado << create_node('Emisor') do |emisor|
|
41
|
+
emisor << create_node('RUTEmisor') { |n| n << '1-9' }
|
42
|
+
emisor << create_node('RznSocEmisor') { |n| n << 'EMPRESA DE PRUEBA' }
|
43
|
+
emisor << create_node('GiroEmisor') { |n| n << 'DESARROLLO DE SISTEMAS' }
|
44
|
+
emisor << create_node('DirOrigen') { |n| n << 'Avenida del Software #11001101' }
|
45
|
+
emisor << create_node('CmnaOrigen') { |n| n << 'PROVIDENCIA' }
|
46
|
+
emisor << create_node('CiudadOrigen') { |n| n << 'SANTIAGO' }
|
47
|
+
end
|
48
|
+
encabezado << create_node('Receptor') do |receptor|
|
49
|
+
receptor << create_node('RUTRecep') { |n| n << '11111111-1' }
|
50
|
+
receptor << create_node('CdgIntRecep') { |n| n << '1000215-220' }
|
51
|
+
receptor << create_node('RznSocRecep') { |n| n << 'CLIENTE DE PRUEBA' }
|
52
|
+
receptor << create_node('Contacto') { |n| n << 'correo@prueba.cl' }
|
53
|
+
receptor << create_node('DirRecep') { |n| n << 'CALLE A 50' }
|
54
|
+
receptor << create_node('CmnaRecep') { |n| n << 'SANTIAGO' }
|
55
|
+
receptor << create_node('CiudadRecep') { |n| n << 'SANTIAGO' }
|
56
|
+
end
|
57
|
+
encabezado << create_node('Totales') do |totales|
|
58
|
+
totales << create_node('MntNeto') { |n| n << '10000' }
|
59
|
+
totales << create_node('MntExe') { |n| n << '1500' }
|
60
|
+
totales << create_node('IVA') { |n| n << '1900' }
|
61
|
+
totales << create_node('MntTotal') { |n| n << '13400' }
|
62
|
+
totales << create_node('MontoNF') { |n| n << '2000' }
|
63
|
+
totales << create_node('TotalPeriodo') { |n| n << '15400' }
|
64
|
+
totales << create_node('SaldoAnterior') { |n| n << '5000' }
|
65
|
+
totales << create_node('VlrPagar') { |n| n << '20400' }
|
66
|
+
end
|
67
|
+
end
|
68
|
+
(1..4).to_a.each do |i|
|
69
|
+
documento << create_node('Detalle') do |detalle|
|
70
|
+
detalle << create_node('NroLinDet') { |n| n << i }
|
71
|
+
detalle << create_node('CdgItem') do |cdg_item|
|
72
|
+
cdg_item << create_node('TpoCodigo') { |n| n << 'INT1' }
|
73
|
+
cdg_item << create_node('VlrCodigo') { |n| n << 'WWW' }
|
74
|
+
end
|
75
|
+
detalle << create_node('NmbItem') { |n| n << "Descripción de producto #{1}" }
|
76
|
+
detalle << create_node('DscItem') { |n| n << 'Serie ABC' }
|
77
|
+
detalle << create_node('QtyItem') { |n| n << '1' }
|
78
|
+
detalle << create_node('UnmdItem') { |n| n << 'M3' }
|
79
|
+
detalle << create_node('PrcItem') { |n| n << 6000 * i }
|
80
|
+
detalle << create_node('MontoItem') { |n| n << 6000 * i }
|
81
|
+
end
|
82
|
+
end
|
83
|
+
documento << create_node('DscRcgGlobal') do |dsc_rcg_global|
|
84
|
+
dsc_rcg_global << create_node('NroLinDR') { |n| n << '1' }
|
85
|
+
dsc_rcg_global << create_node('TpoMov') { |n| n << 'D' }
|
86
|
+
dsc_rcg_global << create_node('GlosaDR') { |n| n << 'Cobro de ventas o servicios previo' }
|
87
|
+
dsc_rcg_global << create_node('TpoValor') { |n| n << '$' }
|
88
|
+
dsc_rcg_global << create_node('ValorDR') { |n| n << '2000' }
|
89
|
+
dsc_rcg_global << create_node('IndExeDR') { |n| n << '2' }
|
90
|
+
end
|
91
|
+
(1..3).to_a.each do |i|
|
92
|
+
documento << create_node('Referencia') do |referencia|
|
93
|
+
referencia << create_node('NroLinRef') { |n| n << i }
|
94
|
+
referencia << create_node('CodRef') { |n| n << 'NROMEDIDOR' }
|
95
|
+
referencia << create_node('RazonRef') { |n| n << '152445596-6655215' }
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
client = Savon.client(
|
102
|
+
wsdl: 'http://ws1.facturacion.cl/WSDS/wsplano.asmx?wsdl'
|
103
|
+
)
|
104
|
+
|
105
|
+
client.operations
|
106
|
+
# => [:procesar, :obtener_link, :get_boleta_ticket, :get_xml_dte, :alt_num,
|
107
|
+
# :reg_ip, :get_ip, :eliminar_doc, :anular_guia, :online, :version]
|
108
|
+
|
109
|
+
login = {
|
110
|
+
'Usuario' => Base64.strict_encode64('MELONCARGO'),
|
111
|
+
'Rut' => Base64.strict_encode64('1-9'),
|
112
|
+
'Clave' => Base64.strict_encode64('plano91098'),
|
113
|
+
'Puerto' => Base64.strict_encode64('9350')
|
114
|
+
}
|
115
|
+
params = {
|
116
|
+
login: login,
|
117
|
+
file: Base64.strict_encode64(doc.to_s),
|
118
|
+
formato: 2
|
119
|
+
}
|
120
|
+
response = client.call(:procesar, message: params)
|
121
|
+
response.body[:procesar_response][:procesar_result]
|
122
|
+
# <?xml version=\"1.0\"?>
|
123
|
+
# <WSPLANO>
|
124
|
+
# <Resultado>False</Resultado>
|
125
|
+
# <Mensaje>Posee documentos con error.</Mensaje>
|
126
|
+
# <Detalle>
|
127
|
+
# <Documento>
|
128
|
+
# <Folio>100</Folio>
|
129
|
+
# <TipoDte>39</TipoDte>
|
130
|
+
# <Operacion>VENTA</Operacion>
|
131
|
+
# <Fecha>2017-02-02T17:00:05</Fecha>
|
132
|
+
# <Resultado>False</Resultado>
|
133
|
+
# <Error>ERROR: P0001: Ya existe la Boleta con TipoDTE = 39 y Folio = 100</Error>
|
134
|
+
# </Documento>
|
135
|
+
# </Detalle>
|
136
|
+
# </WSPLANO>
|
137
|
+
|
138
|
+
# ops = client.operation(:procesar)
|
139
|
+
|
140
|
+
# # build the body of the xml inside the message here
|
141
|
+
# ops.build(message: params).to_s
|
142
|
+
|
143
|
+
doc.save('foo.xml', :indent => true, :encoding => XML::Encoding::UTF_8)
|
144
|
+
|
145
|
+
doc.save('foo.xml', :indent => false, :encoding => XML::Encoding::UTF_8)
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
include Facturapi::Helpers
|
150
|
+
|
151
|
+
Facturapi.configure do |config|
|
152
|
+
config.fact_rut '1-9'
|
153
|
+
config.fact_user 'MELONCARGO'
|
154
|
+
config.fact_password 'plano91098'
|
155
|
+
config.fact_port 9350
|
156
|
+
end
|
157
|
+
|
158
|
+
detalle = []
|
159
|
+
(1..4).to_a.each do |i|
|
160
|
+
detalle << Detalle.new(
|
161
|
+
nro_lin_det: i,
|
162
|
+
tpo_codigo: 'INT1',
|
163
|
+
vlr_codigo: 'WWW',
|
164
|
+
ind_exe: i,
|
165
|
+
rut_mandante: '11111111-1',
|
166
|
+
nmb_item: "Descripción de producto #{i}",
|
167
|
+
dsc_item: 'Serie ABC',
|
168
|
+
qty_item: '1',
|
169
|
+
unmd_item: 'M3',
|
170
|
+
prc_item: 6000 * i,
|
171
|
+
monto_item: 6000 * i
|
172
|
+
)
|
173
|
+
end
|
174
|
+
|
175
|
+
dsc_rcg_global = []
|
176
|
+
(1..2).to_a.each do |i|
|
177
|
+
dsc_rcg_global << DscRcgGlobal.new(
|
178
|
+
nro_lin_dr: i,
|
179
|
+
tpo_mov: 'D',
|
180
|
+
glosa_dr: 'Cobro de ventas o servicios previo',
|
181
|
+
tpo_valor: '$',
|
182
|
+
valor_dr: '2000',
|
183
|
+
ind_exe_dr: '2'
|
184
|
+
)
|
185
|
+
end
|
186
|
+
|
187
|
+
referencia = []
|
188
|
+
(1..3).to_a.each do |i|
|
189
|
+
referencia << Referencia.new(
|
190
|
+
nro_lin_ref: i,
|
191
|
+
cod_ref: 'NROMEDIDOR',
|
192
|
+
razon_ref: '152445596-6655215'
|
193
|
+
)
|
194
|
+
end
|
195
|
+
|
196
|
+
dte = Dte.new(
|
197
|
+
encabezado: Encabezado.new(
|
198
|
+
id_doc: IdDoc.new(
|
199
|
+
tipo_dte: 39,
|
200
|
+
folio: rand(999_999_999),
|
201
|
+
fch_emis: '2008-09-01',
|
202
|
+
ind_servicio: 1,
|
203
|
+
ind_mnt_neto: 2,
|
204
|
+
periodo_desde: '2008-08-01',
|
205
|
+
periodo_hasta: '2008-08-31',
|
206
|
+
fch_venc: '2008-09-20'
|
207
|
+
),
|
208
|
+
emisor: Emisor.new(
|
209
|
+
rut_emisor: '1-9',
|
210
|
+
rzn_soc_emisor: 'EMPRESA DE PRUEBA',
|
211
|
+
giro_emisor: 'DESARROLLO DE SISTEMAS',
|
212
|
+
dir_origen: 'Avenida del Software #11001101',
|
213
|
+
cmna_origen: 'PROVIDENCIA',
|
214
|
+
ciudad_origen: 'SANTIAGO'
|
215
|
+
),
|
216
|
+
receptor: Receptor.new(
|
217
|
+
rut_recep: '11111111-1',
|
218
|
+
cdg_int_recep: '1000215-220',
|
219
|
+
rzn_soc_recep: 'CLIENTE DE PRUEBA',
|
220
|
+
contacto: 'correo@prueba.cl',
|
221
|
+
dir_recep: 'CALLE A 50',
|
222
|
+
cmna_recep: 'SANTIAGO',
|
223
|
+
ciudad_recep: 'SANTIAGO'
|
224
|
+
),
|
225
|
+
totales: Totales.new(
|
226
|
+
mnt_neto: '10000',
|
227
|
+
mnt_exe: '1500',
|
228
|
+
iva: '1900',
|
229
|
+
mnt_total: '13400',
|
230
|
+
monto_nf: '2000',
|
231
|
+
total_periodo: '15400',
|
232
|
+
saldo_anterior: '5000',
|
233
|
+
vlr_pagar: '20400'
|
234
|
+
)
|
235
|
+
),
|
236
|
+
detalle: detalle,
|
237
|
+
dsc_rcg_global: dsc_rcg_global,
|
238
|
+
referencia: referencia
|
239
|
+
)
|
240
|
+
|
241
|
+
procesar = Facturapi::Service::Procesar.new(dte)
|
242
|
+
|
243
|
+
doc = procesar.send
|
244
|
+
ok = doc.css('WSPLANO>Resultado').text
|
245
|
+
mensaje = doc.css('WSPLANO>Mensaje').text
|
246
|
+
error = doc.css('Documento>Error').text
|
metadata
ADDED
@@ -0,0 +1,167 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: facturapi
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alter Lagos
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-02-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: savon
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: libxml-ruby
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: nokogiri
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.4'
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: 1.4.0
|
51
|
+
type: :runtime
|
52
|
+
prerelease: false
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - "~>"
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '1.4'
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 1.4.0
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: bundler
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '1.13'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '1.13'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: rake
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '10.0'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '10.0'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: rspec
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '3.0'
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - "~>"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '3.0'
|
103
|
+
description:
|
104
|
+
email:
|
105
|
+
- alter.strife@gmail.com
|
106
|
+
executables: []
|
107
|
+
extensions: []
|
108
|
+
extra_rdoc_files: []
|
109
|
+
files:
|
110
|
+
- ".gitignore"
|
111
|
+
- ".rspec"
|
112
|
+
- ".ruby-gemset"
|
113
|
+
- ".ruby-version"
|
114
|
+
- ".travis.yml"
|
115
|
+
- CODE_OF_CONDUCT.md
|
116
|
+
- Gemfile
|
117
|
+
- LICENSE.txt
|
118
|
+
- README.md
|
119
|
+
- Rakefile
|
120
|
+
- bin/console
|
121
|
+
- bin/setup
|
122
|
+
- facturapi.gemspec
|
123
|
+
- foo.xml
|
124
|
+
- lala.html
|
125
|
+
- lib/facturapi.rb
|
126
|
+
- lib/facturapi/client.rb
|
127
|
+
- lib/facturapi/config.rb
|
128
|
+
- lib/facturapi/helpers.rb
|
129
|
+
- lib/facturapi/helpers/detalle.rb
|
130
|
+
- lib/facturapi/helpers/dsc_rcg_global.rb
|
131
|
+
- lib/facturapi/helpers/dte.rb
|
132
|
+
- lib/facturapi/helpers/emisor.rb
|
133
|
+
- lib/facturapi/helpers/encabezado.rb
|
134
|
+
- lib/facturapi/helpers/id_doc.rb
|
135
|
+
- lib/facturapi/helpers/receptor.rb
|
136
|
+
- lib/facturapi/helpers/referencia.rb
|
137
|
+
- lib/facturapi/helpers/totales.rb
|
138
|
+
- lib/facturapi/service.rb
|
139
|
+
- lib/facturapi/service/procesar.rb
|
140
|
+
- lib/facturapi/version.rb
|
141
|
+
- lib/facturapi/xml.rb
|
142
|
+
- todo.rb
|
143
|
+
homepage:
|
144
|
+
licenses:
|
145
|
+
- MIT
|
146
|
+
metadata: {}
|
147
|
+
post_install_message:
|
148
|
+
rdoc_options: []
|
149
|
+
require_paths:
|
150
|
+
- lib
|
151
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
152
|
+
requirements:
|
153
|
+
- - ">="
|
154
|
+
- !ruby/object:Gem::Version
|
155
|
+
version: '0'
|
156
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
157
|
+
requirements:
|
158
|
+
- - ">="
|
159
|
+
- !ruby/object:Gem::Version
|
160
|
+
version: '0'
|
161
|
+
requirements: []
|
162
|
+
rubyforge_project:
|
163
|
+
rubygems_version: 2.5.1
|
164
|
+
signing_key:
|
165
|
+
specification_version: 4
|
166
|
+
summary: Ruby integration with facturacion.cl service
|
167
|
+
test_files: []
|