sunat_invoice 0.1.1 → 0.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 40396cec4aee7cc4907b9010728d8069d4b53faee0eec724379d652f08c2e0d9
4
- data.tar.gz: dd6036855facb8d92e78a37e5654569cd7c53e58d8628960d976629e9b9b8049
3
+ metadata.gz: 8c41fdc0f425786c5ce10ffb989fb2d38eb4838c019c1e5ed97777a57ec4246d
4
+ data.tar.gz: 021b2a2733ba5a3c980fd14aa09fce7d9ae3ccef2508571a6edf559ee2f57d1b
5
5
  SHA512:
6
- metadata.gz: 9b937b09684482e2bd3e3b8050891ebbf7bece82648e214afadffbb2a1605a4e01ee0cd243b298fe9e10a17004c8a09c745de8f534803f8fb9d54e5451d63327
7
- data.tar.gz: 0b6a13a021269f0e7a1147fc5c34f761fb495ad87fc43b5d316fb0004bda9fd13391521492556f540c2ae452fdee261746b1af025313a9fa51c1e9df5069fb1f
6
+ metadata.gz: 523df13382787cd1e858e2c22f17dd13bc92ea1d6a11bb35d2470ffdfc95700207e1a11fa68642b2da7a8ad722f9d6dd710500ca291c1b6bc5617677061db72d
7
+ data.tar.gz: 3ca5bc91a0d178ab7ac41f574fbd052032097077819d09ee8011fbf029cd80f95dc4408d08de5d67d72047f8117ec8c6b4b79b5949d6bd621b9a5c555c46ae43
@@ -9,3 +9,8 @@ Metrics/BlockLength:
9
9
  - 'test/*.rb'
10
10
  Metrics/MethodLength:
11
11
  Max: 20
12
+ Metrics/ModuleLength:
13
+ Exclude:
14
+ - 'lib/sunat_invoice/catalogs.rb'
15
+ Naming/MemoizedInstanceVariableName:
16
+ Enabled: false
@@ -8,20 +8,49 @@ module SunatInvoice
8
8
  CATALOG_01 = [
9
9
  '01', # FACTURA
10
10
  '03', # BOLETA DE VENTA
11
+ '06', # CARTA DE PORTE AÉREO
11
12
  '07', # NOTA DE CREDITO
12
13
  '08', # NOTA DE DEBITO
13
14
  '09', # GUIA DE REMISIÓN REMITENTE
14
15
  '12', # TICKET DE MAQUINA REGISTRADORA
15
16
  '13', # DOCUMENTO EMITIDO POR BANCOS, INSTITUCIONES FINANCIERAS
17
+ '14', # RECIBO DE SERVICIOS PÚBLICOS
18
+ '15',
19
+ # BOLETOS EMITIDOS POR SERVICIO TRANSPORTE PÚBLICO TERRESTRE REGULAR
20
+ # URBANO DE PASAJEROS Y FERROVIARIO PÚBLICO DE PASAJEROS
21
+ '16',
22
+ # BOLETOS EMITIDOS POR SERVICIO TRANSPORTE PÚBLICO TERRESTRE
23
+ # INTERPROVINCIAL DE PASAJEROS
16
24
  '18', # DOCUMENTOS EMITIDOS POR LAS AFP
25
+ '20', # COMPROBANTE DE RETENCIÓN
26
+ '21',
27
+ # CONOCIMIENTO DE EMBARQUE POR EL SERVICIO DE TRANSPORTE DE CARGA MARÍTIMA
28
+ '24', # CERTIFICADO DE PAGO DE REGALÍAS EMITIDAS POR PERUPETRO S.A.
17
29
  '31', # GUIA DE REMISIÓN TRANSPORTISTA
30
+ '37',
31
+ # DOCUMENTOS EMITIDOS POR CONCESIONARIOS DE SERVICIO DE REVISIONES
32
+ # TÉCNICAS
33
+ '40', # COMPRANTE DE PERCEPCIÓN
34
+ '43', # BOLETO DE COMPAÑIAS DE AVIACIÓN TRANSPORTE AÉREO NO REGULAR
35
+ '45',
36
+ # DOCUMENTOS EMITIDOS POR CENTROS EDUCATIVOS Y CULTURALES, UNIVERSIDADES,
37
+ # ASOCIACIONES Y FUNDACIONES
38
+ '56', # COMPROBANTE DE PAGO SEAE
39
+ '71', # GUIA DE REMISIÓN REMITENTE COMPLEMENTARIA
40
+ '72' # GUIA DE REMISIÓN TRANSPORTISTA COMPLEMENTARIA
41
+
18
42
  ].freeze
