n8n-nodes-centum 0.2.15 → 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 -49
- package/dist/nodes/Centum/Centum.node.d.ts +1 -1
- package/dist/nodes/Centum/Centum.node.js +683 -219
- package/dist/nodes/Centum/Centum.node.js.map +1 -1
- package/dist/nodes/Centum/CentumDescription.js +553 -268
- 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,86 +571,364 @@ 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
|
|
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]));
|
|
599
|
+
let bodyProveedor;
|
|
600
|
+
const bodyCompraArticulos = {
|
|
601
|
+
IdCliente: idCliente,
|
|
602
|
+
FechaDocumento: separarFecha,
|
|
603
|
+
Ids: ids,
|
|
604
|
+
};
|
|
605
|
+
try {
|
|
606
|
+
const fetchProveedor = await (0, functions_1.apiRequest)(`${centumUrl}/Proveedores/${idProveedor}`, {
|
|
607
|
+
method: "GET",
|
|
608
|
+
headers,
|
|
609
|
+
});
|
|
610
|
+
bodyProveedor = fetchProveedor;
|
|
611
|
+
}
|
|
612
|
+
catch (error) {
|
|
613
|
+
const errorMessage = error?.response?.data?.Message || error.message || "Error desconocido";
|
|
614
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Error obteniendo el proveedor.\n ${errorMessage}`);
|
|
615
|
+
}
|
|
616
|
+
let articulosVenta;
|
|
617
|
+
try {
|
|
618
|
+
articulosVenta = await (0, functions_1.apiRequest)(`${centumUrl}/Articulos/Venta`, {
|
|
619
|
+
method: "POST",
|
|
620
|
+
body: bodyCompraArticulos,
|
|
621
|
+
headers,
|
|
622
|
+
});
|
|
623
|
+
}
|
|
624
|
+
catch (error) {
|
|
625
|
+
const errorMessage = error?.response?.data?.Message || error.message || "Error desconocido";
|
|
626
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Error al obtener la informacion de los articulos ${errorMessage}`);
|
|
627
|
+
}
|
|
628
|
+
const ventaObj = typeof articulosVenta === "string" ? JSON.parse(articulosVenta) : articulosVenta;
|
|
629
|
+
const itemsRespuesta = ventaObj?.Articulos?.Items ?? ventaObj?.CompraArticulos ?? ventaObj?.Items ?? [];
|
|
630
|
+
const compraConCantidad = itemsRespuesta.map((art) => ({
|
|
631
|
+
...art,
|
|
632
|
+
Cantidad: qtyById[String(art.IdArticulo)] ?? 0,
|
|
633
|
+
}));
|
|
634
|
+
const finalBody = {
|
|
635
|
+
TipoComprobanteCompra: {
|
|
636
|
+
IdTipoComprobanteCompra: idTipoComprobante,
|
|
637
|
+
Codigo: codigoComprobante,
|
|
638
|
+
Nombre: nombreTipoComprobante,
|
|
639
|
+
},
|
|
640
|
+
SucursalFisica: {
|
|
641
|
+
IdSucursalFisica: sucursalFisica,
|
|
642
|
+
},
|
|
643
|
+
NumeroDocumento: {
|
|
644
|
+
LetraDocumento: letraDocumento,
|
|
645
|
+
PuntoVenta: puntoVenta,
|
|
646
|
+
Numero: numeroDocumento,
|
|
647
|
+
},
|
|
648
|
+
FechaDocumento: fechaDocumento,
|
|
649
|
+
Proveedor: bodyProveedor,
|
|
650
|
+
CompraArticulos: compraConCantidad,
|
|
651
|
+
};
|
|
652
|
+
try {
|
|
653
|
+
const response = await (0, functions_1.apiRequest)(`${centumUrl}/Compras`, {
|
|
654
|
+
method: "POST",
|
|
655
|
+
headers,
|
|
656
|
+
body: finalBody,
|
|
657
|
+
});
|
|
658
|
+
return [this.helpers.returnJsonArray(response)];
|
|
659
|
+
}
|
|
660
|
+
catch (error) {
|
|
661
|
+
const errorMessage = error?.response?.data?.Message || error.message || "Error desconocido";
|
|
662
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Error creando la compra.\n ${errorMessage}`);
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
case "generarToken": {
|
|
553
666
|
try {
|
|
554
667
|
const tokenGenerado = (0, functions_1.createHash)(headers.publicAccessKey);
|
|
555
668
|
return [this.helpers.returnJsonArray(tokenGenerado)];
|
|
556
669
|
}
|
|
557
670
|
catch (error) {
|
|
558
671
|
console.log(error);
|
|
559
|
-
const errorMessage = error?.response?.data?.Message || error.message ||
|
|
672
|
+
const errorMessage = error?.response?.data?.Message || error.message || "Error desconocido";
|
|
560
673
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), errorMessage);
|
|
561
674
|
}
|
|
562
675
|
}
|
|
563
|
-
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": {
|
|
564
788
|
try {
|
|
565
789
|
const response = await (0, functions_1.apiRequest)(`${centumUrl}/ListasPrecios`, {
|
|
566
|
-
method:
|
|
790
|
+
method: "GET",
|
|
567
791
|
headers,
|
|
568
792
|
});
|
|
569
793
|
return [this.helpers.returnJsonArray(response)];
|
|
570
794
|
}
|
|
571
795
|
catch (error) {
|
|
572
|
-
console.log(
|
|
573
|
-
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";
|
|
574
798
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Error obteniendo el listado de precios. \n ${errorMessage}`);
|
|
575
799
|
}
|
|
576
800
|
}
|
|
577
|
-
case
|
|
578
|
-
|
|
579
|
-
|
|
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);
|
|
580
818
|
console.log(bodyJson);
|
|
581
|
-
if (typeof cuit !==
|
|
582
|
-
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.");
|
|
583
821
|
}
|
|
584
822
|
const contribuyenteJSON = (0, functions_1.createContribuyenteJson)(bodyJson, cuit);
|
|
585
823
|
try {
|
|
586
824
|
const crearCliente = await (0, functions_1.apiRequest)(`${centumUrl}/Clientes`, {
|
|
587
|
-
method:
|
|
825
|
+
method: "POST",
|
|
588
826
|
body: contribuyenteJSON,
|
|
589
827
|
headers,
|
|
590
828
|
});
|
|
591
|
-
console.log(
|
|
829
|
+
console.log("Contribuyente creado:", crearCliente);
|
|
592
830
|
return [this.helpers.returnJsonArray([crearCliente])];
|
|
593
831
|
}
|
|
594
832
|
catch (error) {
|
|
595
|
-
console.error(
|
|
833
|
+
console.error("Error al crear contribuyente:", error);
|
|
596
834
|
const statusCode = error?.response?.status;
|
|
597
835
|
const responseData = error?.response?.data;
|
|
598
|
-
const errorMessage = responseData?.Message ||
|
|
599
|
-
responseData?.message ||
|
|
600
|
-
error?.message ||
|
|
601
|
-
'Error desconocido al crear el contribuyente.';
|
|
836
|
+
const errorMessage = responseData?.Message || responseData?.message || error?.message || "Error desconocido al crear el contribuyente.";
|
|
602
837
|
const fullMessage = statusCode ? `Error ${statusCode}: ${errorMessage}` : errorMessage;
|
|
603
838
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), fullMessage, {
|
|
604
|
-
description: responseData?.Detail ||
|
|
839
|
+
description: responseData?.Detail || "Ocurrió un error inesperado al llamar a la API de Centum.",
|
|
840
|
+
});
|
|
841
|
+
}
|
|
842
|
+
}
|
|
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];
|
|
850
|
+
if (!idCliente && !separarFechaDesde && !separarFechaHasta && !idCobro) {
|
|
851
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), "Debes ingresar almenos un parametro para realizar la búsqueda.");
|
|
852
|
+
}
|
|
853
|
+
const body = {
|
|
854
|
+
idCliente,
|
|
855
|
+
fechaDocumentoDesde: separarFechaDesde,
|
|
856
|
+
fechaDocumentoHasta: separarFechaHasta,
|
|
857
|
+
idCobro,
|
|
858
|
+
};
|
|
859
|
+
try {
|
|
860
|
+
const response = await (0, functions_1.apiRequest)(`${centumUrl}/Cobros/FiltrosCobro`, {
|
|
861
|
+
method: "POST",
|
|
862
|
+
headers,
|
|
863
|
+
body,
|
|
605
864
|
});
|
|
865
|
+
return [this.helpers.returnJsonArray(response)];
|
|
866
|
+
}
|
|
867
|
+
catch (error) {
|
|
868
|
+
console.log("Error en obtener el listado de cobros:", error);
|
|
869
|
+
const errorMessage = error?.response?.data?.Message || error.message || "Error desconocido";
|
|
870
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Error en obtener el listado de cobros para cliente ${idCliente}: ${errorMessage}`);
|
|
871
|
+
}
|
|
872
|
+
}
|
|
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];
|
|
880
|
+
if (!idCliente && !separarFechaDesde && !separarFechaHasta && !idCompra) {
|
|
881
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), "Debes ingresar almenos un parametro para realizar la búsqueda.");
|
|
882
|
+
}
|
|
883
|
+
const body = {
|
|
884
|
+
idCliente,
|
|
885
|
+
fechaDocumentoDesde: separarFechaDesde,
|
|
886
|
+
fechaDocumentoHasta: separarFechaHasta,
|
|
887
|
+
idCompra,
|
|
888
|
+
};
|
|
889
|
+
try {
|
|
890
|
+
const response = await (0, functions_1.apiRequest)(`${centumUrl}/Compras/FiltrosCompra`, {
|
|
891
|
+
method: "POST",
|
|
892
|
+
headers,
|
|
893
|
+
body,
|
|
894
|
+
});
|
|
895
|
+
return [this.helpers.returnJsonArray(response)];
|
|
896
|
+
}
|
|
897
|
+
catch (error) {
|
|
898
|
+
console.log("Error en obtener el listado de cobros:", error);
|
|
899
|
+
const errorMessage = error?.response?.data?.Message || error.message || "Error desconocido";
|
|
900
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Error en obtener el listado de cobros para cliente ${idCliente}: ${errorMessage}`);
|
|
606
901
|
}
|
|
607
902
|
}
|
|
608
|
-
case
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
903
|
+
case "obtenerEstadosPedidosDeVenta": {
|
|
904
|
+
try {
|
|
905
|
+
const response = await (0, functions_1.apiRequest)(`${centumUrl}/EstadosPedidoVenta?bIncluirTodosEstados=true`, {
|
|
906
|
+
method: "GET",
|
|
907
|
+
headers,
|
|
908
|
+
});
|
|
909
|
+
return [this.helpers.returnJsonArray(response)];
|
|
910
|
+
}
|
|
911
|
+
catch (error) {
|
|
912
|
+
console.log(error);
|
|
913
|
+
const errorMessage = error?.response?.data?.Message || error.message || "Error desconocido";
|
|
914
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), errorMessage);
|
|
915
|
+
}
|
|
916
|
+
}
|
|
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];
|
|
614
923
|
const clientId = Number(clientIdParam);
|
|
615
924
|
if (isNaN(clientId) || clientId <= 0) {
|
|
616
|
-
throw new n8n_workflow_1.NodeOperationError(this.getNode(),
|
|
925
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), "clienteId debe ser un número positivo");
|
|
617
926
|
}
|
|
618
927
|
if (!desdeSaldoFecha) {
|
|
619
|
-
throw new n8n_workflow_1.NodeOperationError(this.getNode(),
|
|
928
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), "priceDateModified (fecha desde) es requerido");
|
|
620
929
|
}
|
|
621
930
|
if (!hastaSaldoFecha) {
|
|
622
|
-
throw new n8n_workflow_1.NodeOperationError(this.getNode(),
|
|
931
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), "priceDateModifiedSince (fecha hasta) es requerido");
|
|
623
932
|
}
|
|
624
933
|
try {
|
|
625
934
|
const body = {
|
|
@@ -628,36 +937,36 @@ class Centum {
|
|
|
628
937
|
IdCliente: clientId,
|
|
629
938
|
};
|
|
630
939
|
const response = await (0, functions_1.apiRequest)(`${centumUrl}/Cobros/FiltrosCobro`, {
|
|
631
|
-
method:
|
|
940
|
+
method: "POST",
|
|
632
941
|
headers,
|
|
633
942
|
body,
|
|
634
943
|
});
|
|
635
|
-
if (!response || typeof response !==
|
|
636
|
-
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");
|
|
637
946
|
}
|
|
638
947
|
return [this.helpers.returnJsonArray(response)];
|
|
639
948
|
}
|
|
640
949
|
catch (error) {
|
|
641
|
-
console.log(
|
|
642
|
-
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";
|
|
643
952
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Error obteniendo facturas pedidos ventas para cliente ${clientId}: ${errorMessage}`);
|
|
644
953
|
}
|
|
645
954
|
}
|
|
646
|
-
case
|
|
647
|
-
const clientIdParam = this.getNodeParameter(
|
|
648
|
-
const desdeSaldoFecha = this.getNodeParameter(
|
|
649
|
-
const hastaSaldoFecha = this.getNodeParameter(
|
|
650
|
-
const separarFechaDesde = String(desdeSaldoFecha).split(
|
|
651
|
-
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];
|
|
652
961
|
const clientId = Number(clientIdParam);
|
|
653
962
|
if (isNaN(clientId) || clientId <= 0) {
|
|
654
|
-
throw new n8n_workflow_1.NodeOperationError(this.getNode(),
|
|
963
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), "clienteId debe ser un número positivo");
|
|
655
964
|
}
|
|
656
965
|
if (!desdeSaldoFecha) {
|
|
657
|
-
throw new n8n_workflow_1.NodeOperationError(this.getNode(),
|
|
966
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), "priceDateModified (fecha desde) es requerido");
|
|
658
967
|
}
|
|
659
968
|
if (!hastaSaldoFecha) {
|
|
660
|
-
throw new n8n_workflow_1.NodeOperationError(this.getNode(),
|
|
969
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), "priceDateModifiedSince (fecha hasta) es requerido");
|
|
661
970
|
}
|
|
662
971
|
try {
|
|
663
972
|
const body = {
|
|
@@ -666,28 +975,58 @@ class Centum {
|
|
|
666
975
|
IdCliente: clientId,
|
|
667
976
|
};
|
|
668
977
|
const response = await (0, functions_1.apiRequest)(`${centumUrl}/Ventas/FiltrosVenta`, {
|
|
669
|
-
method:
|
|
978
|
+
method: "POST",
|
|
670
979
|
headers,
|
|
671
980
|
body,
|
|
672
981
|
});
|
|
673
|
-
if (!response || typeof response !==
|
|
674
|
-
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");
|
|
675
984
|
}
|
|
676
985
|
return [this.helpers.returnJsonArray(response)];
|
|
677
986
|
}
|
|
678
987
|
catch (error) {
|
|
679
|
-
console.log(
|
|
680
|
-
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";
|
|
681
990
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Error obteniendo facturas pedidos ventas para cliente ${clientId}: ${errorMessage}`);
|
|
682
991
|
}
|
|
683
992
|
}
|
|
684
|
-
case
|
|
685
|
-
const
|
|
686
|
-
const
|
|
687
|
-
const
|
|
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];
|
|
1000
|
+
if (!idCliente && !idsEstado && !separarFechaDesde && !separarFechaHasta) {
|
|
1001
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), "Debes ingresar almenos un parametro para realizar la búsqueda.");
|
|
1002
|
+
}
|
|
1003
|
+
const body = {
|
|
1004
|
+
idCliente,
|
|
1005
|
+
fechaDocumentoDesde: separarFechaDesde,
|
|
1006
|
+
fechaDocumentoHasta: separarFechaHasta,
|
|
1007
|
+
idsEstado,
|
|
1008
|
+
};
|
|
1009
|
+
try {
|
|
1010
|
+
const response = await (0, functions_1.apiRequest)(`${centumUrl}/PedidosVenta/FiltrosPedidoVenta`, {
|
|
1011
|
+
method: "POST",
|
|
1012
|
+
headers,
|
|
1013
|
+
body,
|
|
1014
|
+
});
|
|
1015
|
+
return [this.helpers.returnJsonArray(response)];
|
|
1016
|
+
}
|
|
1017
|
+
catch (error) {
|
|
1018
|
+
console.log("Error en solicitud de facturas pedidos ventas:", error);
|
|
1019
|
+
const errorMessage = error?.response?.data?.Message || error.message || "Error desconocido";
|
|
1020
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Error obteniendo los pedidos ventas para cliente ${idCliente}: ${errorMessage}`);
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
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];
|
|
688
1027
|
const clientId = Number(clientIdParam);
|
|
689
1028
|
if (isNaN(clientId) || clientId <= 0) {
|
|
690
|
-
throw new n8n_workflow_1.NodeOperationError(this.getNode(),
|
|
1029
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), "clienteId debe ser un número positivo");
|
|
691
1030
|
}
|
|
692
1031
|
try {
|
|
693
1032
|
let url = `${centumUrl}/SaldosCuentasCorrientes/${clientId}`;
|
|
@@ -695,31 +1034,50 @@ class Centum {
|
|
|
695
1034
|
url += `?fechaVencimientoHasta=${soloFecha}`;
|
|
696
1035
|
}
|
|
697
1036
|
const response = await (0, functions_1.apiRequest)(url, {
|
|
698
|
-
method:
|
|
1037
|
+
method: "GET",
|
|
699
1038
|
headers,
|
|
700
1039
|
});
|
|
701
1040
|
return [this.helpers.returnJsonArray(response)];
|
|
702
1041
|
}
|
|
703
1042
|
catch (error) {
|
|
704
|
-
const errorMessage = error?.response?.data?.Message || error.message ||
|
|
1043
|
+
const errorMessage = error?.response?.data?.Message || error.message || "Error desconocido";
|
|
705
1044
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Error obteniendo saldo para cliente ${clientId}: ${errorMessage}`);
|
|
706
1045
|
}
|
|
707
1046
|
}
|
|
708
|
-
case
|
|
709
|
-
const
|
|
1047
|
+
case "operadoresMoviles": {
|
|
1048
|
+
const username = this.getNodeParameter("username", 0, "");
|
|
1049
|
+
const password = this.getNodeParameter("password", 0, "");
|
|
1050
|
+
try {
|
|
1051
|
+
const operadoresActividad = await (0, functions_1.apiRequest)(`
|
|
1052
|
+
${centumUrl}/OperadoresMoviles/Credenciales?Usuario=${username}&Contrasena=${password}`, {
|
|
1053
|
+
method: "GET",
|
|
1054
|
+
headers,
|
|
1055
|
+
});
|
|
1056
|
+
return [this.helpers.returnJsonArray(operadoresActividad)];
|
|
1057
|
+
}
|
|
1058
|
+
catch (error) {
|
|
1059
|
+
const errorMessage = error?.response?.data?.Message || error.message || "Error desconocido";
|
|
1060
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), errorMessage);
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1063
|
+
case "pedidoVentaActividad": {
|
|
1064
|
+
const pedidoID = this.getNodeParameter("id", 0);
|
|
710
1065
|
try {
|
|
711
|
-
const dataActividad = await (0, functions_1.apiRequest)(`${centumUrl}/PedidosVenta/${pedidoID}`, {
|
|
1066
|
+
const dataActividad = await (0, functions_1.apiRequest)(`${centumUrl}/PedidosVenta/${pedidoID}`, {
|
|
1067
|
+
method: "GET",
|
|
1068
|
+
headers,
|
|
1069
|
+
});
|
|
712
1070
|
return [this.helpers.returnJsonArray(dataActividad)];
|
|
713
1071
|
}
|
|
714
1072
|
catch (error) {
|
|
715
1073
|
console.log(error);
|
|
716
|
-
const errorMessage = error?.response?.data?.Message || error.message ||
|
|
1074
|
+
const errorMessage = error?.response?.data?.Message || error.message || "Error desconocido";
|
|
717
1075
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), errorMessage);
|
|
718
1076
|
}
|
|
719
1077
|
}
|
|
720
|
-
case
|
|
721
|
-
const dataImages = this.getNodeParameter(
|
|
722
|
-
const db = this.getNodeParameter(
|
|
1078
|
+
case "procesarImagenes": {
|
|
1079
|
+
const dataImages = this.getNodeParameter("dataImg", 0);
|
|
1080
|
+
const db = this.getNodeParameter("lastModifiedImg", 0);
|
|
723
1081
|
const result = [];
|
|
724
1082
|
for (let i = 0; i < dataImages.length; i++) {
|
|
725
1083
|
const element = dataImages[i];
|
|
@@ -743,28 +1101,28 @@ class Centum {
|
|
|
743
1101
|
}
|
|
744
1102
|
return [this.helpers.returnJsonArray(result)];
|
|
745
1103
|
}
|
|
746
|
-
case
|
|
747
|
-
const clientIdParam = this.getNodeParameter(
|
|
748
|
-
const documentDate = this.getNodeParameter(
|
|
749
|
-
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);
|
|
750
1108
|
const clientId = Number(clientIdParam);
|
|
751
1109
|
if (!documentDate) {
|
|
752
|
-
throw new n8n_workflow_1.NodeOperationError(this.getNode(),
|
|
1110
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), "documentDate es requerido");
|
|
753
1111
|
}
|
|
754
|
-
const formattedDocumentDate = String(documentDate).split(
|
|
1112
|
+
const formattedDocumentDate = String(documentDate).split("T")[0];
|
|
755
1113
|
try {
|
|
756
1114
|
const body = {
|
|
757
1115
|
FechaDocumento: formattedDocumentDate,
|
|
758
1116
|
IdsCliente: clientId,
|
|
759
|
-
DiaSemana: diaSemana ||
|
|
1117
|
+
DiaSemana: diaSemana || "",
|
|
760
1118
|
};
|
|
761
1119
|
const response = await (0, functions_1.apiRequest)(`${centumUrl}/PromocionesComerciales/FiltrosPromocionComercial`, {
|
|
762
|
-
method:
|
|
1120
|
+
method: "POST",
|
|
763
1121
|
headers,
|
|
764
1122
|
body,
|
|
765
1123
|
});
|
|
766
|
-
if (!response || typeof response !==
|
|
767
|
-
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");
|
|
768
1126
|
}
|
|
769
1127
|
if (response.Items && Array.isArray(response.Items)) {
|
|
770
1128
|
return [this.helpers.returnJsonArray(response.Items)];
|
|
@@ -772,20 +1130,98 @@ class Centum {
|
|
|
772
1130
|
return [this.helpers.returnJsonArray(response)];
|
|
773
1131
|
}
|
|
774
1132
|
catch (error) {
|
|
775
|
-
console.log(
|
|
776
|
-
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";
|
|
777
1135
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Error obteniendo promociones para el cliente ${clientId}: \n ${errorMessage}`);
|
|
778
1136
|
}
|
|
779
1137
|
}
|
|
780
|
-
case '
|
|
781
|
-
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, "");
|
|
782
1218
|
try {
|
|
783
1219
|
const queryParams = {};
|
|
784
1220
|
if (idPais) {
|
|
785
1221
|
queryParams.idPais = idPais;
|
|
786
1222
|
}
|
|
787
1223
|
const provincias = await (0, functions_1.apiRequest)(`${centumUrl}/Provincias`, {
|
|
788
|
-
method:
|
|
1224
|
+
method: "GET",
|
|
789
1225
|
headers,
|
|
790
1226
|
queryParams,
|
|
791
1227
|
});
|
|
@@ -793,53 +1229,81 @@ class Centum {
|
|
|
793
1229
|
}
|
|
794
1230
|
catch (error) {
|
|
795
1231
|
console.log(error);
|
|
796
|
-
const errorMessage = error?.response?.data?.Message || error.message ||
|
|
1232
|
+
const errorMessage = error?.response?.data?.Message || error.message || "Error desconocido";
|
|
797
1233
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), errorMessage);
|
|
798
1234
|
}
|
|
799
1235
|
}
|
|
800
|
-
case
|
|
1236
|
+
case "regimenesEspecialesLista": {
|
|
801
1237
|
try {
|
|
802
1238
|
const dataRegimenesList = await (0, functions_1.apiRequest)(`${centumUrl}/RegimenesEspeciales`, {
|
|
803
|
-
method:
|
|
804
|
-
headers
|
|
1239
|
+
method: "GET",
|
|
1240
|
+
headers,
|
|
805
1241
|
});
|
|
806
1242
|
return [this.helpers.returnJsonArray(dataRegimenesList)];
|
|
807
1243
|
}
|
|
808
1244
|
catch (error) {
|
|
809
1245
|
console.log(error);
|
|
810
|
-
const errorMessage = error?.response?.data?.Message || error.message ||
|
|
1246
|
+
const errorMessage = error?.response?.data?.Message || error.message || "Error desconocido";
|
|
811
1247
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), errorMessage);
|
|
812
1248
|
}
|
|
813
1249
|
}
|
|
814
|
-
case
|
|
815
|
-
const regimenId = this.getNodeParameter(
|
|
1250
|
+
case "regimenesEspecialesPorId": {
|
|
1251
|
+
const regimenId = this.getNodeParameter("id", 0);
|
|
816
1252
|
if (!regimenId) {
|
|
817
|
-
throw new n8n_workflow_1.NodeOperationError(this.getNode(),
|
|
1253
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), "El ID del regimen es requerido");
|
|
818
1254
|
}
|
|
819
1255
|
try {
|
|
820
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`, {
|
|
821
1271
|
method: 'GET',
|
|
822
1272
|
headers
|
|
823
1273
|
});
|
|
824
|
-
return [this.helpers.returnJsonArray(
|
|
1274
|
+
return [this.helpers.returnJsonArray(response)];
|
|
825
1275
|
}
|
|
826
1276
|
catch (error) {
|
|
827
1277
|
console.log(error);
|
|
828
|
-
const errorMessage = error?.response?.data?.Message || error.message ||
|
|
1278
|
+
const errorMessage = error?.response?.data?.Message || error.message || "Error desconocido";
|
|
829
1279
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), errorMessage);
|
|
830
1280
|
}
|
|
831
1281
|
}
|
|
832
|
-
case
|
|
1282
|
+
case "sucursalesFisicas": {
|
|
833
1283
|
try {
|
|
834
1284
|
const dataListBranches = await (0, functions_1.apiRequest)(`${centumUrl}/SucursalesFisicas`, {
|
|
835
|
-
method:
|
|
1285
|
+
method: "GET",
|
|
836
1286
|
headers,
|
|
837
1287
|
});
|
|
838
1288
|
return [this.helpers.returnJsonArray(dataListBranches)];
|
|
839
1289
|
}
|
|
840
1290
|
catch (error) {
|
|
841
1291
|
console.log(error);
|
|
842
|
-
const errorMessage = error?.response?.data?.Message || error.message ||
|
|
1292
|
+
const errorMessage = error?.response?.data?.Message || error.message || "Error desconocido";
|
|
1293
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), errorMessage);
|
|
1294
|
+
}
|
|
1295
|
+
}
|
|
1296
|
+
case "tipoComprobante": {
|
|
1297
|
+
try {
|
|
1298
|
+
const comprobanteList = await (0, functions_1.apiRequest)(`${centumUrl}/TiposComprobante`, {
|
|
1299
|
+
method: "GET",
|
|
1300
|
+
headers,
|
|
1301
|
+
});
|
|
1302
|
+
return [this.helpers.returnJsonArray(comprobanteList)];
|
|
1303
|
+
}
|
|
1304
|
+
catch (error) {
|
|
1305
|
+
console.log(error);
|
|
1306
|
+
const errorMessage = error?.response?.data?.Message || error.message || "Error desconocido";
|
|
843
1307
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), errorMessage);
|
|
844
1308
|
}
|
|
845
1309
|
}
|