MX-SAT 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +20 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +11 -0
  5. data/.yardopts +9 -0
  6. data/Gemfile +34 -0
  7. data/Guardfile +26 -0
  8. data/LICENSE.txt +22 -0
  9. data/MX-SAT.gemspec +26 -0
  10. data/README.md +89 -0
  11. data/REFERENCIAS.md +30 -0
  12. data/Rakefile +15 -0
  13. data/data/MX/SAT/contabilidad/archivos/v1.0/pdf/Anexo24_05012015.pdf +0 -0
  14. data/data/MX/SAT/contabilidad/archivos/v1.0/pdf/M_1aRMRMF_270215.pdf +0 -0
  15. data/data/MX/SAT/contabilidad/archivos/v1.0/pdf/RecomendacionesalSAT.pdf +0 -0
  16. data/data/MX/SAT/contabilidad/archivos/v1.0/pdf/catalogo_bancos.pdf +0 -0
  17. data/data/MX/SAT/contabilidad/archivos/v1.0/pdf/catalogo_metodos_pago.pdf +0 -0
  18. data/data/MX/SAT/contabilidad/archivos/v1.0/pdf/catalogo_monedas.pdf +0 -0
  19. data/data/MX/SAT/contabilidad/archivos/v1.0/pdf/codigo_agrupador.pdf +0 -0
  20. data/data/MX/SAT/contabilidad/archivos/v1.0/pdf/e_AuxiliarCtas.pdf +0 -0
  21. data/data/MX/SAT/contabilidad/archivos/v1.0/pdf/e_AuxiliarFolios.pdf +0 -0
  22. data/data/MX/SAT/contabilidad/archivos/v1.0/pdf/e_BalanzaComprobacion.pdf +0 -0
  23. data/data/MX/SAT/contabilidad/archivos/v1.0/pdf/e_CatalogoCuentas.pdf +0 -0
  24. data/data/MX/SAT/contabilidad/archivos/v1.0/pdf/e_PolizasPeriodo.pdf +0 -0
  25. data/data/MX/SAT/contabilidad/archivos/v1.0/pdf/e_SelloDigitalContElec.pdf +0 -0
  26. data/data/MX/SAT/contabilidad/archivos/v1.0/pdf/extracto_reglas.pdf +0 -0
  27. data/data/MX/SAT/contabilidad/archivos/v1.0/plantillas_xls/balanza_comprobacion.xlsx +0 -0
  28. data/data/MX/SAT/contabilidad/archivos/v1.0/plantillas_xls/catalogo_cuentas.xlsx +0 -0
  29. data/lib/MX/SAT.rb +8 -0
  30. data/lib/MX/SAT/Contabilidad/balanza_comprobacion.rb +141 -0
  31. data/lib/MX/SAT/Contabilidad/catalogo_cuentas.rb +117 -0
  32. data/lib/MX/SAT/Contabilidad/data/v1.1/xsd/AuxiliarCtas_1_1.xsd +215 -0
  33. data/lib/MX/SAT/Contabilidad/data/v1.1/xsd/AuxiliarFolios_1_2.xsd +342 -0
  34. data/lib/MX/SAT/Contabilidad/data/v1.1/xsd/BalanzaComprobacion_1_1.xsd +160 -0
  35. data/lib/MX/SAT/Contabilidad/data/v1.1/xsd/CatalogoCuentas_1_1.xsd +157 -0
  36. data/lib/MX/SAT/Contabilidad/data/v1.1/xsd/CatalogosParaEsqContE.xsd +1398 -0
  37. data/lib/MX/SAT/Contabilidad/data/v1.1/xsd/PolizasPeriodo_1_1.xsd +664 -0
  38. data/lib/MX/SAT/Contabilidad/data/v1.1/xsd/SelloDigitalContElec.xsd +80 -0
  39. data/lib/MX/SAT/Contabilidad/data/v1.1/xslt/AuxiliarCtas_1_1.xslt +63 -0
  40. data/lib/MX/SAT/Contabilidad/data/v1.1/xslt/AuxiliarFolios_1_1.xslt +104 -0
  41. data/lib/MX/SAT/Contabilidad/data/v1.1/xslt/BalanzaComprobacion_1_1.xslt +53 -0
  42. data/lib/MX/SAT/Contabilidad/data/v1.1/xslt/CatalogoCuentas_1_1.xslt +47 -0
  43. data/lib/MX/SAT/Contabilidad/data/v1.1/xslt/PolizasPeriodo_1_1.xslt +176 -0
  44. data/lib/MX/SAT/Contabilidad/data/v1.1/xslt/utilerias.xslt +22 -0
  45. data/lib/MX/SAT/certificacion.rb +36 -0
  46. data/lib/MX/SAT/version.rb +6 -0
  47. data/spec/MX/SAT/contabilidad/balanza_comprobacion_spec.rb +160 -0
  48. data/spec/MX/SAT/contabilidad/catalogo_cuentas_spec.rb +101 -0
  49. data/spec/spec_helper.rb +23 -0
  50. data/spec/support/archivos/xlsx/balanza_comprobacion_complementaria.xlsx +0 -0
  51. data/spec/support/archivos/xlsx/balanza_comprobacion_normal.xlsx +0 -0
  52. data/spec/support/archivos/xlsx/catalogo_cuentas.xlsx +0 -0
  53. data/spec/support/archivos/xml/MTS110304UT4201501BC.xml +8 -0
  54. data/spec/support/archivos/xml/MTS110304UT4201501BN.xml +8 -0
  55. data/spec/support/archivos/xml/MTS110304UT4201501CT.xml +8 -0
  56. metadata +152 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 98383d377a37962acb6320a75fb0b418dd53828c
4
+ data.tar.gz: 93fbd15b9c2199fc759b25f16f9bc6e59417df27
5
+ SHA512:
6
+ metadata.gz: d9272231377b151d3f9bd84b9d760f54bd61f89e5c9c6da28aca45c8b892f0950f277819b3999cb1be62c9fbaf16b6a10c6cd53a40597c99a9b5a31a7bd9a390
7
+ data.tar.gz: 6e0e44b4a136565434767077df76149e0923a2e18e53922dd2f3577dca890c85f0875feaea04aa2cc012f0fc79c0aea10850321e72893225ac3fb31e8ed87f3c
@@ -0,0 +1,20 @@
1
+ /.bundle/
2
+ /xmls/
3
+ /.yardoc
4
+ /Gemfile.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
11
+ *.bundle
12
+ *.so
13
+ *.o
14
+ *.a
15
+ *.gem
16
+ .ruby-version
17
+ .ruby-gemset
18
+ mkmf.log
19
+ .DS_Store
20
+ ~*
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format progress
3
+ --require spec_helper
@@ -0,0 +1,11 @@
1
+ language: ruby
2
+
3
+ before_install:
4
+ - gem install bundler -v '>= 1.5.1'
5
+
6
+ rvm:
7
+ - 1.9.3
8
+ - 2.0.0
9
+ - 2.1
10
+ - 2.2
11
+ - ruby-head
@@ -0,0 +1,9 @@
1
+ --title 'MX-ID'
2
+ --output-dir ./doc
3
+ --markup-provider redcarpet
4
+ --markup markdown
5
+ --protected --private
6
+ --readme README.md
7
+ lib/**/*.rb - LICENSE.txt REFERENCIAS.md
8
+
9
+
data/Gemfile ADDED
@@ -0,0 +1,34 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :development do
6
+ gem 'guard'
7
+ gem 'guard-bundler', require: false
8
+ gem 'guard-rspec', require: false
9
+ gem "pry"
10
+ gem "pry-remote"
11
+ gem "pry-byebug", platform: [:mri_20, :mri_21, :mri_22]
12
+ gem 'terminal-notifier'
13
+ gem 'terminal-notifier-guard'
14
+ end
15
+
16
+ group :development, :test do
17
+ gem "bundler"
18
+ gem "rake"
19
+ gem "rspec", "~> 3.2"
20
+ end
21
+
22
+ group :test do
23
+ gem "coveralls", require: false
24
+ gem "codeclimate-test-reporter"
25
+ gem 'rspec-collection_matchers'
26
+ gem 'equivalent-xml'
27
+ gem 'shoulda-matchers', require: false
28
+ end
29
+
30
+ group :doc do
31
+ gem 'yard'
32
+ gem 'redcarpet'
33
+ gem 'github-markup'
34
+ end
@@ -0,0 +1,26 @@
1
+ guard :rspec, cmd: "bundle exec rspec", cmd_additional_args: '-f progress', failed_mode: :focus do
2
+ require "guard/rspec/dsl"
3
+ dsl = Guard::RSpec::Dsl.new(self)
4
+
5
+ # RSpec files
6
+ rspec = dsl.rspec
7
+ watch(rspec.spec_helper) { rspec.spec_dir }
8
+ watch(rspec.spec_support) { rspec.spec_dir }
9
+ watch(rspec.spec_files)
10
+
11
+ # Ruby files
12
+ ruby = dsl.ruby
13
+ dsl.watch_spec_files_for(ruby.lib_files)
14
+ end
15
+
16
+ guard :bundler do
17
+ require 'guard/bundler'
18
+ require 'guard/bundler/verify'
19
+ helper = Guard::Bundler::Verify.new
20
+
21
+ files = ['Gemfile']
22
+ files += Dir['*.gemspec'] if files.any? { |f| helper.uses_gemspec?(f) }
23
+
24
+ # Assume files are symlinked from somewhere
25
+ files.each { |file| watch(helper.real_path(file)) }
26
+ end
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Pablo Ruiz
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.
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'MX/SAT/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "MX-SAT"
8
+ spec.version = MX::SAT::VERSION # `git describe --tags --abbrev=0`.strip
9
+ spec.authors = ["Pablo Ruiz"]
10
+ spec.email = ["pjruiz@maquech.com.mx"]
11
+ spec.summary = %q{Mexican taxpayers utilities / Utilerías para lidiar con Sistema de Administración Tributaria (SAT)}
12
+ spec.description = %q{Mexican taxpayers utilities / Utilerías para lidiar con Sistema de Administración Tributaria (SAT)}
13
+ spec.homepage = "https://github.com/Maquech/MX-SAT"
14
+ spec.license = "MIT"
15
+ spec.post_install_message = "¡Viva México!"
16
+
17
+ spec.required_ruby_version = '>= 1.9.3'
18
+ spec.files = `git ls-files -z`.split("\x0")
19
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_dependency 'nokogiri', '>= 1.6'
24
+ spec.add_dependency 'simple_xlsx_reader'
25
+ spec.add_dependency 'rubyzip'
26
+ end
@@ -0,0 +1,89 @@
1
+ # MX::SAT
2
+
3
+ Utilites for dealing with Mexico's revenue service
4
+
5
+ ---
6
+
7
+ Utilerías para lidiar con el SAT (SHCP) de México.
8
+
9
+
10
+ ## Installation / Instalación
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'MX-SAT'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install MX-SAT
25
+
26
+ ---
27
+
28
+ Agrega esta línea al archivo Gemfile de tu aplicación:
29
+
30
+ ```ruby
31
+ gem 'MX-SAT'
32
+ ```
33
+
34
+ Luego ejecuta:
35
+
36
+ $ bundle
37
+
38
+ O instálalo tu mismo usando:
39
+
40
+ $ gem install MX-SAT
41
+
42
+
43
+ ## Usage / Uso
44
+
45
+
46
+ Pendiente...
47
+
48
+
49
+ ## Contributing / Contribuir
50
+
51
+ 1. Fork it ( https://github.com/Maquech/MX-SAT/fork )
52
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
53
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
54
+ 4. Push to the branch (`git push origin my-new-feature`)
55
+ 5. Create a new Pull Request
56
+
57
+ You can also submit technical observations on the algorithms here implemented alongside with references to official documentation that supports it.
58
+
59
+ ---
60
+
61
+ Puedes contribuir mandándonos tus observaciones sobre la implementación de los algoritmos aquí implementados o referencias a documentos oficiales que las respalde.
62
+
63
+ Ahora, diviérte con esta traducción (si sabes el término correcto en español, háznoslo saber por favor):
64
+
65
+ 1. Crea tu copia del repositorio ( https://github.com/Maquech/MX-SAT/fork )
66
+ 2. Crea tu rama con la funcionalidad propuesta (`git checkout -b mi-nueva-funcionalidad-shubiduby`)
67
+ 3. Compromete tus cambios (`git commit -am 'Nueva funcionalidad shubiduby'`)
68
+ 4. Empuja la rama a tu repositorio (`git push origin mi-nueva-funcionalidad-shubiduby`)
69
+ 5. Crea una nueva petición de jalada|tirada|extracción|acarreo
70
+
71
+
72
+ ## Docs
73
+
74
+ Use `bundle exec yard server --port 8828 --reload` para generar la documentación. También revisa las [referencias](REFERENCIAS.md)
75
+
76
+
77
+ ## Code status / Estado del código
78
+
79
+ [![Build Status][Travis-CI-badge]][Travis-CI-url] [![Code Climate][Code Climate-badge]][Code Climate-url] [![Coverage Status][Coveralls-badge]][Coveralls-url]
80
+ [![Gem Version][gem-badge]][gem-url]
81
+
82
+ [Travis-CI-badge]: https://travis-ci.org/Maquech/MX-SAT.svg?branch=master
83
+ [Travis-CI-url]: https://travis-ci.org/Maquech/MX-SAT
84
+ [Code Climate-badge]: https://codeclimate.com/github/Maquech/MX-SAT/badges/gpa.svg
85
+ [Code Climate-url]: https://codeclimate.com/github/Maquech/MX-SAT
86
+ [Coveralls-badge]: https://coveralls.io/repos/Maquech/MX-SAT/badge.svg?branch=master
87
+ [Coveralls-url]: https://coveralls.io/r/Maquech/MX-SAT?branch=master
88
+ [gem-badge]: https://badge.fury.io/rb/MX-SAT.svg
89
+ [gem-url]: http://badge.fury.io/rb/MX-SAT
@@ -0,0 +1,30 @@
1
+ # Los XSDs del SAT tienen errores (al 28 de Feb de 2015)
2
+ El `schemaLocation` y el `xmlns:catalogoscuentas` tienen errores en las URLs (falta el `http://`) pero de ponerlo, el validador del SAT marca error. Idiotas. Los namespaces válidos son:
3
+
4
+ ```
5
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6
+ xmlns:catalogocuentas="www.sat.gob.mx/esquemas/ContabilidadE/1_1/CatalogoCuentas"
7
+ xsi:schemaLocation="www.sat.gob.mx/esquemas/ContabilidadE/1_1/CatalogoCuentas http://www.sat.gob.mx/esquemas/ContabilidadE/1_1/CatalogoCuentas/CatalogoCuentas_1_1.xsd"
8
+ ```
9
+
10
+ Mismo caso para las balanzas, los namespaces no concuerdan con la documentación del diario oficial. Doblemente idiotas. Los namespaces válidos son:
11
+
12
+ ```
13
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
14
+ xmlns:BCE="www.sat.gob.mx/esquemas/ContabilidadE/1_1/BalanzaComprobacion"
15
+ xsi:schemaLocation="www.sat.gob.mx/esquemas/ContabilidadE/1_1/BalanzaComprobacion http://www.sat.gob.mx/esquemas/ContabilidadE/1_1/BalanzaComprobacion/BalanzaComprobacion_1_1.xsd"
16
+ ```
17
+
18
+
19
+ ## Referencias
20
+
21
+ ### Oficiales
22
+
23
+ * [SAT, contabilidad electrónica](http://www.sat.gob.mx/fichas_tematicas/buzon_tributario/Paginas/contabilidad_electronica.aspx)
24
+ * [Validador del SAT](https://ceportalvalidacionprod.clouda.sat.gob.mx/)
25
+
26
+
27
+ ### No oficiales
28
+
29
+ * [ValidaCFD](http://www.validacfd.com/phpbb3/viewtopic.php?f=16&t=4805&start=130)
30
+ * [Fortiz @ lacorona.com.mx - siempre me saca de dudas con sus publicaciones](http://www.lacorona.com.mx/fortiz/sat/ce/)
@@ -0,0 +1,15 @@
1
+ begin
2
+ require 'bundler/gem_tasks'
3
+ require 'rspec/core/rake_task'
4
+ require 'yard'
5
+ YARD::Rake::YardocTask.new
6
+
7
+ RSpec::Core::RakeTask.new(:spec, :tag) do |t, task_args|
8
+ t.rspec_opts = ["--tag #{task_args[:tag]}", "--format", "--color"]
9
+ end
10
+
11
+ task default: :spec
12
+ task test: :spec
13
+ rescue LoadError
14
+ end
15
+
@@ -0,0 +1,8 @@
1
+ # encoding: utf-8
2
+ require 'simple_xlsx_reader'
3
+ require 'nokogiri'
4
+
5
+ require "MX/SAT/version"
6
+ require "MX/SAT/certificacion"
7
+ require "MX/SAT/Contabilidad/balanza_comprobacion"
8
+ require "MX/SAT/Contabilidad/catalogo_cuentas"
@@ -0,0 +1,141 @@
1
+ # encoding: UTF-8
2
+ module MX::SAT::Contabilidad
3
+ class BalanzaComprobacion
4
+ VERSION = "1.1"
5
+
6
+ XSD_BALANZA_COMPROBACION = File.join(File.dirname(__FILE__), 'data', "v#{VERSION}", 'xsd', 'BalanzaComprobacion_1_1.xsd')
7
+ XSLT_BALANZA_COMPROBACION = File.join(File.dirname(__FILE__), 'data', "v#{VERSION}", 'xslt', 'BalanzaComprobacion_1_1.xslt')
8
+
9
+ TIPO_ENVIO_COMPLEMENTARIA = "C"
10
+ TIPO_ENVIO_NORMAL = "N"
11
+ TIPOS_ENVIO = [TIPO_ENVIO_NORMAL, TIPO_ENVIO_COMPLEMENTARIA].freeze
12
+
13
+ # OJOOOOOO están mal las URLs, pero el SAT así las tiene en sus XSDs al 28 de Feb de 2015
14
+ NAMESPACE = { 'xmlns:BCE' => "www.sat.gob.mx/esquemas/ContabilidadE/1_1/BalanzaComprobacion" }.freeze
15
+ NAMESPACES = {
16
+ 'xsi:schemaLocation' => "www.sat.gob.mx/esquemas/ContabilidadE/1_1/BalanzaComprobacion" +
17
+ " http://www.sat.gob.mx/esquemas/ContabilidadE/1_1/BalanzaComprobacion/BalanzaComprobacion_1_1.xsd",
18
+ 'xmlns:xsi' => "http://www.w3.org/2001/XMLSchema-instance"
19
+ }.merge(NAMESPACE).freeze
20
+
21
+
22
+ attr_reader :xml, :xml_certificado, :nombre_archivo
23
+ attr_accessor :rfc, :año, :mes, :tipo_envio, :fecha_modificacion, :datos, :certificado, :llave_privada, :passwd_llave_privada
24
+
25
+ def initialize
26
+ @xml = nil
27
+ @xml_certificado = nil
28
+ @nombre_archivo = nil
29
+ @rfc = nil
30
+ @año = nil
31
+ @mes = nil
32
+ @tipo_envio = nil
33
+ @fecha_mod_bal = nil
34
+ @fecha_modificacion = nil
35
+ @datos = []
36
+ @certificado = nil
37
+ @llave_privada = nil
38
+ @passwd_llave_privada = nil
39
+ end
40
+
41
+ def cargar_xslx(archivo)
42
+ doc = ::SimpleXlsxReader.open(archivo)
43
+ filas = doc.sheets.find{ |s| s.name.downcase == "datos" }.rows[1..-1]
44
+ obtener_atributos_generales(filas.first)
45
+ obtener_datos(filas)
46
+ end
47
+
48
+ def to_xml
49
+ return if @datos.empty?
50
+ builder = ::Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |xml|
51
+ xml['BCE'].Balanza(atributos_nodo_balanza){ @datos.each{ |dato| xml.Ctas(dato) } }
52
+ end
53
+ @xml = builder.to_xml
54
+ certificar_xml
55
+ end
56
+
57
+ def generar_archivo_xml
58
+ return unless @nombre_archivo
59
+ File.open("#{@nombre_archivo}.xml", "w") {|f| f.write(@xml_certifcado || @xml || self.to_xml) }
60
+ "#{@nombre_archivo}.xml"
61
+ end
62
+
63
+ def generar_archivo_zip
64
+ return unless @nombre_archivo
65
+ self.generar_archivo_xml unless File.exist?("#{@nombre_archivo}.xml")
66
+ ::Zip::File.open(File.join("#{@nombre_archivo}.zip"), ::Zip::File::CREATE) do |archivo_zip|
67
+ archivo_zip.add("#{@nombre_archivo}.xml", "#{@nombre_archivo}.xml")
68
+ end
69
+ "#{@nombre_archivo}.zip"
70
+ end
71
+
72
+ def xml_valido?
73
+ xsd_doc = Nokogiri::XML::Schema(File.open(XSD_BALANZA_COMPROBACION, 'rb'))
74
+ xml_doc = Nokogiri::XML(@xml_certificado || @xml || self.to_xml, nil, 'UTF-8')
75
+ errors = ""
76
+ xsd_doc.validate(xml_doc).each { |error| errors += " #{error.message}" }
77
+ doc_valido = xsd_doc.valid?(xml_doc)
78
+ puts "XML validado con #{xsd} es INVÁLIDO!: #{errors}" unless doc_valido
79
+ return doc_valido
80
+ end
81
+
82
+
83
+ private
84
+ def certificar_xml
85
+ if !@certificado.nil? and !@llave_privada.nil?
86
+ @xml_certificado = agregar_certificacion_xml
87
+ else
88
+ @xml
89
+ end
90
+ end
91
+
92
+ def agregar_certificacion_xml
93
+ xml_doc_sin_sello = Nokogiri::XML(@xml || to_xml, nil, 'UTF-8')
94
+ cadena = ::MX::SAT::Certificacion.generar_cadena_original(@xml, XSLT_BALANZA_COMPROBACION)
95
+ nodo_raiz = xml_doc_sin_sello.at_xpath('/BCE:Balanza', NAMESPACE)
96
+ nodo_raiz['Sello'] = ::MX::SAT::Certificacion.firma_sha256(cadena, @llave_privada, @passwd_llave_privada)
97
+ nodo_raiz['noCertificado'] = ::MX::SAT::Certificacion.num_serial_certificado(@certificado)
98
+ nodo_raiz['Certificado'] = ::MX::SAT::Certificacion.certificado_b64(@certificado)
99
+ xml_doc_sin_sello.to_xml
100
+ end
101
+
102
+ def atributos_nodo_balanza
103
+ atributos = { Version: VERSION, RFC: @rfc, Mes: @mes, Anio: @año, TipoEnvio: @tipo_envio }
104
+ atributos[:FechaModBal] = @fecha_modificacion unless @fecha_modificacion.nil?
105
+ atributos.merge(NAMESPACES)
106
+ end
107
+
108
+ def establecer_fecha_modificacion
109
+ begin
110
+ @fecha_modificacion = Date.parse(@fecha_mod_bal).to_s if @fecha_mod_bal and !@fecha_mod_bal.empty?
111
+ @fecha_modificacion = 'falta_fecha' if @fecha_mod_bal.nil? and @fecha_mod_bal.empty? and (@tipo_envio == "C")
112
+ rescue ArgumentError
113
+ @fecha_modificacion = 'formato_fecha_incorrecta'
114
+ end
115
+ end
116
+
117
+ def obtener_atributos_generales(fila)
118
+ arr = fila[0..4]
119
+ @rfc, mes, @año, @tipo_envio, @fecha_mod_bal = *arr
120
+ @mes = fmto_mes(mes)
121
+ establecer_fecha_modificacion
122
+ @nombre_archivo = "#{@rfc}#{@año}#{@mes}B#{@tipo_envio}"
123
+ end
124
+
125
+ def obtener_datos(filas)
126
+ @datos = filas.map do |fila|
127
+ { NumCta: fila[5], SaldoIni: fmto_decimal(fila[6]),
128
+ Debe: fmto_decimal(fila[7]), Haber: fmto_decimal(fila[8]), SaldoFin: fmto_decimal(fila[9]) }
129
+ end
130
+ end
131
+
132
+ def fmto_decimal(num)
133
+ return "0" if num.to_i.zero?
134
+ "%.2f" % num
135
+ end
136
+
137
+ def fmto_mes(num)
138
+ "%02d" % num
139
+ end
140
+ end
141
+ end