@zauru-sdk/utils 1.0.110 → 1.0.113
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/zauru/4pinos-reception-register.utils.js +99 -14
- package/dist/cjs/zauru/4pinos-receptions-form-history.utils.js +2 -0
- package/dist/esm/zauru/4pinos-reception-register.utils.js +97 -13
- package/dist/esm/zauru/4pinos-receptions-form-history.utils.js +2 -0
- package/dist/zauru/4pinos-reception-register.utils.d.ts +8 -0
- package/dist/zauru/4pinos-receptions-form-history.utils.d.ts +1 -0
- package/package.json +2 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.register4pinosReception = void 0;
|
|
3
|
+
exports.retryPO = exports.register4pinosReception = void 0;
|
|
4
4
|
const common_1 = require("@zauru-sdk/common");
|
|
5
5
|
const services_1 = require("@zauru-sdk/services");
|
|
6
6
|
const motivos_rechazo_utils_js_1 = require("./motivos-rechazo.utils.js");
|
|
@@ -14,6 +14,16 @@ const register4pinosReception = async ({ cookie, idWebAppTable, agency_id, value
|
|
|
14
14
|
};
|
|
15
15
|
try {
|
|
16
16
|
if (apiResponses.apiCall === 1) {
|
|
17
|
+
const responseUpdate = await (0, _4pinos_receptions_form_history_utils_js_1.updateQueueFormReceptionHistory)(headers, session, {
|
|
18
|
+
estado: _4pinos_receptions_form_history_utils_js_1.ESTADOS_COLA_RECEPCIONES.EN_PROCESO,
|
|
19
|
+
}, idWebAppTable);
|
|
20
|
+
if (responseUpdate.error) {
|
|
21
|
+
throw new Error("Error al intentar actualizar el estado de la cola: " +
|
|
22
|
+
responseUpdate?.userMsg);
|
|
23
|
+
}
|
|
24
|
+
apiResponses.apiCall = apiResponses.apiCall + 1;
|
|
25
|
+
}
|
|
26
|
+
if (apiResponses.apiCall === 2) {
|
|
17
27
|
//SI EL API CALL ES DIFERENTE DE 1 SIGNIFICA QUE SOLO VA A REINTENTAR DESDE DONDE FALLÓ
|
|
18
28
|
//Validando que no exista ya una recepción con ese número:
|
|
19
29
|
const responsePOSearch = await (0, services_1.getPurchasesOrderByIdNumber)(session, values?.idNumberInput);
|
|
@@ -109,7 +119,7 @@ const register4pinosReception = async ({ cookie, idWebAppTable, agency_id, value
|
|
|
109
119
|
};
|
|
110
120
|
let [received_baskets, qualityControlBaskets, detail_baskets, detail_discounts, detail_weights,] = processValues();
|
|
111
121
|
//========== PRIMERA LLAMADA DE API Y CAPTURA DE ERRORES
|
|
112
|
-
if (apiResponses.apiCall ===
|
|
122
|
+
if (apiResponses.apiCall === 2) {
|
|
113
123
|
console.log("========================================>");
|
|
114
124
|
console.log("paso 1: REGISTRANDO NUEVA ORDEN DE COMPRA AUTORIZADA...");
|
|
115
125
|
//build net_weights
|
|
@@ -165,7 +175,7 @@ const register4pinosReception = async ({ cookie, idWebAppTable, agency_id, value
|
|
|
165
175
|
apiResponses.authorizedPO = newAuthorizedPurchaseResponse.data;
|
|
166
176
|
apiResponses.apiCall = apiResponses.apiCall + 1;
|
|
167
177
|
}
|
|
168
|
-
if (apiResponses.apiCall ===
|
|
178
|
+
if (apiResponses.apiCall === 3) {
|
|
169
179
|
const createNewReceptionBodyFunction = () => {
|
|
170
180
|
const receptionDetails = {};
|
|
171
181
|
apiResponses.authorizedPO.purchase_order_details.forEach((pod, index) => (receptionDetails[index] = {
|
|
@@ -203,7 +213,7 @@ const register4pinosReception = async ({ cookie, idWebAppTable, agency_id, value
|
|
|
203
213
|
}
|
|
204
214
|
apiResponses.apiCall = apiResponses.apiCall + 1;
|
|
205
215
|
}
|
|
206
|
-
if (apiResponses.apiCall ===
|
|
216
|
+
if (apiResponses.apiCall === 4) {
|
|
207
217
|
console.log("------------- REALIZANDO ENVÍO DE CANASTAS A LA AGENCIA");
|
|
208
218
|
const createBasketsShipmentBodyFunction = () => {
|
|
209
219
|
const movementDetails = [];
|
|
@@ -236,7 +246,7 @@ const register4pinosReception = async ({ cookie, idWebAppTable, agency_id, value
|
|
|
236
246
|
apiResponses.apiCall = apiResponses.apiCall + 1;
|
|
237
247
|
apiResponses.shipment = newShipmentResponse.data;
|
|
238
248
|
}
|
|
239
|
-
if (apiResponses.apiCall ===
|
|
249
|
+
if (apiResponses.apiCall === 5) {
|
|
240
250
|
console.log("------------- RECIBIENDO EL ENVÍO DE CANASTAS");
|
|
241
251
|
const getShipmentResponse = await (0, services_1.getDeliveryByBooking)(headers, apiResponses.shipment.id);
|
|
242
252
|
if (getShipmentResponse.error) {
|
|
@@ -248,10 +258,10 @@ const register4pinosReception = async ({ cookie, idWebAppTable, agency_id, value
|
|
|
248
258
|
//Al momento de este comentario, un ejemplo es que sólo Planta Central no es centro de acopio
|
|
249
259
|
//Ellos si envían canastas a control de calidad.
|
|
250
260
|
//Si es de un centro de acopio, se salta esto...
|
|
251
|
-
if (apiResponses.apiCall ===
|
|
261
|
+
if (apiResponses.apiCall === 6 && qualityControlBaskets.length > 0) {
|
|
252
262
|
console.log("------------- REALIZANDO ENVÍO DE CANASTAS A CONTROL DE CALIDAD");
|
|
253
|
-
const total_qc_baskets =
|
|
254
|
-
const
|
|
263
|
+
const total_qc_baskets = Number(values.totalQCBaskets);
|
|
264
|
+
const netWeightByBasket = Number(netWeight) / total_qc_baskets;
|
|
255
265
|
const lotResponse = await (0, services_1.getLoteByName)(session, apiResponses.authorizedPO.id_number);
|
|
256
266
|
if (lotResponse.error || !lotResponse.data || !lotResponse.data.id) {
|
|
257
267
|
throw new Error("Error al intentar obtener el lote por nombre: " +
|
|
@@ -271,7 +281,7 @@ const register4pinosReception = async ({ cookie, idWebAppTable, agency_id, value
|
|
|
271
281
|
qcMovementDetails.push({
|
|
272
282
|
item_id: apiResponses.authorizedPO.purchase_order_details[0].item_id,
|
|
273
283
|
lot_id: Number(lotResponse.data?.id),
|
|
274
|
-
booked_quantity:
|
|
284
|
+
booked_quantity: total_qc_baskets * netWeightByBasket,
|
|
275
285
|
reference: "Verduras a control de calidad.",
|
|
276
286
|
});
|
|
277
287
|
const qcBasketShipment = {
|
|
@@ -297,16 +307,18 @@ const register4pinosReception = async ({ cookie, idWebAppTable, agency_id, value
|
|
|
297
307
|
apiResponses.apiCall = apiResponses.apiCall + 1;
|
|
298
308
|
apiResponses.qcShipment = new_qc_shipment_response.data;
|
|
299
309
|
}
|
|
300
|
-
if (apiResponses.apiCall ===
|
|
310
|
+
if (apiResponses.apiCall === 7) {
|
|
301
311
|
console.log("------------- RECIBIENDO ENVÍO DE CANASTAS A CONTROL DE CALIDAD");
|
|
302
312
|
const getQCDeliveryResponse = await (0, services_1.getDeliveryByBooking)(headers, apiResponses.qcShipment.id);
|
|
303
313
|
if (getQCDeliveryResponse.error) {
|
|
304
314
|
throw new Error("Error al intentar recibir el envío de control de calidad: " +
|
|
305
|
-
getQCDeliveryResponse?.userMsg
|
|
315
|
+
getQCDeliveryResponse?.userMsg +
|
|
316
|
+
" Body: " +
|
|
317
|
+
JSON.stringify(apiResponses.qcShipment));
|
|
306
318
|
}
|
|
307
319
|
apiResponses.apiCall = apiResponses.apiCall + 1;
|
|
308
320
|
}
|
|
309
|
-
if (apiResponses.apiCall ===
|
|
321
|
+
if (apiResponses.apiCall === 8 || qualityControlBaskets.length === 0) {
|
|
310
322
|
if (webapp_table_object.Canastas !== "" &&
|
|
311
323
|
webapp_table_object.Canastas !== "0") {
|
|
312
324
|
console.log("----------- Guardando rechazo de canastas directo...... -----------");
|
|
@@ -324,13 +336,13 @@ const register4pinosReception = async ({ cookie, idWebAppTable, agency_id, value
|
|
|
324
336
|
}
|
|
325
337
|
}
|
|
326
338
|
}
|
|
327
|
-
|
|
339
|
+
else {
|
|
328
340
|
//Si es centro de acopio, guardo los motivos de rechazo
|
|
329
341
|
if (controlCalidadValues?.razonPrincipal ||
|
|
330
342
|
controlCalidadValues?.razonSecundaria ||
|
|
331
343
|
controlCalidadValues?.razonTerciaria ||
|
|
332
344
|
controlCalidadValues?.otrasRazones) {
|
|
333
|
-
if (apiResponses.apiCall ===
|
|
345
|
+
if (apiResponses.apiCall === 6) {
|
|
334
346
|
console.log("========================================>");
|
|
335
347
|
console.log("paso 3: GUARDAR MOTIVOS DE RECHAZO");
|
|
336
348
|
const saveMotivosResponse = await (0, services_1.saveMotivosDeRechazoByPurchase)(headers, session, {
|
|
@@ -355,6 +367,7 @@ const register4pinosReception = async ({ cookie, idWebAppTable, agency_id, value
|
|
|
355
367
|
//SI OCURRE ALGÚN ERROR, SE INTENTA GUARDAR EL RETRY
|
|
356
368
|
console.log("========================================>");
|
|
357
369
|
console.log("paso -1: ACTUALIZAR EL REGISTRO DE LA COLA A ERROR");
|
|
370
|
+
console.error(`Error: ${e?.toString()}, idWebAppTable: ${idWebAppTable}`);
|
|
358
371
|
await (0, _4pinos_receptions_form_history_utils_js_1.updateQueueFormReceptionHistory)(headers, session, {
|
|
359
372
|
estado: _4pinos_receptions_form_history_utils_js_1.ESTADOS_COLA_RECEPCIONES.ERROR,
|
|
360
373
|
description: e?.toString(),
|
|
@@ -363,3 +376,75 @@ const register4pinosReception = async ({ cookie, idWebAppTable, agency_id, value
|
|
|
363
376
|
}
|
|
364
377
|
};
|
|
365
378
|
exports.register4pinosReception = register4pinosReception;
|
|
379
|
+
const retryPO = async (register, session, headers, hostname, cookie) => {
|
|
380
|
+
console.log("REINTENTO DE REGISTRO DE ORDEN DE COMPRA =======================>");
|
|
381
|
+
if (!register.data.apiResponses || register.data.apiResponses.apiCall === 1) {
|
|
382
|
+
const responsePOSearch = await (0, services_1.getPurchasesOrderByIdNumber)(session, register.data?.formSubmited?.idNumberInput);
|
|
383
|
+
if (responsePOSearch.error || !responsePOSearch.data) {
|
|
384
|
+
console.error("Validate Exists: ", responsePOSearch.userMsg);
|
|
385
|
+
return {
|
|
386
|
+
error: true,
|
|
387
|
+
title: "No se logró comunicar con la red.",
|
|
388
|
+
type: "error",
|
|
389
|
+
description: `No hay comunicación con la red para el reintento - Validate Exists: ${responsePOSearch.userMsg}`,
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
const existentes = responsePOSearch?.data?.filter((x) => !x.voided);
|
|
393
|
+
if (existentes?.length > 0) {
|
|
394
|
+
const msg = `Ya existe una órden de compra con este número de contraseña asociado, revise el listado general. Peso: ${existentes[0].due}, Ingresado el: ${(0, common_1.getFormattedDate)(existentes[0].issue_date)}, Memo: ${existentes[0].memo}, Tipo: ${existentes[0].reference}`;
|
|
395
|
+
console.error(msg);
|
|
396
|
+
await (0, _4pinos_receptions_form_history_utils_js_1.updateQueueFormReceptionHistory)(headers, session, {
|
|
397
|
+
description: msg,
|
|
398
|
+
estado: _4pinos_receptions_form_history_utils_js_1.ESTADOS_COLA_RECEPCIONES.ERROR,
|
|
399
|
+
}, register.id);
|
|
400
|
+
return {
|
|
401
|
+
error: true,
|
|
402
|
+
title: "No se puede crear la órden de compra.",
|
|
403
|
+
type: "error",
|
|
404
|
+
description: msg,
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
const queueResponse = await (0, _4pinos_receptions_form_history_utils_js_1.updateQueueFormReceptionHistory)(headers, session, {
|
|
409
|
+
estado: _4pinos_receptions_form_history_utils_js_1.ESTADOS_COLA_RECEPCIONES.REINTENTANDO,
|
|
410
|
+
}, register.id);
|
|
411
|
+
if (queueResponse.error || !queueResponse.data?.id) {
|
|
412
|
+
return {
|
|
413
|
+
error: true,
|
|
414
|
+
title: "No se logró comunicar con la red.",
|
|
415
|
+
type: "error",
|
|
416
|
+
description: `No hay comunicación con la red para el reintento: ${queueResponse?.userMsg}`,
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
if (hostname.includes("localhost")) {
|
|
420
|
+
console.log("------- EJECUTANDO LOCALMENTE", ` para ${register.data?.formSubmited?.idNumberInput}`);
|
|
421
|
+
(0, exports.register4pinosReception)({
|
|
422
|
+
values: register.data?.formSubmited,
|
|
423
|
+
cookie,
|
|
424
|
+
idWebAppTable: register.id,
|
|
425
|
+
agency_id: register.data?.agency_id,
|
|
426
|
+
originApiResponses: register.data?.apiResponses,
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
else {
|
|
430
|
+
console.log("------- ENVIANDO A EJECUTAR NETLIFY FUNCTION: 4pinosNewPurchaseOrder-background", ` para ${register.data?.formSubmited?.idNumberInput}`);
|
|
431
|
+
fetch(`https://${hostname}/.netlify/functions/4pinosNewPurchaseOrder-background`, {
|
|
432
|
+
method: "post",
|
|
433
|
+
headers: { "Content-type": "application/json" },
|
|
434
|
+
body: JSON.stringify({
|
|
435
|
+
values: register.data?.formSubmited,
|
|
436
|
+
cookie,
|
|
437
|
+
idWebAppTable: register.id,
|
|
438
|
+
agency_id: register.data?.agency_id,
|
|
439
|
+
originApiResponses: register.data?.apiResponses,
|
|
440
|
+
}),
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
return {
|
|
444
|
+
error: false,
|
|
445
|
+
title: "Reintento iniciado con éxito.",
|
|
446
|
+
type: "success",
|
|
447
|
+
description: `Se está procesando el reintento de ingreso de recepción!.`,
|
|
448
|
+
};
|
|
449
|
+
};
|
|
450
|
+
exports.retryPO = retryPO;
|
|
@@ -4,6 +4,7 @@ exports.deleteQueueFormReceptionHistory = exports.updateQueueFormReceptionHistor
|
|
|
4
4
|
const common_1 = require("@zauru-sdk/common");
|
|
5
5
|
const services_1 = require("@zauru-sdk/services");
|
|
6
6
|
exports.ESTADOS_COLA_RECEPCIONES = {
|
|
7
|
+
INICIADO: "Iniciado",
|
|
7
8
|
EN_PROCESO: "En proceso",
|
|
8
9
|
ERROR: "Con error",
|
|
9
10
|
REINTENTANDO: "Reintentando",
|
|
@@ -61,6 +62,7 @@ const createQueueFormReceptionHistory = (headers, session, body) => {
|
|
|
61
62
|
]);
|
|
62
63
|
//Esto es para simular el tiempo de carga de la API nunca subir a producción
|
|
63
64
|
//await new Promise((resolve) => setTimeout(resolve, 7000));
|
|
65
|
+
//throw new Error("Error al crear el historial de colas");
|
|
64
66
|
const response = await (0, services_1.createWebAppTableRegister)(headers, queue_form_recepcion_submited_web_app_table_id, body);
|
|
65
67
|
return response;
|
|
66
68
|
});
|
|
@@ -11,6 +11,16 @@ export const register4pinosReception = async ({ cookie, idWebAppTable, agency_id
|
|
|
11
11
|
};
|
|
12
12
|
try {
|
|
13
13
|
if (apiResponses.apiCall === 1) {
|
|
14
|
+
const responseUpdate = await updateQueueFormReceptionHistory(headers, session, {
|
|
15
|
+
estado: ESTADOS_COLA_RECEPCIONES.EN_PROCESO,
|
|
16
|
+
}, idWebAppTable);
|
|
17
|
+
if (responseUpdate.error) {
|
|
18
|
+
throw new Error("Error al intentar actualizar el estado de la cola: " +
|
|
19
|
+
responseUpdate?.userMsg);
|
|
20
|
+
}
|
|
21
|
+
apiResponses.apiCall = apiResponses.apiCall + 1;
|
|
22
|
+
}
|
|
23
|
+
if (apiResponses.apiCall === 2) {
|
|
14
24
|
//SI EL API CALL ES DIFERENTE DE 1 SIGNIFICA QUE SOLO VA A REINTENTAR DESDE DONDE FALLÓ
|
|
15
25
|
//Validando que no exista ya una recepción con ese número:
|
|
16
26
|
const responsePOSearch = await getPurchasesOrderByIdNumber(session, values?.idNumberInput);
|
|
@@ -106,7 +116,7 @@ export const register4pinosReception = async ({ cookie, idWebAppTable, agency_id
|
|
|
106
116
|
};
|
|
107
117
|
let [received_baskets, qualityControlBaskets, detail_baskets, detail_discounts, detail_weights,] = processValues();
|
|
108
118
|
//========== PRIMERA LLAMADA DE API Y CAPTURA DE ERRORES
|
|
109
|
-
if (apiResponses.apiCall ===
|
|
119
|
+
if (apiResponses.apiCall === 2) {
|
|
110
120
|
console.log("========================================>");
|
|
111
121
|
console.log("paso 1: REGISTRANDO NUEVA ORDEN DE COMPRA AUTORIZADA...");
|
|
112
122
|
//build net_weights
|
|
@@ -162,7 +172,7 @@ export const register4pinosReception = async ({ cookie, idWebAppTable, agency_id
|
|
|
162
172
|
apiResponses.authorizedPO = newAuthorizedPurchaseResponse.data;
|
|
163
173
|
apiResponses.apiCall = apiResponses.apiCall + 1;
|
|
164
174
|
}
|
|
165
|
-
if (apiResponses.apiCall ===
|
|
175
|
+
if (apiResponses.apiCall === 3) {
|
|
166
176
|
const createNewReceptionBodyFunction = () => {
|
|
167
177
|
const receptionDetails = {};
|
|
168
178
|
apiResponses.authorizedPO.purchase_order_details.forEach((pod, index) => (receptionDetails[index] = {
|
|
@@ -200,7 +210,7 @@ export const register4pinosReception = async ({ cookie, idWebAppTable, agency_id
|
|
|
200
210
|
}
|
|
201
211
|
apiResponses.apiCall = apiResponses.apiCall + 1;
|
|
202
212
|
}
|
|
203
|
-
if (apiResponses.apiCall ===
|
|
213
|
+
if (apiResponses.apiCall === 4) {
|
|
204
214
|
console.log("------------- REALIZANDO ENVÍO DE CANASTAS A LA AGENCIA");
|
|
205
215
|
const createBasketsShipmentBodyFunction = () => {
|
|
206
216
|
const movementDetails = [];
|
|
@@ -233,7 +243,7 @@ export const register4pinosReception = async ({ cookie, idWebAppTable, agency_id
|
|
|
233
243
|
apiResponses.apiCall = apiResponses.apiCall + 1;
|
|
234
244
|
apiResponses.shipment = newShipmentResponse.data;
|
|
235
245
|
}
|
|
236
|
-
if (apiResponses.apiCall ===
|
|
246
|
+
if (apiResponses.apiCall === 5) {
|
|
237
247
|
console.log("------------- RECIBIENDO EL ENVÍO DE CANASTAS");
|
|
238
248
|
const getShipmentResponse = await getDeliveryByBooking(headers, apiResponses.shipment.id);
|
|
239
249
|
if (getShipmentResponse.error) {
|
|
@@ -245,10 +255,10 @@ export const register4pinosReception = async ({ cookie, idWebAppTable, agency_id
|
|
|
245
255
|
//Al momento de este comentario, un ejemplo es que sólo Planta Central no es centro de acopio
|
|
246
256
|
//Ellos si envían canastas a control de calidad.
|
|
247
257
|
//Si es de un centro de acopio, se salta esto...
|
|
248
|
-
if (apiResponses.apiCall ===
|
|
258
|
+
if (apiResponses.apiCall === 6 && qualityControlBaskets.length > 0) {
|
|
249
259
|
console.log("------------- REALIZANDO ENVÍO DE CANASTAS A CONTROL DE CALIDAD");
|
|
250
|
-
const total_qc_baskets =
|
|
251
|
-
const
|
|
260
|
+
const total_qc_baskets = Number(values.totalQCBaskets);
|
|
261
|
+
const netWeightByBasket = Number(netWeight) / total_qc_baskets;
|
|
252
262
|
const lotResponse = await getLoteByName(session, apiResponses.authorizedPO.id_number);
|
|
253
263
|
if (lotResponse.error || !lotResponse.data || !lotResponse.data.id) {
|
|
254
264
|
throw new Error("Error al intentar obtener el lote por nombre: " +
|
|
@@ -268,7 +278,7 @@ export const register4pinosReception = async ({ cookie, idWebAppTable, agency_id
|
|
|
268
278
|
qcMovementDetails.push({
|
|
269
279
|
item_id: apiResponses.authorizedPO.purchase_order_details[0].item_id,
|
|
270
280
|
lot_id: Number(lotResponse.data?.id),
|
|
271
|
-
booked_quantity:
|
|
281
|
+
booked_quantity: total_qc_baskets * netWeightByBasket,
|
|
272
282
|
reference: "Verduras a control de calidad.",
|
|
273
283
|
});
|
|
274
284
|
const qcBasketShipment = {
|
|
@@ -294,16 +304,18 @@ export const register4pinosReception = async ({ cookie, idWebAppTable, agency_id
|
|
|
294
304
|
apiResponses.apiCall = apiResponses.apiCall + 1;
|
|
295
305
|
apiResponses.qcShipment = new_qc_shipment_response.data;
|
|
296
306
|
}
|
|
297
|
-
if (apiResponses.apiCall ===
|
|
307
|
+
if (apiResponses.apiCall === 7) {
|
|
298
308
|
console.log("------------- RECIBIENDO ENVÍO DE CANASTAS A CONTROL DE CALIDAD");
|
|
299
309
|
const getQCDeliveryResponse = await getDeliveryByBooking(headers, apiResponses.qcShipment.id);
|
|
300
310
|
if (getQCDeliveryResponse.error) {
|
|
301
311
|
throw new Error("Error al intentar recibir el envío de control de calidad: " +
|
|
302
|
-
getQCDeliveryResponse?.userMsg
|
|
312
|
+
getQCDeliveryResponse?.userMsg +
|
|
313
|
+
" Body: " +
|
|
314
|
+
JSON.stringify(apiResponses.qcShipment));
|
|
303
315
|
}
|
|
304
316
|
apiResponses.apiCall = apiResponses.apiCall + 1;
|
|
305
317
|
}
|
|
306
|
-
if (apiResponses.apiCall ===
|
|
318
|
+
if (apiResponses.apiCall === 8 || qualityControlBaskets.length === 0) {
|
|
307
319
|
if (webapp_table_object.Canastas !== "" &&
|
|
308
320
|
webapp_table_object.Canastas !== "0") {
|
|
309
321
|
console.log("----------- Guardando rechazo de canastas directo...... -----------");
|
|
@@ -321,13 +333,13 @@ export const register4pinosReception = async ({ cookie, idWebAppTable, agency_id
|
|
|
321
333
|
}
|
|
322
334
|
}
|
|
323
335
|
}
|
|
324
|
-
|
|
336
|
+
else {
|
|
325
337
|
//Si es centro de acopio, guardo los motivos de rechazo
|
|
326
338
|
if (controlCalidadValues?.razonPrincipal ||
|
|
327
339
|
controlCalidadValues?.razonSecundaria ||
|
|
328
340
|
controlCalidadValues?.razonTerciaria ||
|
|
329
341
|
controlCalidadValues?.otrasRazones) {
|
|
330
|
-
if (apiResponses.apiCall ===
|
|
342
|
+
if (apiResponses.apiCall === 6) {
|
|
331
343
|
console.log("========================================>");
|
|
332
344
|
console.log("paso 3: GUARDAR MOTIVOS DE RECHAZO");
|
|
333
345
|
const saveMotivosResponse = await saveMotivosDeRechazoByPurchase(headers, session, {
|
|
@@ -352,6 +364,7 @@ export const register4pinosReception = async ({ cookie, idWebAppTable, agency_id
|
|
|
352
364
|
//SI OCURRE ALGÚN ERROR, SE INTENTA GUARDAR EL RETRY
|
|
353
365
|
console.log("========================================>");
|
|
354
366
|
console.log("paso -1: ACTUALIZAR EL REGISTRO DE LA COLA A ERROR");
|
|
367
|
+
console.error(`Error: ${e?.toString()}, idWebAppTable: ${idWebAppTable}`);
|
|
355
368
|
await updateQueueFormReceptionHistory(headers, session, {
|
|
356
369
|
estado: ESTADOS_COLA_RECEPCIONES.ERROR,
|
|
357
370
|
description: e?.toString(),
|
|
@@ -359,3 +372,74 @@ export const register4pinosReception = async ({ cookie, idWebAppTable, agency_id
|
|
|
359
372
|
}, idWebAppTable);
|
|
360
373
|
}
|
|
361
374
|
};
|
|
375
|
+
export const retryPO = async (register, session, headers, hostname, cookie) => {
|
|
376
|
+
console.log("REINTENTO DE REGISTRO DE ORDEN DE COMPRA =======================>");
|
|
377
|
+
if (!register.data.apiResponses || register.data.apiResponses.apiCall === 1) {
|
|
378
|
+
const responsePOSearch = await getPurchasesOrderByIdNumber(session, register.data?.formSubmited?.idNumberInput);
|
|
379
|
+
if (responsePOSearch.error || !responsePOSearch.data) {
|
|
380
|
+
console.error("Validate Exists: ", responsePOSearch.userMsg);
|
|
381
|
+
return {
|
|
382
|
+
error: true,
|
|
383
|
+
title: "No se logró comunicar con la red.",
|
|
384
|
+
type: "error",
|
|
385
|
+
description: `No hay comunicación con la red para el reintento - Validate Exists: ${responsePOSearch.userMsg}`,
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
const existentes = responsePOSearch?.data?.filter((x) => !x.voided);
|
|
389
|
+
if (existentes?.length > 0) {
|
|
390
|
+
const msg = `Ya existe una órden de compra con este número de contraseña asociado, revise el listado general. Peso: ${existentes[0].due}, Ingresado el: ${getFormattedDate(existentes[0].issue_date)}, Memo: ${existentes[0].memo}, Tipo: ${existentes[0].reference}`;
|
|
391
|
+
console.error(msg);
|
|
392
|
+
await updateQueueFormReceptionHistory(headers, session, {
|
|
393
|
+
description: msg,
|
|
394
|
+
estado: ESTADOS_COLA_RECEPCIONES.ERROR,
|
|
395
|
+
}, register.id);
|
|
396
|
+
return {
|
|
397
|
+
error: true,
|
|
398
|
+
title: "No se puede crear la órden de compra.",
|
|
399
|
+
type: "error",
|
|
400
|
+
description: msg,
|
|
401
|
+
};
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
const queueResponse = await updateQueueFormReceptionHistory(headers, session, {
|
|
405
|
+
estado: ESTADOS_COLA_RECEPCIONES.REINTENTANDO,
|
|
406
|
+
}, register.id);
|
|
407
|
+
if (queueResponse.error || !queueResponse.data?.id) {
|
|
408
|
+
return {
|
|
409
|
+
error: true,
|
|
410
|
+
title: "No se logró comunicar con la red.",
|
|
411
|
+
type: "error",
|
|
412
|
+
description: `No hay comunicación con la red para el reintento: ${queueResponse?.userMsg}`,
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
if (hostname.includes("localhost")) {
|
|
416
|
+
console.log("------- EJECUTANDO LOCALMENTE", ` para ${register.data?.formSubmited?.idNumberInput}`);
|
|
417
|
+
register4pinosReception({
|
|
418
|
+
values: register.data?.formSubmited,
|
|
419
|
+
cookie,
|
|
420
|
+
idWebAppTable: register.id,
|
|
421
|
+
agency_id: register.data?.agency_id,
|
|
422
|
+
originApiResponses: register.data?.apiResponses,
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
else {
|
|
426
|
+
console.log("------- ENVIANDO A EJECUTAR NETLIFY FUNCTION: 4pinosNewPurchaseOrder-background", ` para ${register.data?.formSubmited?.idNumberInput}`);
|
|
427
|
+
fetch(`https://${hostname}/.netlify/functions/4pinosNewPurchaseOrder-background`, {
|
|
428
|
+
method: "post",
|
|
429
|
+
headers: { "Content-type": "application/json" },
|
|
430
|
+
body: JSON.stringify({
|
|
431
|
+
values: register.data?.formSubmited,
|
|
432
|
+
cookie,
|
|
433
|
+
idWebAppTable: register.id,
|
|
434
|
+
agency_id: register.data?.agency_id,
|
|
435
|
+
originApiResponses: register.data?.apiResponses,
|
|
436
|
+
}),
|
|
437
|
+
});
|
|
438
|
+
}
|
|
439
|
+
return {
|
|
440
|
+
error: false,
|
|
441
|
+
title: "Reintento iniciado con éxito.",
|
|
442
|
+
type: "success",
|
|
443
|
+
description: `Se está procesando el reintento de ingreso de recepción!.`,
|
|
444
|
+
};
|
|
445
|
+
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { handlePossibleAxiosErrors } from "@zauru-sdk/common";
|
|
2
2
|
import { createWebAppTableRegister, deleteWebAppTableRegister, getVariablesByName, getWebAppRow, getWebAppTableRegisters, updateWebAppTableRegister, } from "@zauru-sdk/services";
|
|
3
3
|
export const ESTADOS_COLA_RECEPCIONES = {
|
|
4
|
+
INICIADO: "Iniciado",
|
|
4
5
|
EN_PROCESO: "En proceso",
|
|
5
6
|
ERROR: "Con error",
|
|
6
7
|
REINTENTANDO: "Reintentando",
|
|
@@ -56,6 +57,7 @@ export const createQueueFormReceptionHistory = (headers, session, body) => {
|
|
|
56
57
|
]);
|
|
57
58
|
//Esto es para simular el tiempo de carga de la API nunca subir a producción
|
|
58
59
|
//await new Promise((resolve) => setTimeout(resolve, 7000));
|
|
60
|
+
//throw new Error("Error al crear el historial de colas");
|
|
59
61
|
const response = await createWebAppTableRegister(headers, queue_form_recepcion_submited_web_app_table_id, body);
|
|
60
62
|
return response;
|
|
61
63
|
});
|
|
@@ -1 +1,9 @@
|
|
|
1
|
+
import { WebAppRowGraphQL, QueueFormReceptionWebAppTable } from "@zauru-sdk/types";
|
|
2
|
+
import { Session } from "@remix-run/node";
|
|
1
3
|
export declare const register4pinosReception: ({ cookie, idWebAppTable, agency_id, values, originApiResponses, }: any) => Promise<void>;
|
|
4
|
+
export declare const retryPO: (register: WebAppRowGraphQL<QueueFormReceptionWebAppTable>, session: Session, headers: any, hostname: string, cookie: string | null) => Promise<{
|
|
5
|
+
error: boolean;
|
|
6
|
+
title: string;
|
|
7
|
+
type: string;
|
|
8
|
+
description: string;
|
|
9
|
+
}>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Session } from "@remix-run/node";
|
|
2
2
|
import { AxiosUtilsResponse, QueueFormReceptionWebAppTable, WebAppRowGraphQL, WebAppTableUpdateResponse } from "@zauru-sdk/types";
|
|
3
3
|
export declare const ESTADOS_COLA_RECEPCIONES: {
|
|
4
|
+
INICIADO: string;
|
|
4
5
|
EN_PROCESO: string;
|
|
5
6
|
ERROR: string;
|
|
6
7
|
REINTENTANDO: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zauru-sdk/utils",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.113",
|
|
4
4
|
"description": "Utilidades, parseo de request y demás para desarrollo de webapps de Zauru",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"module": "./dist/esm/index.js",
|
|
@@ -31,5 +31,5 @@
|
|
|
31
31
|
"@zauru-sdk/services": "^1.0.110",
|
|
32
32
|
"@zauru-sdk/types": "^1.0.109"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "32d6e9f7c23ac5b58be802d23f007f86b4aea904"
|
|
35
35
|
}
|