19
43
 
20
44
  # Tipo de Tributo
21
45
  CATALOG_05 = [
22
46
  '1000', # IGV
47
+ '1016', # IVAP
23
48
  '2000', # ISC
24
- '9999' # Otros
49
+ '9995', # EXP - EXPORTACION
50
+ '9996', # GRA - GRATUITO
51
+ '9997', # EXO - EXONERADO
52
+ '9998', # INA - INAFECTO
53
+ '9999' # OTROS
25
54
  ].freeze
26
55
 
27
56
  # Tipo de Documentos de Identidad
@@ -31,7 +60,11 @@ module SunatInvoice
31
60
  '4', # CARNET DE EXTRANJERIA
32
61
  '6', # REG. UNICO DE CONTRIBUYENTES
33
62
  '7', # PASAPORTE
34
- 'A' # CED. DIPLOMATICA DE IDENTIDAD
63
+ 'A', # CED. DIPLOMATICA DE IDENTIDAD
64
+ 'B', # DOCUMENTO IDENTIDAD PAIS RESIDENCIA - NO DOMICILIADO
65
+ 'C', # TAX IDENTIFICATION NUMBER - TIN – DOC TRIB PP.NN
66
+ 'D', # IDENTIFICATION NUMBER - IN – DOC TRIB PP.JJ
67
+ 'E' # TARJETA ANDINA DE MIGRACION - TAM
35
68
  ].freeze
36
69
 
37
70
  # Tipo de Afectación del IGV
@@ -43,7 +76,9 @@ module SunatInvoice
43
76
  '14', # Gravado – Retiro por publicidad
44
77
  '15', # Gravado – Bonificaciones
45
78
  '16', # Gravado – Retiro por entrega a trabajadores
79
+ '17', # Gravado –IVAP
46
80
  '20', # Exonerado - Operación Onerosa
81
+ '21', # Exonerado - Transferencia Gratuita
47
82
  '30', # Inafecto - Operación Onerosa
48
83
  '31', # Inafecto – Retiro por Bonificación
49
84
  '32', # Inafecto – Retiro
@@ -58,7 +93,7 @@ module SunatInvoice
58
93
  CATALOG_08 = [
59
94
  '01', # Sistema al valor
60
95
  '02', # Aplicación del Monto Fijo
61
- '03', # Sistema de Precios de Venta al Público
96
+ '03' # Sistema de Precios de Venta al Público
62
97
  ].freeze
63
98
 
64
99
  # Tipo de Nota de Crédito Electrónica
@@ -71,13 +106,19 @@ module SunatInvoice
71
106
  '06', # Devolución total
72
107
  '07', # Devolución por ítem
73
108
  '08', # Bonificación
74
- '09' # Disminución en el valor
109
+ '09', # Disminución en el valor
110
+ '10', # Otros Conceptos
111
+ '11', # Ajustes de operaciones de exportación
112
+ '12' # Ajustes afectos al IVAP
75
113
  ].freeze
76
114
 
77
115
  # Tipo de Nota de Débito Electrónica
