n8n-nodes-centum 0.2.12 → 0.2.13
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/dist/nodes/Centum/Centum.node.js +486 -271
- package/dist/nodes/Centum/Centum.node.js.map +1 -1
- package/dist/nodes/Centum/CentumDescription.js +175 -55
- package/dist/nodes/Centum/CentumDescription.js.map +1 -1
- package/dist/nodes/Centum/helpers/functions.d.ts +1 -0
- package/dist/nodes/Centum/helpers/functions.js +49 -0
- package/dist/nodes/Centum/helpers/functions.js.map +1 -1
- package/dist/package.json +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -38,43 +38,7 @@ class Centum {
|
|
|
38
38
|
};
|
|
39
39
|
const resource = this.getNodeParameter('resource', 0);
|
|
40
40
|
switch (resource) {
|
|
41
|
-
case '
|
|
42
|
-
try {
|
|
43
|
-
const tokenGenerado = (0, functions_1.createHash)(headers.publicAccessKey);
|
|
44
|
-
return [this.helpers.returnJsonArray(tokenGenerado)];
|
|
45
|
-
}
|
|
46
|
-
catch (error) {
|
|
47
|
-
console.log(error);
|
|
48
|
-
const errorMessage = error?.response?.data?.Message || error.message || 'Error desconocido';
|
|
49
|
-
throw new n8n_workflow_1.NodeOperationError(this.getNode(), errorMessage);
|
|
50
|
-
}
|
|
51
|
-
case 'pedidoVentaActividad':
|
|
52
|
-
const pedidoID = this.getNodeParameter('id', 0);
|
|
53
|
-
try {
|
|
54
|
-
const dataActividad = await (0, functions_1.apiRequest)(`${centumUrl}/PedidosVenta/${pedidoID}`, { ...headers });
|
|
55
|
-
return [this.helpers.returnJsonArray(dataActividad)];
|
|
56
|
-
}
|
|
57
|
-
catch (error) {
|
|
58
|
-
console.log(error);
|
|
59
|
-
const errorMessage = error?.response?.data?.Message || error.message || 'Error desconocido';
|
|
60
|
-
throw new n8n_workflow_1.NodeOperationError(this.getNode(), errorMessage);
|
|
61
|
-
}
|
|
62
|
-
case 'articulosDatosGenerales':
|
|
63
|
-
try {
|
|
64
|
-
const response = await (0, functions_1.apiRequest)(`${centumUrl}/Articulos/DatosGenerales`, {
|
|
65
|
-
method: 'POST',
|
|
66
|
-
headers,
|
|
67
|
-
body: {},
|
|
68
|
-
queryParams: { tipoOrdenArticulos: 'Nombre' }
|
|
69
|
-
});
|
|
70
|
-
return [this.helpers.returnJsonArray(response)];
|
|
71
|
-
}
|
|
72
|
-
catch (error) {
|
|
73
|
-
console.log('Error en solicitud de artículos', error);
|
|
74
|
-
const errorMessage = error?.response?.data?.Message || error.message || 'Error desconocido';
|
|
75
|
-
throw new n8n_workflow_1.NodeOperationError(this.getNode(), errorMessage);
|
|
76
|
-
}
|
|
77
|
-
case 'articulo':
|
|
41
|
+
case 'articulo': {
|
|
78
42
|
const clientId = this.getNodeParameter('clienteId', 0);
|
|
79
43
|
const documentDate = this.getNodeParameter('documentDate', 0);
|
|
80
44
|
const IdsRubro = this.getNodeParameter('idsRubros', 0);
|
|
@@ -84,6 +48,8 @@ class Centum {
|
|
|
84
48
|
const dateModified = this.getNodeParameter('dateModified', 0);
|
|
85
49
|
const dateModifiedImage = this.getNodeParameter('dateModifiedImage', 0);
|
|
86
50
|
const priceDateModified = this.getNodeParameter('priceDateModified', 0);
|
|
51
|
+
const numeroPagina = this.getNodeParameter('numeroPagina', 0);
|
|
52
|
+
const cantidadPorPagina = this.getNodeParameter('cantidadPorPagina', 0);
|
|
87
53
|
const bodyToSend = {
|
|
88
54
|
idCliente: clientId,
|
|
89
55
|
FechaDocumento: formattedDocumentDate,
|
|
@@ -93,13 +59,15 @@ class Centum {
|
|
|
93
59
|
fechaModificacionDesde: dateModified ? dateModified : '',
|
|
94
60
|
fechaModificacionImagenesDesde: dateModifiedImage ? dateModifiedImage : '',
|
|
95
61
|
fechaPrecioActualizadoDesde: priceDateModified,
|
|
62
|
+
numeroPagina,
|
|
63
|
+
cantidadPorPagina,
|
|
96
64
|
};
|
|
97
65
|
try {
|
|
98
66
|
const response = await (0, functions_1.apiRequest)(`${centumUrl}/Articulos/Venta`, {
|
|
99
67
|
method: 'POST',
|
|
100
68
|
body: bodyToSend,
|
|
101
69
|
headers,
|
|
102
|
-
queryParams: { tipoOrdenArticulos: 'Codigo' }
|
|
70
|
+
queryParams: { tipoOrdenArticulos: 'Codigo' },
|
|
103
71
|
});
|
|
104
72
|
if (response.Articulos.Items.length > 0) {
|
|
105
73
|
const items = response.Articulos.Items;
|
|
@@ -136,7 +104,7 @@ class Centum {
|
|
|
136
104
|
}
|
|
137
105
|
}
|
|
138
106
|
const combinedArrays = [...acc, ...items];
|
|
139
|
-
const filteredArray = Array.from(new Map(combinedArrays.map(obj => [obj.IdArticulo, obj])).values());
|
|
107
|
+
const filteredArray = Array.from(new Map(combinedArrays.map((obj) => [obj.IdArticulo, obj])).values());
|
|
140
108
|
const itemsArray = filteredArray.map((item) => ({
|
|
141
109
|
...item,
|
|
142
110
|
AtributosArticulo: item.Habilitado && item.ActivoWeb ? item.AtributosArticulo : [],
|
|
@@ -154,69 +122,69 @@ class Centum {
|
|
|
154
122
|
const errorMessage = error?.response?.data?.Message || error.message || 'Error desconocido';
|
|
155
123
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), errorMessage);
|
|
156
124
|
}
|
|
157
|
-
|
|
158
|
-
|
|
125
|
+
}
|
|
126
|
+
case 'articuloPorId': {
|
|
127
|
+
const codigo = this.getNodeParameter('codigo', 0);
|
|
128
|
+
const articleId = this.getNodeParameter('articleId', 0);
|
|
129
|
+
if (!codigo && !articleId) {
|
|
130
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'El id o codigo del articulo es obligatorio');
|
|
131
|
+
}
|
|
159
132
|
try {
|
|
160
|
-
const
|
|
133
|
+
const articulo = await (0, functions_1.apiRequest)(`${centumUrl}/Articulos/DatosGenerales`, {
|
|
134
|
+
method: 'POST',
|
|
161
135
|
headers,
|
|
162
|
-
|
|
163
|
-
idsSucursalesFisicas: branchOfficeIds,
|
|
164
|
-
},
|
|
136
|
+
body: { CodigoExacto: codigo, Ids: articleId },
|
|
165
137
|
});
|
|
166
|
-
return [this.helpers.returnJsonArray(
|
|
138
|
+
return [this.helpers.returnJsonArray(articulo)];
|
|
167
139
|
}
|
|
168
140
|
catch (error) {
|
|
169
|
-
console.log('
|
|
141
|
+
console.log('Error en solicitud de artículo por ID:', error);
|
|
170
142
|
const errorMessage = error?.response?.data?.Message || error.message || 'Error desconocido';
|
|
171
143
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), errorMessage);
|
|
172
144
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
const queryParams = {
|
|
176
|
-
Codigo: 'R06SR0601P00010007',
|
|
177
|
-
};
|
|
178
|
-
if (IdSucursalFisica) {
|
|
179
|
-
queryParams.idsSucursalesFisicas = IdSucursalFisica;
|
|
180
|
-
}
|
|
145
|
+
}
|
|
146
|
+
case 'articulosDatosGenerales': {
|
|
181
147
|
try {
|
|
182
|
-
const
|
|
148
|
+
const ajustesHTTP = functions_1.getHttpSettings.call(this);
|
|
149
|
+
const articulosURL = `${centumUrl}/Articulos/DatosGenerales`;
|
|
150
|
+
const fetchOptions = {
|
|
151
|
+
method: 'POST',
|
|
183
152
|
headers,
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
153
|
+
body: {},
|
|
154
|
+
queryParams: { tipoOrdenArticulos: 'Nombre' },
|
|
155
|
+
pagination: ajustesHTTP.pagination,
|
|
156
|
+
cantidadItemsPorPagina: ajustesHTTP.cantidadItemsPorPagina,
|
|
157
|
+
intervaloPagina: ajustesHTTP.intervaloPagina,
|
|
158
|
+
itemsField: 'Items',
|
|
159
|
+
context: this,
|
|
160
|
+
};
|
|
161
|
+
const paginated = await (0, functions_1.apiPostRequestPaginated)(articulosURL, fetchOptions);
|
|
162
|
+
return [this.helpers.returnJsonArray(paginated)];
|
|
187
163
|
}
|
|
188
164
|
catch (error) {
|
|
189
|
-
console.log(error);
|
|
165
|
+
console.log('Error en solicitud de artículos', error);
|
|
190
166
|
const errorMessage = error?.response?.data?.Message || error.message || 'Error desconocido';
|
|
191
167
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), errorMessage);
|
|
192
168
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
FechaDocumento: this.getNodeParameter('documentDate', 0),
|
|
197
|
-
};
|
|
169
|
+
}
|
|
170
|
+
case 'articulosExistencia': {
|
|
171
|
+
const branchOfficeIds = String(this.getNodeParameter('branchOfficeIds', 0));
|
|
198
172
|
try {
|
|
199
|
-
const
|
|
200
|
-
method: 'POST',
|
|
173
|
+
const dataArticulosExistencia = await (0, functions_1.apiRequest)(`${centumUrl}/ArticulosExistencias`, {
|
|
201
174
|
headers,
|
|
202
|
-
queryParams:
|
|
203
|
-
|
|
204
|
-
IdArticulo: 1507,
|
|
205
|
-
Codigo: 'R02SR0206P00070007',
|
|
206
|
-
CodigoAuxiliar: '',
|
|
207
|
-
CodigoPropioProveedor: '',
|
|
208
|
-
Nombre: 'ADHESIVO ACRILICO KEKOL K-645 1 KG',
|
|
209
|
-
NombreFantasia: '',
|
|
175
|
+
queryParams: {
|
|
176
|
+
idsSucursalesFisicas: branchOfficeIds,
|
|
210
177
|
},
|
|
211
178
|
});
|
|
212
|
-
return [this.helpers.returnJsonArray(
|
|
179
|
+
return [this.helpers.returnJsonArray(dataArticulosExistencia.Items)];
|
|
213
180
|
}
|
|
214
181
|
catch (error) {
|
|
215
|
-
console.log(error);
|
|
182
|
+
console.log('ArticulosExistencias error: ', error);
|
|
216
183
|
const errorMessage = error?.response?.data?.Message || error.message || 'Error desconocido';
|
|
217
184
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), errorMessage);
|
|
218
185
|
}
|
|
219
|
-
|
|
186
|
+
}
|
|
187
|
+
case 'articulosImagenes': {
|
|
220
188
|
const arrResult = [];
|
|
221
189
|
const inputData = this.getInputData();
|
|
222
190
|
const requestUrl = `${centumUrl}/ArticulosImagenes`;
|
|
@@ -227,7 +195,10 @@ class Centum {
|
|
|
227
195
|
images: [],
|
|
228
196
|
infoImages: [],
|
|
229
197
|
};
|
|
230
|
-
const allArticleImages = await (0, functions_1.centumGetArticleImages)(1, element.json.IdArticulo, {
|
|
198
|
+
const allArticleImages = await (0, functions_1.centumGetArticleImages)(1, element.json.IdArticulo, {
|
|
199
|
+
consumerApiPublicId,
|
|
200
|
+
publicAccessKey: String(centumApiCredentials.publicAccessKey),
|
|
201
|
+
}, requestUrl);
|
|
231
202
|
if (allArticleImages instanceof Error) {
|
|
232
203
|
console.error(`Failed to download images for article ${element.json.IdArticulo}`, allArticleImages);
|
|
233
204
|
continue;
|
|
@@ -256,87 +227,111 @@ class Centum {
|
|
|
256
227
|
}
|
|
257
228
|
}
|
|
258
229
|
return [this.helpers.returnJsonArray(arrResult)];
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
const
|
|
262
|
-
const
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
for (let j = 0; j < element.json.images?.length; j++) {
|
|
266
|
-
const currentData = element.json.images[j];
|
|
267
|
-
const currentInfoImage = element.json.infoImages[j];
|
|
268
|
-
const articleInDB = db.find((dbData) => dbData.articleId === element.json.idArticulo);
|
|
269
|
-
if (!articleInDB) {
|
|
270
|
-
result.push({ json: {}, binary: currentData });
|
|
271
|
-
}
|
|
272
|
-
else {
|
|
273
|
-
const currentImageInDB = articleInDB.dataImage.find((dataImageDB) => dataImageDB.orderNumber === currentInfoImage.orderNumber);
|
|
274
|
-
if (currentImageInDB?.lastModified !== currentInfoImage.lastModified) {
|
|
275
|
-
result.push({ json: {}, binary: currentData });
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
}
|
|
230
|
+
}
|
|
231
|
+
case 'articulosPrecioPorLista': {
|
|
232
|
+
const idArticulos = this.getNodeParameter('codigo', 0);
|
|
233
|
+
const idLista = this.getNodeParameter('idList', 0);
|
|
234
|
+
if (!idLista || !idArticulos) {
|
|
235
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'El id de la lista y el artículo son obligatorios.');
|
|
279
236
|
}
|
|
280
|
-
|
|
281
|
-
|
|
237
|
+
try {
|
|
238
|
+
const articulo = await (0, functions_1.apiRequest)(`${centumUrl}/Articulos/FiltrosPrecios`, {
|
|
239
|
+
method: 'POST',
|
|
240
|
+
headers,
|
|
241
|
+
body: { IdsArticulos: idArticulos, IdLista: idLista },
|
|
242
|
+
});
|
|
243
|
+
return [this.helpers.returnJsonArray(articulo)];
|
|
244
|
+
}
|
|
245
|
+
catch (error) {
|
|
246
|
+
console.log('Error en solicitud de artículo por ID:', error);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
case 'articulosSucursalesFisicas': {
|
|
250
|
+
const IdSucursalFisica = this.getNodeParameter('IdSucursalFisica', 0);
|
|
251
|
+
const queryParams = {
|
|
252
|
+
idsSucursalesFisicas: IdSucursalFisica,
|
|
253
|
+
};
|
|
254
|
+
if (!IdSucursalFisica) {
|
|
255
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'El id de la sucursal fisica es obligatorio');
|
|
282
256
|
}
|
|
283
|
-
return [this.helpers.returnJsonArray(result)];
|
|
284
|
-
case 'clientes':
|
|
285
257
|
try {
|
|
286
|
-
const
|
|
287
|
-
const clientesURL = `${centumUrl}/Clientes`;
|
|
288
|
-
const fetchOptions = {
|
|
289
|
-
method: 'GET',
|
|
290
|
-
pagination: ajustesHTTP.pagination,
|
|
291
|
-
cantidadItemsPorPagina: ajustesHTTP.cantidadItemsPorPagina,
|
|
292
|
-
intervaloPagina: ajustesHTTP.intervaloPagina,
|
|
293
|
-
itemsField: 'Items',
|
|
294
|
-
context: this,
|
|
258
|
+
const dataArticulosExistencias = await (0, functions_1.apiRequest)(`${centumUrl}/ArticulosSucursalesFisicas`, {
|
|
295
259
|
headers,
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
clientes = paginated;
|
|
300
|
-
return [this.helpers.returnJsonArray(clientes)];
|
|
260
|
+
queryParams,
|
|
261
|
+
});
|
|
262
|
+
return [this.helpers.returnJsonArray(dataArticulosExistencias.Items)];
|
|
301
263
|
}
|
|
302
264
|
catch (error) {
|
|
265
|
+
console.log(error);
|
|
303
266
|
const errorMessage = error?.response?.data?.Message || error.message || 'Error desconocido';
|
|
304
267
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), errorMessage);
|
|
305
268
|
}
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
const
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
269
|
+
}
|
|
270
|
+
case 'articuloSucursalFisica': {
|
|
271
|
+
const IdSucursalFisica = this.getNodeParameter('idSucursalFisica', 0);
|
|
272
|
+
const idArticulo = this.getNodeParameter('articleId', 0);
|
|
273
|
+
const queryParams = {
|
|
274
|
+
IdSucursalFisica: IdSucursalFisica,
|
|
275
|
+
codigoExacto: idArticulo,
|
|
276
|
+
};
|
|
277
|
+
if (!IdSucursalFisica || !idArticulo) {
|
|
278
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'El id de la sucursal fisica y el id del articulo es obligatorio');
|
|
312
279
|
}
|
|
313
|
-
const contribuyenteJSON = (0, functions_1.createContribuyenteJson)(bodyJson, cuit);
|
|
314
280
|
try {
|
|
315
|
-
const
|
|
316
|
-
method: 'POST',
|
|
317
|
-
body: contribuyenteJSON,
|
|
281
|
+
const dataArticulosExistencias = await (0, functions_1.apiRequest)(`${centumUrl}/ArticulosSucursalesFisicas`, {
|
|
318
282
|
headers,
|
|
283
|
+
queryParams,
|
|
319
284
|
});
|
|
320
|
-
|
|
321
|
-
return [this.helpers.returnJsonArray([crearCliente])];
|
|
285
|
+
return [this.helpers.returnJsonArray(dataArticulosExistencias.Items)];
|
|
322
286
|
}
|
|
323
287
|
catch (error) {
|
|
324
|
-
console.
|
|
325
|
-
const
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
288
|
+
console.log(error);
|
|
289
|
+
const errorMessage = error?.response?.data?.Message || error.message || 'Error desconocido';
|
|
290
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), errorMessage);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
case 'buscarContribuyente': {
|
|
294
|
+
const cuit = this.getNodeParameter('cuit', 0, '');
|
|
295
|
+
const razonSocial = this.getNodeParameter('razonSocial', 0, '');
|
|
296
|
+
if (!cuit && !razonSocial) {
|
|
297
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Debe proporcionar al menos CUIT o Razón Social para buscar contribuyentes.');
|
|
298
|
+
}
|
|
299
|
+
let url = `${centumUrl}/Clientes/BuscarContribuyente`;
|
|
300
|
+
const queryParams = {};
|
|
301
|
+
if (cuit && !razonSocial) {
|
|
302
|
+
url += `/${cuit}`;
|
|
303
|
+
}
|
|
304
|
+
else {
|
|
305
|
+
if (cuit)
|
|
306
|
+
queryParams.Cuit = cuit;
|
|
307
|
+
if (razonSocial)
|
|
308
|
+
queryParams.razonSocial = razonSocial;
|
|
309
|
+
}
|
|
310
|
+
const requestDetails = {
|
|
311
|
+
url,
|
|
312
|
+
headers,
|
|
313
|
+
queryParams,
|
|
314
|
+
};
|
|
315
|
+
try {
|
|
316
|
+
console.log(`[BuscarContribuyente] Request:`, JSON.stringify(requestDetails, null, 2));
|
|
317
|
+
const response = await (0, functions_1.apiRequest)(requestDetails.url, {
|
|
318
|
+
method: 'GET',
|
|
319
|
+
headers: requestDetails.headers,
|
|
320
|
+
queryParams: requestDetails.queryParams,
|
|
336
321
|
});
|
|
322
|
+
console.log(`[BuscarContribuyente] Response:`, JSON.stringify(response, null, 2));
|
|
323
|
+
if (response.CantidadTotalItems === 1) {
|
|
324
|
+
return [this.helpers.returnJsonArray(response.Items)];
|
|
325
|
+
}
|
|
326
|
+
return [this.helpers.returnJsonArray(response)];
|
|
327
|
+
}
|
|
328
|
+
catch (error) {
|
|
329
|
+
console.log(`[BuscarContribuyente] Error:`, error);
|
|
330
|
+
const errorMessage = error?.response?.data?.Message || error.message || 'Error desconocido';
|
|
331
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), errorMessage);
|
|
337
332
|
}
|
|
338
333
|
}
|
|
339
|
-
case 'clienteNuevo':
|
|
334
|
+
case 'clienteNuevo': {
|
|
340
335
|
const datosCliente = this.getNodeParameter('cuerpoHTTP', 0);
|
|
341
336
|
const clienteDNI = this.getNodeParameter('dni', 0);
|
|
342
337
|
const datosJSON = (0, functions_1.createCustomerJson)(datosCliente, clienteDNI);
|
|
@@ -356,7 +351,31 @@ class Centum {
|
|
|
356
351
|
};
|
|
357
352
|
return [this.helpers.returnJsonArray(obj)];
|
|
358
353
|
}
|
|
359
|
-
|
|
354
|
+
}
|
|
355
|
+
case 'clientes': {
|
|
356
|
+
try {
|
|
357
|
+
const ajustesHTTP = functions_1.getHttpSettings.call(this);
|
|
358
|
+
const clientesURL = `${centumUrl}/Clientes`;
|
|
359
|
+
const fetchOptions = {
|
|
360
|
+
method: 'GET',
|
|
361
|
+
pagination: ajustesHTTP.pagination,
|
|
362
|
+
cantidadItemsPorPagina: ajustesHTTP.cantidadItemsPorPagina,
|
|
363
|
+
intervaloPagina: ajustesHTTP.intervaloPagina,
|
|
364
|
+
itemsField: 'Items',
|
|
365
|
+
context: this,
|
|
366
|
+
headers,
|
|
367
|
+
};
|
|
368
|
+
let clientes = [];
|
|
369
|
+
const paginated = await (0, functions_1.apiGetRequest)(clientesURL, fetchOptions);
|
|
370
|
+
clientes = paginated;
|
|
371
|
+
return [this.helpers.returnJsonArray(clientes)];
|
|
372
|
+
}
|
|
373
|
+
catch (error) {
|
|
374
|
+
const errorMessage = error?.response?.data?.Message || error.message || 'Error desconocido';
|
|
375
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), errorMessage);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
case 'clientesActualizar': {
|
|
360
379
|
const nuevosDatos = this.getNodeParameter('cuerpoHTTP', 0);
|
|
361
380
|
try {
|
|
362
381
|
const updateCustomer = await (0, functions_1.apiRequest)(`${centumUrl}/Clientes/Actualizar`, {
|
|
@@ -370,6 +389,114 @@ class Centum {
|
|
|
370
389
|
console.log(error);
|
|
371
390
|
return [this.helpers.returnJsonArray([])];
|
|
372
391
|
}
|
|
392
|
+
}
|
|
393
|
+
case 'clientesBusqueda': {
|
|
394
|
+
const customerEmail = this.getNodeParameter('email', 0, '');
|
|
395
|
+
const dni = this.getNodeParameter('dni', 0, '');
|
|
396
|
+
const buildQuery = (campo, valor) => valor ? { [campo]: valor } : {};
|
|
397
|
+
const trySearch = async (campo, valor, label) => {
|
|
398
|
+
if (!valor)
|
|
399
|
+
return null;
|
|
400
|
+
try {
|
|
401
|
+
console.log(`[${label}] Buscando cliente por ${campo}: ${valor}`);
|
|
402
|
+
const response = await (0, functions_1.apiRequest)(`${centumUrl}/Clientes`, {
|
|
403
|
+
method: 'GET',
|
|
404
|
+
headers,
|
|
405
|
+
queryParams: buildQuery(campo, valor),
|
|
406
|
+
}, this);
|
|
407
|
+
console.log(`[${label}] Resultado:`, response);
|
|
408
|
+
return response;
|
|
409
|
+
}
|
|
410
|
+
catch (error) {
|
|
411
|
+
console.error(`[${label}] Error:`, error);
|
|
412
|
+
return null;
|
|
413
|
+
}
|
|
414
|
+
};
|
|
415
|
+
try {
|
|
416
|
+
let response = null;
|
|
417
|
+
if (customerEmail) {
|
|
418
|
+
response = await trySearch('Email', customerEmail, 'email');
|
|
419
|
+
}
|
|
420
|
+
if (!response && dni) {
|
|
421
|
+
response = await trySearch('Codigo', `web-${dni}`, 'dni-web');
|
|
422
|
+
}
|
|
423
|
+
if (!response && dni) {
|
|
424
|
+
response = await trySearch('Codigo', `${dni}`, 'dni');
|
|
425
|
+
}
|
|
426
|
+
console.log('Búsqueda finalizada. Resultado:', response);
|
|
427
|
+
return [this.helpers.returnJsonArray(response)];
|
|
428
|
+
}
|
|
429
|
+
catch (error) {
|
|
430
|
+
console.error('Error general durante la búsqueda de cliente:', error);
|
|
431
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Búsqueda fallida: ${JSON.stringify(error)}`);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
case 'clientesBusquedaPorCuit': {
|
|
435
|
+
const cuit = this.getNodeParameter('cuit', 0, '');
|
|
436
|
+
if (!cuit) {
|
|
437
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Debe proporcionar CUIT para buscar clientes.');
|
|
438
|
+
}
|
|
439
|
+
const queryParams = { Cuit: cuit };
|
|
440
|
+
try {
|
|
441
|
+
const response = await (0, functions_1.apiRequest)(`${centumUrl}/Clientes`, {
|
|
442
|
+
method: 'GET',
|
|
443
|
+
headers,
|
|
444
|
+
queryParams,
|
|
445
|
+
});
|
|
446
|
+
return [this.helpers.returnJsonArray(response.Items)];
|
|
447
|
+
}
|
|
448
|
+
catch (error) {
|
|
449
|
+
console.log(`[ClientesBusquedaPorCuit] Error:`, error);
|
|
450
|
+
const errorMessage = error?.response?.data?.Message || error.message || 'Error desconocido';
|
|
451
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), errorMessage);
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
case 'cobros': {
|
|
455
|
+
const ordenCliente = this.getNodeParameter('cliente', 0);
|
|
456
|
+
const ordenArticulo = this.getNodeParameter('articulo', 0);
|
|
457
|
+
const ordenEnvio = this.getNodeParameter('envio', 0);
|
|
458
|
+
const bodyCharge = (0, functions_1.createChargeJson)(ordenCliente, ordenArticulo, ordenEnvio);
|
|
459
|
+
try {
|
|
460
|
+
const dataCobros = await (0, functions_1.apiRequest)(`${centumUrl}/Cobros`, {
|
|
461
|
+
method: 'POST',
|
|
462
|
+
body: bodyCharge,
|
|
463
|
+
headers,
|
|
464
|
+
});
|
|
465
|
+
return [this.helpers.returnJsonArray(dataCobros)];
|
|
466
|
+
}
|
|
467
|
+
catch (error) {
|
|
468
|
+
console.log(error);
|
|
469
|
+
const errorMessage = error?.response?.data?.Message || error.message || 'Error desconocido';
|
|
470
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), errorMessage);
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
case 'composicionSaldoCliente': {
|
|
474
|
+
const clientIdParam = this.getNodeParameter('clienteId', 0);
|
|
475
|
+
const desdeSaldoFecha = this.getNodeParameter('priceDateModified', 0);
|
|
476
|
+
const separarFecha = String(desdeSaldoFecha).split('T')[0];
|
|
477
|
+
const clientId = Number(clientIdParam);
|
|
478
|
+
if (isNaN(clientId) || clientId <= 0) {
|
|
479
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'clienteId debe ser un número positivo');
|
|
480
|
+
}
|
|
481
|
+
try {
|
|
482
|
+
let url = `${centumUrl}/SaldosCuentasCorrientes/Composicion/${clientId}`;
|
|
483
|
+
if (separarFecha) {
|
|
484
|
+
url += `?fechaVencimientoHasta=${separarFecha}`;
|
|
485
|
+
}
|
|
486
|
+
const response = await (0, functions_1.apiRequest)(url, {
|
|
487
|
+
method: 'GET',
|
|
488
|
+
headers,
|
|
489
|
+
});
|
|
490
|
+
if (!response || typeof response !== 'object') {
|
|
491
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Respuesta inválida del servidor');
|
|
492
|
+
}
|
|
493
|
+
return [this.helpers.returnJsonArray(response)];
|
|
494
|
+
}
|
|
495
|
+
catch (error) {
|
|
496
|
+
const errorMessage = error?.response?.data?.Message || error.message || 'Error desconocido';
|
|
497
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Error obteniendo composición de saldo para cliente ${clientId}: ${errorMessage}`);
|
|
498
|
+
}
|
|
499
|
+
}
|
|
373
500
|
case 'crearPedidoVenta': {
|
|
374
501
|
const customerSalesOrder = this.getNodeParameter('cliente', 0);
|
|
375
502
|
const articlesSalesOrder = this.getNodeParameter('articulo', 0);
|
|
@@ -408,167 +535,260 @@ class Centum {
|
|
|
408
535
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), errorMessage);
|
|
409
536
|
}
|
|
410
537
|
}
|
|
411
|
-
case '
|
|
412
|
-
const
|
|
413
|
-
const ordenArticulo = this.getNodeParameter('articulo', 0);
|
|
414
|
-
const ordenEnvio = this.getNodeParameter('envio', 0);
|
|
415
|
-
const bodyCharge = (0, functions_1.createChargeJson)(ordenCliente, ordenArticulo, ordenEnvio);
|
|
538
|
+
case 'departamentosLista': {
|
|
539
|
+
const idProvincia = this.getNodeParameter('idProvincia', 0, '');
|
|
416
540
|
try {
|
|
417
|
-
const
|
|
418
|
-
|
|
419
|
-
|
|
541
|
+
const queryParams = {};
|
|
542
|
+
if (idProvincia) {
|
|
543
|
+
queryParams.idProvincia = idProvincia;
|
|
544
|
+
}
|
|
545
|
+
const departamentos = await (0, functions_1.apiRequest)(`${centumUrl}/Departamentos`, {
|
|
546
|
+
method: 'GET',
|
|
420
547
|
headers,
|
|
548
|
+
queryParams,
|
|
421
549
|
});
|
|
422
|
-
return [this.helpers.returnJsonArray(
|
|
550
|
+
return [this.helpers.returnJsonArray(departamentos.map((d) => ({ ...d })))];
|
|
423
551
|
}
|
|
424
552
|
catch (error) {
|
|
425
553
|
console.log(error);
|
|
426
554
|
const errorMessage = error?.response?.data?.Message || error.message || 'Error desconocido';
|
|
427
555
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), errorMessage);
|
|
428
556
|
}
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
const
|
|
432
|
-
|
|
433
|
-
|
|
557
|
+
}
|
|
558
|
+
case 'generarProductosWoo': {
|
|
559
|
+
const data = this.getInputData();
|
|
560
|
+
const json = (0, functions_1.createJsonProducts)(data);
|
|
561
|
+
return [this.helpers.returnJsonArray(json)];
|
|
562
|
+
}
|
|
563
|
+
case 'generarToken': {
|
|
564
|
+
try {
|
|
565
|
+
const tokenGenerado = (0, functions_1.createHash)(headers.publicAccessKey);
|
|
566
|
+
return [this.helpers.returnJsonArray(tokenGenerado)];
|
|
434
567
|
}
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
headers,
|
|
443
|
-
queryParams,
|
|
444
|
-
};
|
|
568
|
+
catch (error) {
|
|
569
|
+
console.log(error);
|
|
570
|
+
const errorMessage = error?.response?.data?.Message || error.message || 'Error desconocido';
|
|
571
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), errorMessage);
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
case 'listaPrecios': {
|
|
445
575
|
try {
|
|
446
|
-
|
|
447
|
-
const response = await (0, functions_1.apiRequest)(requestDetails.url, {
|
|
576
|
+
const response = await (0, functions_1.apiRequest)(`${centumUrl}/ListasPrecios`, {
|
|
448
577
|
method: 'GET',
|
|
449
|
-
headers
|
|
450
|
-
queryParams: requestDetails.queryParams,
|
|
578
|
+
headers,
|
|
451
579
|
});
|
|
452
|
-
console.log(`[BuscarContribuyente] Response:`, JSON.stringify(response, null, 2));
|
|
453
|
-
if (response.CantidadTotalItems === 1) {
|
|
454
|
-
return [this.helpers.returnJsonArray(response.Items)];
|
|
455
|
-
}
|
|
456
580
|
return [this.helpers.returnJsonArray(response)];
|
|
457
581
|
}
|
|
458
582
|
catch (error) {
|
|
459
|
-
console.log(
|
|
583
|
+
console.log('Error en solicitud de promociones para el cliente:', error);
|
|
460
584
|
const errorMessage = error?.response?.data?.Message || error.message || 'Error desconocido';
|
|
461
|
-
throw new n8n_workflow_1.NodeOperationError(this.getNode(), errorMessage);
|
|
585
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Error obteniendo el listado de precios. \n ${errorMessage}`);
|
|
462
586
|
}
|
|
463
587
|
}
|
|
464
|
-
case '
|
|
465
|
-
const
|
|
466
|
-
const
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
console.log(`[${label}] Buscando cliente por ${campo}: ${valor}`);
|
|
473
|
-
const response = await (0, functions_1.apiRequest)(`${centumUrl}/Clientes`, {
|
|
474
|
-
method: 'GET',
|
|
475
|
-
headers,
|
|
476
|
-
queryParams: buildQuery(campo, valor),
|
|
477
|
-
}, this);
|
|
478
|
-
console.log(`[${label}] Resultado:`, response);
|
|
479
|
-
return response;
|
|
480
|
-
}
|
|
481
|
-
catch (error) {
|
|
482
|
-
console.error(`[${label}] Error:`, error);
|
|
483
|
-
return null;
|
|
484
|
-
}
|
|
485
|
-
};
|
|
588
|
+
case 'nuevoContribuyente': {
|
|
589
|
+
const bodyJson = this.getNodeParameter('cuerpoHTTP', 0);
|
|
590
|
+
const cuit = this.getNodeParameter('cuit', 0);
|
|
591
|
+
console.log(bodyJson);
|
|
592
|
+
if (typeof cuit !== 'string' || !/^\d{11}$/.test(cuit)) {
|
|
593
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'El CUIT debe ser una cadena de 11 dígitos numéricos.');
|
|
594
|
+
}
|
|
595
|
+
const contribuyenteJSON = (0, functions_1.createContribuyenteJson)(bodyJson, cuit);
|
|
486
596
|
try {
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
597
|
+
const crearCliente = await (0, functions_1.apiRequest)(`${centumUrl}/Clientes`, {
|
|
598
|
+
method: 'POST',
|
|
599
|
+
body: contribuyenteJSON,
|
|
600
|
+
headers,
|
|
601
|
+
});
|
|
602
|
+
console.log('Contribuyente creado:', crearCliente);
|
|
603
|
+
return [this.helpers.returnJsonArray([crearCliente])];
|
|
604
|
+
}
|
|
605
|
+
catch (error) {
|
|
606
|
+
console.error('Error al crear contribuyente:', error);
|
|
607
|
+
const statusCode = error?.response?.status;
|
|
608
|
+
const responseData = error?.response?.data;
|
|
609
|
+
const errorMessage = responseData?.Message ||
|
|
610
|
+
responseData?.message ||
|
|
611
|
+
error?.message ||
|
|
612
|
+
'Error desconocido al crear el contribuyente.';
|
|
613
|
+
const fullMessage = statusCode ? `Error ${statusCode}: ${errorMessage}` : errorMessage;
|
|
614
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), fullMessage, {
|
|
615
|
+
description: responseData?.Detail || 'Ocurrió un error inesperado al llamar a la API de Centum.',
|
|
616
|
+
});
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
case 'obtenerFacturasCobros': {
|
|
620
|
+
const clientIdParam = this.getNodeParameter('clienteId', 0);
|
|
621
|
+
const desdeSaldoFecha = this.getNodeParameter('balanceStartDate', 0);
|
|
622
|
+
const hastaSaldoFecha = this.getNodeParameter('balanceEndDate', 0);
|
|
623
|
+
const separarFechaDesde = String(desdeSaldoFecha).split('T')[0];
|
|
624
|
+
const separarFechaHasta = String(hastaSaldoFecha).split('T')[0];
|
|
625
|
+
const clientId = Number(clientIdParam);
|
|
626
|
+
if (isNaN(clientId) || clientId <= 0) {
|
|
627
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'clienteId debe ser un número positivo');
|
|
628
|
+
}
|
|
629
|
+
if (!desdeSaldoFecha) {
|
|
630
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'priceDateModified (fecha desde) es requerido');
|
|
631
|
+
}
|
|
632
|
+
if (!hastaSaldoFecha) {
|
|
633
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'priceDateModifiedSince (fecha hasta) es requerido');
|
|
634
|
+
}
|
|
635
|
+
try {
|
|
636
|
+
const body = {
|
|
637
|
+
fechaDocumentoDesde: separarFechaDesde,
|
|
638
|
+
fechaDocumentoHasta: separarFechaHasta,
|
|
639
|
+
IdCliente: clientId,
|
|
640
|
+
};
|
|
641
|
+
const response = await (0, functions_1.apiRequest)(`${centumUrl}/Cobros/FiltrosCobro`, {
|
|
642
|
+
method: 'POST',
|
|
643
|
+
headers,
|
|
644
|
+
body,
|
|
645
|
+
});
|
|
646
|
+
if (!response || typeof response !== 'object') {
|
|
647
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Respuesta inválida del servidor');
|
|
493
648
|
}
|
|
494
|
-
|
|
495
|
-
|
|
649
|
+
return [this.helpers.returnJsonArray(response)];
|
|
650
|
+
}
|
|
651
|
+
catch (error) {
|
|
652
|
+
console.log('Error en solicitud de facturas pedidos ventas:', error);
|
|
653
|
+
const errorMessage = error?.response?.data?.Message || error.message || 'Error desconocido';
|
|
654
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Error obteniendo facturas pedidos ventas para cliente ${clientId}: ${errorMessage}`);
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
case 'obtenerFacturasPedidosVentas': {
|
|
658
|
+
const clientIdParam = this.getNodeParameter('clienteId', 0);
|
|
659
|
+
const desdeSaldoFecha = this.getNodeParameter('balanceStartDate', 0);
|
|
660
|
+
const hastaSaldoFecha = this.getNodeParameter('balanceEndDate', 0);
|
|
661
|
+
const separarFechaDesde = String(desdeSaldoFecha).split('T')[0];
|
|
662
|
+
const separarFechaHasta = String(hastaSaldoFecha).split('T')[0];
|
|
663
|
+
const clientId = Number(clientIdParam);
|
|
664
|
+
if (isNaN(clientId) || clientId <= 0) {
|
|
665
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'clienteId debe ser un número positivo');
|
|
666
|
+
}
|
|
667
|
+
if (!desdeSaldoFecha) {
|
|
668
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'priceDateModified (fecha desde) es requerido');
|
|
669
|
+
}
|
|
670
|
+
if (!hastaSaldoFecha) {
|
|
671
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'priceDateModifiedSince (fecha hasta) es requerido');
|
|
672
|
+
}
|
|
673
|
+
try {
|
|
674
|
+
const body = {
|
|
675
|
+
fechaDocumentoDesde: separarFechaDesde,
|
|
676
|
+
fechaDocumentoHasta: separarFechaHasta,
|
|
677
|
+
IdCliente: clientId,
|
|
678
|
+
};
|
|
679
|
+
const response = await (0, functions_1.apiRequest)(`${centumUrl}/Ventas/FiltrosVenta`, {
|
|
680
|
+
method: 'POST',
|
|
681
|
+
headers,
|
|
682
|
+
body,
|
|
683
|
+
});
|
|
684
|
+
if (!response || typeof response !== 'object') {
|
|
685
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Respuesta inválida del servidor');
|
|
496
686
|
}
|
|
497
|
-
console.log('Búsqueda finalizada. Resultado:', response);
|
|
498
687
|
return [this.helpers.returnJsonArray(response)];
|
|
499
688
|
}
|
|
500
689
|
catch (error) {
|
|
501
|
-
console.
|
|
502
|
-
|
|
690
|
+
console.log('Error en solicitud de facturas pedidos ventas:', error);
|
|
691
|
+
const errorMessage = error?.response?.data?.Message || error.message || 'Error desconocido';
|
|
692
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Error obteniendo facturas pedidos ventas para cliente ${clientId}: ${errorMessage}`);
|
|
503
693
|
}
|
|
504
694
|
}
|
|
505
|
-
case '
|
|
695
|
+
case 'obtenerSaldoCliente': {
|
|
696
|
+
const clientIdParam = this.getNodeParameter('clienteId', 0);
|
|
697
|
+
const desdeSaldoFecha = this.getNodeParameter('priceDateModified', 0);
|
|
698
|
+
const soloFecha = String(desdeSaldoFecha).split('T')[0];
|
|
699
|
+
const clientId = Number(clientIdParam);
|
|
700
|
+
if (isNaN(clientId) || clientId <= 0) {
|
|
701
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'clienteId debe ser un número positivo');
|
|
702
|
+
}
|
|
506
703
|
try {
|
|
507
|
-
|
|
704
|
+
let url = `${centumUrl}/SaldosCuentasCorrientes/${clientId}`;
|
|
705
|
+
if (soloFecha) {
|
|
706
|
+
url += `?fechaVencimientoHasta=${soloFecha}`;
|
|
707
|
+
}
|
|
708
|
+
const response = await (0, functions_1.apiRequest)(url, {
|
|
508
709
|
method: 'GET',
|
|
509
710
|
headers,
|
|
510
711
|
});
|
|
511
|
-
return [this.helpers.returnJsonArray(
|
|
712
|
+
return [this.helpers.returnJsonArray(response)];
|
|
713
|
+
}
|
|
714
|
+
catch (error) {
|
|
715
|
+
const errorMessage = error?.response?.data?.Message || error.message || 'Error desconocido';
|
|
716
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Error obteniendo saldo para cliente ${clientId}: ${errorMessage}`);
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
case 'pedidoVentaActividad': {
|
|
720
|
+
const pedidoID = this.getNodeParameter('id', 0);
|
|
721
|
+
try {
|
|
722
|
+
const dataActividad = await (0, functions_1.apiRequest)(`${centumUrl}/PedidosVenta/${pedidoID}`, { ...headers });
|
|
723
|
+
return [this.helpers.returnJsonArray(dataActividad)];
|
|
512
724
|
}
|
|
513
725
|
catch (error) {
|
|
514
726
|
console.log(error);
|
|
515
727
|
const errorMessage = error?.response?.data?.Message || error.message || 'Error desconocido';
|
|
516
728
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), errorMessage);
|
|
517
729
|
}
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
const
|
|
521
|
-
|
|
522
|
-
|
|
730
|
+
}
|
|
731
|
+
case 'procesarImagenes': {
|
|
732
|
+
const dataImages = this.getNodeParameter('dataImg', 0);
|
|
733
|
+
const db = this.getNodeParameter('lastModifiedImg', 0);
|
|
734
|
+
const result = [];
|
|
735
|
+
for (let i = 0; i < dataImages.length; i++) {
|
|
736
|
+
const element = dataImages[i];
|
|
737
|
+
for (let j = 0; j < element.json.images?.length; j++) {
|
|
738
|
+
const currentData = element.json.images[j];
|
|
739
|
+
const currentInfoImage = element.json.infoImages[j];
|
|
740
|
+
const articleInDB = db.find((dbData) => dbData.articleId === element.json.idArticulo);
|
|
741
|
+
if (!articleInDB) {
|
|
742
|
+
result.push({ json: {}, binary: currentData });
|
|
743
|
+
}
|
|
744
|
+
else {
|
|
745
|
+
const currentImageInDB = articleInDB.dataImage.find((dataImageDB) => dataImageDB.orderNumber === currentInfoImage.orderNumber);
|
|
746
|
+
if (currentImageInDB?.lastModified !== currentInfoImage.lastModified) {
|
|
747
|
+
result.push({ json: {}, binary: currentData });
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
if (result.length === 0) {
|
|
753
|
+
result.push([]);
|
|
754
|
+
}
|
|
755
|
+
return [this.helpers.returnJsonArray(result)];
|
|
756
|
+
}
|
|
757
|
+
case 'promocionesCliente': {
|
|
758
|
+
const clientIdParam = this.getNodeParameter('clienteId', 0);
|
|
759
|
+
const documentDate = this.getNodeParameter('documentDate', 0);
|
|
760
|
+
const diaSemana = this.getNodeParameter('diaSemana', 0);
|
|
761
|
+
const clientId = Number(clientIdParam);
|
|
762
|
+
if (!documentDate) {
|
|
763
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'documentDate es requerido');
|
|
764
|
+
}
|
|
765
|
+
const formattedDocumentDate = String(documentDate).split('T')[0];
|
|
523
766
|
try {
|
|
524
|
-
const
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
"ActivoWeb": true
|
|
767
|
+
const body = {
|
|
768
|
+
FechaDocumento: formattedDocumentDate,
|
|
769
|
+
IdsCliente: clientId,
|
|
770
|
+
DiaSemana: diaSemana || '',
|
|
529
771
|
};
|
|
530
|
-
const
|
|
772
|
+
const response = await (0, functions_1.apiRequest)(`${centumUrl}/PromocionesComerciales/FiltrosPromocionComercial`, {
|
|
531
773
|
method: 'POST',
|
|
532
|
-
|
|
533
|
-
|
|
774
|
+
headers,
|
|
775
|
+
body,
|
|
534
776
|
});
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
ActivoWeb: item.ActivoWeb,
|
|
543
|
-
Precio: item.Precio,
|
|
544
|
-
FechaUltimaActualizacionPrecio: item.FechaUltimaActualizacionPrecio,
|
|
545
|
-
StockDisponible: item.StockDisponible,
|
|
546
|
-
Rubro: item.Rubro ? {
|
|
547
|
-
IdRubro: item.Rubro.IdRubro,
|
|
548
|
-
Codigo: item.Rubro.Codigo,
|
|
549
|
-
Nombre: item.Rubro.Nombre
|
|
550
|
-
} : null,
|
|
551
|
-
SubRubro: item.SubRubro ? {
|
|
552
|
-
IdSubRubro: item.SubRubro.IdSubRubro,
|
|
553
|
-
Codigo: item.SubRubro.Codigo,
|
|
554
|
-
Nombre: item.SubRubro.Nombre,
|
|
555
|
-
IdRubro: item.SubRubro.IdRubro
|
|
556
|
-
} : null,
|
|
557
|
-
CategoriaArticulo: item.CategoriaArticulo ? {
|
|
558
|
-
IdCategoriaArticulo: item.CategoriaArticulo.IdCategoriaArticulo,
|
|
559
|
-
Codigo: item.CategoriaArticulo.Codigo,
|
|
560
|
-
Nombre: item.CategoriaArticulo.Nombre,
|
|
561
|
-
IdSubRubro: item.CategoriaArticulo.IdSubRubro
|
|
562
|
-
} : null
|
|
563
|
-
}));
|
|
564
|
-
return [this.helpers.returnJsonArray(formateoObjeto)];
|
|
777
|
+
if (!response || typeof response !== 'object') {
|
|
778
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Respuesta inválida del servidor');
|
|
779
|
+
}
|
|
780
|
+
if (response.Items && Array.isArray(response.Items)) {
|
|
781
|
+
return [this.helpers.returnJsonArray(response.Items)];
|
|
782
|
+
}
|
|
783
|
+
return [this.helpers.returnJsonArray(response)];
|
|
565
784
|
}
|
|
566
785
|
catch (error) {
|
|
567
|
-
console.log(error);
|
|
786
|
+
console.log('Error en solicitud de promociones para el cliente:', error);
|
|
568
787
|
const errorMessage = error?.response?.data?.Message || error.message || 'Error desconocido';
|
|
569
|
-
throw new n8n_workflow_1.NodeOperationError(this.getNode(), errorMessage);
|
|
788
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Error obteniendo promociones para el cliente ${clientId}: \n ${errorMessage}`);
|
|
570
789
|
}
|
|
571
|
-
|
|
790
|
+
}
|
|
791
|
+
case 'provinciasLista': {
|
|
572
792
|
const idPais = this.getNodeParameter('idPais', 0, '');
|
|
573
793
|
try {
|
|
574
794
|
const queryParams = {};
|
|
@@ -580,7 +800,7 @@ class Centum {
|
|
|
580
800
|
headers,
|
|
581
801
|
queryParams,
|
|
582
802
|
});
|
|
583
|
-
return [this.helpers.returnJsonArray(provincias.map(p => ({ ...p })))];
|
|
803
|
+
return [this.helpers.returnJsonArray(provincias.map((p) => ({ ...p })))];
|
|
584
804
|
}
|
|
585
805
|
catch (error) {
|
|
586
806
|
console.log(error);
|
|
@@ -588,19 +808,13 @@ class Centum {
|
|
|
588
808
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), errorMessage);
|
|
589
809
|
}
|
|
590
810
|
}
|
|
591
|
-
case
|
|
592
|
-
const idProvincia = this.getNodeParameter('idProvincia', 0, '');
|
|
811
|
+
case 'sucursalesFisicas': {
|
|
593
812
|
try {
|
|
594
|
-
const
|
|
595
|
-
if (idProvincia) {
|
|
596
|
-
queryParams.idProvincia = idProvincia;
|
|
597
|
-
}
|
|
598
|
-
const departamentos = await (0, functions_1.apiRequest)(`${centumUrl}/Departamentos`, {
|
|
813
|
+
const dataListBranches = await (0, functions_1.apiRequest)(`${centumUrl}/SucursalesFisicas`, {
|
|
599
814
|
method: 'GET',
|
|
600
815
|
headers,
|
|
601
|
-
queryParams,
|
|
602
816
|
});
|
|
603
|
-
return [this.helpers.returnJsonArray(
|
|
817
|
+
return [this.helpers.returnJsonArray(dataListBranches)];
|
|
604
818
|
}
|
|
605
819
|
catch (error) {
|
|
606
820
|
console.log(error);
|
|
@@ -608,8 +822,9 @@ class Centum {
|
|
|
608
822
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), errorMessage);
|
|
609
823
|
}
|
|
610
824
|
}
|
|
611
|
-
default:
|
|
612
|
-
|
|
825
|
+
default: {
|
|
826
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Operación no implementada: ${resource}`);
|
|
827
|
+
}
|
|
613
828
|
}
|
|
614
829
|
}
|
|
615
830
|
}
|