@zauru-sdk/utils 1.0.50 → 1.0.52
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/index.js +40 -0
- package/dist/cjs/zauru/4pinos-receptions-form-history.utils.js +80 -0
- package/dist/cjs/zauru/automatic-number.utils.js +28 -0
- package/dist/cjs/zauru/bitacora-edicion-masiva.utils.js +56 -0
- package/dist/cjs/zauru/bundles.utils.js +168 -0
- package/dist/cjs/zauru/cases.utils.js +21 -0
- package/dist/cjs/zauru/consolidated-history.utils.js +58 -0
- package/dist/cjs/zauru/costos-items.utils.js +617 -0
- package/dist/cjs/zauru/deliveries.utils.js +50 -0
- package/dist/cjs/zauru/discharges-histsory.utils.js +52 -0
- package/dist/cjs/zauru/employees.utils.js +44 -0
- package/dist/cjs/zauru/form.utils.js +160 -0
- package/dist/cjs/zauru/invoices.utils.js +85 -0
- package/dist/cjs/zauru/items.utils.js +126 -0
- package/dist/cjs/zauru/lotes.utils.js +313 -0
- package/dist/cjs/zauru/motivos-rechazo.utils.js +23 -0
- package/dist/cjs/zauru/payees.utils.js +136 -0
- package/dist/cjs/zauru/profiles.utils.js +41 -0
- package/dist/cjs/zauru/providers.utils.js +40 -0
- package/dist/cjs/zauru/purchase-orders.utils.js +390 -0
- package/dist/cjs/zauru/shipments.utils.js +95 -0
- package/dist/cjs/zauru/specialItem.utils.js +69 -0
- package/dist/cjs/zauru/templates.utils.js +102 -0
- package/dist/cjs/zauru/tiposMuestra.utils.js +69 -0
- package/dist/cjs/zauru/webapp-tables.utils.js +20 -0
- package/package.json +12 -9
- package/CHANGELOG.md +0 -256
- package/src/index.ts +0 -24
- package/src/zauru/4pinos-receptions-form-history.utils.ts +0 -142
- package/src/zauru/automatic-number.utils.ts +0 -38
- package/src/zauru/bitacora-edicion-masiva.utils.ts +0 -99
- package/src/zauru/bundles.utils.ts +0 -251
- package/src/zauru/cases.utils.ts +0 -31
- package/src/zauru/consolidated-history.utils.ts +0 -102
- package/src/zauru/costos-items.utils.ts +0 -871
- package/src/zauru/deliveries.utils.ts +0 -77
- package/src/zauru/discharges-histsory.utils.ts +0 -105
- package/src/zauru/employees.utils.ts +0 -59
- package/src/zauru/form.utils.ts +0 -243
- package/src/zauru/invoices.utils.ts +0 -114
- package/src/zauru/items.utils.ts +0 -221
- package/src/zauru/lotes.utils.ts +0 -411
- package/src/zauru/motivos-rechazo.utils.ts +0 -47
- package/src/zauru/payees.utils.ts +0 -213
- package/src/zauru/profiles.utils.ts +0 -44
- package/src/zauru/providers.utils.ts +0 -67
- package/src/zauru/purchase-orders.utils.ts +0 -594
- package/src/zauru/shipments.utils.ts +0 -139
- package/src/zauru/specialItem.utils.ts +0 -136
- package/src/zauru/templates.utils.ts +0 -199
- package/src/zauru/tiposMuestra.utils.ts +0 -136
- package/src/zauru/webapp-tables.utils.ts +0 -36
- package/tsconfig.json +0 -24
- /package/dist/{index.js → esm/index.js} +0 -0
- /package/dist/{zauru → esm/zauru}/4pinos-receptions-form-history.utils.js +0 -0
- /package/dist/{zauru → esm/zauru}/automatic-number.utils.js +0 -0
- /package/dist/{zauru → esm/zauru}/bitacora-edicion-masiva.utils.js +0 -0
- /package/dist/{zauru → esm/zauru}/bundles.utils.js +0 -0
- /package/dist/{zauru → esm/zauru}/cases.utils.js +0 -0
- /package/dist/{zauru → esm/zauru}/consolidated-history.utils.js +0 -0
- /package/dist/{zauru → esm/zauru}/costos-items.utils.js +0 -0
- /package/dist/{zauru → esm/zauru}/deliveries.utils.js +0 -0
- /package/dist/{zauru → esm/zauru}/discharges-histsory.utils.js +0 -0
- /package/dist/{zauru → esm/zauru}/employees.utils.js +0 -0
- /package/dist/{zauru → esm/zauru}/form.utils.js +0 -0
- /package/dist/{zauru → esm/zauru}/invoices.utils.js +0 -0
- /package/dist/{zauru → esm/zauru}/items.utils.js +0 -0
- /package/dist/{zauru → esm/zauru}/lotes.utils.js +0 -0
- /package/dist/{zauru → esm/zauru}/motivos-rechazo.utils.js +0 -0
- /package/dist/{zauru → esm/zauru}/payees.utils.js +0 -0
- /package/dist/{zauru → esm/zauru}/profiles.utils.js +0 -0
- /package/dist/{zauru → esm/zauru}/providers.utils.js +0 -0
- /package/dist/{zauru → esm/zauru}/purchase-orders.utils.js +0 -0
- /package/dist/{zauru → esm/zauru}/shipments.utils.js +0 -0
- /package/dist/{zauru → esm/zauru}/specialItem.utils.js +0 -0
- /package/dist/{zauru → esm/zauru}/templates.utils.js +0 -0
- /package/dist/{zauru → esm/zauru}/tiposMuestra.utils.js +0 -0
- /package/dist/{zauru → esm/zauru}/webapp-tables.utils.js +0 -0
|
@@ -0,0 +1,617 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getCostosBitacora = exports.updateBitacoraCostos = exports.saveBitacoraCostos = exports.corregirCostos = exports.changePrices = exports.changePrice = exports.changePricesInit = exports.updateOneItemPrice = exports.obtenerSemanaAnterior = exports.guardarConfiguracionProductosEspeciales = void 0;
|
|
7
|
+
const common_1 = require("@zauru-sdk/common");
|
|
8
|
+
const moment_1 = __importDefault(require("moment"));
|
|
9
|
+
const specialItem_utils_js_1 = require("./specialItem.utils.js");
|
|
10
|
+
const services_1 = require("@zauru-sdk/services");
|
|
11
|
+
const purchase_orders_utils_js_1 = require("./purchase-orders.utils.js");
|
|
12
|
+
/**
|
|
13
|
+
*
|
|
14
|
+
* @param headers
|
|
15
|
+
* @param session
|
|
16
|
+
* @param configuration
|
|
17
|
+
* @param specialItems
|
|
18
|
+
*/
|
|
19
|
+
const guardarConfiguracionProductosEspeciales = (headers, session, configuration, specialItems) => {
|
|
20
|
+
return (0, common_1.handlePossibleAxiosErrors)(async () => {
|
|
21
|
+
specialItems?.forEach(async (x) => {
|
|
22
|
+
if (!configuration.some((y) => y.id === x.id)) {
|
|
23
|
+
//Elimino los que ya no están
|
|
24
|
+
const response = await (0, specialItem_utils_js_1.updateSpecialItem)(headers, session, x.id.toString(), {
|
|
25
|
+
...x.data,
|
|
26
|
+
fechaEliminacion: (0, moment_1.default)().format("DD/MM/YYYY HH:mm:ss"),
|
|
27
|
+
});
|
|
28
|
+
if (response.error) {
|
|
29
|
+
throw new Error(`Ocurrió un error al intentar eliminar un item especial. - ${response.userMsg ?? ""}`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
configuration.forEach(async (x) => {
|
|
34
|
+
if (typeof x.id === "string") {
|
|
35
|
+
//Creación
|
|
36
|
+
const response = await (0, specialItem_utils_js_1.createSpecialItem)(headers, session, {
|
|
37
|
+
...x,
|
|
38
|
+
});
|
|
39
|
+
if (response.error) {
|
|
40
|
+
throw new Error(`Ocurrió un error al intentar guardar la configuración de items especiales. - ${response.userMsg ?? ""}`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
//actualización
|
|
45
|
+
const response = await (0, specialItem_utils_js_1.updateSpecialItem)(headers, session, x.id.toString(), {
|
|
46
|
+
...x,
|
|
47
|
+
});
|
|
48
|
+
if (response.error) {
|
|
49
|
+
throw new Error(`Ocurrió un error al intentar actualizar un item especial. - ${response.userMsg ?? ""}`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
return true;
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
exports.guardarConfiguracionProductosEspeciales = guardarConfiguracionProductosEspeciales;
|
|
57
|
+
/**
|
|
58
|
+
*
|
|
59
|
+
* @returns
|
|
60
|
+
*/
|
|
61
|
+
const obtenerSemanaAnterior = () => {
|
|
62
|
+
const hoy = (0, moment_1.default)();
|
|
63
|
+
const semanaAnterior = hoy.clone().subtract(7, "days");
|
|
64
|
+
const fechaInicio = semanaAnterior.clone().startOf("isoWeek");
|
|
65
|
+
const fechaInicioFormateada = fechaInicio.format("YYYY/MM/DD");
|
|
66
|
+
const fechaFin = fechaInicio.clone().endOf("isoWeek");
|
|
67
|
+
const fechaFinFormateada = fechaFin.format("YYYY/MM/DD");
|
|
68
|
+
const label = "Semana anterior, del Lunes " +
|
|
69
|
+
fechaInicio.date() +
|
|
70
|
+
" al Domingo " +
|
|
71
|
+
fechaFin.date() +
|
|
72
|
+
", de " +
|
|
73
|
+
fechaInicio.format("MMMM") +
|
|
74
|
+
" de " +
|
|
75
|
+
fechaInicio.year();
|
|
76
|
+
return {
|
|
77
|
+
fechaInicio: fechaInicioFormateada,
|
|
78
|
+
fechaFin: fechaFinFormateada,
|
|
79
|
+
label: label,
|
|
80
|
+
getDay: (dayIndex) => {
|
|
81
|
+
if (dayIndex < 0 || dayIndex > 6) {
|
|
82
|
+
throw new Error("Day index must be between 0 (Monday) and 6 (Sunday).");
|
|
83
|
+
}
|
|
84
|
+
const targetDate = fechaInicio.clone().add(dayIndex, "days");
|
|
85
|
+
return targetDate.format("YYYY/MM/DD");
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
exports.obtenerSemanaAnterior = obtenerSemanaAnterior;
|
|
90
|
+
const getPriceByDate = (date, fechas, costo) => {
|
|
91
|
+
const originDate = new Date(date).setHours(0, 0, 0, 0);
|
|
92
|
+
const lunesDate = new Date(fechas.lunes).setHours(0, 0, 0, 0);
|
|
93
|
+
const martesDate = new Date(fechas.martes).setHours(0, 0, 0, 0);
|
|
94
|
+
const miercolesDate = new Date(fechas.miercoles).setHours(0, 0, 0, 0);
|
|
95
|
+
const juevesDate = new Date(fechas.jueves).setHours(0, 0, 0, 0);
|
|
96
|
+
const viernesDate = new Date(fechas.viernes).setHours(0, 0, 0, 0);
|
|
97
|
+
const sabadoDate = new Date(fechas.sabado).setHours(0, 0, 0, 0);
|
|
98
|
+
const domingoDate = new Date(fechas.domingo).setHours(0, 0, 0, 0);
|
|
99
|
+
if (originDate === lunesDate || originDate === martesDate) {
|
|
100
|
+
return costo?.lunMar ?? 1;
|
|
101
|
+
}
|
|
102
|
+
else if (originDate === miercolesDate || originDate === juevesDate) {
|
|
103
|
+
return costo?.mieJue ?? 1;
|
|
104
|
+
}
|
|
105
|
+
else if (originDate === viernesDate ||
|
|
106
|
+
originDate === sabadoDate ||
|
|
107
|
+
originDate === domingoDate) {
|
|
108
|
+
return costo?.vieSabDom ?? 1;
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
return 1;
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
const logTotal = (total) => {
|
|
115
|
+
console.log("========================================================================");
|
|
116
|
+
console.log("========================================================================");
|
|
117
|
+
console.log("========================================================================");
|
|
118
|
+
console.log("========================================================================");
|
|
119
|
+
console.log(`A PUNTO DE ACTUALIZAR: ${total} órdenes de compra`);
|
|
120
|
+
console.log("========================================================================");
|
|
121
|
+
console.log("========================================================================");
|
|
122
|
+
console.log("========================================================================");
|
|
123
|
+
console.log("========================================================================");
|
|
124
|
+
};
|
|
125
|
+
/**
|
|
126
|
+
* updateOneItemPrice
|
|
127
|
+
* @param headers
|
|
128
|
+
* @param session
|
|
129
|
+
* @param body
|
|
130
|
+
* @returns
|
|
131
|
+
*/
|
|
132
|
+
const updateOneItemPrice = (headers, session, body) => {
|
|
133
|
+
return (0, common_1.handlePossibleAxiosErrors)(async () => {
|
|
134
|
+
//PASO 1
|
|
135
|
+
//Obtengo todas las órdenes de compra dentro del rango de fechas
|
|
136
|
+
const fechaInicio = (0, common_1.localDateToUSDate)(body.fechaInicio);
|
|
137
|
+
const fechaFin = (0, common_1.localDateToUSDate)(body.fechaFin);
|
|
138
|
+
console.log(`==============================> OBTENIENDO ÓRDENES DE COMPRA EN EL RANGO ${fechaInicio} - ${fechaFin}`);
|
|
139
|
+
const allPurchases = await (0, services_1.getPurchasesList)(headers, session, {
|
|
140
|
+
fechaInicio: fechaInicio,
|
|
141
|
+
fechaFin: fechaFin,
|
|
142
|
+
});
|
|
143
|
+
console.log("ORDENES DE COMPRA OBTENIDAS: ", allPurchases.data?.length);
|
|
144
|
+
if (allPurchases.error || !allPurchases.data) {
|
|
145
|
+
//TODO: REGISTRAR EL FALLO EN LA ACTUALIZACIÓN
|
|
146
|
+
return "error";
|
|
147
|
+
}
|
|
148
|
+
//PASO 2
|
|
149
|
+
//Por cada órden de compra, voy a buscar su item para verificar el precio a colocarle en el día que fue emitida
|
|
150
|
+
//Obtengo todos los id's de las órdenes de compra en ese rango de fechas
|
|
151
|
+
const costosWithPurchaseIds = [];
|
|
152
|
+
const purchaseIterations = allPurchases.data.filter((x) => x.purchase_order_details.some((y) => y.item_id === body.item));
|
|
153
|
+
for (const purchase of purchaseIterations) {
|
|
154
|
+
const purchase_order_details = purchase.purchase_order_details.map((details) => {
|
|
155
|
+
return {
|
|
156
|
+
id: details.id,
|
|
157
|
+
item_id: details.item_id,
|
|
158
|
+
unit_cost: body.price,
|
|
159
|
+
};
|
|
160
|
+
});
|
|
161
|
+
costosWithPurchaseIds.push({
|
|
162
|
+
id: purchase.id,
|
|
163
|
+
fecha: purchase.created_at,
|
|
164
|
+
finalizado: true,
|
|
165
|
+
msgResultado: "",
|
|
166
|
+
purchase_order_details,
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
//PASO 3
|
|
170
|
+
//Editar los precios de todas las órdenes de compra
|
|
171
|
+
logTotal(costosWithPurchaseIds.length);
|
|
172
|
+
for (let i = 0; i < costosWithPurchaseIds.length; i++) {
|
|
173
|
+
const x = costosWithPurchaseIds[i];
|
|
174
|
+
console.log(`==============================> ACTUALIZANDO ÓRDEN DE COMPRA: ID: ${x.id} PRICE: ${x.purchase_order_details
|
|
175
|
+
.map((x) => x.unit_cost)
|
|
176
|
+
.join(",")} ID_ITEM: ${x.purchase_order_details
|
|
177
|
+
.map((x) => x.item_id)
|
|
178
|
+
.join(",")}`);
|
|
179
|
+
const updateResponse = await (0, purchase_orders_utils_js_1.updatePurchaseItemPrice)(headers, {
|
|
180
|
+
purchase_order_details_attributes: {
|
|
181
|
+
...x.purchase_order_details
|
|
182
|
+
.map((detail, index) => {
|
|
183
|
+
return {
|
|
184
|
+
[`${index}`]: {
|
|
185
|
+
id: detail.id,
|
|
186
|
+
item_id: detail.item_id,
|
|
187
|
+
unit_cost: detail.unit_cost,
|
|
188
|
+
},
|
|
189
|
+
};
|
|
190
|
+
})
|
|
191
|
+
.reduce((acc, curr) => Object.assign(acc, curr), {}),
|
|
192
|
+
},
|
|
193
|
+
}, x.id);
|
|
194
|
+
if (updateResponse.error) {
|
|
195
|
+
// Si hay error
|
|
196
|
+
costosWithPurchaseIds[i].finalizado = false;
|
|
197
|
+
costosWithPurchaseIds[i].msgResultado =
|
|
198
|
+
updateResponse.userMsg ?? JSON.stringify(updateResponse);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
//PASO 4
|
|
202
|
+
//Guardo la bitácora de cambios
|
|
203
|
+
console.log(`==============================> GUARDANDO BITÁCORA DE CAMBIOS`);
|
|
204
|
+
const response = await (0, exports.saveBitacoraCostos)(headers, session, {
|
|
205
|
+
costosEspeciales: [
|
|
206
|
+
{ specialItemId: body.item, lunMar: 1, mieJue: 1, vieSabDom: 1 },
|
|
207
|
+
],
|
|
208
|
+
accion: "Costos individualmente",
|
|
209
|
+
fechaCreacion: (0, moment_1.default)().format("DD/MM/YYYY HH:mm:ss"),
|
|
210
|
+
fechas: {
|
|
211
|
+
lunes: "",
|
|
212
|
+
martes: "",
|
|
213
|
+
miercoles: "",
|
|
214
|
+
jueves: "",
|
|
215
|
+
viernes: "",
|
|
216
|
+
sabado: "",
|
|
217
|
+
domingo: "",
|
|
218
|
+
},
|
|
219
|
+
modificadoPor: session.get("name"),
|
|
220
|
+
costos: [{ item: body.item, lunMar: 1, mieJue: 1, vieSabDom: 1 }],
|
|
221
|
+
costosActualizados: costosWithPurchaseIds,
|
|
222
|
+
costosEspecialesActualizados: [],
|
|
223
|
+
});
|
|
224
|
+
if (response.error || !response.data) {
|
|
225
|
+
throw new Error(response.userMsg ??
|
|
226
|
+
"Respuesta vacía de saveBitacoraCostos en updateOneItemPrice");
|
|
227
|
+
}
|
|
228
|
+
return response.data;
|
|
229
|
+
});
|
|
230
|
+
};
|
|
231
|
+
exports.updateOneItemPrice = updateOneItemPrice;
|
|
232
|
+
/**
|
|
233
|
+
* changePricesInit
|
|
234
|
+
* @param headers
|
|
235
|
+
* @param session
|
|
236
|
+
* @param specialItems
|
|
237
|
+
* @param body
|
|
238
|
+
* @returns
|
|
239
|
+
*/
|
|
240
|
+
const changePricesInit = (headers, session, specialItems, body) => {
|
|
241
|
+
return (0, common_1.handlePossibleAxiosErrors)(async () => {
|
|
242
|
+
//PASO 1
|
|
243
|
+
//Obtengo todas las órdenes de compra dentro del rango de fechas
|
|
244
|
+
console.log("=======================> FECHAS: ", body.fechas);
|
|
245
|
+
const fechaInicio = body.fechas.lunes;
|
|
246
|
+
const fechaFin = body.fechas.domingo;
|
|
247
|
+
console.log(`==============================> OBTENIENDO ÓRDENES DE COMPRA EN EL RANGO ${fechaInicio} - ${fechaFin}`);
|
|
248
|
+
const allPurchases = await (0, services_1.getPurchasesList)(headers, session, {
|
|
249
|
+
fechaInicio: fechaInicio,
|
|
250
|
+
fechaFin: fechaFin,
|
|
251
|
+
});
|
|
252
|
+
if (allPurchases.error || !allPurchases.data) {
|
|
253
|
+
throw new Error(`Error al ubicar las órdenes de compra en el rango de fechas establecido: ${allPurchases.userMsg}`);
|
|
254
|
+
}
|
|
255
|
+
//PASO 2
|
|
256
|
+
//Por cada órden de compra, voy a buscar su item para verificar el precio a colocarle en el día que fue emitida
|
|
257
|
+
//Obtengo todos los id's de las órdenes de compra en ese rango de fechas
|
|
258
|
+
const costosWithPurchaseIds = [];
|
|
259
|
+
const costosEspecialesWithPurchaseIds = []; //Para las verduras especiales
|
|
260
|
+
ForPrincipal: for (const purchase of allPurchases.data) {
|
|
261
|
+
//Pregunto si la órden de compra coincide con alguno de los casos especiales
|
|
262
|
+
for (const costoEspecial of body.costosEspeciales) {
|
|
263
|
+
//Ubico la configuración de item especial.
|
|
264
|
+
const specialItem = specialItems.find((x) => x.id === costoEspecial.specialItemId);
|
|
265
|
+
for (const details of purchase.purchase_order_details) {
|
|
266
|
+
//Tengo que preguntar por proveedor, region, categoría de proveedores, tipo e item.
|
|
267
|
+
if (specialItem?.data.region === purchase.incoterm_destination &&
|
|
268
|
+
specialItem?.data?.tipo === purchase.reference &&
|
|
269
|
+
specialItem.data.item === details.item_id) {
|
|
270
|
+
const costo = body.costosEspeciales.find((x) => x.specialItemId === specialItem.id);
|
|
271
|
+
const price = getPriceByDate(purchase.created_at, body.fechas, costo);
|
|
272
|
+
costosWithPurchaseIds.push({
|
|
273
|
+
id: purchase.id,
|
|
274
|
+
fecha: purchase.created_at,
|
|
275
|
+
purchase_order_details: [
|
|
276
|
+
{
|
|
277
|
+
id: details.id,
|
|
278
|
+
item_id: details.item_id,
|
|
279
|
+
unit_cost: price,
|
|
280
|
+
},
|
|
281
|
+
],
|
|
282
|
+
});
|
|
283
|
+
continue ForPrincipal;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
//SI SIGUE AQUÍ, ES POR QUE NO ES VERDURA ESPECIAL
|
|
288
|
+
const purchase_order_details = purchase.purchase_order_details.map((details) => {
|
|
289
|
+
const costo = body.costos.find((x) => x.item === details.item_id);
|
|
290
|
+
const price = getPriceByDate(purchase.created_at, body.fechas, costo);
|
|
291
|
+
return { id: details.id, item_id: details.item_id, unit_cost: price };
|
|
292
|
+
});
|
|
293
|
+
costosWithPurchaseIds.push({
|
|
294
|
+
id: purchase.id,
|
|
295
|
+
fecha: purchase.created_at,
|
|
296
|
+
purchase_order_details,
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
//PASO 5
|
|
300
|
+
//Guardo la bitácora de cambios
|
|
301
|
+
console.log(`==============================> GUARDANDO BITÁCORA DE CAMBIOS`);
|
|
302
|
+
const response = await (0, exports.saveBitacoraCostos)(headers, session, {
|
|
303
|
+
...body,
|
|
304
|
+
costosActualizados: costosWithPurchaseIds,
|
|
305
|
+
costosEspecialesActualizados: costosEspecialesWithPurchaseIds,
|
|
306
|
+
});
|
|
307
|
+
if (response.error || !response.data) {
|
|
308
|
+
const errorMsg = `Error al guardar la bitácora de costos ${response.userMsg}` ??
|
|
309
|
+
"Respuesta vacía de saveBitacoraCostos en changePrices";
|
|
310
|
+
console.error(errorMsg);
|
|
311
|
+
throw new Error(errorMsg);
|
|
312
|
+
}
|
|
313
|
+
return response.data;
|
|
314
|
+
});
|
|
315
|
+
};
|
|
316
|
+
exports.changePricesInit = changePricesInit;
|
|
317
|
+
/**
|
|
318
|
+
* changePrice
|
|
319
|
+
* @param headers
|
|
320
|
+
* @param session
|
|
321
|
+
* @param body
|
|
322
|
+
* @returns
|
|
323
|
+
*/
|
|
324
|
+
const changePrice = async (headers, costo) => {
|
|
325
|
+
const x = costo;
|
|
326
|
+
const msgActualizando = `==============================> ACTUALIZANDO ÓRDEN DE COMPRA: ID: ${x.id} PRICE: ${x.purchase_order_details
|
|
327
|
+
.map((x) => x.unit_cost)
|
|
328
|
+
.join(",")} ID_ITEM: ${x.purchase_order_details
|
|
329
|
+
.map((x) => x.item_id)
|
|
330
|
+
.join(",")}`;
|
|
331
|
+
const body = {
|
|
332
|
+
purchase_order_details_attributes: {
|
|
333
|
+
...x.purchase_order_details
|
|
334
|
+
.map((detail, index) => {
|
|
335
|
+
return {
|
|
336
|
+
[`${index}`]: {
|
|
337
|
+
id: detail.id,
|
|
338
|
+
item_id: detail.item_id,
|
|
339
|
+
unit_cost: detail.unit_cost,
|
|
340
|
+
},
|
|
341
|
+
};
|
|
342
|
+
})
|
|
343
|
+
.reduce((acc, curr) => Object.assign(acc, curr), {}),
|
|
344
|
+
},
|
|
345
|
+
};
|
|
346
|
+
console.log(msgActualizando);
|
|
347
|
+
const updateResponse = await (0, purchase_orders_utils_js_1.updatePurchaseItemPrice)(headers, body, x.id);
|
|
348
|
+
if (updateResponse.error) {
|
|
349
|
+
// Si hay error
|
|
350
|
+
costo.finalizado = false;
|
|
351
|
+
costo.msgResultado =
|
|
352
|
+
updateResponse.userMsg ??
|
|
353
|
+
`Ocurrió un error al editar la órden de compra ${JSON.stringify(updateResponse)}`;
|
|
354
|
+
}
|
|
355
|
+
else {
|
|
356
|
+
costo.finalizado = true;
|
|
357
|
+
}
|
|
358
|
+
return costo;
|
|
359
|
+
};
|
|
360
|
+
exports.changePrice = changePrice;
|
|
361
|
+
/**
|
|
362
|
+
* changePrices
|
|
363
|
+
* @param headers
|
|
364
|
+
* @param session
|
|
365
|
+
* @param body
|
|
366
|
+
* @returns
|
|
367
|
+
*/
|
|
368
|
+
const changePrices = (headers, session, bitacora, id_bitacora) => {
|
|
369
|
+
return (0, common_1.handlePossibleAxiosErrors)(async () => {
|
|
370
|
+
const costosWithPurchaseIds = bitacora.costosActualizados;
|
|
371
|
+
const costosEspecialesWithPurchaseIds = bitacora.costosEspecialesActualizados;
|
|
372
|
+
//PASO 3
|
|
373
|
+
//Editar los precios de todas las órdenes de compra
|
|
374
|
+
logTotal(costosWithPurchaseIds.length);
|
|
375
|
+
for (let i = 0; i < costosWithPurchaseIds.length; i++) {
|
|
376
|
+
const x = costosWithPurchaseIds[i];
|
|
377
|
+
const msgActualizando = `==============================> ACTUALIZANDO ÓRDEN DE COMPRA: ID: ${x.id} PRICE: ${x.purchase_order_details
|
|
378
|
+
.map((x) => x.unit_cost)
|
|
379
|
+
.join(",")} ID_ITEM: ${x.purchase_order_details
|
|
380
|
+
.map((x) => x.item_id)
|
|
381
|
+
.join(",")}`;
|
|
382
|
+
console.log(msgActualizando);
|
|
383
|
+
const updateResponse = await (0, purchase_orders_utils_js_1.updatePurchaseItemPrice)(headers, {
|
|
384
|
+
purchase_order_details_attributes: {
|
|
385
|
+
...x.purchase_order_details
|
|
386
|
+
.map((detail, index) => {
|
|
387
|
+
return {
|
|
388
|
+
[`${index}`]: {
|
|
389
|
+
id: detail.id,
|
|
390
|
+
item_id: detail.item_id,
|
|
391
|
+
unit_cost: detail.unit_cost,
|
|
392
|
+
},
|
|
393
|
+
};
|
|
394
|
+
})
|
|
395
|
+
.reduce((acc, curr) => Object.assign(acc, curr), {}),
|
|
396
|
+
},
|
|
397
|
+
}, x.id);
|
|
398
|
+
if (updateResponse.error) {
|
|
399
|
+
// Si hay error
|
|
400
|
+
costosWithPurchaseIds[i].finalizado = false;
|
|
401
|
+
costosWithPurchaseIds[i].msgResultado =
|
|
402
|
+
updateResponse.userMsg ?? JSON.stringify(updateResponse);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
//PASO 4
|
|
406
|
+
//EDITO LAS ORDENES DE COMPRA PARA ITEMS ESPECIALES
|
|
407
|
+
logTotal(costosEspecialesWithPurchaseIds.length);
|
|
408
|
+
for (let i = 0; i < costosEspecialesWithPurchaseIds.length; i++) {
|
|
409
|
+
const x = costosEspecialesWithPurchaseIds[i];
|
|
410
|
+
console.log(`==============================> ACTUALIZANDO ÓRDEN DE COMPRA (ESPECIAL): ID: ${x.id} PRICE: ${x.purchase_order_details
|
|
411
|
+
.map((x) => x.unit_cost)
|
|
412
|
+
.join(",")} ID_ITEM: ${x.purchase_order_details
|
|
413
|
+
.map((x) => x.item_id)
|
|
414
|
+
.join(",")}`);
|
|
415
|
+
const updateResponse = await (0, purchase_orders_utils_js_1.updatePurchaseItemPrice)(headers, {
|
|
416
|
+
purchase_order_details_attributes: {
|
|
417
|
+
...x.purchase_order_details
|
|
418
|
+
.map((detail, index) => {
|
|
419
|
+
return {
|
|
420
|
+
[`${index}`]: {
|
|
421
|
+
id: detail.id,
|
|
422
|
+
item_id: detail.item_id,
|
|
423
|
+
unit_cost: detail.unit_cost,
|
|
424
|
+
},
|
|
425
|
+
};
|
|
426
|
+
})
|
|
427
|
+
.reduce((acc, curr) => Object.assign(acc, curr), {}),
|
|
428
|
+
},
|
|
429
|
+
}, x.id);
|
|
430
|
+
if (updateResponse.error) {
|
|
431
|
+
// Si hay error
|
|
432
|
+
costosEspecialesWithPurchaseIds[i].finalizado = false;
|
|
433
|
+
costosEspecialesWithPurchaseIds[i].msgResultado =
|
|
434
|
+
updateResponse.userMsg ?? JSON.stringify(updateResponse);
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
//PASO 5
|
|
438
|
+
//Actualizo la bitácora de cambios
|
|
439
|
+
console.log(`==============================> GUARDANDO BITÁCORA DE CAMBIOS`);
|
|
440
|
+
const response = await (0, exports.updateBitacoraCostos)(headers, session, {
|
|
441
|
+
...bitacora,
|
|
442
|
+
costosActualizados: costosWithPurchaseIds,
|
|
443
|
+
costosEspecialesActualizados: costosEspecialesWithPurchaseIds,
|
|
444
|
+
}, id_bitacora);
|
|
445
|
+
if (response.error || !response.data) {
|
|
446
|
+
const errorMsg = response.userMsg ?? "Respuesta vacía de updateBitacora en changePrices";
|
|
447
|
+
console.error(errorMsg);
|
|
448
|
+
throw new Error(errorMsg);
|
|
449
|
+
}
|
|
450
|
+
return response.data;
|
|
451
|
+
});
|
|
452
|
+
};
|
|
453
|
+
exports.changePrices = changePrices;
|
|
454
|
+
/**
|
|
455
|
+
* corregirCostos
|
|
456
|
+
* @param headers
|
|
457
|
+
* @param session
|
|
458
|
+
* @param costos
|
|
459
|
+
* @returns
|
|
460
|
+
*/
|
|
461
|
+
const corregirCostos = (headers, session, costos, costosEspeciales) => {
|
|
462
|
+
return (0, common_1.handlePossibleAxiosErrors)(async () => {
|
|
463
|
+
//PASO 1
|
|
464
|
+
//Hago una copia
|
|
465
|
+
const costosTemp = costos;
|
|
466
|
+
const costosEspecialesTemp = costosEspeciales;
|
|
467
|
+
//PASO 2
|
|
468
|
+
//Editar los precios de todas las órdenes de compra
|
|
469
|
+
logTotal(costosTemp.length);
|
|
470
|
+
for (let i = 0; i < costosTemp.length; i++) {
|
|
471
|
+
const x = costosTemp[i];
|
|
472
|
+
console.log(`==============================> ACTUALIZANDO ÓRDEN DE COMPRA: ID: ${x.id} PRICE: ${x.purchase_order_details
|
|
473
|
+
.map((x) => x.unit_cost)
|
|
474
|
+
.join(",")} ID_ITEM: ${x.purchase_order_details
|
|
475
|
+
.map((x) => x.item_id)
|
|
476
|
+
.join(",")}`);
|
|
477
|
+
const updateResponse = await (0, purchase_orders_utils_js_1.updatePurchaseItemPrice)(headers, {
|
|
478
|
+
purchase_order_details_attributes: {
|
|
479
|
+
...x.purchase_order_details
|
|
480
|
+
.map((detail, index) => {
|
|
481
|
+
return {
|
|
482
|
+
[`${index}`]: {
|
|
483
|
+
id: detail.id,
|
|
484
|
+
item_id: detail.item_id,
|
|
485
|
+
unit_cost: detail.unit_cost,
|
|
486
|
+
},
|
|
487
|
+
};
|
|
488
|
+
})
|
|
489
|
+
.reduce((acc, curr) => Object.assign(acc, curr), {}),
|
|
490
|
+
},
|
|
491
|
+
}, x.id);
|
|
492
|
+
if (!updateResponse.error) {
|
|
493
|
+
// Si hay error
|
|
494
|
+
costosTemp[i].finalizado = true;
|
|
495
|
+
}
|
|
496
|
+
else {
|
|
497
|
+
costosTemp[i].finalizado = false;
|
|
498
|
+
costosTemp[i].msgResultado =
|
|
499
|
+
updateResponse.userMsg ?? JSON.stringify(updateResponse);
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
//PASO 3
|
|
503
|
+
//Editar los precios de todas las órdenes de compra de precios especiales
|
|
504
|
+
logTotal(costosEspecialesTemp.length);
|
|
505
|
+
for (let i = 0; i < costosEspecialesTemp.length; i++) {
|
|
506
|
+
const x = costosEspecialesTemp[i];
|
|
507
|
+
console.log(`==============================> ACTUALIZANDO ÓRDEN DE COMPRA (ESPECIAL): ID: ${x.id} PRICE: ${x.purchase_order_details
|
|
508
|
+
.map((x) => x.unit_cost)
|
|
509
|
+
.join(",")} ID_ITEM: ${x.purchase_order_details
|
|
510
|
+
.map((x) => x.item_id)
|
|
511
|
+
.join(",")}`);
|
|
512
|
+
const updateResponse = await (0, purchase_orders_utils_js_1.updatePurchaseItemPrice)(headers, {
|
|
513
|
+
purchase_order_details_attributes: {
|
|
514
|
+
...x.purchase_order_details
|
|
515
|
+
.map((detail, index) => {
|
|
516
|
+
return {
|
|
517
|
+
[`${index}`]: {
|
|
518
|
+
id: detail.id,
|
|
519
|
+
item_id: detail.item_id,
|
|
520
|
+
unit_cost: detail.unit_cost,
|
|
521
|
+
},
|
|
522
|
+
};
|
|
523
|
+
})
|
|
524
|
+
.reduce((acc, curr) => Object.assign(acc, curr), {}),
|
|
525
|
+
},
|
|
526
|
+
}, x.id);
|
|
527
|
+
if (!updateResponse.error) {
|
|
528
|
+
// Si hay error
|
|
529
|
+
costosEspecialesTemp[i].finalizado = true;
|
|
530
|
+
}
|
|
531
|
+
else {
|
|
532
|
+
costosEspecialesTemp[i].finalizado = false;
|
|
533
|
+
costosEspecialesTemp[i].msgResultado =
|
|
534
|
+
updateResponse.userMsg ?? JSON.stringify(updateResponse);
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
//PASO 3
|
|
538
|
+
//Guardo la bitácora de cambios
|
|
539
|
+
console.log(`==============================> GUARDANDO BITÁCORA DE CAMBIOS`);
|
|
540
|
+
const response = await (0, exports.saveBitacoraCostos)(headers, session, {
|
|
541
|
+
accion: "Reintento de asignación de costos",
|
|
542
|
+
costos: [],
|
|
543
|
+
costosEspeciales: [],
|
|
544
|
+
fechaCreacion: (0, moment_1.default)().format("DD/MM/YYYY HH:mm:ss"),
|
|
545
|
+
fechas: {
|
|
546
|
+
domingo: "",
|
|
547
|
+
jueves: "",
|
|
548
|
+
lunes: "",
|
|
549
|
+
martes: "",
|
|
550
|
+
miercoles: "",
|
|
551
|
+
sabado: "",
|
|
552
|
+
viernes: "",
|
|
553
|
+
},
|
|
554
|
+
modificadoPor: session.get("name"),
|
|
555
|
+
costosActualizados: costosTemp,
|
|
556
|
+
costosEspecialesActualizados: costosEspecialesTemp,
|
|
557
|
+
});
|
|
558
|
+
if (response.error || !response.data) {
|
|
559
|
+
throw new Error(response.userMsg ??
|
|
560
|
+
"Respuesta vacía de saveBitacoraCostos en changePrices");
|
|
561
|
+
}
|
|
562
|
+
return response.data;
|
|
563
|
+
});
|
|
564
|
+
};
|
|
565
|
+
exports.corregirCostos = corregirCostos;
|
|
566
|
+
/**
|
|
567
|
+
* Get saveBitacoraCostos from the web app table.
|
|
568
|
+
* @param headers Request headers.
|
|
569
|
+
* @param session Session object.
|
|
570
|
+
* @returns A Promise of AxiosUtilsResponse<WebAppRowGraphQL<BitacoraCostosItems>[]>.
|
|
571
|
+
*/
|
|
572
|
+
const saveBitacoraCostos = (headers, session, body) => {
|
|
573
|
+
return (0, common_1.handlePossibleAxiosErrors)(async () => {
|
|
574
|
+
const { bitacora_costos_verduras_web_app_table_id } = await (0, services_1.getVariablesByName)(headers, session, [
|
|
575
|
+
"bitacora_costos_verduras_web_app_table_id",
|
|
576
|
+
]);
|
|
577
|
+
const response = await (0, services_1.createWebAppTableRegister)(headers, bitacora_costos_verduras_web_app_table_id, { ...body, modificadoPor: session.get("name") });
|
|
578
|
+
return response;
|
|
579
|
+
});
|
|
580
|
+
};
|
|
581
|
+
exports.saveBitacoraCostos = saveBitacoraCostos;
|
|
582
|
+
/**
|
|
583
|
+
* Put updateBitacoraCostos from the web app table.
|
|
584
|
+
* @param headers Request headers.
|
|
585
|
+
* @param session Session object.
|
|
586
|
+
* @returns A Promise of AxiosUtilsResponse<WebAppRowGraphQL<BitacoraCostosItems>[]>.
|
|
587
|
+
*/
|
|
588
|
+
const updateBitacoraCostos = (headers, session, body, id_registro) => {
|
|
589
|
+
return (0, common_1.handlePossibleAxiosErrors)(async () => {
|
|
590
|
+
const { bitacora_costos_verduras_web_app_table_id } = await (0, services_1.getVariablesByName)(headers, session, [
|
|
591
|
+
"bitacora_costos_verduras_web_app_table_id",
|
|
592
|
+
]);
|
|
593
|
+
const response = await (0, services_1.updateWebAppTableRegister)(headers, bitacora_costos_verduras_web_app_table_id, id_registro, { ...body, modificadoPor: session.get("name") });
|
|
594
|
+
return response;
|
|
595
|
+
});
|
|
596
|
+
};
|
|
597
|
+
exports.updateBitacoraCostos = updateBitacoraCostos;
|
|
598
|
+
/**
|
|
599
|
+
* Get getCostosBitacora from the web app table.
|
|
600
|
+
* @param headers Request headers.
|
|
601
|
+
* @param session Session object.
|
|
602
|
+
* @returns A Promise of AxiosUtilsResponse<WebAppRowGraphQL<BitacoraCostosItems>[]>.
|
|
603
|
+
*/
|
|
604
|
+
const getCostosBitacora = (headers, session) => {
|
|
605
|
+
return (0, common_1.handlePossibleAxiosErrors)(async () => {
|
|
606
|
+
const { bitacora_costos_verduras_web_app_table_id } = await (0, services_1.getVariablesByName)(headers, session, [
|
|
607
|
+
"bitacora_costos_verduras_web_app_table_id",
|
|
608
|
+
]);
|
|
609
|
+
const response = await (0, services_1.getWebAppTableRegisters)(session, bitacora_costos_verduras_web_app_table_id);
|
|
610
|
+
if (response.error) {
|
|
611
|
+
throw new Error(`Ocurrió un error al tratar de obtener la bitácora de costos: ${response.userMsg}`);
|
|
612
|
+
}
|
|
613
|
+
const bitacora = response.data ?? [];
|
|
614
|
+
return bitacora;
|
|
615
|
+
});
|
|
616
|
+
};
|
|
617
|
+
exports.getCostosBitacora = getCostosBitacora;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDeliveriesDataTableFormated = void 0;
|
|
4
|
+
const common_1 = require("@zauru-sdk/common");
|
|
5
|
+
const services_1 = require("@zauru-sdk/services");
|
|
6
|
+
/**
|
|
7
|
+
* getDeliveriesFormated
|
|
8
|
+
* @param headers
|
|
9
|
+
* @param session
|
|
10
|
+
*/
|
|
11
|
+
const getDeliveriesDataTableFormated = async (headers, session) => {
|
|
12
|
+
const body = {
|
|
13
|
+
order: {
|
|
14
|
+
"0": {
|
|
15
|
+
column: "0",
|
|
16
|
+
dir: "desc",
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
start: 0,
|
|
20
|
+
length: 40,
|
|
21
|
+
search: {
|
|
22
|
+
value: "",
|
|
23
|
+
regex: false,
|
|
24
|
+
},
|
|
25
|
+
agency: session.get("agency_id"),
|
|
26
|
+
};
|
|
27
|
+
const response = await (0, services_1.getDeliveriesDataTables)(headers, body);
|
|
28
|
+
if (response.error) {
|
|
29
|
+
return { ...response, data: [] };
|
|
30
|
+
}
|
|
31
|
+
const deliveries = response.data?.data?.map((x) => formatHTMLDeliveryList(x)) ?? [];
|
|
32
|
+
return { ...response, data: deliveries };
|
|
33
|
+
};
|
|
34
|
+
exports.getDeliveriesDataTableFormated = getDeliveriesDataTableFormated;
|
|
35
|
+
/**
|
|
36
|
+
* formatHTMLDeliveryList
|
|
37
|
+
* @param delivery
|
|
38
|
+
* @returns
|
|
39
|
+
*/
|
|
40
|
+
const formatHTMLDeliveryList = (delivery) => {
|
|
41
|
+
return {
|
|
42
|
+
zid: (0, common_1.extractValueBetweenTags)(delivery.zid, "a"),
|
|
43
|
+
referencia: (0, common_1.extractValueBetweenTags)(delivery.ref, "a"),
|
|
44
|
+
fechaEntrega: delivery.pd,
|
|
45
|
+
fechaEntregaEstimada: delivery.dt,
|
|
46
|
+
destino: delivery.at,
|
|
47
|
+
origen: delivery.af,
|
|
48
|
+
deliveryId: delivery.DT_RowId.replace("inventories-delivery-", ""),
|
|
49
|
+
};
|
|
50
|
+
};
|