78
116
  CATALOG_10 = [
79
117
  '01', # Intereses por mora
80
- '02' # Aumento en el valor
118
+ '02', # Aumento en el valor
119
+ '03', # Penalidades/ otros conceptos
120
+ '10', # Ajustes de operaciones de exportación
121
+ '11' # Ajustes afectos al IVAP
81
122
  ].freeze
82
123
 
83
124
  # Resumen Diario de Boletas de Ventas Electrónicas y Notas Electrónicas
@@ -93,6 +134,8 @@ module SunatInvoice
93
134
  # Documentos Relacionados Tributarios
94
135
  CATALOG_12 = [
95
136
  '01', # Factura – emitida para corregir error en el RUC
137
+ '02', # Factura – emitida por anticipos
138
+ '03', # Boleta de Venta – emitida por anticipos
96
139
  '04', # Ticket de Salida - ENAPU
97
140
  '05', # Código SCOP
98
141
  '99' # Otros
@@ -100,6 +143,7 @@ module SunatInvoice
100
143
 
101
144
  # Otros conceptos tributarios
102
145
  CATALOG_14 = [
146
+ '1000', # Total valor de venta –operaciones exportadas
103
147
  '1001', # Total valor de venta - operaciones gravadas
104
148
  '1002', # Total valor de venta - operaciones inafectas
105
149
  '1003', # Total valor de venta - operaciones exoneradas
@@ -109,7 +153,8 @@ module SunatInvoice
109
153
  '2002', # Retenciones
110
154
  '2003', # Detracciones
111
155
  '2004', # Bonificaciones
112
- '2005' # Total descuentos
156
+ '2005', # Total descuentos
157
+ '3001' # FISE (Ley 29852) Fondo Inclusión Social Energético
113
158
  ].freeze
114
159
 
115
160
  # Elementos adicionales en la Factura y/o Boleta de Venta Electrónica
@@ -120,7 +165,7 @@ module SunatInvoice
120
165
  # GRATUITAMENTE”
121
166
  '2000', # Leyenda “COMPROBANTE DE PERCEPCIÓN”
122
167
  '2001',
123
- # Leyenda “BIENES TRANSFERIDOS EN LA AMAZONÍA REGIÓN SELVAPARA SER
168
+ # Leyenda “BIENES TRANSFERIDOS EN LA AMAZONÍA REGIÓN SELVA PARA SER
124
169
  # CONSUMIDOS EN LA MISMA”
125
170
  '2002',
126
171
  # Leyenda “SERVICIOS PRESTADOS EN LA AMAZONÍA REGIÓN SELVA PARA SER
@@ -129,6 +174,9 @@ module SunatInvoice
129
174
  # Leyenda “CONTRATOS DE CONSTRUCCIÓN EJECUTADOS EN LA AMAZONÍA REGIÓN
130
175
  # SELVA”
131
176
  '2004', # Leyenda “Agencia de Viaje - Paquete turístico”
177
+ '2005', # Leyenda “Venta realizada por emisor itinerante”
178
+ '2006', # Leyenda: Operación sujeta a detracción
179
+ '2007', # Leyenda: Operación sujeta a IVAP
132
180
  '3000', # Detracciones: CODIGO DE BB Y SS SUJETOS A DETRACCION
133
181
  '3001', # Detracciones: NUMERO DE CTA EN EL BN
134
182
  '3002',
@@ -163,9 +211,26 @@ module SunatInvoice
163
211
  '4008',
164
212
  # Beneficio Hospedajes: Paquete turístico – Tipo documento identidad del
165
213
  # huésped
166
- '4009'
214
+ '4009',
167
215
  # Beneficio Hospedajes: Paquete turístico – Numero de documento identidad
168
216
  # de huésped
217
+ '5000', # Proveedores Estado: Número de Expediente
218
+ '5001', # Proveedores Estado : Código de unidad ejecutora
219
+ '5002', # Proveedores Estado : N° de proceso de selección
220
+ '5003', # Proveedores Estado : N° de contrato
221
+ '6000', # Comercialización de Oro : Código Unico Concesión Minera
222
+ '6001', # Comercialización de Oro : N° declaración compromiso
223
+ '6002', # Comercialización de Oro : N° Reg. Especial .Comerci. Oro
224
+ '6003',
225
+ # Comercialización de Oro : N° Resolución que autoriza Planta de
226
+ # Beneficio
227
+ '6004', # Comercialización de Oro : Ley Mineral (% concent. oro)
228
+ '7000',
229
+ # Primera venta de mercancía identificable entre usuarios de la zona
230
+ # comercial
231
+ '7001'
232
+ # Venta exonerada del IGV-ISC-IPM. Prohibida la venta fuera de la zona
233
+ # comercial de Tacna
169
234
  ].freeze
