facturacr 1.0 → 1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: db381bbaa82171a178d543ba768b109dda40ce9b
4
- data.tar.gz: 3dd2171473e12c9f578c9d21d12d18fe600d587d
3
+ metadata.gz: 784afc0b9e27eeef2d3dbd6770bc37c74c268a4e
4
+ data.tar.gz: 0c1db15bd3360912262cf5ec191432464ee6a9f0
5
5
  SHA512:
6
- metadata.gz: 86db7abd0fc67508f335f56de8d561a7fdbc7bc55147821a2bb07c919f3d2f7e0d5159d6edcf2e971c9914677f11d4d58e1c6b50e533a6b669d028ea220252db
7
- data.tar.gz: f16d24d241f22cc0e70d4672d46528dffbbe1b6e7fb85d21add0754635658c2d39341de002aff4192a0128ce9130db47c4ca0376d01c3e689431387a83bedf93
6
+ metadata.gz: 6e2da292a67d329622eeccd529d0f19232f0c028fc5dd27d53c1184d748f8b121739df10c1c6e392db14566415ad979c9c8aa3cc97c8a69e3f5007f17ccc4a6c
7
+ data.tar.gz: 3d88d6d3e26ccf50d3ec7f0a9db6a6f83e160ea61eab479a12a3c1ae54c4eaf9ad24d9a0897ee52c0949498d6b56dd78d330fe05f94da76875230a8506a51ce3
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
+ *.gem
1
2
  /.bundle/
2
3
  /.yardoc
3
4
  /Gemfile.lock
@@ -8,7 +8,7 @@ module FE
8
8
  def initialize(source, data)
9
9
  source = source.to_s.to_sym
10
10
  raise ArgumentError, "source (#{source}) is not valid" if !SOURCES.include?(source)
11
- raise ArgumentError, "#{data} does not exist" if soruce.eql?(:file) && !File.exists?(data)
11
+ raise ArgumentError, "#{data} does not exist" if source.eql?(:file) && !File.exists?(data)
12
12
 
13
13
  if source.eql?(:string)
14
14
  @contents = data
@@ -42,7 +42,7 @@ module FE
42
42
  attr_accessor :serial, :date, :issuer, :receiver, :condition, :credit_term,
43
43
  :payment_type, :service_type, :reference_information,
44
44
  :regulation, :number, :document_type, :security_code,
45
- :items, :references, :namespaces, :summary, :document_situation
45
+ :items, :references, :namespaces, :summary, :document_situation, :headquarters, :terminal
46
46
 
47
47
  validates :date, presence: true
48
48
  validates :number, presence: true
@@ -53,11 +53,11 @@ module FE
53
53
  private
54
54
 
55
55
  def totals_ok?
56
- errors[:taxable_total] << "invalid amount" unless @taxable_total == (@services_taxable_total + @goods_taxable_total).round(5)
57
- errors[:exent_total] << "invalid amount" unless @exent_total == (@services_exent_total + @goods_exent_total).round(5)
58
- errors[:subtotal] << "invalid amount" unless @subtotal == (@taxable_total + @exent_total).round(5)
59
- errors[:gross_total] << "invalid amount" unless @gross_total == (@subtotal - @discount_total).round(5)
60
- errors[:net_total] << "invalid amount" unless @net_total == (@gross_total + @tax_total).round(5)
56
+ errors[:taxable_total] << "invalid amount" if (@taxable_total - (@services_taxable_total + @goods_taxable_total).round(5)).abs > 0.0005
57
+ errors[:exent_total] << "invalid amount" if (@exent_total - (@services_exent_total + @goods_exent_total).round(5)).abs > 0.0005
58
+ errors[:subtotal] << "invalid amount" if (@subtotal - (@taxable_total + @exent_total).round(5)).abs > 0.0005
59
+ errors[:gross_total] << "invalid amount" if (@gross_total - (@subtotal - @discount_total).round(5)).abs > 0.0005
60
+ errors[:net_total] << "invalid amount" if (@net_total - (@gross_total + @tax_total).round(5)).abs > 0.0005
61
61
  end
62
62
  end
63
63
  end
@@ -8,7 +8,7 @@ module FE
8
8
  # Backwards compatibility with v0.1.4
9
9
  if xml_provider.is_a?(String)
10
10
  raise ArgumentError, "File: #{xml_provider} does not exist" unless File.exists?(xml_provider)
11
- xml_provider = Fe::DataProvider.new(:file, xml_provider)
11
+ xml_provider = FE::DataProvider.new(:file, xml_provider)
12
12
  end
