@zauru-sdk/hooks 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.
Files changed (46) hide show
  1. package/dist/alerts.d.ts +1 -1
  2. package/dist/{alerts.js → cjs/alerts.js} +13 -9
  3. package/dist/{automaticNumbers.js → cjs/automaticNumbers.js} +20 -16
  4. package/dist/cjs/catalogs.js +267 -0
  5. package/dist/{components → cjs/components}/Alert.js +18 -15
  6. package/dist/cjs/components/index.js +17 -0
  7. package/dist/cjs/index.js +26 -0
  8. package/dist/{onlineStatus.js → cjs/onlineStatus.js} +8 -4
  9. package/dist/cjs/profiles.js +64 -0
  10. package/dist/{receptions.js → cjs/receptions.js} +67 -52
  11. package/dist/{session.js → cjs/session.js} +19 -15
  12. package/dist/{templates.js → cjs/templates.js} +20 -16
  13. package/dist/{useWindowDimensions.js → cjs/useWindowDimensions.js} +8 -4
  14. package/dist/esm/alerts.js +37 -0
  15. package/dist/esm/automaticNumbers.js +57 -0
  16. package/dist/esm/catalogs.js +267 -0
  17. package/dist/esm/components/Alert.js +100 -0
  18. package/dist/esm/components/index.js +17 -0
  19. package/dist/esm/index.js +26 -0
  20. package/dist/esm/onlineStatus.js +31 -0
  21. package/dist/esm/profiles.js +64 -0
  22. package/dist/esm/receptions.js +348 -0
  23. package/dist/esm/session.js +55 -0
  24. package/dist/esm/templates.js +58 -0
  25. package/dist/esm/useWindowDimensions.js +31 -0
  26. package/dist/receptions.d.ts +2 -2
  27. package/package.json +14 -19
  28. package/.eslintrc.cjs +0 -83
  29. package/CHANGELOG.md +0 -232
  30. package/dist/catalogs.js +0 -230
  31. package/dist/components/index.js +0 -1
  32. package/dist/index.js +0 -10
  33. package/dist/profiles.js +0 -57
  34. package/src/alerts.ts +0 -43
  35. package/src/automaticNumbers.ts +0 -74
  36. package/src/catalogs.ts +0 -557
  37. package/src/components/Alert.tsx +0 -149
  38. package/src/components/index.ts +0 -1
  39. package/src/index.ts +0 -11
  40. package/src/onlineStatus.ts +0 -34
  41. package/src/profiles.ts +0 -103
  42. package/src/receptions.ts +0 -548
  43. package/src/session.ts +0 -69
  44. package/src/templates.ts +0 -84
  45. package/src/useWindowDimensions.ts +0 -34
  46. package/tsconfig.json +0 -26
@@ -1,34 +0,0 @@
1
- import { useState, useEffect } from "react";
2
-
3
- // Hook personalizado para verificar el estado de conexión
4
- export const useIsOnline = () => {
5
- // Verificar si estamos en el entorno del servidor o del cliente
6
- const isServer = typeof window === "undefined";
7
-
8
- // Estado local para almacenar si la aplicación está en línea o no
9
- const [isOnline, setIsOnline] = useState(!isServer && navigator.onLine);
10
-
11
- // Función para manejar el cambio de estado de conexión
12
- const handleConnectionChange = () => {
13
- setIsOnline(navigator.onLine);
14
- };
15
-
16
- useEffect(() => {
17
- if (isServer) {
18
- // Si estamos en el servidor, no añadir los event listeners
19
- return;
20
- }
21
-
22
- // Añadir event listeners
23
- window.addEventListener("online", handleConnectionChange);
24
- window.addEventListener("offline", handleConnectionChange);
25
-
26
- // Limpiar event listeners al desmontar el componente
27
- return () => {
28
- window.removeEventListener("online", handleConnectionChange);
29
- window.removeEventListener("offline", handleConnectionChange);
30
- };
31
- }, [isServer]);
32
-
33
- return isOnline;
34
- };
package/src/profiles.ts DELETED
@@ -1,103 +0,0 @@
1
- import { useFetcher } from "@remix-run/react";
2
- import { useEffect, useState } from "react";
3
- import { AlertType, showAlert } from "./index.js";
4
- import type {
5
- AgencyGraphQL,
6
- EmployeeGraphQL,
7
- OauthProfile,
8
- ProfileResponse,
9
- } from "@zauru-sdk/types";
10
- import {
11
- PROFILE_NAMES,
12
- profileFetchStart,
13
- profileFetchSuccess,
14
- useAppDispatch,
15
- useAppSelector,
16
- } from "@zauru-sdk/redux";
17
-
18
- type ProfileType<T> = {
19
- data: T;
20
- loading: boolean;
21
- };
22
-
23
- const useGetProfile = <T>(PROFILE_NAME: PROFILE_NAMES): ProfileType<T> => {
24
- const fetcher = useFetcher<
25
- | {
26
- title: string;
27
- description: string;
28
- type: AlertType;
29
- }
30
- | { [key: string]: T[] }
31
- >();
32
- const dispatch = useAppDispatch();
33
- const profileData = useAppSelector((state) => state.profiles[PROFILE_NAME]);
34
- const [data, setData] = useState<ProfileType<T>>({
35
- data: Object.keys(profileData?.data)?.length
36
- ? (profileData?.data as T)
37
- : ({} as T),
38
- loading: profileData?.loading,
39
- });
40
-
41
- useEffect(() => {
42
- if (fetcher.data?.title) {
43
- showAlert({
44
- description: fetcher.data?.description?.toString(),
45
- title: fetcher.data?.title?.toString(),
46
- type: fetcher.data?.type?.toString() as AlertType,
47
- });
48
- }
49
- }, [fetcher.data]);
50
-
51
- useEffect(() => {
52
- if (fetcher.state === "idle" && fetcher.data != null) {
53
- const receivedData = fetcher.data as { [key: string]: T };
54
- if (receivedData) {
55
- setData({ data: receivedData[PROFILE_NAME], loading: false });
56
- dispatch(
57
- profileFetchSuccess({
58
- name: PROFILE_NAME,
59
- data: receivedData[PROFILE_NAME],
60
- })
61
- );
62
- }
63
- }
64
- }, [fetcher, dispatch, PROFILE_NAME]);
65
-
66
- useEffect(() => {
67
- if (Object.keys(profileData?.data).length <= 0) {
68
- try {
69
- setData({ ...data, loading: true });
70
- dispatch(profileFetchStart(PROFILE_NAME));
71
- fetcher.load(`/api/profiles?profile=${PROFILE_NAME}`);
72
- } catch (ex) {
73
- showAlert({
74
- type: "error",
75
- title: `Ocurrió un error al cargar el perfil: ${PROFILE_NAME}.`,
76
- description: "Error: " + ex,
77
- });
78
- }
79
- }
80
- }, []);
81
-
82
- return data;
83
- };
84
-
85
- export const useGetAgencyProfile = (): {
86
- loading: boolean;
87
- data: AgencyGraphQL;
88
- } => useGetProfile<AgencyGraphQL>("agencyProfile");
89
-
90
- export const useGetUserProfile = (): {
91
- loading: boolean;
92
- data: ProfileResponse;
93
- } => useGetProfile<ProfileResponse>("userProfile");
94
-
95
- export const useGetOauthProfile = (): {
96
- loading: boolean;
97
- data: OauthProfile;
98
- } => useGetProfile<OauthProfile>("oauthProfile");
99
-
100
- export const useGetEmployeeProfile = (): {
101
- loading: boolean;
102
- data: EmployeeGraphQL;
103
- } => useGetProfile<EmployeeGraphQL>("employeeProfile");
package/src/receptions.ts DELETED
@@ -1,548 +0,0 @@
1
- import { useFetcher } from "@remix-run/react";
2
- import {
3
- RECEPTION_NAMES,
4
- ReduxParamsConfig,
5
- receptionFetchStart,
6
- receptionFetchSuccess,
7
- useAppDispatch,
8
- useAppSelector,
9
- } from "@zauru-sdk/redux";
10
- import {
11
- ItemAssociatedLots,
12
- ItemGraphQL,
13
- NewPurchaseOrderResponse,
14
- PayeeGraphQL,
15
- PurchaseOrderGeneralInfo,
16
- PurchaseOrderGraphQL,
17
- QueueFormReceptionWebAppTable,
18
- RejectionWebAppTableObject,
19
- WebAppRowGraphQL,
20
- GenericDynamicTableColumn,
21
- } from "@zauru-sdk/types";
22
- import { useEffect, useMemo, useState } from "react";
23
- import { AlertType, showAlert } from "./index.js";
24
- import {
25
- getBasketsSchema,
26
- reduceAdd,
27
- toFixedIfNeeded,
28
- } from "@zauru-sdk/common";
29
-
30
- type ReturnType<T> = {
31
- data: T;
32
- loading: boolean;
33
- };
34
-
35
- type ConfigProps = { online?: boolean; wheres?: string[] };
36
-
37
- const useGetReceptionObject = <T>(
38
- RECEPTION_NAME: RECEPTION_NAMES,
39
- { online = false, wheres = [] }: ReduxParamsConfig = {}
40
- ): ReturnType<T> => {
41
- const fetcher = useFetcher<
42
- | {
43
- title: string;
44
- description: string;
45
- type: AlertType;
46
- }
47
- | { [key: string]: T[] }
48
- >();
49
- const dispatch = useAppDispatch();
50
- const objectData = useAppSelector(
51
- (state) => state.receptions[RECEPTION_NAME]
52
- );
53
-
54
- const [data, setData] = useState<ReturnType<T>>({
55
- data: Array.isArray(objectData?.data)
56
- ? objectData?.data.length
57
- ? (objectData?.data as T)
58
- : ([] as unknown as T)
59
- : Object.keys(objectData?.data || {}).length
60
- ? (objectData?.data as T)
61
- : ({} as T),
62
- loading: objectData.loading,
63
- });
64
-
65
- useEffect(() => {
66
- if (fetcher.data?.title) {
67
- showAlert({
68
- description: fetcher.data?.description?.toString(),
69
- title: fetcher.data?.title?.toString(),
70
- type: fetcher.data?.type?.toString() as AlertType,
71
- });
72
- }
73
- }, [fetcher.data]);
74
-
75
- useEffect(() => {
76
- if (fetcher.state === "idle" && fetcher.data != null) {
77
- const receivedData = fetcher.data as { [key: string]: T };
78
- if (receivedData) {
79
- setData({ data: receivedData[RECEPTION_NAME], loading: false });
80
- dispatch(
81
- receptionFetchSuccess({
82
- name: RECEPTION_NAME,
83
- data: receivedData[RECEPTION_NAME],
84
- })
85
- );
86
- }
87
- }
88
- }, [fetcher, dispatch, RECEPTION_NAME]);
89
-
90
- useEffect(() => {
91
- const isEmptyData = Array.isArray(objectData?.data)
92
- ? objectData?.data.length <= 0
93
- : Object.keys(objectData?.data || {}).length <= 0;
94
-
95
- if (isEmptyData || objectData.reFetch || online) {
96
- try {
97
- setData({ ...data, loading: true });
98
- dispatch(receptionFetchStart(RECEPTION_NAME));
99
- // Convierte cada elemento del array a una cadena codificada para URL
100
- const encodedWheres = wheres.map((where) => encodeURIComponent(where));
101
- // Une los elementos codificados con '&'
102
- const wheresQueryParam = encodedWheres.join("&");
103
- fetcher.load(
104
- `/api/receptions?object=${RECEPTION_NAME}&wheres=${wheresQueryParam}`
105
- );
106
- } catch (ex) {
107
- showAlert({
108
- type: "error",
109
- title: `Ocurrió un error al cargar el object de receptions: ${RECEPTION_NAME}.`,
110
- description: "Error: " + ex,
111
- });
112
- }
113
- }
114
- }, []);
115
-
116
- return data;
117
- };
118
-
119
- export const useGetProcesses = (
120
- config?: ConfigProps
121
- ): {
122
- loading: boolean;
123
- data: WebAppRowGraphQL<QueueFormReceptionWebAppTable>[];
124
- } =>
125
- useGetReceptionObject<WebAppRowGraphQL<QueueFormReceptionWebAppTable>[]>(
126
- "queueNewReceptions",
127
- config
128
- );
129
-
130
- export const useGetPOReceptions = (
131
- config?: ConfigProps
132
- ): {
133
- loading: boolean;
134
- data: PurchaseOrderGraphQL[];
135
- } => useGetReceptionObject<PurchaseOrderGraphQL[]>("poReceptions", config);
136
-
137
- export const useGetBasketLots = (): {
138
- loading: boolean;
139
- data: ItemAssociatedLots;
140
- } => useGetReceptionObject<ItemAssociatedLots>("basketLots");
141
-
142
- export const useGetRejectionInfo = (): {
143
- loading: boolean;
144
- data: RejectionWebAppTableObject;
145
- } => useGetReceptionObject<RejectionWebAppTableObject>("rejectionInfo");
146
-
147
- export const useGetNewPurchaseOrderInfo = (): {
148
- loading: boolean;
149
- data: NewPurchaseOrderResponse;
150
- } => useGetReceptionObject<NewPurchaseOrderResponse>("newPurchaseOrderInfo");
151
-
152
- export const useGetPurchaseOrderGeneralInfo = (): {
153
- loading: boolean;
154
- data: PurchaseOrderGeneralInfo;
155
- } =>
156
- useGetReceptionObject<PurchaseOrderGeneralInfo>("purchaseOrderGeneralInfo");
157
-
158
- /**
159
- * ---------------- Hooks personalizados
160
- */
161
- type FormInput = {
162
- idNumberInput: string;
163
- rType: string;
164
- vendor: string;
165
- porcentajeRechazo: string;
166
- [key: string]: string | undefined;
167
- };
168
-
169
- type PesadaBody = {
170
- id: number;
171
- baskets: number;
172
- totalWeight: number;
173
- discount: number;
174
- netWeight: string;
175
- weightByBasket: string;
176
- probableUtilization: number;
177
- lbDiscounted: number;
178
- };
179
-
180
- type PesadaFooter = {
181
- id: string;
182
- baskets: string;
183
- totalWeight: string;
184
- discount: string;
185
- netWeight: string;
186
- weightByBasket: string;
187
- };
188
-
189
- export const useGetPesadas = (
190
- purchaseOrder: PurchaseOrderGraphQL
191
- ): [PesadaBody[], PesadaFooter, GenericDynamicTableColumn[]] => {
192
- const [pesadas, footerPesadas, headersPesadas] = useMemo(() => {
193
- const tempPesadas: PesadaBody[] = [
194
- ...purchaseOrder.purchase_order_details?.map((x, index) => {
195
- const parsedReference = x.reference?.split(","); //eg: "reference": "698,25,0", // peso neto, canastas, descuento
196
- const totalWeight = parsedReference[0]
197
- ? Number(parsedReference[0]) ?? 0
198
- : 0;
199
- const baskets = parsedReference[1]
200
- ? Number(parsedReference[1]) ?? 0
201
- : 0;
202
- const discount = parsedReference[2]
203
- ? Number(parsedReference[2]) ?? 0
204
- : 0;
205
- //TODO sacar el peso de la canasta de la API de Zauru
206
- const basketWeight = 5;
207
- let netWeight = totalWeight - baskets * basketWeight; //Se le resta el peso de las canastas
208
- netWeight = netWeight * ((100 - discount) / 100); //Se le aplica el descuento
209
- const weightByBasket = netWeight / baskets;
210
-
211
- //Probable aprovechamiento en planta
212
- const probableUtilization =
213
- netWeight * ((100 - purchaseOrder?.discount) / 100);
214
-
215
- //libras o unidades descontadas
216
- const lbDiscounted = netWeight - probableUtilization;
217
-
218
- return {
219
- id: index + 1,
220
- baskets,
221
- totalWeight,
222
- discount,
223
- netWeight: toFixedIfNeeded(netWeight),
224
- weightByBasket: toFixedIfNeeded(weightByBasket),
225
- probableUtilization,
226
- lbDiscounted,
227
- };
228
- }),
229
- ];
230
-
231
- const totales = {
232
- id: "",
233
- baskets: toFixedIfNeeded(
234
- tempPesadas?.map((x) => x.baskets).reduce(reduceAdd, 0)
235
- ),
236
- totalWeight: toFixedIfNeeded(
237
- tempPesadas?.map((x) => x.totalWeight).reduce(reduceAdd, 0)
238
- ),
239
- discount: "-",
240
- netWeight: toFixedIfNeeded(
241
- tempPesadas?.map((x) => Number(x.netWeight)).reduce(reduceAdd, 0)
242
- ),
243
- weightByBasket: "-",
244
- lbDiscounted: toFixedIfNeeded(
245
- tempPesadas?.map((x) => Number(x.lbDiscounted)).reduce(reduceAdd, 0)
246
- ),
247
- probableUtilization: toFixedIfNeeded(
248
- tempPesadas
249
- ?.map((x) => Number(x.probableUtilization))
250
- .reduce(reduceAdd, 0)
251
- ),
252
- };
253
-
254
- const headers: GenericDynamicTableColumn[] = [
255
- { label: "#", name: "id", type: "label", width: 5 },
256
- { label: "Canastas", name: "baskets", type: "label" },
257
- { label: "Peso báscula", name: "totalWeight", type: "label" },
258
- { label: "Descuento (%)", name: "discount", type: "label" },
259
- { label: "Peso Neto", name: "netWeight", type: "label" },
260
- {
261
- label: "Peso Neto - %Rechazo",
262
- name: "probableUtilization",
263
- type: "label",
264
- },
265
- {
266
- label: "Lb o Unidades descontadas",
267
- name: "lbDiscounted",
268
- type: "label",
269
- },
270
- {
271
- label: "Peso Neto por canasta",
272
- name: "weightByBasket",
273
- type: "label",
274
- },
275
- ];
276
- return [tempPesadas, totales, headers];
277
- }, [purchaseOrder]);
278
-
279
- return [pesadas, footerPesadas, headersPesadas];
280
- };
281
-
282
- /**
283
- * Sirve para imprimir offline
284
- * @param formInput
285
- * @returns
286
- */
287
- export const getPesadasByForm = (formInput: FormInput) => {
288
- // Inicializar array de pesadas
289
- const tempPesadas: PesadaBody[] = [];
290
-
291
- // Iterar sobre los campos del formulario y extraer la información de pesadas
292
- let index = 0;
293
- while (formInput.hasOwnProperty(`basket${index}`)) {
294
- const baskets = Number(formInput[`basket${index}`] || 0);
295
- const totalWeight = Number(formInput[`weight${index}`] || 0);
296
- const discount = Number(formInput[`discount${index}`] || 0);
297
-
298
- // Realizar los cálculos necesarios
299
- const basketWeight = 5;
300
- let netWeight = totalWeight - baskets * basketWeight;
301
- netWeight = netWeight * ((100 - discount) / 100);
302
- const weightByBasket = netWeight / baskets;
303
-
304
- //Probable aprovechamiento en planta
305
- const probableUtilization =
306
- netWeight * ((100 - (Number(formInput.porcentajeRechazo) ?? 0)) / 100);
307
-
308
- //libras o unidades descontadas
309
- const lbDiscounted = netWeight - probableUtilization;
310
-
311
- // Añadir al array de pesadas
312
- tempPesadas.push({
313
- id: index + 1,
314
- baskets,
315
- totalWeight,
316
- discount,
317
- netWeight: toFixedIfNeeded(netWeight),
318
- weightByBasket: toFixedIfNeeded(weightByBasket),
319
- probableUtilization,
320
- lbDiscounted,
321
- });
322
-
323
- index++;
324
- }
325
-
326
- const totales = {
327
- id: "",
328
- baskets: toFixedIfNeeded(
329
- tempPesadas?.map((x) => x.baskets).reduce(reduceAdd, 0)
330
- ),
331
- totalWeight: toFixedIfNeeded(
332
- tempPesadas?.map((x) => x.totalWeight).reduce(reduceAdd, 0)
333
- ),
334
- discount: "-",
335
- netWeight: toFixedIfNeeded(
336
- tempPesadas?.map((x) => Number(x.netWeight)).reduce(reduceAdd, 0)
337
- ),
338
- weightByBasket: "-",
339
- lbDiscounted: toFixedIfNeeded(
340
- tempPesadas?.map((x) => Number(x.lbDiscounted)).reduce(reduceAdd, 0)
341
- ),
342
- probableUtilization: toFixedIfNeeded(
343
- tempPesadas
344
- ?.map((x) => Number(x.probableUtilization))
345
- .reduce(reduceAdd, 0)
346
- ),
347
- };
348
-
349
- const headers: GenericDynamicTableColumn[] = [
350
- { label: "#", name: "id", type: "label", width: 5 },
351
- { label: "Canastas", name: "baskets", type: "label" },
352
- { label: "Peso báscula", name: "totalWeight", type: "label" },
353
- { label: "Descuento (%)", name: "discount", type: "label" },
354
- { label: "Peso Neto", name: "netWeight", type: "label" },
355
- {
356
- label: "Peso Neto - %Rechazo",
357
- name: "probableUtilization",
358
- type: "label",
359
- },
360
- {
361
- label: "Lb o Unidades descontadas",
362
- name: "lbDiscounted",
363
- type: "label",
364
- },
365
- {
366
- label: "Peso Neto por canasta",
367
- name: "weightByBasket",
368
- type: "label",
369
- },
370
- ];
371
-
372
- return { tempPesadas, totales, headers };
373
- };
374
-
375
- type BasketDetailsBody = {
376
- id: number;
377
- total: number;
378
- color: string;
379
- cc: number;
380
- };
381
-
382
- type BasketDetailsFooter = {
383
- id: string;
384
- total: string;
385
- cc: number;
386
- };
387
-
388
- export const useGetBasketDetails = (
389
- purchaseOrder: PurchaseOrderGraphQL
390
- ): [BasketDetailsBody[], BasketDetailsFooter, GenericDynamicTableColumn[]] => {
391
- const [basketsJoined, footerBasketsJoined, headersBasketsJoined] =
392
- useMemo(() => {
393
- const bsq =
394
- purchaseOrder?.lots
395
- ?.map((x) => {
396
- const basket = getBasketsSchema(x.description);
397
- return basket;
398
- })
399
- .flat(2) ?? [];
400
-
401
- const bsqToCC = getBasketsSchema(purchaseOrder.memo);
402
-
403
- const joinedBaskets: {
404
- id: number;
405
- total: number;
406
- color: string;
407
- cc: number;
408
- }[] = [];
409
- for (let i = 0; i < bsq.length; i++) {
410
- const found = joinedBaskets.find((item) => item.color === bsq[i].color);
411
- const foundCC = bsqToCC.find((item) => item.color === bsq[i].color);
412
-
413
- if (found) {
414
- found.total += bsq[i].total;
415
- } else {
416
- joinedBaskets.push({
417
- id: i,
418
- total: bsq[i].total + (foundCC ? foundCC.total : 0),
419
- color: bsq[i].color,
420
- cc: foundCC ? foundCC.total : 0,
421
- });
422
- }
423
- }
424
-
425
- const totales = {
426
- id: "",
427
- total: toFixedIfNeeded(
428
- joinedBaskets?.map((x) => x.total).reduce(reduceAdd, 0)
429
- ),
430
- cc: joinedBaskets?.map((x) => x.cc).reduce(reduceAdd, 0),
431
- };
432
-
433
- const headers: GenericDynamicTableColumn[] = [
434
- { label: "Color", name: "color", type: "label" },
435
- { label: "Canastas recibidas", name: "total", type: "label" },
436
- { label: "Enviadas a CC", name: "cc", type: "label" },
437
- ];
438
-
439
- return [joinedBaskets, totales, headers];
440
- }, [purchaseOrder]);
441
-
442
- return [basketsJoined, footerBasketsJoined, headersBasketsJoined];
443
- };
444
-
445
- /**
446
- * Para imprimir en modo offline
447
- * @param formInput
448
- * @returns
449
- */
450
- export const getBasketDetailsByForm = (formInput: FormInput) => {
451
- const basketDetailsArray: BasketDetailsBody[] = [];
452
-
453
- // Regex para identificar los campos relevantes
454
- const recPattern = /^rec\d+-(.+)$/;
455
- const qCPattern = /^qC\d+-(.+)$/;
456
-
457
- for (const key in formInput) {
458
- if (formInput.hasOwnProperty(key)) {
459
- let match;
460
-
461
- // Comprobar si la clave es un campo "rec" y extraer el color y la cantidad
462
- if ((match = recPattern.exec(key))) {
463
- const color = match[1];
464
- const total = Number(formInput[key] || 0);
465
-
466
- const existingBasket = basketDetailsArray.find(
467
- (item) => item.color === color
468
- );
469
- if (existingBasket) {
470
- existingBasket.total += total;
471
- } else {
472
- basketDetailsArray.push({
473
- id: basketDetailsArray.length,
474
- total,
475
- color,
476
- cc: 0, // Inicializar cc a 0, se actualizará más adelante si existe
477
- });
478
- }
479
- }
480
-
481
- // Comprobar si la clave es un campo "qC" y actualizar el campo cc correspondiente
482
- if ((match = qCPattern.exec(key))) {
483
- const color = match[1];
484
- const cc = Number(formInput[key] || 0);
485
-
486
- const existingBasket = basketDetailsArray.find(
487
- (item) => item.color === color
488
- );
489
- if (existingBasket) {
490
- existingBasket.cc += cc;
491
- }
492
- }
493
- }
494
- }
495
-
496
- // Calcular los totales para footerBasketsDetails
497
- const totales: BasketDetailsFooter = {
498
- id: "",
499
- total: basketDetailsArray
500
- .map((x) => x.total)
501
- .reduce((acc, val) => acc + val, 0)
502
- .toFixed(2),
503
- cc: basketDetailsArray.map((x) => x.cc).reduce((acc, val) => acc + val, 0),
504
- };
505
-
506
- // Definir los encabezados de la tabla
507
- const headers: GenericDynamicTableColumn[] = [
508
- { label: "Color", name: "color", type: "label" },
509
- { label: "Canastas recibidas", name: "total", type: "label" },
510
- { label: "Enviadas a CC", name: "cc", type: "label" },
511
- ];
512
-
513
- return { basketDetailsArray, totales, headers };
514
- };
515
-
516
- export const useGetProviderNameByPurchaseOrder = (
517
- payees: PayeeGraphQL[],
518
- purchaseOrder: PurchaseOrderGraphQL
519
- ) => {
520
- const providerName = useMemo(() => {
521
- const provider = payees.find((x) => x.id == purchaseOrder.payee_id);
522
- if (provider) {
523
- return `<${provider.id_number}> ${
524
- provider.tin ? `${provider.tin} | ` : ""
525
- }${provider.name}`;
526
- }
527
- return null;
528
- }, [payees, purchaseOrder]);
529
-
530
- return providerName;
531
- };
532
-
533
- export const useGetItemNameByPurchaseOrder = (
534
- items: ItemGraphQL[],
535
- purchaseOrder: PurchaseOrderGraphQL
536
- ) => {
537
- const itemName = useMemo(() => {
538
- if (purchaseOrder.purchase_order_details.length > 0 && items.length > 0) {
539
- const item = items.find(
540
- (x) => x.id == purchaseOrder.purchase_order_details[0].item_id
541
- );
542
- return `${item?.id} - ${item?.code} - ${item?.name}`;
543
- }
544
- return null;
545
- }, [items, purchaseOrder]);
546
-
547
- return itemName;
548
- };