n8n-nodes-centum 0.2.16 → 0.2.18

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