n8n-nodes-centum 0.1.2 → 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.
- package/README.md +1 -1
- package/dist/nodes/Centum/Centum.node.d.ts +1 -1
- package/dist/nodes/Centum/Centum.node.js +192 -119
- package/dist/nodes/Centum/Centum.node.js.map +1 -1
- package/dist/nodes/Centum/CentumDescription.d.ts +1 -0
- package/dist/nodes/Centum/CentumDescription.js +180 -106
- package/dist/nodes/Centum/CentumDescription.js.map +1 -1
- package/dist/nodes/Centum/centum.svg +565 -0
- package/dist/nodes/Centum/helpers/api.backup.d.ts +14 -0
- package/dist/nodes/Centum/helpers/api.backup.js +111 -0
- package/dist/nodes/Centum/helpers/api.backup.js.map +1 -0
- package/dist/nodes/Centum/helpers/functions.d.ts +26 -3
- package/dist/nodes/Centum/helpers/functions.js +197 -6
- package/dist/nodes/Centum/helpers/functions.js.map +1 -1
- package/dist/nodes/Centum/interfaces/{customers.d.ts → clientes.d.ts} +3 -3
- package/dist/nodes/Centum/interfaces/{customers.js → clientes.js} +49 -49
- package/dist/nodes/Centum/interfaces/clientes.js.map +1 -0
- package/dist/nodes/Centum/interfaces/index.d.ts +3 -3
- package/dist/nodes/Centum/interfaces/index.js +3 -3
- package/dist/nodes/Centum/interfaces/index.js.map +1 -1
- package/dist/nodes/Centum/interfaces/newCobro.d.ts +1 -1
- package/dist/nodes/Centum/interfaces/{newCustomer.d.ts → nuevoCliente.d.ts} +17 -5
- package/dist/nodes/Centum/interfaces/{newCustomer.js → nuevoCliente.js} +1 -1
- package/dist/nodes/Centum/interfaces/nuevoCliente.js.map +1 -0
- package/dist/nodes/Centum/interfaces/{newPedidoVenta.d.ts → nuevoPedidoVenta.d.ts} +1 -1
- package/dist/nodes/Centum/interfaces/{newPedidoVenta.js → nuevoPedidoVenta.js} +1 -1
- package/dist/nodes/Centum/interfaces/nuevoPedidoVenta.js.map +1 -0
- package/dist/package.json +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +10 -10
- package/dist/nodes/Centum/centum.png +0 -0
- package/dist/nodes/Centum/helpers/api.d.ts +0 -10
- package/dist/nodes/Centum/helpers/api.js +0 -48
- package/dist/nodes/Centum/helpers/api.js.map +0 -1
- package/dist/nodes/Centum/interfaces/customers.js.map +0 -1
- package/dist/nodes/Centum/interfaces/newCustomer.js.map +0 -1
- package/dist/nodes/Centum/interfaces/newPedidoVenta.js.map +0 -1
package/README.md
CHANGED
|
@@ -21,7 +21,7 @@ This node uses authenticated requests to the Centum API, ensuring secure and eff
|
|
|
21
21
|
To use this node, ensure you have the following installed on your development machine:
|
|
22
22
|
|
|
23
23
|
- **n8n**: Version 1.75.2 or higher (latest version recommended for compatibility).
|
|
24
|
-
- **Node.js**: Version
|
|
24
|
+
- **Node.js**: Version 20.x or higher.
|
|
25
25
|
- **npm**: Required for installing and building the plugin.
|
|
26
26
|
- **Git**: For cloning the repository.
|
|
27
27
|
- **Centum API Access**: Valid credentials (`centumUrl`, `consumerApiPublicId`, `publicAccessKey`) provided by your Centum provider.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IExecuteFunctions, INodeExecutionData, INodeType, INodeTypeDescription } from 'n8n-workflow';
|
|
1
|
+
import type { IExecuteFunctions, INodeExecutionData, INodeType, INodeTypeDescription } from 'n8n-workflow';
|
|
2
2
|
export declare class Centum implements INodeType {
|
|
3
3
|
description: INodeTypeDescription;
|
|
4
4
|
execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Centum = void 0;
|
|
4
|
-
const
|
|
4
|
+
const n8n_workflow_1 = require("n8n-workflow");
|
|
5
5
|
const CentumDescription_1 = require("./CentumDescription");
|
|
6
6
|
const functions_1 = require("./helpers/functions");
|
|
7
7
|
class Centum {
|
|
@@ -9,7 +9,7 @@ class Centum {
|
|
|
9
9
|
this.description = {
|
|
10
10
|
displayName: 'Centum',
|
|
11
11
|
name: 'centum',
|
|
12
|
-
icon: 'file:centum.
|
|
12
|
+
icon: 'file:centum.svg',
|
|
13
13
|
group: ['transform'],
|
|
14
14
|
version: 1,
|
|
15
15
|
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
|
@@ -25,31 +25,30 @@ class Centum {
|
|
|
25
25
|
required: true,
|
|
26
26
|
},
|
|
27
27
|
],
|
|
28
|
-
properties: [...CentumDescription_1.CentumOperations, ...CentumDescription_1.CentumFields],
|
|
28
|
+
properties: [...CentumDescription_1.CentumOperations, ...CentumDescription_1.CentumFields, ...CentumDescription_1.HttpOptions],
|
|
29
29
|
};
|
|
30
30
|
}
|
|
31
31
|
async execute() {
|
|
32
32
|
const centumApiCredentials = await this.getCredentials('centumApi');
|
|
33
33
|
let centumUrl = centumApiCredentials.centumUrl;
|
|
34
34
|
let consumerApiPublicId = centumApiCredentials.consumerApiPublicId;
|
|
35
|
-
const centumSuiteAccessToken = (0, functions_1.createHash)(centumApiCredentials.publicAccessKey);
|
|
36
35
|
const headers = {
|
|
37
36
|
CentumSuiteConsumidorApiPublicaId: consumerApiPublicId,
|
|
38
|
-
|
|
37
|
+
publicAccessKey: centumApiCredentials.publicAccessKey,
|
|
39
38
|
};
|
|
40
39
|
const resource = this.getNodeParameter('resource', 0);
|
|
41
40
|
switch (resource) {
|
|
42
41
|
case 'activity':
|
|
43
42
|
try {
|
|
44
|
-
const dataActividad = await (0,
|
|
43
|
+
const dataActividad = await (0, functions_1.apiRequest)(`${centumUrl}/PedidosVenta/27231`, { headers });
|
|
45
44
|
return [this.helpers.returnJsonArray(dataActividad)];
|
|
46
45
|
}
|
|
47
46
|
catch (error) {
|
|
48
47
|
console.log(error);
|
|
49
48
|
return [this.helpers.returnJsonArray([])];
|
|
50
49
|
}
|
|
51
|
-
case '
|
|
52
|
-
const clientId = this.getNodeParameter('
|
|
50
|
+
case 'articulo':
|
|
51
|
+
const clientId = this.getNodeParameter('clienteId', 0);
|
|
53
52
|
const documentDate = this.getNodeParameter('documentDate', 0);
|
|
54
53
|
const IdsRubro = this.getNodeParameter('idsRubros', 0);
|
|
55
54
|
const completeMigration = this.getNodeParameter('migracionCompleta', 0);
|
|
@@ -65,18 +64,18 @@ class Centum {
|
|
|
65
64
|
IdsRubro: IdsRubro ? [IdsRubro] : [],
|
|
66
65
|
IdsSubRubro: IdsSubRubro ? [IdsSubRubro] : [''],
|
|
67
66
|
fechaModificacionDesde: dateModified ? dateModified : '',
|
|
68
|
-
|
|
67
|
+
fechaModificacionImagenesDesde: dateModifiedImage ? dateModifiedImage : '',
|
|
69
68
|
fechaPrecioActualizadoDesde: priceDateModified,
|
|
70
69
|
};
|
|
71
70
|
try {
|
|
72
|
-
const
|
|
71
|
+
const response = await (0, functions_1.apiRequest)(`${centumUrl}/Articulos/Venta`, {
|
|
73
72
|
method: 'POST',
|
|
74
73
|
body: bodyToSend,
|
|
75
|
-
responseType: 'json',
|
|
76
74
|
headers,
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
75
|
+
queryParams: { tipoOrdenArticulos: 'Codigo' }
|
|
76
|
+
});
|
|
77
|
+
if (response.Articulos.Items.length > 0) {
|
|
78
|
+
const items = response.Articulos.Items;
|
|
80
79
|
if (!completeMigration) {
|
|
81
80
|
const acc = [];
|
|
82
81
|
for (const item of items) {
|
|
@@ -98,14 +97,14 @@ class Centum {
|
|
|
98
97
|
IdGrupoArticulo: groupArticle.IdGrupoArticulo
|
|
99
98
|
};
|
|
100
99
|
try {
|
|
101
|
-
const
|
|
100
|
+
const response = await (0, functions_1.apiRequest)(`${centumUrl}/Articulos/Venta`, {
|
|
102
101
|
method: 'POST',
|
|
103
102
|
headers: requestHeaders,
|
|
104
103
|
body,
|
|
105
104
|
queryParams: { tipoOrdenArticulos: 'Codigo' },
|
|
106
|
-
}
|
|
107
|
-
if (
|
|
108
|
-
acc.push(...
|
|
105
|
+
});
|
|
106
|
+
if (response.Articulos.Items.length > 0) {
|
|
107
|
+
acc.push(...response.Articulos.Items);
|
|
109
108
|
}
|
|
110
109
|
}
|
|
111
110
|
catch (error) {
|
|
@@ -130,22 +129,22 @@ class Centum {
|
|
|
130
129
|
console.log('Error en solicitud de artículos', error);
|
|
131
130
|
return [this.helpers.returnJsonArray([])];
|
|
132
131
|
}
|
|
133
|
-
case '
|
|
132
|
+
case 'articulosExistencia':
|
|
134
133
|
const branchOfficeIds = String(this.getNodeParameter('branchOfficeIds', 0));
|
|
135
134
|
try {
|
|
136
|
-
const
|
|
135
|
+
const dataArticulosExistencia = await (0, functions_1.apiRequest)(`${centumUrl}/ArticulosExistencias`, {
|
|
137
136
|
headers,
|
|
138
137
|
queryParams: {
|
|
139
138
|
idsSucursalesFisicas: branchOfficeIds,
|
|
140
139
|
},
|
|
141
140
|
});
|
|
142
|
-
return [this.helpers.returnJsonArray(
|
|
141
|
+
return [this.helpers.returnJsonArray(dataArticulosExistencia.Items)];
|
|
143
142
|
}
|
|
144
143
|
catch (error) {
|
|
145
144
|
console.log(error);
|
|
146
145
|
return [this.helpers.returnJsonArray([])];
|
|
147
146
|
}
|
|
148
|
-
case '
|
|
147
|
+
case 'articulosSucursalesFisicas':
|
|
149
148
|
const IdSucursalFisica = this.getNodeParameter('IdSucursalFisica', 0);
|
|
150
149
|
const queryParams = {
|
|
151
150
|
Codigo: 'R06SR0601P00010007',
|
|
@@ -154,23 +153,23 @@ class Centum {
|
|
|
154
153
|
queryParams.idsSucursalesFisicas = IdSucursalFisica;
|
|
155
154
|
}
|
|
156
155
|
try {
|
|
157
|
-
const dataArticulosExistencias = await (0,
|
|
156
|
+
const dataArticulosExistencias = await (0, functions_1.apiRequest)(`${centumUrl}/ArticulosSucursalesFisicas`, {
|
|
158
157
|
headers,
|
|
159
158
|
queryParams,
|
|
160
|
-
}
|
|
159
|
+
});
|
|
161
160
|
return [this.helpers.returnJsonArray(dataArticulosExistencias.Items)];
|
|
162
161
|
}
|
|
163
162
|
catch (error) {
|
|
164
163
|
console.log(error);
|
|
165
164
|
return [this.helpers.returnJsonArray([])];
|
|
166
165
|
}
|
|
167
|
-
case '
|
|
166
|
+
case 'precioArticulo':
|
|
168
167
|
const paramsPrice = {
|
|
169
|
-
Cantidad: this.getNodeParameter('
|
|
168
|
+
Cantidad: this.getNodeParameter('articuloCantidad', 0),
|
|
170
169
|
FechaDocumento: this.getNodeParameter('documentDate', 0),
|
|
171
170
|
};
|
|
172
171
|
try {
|
|
173
|
-
const dataArticulosPrecios = await (0,
|
|
172
|
+
const dataArticulosPrecios = await (0, functions_1.apiRequest)(`${centumUrl}/Articulos/PrecioArticulo`, {
|
|
174
173
|
method: 'POST',
|
|
175
174
|
headers,
|
|
176
175
|
queryParams: paramsPrice,
|
|
@@ -182,14 +181,14 @@ class Centum {
|
|
|
182
181
|
Nombre: 'ADHESIVO ACRILICO KEKOL K-645 1 KG',
|
|
183
182
|
NombreFantasia: '',
|
|
184
183
|
},
|
|
185
|
-
}
|
|
184
|
+
});
|
|
186
185
|
return [this.helpers.returnJsonArray(dataArticulosPrecios)];
|
|
187
186
|
}
|
|
188
187
|
catch (error) {
|
|
189
188
|
console.log(error);
|
|
190
189
|
return [this.helpers.returnJsonArray([])];
|
|
191
190
|
}
|
|
192
|
-
case '
|
|
191
|
+
case 'articulosImagenes':
|
|
193
192
|
const arrResult = [];
|
|
194
193
|
const inputData = this.getInputData();
|
|
195
194
|
const requestUrl = `${centumUrl}/ArticulosImagenes`;
|
|
@@ -202,7 +201,7 @@ class Centum {
|
|
|
202
201
|
};
|
|
203
202
|
const allArticleImages = await (0, functions_1.centumGetArticleImages)(1, element.json.IdArticulo, { consumerApiPublicId, publicAccessKey: String(centumApiCredentials.publicAccessKey) }, requestUrl);
|
|
204
203
|
if (allArticleImages instanceof Error) {
|
|
205
|
-
console.error(`
|
|
204
|
+
console.error(`Failed to download images for article ${element.json.IdArticulo}`, allArticleImages);
|
|
206
205
|
continue;
|
|
207
206
|
}
|
|
208
207
|
if (allArticleImages.length > 0) {
|
|
@@ -229,7 +228,7 @@ class Centum {
|
|
|
229
228
|
}
|
|
230
229
|
}
|
|
231
230
|
return [this.helpers.returnJsonArray(arrResult)];
|
|
232
|
-
case '
|
|
231
|
+
case 'procesarImagenes':
|
|
233
232
|
const dataImages = this.getNodeParameter('dataImg', 0);
|
|
234
233
|
const db = this.getNodeParameter('lastModifiedImg', 0);
|
|
235
234
|
const result = [];
|
|
@@ -254,28 +253,57 @@ class Centum {
|
|
|
254
253
|
result.push([]);
|
|
255
254
|
}
|
|
256
255
|
return [this.helpers.returnJsonArray(result)];
|
|
257
|
-
case '
|
|
256
|
+
case 'clientes':
|
|
258
257
|
try {
|
|
259
|
-
const
|
|
258
|
+
const ajustesHTTP = functions_1.getHttpSettings.call(this);
|
|
259
|
+
const fetchOptions = {
|
|
260
|
+
method: ajustesHTTP.method,
|
|
261
|
+
pagination: ajustesHTTP.pagination,
|
|
262
|
+
cantidadItemsPorPagina: ajustesHTTP.cantidadItemsPorPagina,
|
|
263
|
+
itemsField: 'Items',
|
|
264
|
+
context: this,
|
|
260
265
|
headers,
|
|
261
|
-
}
|
|
262
|
-
|
|
266
|
+
};
|
|
267
|
+
console.log(fetchOptions);
|
|
268
|
+
const clientes = await (0, functions_1.apiGetRequest)(`${centumUrl}/Clientes`, fetchOptions);
|
|
269
|
+
return [this.helpers.returnJsonArray(clientes)];
|
|
263
270
|
}
|
|
264
271
|
catch (error) {
|
|
265
|
-
console.
|
|
272
|
+
console.error('Error al obtener clientes:', error);
|
|
266
273
|
return [this.helpers.returnJsonArray([])];
|
|
267
274
|
}
|
|
268
|
-
case '
|
|
269
|
-
const
|
|
270
|
-
const
|
|
271
|
-
const
|
|
275
|
+
case 'contribuyenteNuevo': {
|
|
276
|
+
const bodyJson = this.getNodeParameter('cuerpoHTTP', 0);
|
|
277
|
+
const cuit = this.getNodeParameter('cuit', 0);
|
|
278
|
+
const contribuyenteJSON = (0, functions_1.createContribuyenteJson)(bodyJson, cuit);
|
|
272
279
|
try {
|
|
273
|
-
const
|
|
280
|
+
const crearCliente = await (0, functions_1.apiRequest)(`${centumUrl}/Clientes`, {
|
|
274
281
|
method: 'POST',
|
|
275
|
-
body:
|
|
282
|
+
body: contribuyenteJSON,
|
|
276
283
|
headers,
|
|
277
|
-
}
|
|
278
|
-
return [this.helpers.returnJsonArray(
|
|
284
|
+
});
|
|
285
|
+
return [this.helpers.returnJsonArray([crearCliente])];
|
|
286
|
+
}
|
|
287
|
+
catch (error) {
|
|
288
|
+
console.log(error);
|
|
289
|
+
const obj = {
|
|
290
|
+
...error.response?.data,
|
|
291
|
+
IdCliente: -1,
|
|
292
|
+
};
|
|
293
|
+
return [this.helpers.returnJsonArray([obj])];
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
case 'clienteNuevo':
|
|
297
|
+
const datosCliente = this.getNodeParameter('cuerpoHTTP', 0);
|
|
298
|
+
const clienteDNI = this.getNodeParameter('dni', 0);
|
|
299
|
+
const datosJSON = (0, functions_1.createCustomerJson)(datosCliente, clienteDNI);
|
|
300
|
+
try {
|
|
301
|
+
const crearCliente = await (0, functions_1.apiRequest)(`${centumUrl}/Clientes`, {
|
|
302
|
+
method: 'POST',
|
|
303
|
+
body: datosJSON,
|
|
304
|
+
headers,
|
|
305
|
+
});
|
|
306
|
+
return [this.helpers.returnJsonArray(crearCliente)];
|
|
279
307
|
}
|
|
280
308
|
catch (error) {
|
|
281
309
|
console.log(error);
|
|
@@ -285,29 +313,29 @@ class Centum {
|
|
|
285
313
|
};
|
|
286
314
|
return [this.helpers.returnJsonArray(obj)];
|
|
287
315
|
}
|
|
288
|
-
case '
|
|
289
|
-
const
|
|
316
|
+
case 'clientesActualizar':
|
|
317
|
+
const nuevosDatos = this.getNodeParameter('cuerpoHTTP', 0);
|
|
290
318
|
try {
|
|
291
|
-
const updateCustomer = await (0,
|
|
319
|
+
const updateCustomer = await (0, functions_1.apiRequest)(`${centumUrl}/Clientes/Actualizar`, {
|
|
292
320
|
method: 'POST',
|
|
293
|
-
body:
|
|
321
|
+
body: nuevosDatos,
|
|
294
322
|
headers,
|
|
295
|
-
}
|
|
323
|
+
});
|
|
296
324
|
return [this.helpers.returnJsonArray(updateCustomer)];
|
|
297
325
|
}
|
|
298
326
|
catch (error) {
|
|
299
327
|
console.log(error);
|
|
300
328
|
return [this.helpers.returnJsonArray([])];
|
|
301
329
|
}
|
|
302
|
-
case '
|
|
303
|
-
const customerSalesOrder = this.getNodeParameter('
|
|
304
|
-
const articlesSalesOrder = this.getNodeParameter('
|
|
305
|
-
const shippingSalesOrder = this.getNodeParameter('
|
|
306
|
-
const
|
|
330
|
+
case 'crearPedidoVenta': {
|
|
331
|
+
const customerSalesOrder = this.getNodeParameter('cliente', 0);
|
|
332
|
+
const articlesSalesOrder = this.getNodeParameter('articulo', 0);
|
|
333
|
+
const shippingSalesOrder = this.getNodeParameter('envio', 0);
|
|
334
|
+
const idCobro = this.getNodeParameter('idCobro', 0);
|
|
307
335
|
const date = new Date().toISOString();
|
|
308
336
|
const formattedDate = date.replace(/\..+/, '');
|
|
309
337
|
try {
|
|
310
|
-
const arrArticles = await (0,
|
|
338
|
+
const arrArticles = await (0, functions_1.apiRequest)(`${centumUrl}/Articulos/Venta`, {
|
|
311
339
|
method: 'POST',
|
|
312
340
|
headers,
|
|
313
341
|
body: {
|
|
@@ -316,117 +344,161 @@ class Centum {
|
|
|
316
344
|
Habilitado: true,
|
|
317
345
|
ActivoWeb: true,
|
|
318
346
|
},
|
|
319
|
-
}
|
|
320
|
-
const bodyPedidoVenta = (0, functions_1.createOrderSaleJson)(arrArticles.Articulos.Items, customerSalesOrder, articlesSalesOrder, shippingSalesOrder,
|
|
347
|
+
});
|
|
348
|
+
const bodyPedidoVenta = (0, functions_1.createOrderSaleJson)(arrArticles.Articulos.Items, customerSalesOrder, articlesSalesOrder, shippingSalesOrder, idCobro);
|
|
321
349
|
const centumSuiteAccessTokenSalesOrder = (0, functions_1.createHash)(centumApiCredentials.publicAccessKey);
|
|
322
350
|
const headersSalesOrder = {
|
|
323
351
|
CentumSuiteConsumidorApiPublicaId: consumerApiPublicId,
|
|
324
352
|
CentumSuiteAccessToken: centumSuiteAccessTokenSalesOrder,
|
|
325
353
|
};
|
|
326
|
-
const dataPedidosVenta = await (0,
|
|
354
|
+
const dataPedidosVenta = await (0, functions_1.apiRequest)(`${centumUrl}/PedidosVenta`, {
|
|
327
355
|
method: 'POST',
|
|
328
356
|
headers: headersSalesOrder,
|
|
329
357
|
body: bodyPedidoVenta,
|
|
330
|
-
}
|
|
331
|
-
dataPedidosVenta.IdCobro =
|
|
358
|
+
});
|
|
359
|
+
dataPedidosVenta.IdCobro = idCobro;
|
|
332
360
|
return [this.helpers.returnJsonArray(dataPedidosVenta)];
|
|
333
361
|
}
|
|
334
362
|
catch (error) {
|
|
335
|
-
console.log('Error
|
|
363
|
+
console.log('Error creating sales order:', error);
|
|
336
364
|
return [this.helpers.returnJsonArray([])];
|
|
337
365
|
}
|
|
338
366
|
}
|
|
339
|
-
case '
|
|
340
|
-
const
|
|
341
|
-
const
|
|
342
|
-
const
|
|
343
|
-
const bodyCharge = (0, functions_1.createChargeJson)(
|
|
367
|
+
case 'cobros':
|
|
368
|
+
const ordenCliente = this.getNodeParameter('cliente', 0);
|
|
369
|
+
const ordenArticulo = this.getNodeParameter('articulo', 0);
|
|
370
|
+
const ordenEnvio = this.getNodeParameter('envio', 0);
|
|
371
|
+
const bodyCharge = (0, functions_1.createChargeJson)(ordenCliente, ordenArticulo, ordenEnvio);
|
|
344
372
|
try {
|
|
345
|
-
const dataCobros = await (0,
|
|
373
|
+
const dataCobros = await (0, functions_1.apiRequest)(`${centumUrl}/Cobros`, {
|
|
374
|
+
method: 'POST',
|
|
346
375
|
body: bodyCharge,
|
|
347
376
|
headers,
|
|
348
|
-
}
|
|
377
|
+
});
|
|
349
378
|
return [this.helpers.returnJsonArray(dataCobros)];
|
|
350
379
|
}
|
|
351
380
|
catch (error) {
|
|
352
381
|
console.log(error);
|
|
353
382
|
return [this.helpers.returnJsonArray([])];
|
|
354
383
|
}
|
|
355
|
-
case '
|
|
356
|
-
const customerEmail = String(this.getNodeParameter('email', 0));
|
|
357
|
-
const tipoDocumento = this.getNodeParameter('tipoDocumento', 0);
|
|
358
|
-
const dni = this.getNodeParameter('dni', 0, '');
|
|
384
|
+
case 'buscarContribuyente': {
|
|
359
385
|
const cuit = this.getNodeParameter('cuit', 0, '');
|
|
360
|
-
const razonSocial =
|
|
386
|
+
const razonSocial = this.getNodeParameter('razonSocial', 0, '');
|
|
387
|
+
if (!cuit && !razonSocial) {
|
|
388
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Debe proporcionar al menos CUIT o Razón Social para buscar contribuyentes.');
|
|
389
|
+
}
|
|
390
|
+
const queryParams = {};
|
|
391
|
+
if (cuit)
|
|
392
|
+
queryParams.Cuit = cuit;
|
|
393
|
+
if (razonSocial)
|
|
394
|
+
queryParams.razonSocial = razonSocial;
|
|
395
|
+
const requestDetails = {
|
|
396
|
+
url: `${centumUrl}/Clientes`,
|
|
397
|
+
headers,
|
|
398
|
+
queryParams,
|
|
399
|
+
};
|
|
361
400
|
try {
|
|
362
|
-
console.log(
|
|
363
|
-
const
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
401
|
+
console.log(`[BuscarContribuyente] Request:`, JSON.stringify(requestDetails, null, 2));
|
|
402
|
+
const response = await (0, functions_1.apiRequest)(requestDetails.url, {
|
|
403
|
+
method: 'GET',
|
|
404
|
+
headers: requestDetails.headers,
|
|
405
|
+
queryParams: requestDetails.queryParams,
|
|
406
|
+
});
|
|
407
|
+
console.log(`[BuscarContribuyente] Response:`, JSON.stringify(response, null, 2));
|
|
408
|
+
if (response.CantidadTotalItems === 1) {
|
|
409
|
+
return [this.helpers.returnJsonArray(response.Items)];
|
|
410
|
+
}
|
|
411
|
+
return [this.helpers.returnJsonArray(response)];
|
|
412
|
+
}
|
|
413
|
+
catch (error) {
|
|
414
|
+
console.log(`[BuscarContribuyente] Error:`, error);
|
|
415
|
+
return [this.helpers.returnJsonArray([])];
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
case 'clientesBusqueda': {
|
|
419
|
+
const customerEmail = this.getNodeParameter('email', 0, '');
|
|
420
|
+
const dni = this.getNodeParameter('dni', 0, '');
|
|
421
|
+
const buildQuery = (campo, valor) => valor ? { [campo]: valor } : {};
|
|
422
|
+
let clientResponse = null;
|
|
423
|
+
try {
|
|
424
|
+
if (customerEmail) {
|
|
425
|
+
try {
|
|
426
|
+
console.log('[email] Buscando cliente por email...');
|
|
427
|
+
const response = await (0, functions_1.apiRequest)(`${centumUrl}/Clientes`, {
|
|
428
|
+
method: 'GET',
|
|
429
|
+
headers,
|
|
430
|
+
queryParams: buildQuery('Email', customerEmail),
|
|
431
|
+
});
|
|
432
|
+
console.log('[email] Resultado:', response);
|
|
433
|
+
clientResponse = response;
|
|
434
|
+
if (response.CantidadTotalItems === 1) {
|
|
435
|
+
return [this.helpers.returnJsonArray(response.Items)];
|
|
436
|
+
}
|
|
382
437
|
}
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
438
|
+
catch (error) {
|
|
439
|
+
console.log('[email] Error en búsqueda por email:', error);
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
if (!clientResponse && dni) {
|
|
388
443
|
try {
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
444
|
+
console.log('[dni] Buscando cliente por Código: web-{dni}...');
|
|
445
|
+
const response = await (0, functions_1.apiRequest)(`${centumUrl}/Clientes`, {
|
|
446
|
+
method: 'GET',
|
|
447
|
+
headers,
|
|
448
|
+
queryParams: buildQuery('Codigo', `web-${dni}`),
|
|
392
449
|
});
|
|
450
|
+
console.log('[dni] Resultado:', response);
|
|
451
|
+
clientResponse = response;
|
|
393
452
|
if (response.CantidadTotalItems === 1) {
|
|
394
|
-
|
|
395
|
-
break;
|
|
453
|
+
return [this.helpers.returnJsonArray(response.Items)];
|
|
396
454
|
}
|
|
397
455
|
}
|
|
398
456
|
catch (error) {
|
|
399
|
-
console.log(
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
457
|
+
console.log('[dni] Error con Código web-{dni}:', error);
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
if (!clientResponse && dni) {
|
|
461
|
+
try {
|
|
462
|
+
console.log('[dni-alt] Buscando cliente por Código simple (dni sin "web-")...');
|
|
463
|
+
const response = await (0, functions_1.apiRequest)(`${centumUrl}/Clientes`, {
|
|
464
|
+
method: 'GET',
|
|
465
|
+
headers,
|
|
466
|
+
queryParams: buildQuery('Codigo', dni),
|
|
403
467
|
});
|
|
404
|
-
|
|
468
|
+
console.log('[dni-alt] Resultado:', response);
|
|
469
|
+
clientResponse = response;
|
|
470
|
+
if (response.CantidadTotalItems === 1) {
|
|
471
|
+
return [this.helpers.returnJsonArray(response.Items)];
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
catch (error) {
|
|
475
|
+
console.log('[dni-alt] Error con Código sin "web-":', error);
|
|
405
476
|
}
|
|
406
477
|
}
|
|
407
|
-
|
|
408
|
-
return [this.helpers.returnJsonArray(result)];
|
|
478
|
+
return [this.helpers.returnJsonArray(clientResponse)];
|
|
409
479
|
}
|
|
410
480
|
catch (error) {
|
|
411
|
-
console.log('
|
|
412
|
-
return [this.helpers.returnJsonArray(error
|
|
481
|
+
console.log('General error during customer search:', error);
|
|
482
|
+
return [this.helpers.returnJsonArray([{ error: 'Búsqueda fallida', detalle: error }])];
|
|
413
483
|
}
|
|
414
|
-
|
|
484
|
+
}
|
|
485
|
+
case 'sucursalesLista':
|
|
415
486
|
try {
|
|
416
|
-
const dataListBranches = await (0,
|
|
487
|
+
const dataListBranches = await (0, functions_1.apiRequest)(`${centumUrl}/SucursalesFisicas`, {
|
|
488
|
+
method: 'GET',
|
|
417
489
|
headers,
|
|
418
|
-
}
|
|
490
|
+
});
|
|
419
491
|
return [this.helpers.returnJsonArray(dataListBranches)];
|
|
420
492
|
}
|
|
421
493
|
catch (error) {
|
|
422
494
|
console.log(error);
|
|
423
495
|
return [this.helpers.returnJsonArray(error.response.data)];
|
|
424
496
|
}
|
|
425
|
-
case '
|
|
497
|
+
case 'generarProductosWoo':
|
|
426
498
|
const data = this.getInputData();
|
|
427
499
|
const json = (0, functions_1.createJsonProducts)(data);
|
|
428
500
|
return [this.helpers.returnJsonArray(json)];
|
|
429
|
-
case '
|
|
501
|
+
case 'obtenerProductos':
|
|
430
502
|
try {
|
|
431
503
|
const payload = {
|
|
432
504
|
"IdCliente": 47924,
|
|
@@ -434,11 +506,11 @@ class Centum {
|
|
|
434
506
|
"Habilitado": true,
|
|
435
507
|
"ActivoWeb": true
|
|
436
508
|
};
|
|
437
|
-
const dataProductos = await (0,
|
|
509
|
+
const dataProductos = await (0, functions_1.apiRequest)(`${centumUrl}/Articulos/Venta`, {
|
|
438
510
|
method: 'POST',
|
|
439
511
|
body: payload,
|
|
440
512
|
headers
|
|
441
|
-
}
|
|
513
|
+
});
|
|
442
514
|
const items = dataProductos.Articulos?.Items || [];
|
|
443
515
|
const formateoObjeto = items.map((item) => ({
|
|
444
516
|
IdArticulo: item.IdArticulo,
|
|
@@ -471,6 +543,7 @@ class Centum {
|
|
|
471
543
|
return [this.helpers.returnJsonArray(formateoObjeto)];
|
|
472
544
|
}
|
|
473
545
|
catch (error) {
|
|
546
|
+
console.log(error);
|
|
474
547
|
return [this.helpers.returnJsonArray([])];
|
|
475
548
|
}
|
|
476
549
|
default:
|