buho_cfdi 0.1.12

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.
@@ -0,0 +1,20 @@
1
+ module Nodes
2
+ class TaxDetained < ::BuhoCfdi::BaseNode
3
+ attr_accessor(
4
+ :base, # Base - required
5
+ :tax, # Impuesto - required
6
+ :factor_type, # TipoFactor - required
7
+ :rate_or_fee, # TasaOCuota - required
8
+ :import # Importe - required
9
+ )
10
+
11
+ validates_presence_of(
12
+ :base,
13
+ :tax,
14
+ :factor_type,
15
+ :rate_or_fee,
16
+ :import
17
+ )
18
+ end
19
+ end
20
+
@@ -0,0 +1,17 @@
1
+ module Nodes
2
+ class TaxTransferred < ::BuhoCfdi::BaseNode
3
+ attr_accessor(
4
+ :base, # Base - required
5
+ :tax, # Impuesto - required
6
+ :factor_type, # TipoFactor - required
7
+ :rate_or_fee, # TasaOCuota - optional
8
+ :import # Importe - optional
9
+ )
10
+
11
+ validates_presence_of(
12
+ :base,
13
+ :tax,
14
+ :factor_type,
15
+ )
16
+ end
17
+ end
@@ -0,0 +1,8 @@
1
+ module Nodes
2
+ class Taxes < ::BuhoCfdi::BaseNode
3
+ attr_accessor(
4
+ :total_taxes_transferred, # TotalImpuestosTrasladados - optional
5
+ :total_taxes_detained # TotalImpuestosRetenidos - optional
6
+ )
7
+ end
8
+ end
@@ -0,0 +1,17 @@
1
+ module Nodes
2
+ class Transferred < ::BuhoCfdi::BaseNode
3
+ attr_accessor(
4
+ :tax, # Impuesto - required
5
+ :factor_type, # TipoFactor - required
6
+ :rate_or_fee, # TasaOCuota - required
7
+ :import # Importe - required
8
+ )
9
+
10
+ validates_presence_of(
11
+ :tax,
12
+ :factor_type,
13
+ :rate_or_fee,
14
+ :import
15
+ )
16
+ end
17
+ end
@@ -0,0 +1,125 @@
1
+ module BuhoCfdi
2
+ class ParamsBuilder
3
+
4
+ attr_accessor(
5
+ :params,
6
+ :receipt
7
+ )
8
+
9
+ def initialize(params)
10
+ @params = params
11
+
12
+ build_receipt
13
+ build_cfdi_related
14
+ build_issuer
15
+ build_receiver
16
+ build_concepts
17
+ build_taxes
18
+
19
+ receipt
20
+ end
21
+
22
+ def build_receipt
23
+ if params.include?(:receipt)
24
+ @receipt = ::Nodes::Receipt.new params.fetch(:receipt)
25
+ else
26
+ nil
27
+ end
28
+ end
29
+
30
+ def build_cfdi_related
31
+ if params.fetch(:receipt).include?(:cfdi_related_attributes)
32
+ @receipt.build_child! ::Nodes::CfdiRelated, params.fetch(:receipt).fetch(:cfdi_related_attributes)
33
+
34
+ if params.fetch(:receipt).fetch(:cfdi_related_attributes).include?(:related_attributes)
35
+ @receipt.nodes_cfdirelated.build_children ::Nodes::Related
36
+
37
+ params.fetch(:receipt).fetch(:cfdi_related_attributes).fetch(:related_attributes).each do |params|
38
+ @receipt.nodes_cfdirelated.nodes_related.add params
39
+ end
40
+ end
41
+ else
42
+ nil
43
+ end
44
+ end
45
+
46
+ def build_issuer
47
+ if params.include?(:receipt) && params.fetch(:receipt).include?(:issuer_attributes)
48
+ @receipt.build_child! ::Nodes::Issuer, params.fetch(:receipt).fetch(:issuer_attributes)
49
+ else
50
+ nil
51
+ end
52
+ end
53
+
54
+ def build_receiver
55
+ if params.include?(:receipt) && params.fetch(:receipt).include?(:receiver_attributes)
56
+ @receipt.build_child! ::Nodes::Receiver, params.fetch(:receipt).fetch(:receiver_attributes)
57
+ else
58
+ nil
59
+ end
60
+ end
61
+
62
+ def build_concepts
63
+ if params.include?(:receipt) && params.fetch(:receipt).include?(:concepts_attributes)
64
+ @receipt.build_children ::Nodes::Concept
65
+
66
+ params.fetch(:receipt).fetch(:concepts_attributes).each do |params|
67
+
68
+ concept = @receipt.nodes_concept.add params
69
+
70
+ if params.include?(:transferred_attributes)
71
+ concept.build_children ::Nodes::TaxTransferred
72
+
73
+ params.fetch(:transferred_attributes).each do |params|
74
+ concept.nodes_taxtransferred.add params
75
+ end
76
+ end
77
+
78
+ if params.include?(:detained_attributes)
79
+ concept.build_children ::Nodes::TaxDetained
80
+
81
+ params.fetch(:detained_attributes).each do |params|
82
+ concept.nodes_taxdetained.add params
83
+ end
84
+ end
85
+
86
+ if params.include?(:customs_information_attributes)
87
+ concept.build_child! ::Nodes::CustomsInformation, params.fetch(:customs_information_attributes)
88
+ end
89
+
90
+ if params.include?(:property_account_attributes)
91
+ concept.build_child! ::Nodes::PropertyAccount, params.fetch(:property_account_attributes)
92
+ end
93
+
94
+ if params.include?(:part_attributes)
95
+ concept.build_child! ::Nodes::Part, params.fetch(:part_attributes)
96
+ end
97
+ end
98
+ else
99
+ nil
100
+ end
101
+ end
102
+
103
+ def build_taxes
104
+ if params.include?(:receipt) && params.fetch(:receipt).include?(:taxes_attributes)
105
+ @receipt.build_child! ::Nodes::Taxes, params.fetch(:receipt).fetch(:taxes_attributes)
106
+
107
+ if params.fetch(:receipt).fetch(:taxes_attributes).include?(:transferred_attributes)
108
+ @receipt.nodes_taxes.build_children ::Nodes::Transferred
109
+
110
+ params.fetch(:receipt).fetch(:taxes_attributes).fetch(:transferred_attributes).each do |params|
111
+ @receipt.nodes_taxes.nodes_transferred.add params
112
+ end
113
+ end
114
+
115
+ if params.fetch(:receipt).fetch(:taxes_attributes).include?(:detained_attributes)
116
+ @receipt.nodes_taxes.build_children ::Nodes::Detained
117
+
118
+ params.fetch(:receipt).fetch(:taxes_attributes).fetch(:detained_attributes).each do |params|
119
+ @receipt.nodes_taxes.nodes_detained.add params
120
+ end
121
+ end
122
+ end
123
+ end
124
+ end
125
+ end
@@ -0,0 +1,106 @@
1
+ {
2
+ "receipt": {
3
+ "version": "3.3",
4
+ "serie": "shuhsuhsuhsw",
5
+ "folio_number": "74777e8e8e",
6
+ "date": "sjsjjsjs",
7
+ "stamp": "jsjsjsjjs",
8
+ "payment_method": "ikskskskis",
9
+ "certificate_number": "osiskksj",
10
+ "certificate": "jsjsjsjjsjs",
11
+ "payment_conditions": "kjsksisosos",
12
+ "subtotal": "jiksksksks",
13
+ "discount": "jjjsjsjsjsj",
14
+ "currency": "jsjksjdhdhd",
15
+ "exchange_rate": "jsjsjdhdfhd",
16
+ "total": "isjsxjdjf",
17
+ "type_of_receipt": "jjsjsjjfd",
18
+ "payment_method": "jjsjsjsjsd",
19
+ "expedition_place": "jsjsjsjjs",
20
+ "confirmation": "jjsjsjsjsjdjd",
21
+ "cfdi_related_attributes": {
22
+ "relationship_type": "jhususjujsujdius",
23
+ "related_attributes": [
24
+ {
25
+ "uuid": "ijisjisjisjisjisj"
26
+ }
27
+ ]
28
+ },
29
+ "issuer_attributes": {
30
+ "rfc": "hudshududhs",
31
+ "name": "jdsjidjsijdi",
32
+ "fiscal_regime": "jdisjdisjid"
33
+ },
34
+ "receiver_attributes": {
35
+ "rfc": "jdisjdisj",
36
+ "name": "jdsjdijsijds",
37
+ "tax_residency": "udisjdisjidjisjd",
38
+ "tax_identity_registration_number": "djisjdisjidjsidjis",
39
+ "cfdi_usage": "disjdisidisdjs"
40
+ },
41
+ "concepts_attributes": [
42
+ {
43
+ "prod_or_svc_key": "",
44
+ "identification_number": "",
45
+ "quantity": "",
46
+ "unit_measure_key": "",
47
+ "unit_measure": "",
48
+ "description": "",
49
+ "unit_value": "",
50
+ "amount": "",
51
+ "discount": "",
52
+ "transferred_attributes": [
53
+ {
54
+ "base": "yysysy",
55
+ "tax": "uususuus",
56
+ "factor_type": "sjisjijis",
57
+ "rate_or_fee": "jsisjijsijs",
58
+ "import": "jsijsijsij"
59
+ }
60
+ ],
61
+ "detained_attributes": [
62
+ {
63
+ "base": "sjisjijsijs",
64
+ "tax": "sjisjijsijsi",
65
+ "factor_type": "sjijsijsijsi",
66
+ "rate_or_fee": "ssijisjisj",
67
+ "import": "sjijsisijisj"
68
+ }
69
+ ],
70
+ "customs_information_attributes": {
71
+ "requirement_number": ""
72
+ },
73
+ "property_account_attributes": {
74
+ "number": ""
75
+ },
76
+ "part_attributes": {
77
+ "prod_or_svc_key": "",
78
+ "identification_number": "",
79
+ "quantity": "",
80
+ "unit_measure": "",
81
+ "description": "",
82
+ "unit_value": "",
83
+ "amount": ""
84
+ }
85
+ }
86
+ ],
87
+ "taxes_attributes": {
88
+ "total_taxes_transferred": "",
89
+ "total_taxes_detained": "",
90
+ "transferred_attributes": [
91
+ {
92
+ "tax": "",
93
+ "factor_type": "",
94
+ "rate_or_fee": "",
95
+ "import": ""
96
+ }
97
+ ],
98
+ "detained_attributes": [
99
+ {
100
+ "tax": "",
101
+ "import": ""
102
+ }
103
+ ]
104
+ }
105
+ }
106
+ }
@@ -0,0 +1,76 @@
1
+ XML_BUILDING_STRATEGY = lambda do |receipt|
2
+ Nokogiri::XML::Builder.new do |xml|
3
+ xml.Comprobante(receipt.to_hash) do
4
+ xml.doc.root.namespace = xml.doc.root.add_namespace_definition('cfdi', 'http://www.sat.gob.mx/cfd/3')
5
+ xml.doc.root.add_namespace_definition('xsi', 'http://www.w3.org/2001/XMLSchema-instance')
6
+
7
+ if ((defined? receipt.nodes_cfdirelated) && receipt.nodes_cfdirelated)
8
+ xml.CfdiRelacionados(receipt.nodes_cfdirelated.to_hash) do
9
+
10
+ if receipt.nodes_cfdirelated.nodes_related
11
+ receipt.nodes_cfdirelated.nodes_related.all.each do |related|
12
+ xml.CfdiRelacionado(related.to_hash)
13
+ end
14
+ end
15
+ end
16
+ end
17
+
18
+ xml.Emisor(receipt.nodes_issuer.to_hash) if receipt.nodes_issuer
19
+
20
+ xml.Receptor(receipt.nodes_receiver.to_hash) if receipt.nodes_receiver
21
+
22
+ if receipt.nodes_concept
23
+ xml.Conceptos do
24
+ receipt.nodes_concept.all.each do |concept|
25
+ xml.Concepto(concept.to_hash) do
26
+ if ((defined? concept.nodes_taxtransferred) && concept.nodes_taxtransferred ) || ((defined? concept.nodes_taxdetained) && concept.nodes_taxdetained)
27
+ xml.Impuestos do
28
+ if (defined? concept.nodes_taxtransferred) && concept.nodes_taxtransferred
29
+ xml.Traslados do
30
+ concept.nodes_taxtransferred.all.each do |transferred|
31
+ xml.Traslado(transferred.to_hash)
32
+ end
33
+ end
34
+ end
35
+
36
+ if (defined? concept.nodes_taxdetained) && concept.nodes_taxdetained
37
+ xml.Retenciones do
38
+ concept.nodes_taxdetained.all.each do |detained|
39
+ xml.Retencion(detained.to_hash)
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+
46
+ xml.InformacionAduanera(concept.nodes_customsinformation.to_hash) if ((defined? concept.nodes_customsinformation) && concept.nodes_customsinformation)
47
+
48
+ xml.CuentaPredial(concept.nodes_propertyaccount.to_hash) if ((defined? concept.nodes_propertyaccount) && concept.nodes_propertyaccount)
49
+
50
+ xml.Parte(concept.nodes_part.to_hash) if ((defined? concept.nodes_part) && concept.nodes_part)
51
+ end
52
+ end
53
+ end
54
+ end
55
+
56
+ if ((defined? receipt.nodes_taxes) && !receipt.nodes_taxes.blank?)
57
+ xml.Impuestos(receipt.nodes_taxes.to_hash) do
58
+ if ((defined? receipt.nodes_taxes.nodes_detained) && receipt.nodes_taxes.nodes_detained)
59
+ xml.Retenciones do
60
+ receipt.nodes_taxes.nodes_detained.all.each do |detained|
61
+ xml.Retencion(detained.to_hash)
62
+ end
63
+ end
64
+ end
65
+ if ((defined? receipt.nodes_taxes.nodes_transferred) && receipt.nodes_taxes.nodes_transferred)
66
+ xml.Traslados do
67
+ receipt.nodes_taxes.nodes_transferred.all.each do |transferred|
68
+ xml.Traslado(transferred.to_hash)
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,3 @@
1
+ module BuhoCfdi
2
+ VERSION = "0.1.12"
3
+ end
metadata ADDED
@@ -0,0 +1,178 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: buho_cfdi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.12
5
+ platform: ruby
6
+ authors:
7
+ - Armando Alejandre
8
+ - Pablo Icaza
9
+ - Oscar Cocom
10
+ autorequire:
11
+ bindir: exe
12
+ cert_chain: []
13
+ date: 2020-05-05 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: activemodel
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - "~>"
20
+ - !ruby/object:Gem::Version
21
+ version: 5.2.3
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - "~>"
27
+ - !ruby/object:Gem::Version
28
+ version: 5.2.3
29
+ - !ruby/object:Gem::Dependency
30
+ name: nokogiri
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - "~>"
34
+ - !ruby/object:Gem::Version
35
+ version: '1.6'
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: 1.6.8
39
+ type: :runtime
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - "~>"
44
+ - !ruby/object:Gem::Version
45
+ version: '1.6'
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: 1.6.8
49
+ - !ruby/object:Gem::Dependency
50
+ name: bundler
51
+ requirement: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '1.17'
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '1.17'
63
+ - !ruby/object:Gem::Dependency
64
+ name: rake
65
+ requirement: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: 12.3.3
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: 12.3.3
77
+ - !ruby/object:Gem::Dependency
78
+ name: rspec
79
+ requirement: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '3.0'
84
+ type: :development
85
+ prerelease: false
86
+ version_requirements: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: '3.0'
91
+ - !ruby/object:Gem::Dependency
92
+ name: pry
93
+ requirement: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: 0.13.0
98
+ type: :development
99
+ prerelease: false
100
+ version_requirements: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - "~>"
103
+ - !ruby/object:Gem::Version
104
+ version: 0.13.0
105
+ description: CFDI generator for 3.3 version.
106
+ email:
107
+ - armando1339@gmail.com
108
+ - pablo@buhocontable.com
109
+ - oscar@buhocontable.com
110
+ executables: []
111
+ extensions: []
112
+ extra_rdoc_files: []
113
+ files:
114
+ - ".coveralls.yml"
115
+ - ".gitignore"
116
+ - ".rspec"
117
+ - ".travis.yml"
118
+ - Gemfile
119
+ - Gemfile.lock
120
+ - LICENSE.txt
121
+ - README.md
122
+ - Rakefile
123
+ - bin/console
124
+ - bin/setup
125
+ - buho_cfdi.gemspec
126
+ - dump.rdb
127
+ - lib/buho_cfdi.rb
128
+ - lib/buho_cfdi/base_node.rb
129
+ - lib/buho_cfdi/certificate.rb
130
+ - lib/buho_cfdi/i18n.rb
131
+ - lib/buho_cfdi/key.rb
132
+ - lib/buho_cfdi/locale/es.yml
133
+ - lib/buho_cfdi/nodes/cfdi_related.rb
134
+ - lib/buho_cfdi/nodes/collection.rb
135
+ - lib/buho_cfdi/nodes/concept.rb
136
+ - lib/buho_cfdi/nodes/customs_information.rb
137
+ - lib/buho_cfdi/nodes/detained.rb
138
+ - lib/buho_cfdi/nodes/issuer.rb
139
+ - lib/buho_cfdi/nodes/part.rb
140
+ - lib/buho_cfdi/nodes/property_account.rb
141
+ - lib/buho_cfdi/nodes/receipt.rb
142
+ - lib/buho_cfdi/nodes/receiver.rb
143
+ - lib/buho_cfdi/nodes/related.rb
144
+ - lib/buho_cfdi/nodes/tax_detained.rb
145
+ - lib/buho_cfdi/nodes/tax_transferred.rb
146
+ - lib/buho_cfdi/nodes/taxes.rb
147
+ - lib/buho_cfdi/nodes/transferred.rb
148
+ - lib/buho_cfdi/params_builder.rb
149
+ - lib/buho_cfdi/params_example.json
150
+ - lib/buho_cfdi/strategy.rb
151
+ - lib/buho_cfdi/version.rb
152
+ homepage: https://buhocontable.com/
153
+ licenses:
154
+ - MIT
155
+ metadata:
156
+ allowed_push_host: https://rubygems.org/
157
+ homepage_uri: https://buhocontable.com/
158
+ source_code_uri: https://github.com/buhocontable/buho_cfdi
159
+ post_install_message:
160
+ rdoc_options: []
161
+ require_paths:
162
+ - lib
163
+ required_ruby_version: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - ">="
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
168
+ required_rubygems_version: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - ">="
171
+ - !ruby/object:Gem::Version
172
+ version: '0'
173
+ requirements: []
174
+ rubygems_version: 3.0.1
175
+ signing_key:
176
+ specification_version: 4
177
+ summary: CFDI generator for 3.3 version.
178
+ test_files: []