170
235
 
171
236
  # Tipo de Precio de Venta Unitario
@@ -173,5 +238,76 @@ module SunatInvoice
173
238
  '01', # Precio unitario (incluye el IGV)
174
239
  '02' # Valor referencial unitario en operaciones no onerosas
175
240
  ].freeze
241
+
242
+ # Tipo de Operación
243
+ CATALOG_17 = [
244
+ '01', # Venta Interna
245
+ '02', # Exportación de bienes
246
+ '03', # No Domiciliados
247
+ '04', # Venta Interna – Anticipos
248
+ '05', # Venta Itinerante
249
+ '06', # Factura Guía
250
+ '07', # Venta Arroz Pilado
251
+ '08', # Factura - Comprobante de Percepción
252
+ '10', # Factura - Guía remitente
253
+ '11', # Factura - Guía transportista
254
+ '12', # Boleta de venta – Comprobante de Percepción
255
+ '13', # Gasto Deducible Persona Natural
256
+ '14',
257
+ # Exportación de servicios – Prestación de servicios de hospedaje No Dom
258
+ '15', # Exportación de servicios – Transporte de navieras
259
+ '16',
260
+ # Exportación de servicios – Servicios a naves y aeronaves de bandera
261
+ # extranjera
262
+ '17', # Exportación de servicios – RES
263
+ '18',
264
+ # Exportación de servicios - Servicios que conformen un Paquete Turístico
265
+ '19',
266
+ # Exportación de servicios – Servicios complementarios al transporte de
267
+ # carga
268
+ '20',
269
+ # Exportación de servicios – Suministro de energía eléctrica a favor de
270
+ # sujetos domiciliados en ZED
271
+ '21'
272
+ # Exportación de servicios – Prestación servicios realizados parcialmente
273
+ # en el extranjero
274
+ ].freeze
275
+
276
+ # Modalidad de traslado
277
+ CATALOG_18 = [
278
+ '01', # Transporte público
279
+ '02' # Transporte privado
280
+ ].freeze
281
+
282
+ # Resumen diario de boletas de venta y notas electrónicas
283
+ # Códigos de estado de ítem
284
+ CATALOG_19 = [
285
+ '1', # Adicionar
286
+ '2', # Modificar
287
+ '3' # Anulado
288
+ ].freeze
289
+
290
+ # Motivos de traslado
291
+ CATALOG_20 = [
292
+ '01', # Venta
293
+ '14', # Venta sujeta a confirmación del comprador
294
+ '02', # Compra
295
+ '04', # Traslado entre establecimientos de la misma empresa
296
+ '08', # Importación
297
+ '09', # Exportación
298
+ '18', # Traslado emisor itinerante CP
299
+ '19', # Traslado a zona primaria
300
+ '13' # Otros
301
+ ].freeze
302
+
303
+ # Documentos relacionados-aplicable solo para Guía de remisión electrónica
304
+ CATALOG_21 = [
305
+ '01', # Numeración DAM
306
+ '02', # Número de orden de entrega
307
+ '03', # Número SCOP
308
+ '04', # Número de manifiesto de carga
309
+ '05', # Número de constancia de detracción
310
+ '06' # Otros
311
+ ].freeze
176
312
  end
