@zauru-sdk/utils 1.0.50 → 1.0.60

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.
Files changed (79) hide show
  1. package/LICENCE.md +11 -11
  2. package/dist/cjs/index.js +40 -0
  3. package/dist/cjs/zauru/4pinos-receptions-form-history.utils.js +80 -0
  4. package/dist/cjs/zauru/automatic-number.utils.js +28 -0
  5. package/dist/cjs/zauru/bitacora-edicion-masiva.utils.js +56 -0
  6. package/dist/cjs/zauru/bundles.utils.js +168 -0
  7. package/dist/cjs/zauru/cases.utils.js +21 -0
  8. package/dist/cjs/zauru/consolidated-history.utils.js +58 -0
  9. package/dist/cjs/zauru/costos-items.utils.js +617 -0
  10. package/dist/cjs/zauru/deliveries.utils.js +50 -0
  11. package/dist/cjs/zauru/discharges-histsory.utils.js +52 -0
  12. package/dist/cjs/zauru/employees.utils.js +44 -0
  13. package/dist/cjs/zauru/form.utils.js +160 -0
  14. package/dist/cjs/zauru/invoices.utils.js +85 -0
  15. package/dist/cjs/zauru/items.utils.js +126 -0
  16. package/dist/cjs/zauru/lotes.utils.js +313 -0
  17. package/dist/cjs/zauru/motivos-rechazo.utils.js +23 -0
  18. package/dist/cjs/zauru/payees.utils.js +136 -0
  19. package/dist/cjs/zauru/profiles.utils.js +41 -0
  20. package/dist/cjs/zauru/providers.utils.js +40 -0
  21. package/dist/cjs/zauru/purchase-orders.utils.js +390 -0
  22. package/dist/cjs/zauru/shipments.utils.js +95 -0
  23. package/dist/cjs/zauru/specialItem.utils.js +69 -0
  24. package/dist/cjs/zauru/templates.utils.js +102 -0
  25. package/dist/cjs/zauru/tiposMuestra.utils.js +69 -0
  26. package/dist/cjs/zauru/webapp-tables.utils.js +20 -0
  27. package/package.json +16 -13
  28. package/CHANGELOG.md +0 -256
  29. package/src/index.ts +0 -24
  30. package/src/zauru/4pinos-receptions-form-history.utils.ts +0 -142
  31. package/src/zauru/automatic-number.utils.ts +0 -38
  32. package/src/zauru/bitacora-edicion-masiva.utils.ts +0 -99
  33. package/src/zauru/bundles.utils.ts +0 -251
  34. package/src/zauru/cases.utils.ts +0 -31
  35. package/src/zauru/consolidated-history.utils.ts +0 -102
  36. package/src/zauru/costos-items.utils.ts +0 -871
  37. package/src/zauru/deliveries.utils.ts +0 -77
  38. package/src/zauru/discharges-histsory.utils.ts +0 -105
  39. package/src/zauru/employees.utils.ts +0 -59
  40. package/src/zauru/form.utils.ts +0 -243
  41. package/src/zauru/invoices.utils.ts +0 -114
  42. package/src/zauru/items.utils.ts +0 -221
  43. package/src/zauru/lotes.utils.ts +0 -411
  44. package/src/zauru/motivos-rechazo.utils.ts +0 -47
  45. package/src/zauru/payees.utils.ts +0 -213
  46. package/src/zauru/profiles.utils.ts +0 -44
  47. package/src/zauru/providers.utils.ts +0 -67
  48. package/src/zauru/purchase-orders.utils.ts +0 -594
  49. package/src/zauru/shipments.utils.ts +0 -139
  50. package/src/zauru/specialItem.utils.ts +0 -136
  51. package/src/zauru/templates.utils.ts +0 -199
  52. package/src/zauru/tiposMuestra.utils.ts +0 -136
  53. package/src/zauru/webapp-tables.utils.ts +0 -36
  54. package/tsconfig.json +0 -24
  55. /package/dist/{index.js → esm/index.js} +0 -0
  56. /package/dist/{zauru → esm/zauru}/4pinos-receptions-form-history.utils.js +0 -0
  57. /package/dist/{zauru → esm/zauru}/automatic-number.utils.js +0 -0
  58. /package/dist/{zauru → esm/zauru}/bitacora-edicion-masiva.utils.js +0 -0
  59. /package/dist/{zauru → esm/zauru}/bundles.utils.js +0 -0
  60. /package/dist/{zauru → esm/zauru}/cases.utils.js +0 -0
  61. /package/dist/{zauru → esm/zauru}/consolidated-history.utils.js +0 -0
  62. /package/dist/{zauru → esm/zauru}/costos-items.utils.js +0 -0
  63. /package/dist/{zauru → esm/zauru}/deliveries.utils.js +0 -0
  64. /package/dist/{zauru → esm/zauru}/discharges-histsory.utils.js +0 -0
  65. /package/dist/{zauru → esm/zauru}/employees.utils.js +0 -0
  66. /package/dist/{zauru → esm/zauru}/form.utils.js +0 -0
  67. /package/dist/{zauru → esm/zauru}/invoices.utils.js +0 -0
  68. /package/dist/{zauru → esm/zauru}/items.utils.js +0 -0
  69. /package/dist/{zauru → esm/zauru}/lotes.utils.js +0 -0
  70. /package/dist/{zauru → esm/zauru}/motivos-rechazo.utils.js +0 -0
  71. /package/dist/{zauru → esm/zauru}/payees.utils.js +0 -0
  72. /package/dist/{zauru → esm/zauru}/profiles.utils.js +0 -0
  73. /package/dist/{zauru → esm/zauru}/providers.utils.js +0 -0
  74. /package/dist/{zauru → esm/zauru}/purchase-orders.utils.js +0 -0
  75. /package/dist/{zauru → esm/zauru}/shipments.utils.js +0 -0
  76. /package/dist/{zauru → esm/zauru}/specialItem.utils.js +0 -0
  77. /package/dist/{zauru → esm/zauru}/templates.utils.js +0 -0
  78. /package/dist/{zauru → esm/zauru}/tiposMuestra.utils.js +0 -0
  79. /package/dist/{zauru → esm/zauru}/webapp-tables.utils.js +0 -0
@@ -1,594 +0,0 @@
1
- import type { Session } from "@remix-run/node";
2
- import { CURRENCY_PREFIX, getNewDateByFormat, getStringFullDate, getZauruDateByText, handlePossibleAxiosErrors } from "@zauru-sdk/common";
3
- import { commitSession, createNewPurchaseOrder, deleteDelivery, deletePurchaseOrder, deleteReception, generateDistinctCode, getLotesWithPurchaseFormated, getPurchaseOrder, getPurchasesListDataTables, getVariablesByName, inactivarLote, updateReceivedPurchaseOrder } from "@zauru-sdk/services";
4
- import { AxiosUtilsResponse, DataTablesFilterBody, HTMLPurchasesListSchema, LoteWithPurchaseFormatedSchema, ObjectKeyString, PurchaseOrderGraphQL, PurchasesDataTableListFormatedSchema, PurchasesListResponseSchema, UpdatePurchaseOrderBody } from "@zauru-sdk/types";
5
-
6
-
7
- /**
8
- * Obtiene el listado de ordenes de compra, formateado especialmente para armar la tabla de edición de porcentajes y tolerancia
9
- * @param headers
10
- * @param session
11
- * @returns
12
- */
13
- export const getPurchasesDataTableListFormated = async (
14
- headers: any,
15
- session: Session,
16
- params: {
17
- page: string | null;
18
- perPage: string | null;
19
- search: string | null;
20
- from_production_agency_id?: boolean;
21
- }
22
- ): Promise<
23
- AxiosUtilsResponse<
24
- PurchasesListResponseSchema<LoteWithPurchaseFormatedSchema>
25
- >
26
- > => {
27
- return handlePossibleAxiosErrors(async () => {
28
- //PASO 1: Obtengo las variables, para buscar mi tag_id y mi basket_id
29
- const {
30
- recepciones_tag_id: tag_id,
31
- recepciones_basket_item_id: basket_id,
32
- production_agency_id: temp_production_agency_id,
33
- } = await getVariablesByName(headers, session, [
34
- "recepciones_tag_id",
35
- "recepciones_basket_item_id",
36
- "production_agency_id",
37
- ]);
38
- const hashProductionAgencyId = JSON.parse(
39
- temp_production_agency_id ?? "{}"
40
- );
41
- const production_agency_id =
42
- hashProductionAgencyId[session.get("agency_id")];
43
-
44
- const agency_id = params.from_production_agency_id
45
- ? production_agency_id
46
- : session.get("agency_id");
47
-
48
- //PASO 2: Busco mis ordenes de compra
49
- const ordersDataTablesResponse = await getOrdersDataTables(
50
- headers,
51
- params?.page ? Number(params?.page) : 1,
52
- params?.perPage ? Number(params?.perPage) : 10,
53
- params?.search ?? "",
54
- tag_id,
55
- agency_id
56
- );
57
-
58
- if (ordersDataTablesResponse.error) {
59
- throw new Error(ordersDataTablesResponse.userMsg);
60
- }
61
-
62
- const ordersDataTables = ordersDataTablesResponse?.data;
63
-
64
- //PASO 3: Busco mis lotes
65
- const lotesResponse = await getLotesWithPurchaseFormated(
66
- headers,
67
- agency_id,
68
- Number(basket_id),
69
- ordersDataTables?.orders ?? {},
70
- ordersDataTables?.desde,
71
- ordersDataTables?.hasta
72
- );
73
-
74
- if (lotesResponse.error) {
75
- throw new Error(lotesResponse.userMsg);
76
- }
77
-
78
- //PASO 4: Retorno la información
79
- return {
80
- recordsTotal: ordersDataTables?.recordsTotal ?? 0,
81
- recordsFiltered: ordersDataTables?.recordsFiltered ?? 0,
82
- draw: ordersDataTables?.draw ?? 0,
83
- data: lotesResponse?.data ?? [],
84
- };
85
- });
86
- };
87
-
88
- /**
89
- *
90
- * @param headers
91
- * @param tag_id
92
- * @param agency_id
93
- * @param page
94
- * @param perPage
95
- * @param search
96
- * @returns
97
- */
98
- const getOrdersDataTables = async (
99
- headers: any,
100
- page?: number,
101
- perPage?: number,
102
- search?: string,
103
- tag_id?: string,
104
- agency_id?: string
105
- ): Promise<
106
- AxiosUtilsResponse<{
107
- orders: ObjectKeyString<PurchasesDataTableListFormatedSchema>;
108
- desde?: string;
109
- hasta?: string;
110
- draw: number;
111
- recordsFiltered: number;
112
- recordsTotal: number;
113
- }>
114
- > => {
115
- return handlePossibleAxiosErrors(async () => {
116
- const body: DataTablesFilterBody = {
117
- order: { "0": { column: "1", dir: "desc" } },
118
- start: ((page ?? 1) - 1) * (perPage ?? 0),
119
- length: perPage ?? 0,
120
- search: { value: search ?? "", regex: false },
121
- tag: tag_id,
122
- agency: agency_id,
123
- };
124
-
125
- //Voy por las ordenes y las ordeno por fecha de recepción
126
- const ordersDataTablesResponse = await getPurchasesListDataTables(
127
- headers,
128
- body
129
- );
130
- const ordersDataTables = ordersDataTablesResponse.data;
131
- const orders = ordersDataTables?.data.sort(
132
- (a: HTMLPurchasesListSchema, b: HTMLPurchasesListSchema) =>
133
- getNewDateByFormat(a.rd).getTime() - getNewDateByFormat(b.rd).getTime()
134
- );
135
-
136
- const purchaseOrders: ObjectKeyString<PurchasesDataTableListFormatedSchema> =
137
- {};
138
- orders?.forEach((value: HTMLPurchasesListSchema) => {
139
- const id_i_pos = value.z.indexOf("purchase_orders/") + 16;
140
- const id_f_pos = value.z.indexOf('">');
141
- const zid_f_pos = value.z.indexOf("</a>");
142
- const id_n_i_pos = value.i.indexOf(">");
143
- const id_n_f_pos = value.i.indexOf("</a>");
144
- const new_date = getNewDateByFormat(value.dte);
145
- const ven_i_pos = value.ven.indexOf('">');
146
- const ven_f_pos = value.ven.indexOf("</a>");
147
- const id_number = value.i.substring(id_n_i_pos + 1, id_n_f_pos);
148
- const purchase_id = value.DT_RowId.replace(
149
- "purchases-purchase-order-",
150
- ""
151
- );
152
-
153
- purchaseOrders[id_number] = {
154
- id: value.z.substring(id_i_pos, id_f_pos),
155
- zid: value.z.substring(id_f_pos + 2, zid_f_pos),
156
- id_number: Number(id_number),
157
- no_orden: Number(purchase_id),
158
- dte: new_date,
159
- o: Boolean(value.o),
160
- vendor: value.ven.substring(ven_i_pos + 2, ven_f_pos),
161
- po_editable: parseInt(value.due.substring(1)) > 0,
162
- dis: Number(value.dis),
163
- och: Number(value.och),
164
- rd: value.rd,
165
- } as PurchasesDataTableListFormatedSchema;
166
- });
167
-
168
- return {
169
- orders: purchaseOrders,
170
- draw: ordersDataTables?.draw ?? 0,
171
- recordsFiltered: ordersDataTables?.recordsFiltered ?? 0,
172
- recordsTotal: ordersDataTables?.recordsTotal ?? 0,
173
- desde: orders?.length ? getZauruDateByText(orders[0].rd) : undefined,
174
- hasta: orders?.length
175
- ? getZauruDateByText(orders[orders.length - 1].rd)
176
- : undefined,
177
- };
178
- });
179
- };
180
-
181
- /**
182
- * getPurchaseOrderDataTables Obtiene una orden de compra ya formateada con todos sus campos.
183
- * @param headers
184
- * @param tag_id
185
- * @param agency_id
186
- * @param search
187
- * @returns
188
- */
189
- export const getPurchaseOrderDataTables = async (
190
- headers: any,
191
- search: string,
192
- tag_id?: string,
193
- agency_id?: string
194
- ): Promise<PurchasesDataTableListFormatedSchema> => {
195
- const body: DataTablesFilterBody = {
196
- order: { "0": { column: "1", dir: "desc" } },
197
- start: 0,
198
- length: 0,
199
- search: { value: search, regex: false },
200
- tag: tag_id,
201
- agency: agency_id,
202
- };
203
-
204
- //Voy por las ordenes y las ordeno por fecha de recepción
205
- const ordersDataTablesResponse = await getPurchasesListDataTables(
206
- headers,
207
- body
208
- );
209
-
210
- const ordersDataTables = ordersDataTablesResponse.data;
211
-
212
- const getPurchaseOrderFormated = (
213
- value: HTMLPurchasesListSchema
214
- ): PurchasesDataTableListFormatedSchema => {
215
- const id_i_pos = value.z.indexOf("purchase_orders/") + 16;
216
- const id_f_pos = value.z.indexOf('">');
217
- const zid_f_pos = value.z.indexOf("</a>");
218
- const id_n_i_pos = value.i.indexOf(">");
219
- const id_n_f_pos = value.i.indexOf("</a>");
220
- const new_date = getNewDateByFormat(value.dte);
221
- const ven_i_pos = value.ven.indexOf('">');
222
- const ven_f_pos = value.ven.indexOf("</a>");
223
- const id_number = value.i.substring(id_n_i_pos + 1, id_n_f_pos);
224
- const purchase_id = value.DT_RowId.replace("purchases-purchase-order-", "");
225
-
226
- return {
227
- id: value.z.substring(id_i_pos, id_f_pos),
228
- zid: value.z.substring(id_f_pos + 2, zid_f_pos),
229
- id_number: Number(id_number),
230
- no_orden: Number(purchase_id),
231
- dte: new_date,
232
- o: Boolean(value.o),
233
- vendor: value.ven.substring(ven_i_pos + 2, ven_f_pos),
234
- po_editable: parseInt(value.due.substring(1)) > 0,
235
- dis: Number(value.dis),
236
- och: Number(value.och),
237
- rd: value.rd,
238
- } as PurchasesDataTableListFormatedSchema;
239
- };
240
-
241
- !ordersDataTables?.data?.length &&
242
- console.log(
243
- "========== NO SE ENCONTRO NINGUNA ORDEN DE COMPRA ==========="
244
- );
245
-
246
- const purchaseOrderDataTable = getPurchaseOrderFormated(
247
- ordersDataTables?.data[0] as HTMLPurchasesListSchema
248
- );
249
-
250
- return purchaseOrderDataTable;
251
- };
252
-
253
- /**
254
- * updatePurchaseItemPrice
255
- * @param headers
256
- * @param data
257
- * @param purchase_id
258
- */
259
- export const updatePurchaseItemPrice = async (
260
- headers: any,
261
- data: {
262
- purchase_order_details_attributes: Record<
263
- string,
264
- { unit_cost: number; item_id: number; id: number }
265
- >;
266
- },
267
- purchase_id: number
268
- ): Promise<AxiosUtilsResponse<boolean>> => {
269
- return handlePossibleAxiosErrors(async () => {
270
- const body = {
271
- purchase_order: {
272
- purchase_order_details_attributes:
273
- data.purchase_order_details_attributes,
274
- },
275
- } as UpdatePurchaseOrderBody;
276
- const responseUpdate = await updateReceivedPurchaseOrder(
277
- headers,
278
- body,
279
- purchase_id
280
- );
281
- if (responseUpdate.error) {
282
- throw new Error(responseUpdate.userMsg);
283
- }
284
-
285
- return true;
286
- });
287
- };
288
-
289
- /**
290
- * updateOchAndDis
291
- * @param headers
292
- * @param session
293
- * @returns
294
- */
295
- export const updateOchAndDis = async (
296
- headers: any,
297
- data: { discount?: number | string; other_charges?: number | string },
298
- purchase_id: number
299
- ): Promise<AxiosUtilsResponse<boolean>> => {
300
- return handlePossibleAxiosErrors(async () => {
301
- const body = {
302
- purchase_order: {
303
- discount: data?.discount,
304
- other_charges: data.other_charges,
305
- },
306
- } as UpdatePurchaseOrderBody;
307
- await updateReceivedPurchaseOrder(headers, body, purchase_id);
308
-
309
- return true;
310
- });
311
- };
312
-
313
- /**
314
- * updatePurchaseOrderReception
315
- * @param headers
316
- * @param data
317
- * @param purchase_id
318
- * @returns
319
- */
320
- export const updatePurchaseOrderReception = async (
321
- headers: any,
322
- data: {
323
- payee_id?: string;
324
- purchase_order_details_attributes: Record<
325
- string,
326
- { item_id: number; id: number }
327
- >;
328
- },
329
- purchase_id: number
330
- ): Promise<AxiosUtilsResponse<boolean>> => {
331
- return handlePossibleAxiosErrors(async () => {
332
- const body = {
333
- purchase_order: {
334
- payee_id: data.payee_id,
335
- purchase_order_details_attributes:
336
- data.purchase_order_details_attributes,
337
- },
338
- } as UpdatePurchaseOrderBody;
339
- await updateReceivedPurchaseOrder(headers, body, purchase_id);
340
-
341
- return true;
342
- });
343
- };
344
-
345
- /**
346
- * Obtengo los id's de las órdenes de compra en un arreglo numérico
347
- * @param headers
348
- * @param session
349
- * @param extraParams
350
- * @returns
351
- */
352
- export const getOrderIDS = async (
353
- headers: any,
354
- session: Session,
355
- extraParams: {
356
- vendor?: string;
357
- vendor_category?: string;
358
- item?: string;
359
- desde?: string;
360
- hasta?: string;
361
- }
362
- ): Promise<AxiosUtilsResponse<number[]>> => {
363
- return handlePossibleAxiosErrors(async () => {
364
- const { recepciones_tag_id: tag_id } = await getVariablesByName(
365
- headers,
366
- session,
367
- ["recepciones_tag_id", "recepciones_basket_item_id"]
368
- );
369
-
370
- const body: DataTablesFilterBody = {
371
- order: { "0": { column: "1", dir: "desc" } },
372
- start: 0,
373
- length: 2000, //para ir por todas
374
- search: { value: "", regex: false },
375
- tag: tag_id,
376
- agency: session.get("agency_id") ?? undefined,
377
- vendor: extraParams.vendor,
378
- vendor_category: extraParams.vendor_category,
379
- item: extraParams.item,
380
- Desde: extraParams.desde,
381
- Hasta: extraParams.hasta,
382
- };
383
-
384
- //Voy por las ordenes y las ordeno por fecha de recepción
385
- const ordersDataTablesResponse = await getPurchasesListDataTables(
386
- headers,
387
- body
388
- );
389
-
390
- const ordersDataTables = ordersDataTablesResponse.data;
391
-
392
- return (
393
- ordersDataTables?.data?.map((x) =>
394
- Number(x.DT_RowId.replace("purchases-purchase-order-", ""))
395
- ) ?? []
396
- );
397
- });
398
- };
399
-
400
- /**
401
- * deleteOrder
402
- * @returns
403
- */
404
- export const deletePurchaseOrderProcess = async (
405
- headers: any,
406
- session: Session,
407
- id: string | number
408
- ) => {
409
- return handlePossibleAxiosErrors(async () => {
410
- const {
411
- data: purchaseOrder,
412
- error: poError,
413
- userMsg: poUserMsg,
414
- } = await getPurchaseOrder(session, id);
415
-
416
- if (poError || !purchaseOrder) {
417
- throw new Error(poUserMsg);
418
- }
419
-
420
- //Elimino las recepciones si es que tiene
421
- for (const reception of purchaseOrder.receptions) {
422
- if (reception.received && !reception.voided) {
423
- const responseDeleteReception = await deleteReception(
424
- headers,
425
- reception.id,
426
- purchaseOrder.id
427
- );
428
-
429
- if (responseDeleteReception.error || !responseDeleteReception.data) {
430
- throw new Error(responseDeleteReception.userMsg);
431
- }
432
- }
433
- }
434
-
435
- //Elimino los envíos si es que tiene
436
- for (const ship of purchaseOrder.shipment_purchase_orders) {
437
- const responseDeleteShip = await deleteDelivery(
438
- headers,
439
- ship.shipment_id
440
- );
441
-
442
- if (responseDeleteShip.error || !responseDeleteShip.data) {
443
- throw new Error(responseDeleteShip.userMsg);
444
- }
445
- }
446
-
447
- //Inactivo los lotes que tenga
448
- for (const lot of purchaseOrder.lots) {
449
- await inactivarLote(headers, lot.id);
450
- }
451
-
452
- const responseDeletePO = await deletePurchaseOrder(headers, id);
453
- if (responseDeletePO.error) {
454
- throw new Error(responseDeletePO.userMsg);
455
- }
456
-
457
- return true;
458
- });
459
- };
460
-
461
- //============================================ METODOS TASK (Commits de sesión para dejar las notificaciones de editando...)
462
- export type TaskSchema = {
463
- timeStamp: number;
464
- iniciada: string;
465
- total_ordenes: number;
466
- completadas: number;
467
- };
468
-
469
- /**
470
- * Commitea una task iniciada para la pantalla de edición masiva de órdenes de compra
471
- * @param session
472
- * @param ordenes
473
- * @param timeStamp
474
- */
475
- export const commitTask = async (
476
- session: Session,
477
- ordenes: Array<number>,
478
- timeStamp: number
479
- ) => {
480
- const newTask = {
481
- timeStamp,
482
- iniciada: getStringFullDate(new Date()),
483
- total_ordenes: ordenes.length,
484
- completadas: 0,
485
- } as TaskSchema;
486
- const updateTasks = (session.get("updateTasks") ?? []) as Array<TaskSchema>;
487
- session.set("updateTasks", [...updateTasks, newTask]);
488
- await commitSession(session);
489
- };
490
-
491
- /**
492
- * Comitea una task finalizada para la pantalla de edición de órdenes de compra masiva
493
- * @param session
494
- * @param timeStamp
495
- */
496
- export const commitEndTask = async (session: Session, timeStamp: number) => {
497
- let updateTasks = session.get("updateTasks") as Array<TaskSchema>;
498
- if (
499
- Array.isArray(updateTasks) &&
500
- updateTasks.some((task: TaskSchema) => task.timeStamp === timeStamp)
501
- ) {
502
- updateTasks = updateTasks.map((x: TaskSchema) => {
503
- if (x.timeStamp === timeStamp) {
504
- return {
505
- ...x,
506
- completadas: Number(x.completadas) + 1,
507
- } as TaskSchema;
508
- }
509
- return x;
510
- });
511
- session.set("updateTasks", updateTasks);
512
- await commitSession(session);
513
- }
514
- };
515
-
516
- /**
517
- * Elimina de la sesión una task.
518
- * @param session
519
- * @param timeStamp
520
- */
521
- export const deleteTask = async (
522
- session: Session,
523
- timeStamp: number
524
- ): Promise<boolean> => {
525
- let updateTasks = session.get("updateTasks") as Array<TaskSchema>;
526
- if (
527
- Array.isArray(updateTasks) &&
528
- updateTasks.some((task: TaskSchema) => task.timeStamp === timeStamp)
529
- ) {
530
- //La elimino de la lista
531
- updateTasks = updateTasks.filter((task) => task.timeStamp !== timeStamp);
532
- session.set("updateTasks", updateTasks);
533
- await commitSession(session);
534
- return true;
535
- }
536
- return false;
537
- };
538
-
539
- /**
540
- * createNewLabItemRequest
541
- * @param headers
542
- * @param session
543
- * @param body
544
- * @returns
545
- */
546
- export const createNewLabItemRequest = (
547
- headers: any,
548
- session: Session,
549
- body: Partial<PurchaseOrderGraphQL> & { [key: string]: any }
550
- ): Promise<AxiosUtilsResponse<PurchaseOrderGraphQL>> => {
551
- return handlePossibleAxiosErrors(async () => {
552
- const { lab_charge_term_default_id, lab_agency_id, laboratory_proyect_id } =
553
- await getVariablesByName(headers, session, [
554
- "lab_charge_term_default_id",
555
- "lab_agency_id",
556
- "laboratory_proyect_id",
557
- ]);
558
-
559
- const id_number = generateDistinctCode("POLAB");
560
-
561
- const sendBody = {
562
- ...body,
563
- shipping_date: body.issue_date,
564
- charge_term_id: Number(lab_charge_term_default_id),
565
- agency_id: Number(lab_agency_id),
566
- currency_id: CURRENCY_PREFIX.find((x) => x.prefix === "Q")?.id,
567
- incoterm_id: 1,
568
- taxable: false,
569
- import: false,
570
- id_number,
571
- reference: "LABORATORIO - Solicitud de insumos desde WebApp",
572
- origin: "LABORATORIO",
573
- purchase_order_details: [
574
- {
575
- booked_quantity: body.booked_quantity,
576
- item_id: body.item_id,
577
- unit_cost: 1,
578
- tag_id: Number(laboratory_proyect_id),
579
- },
580
- ],
581
- taggings: [{ tag_id: Number(laboratory_proyect_id) }],
582
- } as Partial<PurchaseOrderGraphQL>;
583
-
584
- const response = await createNewPurchaseOrder(headers, sendBody);
585
-
586
- if (!response.data || response.error) {
587
- throw new Error(
588
- "Ocurrió un error al crear la recepción de insumos: " + response.userMsg
589
- );
590
- }
591
-
592
- return response.data;
593
- });
594
- };