@zauru-sdk/hooks 2.0.99 → 2.0.107

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,11 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useGetItemByPurchaseOrder = exports.useGetItemNameByPurchaseOrder = exports.useGetProviderNameByPurchaseOrder = exports.getBasketDetailsByForm = exports.useGetBasketDetails = exports.getPesadasByForm = exports.useGetPesadas = exports.useGetPurchaseOrderGeneralInfo = exports.useGetNewPurchaseOrderInfo = exports.useGetRejectionInfo = exports.useGetBasketLots = exports.useGetPOReceptions = exports.useGetProcesses = void 0;
3
+ exports.useGetItemByPurchaseOrder = exports.useGetItemNameByPurchaseOrder = exports.useGetProviderNameByPurchaseOrder = exports.useGetPurchaseOrderGeneralInfo = exports.useGetNewPurchaseOrderInfo = exports.useGetRejectionInfo = exports.useGetBasketLots = exports.useGetPOReceptions = exports.useGetProcesses = void 0;
4
4
  const react_1 = require("@remix-run/react");
5
5
  const redux_1 = require("@zauru-sdk/redux");
6
6
  const react_2 = require("react");
7
7
  const index_js_1 = require("./index.js");
8
- const common_1 = require("@zauru-sdk/common");
9
8
  const useGetReceptionObject = (RECEPTION_NAME, { online = false, wheres = [] } = {}) => {
10
9
  try {
11
10
  const fetcher = (0, react_1.useFetcher)();
@@ -89,366 +88,6 @@ const useGetNewPurchaseOrderInfo = () => useGetReceptionObject("newPurchaseOrder
89
88
  exports.useGetNewPurchaseOrderInfo = useGetNewPurchaseOrderInfo;
90
89
  const useGetPurchaseOrderGeneralInfo = () => useGetReceptionObject("purchaseOrderGeneralInfo");
91
90
  exports.useGetPurchaseOrderGeneralInfo = useGetPurchaseOrderGeneralInfo;
92
- const useGetPesadas = (purchaseOrder, stocks_only_integer = false) => {
93
- const [pesadas, footerPesadas, headersPesadas] = (0, react_2.useMemo)(() => {
94
- if (!purchaseOrder)
95
- return [[], [], []];
96
- const tempPesadas = [
97
- ...purchaseOrder.purchase_order_details?.map((x, index) => {
98
- const parsedReference = x.reference?.split(","); //eg: "reference": "698,25,0", // peso neto, canastas, descuento
99
- const totalWeight = parsedReference[0]
100
- ? Number(parsedReference[0]) ?? 0
101
- : 0;
102
- const baskets = parsedReference[1]
103
- ? Number(parsedReference[1]) ?? 0
104
- : 0;
105
- const discount = parsedReference[2]
106
- ? isNaN(Number(parsedReference[2]))
107
- ? 0
108
- : Number(parsedReference[2])
109
- : 0;
110
- //TODO sacar el peso de la canasta de la API de Zauru, ahorita se supone que no debería cambiar de 5 libras.
111
- const basketWeight = 5;
112
- let netWeight = totalWeight - baskets * basketWeight; //Se le resta el peso de las canastas
113
- netWeight = netWeight * ((100 - discount) / 100); //Se le aplica el descuento
114
- if (stocks_only_integer)
115
- netWeight = totalWeight; //si es en unidades no divido el peso entre las canastas
116
- const weightByBasket = netWeight / baskets;
117
- //Probable aprovechamiento en planta
118
- const probableUtilization = netWeight * ((100 - purchaseOrder?.discount) / 100);
119
- //libras o unidades descontadas
120
- const lbDiscounted = netWeight - probableUtilization;
121
- return {
122
- id: index + 1,
123
- baskets,
124
- totalWeight,
125
- discount,
126
- netWeight: (0, common_1.toFixedIfNeeded)(netWeight)?.toString(),
127
- weightByBasket: (0, common_1.toFixedIfNeeded)(weightByBasket)?.toString(),
128
- probableUtilization: (0, common_1.toFixedIfNeeded)(probableUtilization)?.toString(),
129
- lbDiscounted: (0, common_1.toFixedIfNeeded)(lbDiscounted)?.toString(),
130
- };
131
- }),
132
- ];
133
- const totales = [
134
- //#
135
- {
136
- content: "",
137
- name: "id",
138
- },
139
- //baskets
140
- {
141
- content: (0, common_1.toFixedIfNeeded)(tempPesadas?.map((x) => x.baskets).reduce(common_1.reduceAdd, 0))?.toString(),
142
- name: "baskets",
143
- },
144
- //totalWeight
145
- {
146
- content: (0, common_1.toFixedIfNeeded)(tempPesadas?.map((x) => x.totalWeight).reduce(common_1.reduceAdd, 0))?.toString(),
147
- name: "totalWeight",
148
- },
149
- //discount
150
- {
151
- content: "-",
152
- name: "discount",
153
- },
154
- //netWeight
155
- {
156
- content: (0, common_1.toFixedIfNeeded)(tempPesadas?.map((x) => Number(x.netWeight)).reduce(common_1.reduceAdd, 0))?.toString(),
157
- name: "netWeight",
158
- },
159
- //weightByBasket
160
- {
161
- content: "-",
162
- name: "weightByBasket",
163
- },
164
- //lbDiscounted
165
- {
166
- content: (0, common_1.toFixedIfNeeded)(tempPesadas?.map((x) => Number(x.lbDiscounted)).reduce(common_1.reduceAdd, 0))?.toString(),
167
- name: "lbDiscounted",
168
- },
169
- //probableUtilization
170
- {
171
- content: (0, common_1.toFixedIfNeeded)(tempPesadas
172
- ?.map((x) => Number(x.probableUtilization))
173
- .reduce(common_1.reduceAdd, 0)),
174
- name: "probableUtilization",
175
- },
176
- ];
177
- const headers = [
178
- { label: "#", name: "id", type: "label", width: 5 },
179
- { label: "Canastas", name: "baskets", type: "label" },
180
- {
181
- label: `${stocks_only_integer ? "Unidades" : "Peso báscula"}`,
182
- name: "totalWeight",
183
- type: "label",
184
- },
185
- { label: "Descuento (%)", name: "discount", type: "label" },
186
- {
187
- label: `${stocks_only_integer ? "Unidades" : "Peso Neto"}`,
188
- name: "netWeight",
189
- type: "label",
190
- },
191
- {
192
- label: `${stocks_only_integer ? "Unidades" : "Peso Neto"} - %Rechazo`,
193
- name: "probableUtilization",
194
- type: "label",
195
- },
196
- {
197
- label: `${stocks_only_integer ? "Unidades" : "Libras"} descontadas`,
198
- name: "lbDiscounted",
199
- type: "label",
200
- },
201
- {
202
- label: `${stocks_only_integer ? "Unidades" : "Peso Neto"} por canasta`,
203
- name: "weightByBasket",
204
- type: "label",
205
- },
206
- ];
207
- return [tempPesadas, totales, headers];
208
- }, [purchaseOrder]);
209
- return [pesadas, footerPesadas, headersPesadas];
210
- };
211
- exports.useGetPesadas = useGetPesadas;
212
- /**
213
- * Sirve para imprimir offline
214
- * @param formInput
215
- * @returns
216
- */
217
- const getPesadasByForm = (formInput, stocks_only_integer = false) => {
218
- // Inicializar array de pesadas
219
- const tempPesadas = [];
220
- // Iterar sobre los campos del formulario y extraer la información de pesadas
221
- let index = 0;
222
- while (formInput.hasOwnProperty(`basket${index}`)) {
223
- const baskets = isNaN(Number(formInput[`basket${index}`]))
224
- ? 0
225
- : Number(formInput[`basket${index}`]);
226
- const totalWeight = isNaN(Number(formInput[`weight${index}`]))
227
- ? 0
228
- : Number(formInput[`weight${index}`]);
229
- const discount = isNaN(Number(formInput[`discount${index}`]))
230
- ? 0
231
- : Number(formInput[`discount${index}`]);
232
- // Realizar los cálculos necesarios
233
- const basketWeight = 5;
234
- let netWeight = totalWeight - baskets * basketWeight;
235
- netWeight = netWeight * ((100 - discount) / 100);
236
- netWeight = stocks_only_integer ? totalWeight : netWeight;
237
- const weightByBasket = netWeight / baskets;
238
- //Probable aprovechamiento en planta
239
- const probableUtilization = netWeight * ((100 - (Number(formInput.porcentajeRechazo) ?? 0)) / 100);
240
- //libras o unidades descontadas
241
- const lbDiscounted = netWeight - probableUtilization;
242
- // Añadir al array de pesadas
243
- tempPesadas.push({
244
- id: index + 1,
245
- baskets,
246
- totalWeight,
247
- discount,
248
- netWeight: (0, common_1.toFixedIfNeeded)(netWeight)?.toString(),
249
- weightByBasket: (0, common_1.toFixedIfNeeded)(weightByBasket)?.toString(),
250
- probableUtilization: (0, common_1.toFixedIfNeeded)(probableUtilization)?.toString(),
251
- lbDiscounted: (0, common_1.toFixedIfNeeded)(lbDiscounted)?.toString(),
252
- });
253
- index++;
254
- }
255
- const totales = [
256
- //#
257
- {
258
- content: "",
259
- name: "id",
260
- },
261
- //baskets
262
- {
263
- content: (0, common_1.toFixedIfNeeded)(tempPesadas?.map((x) => x.baskets).reduce(common_1.reduceAdd, 0))?.toString(),
264
- name: "baskets",
265
- },
266
- //totalWeight
267
- {
268
- content: (0, common_1.toFixedIfNeeded)(tempPesadas?.map((x) => x.totalWeight).reduce(common_1.reduceAdd, 0))?.toString(),
269
- name: "totalWeight",
270
- },
271
- //netWeight
272
- {
273
- content: (0, common_1.toFixedIfNeeded)(tempPesadas?.map((x) => Number(x.netWeight)).reduce(common_1.reduceAdd, 0))?.toString(),
274
- name: "netWeight",
275
- },
276
- //weightByBasket
277
- {
278
- content: "-",
279
- name: "weightByBasket",
280
- },
281
- ];
282
- const headers = [
283
- { label: "#", name: "id", type: "label", width: 5 },
284
- { label: "Canastas", name: "baskets", type: "label" },
285
- {
286
- label: `${stocks_only_integer ? "Unidades" : "Peso báscula"}`,
287
- name: "totalWeight",
288
- type: "label",
289
- },
290
- {
291
- label: `${stocks_only_integer ? "Unidades" : "Peso Neto"}`,
292
- name: "netWeight",
293
- type: "label",
294
- },
295
- {
296
- label: `${stocks_only_integer ? "Unidades" : "Peso Neto"} por canasta`,
297
- name: "weightByBasket",
298
- type: "label",
299
- },
300
- ];
301
- return { tempPesadas, totales, headers };
302
- };
303
- exports.getPesadasByForm = getPesadasByForm;
304
- const useGetBasketDetails = (purchaseOrder) => {
305
- const [basketsJoined, footerBasketsJoined, headersBasketsJoined] = (0, react_2.useMemo)(() => {
306
- if (!purchaseOrder)
307
- return [[], [], []];
308
- const bsq = purchaseOrder?.lots.length > 0
309
- ? purchaseOrder?.lots
310
- ?.map((x) => {
311
- const basket = (0, common_1.getBasketsSchema)(x.description);
312
- return basket;
313
- })
314
- .flat(2)
315
- : //------- INTENTO IMPRIMIR EL TOTAL DE CANASTAS DEL PURCHASE ORDER DETAILS, PORQUE DEPLANO HUBO UN ERROR EN LA CREACION DE LOS LOTES Y POR ESO VIENE VACIO
316
- //ESTO SOLO ES UNA CONTINGENCIA PARA QUE POR LO MENOS PUEDAN IMPRIMIR EL NUMERO DE CANASTAS, PERO NO LES ESTARÁ MOSTRANDO EL COLOR
317
- //--- TODO
318
- purchaseOrder?.purchase_order_details.length > 0
319
- ? purchaseOrder?.purchase_order_details
320
- ?.map((x) => {
321
- return {
322
- id: 0,
323
- color: "-",
324
- total: Number(x.reference.split(",")[1]) ?? 0,
325
- };
326
- })
327
- .flat(2)
328
- : [];
329
- const bsqToCC = (0, common_1.getBasketsSchema)(purchaseOrder.memo);
330
- const joinedBaskets = [];
331
- for (let i = 0; i < bsq.length; i++) {
332
- let found = joinedBaskets.find((item) => item.color === bsq[i].color);
333
- let foundCC = bsqToCC.find((item) => item.color === bsq[i].color);
334
- if (found) {
335
- found.total += bsq[i].total;
336
- }
337
- else {
338
- joinedBaskets.push({
339
- id: i,
340
- total: bsq[i].total - (foundCC ? foundCC.total : 0),
341
- //granTotal: bsq[i].total,
342
- color: bsq[i].color,
343
- cc: foundCC ? foundCC.total : 0,
344
- });
345
- }
346
- }
347
- const totales = [
348
- //color
349
- {
350
- content: "",
351
- name: "color",
352
- },
353
- //total
354
- {
355
- content: (0, common_1.toFixedIfNeeded)(joinedBaskets?.map((x) => x.total).reduce(common_1.reduceAdd, 0))?.toString(),
356
- name: "total",
357
- },
358
- //cc
359
- {
360
- content: joinedBaskets?.map((x) => x.cc).reduce(common_1.reduceAdd, 0),
361
- name: "cc",
362
- },
363
- ];
364
- const headers = [
365
- { label: "Color", name: "color", type: "label" },
366
- { label: "Canastas recibidas", name: "total", type: "label" },
367
- { label: "Enviadas a CC", name: "cc", type: "label" },
368
- //{ label: "Total", name: "granTotal", type: "label" },
369
- ];
370
- return [joinedBaskets, totales, headers];
371
- }, [purchaseOrder]);
372
- return [basketsJoined, footerBasketsJoined, headersBasketsJoined];
373
- };
374
- exports.useGetBasketDetails = useGetBasketDetails;
375
- /**
376
- * Para imprimir en modo offline
377
- * @param formInput
378
- * @returns
379
- */
380
- const getBasketDetailsByForm = (formInput) => {
381
- const basketDetailsArray = [];
382
- if (!formInput)
383
- return {
384
- basketDetailsArray,
385
- totales: [],
386
- headers: [],
387
- };
388
- // Regex para identificar los campos relevantes
389
- const recPattern = /^rec\d+-(.+)$/;
390
- const qCPattern = /^qC\d+-(.+)$/;
391
- for (const key in formInput) {
392
- if (formInput.hasOwnProperty(key)) {
393
- let match;
394
- // Comprobar si la clave es un campo "rec" y extraer el color y la cantidad
395
- if ((match = recPattern.exec(key))) {
396
- const color = match[1];
397
- const total = isNaN(Number(formInput[key]))
398
- ? 0
399
- : Number(formInput[key]);
400
- const existingBasket = basketDetailsArray.find((item) => item.color === color);
401
- if (existingBasket) {
402
- existingBasket.total += total;
403
- }
404
- else {
405
- if (total > 0) {
406
- basketDetailsArray.push({
407
- id: basketDetailsArray.length,
408
- total,
409
- color,
410
- cc: 0, // Inicializar cc a 0, se actualizará más adelante si existe
411
- });
412
- }
413
- }
414
- }
415
- // Comprobar si la clave es un campo "qC" y actualizar el campo cc correspondiente
416
- if ((match = qCPattern.exec(key))) {
417
- const color = match[1];
418
- const cc = isNaN(Number(formInput[key])) ? 0 : Number(formInput[key]);
419
- const existingBasket = basketDetailsArray.find((item) => item.color === color);
420
- if (existingBasket) {
421
- existingBasket.cc += cc;
422
- }
423
- }
424
- }
425
- }
426
- const totales = [
427
- //color
428
- {
429
- content: "",
430
- name: "color",
431
- },
432
- //total
433
- {
434
- content: (0, common_1.toFixedIfNeeded)(basketDetailsArray.map((x) => x.total).reduce(common_1.reduceAdd, 0))?.toString(),
435
- name: "total",
436
- },
437
- //cc
438
- {
439
- content: basketDetailsArray.map((x) => x.cc).reduce(common_1.reduceAdd, 0),
440
- name: "cc",
441
- },
442
- ];
443
- // Definir los encabezados de la tabla
444
- const headers = [
445
- { label: "Color", name: "color", type: "label" },
446
- { label: "Canastas recibidas", name: "total", type: "label" },
447
- { label: "Enviadas a CC", name: "cc", type: "label" },
448
- ];
449
- return { basketDetailsArray, totales, headers };
450
- };
451
- exports.getBasketDetailsByForm = getBasketDetailsByForm;
452
91
  const useGetProviderNameByPurchaseOrder = (payees, purchaseOrder) => {
453
92
  const providerName = (0, react_2.useMemo)(() => {
454
93
  if (!purchaseOrder)
@@ -1,4 +1,4 @@
1
- import { ItemAssociatedLots, ItemGraphQL, NewPurchaseOrderResponse, PayeeGraphQL, PurchaseOrderGraphQL, WebAppRowGraphQL, GenericDynamicTableColumn, QueueFormReceptionWebAppTable, RejectionWebAppTableObject, PurchaseOrderGeneralInfo } from "@zauru-sdk/types";
1
+ import { ItemAssociatedLots, ItemGraphQL, NewPurchaseOrderResponse, PayeeGraphQL, PurchaseOrderGraphQL, WebAppRowGraphQL, QueueFormReceptionWebAppTable, RejectionWebAppTableObject, PurchaseOrderGeneralInfo } from "@zauru-sdk/types";
2
2
  type ConfigProps = {
3
3
  online?: boolean;
4
4
  wheres?: string[];
@@ -30,65 +30,11 @@ export declare const useGetPurchaseOrderGeneralInfo: () => {
30
30
  /**
31
31
  * ---------------- Hooks personalizados
32
32
  */
33
- type FormInput = {
34
- idNumberInput: string;
35
- rType: string;
36
- vendor: string;
37
- porcentajeRechazo: string;
38
- [key: string]: string | undefined;
39
- };
40
- type PesadaBody = {
41
- id: number;
42
- baskets: number;
43
- totalWeight: number;
44
- discount: number;
45
- netWeight: string;
46
- weightByBasket: string;
47
- probableUtilization: string;
48
- lbDiscounted: string;
49
- };
50
33
  export type FooterColumnConfig = {
51
34
  content: React.ReactNode;
52
35
  className?: string;
53
36
  name?: string;
54
37
  };
55
- export declare const useGetPesadas: (purchaseOrder?: PurchaseOrderGraphQL, stocks_only_integer?: boolean) => [PesadaBody[], FooterColumnConfig[], GenericDynamicTableColumn[]];
56
- /**
57
- * Sirve para imprimir offline
58
- * @param formInput
59
- * @returns
60
- */
61
- export declare const getPesadasByForm: (formInput: FormInput, stocks_only_integer?: boolean) => {
62
- tempPesadas: PesadaBody[];
63
- totales: {
64
- content: string;
65
- name: string;
66
- }[];
67
- headers: GenericDynamicTableColumn[];
68
- };
69
- type BasketDetailsBody = {
70
- id: number;
71
- total: number;
72
- color: string;
73
- cc: number;
74
- };
75
- export declare const useGetBasketDetails: (purchaseOrder?: PurchaseOrderGraphQL) => [BasketDetailsBody[], FooterColumnConfig[], GenericDynamicTableColumn[]];
76
- /**
77
- * Para imprimir en modo offline
78
- * @param formInput
79
- * @returns
80
- */
81
- export declare const getBasketDetailsByForm: (formInput: FormInput) => {
82
- basketDetailsArray: BasketDetailsBody[];
83
- totales: ({
84
- content: string;
85
- name: string;
86
- } | {
87
- content: number;
88
- name: string;
89
- })[];
90
- headers: GenericDynamicTableColumn[];
91
- };
92
38
  export declare const useGetProviderNameByPurchaseOrder: (payees: PayeeGraphQL[], purchaseOrder?: PurchaseOrderGraphQL) => string;
93
39
  export declare const useGetItemNameByPurchaseOrder: (items: ItemGraphQL[], purchaseOrder?: PurchaseOrderGraphQL) => string;
94
40
  export declare const useGetItemByPurchaseOrder: (items: ItemGraphQL[], purchaseOrder?: PurchaseOrderGraphQL) => ItemGraphQL;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zauru-sdk/hooks",
3
- "version": "2.0.99",
3
+ "version": "2.0.107",
4
4
  "description": "Hooks reutilizables dentro de las webapps de Zauru.",
5
5
  "main": "./dist/esm/index.js",
6
6
  "module": "./dist/esm/index.js",
@@ -33,5 +33,5 @@
33
33
  "react": "^18.2.0",
34
34
  "react-dom": "^18.2.0"
35
35
  },
36
- "gitHead": "ac0a91be4f6ee9c35217dbc1909c352864e2c982"
36
+ "gitHead": "38616ca0ee58e75e1a5bac568e1e60f0c1f46a75"
37
37
  }