13
13
  raise ArgumentError, "Invalid Argument" unless xml_provider.is_a?(FE::DataProvider)
14
14
 
@@ -23,7 +23,14 @@ module FE
23
23
  XADES = "http://uri.etsi.org/01903/v1.3.2#"
24
24
  XADES141 = "http://uri.etsi.org/01903/v1.4.1#"
25
25
  SIGNATURE_POLICY = "https://tribunet.hacienda.go.cr/docs/esquemas/2016/v4/Resolucion%20Comprobantes%20Electronicos%20%20DGT-R-48-2016.pdf"
26
-
26
+
27
+ XMLNS_MAP = {
28
+ "FacturaElectronica" => "https://tribunet.hacienda.go.cr/docs/esquemas/2017/v4.2/facturaElectronica",
29
+ "NotaCreditoElectronica" => "https://tribunet.hacienda.go.cr/docs/esquemas/2017/v4.2/notaCreditoElectronica",
30
+ "TiqueteElectronico" => "https://tribunet.hacienda.go.cr/docs/esquemas/2017/v4.2/tiqueteElectronico",
31
+ "NotaDebitoElectronica" => "https://tribunet.hacienda.go.cr/docs/esquemas/2017/v4.2/notaDebitoElectronica",
32
+ "MensajeReceptor" => "https://tribunet.hacienda.go.cr/docs/esquemas/2017/v4.2/mensajeReceptor"
33
+ }
27
34
 
28
35
  def initialize(args = {})
29
36
  document_provider = args[:xml_provider]
@@ -36,6 +43,7 @@ module FE
36
43
  @p12 = OpenSSL::PKCS12.new(key_provider.contents,args[:pin])
37
44
  @x509 = @p12.certificate
38
45
  @output_path = args[:output_path]
46
+ @document_tag = @doc.elements.first.name
39
47
  end
40
48
 
41
49
  def sign
@@ -88,7 +96,7 @@ module FE
88
96
  def build_key_info_element
89
97
  builder = Nokogiri::XML::Builder.new
90
98
  attributes = {
91
- "xmlns" => "https://tribunet.hacienda.go.cr/docs/esquemas/2017/v4.2/facturaElectronica",
99
+ "xmlns" => XMLNS_MAP[@document_tag],
92
100
  "xmlns:ds" => "http://www.w3.org/2000/09/xmldsig#",
93
101
  "xmlns:xsd" => "http://www.w3.org/2001/XMLSchema",
94
102
  "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance",
@@ -115,7 +123,7 @@ module FE
115
123
  signing_time = DateTime.now.rfc3339
116
124
  builder = Nokogiri::XML::Builder.new
117
125
  attributes = {
118
- "xmlns"=>"https://tribunet.hacienda.go.cr/docs/esquemas/2017/v4.2/facturaElectronica",
126
+ "xmlns"=>XMLNS_MAP[@document_tag],
119
127
  "xmlns:ds" => "http://www.w3.org/2000/09/xmldsig#",
120
128
  "xmlns:xades" => "http://uri.etsi.org/01903/v1.3.2#",
121
129
  "xmlns:xsd" => "http://www.w3.org/2001/XMLSchema",
@@ -168,7 +176,7 @@ module FE
168
176
 
169
177
  builder = builder = Nokogiri::XML::Builder.new
170
178
  attributes = {
171
- "xmlns"=>"https://tribunet.hacienda.go.cr/docs/esquemas/2017/v4.2/facturaElectronica",
179
+ "xmlns"=>XMLNS_MAP[@document_tag],
172
180
  "xmlns:ds" => "http://www.w3.org/2000/09/xmldsig#",
173
181
  "xmlns:xsd" => "http://www.w3.org/2001/XMLSchema",
174
182
  "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance"
@@ -1,3 +1,3 @@
1
1
  module FE
2
- VERSION = "1.0"
2
+ VERSION = "1.0.1"
3
3
  end
@@ -11,7 +11,7 @@ module FE
11
11
  # Backwards compatibility with v0.1.4
12
12
  if xml_provider.is_a?(String)
13
13
  raise ArgumentError, "File: #{xml_provider} does not exist" unless File.exists?(xml_provider)
14
- xml_provider = Fe::DataProvider.new(:file, xml_provider)
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
17
 
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'
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josef Sauter
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-08-02 00:00:00.000000000 Z
11
+ date: 2018-10-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler