@zauru-sdk/utils 1.0.49 → 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 +13 -10
- package/CHANGELOG.md +0 -248
- 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,390 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createNewLabItemRequest = exports.deleteTask = exports.commitEndTask = exports.commitTask = exports.deletePurchaseOrderProcess = exports.getOrderIDS = exports.updatePurchaseOrderReception = exports.updateOchAndDis = exports.updatePurchaseItemPrice = exports.getPurchaseOrderDataTables = exports.getPurchasesDataTableListFormated = void 0;
|
|
4
|
+
const common_1 = require("@zauru-sdk/common");
|
|
5
|
+
const services_1 = require("@zauru-sdk/services");
|
|
6
|
+
/**
|
|
7
|
+
* Obtiene el listado de ordenes de compra, formateado especialmente para armar la tabla de edición de porcentajes y tolerancia
|
|
8
|
+
* @param headers
|
|
9
|
+
* @param session
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
const getPurchasesDataTableListFormated = async (headers, session, params) => {
|
|
13
|
+
return (0, common_1.handlePossibleAxiosErrors)(async () => {
|
|
14
|
+
//PASO 1: Obtengo las variables, para buscar mi tag_id y mi basket_id
|
|
15
|
+
const { recepciones_tag_id: tag_id, recepciones_basket_item_id: basket_id, production_agency_id: temp_production_agency_id, } = await (0, services_1.getVariablesByName)(headers, session, [
|
|
16
|
+
"recepciones_tag_id",
|
|
17
|
+
"recepciones_basket_item_id",
|
|
18
|
+
"production_agency_id",
|
|
19
|
+
]);
|
|
20
|
+
const hashProductionAgencyId = JSON.parse(temp_production_agency_id ?? "{}");
|
|
21
|
+
const production_agency_id = hashProductionAgencyId[session.get("agency_id")];
|
|
22
|
+
const agency_id = params.from_production_agency_id
|
|
23
|
+
? production_agency_id
|
|
24
|
+
: session.get("agency_id");
|
|
25
|
+
//PASO 2: Busco mis ordenes de compra
|
|
26
|
+
const ordersDataTablesResponse = await getOrdersDataTables(headers, params?.page ? Number(params?.page) : 1, params?.perPage ? Number(params?.perPage) : 10, params?.search ?? "", tag_id, agency_id);
|
|
27
|
+
if (ordersDataTablesResponse.error) {
|
|
28
|
+
throw new Error(ordersDataTablesResponse.userMsg);
|
|
29
|
+
}
|
|
30
|
+
const ordersDataTables = ordersDataTablesResponse?.data;
|
|
31
|
+
//PASO 3: Busco mis lotes
|
|
32
|
+
const lotesResponse = await (0, services_1.getLotesWithPurchaseFormated)(headers, agency_id, Number(basket_id), ordersDataTables?.orders ?? {}, ordersDataTables?.desde, ordersDataTables?.hasta);
|
|
33
|
+
if (lotesResponse.error) {
|
|
34
|
+
throw new Error(lotesResponse.userMsg);
|
|
35
|
+
}
|
|
36
|
+
//PASO 4: Retorno la información
|
|
37
|
+
return {
|
|
38
|
+
recordsTotal: ordersDataTables?.recordsTotal ?? 0,
|
|
39
|
+
recordsFiltered: ordersDataTables?.recordsFiltered ?? 0,
|
|
40
|
+
draw: ordersDataTables?.draw ?? 0,
|
|
41
|
+
data: lotesResponse?.data ?? [],
|
|
42
|
+
};
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
exports.getPurchasesDataTableListFormated = getPurchasesDataTableListFormated;
|
|
46
|
+
/**
|
|
47
|
+
*
|
|
48
|
+
* @param headers
|
|
49
|
+
* @param tag_id
|
|
50
|
+
* @param agency_id
|
|
51
|
+
* @param page
|
|
52
|
+
* @param perPage
|
|
53
|
+
* @param search
|
|
54
|
+
* @returns
|
|
55
|
+
*/
|
|
56
|
+
const getOrdersDataTables = async (headers, page, perPage, search, tag_id, agency_id) => {
|
|
57
|
+
return (0, common_1.handlePossibleAxiosErrors)(async () => {
|
|
58
|
+
const body = {
|
|
59
|
+
order: { "0": { column: "1", dir: "desc" } },
|
|
60
|
+
start: ((page ?? 1) - 1) * (perPage ?? 0),
|
|
61
|
+
length: perPage ?? 0,
|
|
62
|
+
search: { value: search ?? "", regex: false },
|
|
63
|
+
tag: tag_id,
|
|
64
|
+
agency: agency_id,
|
|
65
|
+
};
|
|
66
|
+
//Voy por las ordenes y las ordeno por fecha de recepción
|
|
67
|
+
const ordersDataTablesResponse = await (0, services_1.getPurchasesListDataTables)(headers, body);
|
|
68
|
+
const ordersDataTables = ordersDataTablesResponse.data;
|
|
69
|
+
const orders = ordersDataTables?.data.sort((a, b) => (0, common_1.getNewDateByFormat)(a.rd).getTime() - (0, common_1.getNewDateByFormat)(b.rd).getTime());
|
|
70
|
+
const purchaseOrders = {};
|
|
71
|
+
orders?.forEach((value) => {
|
|
72
|
+
const id_i_pos = value.z.indexOf("purchase_orders/") + 16;
|
|
73
|
+
const id_f_pos = value.z.indexOf('">');
|
|
74
|
+
const zid_f_pos = value.z.indexOf("</a>");
|
|
75
|
+
const id_n_i_pos = value.i.indexOf(">");
|
|
76
|
+
const id_n_f_pos = value.i.indexOf("</a>");
|
|
77
|
+
const new_date = (0, common_1.getNewDateByFormat)(value.dte);
|
|
78
|
+
const ven_i_pos = value.ven.indexOf('">');
|
|
79
|
+
const ven_f_pos = value.ven.indexOf("</a>");
|
|
80
|
+
const id_number = value.i.substring(id_n_i_pos + 1, id_n_f_pos);
|
|
81
|
+
const purchase_id = value.DT_RowId.replace("purchases-purchase-order-", "");
|
|
82
|
+
purchaseOrders[id_number] = {
|
|
83
|
+
id: value.z.substring(id_i_pos, id_f_pos),
|
|
84
|
+
zid: value.z.substring(id_f_pos + 2, zid_f_pos),
|
|
85
|
+
id_number: Number(id_number),
|
|
86
|
+
no_orden: Number(purchase_id),
|
|
87
|
+
dte: new_date,
|
|
88
|
+
o: Boolean(value.o),
|
|
89
|
+
vendor: value.ven.substring(ven_i_pos + 2, ven_f_pos),
|
|
90
|
+
po_editable: parseInt(value.due.substring(1)) > 0,
|
|
91
|
+
dis: Number(value.dis),
|
|
92
|
+
och: Number(value.och),
|
|
93
|
+
rd: value.rd,
|
|
94
|
+
};
|
|
95
|
+
});
|
|
96
|
+
return {
|
|
97
|
+
orders: purchaseOrders,
|
|
98
|
+
draw: ordersDataTables?.draw ?? 0,
|
|
99
|
+
recordsFiltered: ordersDataTables?.recordsFiltered ?? 0,
|
|
100
|
+
recordsTotal: ordersDataTables?.recordsTotal ?? 0,
|
|
101
|
+
desde: orders?.length ? (0, common_1.getZauruDateByText)(orders[0].rd) : undefined,
|
|
102
|
+
hasta: orders?.length
|
|
103
|
+
? (0, common_1.getZauruDateByText)(orders[orders.length - 1].rd)
|
|
104
|
+
: undefined,
|
|
105
|
+
};
|
|
106
|
+
});
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* getPurchaseOrderDataTables Obtiene una orden de compra ya formateada con todos sus campos.
|
|
110
|
+
* @param headers
|
|
111
|
+
* @param tag_id
|
|
112
|
+
* @param agency_id
|
|
113
|
+
* @param search
|
|
114
|
+
* @returns
|
|
115
|
+
*/
|
|
116
|
+
const getPurchaseOrderDataTables = async (headers, search, tag_id, agency_id) => {
|
|
117
|
+
const body = {
|
|
118
|
+
order: { "0": { column: "1", dir: "desc" } },
|
|
119
|
+
start: 0,
|
|
120
|
+
length: 0,
|
|
121
|
+
search: { value: search, regex: false },
|
|
122
|
+
tag: tag_id,
|
|
123
|
+
agency: agency_id,
|
|
124
|
+
};
|
|
125
|
+
//Voy por las ordenes y las ordeno por fecha de recepción
|
|
126
|
+
const ordersDataTablesResponse = await (0, services_1.getPurchasesListDataTables)(headers, body);
|
|
127
|
+
const ordersDataTables = ordersDataTablesResponse.data;
|
|
128
|
+
const getPurchaseOrderFormated = (value) => {
|
|
129
|
+
const id_i_pos = value.z.indexOf("purchase_orders/") + 16;
|
|
130
|
+
const id_f_pos = value.z.indexOf('">');
|
|
131
|
+
const zid_f_pos = value.z.indexOf("</a>");
|
|
132
|
+
const id_n_i_pos = value.i.indexOf(">");
|
|
133
|
+
const id_n_f_pos = value.i.indexOf("</a>");
|
|
134
|
+
const new_date = (0, common_1.getNewDateByFormat)(value.dte);
|
|
135
|
+
const ven_i_pos = value.ven.indexOf('">');
|
|
136
|
+
const ven_f_pos = value.ven.indexOf("</a>");
|
|
137
|
+
const id_number = value.i.substring(id_n_i_pos + 1, id_n_f_pos);
|
|
138
|
+
const purchase_id = value.DT_RowId.replace("purchases-purchase-order-", "");
|
|
139
|
+
return {
|
|
140
|
+
id: value.z.substring(id_i_pos, id_f_pos),
|
|
141
|
+
zid: value.z.substring(id_f_pos + 2, zid_f_pos),
|
|
142
|
+
id_number: Number(id_number),
|
|
143
|
+
no_orden: Number(purchase_id),
|
|
144
|
+
dte: new_date,
|
|
145
|
+
o: Boolean(value.o),
|
|
146
|
+
vendor: value.ven.substring(ven_i_pos + 2, ven_f_pos),
|
|
147
|
+
po_editable: parseInt(value.due.substring(1)) > 0,
|
|
148
|
+
dis: Number(value.dis),
|
|
149
|
+
och: Number(value.och),
|
|
150
|
+
rd: value.rd,
|
|
151
|
+
};
|
|
152
|
+
};
|
|
153
|
+
!ordersDataTables?.data?.length &&
|
|
154
|
+
console.log("========== NO SE ENCONTRO NINGUNA ORDEN DE COMPRA ===========");
|
|
155
|
+
const purchaseOrderDataTable = getPurchaseOrderFormated(ordersDataTables?.data[0]);
|
|
156
|
+
return purchaseOrderDataTable;
|
|
157
|
+
};
|
|
158
|
+
exports.getPurchaseOrderDataTables = getPurchaseOrderDataTables;
|
|
159
|
+
/**
|
|
160
|
+
* updatePurchaseItemPrice
|
|
161
|
+
* @param headers
|
|
162
|
+
* @param data
|
|
163
|
+
* @param purchase_id
|
|
164
|
+
*/
|
|
165
|
+
const updatePurchaseItemPrice = async (headers, data, purchase_id) => {
|
|
166
|
+
return (0, common_1.handlePossibleAxiosErrors)(async () => {
|
|
167
|
+
const body = {
|
|
168
|
+
purchase_order: {
|
|
169
|
+
purchase_order_details_attributes: data.purchase_order_details_attributes,
|
|
170
|
+
},
|
|
171
|
+
};
|
|
172
|
+
const responseUpdate = await (0, services_1.updateReceivedPurchaseOrder)(headers, body, purchase_id);
|
|
173
|
+
if (responseUpdate.error) {
|
|
174
|
+
throw new Error(responseUpdate.userMsg);
|
|
175
|
+
}
|
|
176
|
+
return true;
|
|
177
|
+
});
|
|
178
|
+
};
|
|
179
|
+
exports.updatePurchaseItemPrice = updatePurchaseItemPrice;
|
|
180
|
+
/**
|
|
181
|
+
* updateOchAndDis
|
|
182
|
+
* @param headers
|
|
183
|
+
* @param session
|
|
184
|
+
* @returns
|
|
185
|
+
*/
|
|
186
|
+
const updateOchAndDis = async (headers, data, purchase_id) => {
|
|
187
|
+
return (0, common_1.handlePossibleAxiosErrors)(async () => {
|
|
188
|
+
const body = {
|
|
189
|
+
purchase_order: {
|
|
190
|
+
discount: data?.discount,
|
|
191
|
+
other_charges: data.other_charges,
|
|
192
|
+
},
|
|
193
|
+
};
|
|
194
|
+
await (0, services_1.updateReceivedPurchaseOrder)(headers, body, purchase_id);
|
|
195
|
+
return true;
|
|
196
|
+
});
|
|
197
|
+
};
|
|
198
|
+
exports.updateOchAndDis = updateOchAndDis;
|
|
199
|
+
/**
|
|
200
|
+
* updatePurchaseOrderReception
|
|
201
|
+
* @param headers
|
|
202
|
+
* @param data
|
|
203
|
+
* @param purchase_id
|
|
204
|
+
* @returns
|
|
205
|
+
*/
|
|
206
|
+
const updatePurchaseOrderReception = async (headers, data, purchase_id) => {
|
|
207
|
+
return (0, common_1.handlePossibleAxiosErrors)(async () => {
|
|
208
|
+
const body = {
|
|
209
|
+
purchase_order: {
|
|
210
|
+
payee_id: data.payee_id,
|
|
211
|
+
purchase_order_details_attributes: data.purchase_order_details_attributes,
|
|
212
|
+
},
|
|
213
|
+
};
|
|
214
|
+
await (0, services_1.updateReceivedPurchaseOrder)(headers, body, purchase_id);
|
|
215
|
+
return true;
|
|
216
|
+
});
|
|
217
|
+
};
|
|
218
|
+
exports.updatePurchaseOrderReception = updatePurchaseOrderReception;
|
|
219
|
+
/**
|
|
220
|
+
* Obtengo los id's de las órdenes de compra en un arreglo numérico
|
|
221
|
+
* @param headers
|
|
222
|
+
* @param session
|
|
223
|
+
* @param extraParams
|
|
224
|
+
* @returns
|
|
225
|
+
*/
|
|
226
|
+
const getOrderIDS = async (headers, session, extraParams) => {
|
|
227
|
+
return (0, common_1.handlePossibleAxiosErrors)(async () => {
|
|
228
|
+
const { recepciones_tag_id: tag_id } = await (0, services_1.getVariablesByName)(headers, session, ["recepciones_tag_id", "recepciones_basket_item_id"]);
|
|
229
|
+
const body = {
|
|
230
|
+
order: { "0": { column: "1", dir: "desc" } },
|
|
231
|
+
start: 0,
|
|
232
|
+
length: 2000, //para ir por todas
|
|
233
|
+
search: { value: "", regex: false },
|
|
234
|
+
tag: tag_id,
|
|
235
|
+
agency: session.get("agency_id") ?? undefined,
|
|
236
|
+
vendor: extraParams.vendor,
|
|
237
|
+
vendor_category: extraParams.vendor_category,
|
|
238
|
+
item: extraParams.item,
|
|
239
|
+
Desde: extraParams.desde,
|
|
240
|
+
Hasta: extraParams.hasta,
|
|
241
|
+
};
|
|
242
|
+
//Voy por las ordenes y las ordeno por fecha de recepción
|
|
243
|
+
const ordersDataTablesResponse = await (0, services_1.getPurchasesListDataTables)(headers, body);
|
|
244
|
+
const ordersDataTables = ordersDataTablesResponse.data;
|
|
245
|
+
return (ordersDataTables?.data?.map((x) => Number(x.DT_RowId.replace("purchases-purchase-order-", ""))) ?? []);
|
|
246
|
+
});
|
|
247
|
+
};
|
|
248
|
+
exports.getOrderIDS = getOrderIDS;
|
|
249
|
+
/**
|
|
250
|
+
* deleteOrder
|
|
251
|
+
* @returns
|
|
252
|
+
*/
|
|
253
|
+
const deletePurchaseOrderProcess = async (headers, session, id) => {
|
|
254
|
+
return (0, common_1.handlePossibleAxiosErrors)(async () => {
|
|
255
|
+
const { data: purchaseOrder, error: poError, userMsg: poUserMsg, } = await (0, services_1.getPurchaseOrder)(session, id);
|
|
256
|
+
if (poError || !purchaseOrder) {
|
|
257
|
+
throw new Error(poUserMsg);
|
|
258
|
+
}
|
|
259
|
+
//Elimino las recepciones si es que tiene
|
|
260
|
+
for (const reception of purchaseOrder.receptions) {
|
|
261
|
+
if (reception.received && !reception.voided) {
|
|
262
|
+
const responseDeleteReception = await (0, services_1.deleteReception)(headers, reception.id, purchaseOrder.id);
|
|
263
|
+
if (responseDeleteReception.error || !responseDeleteReception.data) {
|
|
264
|
+
throw new Error(responseDeleteReception.userMsg);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
//Elimino los envíos si es que tiene
|
|
269
|
+
for (const ship of purchaseOrder.shipment_purchase_orders) {
|
|
270
|
+
const responseDeleteShip = await (0, services_1.deleteDelivery)(headers, ship.shipment_id);
|
|
271
|
+
if (responseDeleteShip.error || !responseDeleteShip.data) {
|
|
272
|
+
throw new Error(responseDeleteShip.userMsg);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
//Inactivo los lotes que tenga
|
|
276
|
+
for (const lot of purchaseOrder.lots) {
|
|
277
|
+
await (0, services_1.inactivarLote)(headers, lot.id);
|
|
278
|
+
}
|
|
279
|
+
const responseDeletePO = await (0, services_1.deletePurchaseOrder)(headers, id);
|
|
280
|
+
if (responseDeletePO.error) {
|
|
281
|
+
throw new Error(responseDeletePO.userMsg);
|
|
282
|
+
}
|
|
283
|
+
return true;
|
|
284
|
+
});
|
|
285
|
+
};
|
|
286
|
+
exports.deletePurchaseOrderProcess = deletePurchaseOrderProcess;
|
|
287
|
+
/**
|
|
288
|
+
* Commitea una task iniciada para la pantalla de edición masiva de órdenes de compra
|
|
289
|
+
* @param session
|
|
290
|
+
* @param ordenes
|
|
291
|
+
* @param timeStamp
|
|
292
|
+
*/
|
|
293
|
+
const commitTask = async (session, ordenes, timeStamp) => {
|
|
294
|
+
const newTask = {
|
|
295
|
+
timeStamp,
|
|
296
|
+
iniciada: (0, common_1.getStringFullDate)(new Date()),
|
|
297
|
+
total_ordenes: ordenes.length,
|
|
298
|
+
completadas: 0,
|
|
299
|
+
};
|
|
300
|
+
const updateTasks = (session.get("updateTasks") ?? []);
|
|
301
|
+
session.set("updateTasks", [...updateTasks, newTask]);
|
|
302
|
+
await (0, services_1.commitSession)(session);
|
|
303
|
+
};
|
|
304
|
+
exports.commitTask = commitTask;
|
|
305
|
+
/**
|
|
306
|
+
* Comitea una task finalizada para la pantalla de edición de órdenes de compra masiva
|
|
307
|
+
* @param session
|
|
308
|
+
* @param timeStamp
|
|
309
|
+
*/
|
|
310
|
+
const commitEndTask = async (session, timeStamp) => {
|
|
311
|
+
let updateTasks = session.get("updateTasks");
|
|
312
|
+
if (Array.isArray(updateTasks) &&
|
|
313
|
+
updateTasks.some((task) => task.timeStamp === timeStamp)) {
|
|
314
|
+
updateTasks = updateTasks.map((x) => {
|
|
315
|
+
if (x.timeStamp === timeStamp) {
|
|
316
|
+
return {
|
|
317
|
+
...x,
|
|
318
|
+
completadas: Number(x.completadas) + 1,
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
return x;
|
|
322
|
+
});
|
|
323
|
+
session.set("updateTasks", updateTasks);
|
|
324
|
+
await (0, services_1.commitSession)(session);
|
|
325
|
+
}
|
|
326
|
+
};
|
|
327
|
+
exports.commitEndTask = commitEndTask;
|
|
328
|
+
/**
|
|
329
|
+
* Elimina de la sesión una task.
|
|
330
|
+
* @param session
|
|
331
|
+
* @param timeStamp
|
|
332
|
+
*/
|
|
333
|
+
const deleteTask = async (session, timeStamp) => {
|
|
334
|
+
let updateTasks = session.get("updateTasks");
|
|
335
|
+
if (Array.isArray(updateTasks) &&
|
|
336
|
+
updateTasks.some((task) => task.timeStamp === timeStamp)) {
|
|
337
|
+
//La elimino de la lista
|
|
338
|
+
updateTasks = updateTasks.filter((task) => task.timeStamp !== timeStamp);
|
|
339
|
+
session.set("updateTasks", updateTasks);
|
|
340
|
+
await (0, services_1.commitSession)(session);
|
|
341
|
+
return true;
|
|
342
|
+
}
|
|
343
|
+
return false;
|
|
344
|
+
};
|
|
345
|
+
exports.deleteTask = deleteTask;
|
|
346
|
+
/**
|
|
347
|
+
* createNewLabItemRequest
|
|
348
|
+
* @param headers
|
|
349
|
+
* @param session
|
|
350
|
+
* @param body
|
|
351
|
+
* @returns
|
|
352
|
+
*/
|
|
353
|
+
const createNewLabItemRequest = (headers, session, body) => {
|
|
354
|
+
return (0, common_1.handlePossibleAxiosErrors)(async () => {
|
|
355
|
+
const { lab_charge_term_default_id, lab_agency_id, laboratory_proyect_id } = await (0, services_1.getVariablesByName)(headers, session, [
|
|
356
|
+
"lab_charge_term_default_id",
|
|
357
|
+
"lab_agency_id",
|
|
358
|
+
"laboratory_proyect_id",
|
|
359
|
+
]);
|
|
360
|
+
const id_number = (0, services_1.generateDistinctCode)("POLAB");
|
|
361
|
+
const sendBody = {
|
|
362
|
+
...body,
|
|
363
|
+
shipping_date: body.issue_date,
|
|
364
|
+
charge_term_id: Number(lab_charge_term_default_id),
|
|
365
|
+
agency_id: Number(lab_agency_id),
|
|
366
|
+
currency_id: common_1.CURRENCY_PREFIX.find((x) => x.prefix === "Q")?.id,
|
|
367
|
+
incoterm_id: 1,
|
|
368
|
+
taxable: false,
|
|
369
|
+
import: false,
|
|
370
|
+
id_number,
|
|
371
|
+
reference: "LABORATORIO - Solicitud de insumos desde WebApp",
|
|
372
|
+
origin: "LABORATORIO",
|
|
373
|
+
purchase_order_details: [
|
|
374
|
+
{
|
|
375
|
+
booked_quantity: body.booked_quantity,
|
|
376
|
+
item_id: body.item_id,
|
|
377
|
+
unit_cost: 1,
|
|
378
|
+
tag_id: Number(laboratory_proyect_id),
|
|
379
|
+
},
|
|
380
|
+
],
|
|
381
|
+
taggings: [{ tag_id: Number(laboratory_proyect_id) }],
|
|
382
|
+
};
|
|
383
|
+
const response = await (0, services_1.createNewPurchaseOrder)(headers, sendBody);
|
|
384
|
+
if (!response.data || response.error) {
|
|
385
|
+
throw new Error("Ocurrió un error al crear la recepción de insumos: " + response.userMsg);
|
|
386
|
+
}
|
|
387
|
+
return response.data;
|
|
388
|
+
});
|
|
389
|
+
};
|
|
390
|
+
exports.createNewLabItemRequest = createNewLabItemRequest;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.shipmentToVirtualClientAgency = exports.getShipmentsToMyAgency = void 0;
|
|
4
|
+
const common_1 = require("@zauru-sdk/common");
|
|
5
|
+
const services_1 = require("@zauru-sdk/services");
|
|
6
|
+
/**
|
|
7
|
+
*
|
|
8
|
+
* @param headers
|
|
9
|
+
* @param session
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
const getShipmentsToMyAgency = async (session) => {
|
|
13
|
+
return (0, common_1.handlePossibleAxiosErrors)(async () => {
|
|
14
|
+
const response = await (0, services_1.getShipmentsByToAgencyLast100Id_booking)(session, session.get("agency_id"));
|
|
15
|
+
if (response.error) {
|
|
16
|
+
throw new Error(`Ocurrió un error al consultar los envíos a mi agencia actual: ${response.userMsg}`);
|
|
17
|
+
}
|
|
18
|
+
return response?.data ?? [];
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
exports.getShipmentsToMyAgency = getShipmentsToMyAgency;
|
|
22
|
+
/**
|
|
23
|
+
*
|
|
24
|
+
* @param headers
|
|
25
|
+
* @param session
|
|
26
|
+
* @param props
|
|
27
|
+
* @returns
|
|
28
|
+
*/
|
|
29
|
+
const shipmentToVirtualClientAgency = async (headers, session, props) => {
|
|
30
|
+
return (0, common_1.handlePossibleAxiosErrors)(async () => {
|
|
31
|
+
const { virtual_client_agency_id } = await (0, services_1.getVariablesByName)(headers, session, ["virtual_client_agency_id"]);
|
|
32
|
+
let bookingBody = {};
|
|
33
|
+
if (props?.esPerecedero) {
|
|
34
|
+
const responseStocks = await (0, services_1.getMyAgencyLotStocks)(session);
|
|
35
|
+
if (!responseStocks.data || responseStocks.error) {
|
|
36
|
+
throw new Error(`Ocurrió un error al tratar de obtener los stocks de mi agencia. ${responseStocks.userMsg}`);
|
|
37
|
+
}
|
|
38
|
+
let deliverQuantity = props.deliver_quantity;
|
|
39
|
+
const itemStocks = responseStocks.data
|
|
40
|
+
.filter((x) => x.lot.item_id === props.item_id)
|
|
41
|
+
.sort((a, b) => b.available - a.available);
|
|
42
|
+
if (itemStocks.map((x) => x.available).reduce(common_1.reduceAdd, 0) <
|
|
43
|
+
props.deliver_quantity) {
|
|
44
|
+
throw new Error(`No hay suficiente stock en los lotes para realizar el descuento.`);
|
|
45
|
+
}
|
|
46
|
+
const movements = itemStocks.reduce((acc, stock) => {
|
|
47
|
+
if (deliverQuantity > 0 && stock.available > 0) {
|
|
48
|
+
const bookedQuantity = Math.min(stock.available, deliverQuantity);
|
|
49
|
+
deliverQuantity -= bookedQuantity;
|
|
50
|
+
acc.push({
|
|
51
|
+
item_id: props.item_id,
|
|
52
|
+
booked_quantity: bookedQuantity,
|
|
53
|
+
lot_id: stock.lot_id,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
return acc;
|
|
57
|
+
}, []);
|
|
58
|
+
bookingBody = {
|
|
59
|
+
reference: "LABORATORIO - Descuento de stock, desde webapp.",
|
|
60
|
+
agency_from_id: session.get("agency_id"),
|
|
61
|
+
agency_to_id: Number(virtual_client_agency_id),
|
|
62
|
+
booker_id: session.get("employee_id"),
|
|
63
|
+
transporter_id: session.get("employee_id"),
|
|
64
|
+
planned_delivery: (0, common_1.getDatePickerCurrentDate)(),
|
|
65
|
+
needs_transport: false,
|
|
66
|
+
movements,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
bookingBody = {
|
|
71
|
+
reference: "LABORATORIO - Descuento de stock, desde webapp.",
|
|
72
|
+
agency_from_id: session.get("agency_id"),
|
|
73
|
+
agency_to_id: Number(virtual_client_agency_id),
|
|
74
|
+
booker_id: session.get("employee_id"),
|
|
75
|
+
transporter_id: session.get("employee_id"),
|
|
76
|
+
planned_delivery: (0, common_1.getDatePickerCurrentDate)(),
|
|
77
|
+
needs_transport: false,
|
|
78
|
+
movements: [
|
|
79
|
+
{ item_id: props.item_id, booked_quantity: props.deliver_quantity },
|
|
80
|
+
],
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
const response1 = await (0, services_1.insertBookings)(headers, bookingBody);
|
|
84
|
+
if (response1.error || !response1.data) {
|
|
85
|
+
throw new Error(`Ocurrió un error al tratar de crear el envío a agencia virtual de cliente: ${response1.userMsg}`);
|
|
86
|
+
}
|
|
87
|
+
//Entregar el envío
|
|
88
|
+
const response2 = await (0, services_1.getDeliveryByBooking)(headers, response1.data.id);
|
|
89
|
+
if (response2.error || !response2.data) {
|
|
90
|
+
throw new Error(`Ocurrió un error al tratar de recibir: ${response1.userMsg}`);
|
|
91
|
+
}
|
|
92
|
+
return true;
|
|
93
|
+
});
|
|
94
|
+
};
|
|
95
|
+
exports.shipmentToVirtualClientAgency = shipmentToVirtualClientAgency;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.updateSpecialItem = exports.deleteSpecialItem = exports.createSpecialItem = exports.getSpecialItems = void 0;
|
|
4
|
+
const common_1 = require("@zauru-sdk/common");
|
|
5
|
+
const services_1 = require("@zauru-sdk/services");
|
|
6
|
+
/**
|
|
7
|
+
* Get specialItems from the web app table.
|
|
8
|
+
* @param headers Request headers.
|
|
9
|
+
* @param session Session object.
|
|
10
|
+
* @returns A Promise of AxiosUtilsResponse<WebAppRowGraphQL<SpecialItem>[]>>.
|
|
11
|
+
*/
|
|
12
|
+
const getSpecialItems = (headers, session) => {
|
|
13
|
+
return (0, common_1.handlePossibleAxiosErrors)(async () => {
|
|
14
|
+
const { special_product_web_app_table_id } = await (0, services_1.getVariablesByName)(headers, session, ["special_product_web_app_table_id"]);
|
|
15
|
+
const response = await (0, services_1.getWebAppTableRegisters)(session, special_product_web_app_table_id);
|
|
16
|
+
if (response.error) {
|
|
17
|
+
throw new Error(`Ocurrió un error al consultar los items especiales: ${response.userMsg}`);
|
|
18
|
+
}
|
|
19
|
+
const specialItems = response.data ?? [];
|
|
20
|
+
return specialItems;
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
exports.getSpecialItems = getSpecialItems;
|
|
24
|
+
/**
|
|
25
|
+
* Create a specialItem in the web app table.
|
|
26
|
+
* @param headers Request headers.
|
|
27
|
+
* @param session Session object.
|
|
28
|
+
* @param body SpecialItem data to be created.
|
|
29
|
+
* @returns A Promise of AxiosUtilsResponse<WebAppTableUpdateResponse>.
|
|
30
|
+
*/
|
|
31
|
+
const createSpecialItem = (headers, session, body) => {
|
|
32
|
+
return (0, common_1.handlePossibleAxiosErrors)(async () => {
|
|
33
|
+
const { special_product_web_app_table_id } = await (0, services_1.getVariablesByName)(headers, session, ["special_product_web_app_table_id"]);
|
|
34
|
+
const response = await (0, services_1.createWebAppTableRegister)(headers, special_product_web_app_table_id, body);
|
|
35
|
+
return response;
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
exports.createSpecialItem = createSpecialItem;
|
|
39
|
+
/**
|
|
40
|
+
* Delete a specialItem from the web app table.
|
|
41
|
+
* @param headers Request headers.
|
|
42
|
+
* @param session Session object.
|
|
43
|
+
* @param id ID of the specialItem to be deleted.
|
|
44
|
+
* @returns A Promise of AxiosUtilsResponse<WebAppTableUpdateResponse>.
|
|
45
|
+
*/
|
|
46
|
+
const deleteSpecialItem = (headers, session, id) => {
|
|
47
|
+
return (0, common_1.handlePossibleAxiosErrors)(async () => {
|
|
48
|
+
const { special_product_web_app_table_id } = await (0, services_1.getVariablesByName)(headers, session, ["special_product_web_app_table_id"]);
|
|
49
|
+
const response = await (0, services_1.deleteWebAppTableRegister)(headers, special_product_web_app_table_id, Number(id));
|
|
50
|
+
return response;
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
exports.deleteSpecialItem = deleteSpecialItem;
|
|
54
|
+
/**
|
|
55
|
+
* Update a specialItem in the web app table.
|
|
56
|
+
* @param headers Request headers.
|
|
57
|
+
* @param session Session object.
|
|
58
|
+
* @param id ID of the specialItem to be updated.
|
|
59
|
+
* @param body Updated specialItem data.
|
|
60
|
+
* @returns A Promise of AxiosUtilsResponse<WebAppTableUpdateResponse>.
|
|
61
|
+
*/
|
|
62
|
+
const updateSpecialItem = (headers, session, id, body) => {
|
|
63
|
+
return (0, common_1.handlePossibleAxiosErrors)(async () => {
|
|
64
|
+
const { special_product_web_app_table_id } = await (0, services_1.getVariablesByName)(headers, session, ["special_product_web_app_table_id"]);
|
|
65
|
+
const response = await (0, services_1.updateWebAppTableRegister)(headers, special_product_web_app_table_id, Number(id), body);
|
|
66
|
+
return response;
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
exports.updateSpecialItem = updateSpecialItem;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getTemplatesHistory = exports.createTemplateHistory = exports.updateTemplate = exports.deleteTemplate = exports.createTemplate = exports.getTemplates = void 0;
|
|
4
|
+
const common_1 = require("@zauru-sdk/common");
|
|
5
|
+
const services_1 = require("@zauru-sdk/services");
|
|
6
|
+
/**
|
|
7
|
+
* Get templates from the web app table.
|
|
8
|
+
* @param headers Request headers.
|
|
9
|
+
* @param session Session object.
|
|
10
|
+
* @returns A Promise of AxiosUtilsResponse<TemplateWebAppTable[]>.
|
|
11
|
+
*/
|
|
12
|
+
const getTemplates = (headers, session) => {
|
|
13
|
+
return (0, common_1.handlePossibleAxiosErrors)(async () => {
|
|
14
|
+
const { templates_web_app_table_id } = await (0, services_1.getVariablesByName)(headers, session, ["templates_web_app_table_id"]);
|
|
15
|
+
const response = await (0, services_1.getWebAppTableRegisters)(session, templates_web_app_table_id);
|
|
16
|
+
if (response.error) {
|
|
17
|
+
throw new Error(`Ocurrió un error al intentar obtener los templates: ${response.userMsg}`);
|
|
18
|
+
}
|
|
19
|
+
const templateRegisters = response.data ?? [];
|
|
20
|
+
return templateRegisters;
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
exports.getTemplates = getTemplates;
|
|
24
|
+
/**
|
|
25
|
+
* Create a template in the web app table.
|
|
26
|
+
* @param headers Request headers.
|
|
27
|
+
* @param session Session object.
|
|
28
|
+
* @param body Template data to be created.
|
|
29
|
+
* @returns A Promise of AxiosUtilsResponse<WebAppTableUpdateResponse>.
|
|
30
|
+
*/
|
|
31
|
+
const createTemplate = (headers, session, body) => {
|
|
32
|
+
return (0, common_1.handlePossibleAxiosErrors)(async () => {
|
|
33
|
+
const { templates_web_app_table_id } = await (0, services_1.getVariablesByName)(headers, session, ["templates_web_app_table_id"]);
|
|
34
|
+
const response = await (0, services_1.createWebAppTableRegister)(headers, templates_web_app_table_id, body);
|
|
35
|
+
return response;
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
exports.createTemplate = createTemplate;
|
|
39
|
+
/**
|
|
40
|
+
* Delete a template from the web app table.
|
|
41
|
+
* @param headers Request headers.
|
|
42
|
+
* @param session Session object.
|
|
43
|
+
* @param id ID of the template to be deleted.
|
|
44
|
+
* @returns A Promise of AxiosUtilsResponse<WebAppTableUpdateResponse>.
|
|
45
|
+
*/
|
|
46
|
+
const deleteTemplate = (headers, session, id) => {
|
|
47
|
+
return (0, common_1.handlePossibleAxiosErrors)(async () => {
|
|
48
|
+
const { templates_web_app_table_id } = await (0, services_1.getVariablesByName)(headers, session, ["templates_web_app_table_id"]);
|
|
49
|
+
const response = await (0, services_1.deleteWebAppTableRegister)(headers, templates_web_app_table_id, Number(id));
|
|
50
|
+
return response;
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
exports.deleteTemplate = deleteTemplate;
|
|
54
|
+
/**
|
|
55
|
+
* Update a template in the web app table.
|
|
56
|
+
* @param headers Request headers.
|
|
57
|
+
* @param session Session object.
|
|
58
|
+
* @param id ID of the template to be updated.
|
|
59
|
+
* @param body Updated template data.
|
|
60
|
+
* @returns A Promise of AxiosUtilsResponse<WebAppTableUpdateResponse>.
|
|
61
|
+
*/
|
|
62
|
+
const updateTemplate = (headers, session, id, body) => {
|
|
63
|
+
return (0, common_1.handlePossibleAxiosErrors)(async () => {
|
|
64
|
+
const { templates_web_app_table_id } = await (0, services_1.getVariablesByName)(headers, session, ["templates_web_app_table_id"]);
|
|
65
|
+
const response = await (0, services_1.updateWebAppTableRegister)(headers, templates_web_app_table_id, Number(id), body);
|
|
66
|
+
return response;
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
exports.updateTemplate = updateTemplate;
|
|
70
|
+
/**
|
|
71
|
+
* Create a template history entry in the web app table.
|
|
72
|
+
* @param headers Request headers.
|
|
73
|
+
* @param session Session object.
|
|
74
|
+
* @param body Template history data to be created.
|
|
75
|
+
* @returns A Promise of AxiosUtilsResponse<WebAppTableUpdateResponse>.
|
|
76
|
+
*/
|
|
77
|
+
const createTemplateHistory = (headers, session, body) => {
|
|
78
|
+
return (0, common_1.handlePossibleAxiosErrors)(async () => {
|
|
79
|
+
const { history_templates_web_app_table_id } = await (0, services_1.getVariablesByName)(headers, session, ["history_templates_web_app_table_id"]);
|
|
80
|
+
const response = await (0, services_1.createWebAppTableRegister)(headers, history_templates_web_app_table_id, body);
|
|
81
|
+
return response;
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
exports.createTemplateHistory = createTemplateHistory;
|
|
85
|
+
/**
|
|
86
|
+
* Get template history entries from the web app table.
|
|
87
|
+
* @param headers Request headers.
|
|
88
|
+
* @param session Session object.
|
|
89
|
+
* @returns A Promise of AxiosUtilsResponse<TemplateHistoryWebAppTable[]>.
|
|
90
|
+
*/
|
|
91
|
+
const getTemplatesHistory = (headers, session) => {
|
|
92
|
+
return (0, common_1.handlePossibleAxiosErrors)(async () => {
|
|
93
|
+
const { history_templates_web_app_table_id } = await (0, services_1.getVariablesByName)(headers, session, ["history_templates_web_app_table_id"]);
|
|
94
|
+
const response = await (0, services_1.getWebAppTableRegisters)(session, history_templates_web_app_table_id);
|
|
95
|
+
if (response.error) {
|
|
96
|
+
throw new Error(`Ocurrió un error al intentar obtener los history templates: ${response.userMsg}`);
|
|
97
|
+
}
|
|
98
|
+
const templateRegisters = response.data ?? [];
|
|
99
|
+
return templateRegisters;
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
exports.getTemplatesHistory = getTemplatesHistory;
|