n8n-nodes-centum 0.2.16 → 0.2.17
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 +75 -50
- package/dist/nodes/Centum/Centum.node.d.ts +1 -1
- package/dist/nodes/Centum/Centum.node.js +541 -299
- package/dist/nodes/Centum/Centum.node.js.map +1 -1
- package/dist/nodes/Centum/CentumDescription.js +455 -344
- package/dist/nodes/Centum/CentumDescription.js.map +1 -1
- package/dist/package.json +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -7,21 +7,21 @@ const functions_1 = require("./helpers/functions");
|
|
|
7
7
|
class Centum {
|
|
8
8
|
constructor() {
|
|
9
9
|
this.description = {
|
|
10
|
-
displayName:
|
|
11
|
-
name:
|
|
12
|
-
icon:
|
|
13
|
-
group: [
|
|
10
|
+
displayName: "Centum",
|
|
11
|
+
name: "centum",
|
|
12
|
+
icon: "file:centum.svg",
|
|
13
|
+
group: ["transform"],
|
|
14
14
|
version: 1,
|
|
15
15
|
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
|
16
|
-
description:
|
|
16
|
+
description: "Consumes Centum API",
|
|
17
17
|
defaults: {
|
|
18
|
-
name:
|
|
18
|
+
name: "Centum",
|
|
19
19
|
},
|
|
20
|
-
inputs: [
|
|
21
|
-
outputs: [
|
|
20
|
+
inputs: ["main"],
|
|
21
|
+
outputs: ["main"],
|
|
22
22
|
credentials: [
|
|
23
23
|
{
|
|
24
|
-
name:
|
|
24
|
+
name: "centumApi",
|
|
25
25
|
required: true,
|
|
26
26
|
},
|
|
27
27
|
],
|
|
@@ -29,45 +29,45 @@ class Centum {
|
|
|
29
29
|
};
|
|
30
30
|
}
|
|
31
31
|
async execute() {
|
|
32
|
-
const centumApiCredentials = await this.getCredentials(
|
|
32
|
+
const centumApiCredentials = await this.getCredentials("centumApi");
|
|
33
33
|
let centumUrl = centumApiCredentials.centumUrl;
|
|
34
34
|
let consumerApiPublicId = centumApiCredentials.consumerApiPublicId;
|
|
35
35
|
const headers = {
|
|
36
36
|
CentumSuiteConsumidorApiPublicaId: consumerApiPublicId,
|
|
37
37
|
publicAccessKey: centumApiCredentials.publicAccessKey,
|
|
38
38
|
};
|
|
39
|
-
const resource = this.getNodeParameter(
|
|
39
|
+
const resource = this.getNodeParameter("resource", 0);
|
|
40
40
|
switch (resource) {
|
|
41
|
-
case
|
|
42
|
-
const clientId = this.getNodeParameter(
|
|
43
|
-
const documentDate = this.getNodeParameter(
|
|
44
|
-
const IdsRubro = this.getNodeParameter(
|
|
45
|
-
const completeMigration = this.getNodeParameter(
|
|
46
|
-
const IdsSubRubro = this.getNodeParameter(
|
|
47
|
-
const formattedDocumentDate = documentDate.replace(/\..+/,
|
|
48
|
-
const dateModified = this.getNodeParameter(
|
|
49
|
-
const dateModifiedImage = this.getNodeParameter(
|
|
50
|
-
const priceDateModified = this.getNodeParameter(
|
|
51
|
-
const numeroPagina = this.getNodeParameter(
|
|
52
|
-
const cantidadPorPagina = this.getNodeParameter(
|
|
41
|
+
case "articulo": {
|
|
42
|
+
const clientId = this.getNodeParameter("clienteId", 0);
|
|
43
|
+
const documentDate = this.getNodeParameter("documentDate", 0);
|
|
44
|
+
const IdsRubro = this.getNodeParameter("idsRubros", 0);
|
|
45
|
+
const completeMigration = this.getNodeParameter("migracionCompleta", 0);
|
|
46
|
+
const IdsSubRubro = this.getNodeParameter("idsSubRubros", 0);
|
|
47
|
+
const formattedDocumentDate = documentDate.replace(/\..+/, "");
|
|
48
|
+
const dateModified = this.getNodeParameter("dateModified", 0);
|
|
49
|
+
const dateModifiedImage = this.getNodeParameter("dateModifiedImage", 0);
|
|
50
|
+
const priceDateModified = this.getNodeParameter("priceDateModified", 0);
|
|
51
|
+
const numeroPagina = this.getNodeParameter("numeroPagina", 0);
|
|
52
|
+
const cantidadPorPagina = this.getNodeParameter("cantidadPorPagina", 0);
|
|
53
53
|
const bodyToSend = {
|
|
54
54
|
idCliente: clientId,
|
|
55
55
|
FechaDocumento: formattedDocumentDate,
|
|
56
56
|
incluirAtributosArticulos: true,
|
|
57
57
|
IdsRubro: IdsRubro ? [IdsRubro] : [],
|
|
58
|
-
IdsSubRubro: IdsSubRubro ? [IdsSubRubro] : [
|
|
59
|
-
fechaModificacionDesde: dateModified ? dateModified :
|
|
60
|
-
fechaModificacionImagenesDesde: dateModifiedImage ? dateModifiedImage :
|
|
58
|
+
IdsSubRubro: IdsSubRubro ? [IdsSubRubro] : [""],
|
|
59
|
+
fechaModificacionDesde: dateModified ? dateModified : "",
|
|
60
|
+
fechaModificacionImagenesDesde: dateModifiedImage ? dateModifiedImage : "",
|
|
61
61
|
fechaPrecioActualizadoDesde: priceDateModified,
|
|
62
62
|
numeroPagina,
|
|
63
63
|
cantidadPorPagina,
|
|
64
64
|
};
|
|
65
65
|
try {
|
|
66
66
|
const response = await (0, functions_1.apiRequest)(`${centumUrl}/Articulos/Venta`, {
|
|
67
|
-
method:
|
|
67
|
+
method: "POST",
|
|
68
68
|
body: bodyToSend,
|
|
69
69
|
headers,
|
|
70
|
-
queryParams: { tipoOrdenArticulos:
|
|
70
|
+
queryParams: { tipoOrdenArticulos: "Codigo" },
|
|
71
71
|
});
|
|
72
72
|
if (response.Articulos.Items.length > 0) {
|
|
73
73
|
const items = response.Articulos.Items;
|
|
@@ -82,24 +82,24 @@ class Centum {
|
|
|
82
82
|
FechaDocumento: formattedDocumentDate,
|
|
83
83
|
incluirAtributosArticulos: true,
|
|
84
84
|
IdsRubro: IdsRubro ? [IdsRubro] : [],
|
|
85
|
-
IdsSubRubro: IdsSubRubro ? [IdsSubRubro] : [
|
|
85
|
+
IdsSubRubro: IdsSubRubro ? [IdsSubRubro] : [""],
|
|
86
86
|
NombreGrupoArticulo: groupArticle.Nombre,
|
|
87
87
|
IdGrupoArticulo: groupArticle.IdGrupoArticulo,
|
|
88
88
|
};
|
|
89
89
|
try {
|
|
90
90
|
const response = await (0, functions_1.apiRequest)(`${centumUrl}/Articulos/Venta`, {
|
|
91
|
-
method:
|
|
91
|
+
method: "POST",
|
|
92
92
|
headers: { ...headers },
|
|
93
93
|
body,
|
|
94
|
-
queryParams: { tipoOrdenArticulos:
|
|
94
|
+
queryParams: { tipoOrdenArticulos: "Codigo" },
|
|
95
95
|
});
|
|
96
96
|
if (response.Articulos.Items.length > 0) {
|
|
97
97
|
acc.push(...response.Articulos.Items);
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
100
|
catch (error) {
|
|
101
|
-
console.log(
|
|
102
|
-
const errorMessage = error?.response?.data?.Message || error.message ||
|
|
101
|
+
console.log("Error en solicitud de grupo de artículos", { error });
|
|
102
|
+
const errorMessage = error?.response?.data?.Message || error.message || "Error desconocido";
|
|
103
103
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), errorMessage);
|
|
104
104
|
}
|
|
105
105
|
}
|
|
@@ -118,57 +118,57 @@ class Centum {
|
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
120
|
catch (error) {
|
|
121
|
-
console.log(
|
|
122
|
-
const errorMessage = error?.response?.data?.Message || error.message ||
|
|
121
|
+
console.log("Error en solicitud de artículos", error);
|
|
122
|
+
const errorMessage = error?.response?.data?.Message || error.message || "Error desconocido";
|
|
123
123
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), errorMessage);
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
|
-
case
|
|
127
|
-
const codigo = this.getNodeParameter(
|
|
128
|
-
const articleId = this.getNodeParameter(
|
|
126
|
+
case "articuloPorId": {
|
|
127
|
+
const codigo = this.getNodeParameter("codigo", 0);
|
|
128
|
+
const articleId = this.getNodeParameter("articleId", 0);
|
|
129
129
|
if (!codigo && !articleId) {
|
|
130
|
-
throw new n8n_workflow_1.NodeOperationError(this.getNode(),
|
|
130
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), "El id o codigo del articulo es obligatorio");
|
|
131
131
|
}
|
|
132
132
|
try {
|
|
133
133
|
const articulo = await (0, functions_1.apiRequest)(`${centumUrl}/Articulos/DatosGenerales`, {
|
|
134
|
-
method:
|
|
134
|
+
method: "POST",
|
|
135
135
|
headers,
|
|
136
136
|
body: { CodigoExacto: codigo, Ids: articleId },
|
|
137
137
|
});
|
|
138
138
|
return [this.helpers.returnJsonArray(articulo)];
|
|
139
139
|
}
|
|
140
140
|
catch (error) {
|
|
141
|
-
console.log(
|
|
142
|
-
const errorMessage = error?.response?.data?.Message || error.message ||
|
|
141
|
+
console.log("Error en solicitud de artículo por ID:", error);
|
|
142
|
+
const errorMessage = error?.response?.data?.Message || error.message || "Error desconocido";
|
|
143
143
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), errorMessage);
|
|
144
144
|
}
|
|
145
145
|
}
|
|
146
|
-
case
|
|
146
|
+
case "articulosDatosGenerales": {
|
|
147
147
|
try {
|
|
148
148
|
const ajustesHTTP = functions_1.getHttpSettings.call(this);
|
|
149
149
|
const articulosURL = `${centumUrl}/Articulos/DatosGenerales`;
|
|
150
150
|
const fetchOptions = {
|
|
151
|
-
method:
|
|
151
|
+
method: "POST",
|
|
152
152
|
headers,
|
|
153
153
|
body: {},
|
|
154
|
-
queryParams: { tipoOrdenArticulos:
|
|
154
|
+
queryParams: { tipoOrdenArticulos: "Nombre" },
|
|
155
155
|
pagination: ajustesHTTP.pagination,
|
|
156
156
|
cantidadItemsPorPagina: ajustesHTTP.cantidadItemsPorPagina,
|
|
157
157
|
intervaloPagina: ajustesHTTP.intervaloPagina,
|
|
158
|
-
itemsField:
|
|
158
|
+
itemsField: "Items",
|
|
159
159
|
context: this,
|
|
160
160
|
};
|
|
161
161
|
const paginated = await (0, functions_1.apiPostRequestPaginated)(articulosURL, fetchOptions);
|
|
162
162
|
return [this.helpers.returnJsonArray(paginated)];
|
|
163
163
|
}
|
|
164
164
|
catch (error) {
|
|
165
|
-
console.log(
|
|
166
|
-
const errorMessage = error?.response?.data?.Message || error.message ||
|
|
165
|
+
console.log("Error en solicitud de artículos", error);
|
|
166
|
+
const errorMessage = error?.response?.data?.Message || error.message || "Error desconocido";
|
|
167
167
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), errorMessage);
|
|
168
168
|
}
|
|
169
169
|
}
|
|
170
|
-
case
|
|
171
|
-
const branchOfficeIds = String(this.getNodeParameter(
|
|
170
|
+
case "articulosExistencia": {
|
|
171
|
+
const branchOfficeIds = String(this.getNodeParameter("branchOfficeIds", 0));
|
|
172
172
|
try {
|
|
173
173
|
const dataArticulosExistencia = await (0, functions_1.apiRequest)(`${centumUrl}/ArticulosExistencias`, {
|
|
174
174
|
headers,
|
|
@@ -179,12 +179,12 @@ class Centum {
|
|
|
179
179
|
return [this.helpers.returnJsonArray(dataArticulosExistencia.Items)];
|
|
180
180
|
}
|
|
181
181
|
catch (error) {
|
|
182
|
-
console.log(
|
|
183
|
-
const errorMessage = error?.response?.data?.Message || error.message ||
|
|
182
|
+
console.log("ArticulosExistencias error: ", error);
|
|
183
|
+
const errorMessage = error?.response?.data?.Message || error.message || "Error desconocido";
|
|
184
184
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), errorMessage);
|
|
185
185
|
}
|
|
186
186
|
}
|
|
187
|
-
case
|
|
187
|
+
case "articulosImagenes": {
|
|
188
188
|
const arrResult = [];
|
|
189
189
|
const inputData = this.getInputData();
|
|
190
190
|
const requestUrl = `${centumUrl}/ArticulosImagenes`;
|
|
@@ -208,7 +208,7 @@ class Centum {
|
|
|
208
208
|
const binary = {};
|
|
209
209
|
const dataImage = allArticleImages[j];
|
|
210
210
|
const buffer = Buffer.from(dataImage.buffer);
|
|
211
|
-
binary[
|
|
211
|
+
binary["data"] = await this.helpers.prepareBinaryData(buffer);
|
|
212
212
|
binary.data.fileName = `${element.json.Codigo}_${j + 1}.${binary.data.fileExtension}`;
|
|
213
213
|
dataObj.images.push(binary);
|
|
214
214
|
dataObj.infoImages.push({
|
|
@@ -228,31 +228,31 @@ class Centum {
|
|
|
228
228
|
}
|
|
229
229
|
return [this.helpers.returnJsonArray(arrResult)];
|
|
230
230
|
}
|
|
231
|
-
case
|
|
232
|
-
const idArticulos = this.getNodeParameter(
|
|
233
|
-
const idLista = this.getNodeParameter(
|
|
231
|
+
case "articulosPrecioPorLista": {
|
|
232
|
+
const idArticulos = this.getNodeParameter("codigo", 0);
|
|
233
|
+
const idLista = this.getNodeParameter("idList", 0);
|
|
234
234
|
if (!idLista || !idArticulos) {
|
|
235
|
-
throw new n8n_workflow_1.NodeOperationError(this.getNode(),
|
|
235
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), "El id de la lista y el artículo son obligatorios.");
|
|
236
236
|
}
|
|
237
237
|
try {
|
|
238
238
|
const articulo = await (0, functions_1.apiRequest)(`${centumUrl}/Articulos/FiltrosPrecios`, {
|
|
239
|
-
method:
|
|
239
|
+
method: "POST",
|
|
240
240
|
headers,
|
|
241
241
|
body: { IdsArticulos: idArticulos, IdLista: idLista },
|
|
242
242
|
});
|
|
243
243
|
return [this.helpers.returnJsonArray(articulo)];
|
|
244
244
|
}
|
|
245
245
|
catch (error) {
|
|
246
|
-
console.log(
|
|
246
|
+
console.log("Error en solicitud de artículo por ID:", error);
|
|
247
247
|
}
|
|
248
248
|
}
|
|
249
|
-
case
|
|
250
|
-
const IdSucursalFisica = this.getNodeParameter(
|
|
249
|
+
case "articulosSucursalesFisicas": {
|
|
250
|
+
const IdSucursalFisica = this.getNodeParameter("IdSucursalFisica", 0);
|
|
251
251
|
const queryParams = {
|
|
252
252
|
idsSucursalesFisicas: IdSucursalFisica,
|
|
253
253
|
};
|
|
254
254
|
if (!IdSucursalFisica) {
|
|
255
|
-
throw new n8n_workflow_1.NodeOperationError(this.getNode(),
|
|
255
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), "El id de la sucursal fisica es obligatorio");
|
|
256
256
|
}
|
|
257
257
|
try {
|
|
258
258
|
const dataArticulosExistencias = await (0, functions_1.apiRequest)(`${centumUrl}/ArticulosSucursalesFisicas`, {
|
|
@@ -263,21 +263,21 @@ class Centum {
|
|
|
263
263
|
}
|
|
264
264
|
catch (error) {
|
|
265
265
|
console.log(error);
|
|
266
|
-
const errorMessage = error?.response?.data?.Message || error.message ||
|
|
266
|
+
const errorMessage = error?.response?.data?.Message || error.message || "Error desconocido";
|
|
267
267
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), errorMessage);
|
|
268
268
|
}
|
|
269
269
|
}
|
|
270
|
-
case
|
|
271
|
-
const IdSucursalFisica = this.getNodeParameter(
|
|
272
|
-
const idArticulo = this.getNodeParameter(
|
|
273
|
-
const codigo = this.getNodeParameter(
|
|
270
|
+
case "articuloSucursalFisica": {
|
|
271
|
+
const IdSucursalFisica = this.getNodeParameter("idSucursalFisica", 0);
|
|
272
|
+
const idArticulo = this.getNodeParameter("articleId", 0);
|
|
273
|
+
const codigo = this.getNodeParameter("codigo", 0);
|
|
274
274
|
const queryParams = {
|
|
275
275
|
IdSucursalFisica: IdSucursalFisica,
|
|
276
276
|
codigoExacto: codigo,
|
|
277
|
-
idsArticulos: idArticulo
|
|
277
|
+
idsArticulos: idArticulo,
|
|
278
278
|
};
|
|
279
279
|
if (!IdSucursalFisica || (!idArticulo && !codigo)) {
|
|
280
|
-
throw new n8n_workflow_1.NodeOperationError(this.getNode(),
|
|
280
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), "El id de la sucursal fisica y el id del articulo o el codigo son obligatorios");
|
|
281
281
|
}
|
|
282
282
|
try {
|
|
283
283
|
const dataArticulosExistencias = await (0, functions_1.apiRequest)(`${centumUrl}/ArticulosSucursalesFisicas`, {
|
|
@@ -288,15 +288,31 @@ class Centum {
|
|
|
288
288
|
}
|
|
289
289
|
catch (error) {
|
|
290
290
|
console.log(error);
|
|
291
|
-
const errorMessage = error?.response?.data?.Message || error.message ||
|
|
291
|
+
const errorMessage = error?.response?.data?.Message || error.message || "Error desconocido";
|
|
292
292
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), errorMessage);
|
|
293
293
|
}
|
|
294
294
|
}
|
|
295
|
-
case '
|
|
296
|
-
const
|
|
297
|
-
|
|
295
|
+
case 'buscarArticulo': {
|
|
296
|
+
const nombreArticulo = this.getNodeParameter('nombreArticulo', 0, '');
|
|
297
|
+
try {
|
|
298
|
+
const response = await (0, functions_1.apiRequest)(`${centumUrl}/Articulos/DatosGenerales`, {
|
|
299
|
+
method: 'POST',
|
|
300
|
+
headers,
|
|
301
|
+
body: {
|
|
302
|
+
Nombre: nombreArticulo
|
|
303
|
+
}
|
|
304
|
+
});
|
|
305
|
+
return [this.helpers.returnJsonArray(response)];
|
|
306
|
+
}
|
|
307
|
+
catch (error) {
|
|
308
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Hubo un error al buscar el articulo. Error: ${error}`);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
case "buscarContribuyente": {
|
|
312
|
+
const cuit = this.getNodeParameter("cuit", 0, "");
|
|
313
|
+
const razonSocial = this.getNodeParameter("razonSocial", 0, "");
|
|
298
314
|
if (!cuit && !razonSocial) {
|
|
299
|
-
throw new n8n_workflow_1.NodeOperationError(this.getNode(),
|
|
315
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), "Debe proporcionar al menos CUIT o Razón Social para buscar contribuyentes.");
|
|
300
316
|
}
|
|
301
317
|
let url = `${centumUrl}/Clientes/BuscarContribuyente`;
|
|
302
318
|
const queryParams = {};
|
|
@@ -317,7 +333,7 @@ class Centum {
|
|
|
317
333
|
try {
|
|
318
334
|
console.log(`[BuscarContribuyente] Request:`, JSON.stringify(requestDetails, null, 2));
|
|
319
335
|
const response = await (0, functions_1.apiRequest)(requestDetails.url, {
|
|
320
|
-
method:
|
|
336
|
+
method: "GET",
|
|
321
337
|
headers: requestDetails.headers,
|
|
322
338
|
queryParams: requestDetails.queryParams,
|
|
323
339
|
});
|
|
@@ -329,17 +345,31 @@ class Centum {
|
|
|
329
345
|
}
|
|
330
346
|
catch (error) {
|
|
331
347
|
console.log(`[BuscarContribuyente] Error:`, error);
|
|
332
|
-
const errorMessage = error?.response?.data?.Message || error.message ||
|
|
348
|
+
const errorMessage = error?.response?.data?.Message || error.message || "Error desconocido";
|
|
333
349
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), errorMessage);
|
|
334
350
|
}
|
|
335
351
|
}
|
|
336
|
-
case
|
|
337
|
-
const
|
|
338
|
-
|
|
352
|
+
case "categoriasObtener": {
|
|
353
|
+
const subRubro = this.getNodeParameter('idsSubRubros', 0);
|
|
354
|
+
let url = `${centumUrl}/CategoriasArticulo`;
|
|
355
|
+
if (subRubro) {
|
|
356
|
+
url = `${url}?idSubRubro=${subRubro}`;
|
|
357
|
+
}
|
|
358
|
+
try {
|
|
359
|
+
const response = await (0, functions_1.apiRequest)(url);
|
|
360
|
+
return [this.helpers.returnJsonArray(response)];
|
|
361
|
+
}
|
|
362
|
+
catch (error) {
|
|
363
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Hubo un error al obtener el listado de categorias. Error: ${error}`);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
case "clienteNuevo": {
|
|
367
|
+
const datosCliente = this.getNodeParameter("cuerpoHTTP", 0);
|
|
368
|
+
const clienteDNI = this.getNodeParameter("dni", 0);
|
|
339
369
|
const datosJSON = (0, functions_1.createCustomerJson)(datosCliente, clienteDNI);
|
|
340
370
|
try {
|
|
341
371
|
const crearCliente = await (0, functions_1.apiRequest)(`${centumUrl}/Clientes`, {
|
|
342
|
-
method:
|
|
372
|
+
method: "POST",
|
|
343
373
|
body: datosJSON,
|
|
344
374
|
headers,
|
|
345
375
|
});
|
|
@@ -354,16 +384,16 @@ class Centum {
|
|
|
354
384
|
return [this.helpers.returnJsonArray(obj)];
|
|
355
385
|
}
|
|
356
386
|
}
|
|
357
|
-
case
|
|
387
|
+
case "clientes": {
|
|
358
388
|
try {
|
|
359
389
|
const ajustesHTTP = functions_1.getHttpSettings.call(this);
|
|
360
390
|
const clientesURL = `${centumUrl}/Clientes`;
|
|
361
391
|
const fetchOptions = {
|
|
362
|
-
method:
|
|
392
|
+
method: "GET",
|
|
363
393
|
pagination: ajustesHTTP.pagination,
|
|
364
394
|
cantidadItemsPorPagina: ajustesHTTP.cantidadItemsPorPagina,
|
|
365
395
|
intervaloPagina: ajustesHTTP.intervaloPagina,
|
|
366
|
-
itemsField:
|
|
396
|
+
itemsField: "Items",
|
|
367
397
|
context: this,
|
|
368
398
|
headers,
|
|
369
399
|
};
|
|
@@ -373,15 +403,15 @@ class Centum {
|
|
|
373
403
|
return [this.helpers.returnJsonArray(clientes)];
|
|
374
404
|
}
|
|
375
405
|
catch (error) {
|
|
376
|
-
const errorMessage = error?.response?.data?.Message || error.message ||
|
|
406
|
+
const errorMessage = error?.response?.data?.Message || error.message || "Error desconocido";
|
|
377
407
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), errorMessage);
|
|
378
408
|
}
|
|
379
409
|
}
|
|
380
|
-
case
|
|
381
|
-
const nuevosDatos = this.getNodeParameter(
|
|
410
|
+
case "clientesActualizar": {
|
|
411
|
+
const nuevosDatos = this.getNodeParameter("cuerpoHTTP", 0);
|
|
382
412
|
try {
|
|
383
413
|
const updateCustomer = await (0, functions_1.apiRequest)(`${centumUrl}/Clientes/Actualizar`, {
|
|
384
|
-
method:
|
|
414
|
+
method: "POST",
|
|
385
415
|
body: nuevosDatos,
|
|
386
416
|
headers,
|
|
387
417
|
});
|
|
@@ -392,12 +422,12 @@ class Centum {
|
|
|
392
422
|
return [this.helpers.returnJsonArray([])];
|
|
393
423
|
}
|
|
394
424
|
}
|
|
395
|
-
case
|
|
396
|
-
const codigo = this.getNodeParameter(
|
|
397
|
-
const cuit = this.getNodeParameter(
|
|
398
|
-
const razonSocial = this.getNodeParameter(
|
|
425
|
+
case "clientesBusqueda": {
|
|
426
|
+
const codigo = this.getNodeParameter("codigo", 0, "");
|
|
427
|
+
const cuit = this.getNodeParameter("cuit", 0, "");
|
|
428
|
+
const razonSocial = this.getNodeParameter("razonSocial", 0, "");
|
|
399
429
|
if (!codigo && !cuit && !razonSocial) {
|
|
400
|
-
throw new n8n_workflow_1.NodeOperationError(this.getNode(),
|
|
430
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), "Debe proporcionar al menos un campo para la búsqueda (CUIT, Codigo o Razón Social).");
|
|
401
431
|
}
|
|
402
432
|
const queryParams = {};
|
|
403
433
|
if (cuit)
|
|
@@ -408,27 +438,28 @@ class Centum {
|
|
|
408
438
|
queryParams.RazonSocial = razonSocial;
|
|
409
439
|
try {
|
|
410
440
|
const response = await (0, functions_1.apiRequest)(`${centumUrl}/Clientes`, {
|
|
411
|
-
method:
|
|
441
|
+
method: "GET",
|
|
412
442
|
headers,
|
|
413
443
|
queryParams,
|
|
414
444
|
});
|
|
445
|
+
console.log(response);
|
|
415
446
|
return [this.helpers.returnJsonArray(response.Items)];
|
|
416
447
|
}
|
|
417
448
|
catch (error) {
|
|
418
449
|
console.log(`[ClientesBusqueda] Error:`, error);
|
|
419
|
-
const errorMessage = error?.response?.data?.Message || error.message ||
|
|
450
|
+
const errorMessage = error?.response?.data?.Message || error.message || "Error desconocido";
|
|
420
451
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), errorMessage);
|
|
421
452
|
}
|
|
422
453
|
}
|
|
423
|
-
case
|
|
424
|
-
const cuit = this.getNodeParameter(
|
|
454
|
+
case "clientesBusquedaPorCuit": {
|
|
455
|
+
const cuit = this.getNodeParameter("cuit", 0, "");
|
|
425
456
|
if (!cuit) {
|
|
426
|
-
throw new n8n_workflow_1.NodeOperationError(this.getNode(),
|
|
457
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), "Debe proporcionar CUIT para buscar clientes.");
|
|
427
458
|
}
|
|
428
459
|
const queryParams = { Cuit: cuit };
|
|
429
460
|
try {
|
|
430
461
|
const response = await (0, functions_1.apiRequest)(`${centumUrl}/Clientes`, {
|
|
431
|
-
method:
|
|
462
|
+
method: "GET",
|
|
432
463
|
headers,
|
|
433
464
|
queryParams,
|
|
434
465
|
});
|
|
@@ -436,18 +467,18 @@ class Centum {
|
|
|
436
467
|
}
|
|
437
468
|
catch (error) {
|
|
438
469
|
console.log(`[ClientesBusquedaPorCuit] Error:`, error);
|
|
439
|
-
const errorMessage = error?.response?.data?.Message || error.message ||
|
|
470
|
+
const errorMessage = error?.response?.data?.Message || error.message || "Error desconocido";
|
|
440
471
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), errorMessage);
|
|
441
472
|
}
|
|
442
473
|
}
|
|
443
|
-
case
|
|
444
|
-
const ordenCliente = this.getNodeParameter(
|
|
445
|
-
const ordenArticulo = this.getNodeParameter(
|
|
446
|
-
const ordenEnvio = this.getNodeParameter(
|
|
474
|
+
case "cobros": {
|
|
475
|
+
const ordenCliente = this.getNodeParameter("cliente", 0);
|
|
476
|
+
const ordenArticulo = this.getNodeParameter("articulo", 0);
|
|
477
|
+
const ordenEnvio = this.getNodeParameter("envio", 0);
|
|
447
478
|
const bodyCharge = (0, functions_1.createChargeJson)(ordenCliente, ordenArticulo, ordenEnvio);
|
|
448
479
|
try {
|
|
449
480
|
const dataCobros = await (0, functions_1.apiRequest)(`${centumUrl}/Cobros`, {
|
|
450
|
-
method:
|
|
481
|
+
method: "POST",
|
|
451
482
|
body: bodyCharge,
|
|
452
483
|
headers,
|
|
453
484
|
});
|
|
@@ -455,17 +486,17 @@ class Centum {
|
|
|
455
486
|
}
|
|
456
487
|
catch (error) {
|
|
457
488
|
console.log(error);
|
|
458
|
-
const errorMessage = error?.response?.data?.Message || error.message ||
|
|
489
|
+
const errorMessage = error?.response?.data?.Message || error.message || "Error desconocido";
|
|
459
490
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), errorMessage);
|
|
460
491
|
}
|
|
461
492
|
}
|
|
462
|
-
case
|
|
463
|
-
const clientIdParam = this.getNodeParameter(
|
|
464
|
-
const desdeSaldoFecha = this.getNodeParameter(
|
|
465
|
-
const separarFecha = String(desdeSaldoFecha).split(
|
|
493
|
+
case "composicionSaldoCliente": {
|
|
494
|
+
const clientIdParam = this.getNodeParameter("clienteId", 0);
|
|
495
|
+
const desdeSaldoFecha = this.getNodeParameter("priceDateModified", 0);
|
|
496
|
+
const separarFecha = String(desdeSaldoFecha).split("T")[0];
|
|
466
497
|
const clientId = Number(clientIdParam);
|
|
467
498
|
if (isNaN(clientId) || clientId <= 0) {
|
|
468
|
-
throw new n8n_workflow_1.NodeOperationError(this.getNode(),
|
|
499
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), "clienteId debe ser un número positivo");
|
|
469
500
|
}
|
|
470
501
|
try {
|
|
471
502
|
let url = `${centumUrl}/SaldosCuentasCorrientes/Composicion/${clientId}`;
|
|
@@ -473,29 +504,29 @@ class Centum {
|
|
|
473
504
|
url += `?fechaVencimientoHasta=${separarFecha}`;
|
|
474
505
|
}
|
|
475
506
|
const response = await (0, functions_1.apiRequest)(url, {
|
|
476
|
-
method:
|
|
507
|
+
method: "GET",
|
|
477
508
|
headers,
|
|
478
509
|
});
|
|
479
|
-
if (!response || typeof response !==
|
|
480
|
-
throw new n8n_workflow_1.NodeOperationError(this.getNode(),
|
|
510
|
+
if (!response || typeof response !== "object") {
|
|
511
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), "Respuesta inválida del servidor");
|
|
481
512
|
}
|
|
482
513
|
return [this.helpers.returnJsonArray(response)];
|
|
483
514
|
}
|
|
484
515
|
catch (error) {
|
|
485
|
-
const errorMessage = error?.response?.data?.Message || error.message ||
|
|
516
|
+
const errorMessage = error?.response?.data?.Message || error.message || "Error desconocido";
|
|
486
517
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Error obteniendo composición de saldo para cliente ${clientId}: ${errorMessage}`);
|
|
487
518
|
}
|
|
488
519
|
}
|
|
489
|
-
case
|
|
490
|
-
const customerSalesOrder = this.getNodeParameter(
|
|
491
|
-
const articlesSalesOrder = this.getNodeParameter(
|
|
492
|
-
const shippingSalesOrder = this.getNodeParameter(
|
|
493
|
-
const idCobro = this.getNodeParameter(
|
|
520
|
+
case "crearPedidoVenta": {
|
|
521
|
+
const customerSalesOrder = this.getNodeParameter("cliente", 0);
|
|
522
|
+
const articlesSalesOrder = this.getNodeParameter("articulo", 0);
|
|
523
|
+
const shippingSalesOrder = this.getNodeParameter("envio", 0);
|
|
524
|
+
const idCobro = this.getNodeParameter("idCobro", 0);
|
|
494
525
|
const date = new Date().toISOString();
|
|
495
|
-
const formattedDate = date.replace(/\..+/,
|
|
526
|
+
const formattedDate = date.replace(/\..+/, "");
|
|
496
527
|
try {
|
|
497
528
|
const arrArticles = await (0, functions_1.apiRequest)(`${centumUrl}/Articulos/Venta`, {
|
|
498
|
-
method:
|
|
529
|
+
method: "POST",
|
|
499
530
|
headers,
|
|
500
531
|
body: {
|
|
501
532
|
idCliente: 1,
|
|
@@ -511,7 +542,7 @@ class Centum {
|
|
|
511
542
|
CentumSuiteAccessToken: centumSuiteAccessTokenSalesOrder,
|
|
512
543
|
};
|
|
513
544
|
const dataPedidosVenta = await (0, functions_1.apiRequest)(`${centumUrl}/PedidosVenta`, {
|
|
514
|
-
method:
|
|
545
|
+
method: "POST",
|
|
515
546
|
headers: headersSalesOrder,
|
|
516
547
|
body: bodyPedidoVenta,
|
|
517
548
|
});
|
|
@@ -519,20 +550,20 @@ class Centum {
|
|
|
519
550
|
return [this.helpers.returnJsonArray(dataPedidosVenta)];
|
|
520
551
|
}
|
|
521
552
|
catch (error) {
|
|
522
|
-
console.log(
|
|
523
|
-
const errorMessage = error?.response?.data?.Message || error.message ||
|
|
553
|
+
console.log("Error creating sales order:", error);
|
|
554
|
+
const errorMessage = error?.response?.data?.Message || error.message || "Error desconocido";
|
|
524
555
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), errorMessage);
|
|
525
556
|
}
|
|
526
557
|
}
|
|
527
|
-
case
|
|
528
|
-
const idProvincia = this.getNodeParameter(
|
|
558
|
+
case "departamentosLista": {
|
|
559
|
+
const idProvincia = this.getNodeParameter("idProvincia", 0, "");
|
|
529
560
|
try {
|
|
530
561
|
const queryParams = {};
|
|
531
562
|
if (idProvincia) {
|
|
532
563
|
queryParams.idProvincia = idProvincia;
|
|
533
564
|
}
|
|
534
565
|
const departamentos = await (0, functions_1.apiRequest)(`${centumUrl}/Departamentos`, {
|
|
535
|
-
method:
|
|
566
|
+
method: "GET",
|
|
536
567
|
headers,
|
|
537
568
|
queryParams,
|
|
538
569
|
});
|
|
@@ -540,31 +571,31 @@ class Centum {
|
|
|
540
571
|
}
|
|
541
572
|
catch (error) {
|
|
542
573
|
console.log(error);
|
|
543
|
-
const errorMessage = error?.response?.data?.Message || error.message ||
|
|
574
|
+
const errorMessage = error?.response?.data?.Message || error.message || "Error desconocido";
|
|
544
575
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), errorMessage);
|
|
545
576
|
}
|
|
546
577
|
}
|
|
547
|
-
case
|
|
578
|
+
case "generarProductosWoo": {
|
|
548
579
|
const data = this.getInputData();
|
|
549
580
|
const json = (0, functions_1.createJsonProducts)(data);
|
|
550
581
|
return [this.helpers.returnJsonArray(json)];
|
|
551
582
|
}
|
|
552
|
-
case
|
|
553
|
-
const nombreTipoComprobante = this.getNodeParameter(
|
|
554
|
-
const codigoComprobante = this.getNodeParameter(
|
|
555
|
-
const idTipoComprobante = this.getNodeParameter(
|
|
556
|
-
const numeroDocumento = this.getNodeParameter(
|
|
557
|
-
const puntoVenta = this.getNodeParameter(
|
|
558
|
-
const letraDocumento = this.getNodeParameter(
|
|
559
|
-
const fechaDocumento = this.getNodeParameter(
|
|
560
|
-
const sucursalFisica = this.getNodeParameter(
|
|
561
|
-
const articulosArray = this.getNodeParameter(
|
|
562
|
-
const idCliente = this.getNodeParameter(
|
|
563
|
-
const idProveedor = this.getNodeParameter(
|
|
564
|
-
const fechaProducto = this.getNodeParameter(
|
|
565
|
-
const separarFecha = String(fechaProducto).split(
|
|
566
|
-
const ids = articulosArray.map(a => a.ID);
|
|
567
|
-
const qtyById = Object.fromEntries(articulosArray.map(a => [a.ID, a.Cantidad]));
|
|
583
|
+
case "generarCompras": {
|
|
584
|
+
const nombreTipoComprobante = this.getNodeParameter("nombreTipoComprobante", 0, "");
|
|
585
|
+
const codigoComprobante = this.getNodeParameter("codigoComprobante", 0, "");
|
|
586
|
+
const idTipoComprobante = this.getNodeParameter("idTipoComprobante", 0);
|
|
587
|
+
const numeroDocumento = this.getNodeParameter("numeroFactura", 0);
|
|
588
|
+
const puntoVenta = this.getNodeParameter("puntoDeVenta", 0);
|
|
589
|
+
const letraDocumento = this.getNodeParameter("letraDocumento", 0, "");
|
|
590
|
+
const fechaDocumento = this.getNodeParameter("fechaFactura", 0, "");
|
|
591
|
+
const sucursalFisica = this.getNodeParameter("idSucursalFisica", 0);
|
|
592
|
+
const articulosArray = this.getNodeParameter("articlesCollection", 0);
|
|
593
|
+
const idCliente = this.getNodeParameter("clienteId", 0);
|
|
594
|
+
const idProveedor = this.getNodeParameter("idProveedor", 0);
|
|
595
|
+
const fechaProducto = this.getNodeParameter("startDate", 0);
|
|
596
|
+
const separarFecha = String(fechaProducto).split("T")[0];
|
|
597
|
+
const ids = articulosArray.map((a) => a.ID);
|
|
598
|
+
const qtyById = Object.fromEntries(articulosArray.map((a) => [a.ID, a.Cantidad]));
|
|
568
599
|
let bodyProveedor;
|
|
569
600
|
const bodyCompraArticulos = {
|
|
570
601
|
IdCliente: idCliente,
|
|
@@ -573,32 +604,29 @@ class Centum {
|
|
|
573
604
|
};
|
|
574
605
|
try {
|
|
575
606
|
const fetchProveedor = await (0, functions_1.apiRequest)(`${centumUrl}/Proveedores/${idProveedor}`, {
|
|
576
|
-
method:
|
|
607
|
+
method: "GET",
|
|
577
608
|
headers,
|
|
578
609
|
});
|
|
579
610
|
bodyProveedor = fetchProveedor;
|
|
580
611
|
}
|
|
581
612
|
catch (error) {
|
|
582
|
-
const errorMessage = error?.response?.data?.Message || error.message ||
|
|
613
|
+
const errorMessage = error?.response?.data?.Message || error.message || "Error desconocido";
|
|
583
614
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Error obteniendo el proveedor.\n ${errorMessage}`);
|
|
584
615
|
}
|
|
585
616
|
let articulosVenta;
|
|
586
617
|
try {
|
|
587
618
|
articulosVenta = await (0, functions_1.apiRequest)(`${centumUrl}/Articulos/Venta`, {
|
|
588
|
-
method:
|
|
619
|
+
method: "POST",
|
|
589
620
|
body: bodyCompraArticulos,
|
|
590
621
|
headers,
|
|
591
622
|
});
|
|
592
623
|
}
|
|
593
624
|
catch (error) {
|
|
594
|
-
const errorMessage = error?.response?.data?.Message || error.message ||
|
|
625
|
+
const errorMessage = error?.response?.data?.Message || error.message || "Error desconocido";
|
|
595
626
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Error al obtener la informacion de los articulos ${errorMessage}`);
|
|
596
627
|
}
|
|
597
|
-
const ventaObj = typeof articulosVenta ===
|
|
598
|
-
const itemsRespuesta = ventaObj?.Articulos?.Items ??
|
|
599
|
-
ventaObj?.CompraArticulos ??
|
|
600
|
-
ventaObj?.Items ??
|
|
601
|
-
[];
|
|
628
|
+
const ventaObj = typeof articulosVenta === "string" ? JSON.parse(articulosVenta) : articulosVenta;
|
|
629
|
+
const itemsRespuesta = ventaObj?.Articulos?.Items ?? ventaObj?.CompraArticulos ?? ventaObj?.Items ?? [];
|
|
602
630
|
const compraConCantidad = itemsRespuesta.map((art) => ({
|
|
603
631
|
...art,
|
|
604
632
|
Cantidad: qtyById[String(art.IdArticulo)] ?? 0,
|
|
@@ -623,162 +651,284 @@ class Centum {
|
|
|
623
651
|
};
|
|
624
652
|
try {
|
|
625
653
|
const response = await (0, functions_1.apiRequest)(`${centumUrl}/Compras`, {
|
|
626
|
-
method:
|
|
654
|
+
method: "POST",
|
|
627
655
|
headers,
|
|
628
656
|
body: finalBody,
|
|
629
657
|
});
|
|
630
658
|
return [this.helpers.returnJsonArray(response)];
|
|
631
659
|
}
|
|
632
660
|
catch (error) {
|
|
633
|
-
const errorMessage = error?.response?.data?.Message || error.message ||
|
|
661
|
+
const errorMessage = error?.response?.data?.Message || error.message || "Error desconocido";
|
|
634
662
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Error creando la compra.\n ${errorMessage}`);
|
|
635
663
|
}
|
|
636
664
|
}
|
|
637
|
-
case
|
|
665
|
+
case "generarToken": {
|
|
638
666
|
try {
|
|
639
667
|
const tokenGenerado = (0, functions_1.createHash)(headers.publicAccessKey);
|
|
640
668
|
return [this.helpers.returnJsonArray(tokenGenerado)];
|
|
641
669
|
}
|
|
642
670
|
catch (error) {
|
|
643
671
|
console.log(error);
|
|
644
|
-
const errorMessage = error?.response?.data?.Message || error.message ||
|
|
672
|
+
const errorMessage = error?.response?.data?.Message || error.message || "Error desconocido";
|
|
645
673
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), errorMessage);
|
|
646
674
|
}
|
|
647
675
|
}
|
|
648
|
-
case
|
|
676
|
+
case "generarVentas": {
|
|
677
|
+
const numeroPuntoDeVenta = this.getNodeParameter("puntoDeVenta", 0);
|
|
678
|
+
const bonificacion = this.getNodeParameter("bonificacion", 0, "");
|
|
679
|
+
const esContado = this.getNodeParameter("esContado", 0);
|
|
680
|
+
const idCliente = this.getNodeParameter("clienteId", 0);
|
|
681
|
+
const condicionVentaId = this.getNodeParameter("idCondicionVenta", 0);
|
|
682
|
+
const tipoComprobanteVenta = this.getNodeParameter("idTipoComprobanteVenta", 0);
|
|
683
|
+
const idVendedor = this.getNodeParameter("idVendedor", 0);
|
|
684
|
+
const preciosListaId = this.getNodeParameter("idList", 0);
|
|
685
|
+
const articlesCollectionRaw = this.getNodeParameter("articlesCollection", 0, "");
|
|
686
|
+
let articulosArray = [];
|
|
687
|
+
try {
|
|
688
|
+
articulosArray = JSON.parse(articlesCollectionRaw);
|
|
689
|
+
if (!Array.isArray(articulosArray)) {
|
|
690
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), "El campo articlesCollection debe ser un array JSON válido.");
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
catch (err) {
|
|
694
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `El campo articlesCollection debe ser un JSON string válido. Ejemplo:[{"ID":"1450","Cantidad":2},{"ID":"1451","Cantidad":5}] Error: ${err?.message ?? String(err)}`);
|
|
695
|
+
}
|
|
696
|
+
const fechaDesde = this.getNodeParameter("startDate", 0, "");
|
|
697
|
+
const separarFechaDesde = String(fechaDesde).split("T")[0];
|
|
698
|
+
const idValorEfectivo = this.getNodeParameter("idValorEfectivo", 0, null);
|
|
699
|
+
const cotizacionValorEfectivo = this.getNodeParameter("cotizacionValorEfectivo", 0, null);
|
|
700
|
+
const importeValorEfectivo = this.getNodeParameter("importeValorEfectivo", 0, null);
|
|
701
|
+
const observacionesValorEfectivo = this.getNodeParameter("observacionesValorEfectivo", 0, "");
|
|
702
|
+
const cantidadCuotasValorEfectivo = this.getNodeParameter("cantidadCuotasValorEfectivo", 0, null);
|
|
703
|
+
if (!numeroPuntoDeVenta)
|
|
704
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), "El punto de venta es obligatorio.");
|
|
705
|
+
if (!tipoComprobanteVenta)
|
|
706
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), "El tipo de comprobante de venta es obligatorio.");
|
|
707
|
+
if (!idCliente)
|
|
708
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), "El IdCliente es obligatorio.");
|
|
709
|
+
if (!preciosListaId)
|
|
710
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), "El IdListaPrecio es obligatorio.");
|
|
711
|
+
if (!articulosArray?.length)
|
|
712
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), "Debes enviar al menos un artículo en articlesCollection.");
|
|
713
|
+
if (esContado === true) {
|
|
714
|
+
if (idValorEfectivo == null)
|
|
715
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), "IdValor (efectivo) es obligatorio cuando EsContado = true.");
|
|
716
|
+
if (importeValorEfectivo == null)
|
|
717
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), "Importe (efectivo) es obligatorio cuando EsContado = true.");
|
|
718
|
+
}
|
|
719
|
+
const ids = articulosArray.map((a) => a.ID);
|
|
720
|
+
const qtyById = Object.fromEntries(articulosArray.map((a) => [a.ID, a.Cantidad]));
|
|
721
|
+
let ventaItemsConCantidad = [];
|
|
722
|
+
try {
|
|
723
|
+
const bodyArticulosVenta = {
|
|
724
|
+
IdCliente: idCliente,
|
|
725
|
+
FechaDocumento: separarFechaDesde,
|
|
726
|
+
Ids: ids,
|
|
727
|
+
};
|
|
728
|
+
let articulosVenta = await (0, functions_1.apiRequest)(`${centumUrl}/Articulos/Venta`, {
|
|
729
|
+
headers,
|
|
730
|
+
method: "POST",
|
|
731
|
+
body: bodyArticulosVenta,
|
|
732
|
+
});
|
|
733
|
+
const ventaObj = typeof articulosVenta === "string" ? JSON.parse(articulosVenta) : articulosVenta;
|
|
734
|
+
const itemsRespuesta = ventaObj?.Articulos?.Items ?? ventaObj?.VentaArticulos ?? ventaObj?.Items ?? [];
|
|
735
|
+
ventaItemsConCantidad = itemsRespuesta.map((art) => ({
|
|
736
|
+
...art,
|
|
737
|
+
Cantidad: qtyById[String(art.IdArticulo)] ?? 0,
|
|
738
|
+
}));
|
|
739
|
+
console.log(ventaItemsConCantidad);
|
|
740
|
+
}
|
|
741
|
+
catch (error) {
|
|
742
|
+
const errorMessage = error?.response?.data?.Message || error.message || "Error desconocido";
|
|
743
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Error obteniendo los artículos de venta.\n${errorMessage}`);
|
|
744
|
+
}
|
|
745
|
+
const bodyVenta = {
|
|
746
|
+
NumeroDocumento: { PuntoVenta: Number(numeroPuntoDeVenta) },
|
|
747
|
+
EsContado: Boolean(esContado),
|
|
748
|
+
Cliente: { IdCliente: Number(idCliente) },
|
|
749
|
+
CondicionVenta: { IdCondicionVenta: Number(condicionVentaId) },
|
|
750
|
+
Observaciones: "Venta desde API",
|
|
751
|
+
TipoComprobanteVenta: { IdTipoComprobanteVenta: Number(tipoComprobanteVenta) },
|
|
752
|
+
Vendedor: { IdVendedor: Number(idVendedor) },
|
|
753
|
+
ListaPrecio: { IdListaPrecio: Number(preciosListaId) },
|
|
754
|
+
VentaArticulos: ventaItemsConCantidad,
|
|
755
|
+
PorcentajeDescuento: 0,
|
|
756
|
+
};
|
|
757
|
+
if (bonificacion) {
|
|
758
|
+
bodyVenta.Bonificacion = { IdBonificacion: bonificacion };
|
|
759
|
+
}
|
|
760
|
+
if (esContado === true) {
|
|
761
|
+
const cotizacion = !cotizacionValorEfectivo || cotizacionValorEfectivo <= 0 ? 1 : Number(cotizacionValorEfectivo);
|
|
762
|
+
const cuotas = !cantidadCuotasValorEfectivo || cantidadCuotasValorEfectivo <= 0 ? 1 : Number(cantidadCuotasValorEfectivo);
|
|
763
|
+
bodyVenta.VentaValoresEfectivos = [
|
|
764
|
+
{
|
|
765
|
+
IdValor: Number(idValorEfectivo),
|
|
766
|
+
Cotizacion: cotizacion,
|
|
767
|
+
Importe: Number(importeValorEfectivo),
|
|
768
|
+
Observaciones: observacionesValorEfectivo || "",
|
|
769
|
+
CantidadCuotas: cuotas,
|
|
770
|
+
},
|
|
771
|
+
];
|
|
772
|
+
}
|
|
773
|
+
try {
|
|
774
|
+
const url = `${centumUrl}/Ventas?verificaLimiteCreditoCliente=false&verificaStockNegativo=false&verificaCuotificador=false`;
|
|
775
|
+
const response = await (0, functions_1.apiRequest)(url, {
|
|
776
|
+
method: "POST",
|
|
777
|
+
headers,
|
|
778
|
+
body: bodyVenta,
|
|
779
|
+
});
|
|
780
|
+
return [this.helpers.returnJsonArray(response)];
|
|
781
|
+
}
|
|
782
|
+
catch (error) {
|
|
783
|
+
const errorMessage = error?.response?.data?.Message || error.message || "Error desconocido";
|
|
784
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Error creando la venta.\n${errorMessage}`);
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
case "listaPrecios": {
|
|
649
788
|
try {
|
|
650
789
|
const response = await (0, functions_1.apiRequest)(`${centumUrl}/ListasPrecios`, {
|
|
651
|
-
method:
|
|
790
|
+
method: "GET",
|
|
652
791
|
headers,
|
|
653
792
|
});
|
|
654
793
|
return [this.helpers.returnJsonArray(response)];
|
|
655
794
|
}
|
|
656
795
|
catch (error) {
|
|
657
|
-
console.log(
|
|
658
|
-
const errorMessage = error?.response?.data?.Message || error.message ||
|
|
796
|
+
console.log("Error en solicitud de promociones para el cliente:", error);
|
|
797
|
+
const errorMessage = error?.response?.data?.Message || error.message || "Error desconocido";
|
|
659
798
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Error obteniendo el listado de precios. \n ${errorMessage}`);
|
|
660
799
|
}
|
|
661
800
|
}
|
|
662
|
-
case
|
|
663
|
-
|
|
664
|
-
|
|
801
|
+
case "marcasObtener": {
|
|
802
|
+
try {
|
|
803
|
+
const response = await (0, functions_1.apiRequest)(`${centumUrl}/MarcasArticulo`, {
|
|
804
|
+
method: 'GET',
|
|
805
|
+
headers
|
|
806
|
+
});
|
|
807
|
+
return [this.helpers.returnJsonArray(response)];
|
|
808
|
+
}
|
|
809
|
+
catch (error) {
|
|
810
|
+
console.log("Error en obtener el listado de marcas:", error);
|
|
811
|
+
const errorMessage = error?.response?.data?.Message || error.message || "Error desconocido";
|
|
812
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Error en obtener el listado de marcas. \n ${errorMessage}`);
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
case "nuevoContribuyente": {
|
|
816
|
+
const bodyJson = this.getNodeParameter("cuerpoHTTP", 0);
|
|
817
|
+
const cuit = this.getNodeParameter("cuit", 0);
|
|
665
818
|
console.log(bodyJson);
|
|
666
|
-
if (typeof cuit !==
|
|
667
|
-
throw new n8n_workflow_1.NodeOperationError(this.getNode(),
|
|
819
|
+
if (typeof cuit !== "string" || !/^\d{11}$/.test(cuit)) {
|
|
820
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), "El CUIT debe ser una cadena de 11 dígitos numéricos.");
|
|
668
821
|
}
|
|
669
822
|
const contribuyenteJSON = (0, functions_1.createContribuyenteJson)(bodyJson, cuit);
|
|
670
823
|
try {
|
|
671
824
|
const crearCliente = await (0, functions_1.apiRequest)(`${centumUrl}/Clientes`, {
|
|
672
|
-
method:
|
|
825
|
+
method: "POST",
|
|
673
826
|
body: contribuyenteJSON,
|
|
674
827
|
headers,
|
|
675
828
|
});
|
|
676
|
-
console.log(
|
|
829
|
+
console.log("Contribuyente creado:", crearCliente);
|
|
677
830
|
return [this.helpers.returnJsonArray([crearCliente])];
|
|
678
831
|
}
|
|
679
832
|
catch (error) {
|
|
680
|
-
console.error(
|
|
833
|
+
console.error("Error al crear contribuyente:", error);
|
|
681
834
|
const statusCode = error?.response?.status;
|
|
682
835
|
const responseData = error?.response?.data;
|
|
683
|
-
const errorMessage = responseData?.Message ||
|
|
684
|
-
responseData?.message ||
|
|
685
|
-
error?.message ||
|
|
686
|
-
'Error desconocido al crear el contribuyente.';
|
|
836
|
+
const errorMessage = responseData?.Message || responseData?.message || error?.message || "Error desconocido al crear el contribuyente.";
|
|
687
837
|
const fullMessage = statusCode ? `Error ${statusCode}: ${errorMessage}` : errorMessage;
|
|
688
838
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), fullMessage, {
|
|
689
|
-
description: responseData?.Detail ||
|
|
839
|
+
description: responseData?.Detail || "Ocurrió un error inesperado al llamar a la API de Centum.",
|
|
690
840
|
});
|
|
691
841
|
}
|
|
692
842
|
}
|
|
693
|
-
case
|
|
694
|
-
const idCliente = this.getNodeParameter(
|
|
695
|
-
const idCobro = this.getNodeParameter(
|
|
696
|
-
const fechaDesde = this.getNodeParameter(
|
|
697
|
-
const fechaHasta = this.getNodeParameter(
|
|
698
|
-
const separarFechaDesde = String(fechaDesde).split(
|
|
699
|
-
const separarFechaHasta = String(fechaHasta).split(
|
|
843
|
+
case "obtenerCobros": {
|
|
844
|
+
const idCliente = this.getNodeParameter("clienteId", 0);
|
|
845
|
+
const idCobro = this.getNodeParameter("idCobro", 0);
|
|
846
|
+
const fechaDesde = this.getNodeParameter("startDate", 0, "");
|
|
847
|
+
const fechaHasta = this.getNodeParameter("endDate", 0, "");
|
|
848
|
+
const separarFechaDesde = String(fechaDesde).split("T")[0];
|
|
849
|
+
const separarFechaHasta = String(fechaHasta).split("T")[0];
|
|
700
850
|
if (!idCliente && !separarFechaDesde && !separarFechaHasta && !idCobro) {
|
|
701
|
-
throw new n8n_workflow_1.NodeOperationError(this.getNode(),
|
|
851
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), "Debes ingresar almenos un parametro para realizar la búsqueda.");
|
|
702
852
|
}
|
|
703
853
|
const body = {
|
|
704
854
|
idCliente,
|
|
705
855
|
fechaDocumentoDesde: separarFechaDesde,
|
|
706
856
|
fechaDocumentoHasta: separarFechaHasta,
|
|
707
|
-
idCobro
|
|
857
|
+
idCobro,
|
|
708
858
|
};
|
|
709
859
|
try {
|
|
710
860
|
const response = await (0, functions_1.apiRequest)(`${centumUrl}/Cobros/FiltrosCobro`, {
|
|
711
|
-
method:
|
|
861
|
+
method: "POST",
|
|
712
862
|
headers,
|
|
713
|
-
body
|
|
863
|
+
body,
|
|
714
864
|
});
|
|
715
865
|
return [this.helpers.returnJsonArray(response)];
|
|
716
866
|
}
|
|
717
867
|
catch (error) {
|
|
718
|
-
console.log(
|
|
719
|
-
const errorMessage = error?.response?.data?.Message || error.message ||
|
|
868
|
+
console.log("Error en obtener el listado de cobros:", error);
|
|
869
|
+
const errorMessage = error?.response?.data?.Message || error.message || "Error desconocido";
|
|
720
870
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Error en obtener el listado de cobros para cliente ${idCliente}: ${errorMessage}`);
|
|
721
871
|
}
|
|
722
872
|
}
|
|
723
|
-
case
|
|
724
|
-
const idCliente = this.getNodeParameter(
|
|
725
|
-
const idCompra = this.getNodeParameter(
|
|
726
|
-
const fechaDesde = this.getNodeParameter(
|
|
727
|
-
const fechaHasta = this.getNodeParameter(
|
|
728
|
-
const separarFechaDesde = String(fechaDesde).split(
|
|
729
|
-
const separarFechaHasta = String(fechaHasta).split(
|
|
873
|
+
case "obtenerCompras": {
|
|
874
|
+
const idCliente = this.getNodeParameter("clienteId", 0);
|
|
875
|
+
const idCompra = this.getNodeParameter("idCompra", 0);
|
|
876
|
+
const fechaDesde = this.getNodeParameter("startDate", 0, "");
|
|
877
|
+
const fechaHasta = this.getNodeParameter("endDate", 0, "");
|
|
878
|
+
const separarFechaDesde = String(fechaDesde).split("T")[0];
|
|
879
|
+
const separarFechaHasta = String(fechaHasta).split("T")[0];
|
|
730
880
|
if (!idCliente && !separarFechaDesde && !separarFechaHasta && !idCompra) {
|
|
731
|
-
throw new n8n_workflow_1.NodeOperationError(this.getNode(),
|
|
881
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), "Debes ingresar almenos un parametro para realizar la búsqueda.");
|
|
732
882
|
}
|
|
733
883
|
const body = {
|
|
734
884
|
idCliente,
|
|
735
885
|
fechaDocumentoDesde: separarFechaDesde,
|
|
736
886
|
fechaDocumentoHasta: separarFechaHasta,
|
|
737
|
-
idCompra
|
|
887
|
+
idCompra,
|
|
738
888
|
};
|
|
739
889
|
try {
|
|
740
890
|
const response = await (0, functions_1.apiRequest)(`${centumUrl}/Compras/FiltrosCompra`, {
|
|
741
|
-
method:
|
|
891
|
+
method: "POST",
|
|
742
892
|
headers,
|
|
743
|
-
body
|
|
893
|
+
body,
|
|
744
894
|
});
|
|
745
895
|
return [this.helpers.returnJsonArray(response)];
|
|
746
896
|
}
|
|
747
897
|
catch (error) {
|
|
748
|
-
console.log(
|
|
749
|
-
const errorMessage = error?.response?.data?.Message || error.message ||
|
|
898
|
+
console.log("Error en obtener el listado de cobros:", error);
|
|
899
|
+
const errorMessage = error?.response?.data?.Message || error.message || "Error desconocido";
|
|
750
900
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Error en obtener el listado de cobros para cliente ${idCliente}: ${errorMessage}`);
|
|
751
901
|
}
|
|
752
902
|
}
|
|
753
|
-
case
|
|
903
|
+
case "obtenerEstadosPedidosDeVenta": {
|
|
754
904
|
try {
|
|
755
905
|
const response = await (0, functions_1.apiRequest)(`${centumUrl}/EstadosPedidoVenta?bIncluirTodosEstados=true`, {
|
|
756
|
-
method:
|
|
757
|
-
headers
|
|
906
|
+
method: "GET",
|
|
907
|
+
headers,
|
|
758
908
|
});
|
|
759
909
|
return [this.helpers.returnJsonArray(response)];
|
|
760
910
|
}
|
|
761
911
|
catch (error) {
|
|
762
912
|
console.log(error);
|
|
763
|
-
const errorMessage = error?.response?.data?.Message || error.message ||
|
|
913
|
+
const errorMessage = error?.response?.data?.Message || error.message || "Error desconocido";
|
|
764
914
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), errorMessage);
|
|
765
915
|
}
|
|
766
916
|
}
|
|
767
|
-
case
|
|
768
|
-
const clientIdParam = this.getNodeParameter(
|
|
769
|
-
const desdeSaldoFecha = this.getNodeParameter(
|
|
770
|
-
const hastaSaldoFecha = this.getNodeParameter(
|
|
771
|
-
const separarFechaDesde = String(desdeSaldoFecha).split(
|
|
772
|
-
const separarFechaHasta = String(hastaSaldoFecha).split(
|
|
917
|
+
case "obtenerFacturasCobros": {
|
|
918
|
+
const clientIdParam = this.getNodeParameter("clienteId", 0);
|
|
919
|
+
const desdeSaldoFecha = this.getNodeParameter("startDate", 0);
|
|
920
|
+
const hastaSaldoFecha = this.getNodeParameter("endDate", 0);
|
|
921
|
+
const separarFechaDesde = String(desdeSaldoFecha).split("T")[0];
|
|
922
|
+
const separarFechaHasta = String(hastaSaldoFecha).split("T")[0];
|
|
773
923
|
const clientId = Number(clientIdParam);
|
|
774
924
|
if (isNaN(clientId) || clientId <= 0) {
|
|
775
|
-
throw new n8n_workflow_1.NodeOperationError(this.getNode(),
|
|
925
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), "clienteId debe ser un número positivo");
|
|
776
926
|
}
|
|
777
927
|
if (!desdeSaldoFecha) {
|
|
778
|
-
throw new n8n_workflow_1.NodeOperationError(this.getNode(),
|
|
928
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), "priceDateModified (fecha desde) es requerido");
|
|
779
929
|
}
|
|
780
930
|
if (!hastaSaldoFecha) {
|
|
781
|
-
throw new n8n_workflow_1.NodeOperationError(this.getNode(),
|
|
931
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), "priceDateModifiedSince (fecha hasta) es requerido");
|
|
782
932
|
}
|
|
783
933
|
try {
|
|
784
934
|
const body = {
|
|
@@ -787,36 +937,36 @@ class Centum {
|
|
|
787
937
|
IdCliente: clientId,
|
|
788
938
|
};
|
|
789
939
|
const response = await (0, functions_1.apiRequest)(`${centumUrl}/Cobros/FiltrosCobro`, {
|
|
790
|
-
method:
|
|
940
|
+
method: "POST",
|
|
791
941
|
headers,
|
|
792
942
|
body,
|
|
793
943
|
});
|
|
794
|
-
if (!response || typeof response !==
|
|
795
|
-
throw new n8n_workflow_1.NodeOperationError(this.getNode(),
|
|
944
|
+
if (!response || typeof response !== "object") {
|
|
945
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), "Respuesta inválida del servidor");
|
|
796
946
|
}
|
|
797
947
|
return [this.helpers.returnJsonArray(response)];
|
|
798
948
|
}
|
|
799
949
|
catch (error) {
|
|
800
|
-
console.log(
|
|
801
|
-
const errorMessage = error?.response?.data?.Message || error.message ||
|
|
950
|
+
console.log("Error en solicitud de facturas pedidos ventas:", error);
|
|
951
|
+
const errorMessage = error?.response?.data?.Message || error.message || "Error desconocido";
|
|
802
952
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Error obteniendo facturas pedidos ventas para cliente ${clientId}: ${errorMessage}`);
|
|
803
953
|
}
|
|
804
954
|
}
|
|
805
|
-
case
|
|
806
|
-
const clientIdParam = this.getNodeParameter(
|
|
807
|
-
const desdeSaldoFecha = this.getNodeParameter(
|
|
808
|
-
const hastaSaldoFecha = this.getNodeParameter(
|
|
809
|
-
const separarFechaDesde = String(desdeSaldoFecha).split(
|
|
810
|
-
const separarFechaHasta = String(hastaSaldoFecha).split(
|
|
955
|
+
case "obtenerFacturasPedidosVentas": {
|
|
956
|
+
const clientIdParam = this.getNodeParameter("clienteId", 0);
|
|
957
|
+
const desdeSaldoFecha = this.getNodeParameter("startDate", 0);
|
|
958
|
+
const hastaSaldoFecha = this.getNodeParameter("endDate", 0);
|
|
959
|
+
const separarFechaDesde = String(desdeSaldoFecha).split("T")[0];
|
|
960
|
+
const separarFechaHasta = String(hastaSaldoFecha).split("T")[0];
|
|
811
961
|
const clientId = Number(clientIdParam);
|
|
812
962
|
if (isNaN(clientId) || clientId <= 0) {
|
|
813
|
-
throw new n8n_workflow_1.NodeOperationError(this.getNode(),
|
|
963
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), "clienteId debe ser un número positivo");
|
|
814
964
|
}
|
|
815
965
|
if (!desdeSaldoFecha) {
|
|
816
|
-
throw new n8n_workflow_1.NodeOperationError(this.getNode(),
|
|
966
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), "priceDateModified (fecha desde) es requerido");
|
|
817
967
|
}
|
|
818
968
|
if (!hastaSaldoFecha) {
|
|
819
|
-
throw new n8n_workflow_1.NodeOperationError(this.getNode(),
|
|
969
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), "priceDateModifiedSince (fecha hasta) es requerido");
|
|
820
970
|
}
|
|
821
971
|
try {
|
|
822
972
|
const body = {
|
|
@@ -825,58 +975,58 @@ class Centum {
|
|
|
825
975
|
IdCliente: clientId,
|
|
826
976
|
};
|
|
827
977
|
const response = await (0, functions_1.apiRequest)(`${centumUrl}/Ventas/FiltrosVenta`, {
|
|
828
|
-
method:
|
|
978
|
+
method: "POST",
|
|
829
979
|
headers,
|
|
830
980
|
body,
|
|
831
981
|
});
|
|
832
|
-
if (!response || typeof response !==
|
|
833
|
-
throw new n8n_workflow_1.NodeOperationError(this.getNode(),
|
|
982
|
+
if (!response || typeof response !== "object") {
|
|
983
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), "Respuesta inválida del servidor");
|
|
834
984
|
}
|
|
835
985
|
return [this.helpers.returnJsonArray(response)];
|
|
836
986
|
}
|
|
837
987
|
catch (error) {
|
|
838
|
-
console.log(
|
|
839
|
-
const errorMessage = error?.response?.data?.Message || error.message ||
|
|
988
|
+
console.log("Error en solicitud de facturas pedidos ventas:", error);
|
|
989
|
+
const errorMessage = error?.response?.data?.Message || error.message || "Error desconocido";
|
|
840
990
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Error obteniendo facturas pedidos ventas para cliente ${clientId}: ${errorMessage}`);
|
|
841
991
|
}
|
|
842
992
|
}
|
|
843
|
-
case
|
|
844
|
-
const idCliente = this.getNodeParameter(
|
|
845
|
-
const idsEstado = this.getNodeParameter(
|
|
846
|
-
const fechaDesde = this.getNodeParameter(
|
|
847
|
-
const fechaHasta = this.getNodeParameter(
|
|
848
|
-
const separarFechaDesde = String(fechaDesde).split(
|
|
849
|
-
const separarFechaHasta = String(fechaHasta).split(
|
|
993
|
+
case "obtenerPedidosDeVenta": {
|
|
994
|
+
const idCliente = this.getNodeParameter("clienteId", 0);
|
|
995
|
+
const idsEstado = this.getNodeParameter("statusId", 0);
|
|
996
|
+
const fechaDesde = this.getNodeParameter("startDate", 0, "");
|
|
997
|
+
const fechaHasta = this.getNodeParameter("endDate", 0, "");
|
|
998
|
+
const separarFechaDesde = String(fechaDesde).split("T")[0];
|
|
999
|
+
const separarFechaHasta = String(fechaHasta).split("T")[0];
|
|
850
1000
|
if (!idCliente && !idsEstado && !separarFechaDesde && !separarFechaHasta) {
|
|
851
|
-
throw new n8n_workflow_1.NodeOperationError(this.getNode(),
|
|
1001
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), "Debes ingresar almenos un parametro para realizar la búsqueda.");
|
|
852
1002
|
}
|
|
853
1003
|
const body = {
|
|
854
1004
|
idCliente,
|
|
855
1005
|
fechaDocumentoDesde: separarFechaDesde,
|
|
856
1006
|
fechaDocumentoHasta: separarFechaHasta,
|
|
857
|
-
idsEstado
|
|
1007
|
+
idsEstado,
|
|
858
1008
|
};
|
|
859
1009
|
try {
|
|
860
1010
|
const response = await (0, functions_1.apiRequest)(`${centumUrl}/PedidosVenta/FiltrosPedidoVenta`, {
|
|
861
|
-
method:
|
|
1011
|
+
method: "POST",
|
|
862
1012
|
headers,
|
|
863
|
-
body
|
|
1013
|
+
body,
|
|
864
1014
|
});
|
|
865
1015
|
return [this.helpers.returnJsonArray(response)];
|
|
866
1016
|
}
|
|
867
1017
|
catch (error) {
|
|
868
|
-
console.log(
|
|
869
|
-
const errorMessage = error?.response?.data?.Message || error.message ||
|
|
1018
|
+
console.log("Error en solicitud de facturas pedidos ventas:", error);
|
|
1019
|
+
const errorMessage = error?.response?.data?.Message || error.message || "Error desconocido";
|
|
870
1020
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Error obteniendo los pedidos ventas para cliente ${idCliente}: ${errorMessage}`);
|
|
871
1021
|
}
|
|
872
1022
|
}
|
|
873
|
-
case
|
|
874
|
-
const clientIdParam = this.getNodeParameter(
|
|
875
|
-
const desdeSaldoFecha = this.getNodeParameter(
|
|
876
|
-
const soloFecha = String(desdeSaldoFecha).split(
|
|
1023
|
+
case "obtenerSaldoCliente": {
|
|
1024
|
+
const clientIdParam = this.getNodeParameter("clienteId", 0);
|
|
1025
|
+
const desdeSaldoFecha = this.getNodeParameter("priceDateModified", 0);
|
|
1026
|
+
const soloFecha = String(desdeSaldoFecha).split("T")[0];
|
|
877
1027
|
const clientId = Number(clientIdParam);
|
|
878
1028
|
if (isNaN(clientId) || clientId <= 0) {
|
|
879
|
-
throw new n8n_workflow_1.NodeOperationError(this.getNode(),
|
|
1029
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), "clienteId debe ser un número positivo");
|
|
880
1030
|
}
|
|
881
1031
|
try {
|
|
882
1032
|
let url = `${centumUrl}/SaldosCuentasCorrientes/${clientId}`;
|
|
@@ -884,50 +1034,50 @@ class Centum {
|
|
|
884
1034
|
url += `?fechaVencimientoHasta=${soloFecha}`;
|
|
885
1035
|
}
|
|
886
1036
|
const response = await (0, functions_1.apiRequest)(url, {
|
|
887
|
-
method:
|
|
1037
|
+
method: "GET",
|
|
888
1038
|
headers,
|
|
889
1039
|
});
|
|
890
1040
|
return [this.helpers.returnJsonArray(response)];
|
|
891
1041
|
}
|
|
892
1042
|
catch (error) {
|
|
893
|
-
const errorMessage = error?.response?.data?.Message || error.message ||
|
|
1043
|
+
const errorMessage = error?.response?.data?.Message || error.message || "Error desconocido";
|
|
894
1044
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Error obteniendo saldo para cliente ${clientId}: ${errorMessage}`);
|
|
895
1045
|
}
|
|
896
1046
|
}
|
|
897
|
-
case
|
|
898
|
-
const username = this.getNodeParameter(
|
|
899
|
-
const password = this.getNodeParameter(
|
|
1047
|
+
case "operadoresMoviles": {
|
|
1048
|
+
const username = this.getNodeParameter("username", 0, "");
|
|
1049
|
+
const password = this.getNodeParameter("password", 0, "");
|
|
900
1050
|
try {
|
|
901
1051
|
const operadoresActividad = await (0, functions_1.apiRequest)(`
|
|
902
1052
|
${centumUrl}/OperadoresMoviles/Credenciales?Usuario=${username}&Contrasena=${password}`, {
|
|
903
|
-
method:
|
|
904
|
-
headers
|
|
1053
|
+
method: "GET",
|
|
1054
|
+
headers,
|
|
905
1055
|
});
|
|
906
1056
|
return [this.helpers.returnJsonArray(operadoresActividad)];
|
|
907
1057
|
}
|
|
908
1058
|
catch (error) {
|
|
909
|
-
const errorMessage = error?.response?.data?.Message || error.message ||
|
|
1059
|
+
const errorMessage = error?.response?.data?.Message || error.message || "Error desconocido";
|
|
910
1060
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), errorMessage);
|
|
911
1061
|
}
|
|
912
1062
|
}
|
|
913
|
-
case
|
|
914
|
-
const pedidoID = this.getNodeParameter(
|
|
1063
|
+
case "pedidoVentaActividad": {
|
|
1064
|
+
const pedidoID = this.getNodeParameter("id", 0);
|
|
915
1065
|
try {
|
|
916
1066
|
const dataActividad = await (0, functions_1.apiRequest)(`${centumUrl}/PedidosVenta/${pedidoID}`, {
|
|
917
|
-
method:
|
|
918
|
-
headers
|
|
1067
|
+
method: "GET",
|
|
1068
|
+
headers,
|
|
919
1069
|
});
|
|
920
1070
|
return [this.helpers.returnJsonArray(dataActividad)];
|
|
921
1071
|
}
|
|
922
1072
|
catch (error) {
|
|
923
1073
|
console.log(error);
|
|
924
|
-
const errorMessage = error?.response?.data?.Message || error.message ||
|
|
1074
|
+
const errorMessage = error?.response?.data?.Message || error.message || "Error desconocido";
|
|
925
1075
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), errorMessage);
|
|
926
1076
|
}
|
|
927
1077
|
}
|
|
928
|
-
case
|
|
929
|
-
const dataImages = this.getNodeParameter(
|
|
930
|
-
const db = this.getNodeParameter(
|
|
1078
|
+
case "procesarImagenes": {
|
|
1079
|
+
const dataImages = this.getNodeParameter("dataImg", 0);
|
|
1080
|
+
const db = this.getNodeParameter("lastModifiedImg", 0);
|
|
931
1081
|
const result = [];
|
|
932
1082
|
for (let i = 0; i < dataImages.length; i++) {
|
|
933
1083
|
const element = dataImages[i];
|
|
@@ -951,28 +1101,28 @@ class Centum {
|
|
|
951
1101
|
}
|
|
952
1102
|
return [this.helpers.returnJsonArray(result)];
|
|
953
1103
|
}
|
|
954
|
-
case
|
|
955
|
-
const clientIdParam = this.getNodeParameter(
|
|
956
|
-
const documentDate = this.getNodeParameter(
|
|
957
|
-
const diaSemana = this.getNodeParameter(
|
|
1104
|
+
case "promocionesCliente": {
|
|
1105
|
+
const clientIdParam = this.getNodeParameter("clienteId", 0);
|
|
1106
|
+
const documentDate = this.getNodeParameter("documentDate", 0);
|
|
1107
|
+
const diaSemana = this.getNodeParameter("diaSemana", 0);
|
|
958
1108
|
const clientId = Number(clientIdParam);
|
|
959
1109
|
if (!documentDate) {
|
|
960
|
-
throw new n8n_workflow_1.NodeOperationError(this.getNode(),
|
|
1110
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), "documentDate es requerido");
|
|
961
1111
|
}
|
|
962
|
-
const formattedDocumentDate = String(documentDate).split(
|
|
1112
|
+
const formattedDocumentDate = String(documentDate).split("T")[0];
|
|
963
1113
|
try {
|
|
964
1114
|
const body = {
|
|
965
1115
|
FechaDocumento: formattedDocumentDate,
|
|
966
1116
|
IdsCliente: clientId,
|
|
967
|
-
DiaSemana: diaSemana ||
|
|
1117
|
+
DiaSemana: diaSemana || "",
|
|
968
1118
|
};
|
|
969
1119
|
const response = await (0, functions_1.apiRequest)(`${centumUrl}/PromocionesComerciales/FiltrosPromocionComercial`, {
|
|
970
|
-
method:
|
|
1120
|
+
method: "POST",
|
|
971
1121
|
headers,
|
|
972
1122
|
body,
|
|
973
1123
|
});
|
|
974
|
-
if (!response || typeof response !==
|
|
975
|
-
throw new n8n_workflow_1.NodeOperationError(this.getNode(),
|
|
1124
|
+
if (!response || typeof response !== "object") {
|
|
1125
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), "Respuesta inválida del servidor");
|
|
976
1126
|
}
|
|
977
1127
|
if (response.Items && Array.isArray(response.Items)) {
|
|
978
1128
|
return [this.helpers.returnJsonArray(response.Items)];
|
|
@@ -980,20 +1130,98 @@ class Centum {
|
|
|
980
1130
|
return [this.helpers.returnJsonArray(response)];
|
|
981
1131
|
}
|
|
982
1132
|
catch (error) {
|
|
983
|
-
console.log(
|
|
984
|
-
const errorMessage = error?.response?.data?.Message || error.message ||
|
|
1133
|
+
console.log("Error en solicitud de promociones para el cliente:", error);
|
|
1134
|
+
const errorMessage = error?.response?.data?.Message || error.message || "Error desconocido";
|
|
985
1135
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Error obteniendo promociones para el cliente ${clientId}: \n ${errorMessage}`);
|
|
986
1136
|
}
|
|
987
1137
|
}
|
|
988
|
-
case '
|
|
989
|
-
const
|
|
1138
|
+
case 'proveedorBuscar': {
|
|
1139
|
+
const proveedorId = this.getNodeParameter('proveedorId', 0);
|
|
1140
|
+
try {
|
|
1141
|
+
const response = await (0, functions_1.apiRequest)(`${centumUrl}/Proveedores/${proveedorId}`, {
|
|
1142
|
+
method: 'GET',
|
|
1143
|
+
headers
|
|
1144
|
+
});
|
|
1145
|
+
return [this.helpers.returnJsonArray(response)];
|
|
1146
|
+
}
|
|
1147
|
+
catch (error) {
|
|
1148
|
+
const errorMessage = error?.response?.data?.Message || error.message || "Error desconocido";
|
|
1149
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), errorMessage);
|
|
1150
|
+
}
|
|
1151
|
+
}
|
|
1152
|
+
case 'proveedorCrear': {
|
|
1153
|
+
const codigo = this.getNodeParameter('codigo', 0, '');
|
|
1154
|
+
const razonSocial = this.getNodeParameter('razonSocial', 0, '');
|
|
1155
|
+
const cuit = this.getNodeParameter('cuit', 0);
|
|
1156
|
+
const provincia = this.getNodeParameter('idProvincia', 0);
|
|
1157
|
+
const pais = this.getNodeParameter('idPais', 0);
|
|
1158
|
+
const condicionIVA = this.getNodeParameter('condicionIVA', 0, '');
|
|
1159
|
+
const formaPagoProveedor = this.getNodeParameter('formaPagoProveedor', 0);
|
|
1160
|
+
const condicionPago = this.getNodeParameter('condicionDePago', 0);
|
|
1161
|
+
const categoriaImpuestoGanancias = this.getNodeParameter('categoriaImpuestosGanancias', 0);
|
|
1162
|
+
const claseProveedor = this.getNodeParameter('claseProveedor', 0);
|
|
1163
|
+
const activo = this.getNodeParameter('active', 0);
|
|
1164
|
+
const idOperadorCompra = this.getNodeParameter('idOperadorCompra', 0);
|
|
1165
|
+
const idZona = this.getNodeParameter('idZona', 0);
|
|
1166
|
+
const idDescuentoProveedor = this.getNodeParameter('idDescuentoProveedor', 0);
|
|
1167
|
+
const body = {
|
|
1168
|
+
Codigo: codigo,
|
|
1169
|
+
RazonSocial: razonSocial,
|
|
1170
|
+
CUIT: cuit,
|
|
1171
|
+
Provincia: {
|
|
1172
|
+
IdProvincia: provincia
|
|
1173
|
+
},
|
|
1174
|
+
Pais: {
|
|
1175
|
+
IdPais: pais
|
|
1176
|
+
},
|
|
1177
|
+
CondicionIVA: {
|
|
1178
|
+
IdCondicionIVA: condicionIVA
|
|
1179
|
+
},
|
|
1180
|
+
FormaPagoProveedor: {
|
|
1181
|
+
IdFormaPagoProveedor: formaPagoProveedor
|
|
1182
|
+
},
|
|
1183
|
+
CondicionPago: {
|
|
1184
|
+
IdCondicionPago: condicionPago
|
|
1185
|
+
},
|
|
1186
|
+
CategoriaImpuestoGanancias: {
|
|
1187
|
+
IdCategoriaImpuestoGanancia: categoriaImpuestoGanancias
|
|
1188
|
+
},
|
|
1189
|
+
ClaseProveedor: {
|
|
1190
|
+
IdClaseProveedor: claseProveedor
|
|
1191
|
+
},
|
|
1192
|
+
OperadorCompra: {
|
|
1193
|
+
IdOperadorCompra: idOperadorCompra
|
|
1194
|
+
},
|
|
1195
|
+
Activo: activo,
|
|
1196
|
+
Zona: {
|
|
1197
|
+
IdZona: idZona
|
|
1198
|
+
},
|
|
1199
|
+
DescuentoProveedor: {
|
|
1200
|
+
IdDescuentoProveedor: idDescuentoProveedor
|
|
1201
|
+
}
|
|
1202
|
+
};
|
|
1203
|
+
try {
|
|
1204
|
+
const response = await (0, functions_1.apiRequest)(`${centumUrl}/Proveedores/`, {
|
|
1205
|
+
method: 'POST',
|
|
1206
|
+
headers,
|
|
1207
|
+
body
|
|
1208
|
+
});
|
|
1209
|
+
return [this.helpers.returnJsonArray(response)];
|
|
1210
|
+
}
|
|
1211
|
+
catch (error) {
|
|
1212
|
+
const errorMessage = error?.response?.data?.Message || error.message || "Error desconocido";
|
|
1213
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), errorMessage);
|
|
1214
|
+
}
|
|
1215
|
+
}
|
|
1216
|
+
case "provinciasLista": {
|
|
1217
|
+
const idPais = this.getNodeParameter("idPais", 0, "");
|
|
990
1218
|
try {
|
|
991
1219
|
const queryParams = {};
|
|
992
1220
|
if (idPais) {
|
|
993
1221
|
queryParams.idPais = idPais;
|
|
994
1222
|
}
|
|
995
1223
|
const provincias = await (0, functions_1.apiRequest)(`${centumUrl}/Provincias`, {
|
|
996
|
-
method:
|
|
1224
|
+
method: "GET",
|
|
997
1225
|
headers,
|
|
998
1226
|
queryParams,
|
|
999
1227
|
});
|
|
@@ -1001,67 +1229,81 @@ class Centum {
|
|
|
1001
1229
|
}
|
|
1002
1230
|
catch (error) {
|
|
1003
1231
|
console.log(error);
|
|
1004
|
-
const errorMessage = error?.response?.data?.Message || error.message ||
|
|
1232
|
+
const errorMessage = error?.response?.data?.Message || error.message || "Error desconocido";
|
|
1005
1233
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), errorMessage);
|
|
1006
1234
|
}
|
|
1007
1235
|
}
|
|
1008
|
-
case
|
|
1236
|
+
case "regimenesEspecialesLista": {
|
|
1009
1237
|
try {
|
|
1010
1238
|
const dataRegimenesList = await (0, functions_1.apiRequest)(`${centumUrl}/RegimenesEspeciales`, {
|
|
1011
|
-
method:
|
|
1012
|
-
headers
|
|
1239
|
+
method: "GET",
|
|
1240
|
+
headers,
|
|
1013
1241
|
});
|
|
1014
1242
|
return [this.helpers.returnJsonArray(dataRegimenesList)];
|
|
1015
1243
|
}
|
|
1016
1244
|
catch (error) {
|
|
1017
1245
|
console.log(error);
|
|
1018
|
-
const errorMessage = error?.response?.data?.Message || error.message ||
|
|
1246
|
+
const errorMessage = error?.response?.data?.Message || error.message || "Error desconocido";
|
|
1019
1247
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), errorMessage);
|
|
1020
1248
|
}
|
|
1021
1249
|
}
|
|
1022
|
-
case
|
|
1023
|
-
const regimenId = this.getNodeParameter(
|
|
1250
|
+
case "regimenesEspecialesPorId": {
|
|
1251
|
+
const regimenId = this.getNodeParameter("id", 0);
|
|
1024
1252
|
if (!regimenId) {
|
|
1025
|
-
throw new n8n_workflow_1.NodeOperationError(this.getNode(),
|
|
1253
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), "El ID del regimen es requerido");
|
|
1026
1254
|
}
|
|
1027
1255
|
try {
|
|
1028
1256
|
const regimen = await (0, functions_1.apiRequest)(`${centumUrl}/RegimenesEspeciales/${regimenId}`, {
|
|
1257
|
+
method: "GET",
|
|
1258
|
+
headers,
|
|
1259
|
+
});
|
|
1260
|
+
return [this.helpers.returnJsonArray(regimen)];
|
|
1261
|
+
}
|
|
1262
|
+
catch (error) {
|
|
1263
|
+
console.log(error);
|
|
1264
|
+
const errorMessage = error?.response?.data?.Message || error.message || "Error desconocido";
|
|
1265
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), errorMessage);
|
|
1266
|
+
}
|
|
1267
|
+
}
|
|
1268
|
+
case "rubrosObtener": {
|
|
1269
|
+
try {
|
|
1270
|
+
const response = await (0, functions_1.apiRequest)(`${centumUrl}/Rubros`, {
|
|
1029
1271
|
method: 'GET',
|
|
1030
1272
|
headers
|
|
1031
1273
|
});
|
|
1032
|
-
return [this.helpers.returnJsonArray(
|
|
1274
|
+
return [this.helpers.returnJsonArray(response)];
|
|
1033
1275
|
}
|
|
1034
1276
|
catch (error) {
|
|
1035
1277
|
console.log(error);
|
|
1036
|
-
const errorMessage = error?.response?.data?.Message || error.message ||
|
|
1278
|
+
const errorMessage = error?.response?.data?.Message || error.message || "Error desconocido";
|
|
1037
1279
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), errorMessage);
|
|
1038
1280
|
}
|
|
1039
1281
|
}
|
|
1040
|
-
case
|
|
1282
|
+
case "sucursalesFisicas": {
|
|
1041
1283
|
try {
|
|
1042
1284
|
const dataListBranches = await (0, functions_1.apiRequest)(`${centumUrl}/SucursalesFisicas`, {
|
|
1043
|
-
method:
|
|
1285
|
+
method: "GET",
|
|
1044
1286
|
headers,
|
|
1045
1287
|
});
|
|
1046
1288
|
return [this.helpers.returnJsonArray(dataListBranches)];
|
|
1047
1289
|
}
|
|
1048
1290
|
catch (error) {
|
|
1049
1291
|
console.log(error);
|
|
1050
|
-
const errorMessage = error?.response?.data?.Message || error.message ||
|
|
1292
|
+
const errorMessage = error?.response?.data?.Message || error.message || "Error desconocido";
|
|
1051
1293
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), errorMessage);
|
|
1052
1294
|
}
|
|
1053
1295
|
}
|
|
1054
|
-
case
|
|
1296
|
+
case "tipoComprobante": {
|
|
1055
1297
|
try {
|
|
1056
1298
|
const comprobanteList = await (0, functions_1.apiRequest)(`${centumUrl}/TiposComprobante`, {
|
|
1057
|
-
method:
|
|
1299
|
+
method: "GET",
|
|
1058
1300
|
headers,
|
|
1059
1301
|
});
|
|
1060
1302
|
return [this.helpers.returnJsonArray(comprobanteList)];
|
|
1061
1303
|
}
|
|
1062
1304
|
catch (error) {
|
|
1063
1305
|
console.log(error);
|
|
1064
|
-
const errorMessage = error?.response?.data?.Message || error.message ||
|
|
1306
|
+
const errorMessage = error?.response?.data?.Message || error.message || "Error desconocido";
|
|
1065
1307
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), errorMessage);
|
|
1066
1308
|
}
|
|
1067
1309
|
}
|