nubefact 0.0.8 → 0.0.9
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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/nube_fact.rb +7 -2
- data/lib/nube_fact/credit_note.rb +14 -0
- data/lib/nube_fact/document.rb +192 -0
- data/lib/nube_fact/{invoice → document}/guia.rb +1 -1
- data/lib/nube_fact/{invoice → document}/item.rb +2 -2
- data/lib/nube_fact/invoice.rb +2 -163
- data/lib/nube_fact/version.rb +1 -1
- data/lib/util/validator.rb +21 -1
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8695ece4b65663a5f5b031b88db075577fb2151d
|
4
|
+
data.tar.gz: 7ca18095a2f273fc575b74fd21c8c55a9daa4f5f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 927428b5fb31f0d7db30c62ef0eeadba32fdbd80495e55c51c68cf7081b1b819c4e4e2207927d8a317ebbaa65af9715478dd7dd78ed89c08b7c996ad20eeaed4
|
7
|
+
data.tar.gz: ebbcadace559122a55be361e65a1d44b1d4b66055cb365a31c20480b9663c349b7131cd849bae6d4ecfce45029cab3762a0987e8da0a8adc820e2548c3acc933
|
data/Gemfile.lock
CHANGED
data/lib/nube_fact.rb
CHANGED
@@ -3,6 +3,8 @@ require 'net/http'
|
|
3
3
|
require 'openssl'
|
4
4
|
require 'json'
|
5
5
|
|
6
|
+
# https://docs.google.com/document/d/1QWWSILBbjd4MDkJl7vCkL2RZvkPh0IC7Wa67BvoYIhA/edit
|
7
|
+
|
6
8
|
module NubeFact; end
|
7
9
|
|
8
10
|
require "util/validator"
|
@@ -11,9 +13,12 @@ require "util/sunat"
|
|
11
13
|
|
12
14
|
require "nube_fact/version"
|
13
15
|
require "nube_fact/exceptions"
|
16
|
+
|
17
|
+
require "nube_fact/document"
|
18
|
+
require 'nube_fact/document/guia'
|
19
|
+
require 'nube_fact/document/item'
|
14
20
|
require "nube_fact/invoice"
|
15
|
-
require
|
16
|
-
require 'nube_fact/invoice/item'
|
21
|
+
require "nube_fact/credit_note"
|
17
22
|
|
18
23
|
module NubeFact
|
19
24
|
API_BASE = 'https://www.nubefact.com/api/v1'
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class NubeFact::CreditNote < NubeFact::Document
|
2
|
+
TIPO_DE_COMPROBANTE = 3
|
3
|
+
|
4
|
+
DEFAULT_DATA = {
|
5
|
+
operacion: 'generar_comprobante',
|
6
|
+
tipo_de_comprobante: 3,
|
7
|
+
serie: 'F',
|
8
|
+
sunat_transaction: 1,
|
9
|
+
fecha_de_emision: ->(_i) { Date.today },
|
10
|
+
porcentaje_de_igv: 18,
|
11
|
+
moneda: 1,
|
12
|
+
tipo_de_cambio: ->(invoice) { invoice.set_tipo_de_cambio }
|
13
|
+
}
|
14
|
+
end
|
@@ -0,0 +1,192 @@
|
|
1
|
+
class NubeFact::Document
|
2
|
+
include NubeFact::Validator
|
3
|
+
include NubeFact::Utils
|
4
|
+
|
5
|
+
FIELDS = [
|
6
|
+
"operacion",
|
7
|
+
"tipo_de_comprobante",
|
8
|
+
# 1=FACTURA
|
9
|
+
# 2=BOLETA
|
10
|
+
# 3=NOTA CREDITO
|
11
|
+
# 4=NOTA DEBITO
|
12
|
+
"serie", # F para FACTURA | B PARA BOLETA
|
13
|
+
"numero",
|
14
|
+
"sunat_transaction",
|
15
|
+
# 1 = VENTA INTERNA
|
16
|
+
# 2 = EXPORTACIÓN
|
17
|
+
# 3 = NO DOMICILIADO
|
18
|
+
# 4 = VENTA INTERNA – ANTICIPOS
|
19
|
+
# 5 = VENTA ITINERANTE
|
20
|
+
# 6 = FACTURA GUÍA
|
21
|
+
# 7 = VENTA ARROZ PILADO
|
22
|
+
# 8 = FACTURA - COMPROBANTE DE PERCEPCIÓN
|
23
|
+
# 10 = FACTURA - GUÍA REMITENTE
|
24
|
+
# 11 = FACTURA - GUÍA TRANSPORTISTA
|
25
|
+
# 12 = BOLETA DE VENTA – COMPROBANTE DE PERCEPCIÓN
|
26
|
+
# 13 = GASTO DEDUCIBLE PERSONA NATURAL
|
27
|
+
|
28
|
+
"cliente_tipo_de_documento",
|
29
|
+
# 6 = RUC - REGISTRO ÚNICO DE CONTRIBUYENTE
|
30
|
+
# 1 = DNI - DOC. NACIONAL DE IDENTIDAD
|
31
|
+
# - = VARIOS - VENTAS MENORES A S/.700.00 Y OTROS
|
32
|
+
# 4 = CARNET DE EXTRANJERÍA
|
33
|
+
# 7 = PASAPORTE
|
34
|
+
# A = CÉDULA DIPLOMÁTICA DE IDENTIDAD
|
35
|
+
# 0 = NO DOMICILIADO, SIN RUC (EXPORTACIÓN)
|
36
|
+
|
37
|
+
"cliente_numero_de_documento",
|
38
|
+
"cliente_denominacion",
|
39
|
+
"cliente_direccion",
|
40
|
+
"cliente_email",
|
41
|
+
"cliente_email_1",
|
42
|
+
"cliente_email_2",
|
43
|
+
|
44
|
+
"fecha_de_emision",
|
45
|
+
"fecha_de_vencimiento",
|
46
|
+
"moneda",
|
47
|
+
# 1 = SOLES
|
48
|
+
# 2 = DÓLARES
|
49
|
+
# 3 = EUROS
|
50
|
+
"tipo_de_cambio",
|
51
|
+
|
52
|
+
"porcentaje_de_igv",
|
53
|
+
"descuento_global",
|
54
|
+
"total_descuento",
|
55
|
+
"total_anticipo",
|
56
|
+
"total_gravada",
|
57
|
+
"total_inafecta",
|
58
|
+
"total_exonerada",
|
59
|
+
"total_igv",
|
60
|
+
"total_gratuita",
|
61
|
+
"total_otros_cargos",
|
62
|
+
"total",
|
63
|
+
|
64
|
+
"percepcion_tipo",
|
65
|
+
"percepcion_base_imponible",
|
66
|
+
"total_percepcion",
|
67
|
+
"total_incluido_percepcion",
|
68
|
+
"detraccion",
|
69
|
+
|
70
|
+
"observaciones",
|
71
|
+
|
72
|
+
# Nota de credito
|
73
|
+
"documento_que_se_modifica_tipo",
|
74
|
+
# 1 = ANULACIÓN DE LA OPERACIÓN
|
75
|
+
# 2 = ANULACIÓN POR ERROR EN EL RUC
|
76
|
+
# 3 = CORRECCIÓN POR ERROR EN LA DESCRIPCIÓN
|
77
|
+
# 4 = DESCUENTO GLOBAL
|
78
|
+
# 5 = DESCUENTO POR ÍTEM
|
79
|
+
# 6 = DEVOLUCIÓN TOTAL
|
80
|
+
# 7 = DEVOLUCIÓN POR ÍTEM
|
81
|
+
# 8 = BONIFICACIÓN
|
82
|
+
# 9 = DISMINUCIÓN EN EL VALOR
|
83
|
+
|
84
|
+
"documento_que_se_modifica_serie",
|
85
|
+
"documento_que_se_modifica_numero",
|
86
|
+
|
87
|
+
"tipo_de_nota_de_credito",
|
88
|
+
"tipo_de_nota_de_debito",
|
89
|
+
|
90
|
+
"enviar_automaticamente_a_la_sunat",
|
91
|
+
"enviar_automaticamente_al_cliente",
|
92
|
+
|
93
|
+
"codigo_unico",
|
94
|
+
"condiciones_de_pago",
|
95
|
+
"medio_de_pago",
|
96
|
+
# Ejemplo: TARJETA VISA OP: 232231
|
97
|
+
"placa_vehiculo",
|
98
|
+
"orden_compra_servicio",
|
99
|
+
"tabla_personalizada_codigo",
|
100
|
+
"formato_de_pdf",
|
101
|
+
# A4, A5 o TICKET.
|
102
|
+
|
103
|
+
"items",
|
104
|
+
"guias"
|
105
|
+
]
|
106
|
+
|
107
|
+
attr_accessor *FIELDS
|
108
|
+
|
109
|
+
REQUIRED_FIELDS = %i(
|
110
|
+
serie
|
111
|
+
numero
|
112
|
+
sunat_transaction
|
113
|
+
cliente_tipo_de_documento
|
114
|
+
cliente_numero_de_documento
|
115
|
+
cliente_denominacion
|
116
|
+
cliente_direccion
|
117
|
+
fecha_de_emision
|
118
|
+
moneda
|
119
|
+
porcentaje_de_igv
|
120
|
+
total
|
121
|
+
)
|
122
|
+
|
123
|
+
def initialize(data_hash)
|
124
|
+
if self.class == NubeFact::Document
|
125
|
+
raise "Don't initialize NubeFact::Document directly "
|
126
|
+
end
|
127
|
+
|
128
|
+
@items = []
|
129
|
+
@guias = []
|
130
|
+
|
131
|
+
load_data_from_param data_hash
|
132
|
+
end
|
133
|
+
|
134
|
+
def add_item(item)
|
135
|
+
if item.is_a? Hash
|
136
|
+
item = Item.new self, item
|
137
|
+
end
|
138
|
+
@items << item
|
139
|
+
end
|
140
|
+
|
141
|
+
def add_guia(guia)
|
142
|
+
|
143
|
+
end
|
144
|
+
|
145
|
+
def deliver
|
146
|
+
if items.empty?
|
147
|
+
raise NubeFact::ValidationError.new "At least one item have to be present"
|
148
|
+
end
|
149
|
+
validate!
|
150
|
+
|
151
|
+
NubeFact.request to_h
|
152
|
+
end
|
153
|
+
|
154
|
+
def calculate_amounts
|
155
|
+
|
156
|
+
end
|
157
|
+
|
158
|
+
def set_tipo_de_cambio
|
159
|
+
return "" unless moneda == 2
|
160
|
+
NubeFact::Sunat.dollar_rate Date.parse(fecha_de_emision)
|
161
|
+
end
|
162
|
+
|
163
|
+
|
164
|
+
def fecha_de_emision
|
165
|
+
if [Date, Time, DateTime].include? @fecha_de_emision.class
|
166
|
+
return @fecha_de_emision.strftime(NubeFact::DATE_FORMAT)
|
167
|
+
end
|
168
|
+
@fecha_de_emision
|
169
|
+
end
|
170
|
+
|
171
|
+
class << self
|
172
|
+
def consultar(serie, numero)
|
173
|
+
NubeFact.request({
|
174
|
+
operacion: "consultar_comprobante",
|
175
|
+
tipo_de_comprobante: self::TIPO_DE_COMPROBANTE,
|
176
|
+
serie: serie,
|
177
|
+
numero: numero
|
178
|
+
})
|
179
|
+
end
|
180
|
+
|
181
|
+
def anular(serie, numero, motivo)
|
182
|
+
NubeFact.request({
|
183
|
+
operacion: "generar_anulacion",
|
184
|
+
tipo_de_comprobante: self::TIPO_DE_COMPROBANTE,
|
185
|
+
serie: serie,
|
186
|
+
numero: numero,
|
187
|
+
motivo: motivo
|
188
|
+
})
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class NubeFact::
|
1
|
+
class NubeFact::Document::Item
|
2
2
|
include NubeFact::Validator
|
3
3
|
include NubeFact::Utils
|
4
4
|
|
@@ -16,7 +16,7 @@ class NubeFact::Invoice::Item
|
|
16
16
|
# con IGV
|
17
17
|
"descuento",
|
18
18
|
"subtotal",
|
19
|
-
#
|
19
|
+
# VALOR_UNITARIO * CANTIDAD - DESCUENTO
|
20
20
|
"tipo_de_igv",
|
21
21
|
# 1 = Gravado - Operación Onerosa
|
22
22
|
# 2 = Gravado – Retiro por premio
|
data/lib/nube_fact/invoice.rb
CHANGED
@@ -1,110 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
class NubeFact::Invoice
|
5
|
-
include NubeFact::Validator
|
6
|
-
include NubeFact::Utils
|
7
|
-
|
8
|
-
FIELDS = [
|
9
|
-
"operacion",
|
10
|
-
"tipo_de_comprobante", # 1=FACTURA 2=BOLETA 3=NOTA CREDITO 4 NOTA DEBITO
|
11
|
-
"serie", # F para FACTURA | B PARA BOLETA
|
12
|
-
"numero",
|
13
|
-
"sunat_transaction",
|
14
|
-
# 1 = VENTA INTERNA
|
15
|
-
# 2 = EXPORTACIÓN
|
16
|
-
# 3 = NO DOMICILIADO
|
17
|
-
# 4 = VENTA INTERNA – ANTICIPOS
|
18
|
-
# 5 = VENTA ITINERANTE
|
19
|
-
# 6 = FACTURA GUÍA
|
20
|
-
# 7 = VENTA ARROZ PILADO
|
21
|
-
# 8 = FACTURA - COMPROBANTE DE PERCEPCIÓN
|
22
|
-
# 10 = FACTURA - GUÍA REMITENTE
|
23
|
-
# 11 = FACTURA - GUÍA TRANSPORTISTA
|
24
|
-
# 12 = BOLETA DE VENTA – COMPROBANTE DE PERCEPCIÓN
|
25
|
-
# 13 = GASTO DEDUCIBLE PERSONA NATURAL
|
26
|
-
|
27
|
-
"cliente_tipo_de_documento",
|
28
|
-
# 6 = RUC - REGISTRO ÚNICO DE CONTRIBUYENTE
|
29
|
-
# 1 = DNI - DOC. NACIONAL DE IDENTIDAD
|
30
|
-
# - = VARIOS - VENTAS MENORES A S/.700.00 Y OTROS
|
31
|
-
# 4 = CARNET DE EXTRANJERÍA
|
32
|
-
# 7 = PASAPORTE
|
33
|
-
# A = CÉDULA DIPLOMÁTICA DE IDENTIDAD
|
34
|
-
# 0 = NO DOMICILIADO, SIN RUC (EXPORTACIÓN)
|
35
|
-
|
36
|
-
"cliente_numero_de_documento",
|
37
|
-
"cliente_denominacion",
|
38
|
-
"cliente_direccion",
|
39
|
-
"cliente_email",
|
40
|
-
"cliente_email_1",
|
41
|
-
"cliente_email_2",
|
42
|
-
|
43
|
-
"fecha_de_emision",
|
44
|
-
"fecha_de_vencimiento",
|
45
|
-
"moneda",
|
46
|
-
# 1 = SOLES
|
47
|
-
# 2 = DÓLARES
|
48
|
-
# 3 = EUROS
|
49
|
-
"tipo_de_cambio",
|
50
|
-
|
51
|
-
"porcentaje_de_igv",
|
52
|
-
"descuento_global",
|
53
|
-
"total_descuento",
|
54
|
-
"total_anticipo",
|
55
|
-
"total_gravada",
|
56
|
-
"total_inafecta",
|
57
|
-
"total_exonerada",
|
58
|
-
"total_igv",
|
59
|
-
"total_gratuita",
|
60
|
-
"total_otros_cargos",
|
61
|
-
"total",
|
62
|
-
|
63
|
-
"percepcion_tipo",
|
64
|
-
"percepcion_base_imponible",
|
65
|
-
"total_percepcion",
|
66
|
-
"total_incluido_percepcion",
|
67
|
-
"detraccion",
|
68
|
-
|
69
|
-
"observaciones",
|
70
|
-
|
71
|
-
"documento_que_se_modifica_tipo",
|
72
|
-
"documento_que_se_modifica_serie",
|
73
|
-
"documento_que_se_modifica_numero",
|
74
|
-
|
75
|
-
"tipo_de_nota_de_credito",
|
76
|
-
"tipo_de_nota_de_debito",
|
77
|
-
|
78
|
-
"enviar_automaticamente_a_la_sunat",
|
79
|
-
"enviar_automaticamente_al_cliente",
|
80
|
-
|
81
|
-
"codigo_unico",
|
82
|
-
"condiciones_de_pago",
|
83
|
-
"medio_de_pago",
|
84
|
-
"placa_vehiculo",
|
85
|
-
"orden_compra_servicio",
|
86
|
-
"tabla_personalizada_codigo",
|
87
|
-
"formato_de_pdf",
|
88
|
-
|
89
|
-
"items",
|
90
|
-
"guias"
|
91
|
-
]
|
92
|
-
|
93
|
-
attr_accessor *FIELDS
|
94
|
-
|
95
|
-
REQUIRED_FIELDS = %i(
|
96
|
-
serie
|
97
|
-
numero
|
98
|
-
sunat_transaction
|
99
|
-
cliente_tipo_de_documento
|
100
|
-
cliente_numero_de_documento
|
101
|
-
cliente_denominacion
|
102
|
-
cliente_direccion
|
103
|
-
fecha_de_emision
|
104
|
-
moneda
|
105
|
-
porcentaje_de_igv
|
106
|
-
total
|
107
|
-
)
|
1
|
+
class NubeFact::Invoice < NubeFact::Document
|
2
|
+
TIPO_DE_COMPROBANTE = 1
|
108
3
|
|
109
4
|
DEFAULT_DATA = {
|
110
5
|
operacion: 'generar_comprobante',
|
@@ -116,60 +11,4 @@ class NubeFact::Invoice
|
|
116
11
|
moneda: 1,
|
117
12
|
tipo_de_cambio: ->(invoice) { invoice.set_tipo_de_cambio }
|
118
13
|
}
|
119
|
-
|
120
|
-
def initialize(data_hash)
|
121
|
-
@items = []
|
122
|
-
@guias = []
|
123
|
-
|
124
|
-
load_data_from_param data_hash
|
125
|
-
end
|
126
|
-
|
127
|
-
def add_item(item)
|
128
|
-
if item.is_a? Hash
|
129
|
-
item = Item.new self, item
|
130
|
-
end
|
131
|
-
@items << item
|
132
|
-
end
|
133
|
-
|
134
|
-
def add_guia(guia)
|
135
|
-
|
136
|
-
end
|
137
|
-
|
138
|
-
def deliver
|
139
|
-
if items.empty?
|
140
|
-
raise NubeFact::ValidationError.new "At least one item have to be present"
|
141
|
-
end
|
142
|
-
validate!
|
143
|
-
|
144
|
-
NubeFact.request to_h
|
145
|
-
end
|
146
|
-
|
147
|
-
def calculate_amounts
|
148
|
-
|
149
|
-
end
|
150
|
-
|
151
|
-
def set_tipo_de_cambio
|
152
|
-
return "" unless moneda == 2
|
153
|
-
NubeFact::Sunat.dollar_rate Date.parse(fecha_de_emision)
|
154
|
-
end
|
155
|
-
|
156
|
-
|
157
|
-
def fecha_de_emision
|
158
|
-
if [Date, Time, DateTime].include? @fecha_de_emision.class
|
159
|
-
return @fecha_de_emision.strftime(NubeFact::DATE_FORMAT)
|
160
|
-
end
|
161
|
-
@fecha_de_emision
|
162
|
-
end
|
163
|
-
|
164
|
-
class << self
|
165
|
-
def consultar(serie, numero)
|
166
|
-
NubeFact.request({
|
167
|
-
operacion: "consultar_comprobante",
|
168
|
-
tipo_de_comprobante: 1,
|
169
|
-
serie: serie,
|
170
|
-
numero: numero
|
171
|
-
})
|
172
|
-
end
|
173
|
-
end
|
174
|
-
|
175
14
|
end
|
data/lib/nube_fact/version.rb
CHANGED
data/lib/util/validator.rb
CHANGED
@@ -1,7 +1,27 @@
|
|
1
1
|
module NubeFact::Validator
|
2
|
+
def self.included(klass)
|
3
|
+
klass.extend ClassMethods
|
4
|
+
klass.class_variable_set :@@required_fields, []
|
5
|
+
end
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
def add_required_fields(*fields)
|
9
|
+
base = required_fields
|
10
|
+
|
11
|
+
self.class_variable_set :@@required_fields, \
|
12
|
+
required_fields + fields
|
13
|
+
end
|
14
|
+
|
15
|
+
def required_fields
|
16
|
+
required_fields = self.class_variable_get :@@required_fields
|
17
|
+
return self::REQUIRED_FIELDS if required_fields.empty?
|
18
|
+
required_fields
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
2
22
|
def validate!
|
3
23
|
#ToDO change for a real validator like ActiveModel::Validations or Hanami::Validations
|
4
|
-
self.class::
|
24
|
+
self.class::required_fields.each do |field|
|
5
25
|
if send(field).nil?
|
6
26
|
raise NubeFact::ValidationError.new "#{field} it's a required field."
|
7
27
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nubefact
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arnold Roa
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-11-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -88,10 +88,12 @@ files:
|
|
88
88
|
- bin/console
|
89
89
|
- bin/setup
|
90
90
|
- lib/nube_fact.rb
|
91
|
+
- lib/nube_fact/credit_note.rb
|
92
|
+
- lib/nube_fact/document.rb
|
93
|
+
- lib/nube_fact/document/guia.rb
|
94
|
+
- lib/nube_fact/document/item.rb
|
91
95
|
- lib/nube_fact/exceptions.rb
|
92
96
|
- lib/nube_fact/invoice.rb
|
93
|
-
- lib/nube_fact/invoice/guia.rb
|
94
|
-
- lib/nube_fact/invoice/item.rb
|
95
97
|
- lib/nube_fact/version.rb
|
96
98
|
- lib/util/sunat.rb
|
97
99
|
- lib/util/utils.rb
|