@zauru-sdk/utils 2.0.221 → 2.0.223
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.
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { getDeliveryByBooking, getLote, getLotesFiltered, getPurchase, getPurchaseOrder, getVariablesByName, insertBookings, saveMotivosDeRechazoByPurchase, updateLote, updateReceivedPurchaseOrder, } from "@zauru-sdk/services";
|
|
1
|
+
import { getLote, getLotesFiltered, getPurchase, getVariablesByName, } from "@zauru-sdk/services";
|
|
3
2
|
import { getPurchaseOrderDataTables } from "./purchase-orders.utils.js";
|
|
4
3
|
/**
|
|
5
4
|
* Obtiene el listado de ordenes de compra, formateado especialmente para armar la tabla de edición de porcentajes de rechazo
|
|
@@ -21,238 +20,6 @@ export const getLotesFormated = async (headers, session) => {
|
|
|
21
20
|
}
|
|
22
21
|
return [];
|
|
23
22
|
};
|
|
24
|
-
/**
|
|
25
|
-
* procesarLote
|
|
26
|
-
* @param headers
|
|
27
|
-
* @param session
|
|
28
|
-
* @param data
|
|
29
|
-
* @param byPercent
|
|
30
|
-
*/
|
|
31
|
-
export const procesarLote = async (headers, session, data, poId) => {
|
|
32
|
-
return handlePossibleAxiosErrors(async () => {
|
|
33
|
-
//=====================================================================================
|
|
34
|
-
//=====================================================================================
|
|
35
|
-
//PASO 1: OBTENER TODAS LAS VARIABLES QUE VAMOS A UTILIZAR EN EL FLUJO
|
|
36
|
-
const { production_agency, operative_rejection_agency_id, recepciones_basket_item_id: basket_id, } = await getVariablesByName(headers, session, [
|
|
37
|
-
"production_agency",
|
|
38
|
-
"operative_rejection_agency_id",
|
|
39
|
-
"recepciones_basket_item_id",
|
|
40
|
-
]);
|
|
41
|
-
const session_agency_id = session.get("agency_id");
|
|
42
|
-
const hashObject = JSON.parse(operative_rejection_agency_id);
|
|
43
|
-
const op_rejection_agency_id = hashObject[session_agency_id];
|
|
44
|
-
//PARSEO DE LA INFORMACIÓN QUE VIENE DEL SUBMIT
|
|
45
|
-
const byPercent = data.byPercent === "true";
|
|
46
|
-
const porcentajeRechazo = !byPercent
|
|
47
|
-
? toFixedIfNeeded((Number(data.lbRechazo ?? "0") /
|
|
48
|
-
(Number(data?.lbRechazo ?? "0") + Number(data.lbBueno))) *
|
|
49
|
-
100)
|
|
50
|
-
: data.porcentajeRechazo;
|
|
51
|
-
const basket_keys = Object.keys(data).filter((x) => x.includes("basket-"));
|
|
52
|
-
const baskets_regresadas = basket_keys.map((basket_key) => {
|
|
53
|
-
//ejemplo de una key: basket-CONVENCIONAL-58281
|
|
54
|
-
const splited = basket_key.split("-");
|
|
55
|
-
return {
|
|
56
|
-
id: splited[2] || 0,
|
|
57
|
-
color: splited[1] || "",
|
|
58
|
-
total: Number(data[basket_key]) || 0,
|
|
59
|
-
};
|
|
60
|
-
});
|
|
61
|
-
//1.2 OBTENER LA INFORMACIÓN DEL LOTE A PROCESAR (LA TOMO DE LA QUE YA TENGO AL CARGAR LA INFO)
|
|
62
|
-
const purchaseOrderResponse = await getPurchaseOrder(session, poId, {
|
|
63
|
-
withLotStocksToMyAgency: true,
|
|
64
|
-
});
|
|
65
|
-
if (purchaseOrderResponse.error || !purchaseOrderResponse?.data) {
|
|
66
|
-
throw new Error(`Error al intentar encontrar la órden de compra: ${purchaseOrderResponse.userMsg}`);
|
|
67
|
-
}
|
|
68
|
-
const purchaseOrder = purchaseOrderResponse.data;
|
|
69
|
-
const lbsEsperadas = purchaseOrder.lots[0].lot_stocks[0].available;
|
|
70
|
-
const lbsMalas = Number(toFixedIfNeeded(lbsEsperadas * (Number(porcentajeRechazo) / 100)));
|
|
71
|
-
const lbsBuenas = Number(toFixedIfNeeded(lbsEsperadas - lbsMalas));
|
|
72
|
-
const baskets_memo = getBasketsSchema(purchaseOrder.memo);
|
|
73
|
-
const baskets_memo_quantity = baskets_memo
|
|
74
|
-
.map((basket) => basket.total)
|
|
75
|
-
.reduce(reduceAdd, 0);
|
|
76
|
-
//SI SE INGRESA POR LIBRAS, ES QUE SE ESTÁ INGRESANDO CANASTAS A DEVOLVER ETC Y HAY QUE HACER LOS ENVÍOS CORRESPONDIENTES
|
|
77
|
-
if (!byPercent) {
|
|
78
|
-
console.log("=============> PROCESANDO DATA POR PESO...");
|
|
79
|
-
//CUANDO NO ES POR PORCENTAJE DIRECTO HAY QUE HACER TODO EL FLUJO DE CREAR LOS ENVÍOS ETC...
|
|
80
|
-
//1.3: SE CREA EL ENVÍO DE VEGETALES Y CANASTAS DEVUELTOS POR CONTROL DE CALIDAD, (LOS QUE ESTÁN BUENOS)
|
|
81
|
-
//Las canastas vienen en data en campos como estos "basket-CONVENCIONAL-58281": "2",
|
|
82
|
-
const bodyGoodToProduction = {
|
|
83
|
-
booker_id: Number(session.get("employee_id")),
|
|
84
|
-
needs_transport: false,
|
|
85
|
-
payee_id: purchaseOrder.payee_id,
|
|
86
|
-
memo: `${purchaseOrder.lots[0].id};${purchaseOrder.id_number};${purchaseOrder.purchase_order_details[0]?.item?.name};${purchaseOrder.purchase_order_details
|
|
87
|
-
.map((purchase) => Number(purchase.booked_quantity))
|
|
88
|
-
.reduce(reduceAdd, 0)};${baskets_memo_quantity};${porcentajeRechazo};${purchaseOrder.delivery_date}`,
|
|
89
|
-
planned_delivery: `${data.date}`,
|
|
90
|
-
agency_from_id: Number(session_agency_id), //agencia donde está loggeado mi usuario
|
|
91
|
-
agency_to_id: purchaseOrder.agency_id, //de donde viene la orden de compra
|
|
92
|
-
reference: "Vegetales buenos devueltos desde control de calidad.",
|
|
93
|
-
movements: [
|
|
94
|
-
{
|
|
95
|
-
item_id: purchaseOrder.purchase_order_details[0].item_id,
|
|
96
|
-
lot_id: purchaseOrder.lots[0].id,
|
|
97
|
-
reference: "Vegetales devueltos de CC",
|
|
98
|
-
booked_quantity: lbsBuenas,
|
|
99
|
-
},
|
|
100
|
-
],
|
|
101
|
-
};
|
|
102
|
-
/**
|
|
103
|
-
* Para las canastas
|
|
104
|
-
* el item_id = 490533 = recepciones_basket_item_id
|
|
105
|
-
* lot_id: código de la canasta,
|
|
106
|
-
* booked_quantity = cantidad de canastas que ingresa el usuario que va a devolver
|
|
107
|
-
*/
|
|
108
|
-
baskets_regresadas.forEach((basket) => {
|
|
109
|
-
bodyGoodToProduction.movements.push({
|
|
110
|
-
item_id: Number(basket_id),
|
|
111
|
-
lot_id: basket.id,
|
|
112
|
-
reference: `Canasta ${basket.color}-${basket.id} devuelta a CC`,
|
|
113
|
-
booked_quantity: basket.total,
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
console.log("-------- Insertando booking con canastas buenas devueltas");
|
|
117
|
-
const goodVegetablesInserted = await insertBookings(headers, bodyGoodToProduction, `${purchaseOrder.id}`);
|
|
118
|
-
if (!goodVegetablesInserted.error && goodVegetablesInserted.data) {
|
|
119
|
-
//1.4 Recibir la reserva para que las cantidades se muevan correctamente a la bodega de destino
|
|
120
|
-
console.log("recibiendo la reserva: ", goodVegetablesInserted.data?.id);
|
|
121
|
-
await getDeliveryByBooking(headers, goodVegetablesInserted.data?.id);
|
|
122
|
-
}
|
|
123
|
-
if (lbsMalas && lbsMalas > 0) {
|
|
124
|
-
//=====================================================================================
|
|
125
|
-
//=====================================================================================
|
|
126
|
-
//PASO 2: Envío con vegetales rechazados a bodega de PRODUCCIÓN desde la agencia del usuario loggeado
|
|
127
|
-
const bodyOchToProduction = {
|
|
128
|
-
booker_id: Number(session.get("employee_id")),
|
|
129
|
-
needs_transport: false,
|
|
130
|
-
memo: "",
|
|
131
|
-
planned_delivery: `${data.date}`,
|
|
132
|
-
agency_from_id: Number(session_agency_id), //agencia donde está loggeado mi usuario
|
|
133
|
-
agency_to_id: Number(production_agency), //de donde viene la orden de compra
|
|
134
|
-
reference: "Envío de vegetales rechazados a la bodega de producción.",
|
|
135
|
-
movements: [
|
|
136
|
-
{
|
|
137
|
-
item_id: purchaseOrder.purchase_order_details[0].item_id,
|
|
138
|
-
lot_id: purchaseOrder.lots[0].id,
|
|
139
|
-
reference: "Vegetales rechazados de CC",
|
|
140
|
-
booked_quantity: lbsMalas,
|
|
141
|
-
},
|
|
142
|
-
],
|
|
143
|
-
};
|
|
144
|
-
console.log("--------- enviando a insertar booking de rechazo a la bodega de producción");
|
|
145
|
-
const ochToProductionVegetablesInserted = await insertBookings(headers, bodyOchToProduction, `${purchaseOrder.id}`);
|
|
146
|
-
if (!ochToProductionVegetablesInserted.error &&
|
|
147
|
-
ochToProductionVegetablesInserted.data) {
|
|
148
|
-
//2.1 Recibir la reserva para que las cantidades se muevan correctamente a la bodega de destino
|
|
149
|
-
console.log("Recibiendo booking de rechazo...");
|
|
150
|
-
await getDeliveryByBooking(headers, ochToProductionVegetablesInserted.data.id);
|
|
151
|
-
}
|
|
152
|
-
//=====================================================================================
|
|
153
|
-
//=====================================================================================
|
|
154
|
-
//PASO 3: Envío con vegetales rechazados a bodega de RECHAZO desde la bodega de PRODUCCIÓN
|
|
155
|
-
//Sólo cambia el agency_from_id y el agency_to_id, de ahí lo demás lo mismo que PASO 2
|
|
156
|
-
bodyOchToProduction.agency_from_id = Number(production_agency);
|
|
157
|
-
bodyOchToProduction.agency_to_id = Number(op_rejection_agency_id);
|
|
158
|
-
bodyOchToProduction.reference =
|
|
159
|
-
"Envío de vegetales rechazados a la bodega de rechazo.";
|
|
160
|
-
console.log("--------- enviando a insertar booking de rechazo a la bodega de rechazo");
|
|
161
|
-
const ochToOchVegetablesInserted = await insertBookings(headers, bodyOchToProduction);
|
|
162
|
-
if (!ochToOchVegetablesInserted.error &&
|
|
163
|
-
ochToOchVegetablesInserted.data) {
|
|
164
|
-
//3.1 Recibir la reserva para que las cantidades se muevan correctamente a la bodega de destino
|
|
165
|
-
await getDeliveryByBooking(headers, ochToOchVegetablesInserted.data?.id);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
//=====================================================================================
|
|
169
|
-
//=====================================================================================
|
|
170
|
-
//PASO 5: Modificación de canastas en el lote de verdura
|
|
171
|
-
//la misma description del detalle del lote pero modificando la cantidad de canastas que quedaron.
|
|
172
|
-
//ejemplo: original: 27-53311-VERDE,1-53313-ROJA,1-53317-CELESTE,3-53312-AZUL,3-53314-AMARILLA
|
|
173
|
-
//ahora: 27-53311-VERDE,1-53313-ROJA,1-53317-CELESTE,2-53312-AZUL,3-53314-AMARILLA // ahora sólo 2 azules porque no devolví una
|
|
174
|
-
const newDescriptions = [];
|
|
175
|
-
baskets_memo.forEach((basket) => {
|
|
176
|
-
//Si existe una basket a regresar con el mismo id, pregunto cuantas va a regresar, para restarlas del total.
|
|
177
|
-
const basket_regresada = baskets_regresadas.find((x) => x.id === basket.id);
|
|
178
|
-
const resta = basket_regresada?.total ?? 0;
|
|
179
|
-
newDescriptions.push(`${basket.total - resta}-${basket.id}-${basket.color}`);
|
|
180
|
-
});
|
|
181
|
-
await updateLote(headers, purchaseOrder.lots[0].id, {
|
|
182
|
-
lot: {
|
|
183
|
-
description: newDescriptions.join(","),
|
|
184
|
-
},
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
else {
|
|
188
|
-
console.log("PROCESANDO DATA POR PORCENTAJE...");
|
|
189
|
-
//CUANDO NO ES POR PORCENTAJE DIRECTO HAY QUE HACER TODO EL FLUJO DE CREAR LOS ENVÍOS ETC...
|
|
190
|
-
//1.3: SE CREA EL ENVÍO DE VEGETALES Y CANASTAS DEVUELTOS POR CONTROL DE CALIDAD, (LOS QUE ESTÁN BUENOS)
|
|
191
|
-
//Las canastas vienen en data en campos como estos "basket-CONVENCIONAL-58281": "2",
|
|
192
|
-
const bodyGoodToProduction = {
|
|
193
|
-
booker_id: Number(session.get("employee_id")),
|
|
194
|
-
needs_transport: false,
|
|
195
|
-
payee_id: purchaseOrder.payee_id,
|
|
196
|
-
memo: `${purchaseOrder.lots[0].id};${purchaseOrder.lots[0].name};${purchaseOrder.purchase_order_details[0]?.item?.name};${purchaseOrder.purchase_order_details
|
|
197
|
-
.map((detail) => Number(detail.booked_quantity))
|
|
198
|
-
.reduce(reduceAdd, 0)};${baskets_memo_quantity};${porcentajeRechazo};${purchaseOrder.delivery_date}`,
|
|
199
|
-
planned_delivery: `${data.date}`,
|
|
200
|
-
agency_from_id: Number(session_agency_id), //agencia donde está loggeado mi usuario
|
|
201
|
-
agency_to_id: purchaseOrder.agency_id, //de donde viene la orden de compra
|
|
202
|
-
reference: "Regreando vegetales buenos desde control de calidad.",
|
|
203
|
-
movements: [
|
|
204
|
-
{
|
|
205
|
-
item_id: purchaseOrder.purchase_order_details[0].item_id,
|
|
206
|
-
lot_id: purchaseOrder.lots[0].id,
|
|
207
|
-
reference: "Vegetales devueltos de CC",
|
|
208
|
-
booked_quantity: lbsEsperadas, //devuelvo la misma cantidad que fue enviada
|
|
209
|
-
},
|
|
210
|
-
],
|
|
211
|
-
};
|
|
212
|
-
/**
|
|
213
|
-
* Para las canastas
|
|
214
|
-
* el item_id = 490533 = recepciones_basket_item_id
|
|
215
|
-
* lot_id: código de la canasta,
|
|
216
|
-
* booked_quantity = cantidad de canastas que ingresa el usuario que va a devolver
|
|
217
|
-
*/
|
|
218
|
-
//Todas las canastas que fueron enviadas originalmente
|
|
219
|
-
baskets_memo.forEach((basket) => {
|
|
220
|
-
bodyGoodToProduction.movements.push({
|
|
221
|
-
item_id: Number(basket_id),
|
|
222
|
-
lot_id: basket.id,
|
|
223
|
-
reference: `Canasta ${basket.color}-${basket.id} devuelta a CC`,
|
|
224
|
-
booked_quantity: basket.total,
|
|
225
|
-
});
|
|
226
|
-
});
|
|
227
|
-
console.log("-------- Insertando booking con canastas buenas devueltas");
|
|
228
|
-
const goodVegetablesInserted = await insertBookings(headers, bodyGoodToProduction, `${purchaseOrder.id}`);
|
|
229
|
-
//1.4 Recibir la reserva para que las cantidades se muevan correctamente a la bodega de destino
|
|
230
|
-
if (!goodVegetablesInserted.error && goodVegetablesInserted.data) {
|
|
231
|
-
console.log("A RECIBIR BOOKING - POR PORCENTAJE");
|
|
232
|
-
await getDeliveryByBooking(headers, goodVegetablesInserted.data.id);
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
//=====================================================================================
|
|
236
|
-
//=====================================================================================
|
|
237
|
-
//PASO 4: Modificación de porcentaje de rechazo en la orden de compra
|
|
238
|
-
//4.3 Editar porcentajes de rechazo
|
|
239
|
-
const updateBodyPurchase = {
|
|
240
|
-
purchase_order: { discount: porcentajeRechazo },
|
|
241
|
-
};
|
|
242
|
-
await updateReceivedPurchaseOrder(headers, updateBodyPurchase, purchaseOrder.id);
|
|
243
|
-
//=====================================================================================
|
|
244
|
-
//=====================================================================================
|
|
245
|
-
//PASO 6: Guardar razones de rechazo en webapp table
|
|
246
|
-
await saveMotivosDeRechazoByPurchase(headers, session, {
|
|
247
|
-
Razon_primaria: `${data.razonPrincipal ?? ""}`,
|
|
248
|
-
Razon_secundaria: `${data.razonSecundaria ?? ""}`,
|
|
249
|
-
Razon_terciaria: `${data.razonTerciaria ?? ""}`,
|
|
250
|
-
Canastas: `${data.ochBaskets ?? ""}`,
|
|
251
|
-
}, {
|
|
252
|
-
temp_purchase_order_id: `${purchaseOrder.id}`,
|
|
253
|
-
});
|
|
254
|
-
});
|
|
255
|
-
};
|
|
256
23
|
/**
|
|
257
24
|
* Obtiene toda la información de lote, con las canastas y razones de rechazo
|
|
258
25
|
* @param headers
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Session } from "@remix-run/node";
|
|
2
|
-
import {
|
|
2
|
+
import { BasketSchema } from "@zauru-sdk/types";
|
|
3
3
|
/**
|
|
4
4
|
* Obtiene el listado de ordenes de compra, formateado especialmente para armar la tabla de edición de porcentajes de rechazo
|
|
5
5
|
* @param headers
|
|
@@ -7,14 +7,6 @@ import { AxiosUtilsResponse, BasketSchema } from "@zauru-sdk/types";
|
|
|
7
7
|
* @returns
|
|
8
8
|
*/
|
|
9
9
|
export declare const getLotesFormated: (headers: any, session: Session) => Promise<import("@zauru-sdk/types").LoteSchema[]>;
|
|
10
|
-
/**
|
|
11
|
-
* procesarLote
|
|
12
|
-
* @param headers
|
|
13
|
-
* @param session
|
|
14
|
-
* @param data
|
|
15
|
-
* @param byPercent
|
|
16
|
-
*/
|
|
17
|
-
export declare const procesarLote: (headers: any, session: Session, data: any, poId: number | string) => Promise<AxiosUtilsResponse<any>>;
|
|
18
10
|
/**
|
|
19
11
|
* Obtiene toda la información de lote, con las canastas y razones de rechazo
|
|
20
12
|
* @param headers
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zauru-sdk/utils",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.223",
|
|
4
4
|
"description": "Utilidades, parseo de request y demás para desarrollo de webapps de Zauru",
|
|
5
5
|
"main": "./dist/esm/index.js",
|
|
6
6
|
"module": "./dist/esm/index.js",
|
|
@@ -24,11 +24,11 @@
|
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@remix-run/node": "^2.8.1",
|
|
27
|
-
"@zauru-sdk/common": "^2.0.
|
|
27
|
+
"@zauru-sdk/common": "^2.0.223",
|
|
28
28
|
"@zauru-sdk/config": "^2.0.220",
|
|
29
|
-
"@zauru-sdk/graphql": "^2.0.
|
|
30
|
-
"@zauru-sdk/services": "^2.0.
|
|
31
|
-
"@zauru-sdk/types": "^2.0.
|
|
29
|
+
"@zauru-sdk/graphql": "^2.0.223",
|
|
30
|
+
"@zauru-sdk/services": "^2.0.223",
|
|
31
|
+
"@zauru-sdk/types": "^2.0.223"
|
|
32
32
|
},
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "6315d069c4c276a87f7384947e01fe2420f1eab3"
|
|
34
34
|
}
|