177
313
  end
@@ -41,7 +41,9 @@ module SunatInvoice
41
41
  end
42
42
 
43
43
  def set_price
44
- @price ||= (@price_included_tax - sum_taxes).round(2) if @price_included_tax
44
+ return unless @price_included_tax
45
+
46
+ @price ||= (@price_included_tax - sum_taxes).round(2)
45
47
  end
46
48
 
47
49
  def bi_value
@@ -7,5 +7,14 @@ module SunatInvoice
7
7
  send("#{key}=", value) if respond_to?("#{key}=")
8
8
  end
9
9
  end
10
+
11
+ def to_hash
12
+ hash = {}
13
+ instance_variables.map do |var|
14
+ var_name = var.to_s.split('@')[1]
15
+ hash[var_name] = instance_variable_get(var)
16
+ end
17
+ hash
18
+ end
10
19
  end
11
20
  end
@@ -20,6 +20,7 @@ module SunatInvoice
20
20
  # body: SOAP body as a Hash. Typically Savon Response body.
21
21
  # parser_type: kind of parser to use.
22
22
  raise InvalidResponseParser unless ALLOWED_PARSERS.include?(parser_type)
23
+
23
24
  send("parse_#{parser_type}", body)
24
25
  end
25
26
 
@@ -61,6 +61,7 @@ module SunatInvoice
61
61
 
62
62
  def tax_exemption(xml)
63
63
  return unless tax_exemption_reason
64
+
64
65
  xml['cbc'].TaxExemptionReasonCode(tax_exemption_reason)
65
66
  end
66
67
  end
@@ -12,17 +12,17 @@ module SignatureHelper
12
12
  File.open("#{keys_dir}/cert_file", 'w') { |f| f.puts cert.to_pem }
13
13
  end
14
14
 
15
- def self.generate_certificate(pk)
15
+ def self.generate_certificate(pkey)
16
16
  name = OpenSSL::X509::Name.parse('CN=example.com/C=EE')
17
17
  cert = OpenSSL::X509::Certificate.new
18
18
  cert.version = 2
19
19
  cert.serial = 0
20
20
  cert.not_before = Time.now
21
21
  cert.not_after = cert.not_before + 1 * 365 * 24 * 60 * 60
22
- cert.public_key = pk.public_key
22
+ cert.public_key = pkey.public_key
23
23
  cert.subject = name
24
24
  cert.issuer = name
25
- cert.sign pk, OpenSSL::Digest::SHA1.new
25
+ cert.sign pkey, OpenSSL::Digest::SHA1.new
26
26
  cert
27
27
  end
28
28
  end
@@ -26,7 +26,8 @@ module SunatInvoice
26
26
  total_code = get_total_code(item.taxes.first)
27
27
  if total_code
28
28
  @sale_totals[total_code] = 0 unless @sale_totals[total_code]
29
- @sale_totals[total_code] = (@sale_totals[total_code] + item.bi_value).round(2)
29
+ @sale_totals[total_code] = (@sale_totals[total_code] + item.bi_value)
30
+ .round(2)
30
31
  end
31
32
  end
32
33
  end
@@ -44,6 +45,7 @@ module SunatInvoice
44
45
 
45
46
  def get_total_code(tax)
46
47
  return unless tax
48
+
47
49
  case tax.tax_type
48
50
  # TODO: :isc
49
51
  when :igv
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'sunat_invoice'
5
- s.version = '0.1.1'
5
+ s.version = '0.2.0'
6
6
  s.summary = 'Ruby gem to use SUNAT Electronic Billing from your app'
7
7
  s.description = 'Generate and send Electronic Invoices to SUNAT'
8
8
  s.authors = ['César Carruitero']
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sunat_invoice
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - César Carruitero
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-20 00:00:00.000000000 Z
11
+ date: 2019-12-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri