facturacr 1.0.9 → 1.1.0

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.
@@ -1,3 +1,3 @@
1
1
  module FE
2
- VERSION = "1.0.9"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -5,7 +5,7 @@ require 'facturacr/document'
5
5
  module FE
6
6
  class XmlDocument
7
7
 
8
- attr_accessor :document, :root_tag
8
+ attr_accessor :document, :root_tag, :doc, :xml
9
9
 
10
10
  def initialize(xml_provider)
11
11
  # Backwards compatibility with v0.1.4
@@ -14,8 +14,8 @@ module FE
14
14
  xml_provider = FE::DataProvider.new(:file, xml_provider)
15
15
  end
16
16
  raise ArgumentError, "Invalid Argument" unless xml_provider.is_a?(FE::DataProvider)
17
-
18
- @doc = Nokogiri::XML(xml_provider.contents) do |config|
17
+ @xml = xml_provider.contents
18
+ @doc = Nokogiri::XML(@xml) do |config|
19
19
  config.options = Nokogiri::XML::ParseOptions::NOBLANKS | Nokogiri::XML::ParseOptions::NOENT
20
20
  end
21
21
  root_tag = @doc.elements.first.name
@@ -33,8 +33,11 @@ module FE
33
33
  end
34
34
 
35
35
  if @document.is_a?(FE::Document)
36
-
36
+ @document.version = @doc.elements.first.namespace.href.scan(/v4\..{1}/).first[1..-1]
37
37
  @document.date = DateTime.parse(@doc.css("#{root_tag} FechaEmision").first&.text)
38
+ if @document.version_43?
39
+ @document.economic_activity = @doc.css("#{root_tag} CodigoActividad").text
40
+ end
38
41
  @key = @doc.css("#{root_tag} Clave").text
39
42
  @document.key = @key if @key.present?
40
43
  @document.headquarters = @key[21..23]
@@ -97,7 +100,11 @@ module FE
97
100
  @doc.css("#{root_tag} DetalleServicio LineaDetalle").each do |line|
98
101
  item = FE::Document::Item.new
99
102
  item.line_number = line.css("NumeroLinea").text.to_i
100
- item.code = line.css("Codigo Codigo").text
103
+ if @document.version_42?
104
+ item.code = line.css("Codigo Codigo").text
105
+ elsif @document.version_43?
106
+ item.code = line.css("CodigoComercial Codigo").text
107
+ end
101
108
  item.quantity = line.css("Cantidad").text
102
109
  item.unit = line.css("UnidadMedida").text
103
110
  item.description = line.css("Detalle").text
@@ -130,8 +137,13 @@ module FE
130
137
 
131
138
  @summary = FE::Document::Summary.new
132
139
  sum = @doc.css("#{root_tag} ResumenFactura")
133
- @summary.currency = sum.css("CodigoMoneda").text
134
- @summary.exchange_rate = sum.css("TipoCambio").text.to_f
140
+ if @document.version_42?
141
+ @summary.currency = sum.css("CodigoMoneda").text
142
+ @summary.exchange_rate = sum.css("TipoCambio").text.to_f
143
+ elsif @document.version_43?
144
+ @summary.currency = sum.css("CodigoTipoMoneda CodigoMoneda").text
145
+ @summary.exchange_rate = sum.css("CodigoTipoMoneda TipoCambio").text.to_f
146
+ end
135
147
  @summary.services_taxable_total = sum.css("TotalServGravados").text.to_f
136
148
  @summary.services_exent_total = sum.css("TotalServExentos").text.to_f
137
149
  @summary.goods_taxable_total = sum.css("TotalMercanciasGravadas").text.to_f
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: facturacr
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.9
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josef Sauter
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-02-12 00:00:00.000000000 Z
11
+ date: 2019-09-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -188,6 +188,7 @@ files:
188
188
  - lib/facturacr/document/issuer.rb
189
189
  - lib/facturacr/document/item.rb
190
190
  - lib/facturacr/document/location.rb
191
+ - lib/facturacr/document/other_charges.rb
191
192
  - lib/facturacr/document/other_content.rb
192
193
  - lib/facturacr/document/other_content/price_smart.rb
193
194
  - lib/facturacr/document/other_text.rb
@@ -198,7 +199,11 @@ files:
198
199
  - lib/facturacr/document/regulation.rb
199
200
  - lib/facturacr/document/summary.rb
200
201
  - lib/facturacr/document/tax.rb
202
+ - lib/facturacr/element.rb
203
+ - lib/facturacr/error.rb
204
+ - lib/facturacr/export_invoice.rb
201
205
  - lib/facturacr/invoice.rb
206
+ - lib/facturacr/purchase_invoice.rb
202
207
  - lib/facturacr/reception_message.rb
203
208
  - lib/facturacr/signed_document.rb
204
209
  - lib/facturacr/signer/signer.rb