npm-pkg-hook 1.10.2 → 1.10.6
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/package.json +1 -1
- package/src/hooks/index.js +7 -0
- package/src/hooks/useCatWithProduct/queries.js +3 -2
- package/src/hooks/useCatWithProductClient/queries.js +1 -0
- package/src/hooks/useChartData/useChartDataAllOrders/index.js +1 -1
- package/src/hooks/useCreateProduct/index.js +35 -13
- package/src/hooks/useDepartments/queries.js +5 -4
- package/src/hooks/useImagesStore/queries.js +1 -65
- package/src/hooks/useInventory/index.js +2 -0
- package/src/hooks/useInventory/queries.js +58 -0
- package/src/hooks/useInventory/useGetProductsInStock.js +15 -0
- package/src/hooks/useInventory/useUpdateManageStock.js +41 -0
- package/src/hooks/useLocationManager/index.js +2 -2
- package/src/hooks/useModules/helpers/validateModules.js +15 -15
- package/src/hooks/useOrders/queries.js +1 -1
- package/src/hooks/useProductsFood/index.js +13 -5
- package/src/hooks/useProductsFood/queriesStore.js +20 -9
- package/src/hooks/useReport/index.js +1 -1
- package/src/hooks/useSales/index.js +130 -41
- package/src/hooks/useSetImageProducts/index.js +30 -0
- package/src/hooks/useSetImageProducts/queries.js +13 -0
- package/src/hooks/useStockMovements/helpers/index.js +16 -0
- package/src/hooks/useStockMovements/index.js +36 -0
- package/src/hooks/useTopProductsMovements/index.js +27 -0
- package/src/hooks/useTotalAllSales/index.js +25 -0
- package/src/hooks/useTotalProductsInStock/index.js +23 -0
- package/src/hooks/useTotalProductsSold/index.js +23 -0
- package/src/hooks/useTotalProductsSolded/index.js +20 -0
- package/src/hooks/useUpdateExistingOrders/index.js +1 -1
- package/src/hooks/useUpdateMultipleProducts/index.js +29 -8
- package/src/hooks/useUpdateMultipleProducts/queries.js +1 -1
- package/src/hooks/useUploadProducts/helpers/validateProductDataExcel.js +24 -16
- package/src/hooks/useUploadProducts/index.js +9 -4
- package/src/hooks/useUser/queries.js +1 -2
- package/src/index.jsx +3 -1
- package/src/utils/index.js +2 -5
|
@@ -153,7 +153,13 @@ export const useSales = ({
|
|
|
153
153
|
setDataExtra([])
|
|
154
154
|
}
|
|
155
155
|
})
|
|
156
|
-
|
|
156
|
+
|
|
157
|
+
const [productsFood, {
|
|
158
|
+
loading,
|
|
159
|
+
fetchMore,
|
|
160
|
+
pagination,
|
|
161
|
+
refetch
|
|
162
|
+
}] = useProductsFood({
|
|
157
163
|
// @ts-ignore
|
|
158
164
|
search: search?.length >= 4 ? search : '',
|
|
159
165
|
gender: [],
|
|
@@ -164,6 +170,13 @@ export const useSales = ({
|
|
|
164
170
|
max: showMore,
|
|
165
171
|
min: 0
|
|
166
172
|
})
|
|
173
|
+
const [currentPage, setCurrentPage] = useState(1)
|
|
174
|
+
|
|
175
|
+
const handlePageChange = (pageNumber) => {
|
|
176
|
+
setCurrentPage(pageNumber)
|
|
177
|
+
refetch({ page: pageNumber })
|
|
178
|
+
}
|
|
179
|
+
|
|
167
180
|
const handleChangeCheck = (caId) => {
|
|
168
181
|
// @ts-ignore
|
|
169
182
|
setCategories((prev) => {
|
|
@@ -176,7 +189,6 @@ export const useSales = ({
|
|
|
176
189
|
})
|
|
177
190
|
})
|
|
178
191
|
}
|
|
179
|
-
|
|
180
192
|
const max = productsFood?.reduce(function (a, b) {
|
|
181
193
|
return Math.max(a, b?.ProPrice || 0)
|
|
182
194
|
}, 0)
|
|
@@ -281,7 +293,7 @@ export const useSales = ({
|
|
|
281
293
|
* @returns {Object} - The new state with the updated product quantity and editing status.
|
|
282
294
|
*/
|
|
283
295
|
const handleCancelUpdateQuantity = (state, payload) => {
|
|
284
|
-
|
|
296
|
+
// Validación de `state`
|
|
285
297
|
if (!state || typeof state !== 'object') {
|
|
286
298
|
sendNotification({
|
|
287
299
|
title: 'Error',
|
|
@@ -315,7 +327,7 @@ export const useSales = ({
|
|
|
315
327
|
return {
|
|
316
328
|
...state,
|
|
317
329
|
PRODUCT: state.PRODUCT.map((item) => {
|
|
318
|
-
|
|
330
|
+
// Validación de propiedades en cada item
|
|
319
331
|
if (item.pId === pId) {
|
|
320
332
|
if (typeof item.oldQuantity !== 'number' || typeof item.unitPrice !== 'number') {
|
|
321
333
|
sendNotification({
|
|
@@ -343,28 +355,48 @@ export const useSales = ({
|
|
|
343
355
|
(state, action) => {
|
|
344
356
|
const event = action.payload
|
|
345
357
|
const { value, index, id } = event || {}
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
358
|
+
|
|
359
|
+
const productExist = productsFood?.find((items) => items.pId === id)
|
|
360
|
+
const OneProduct = state?.PRODUCT.find((items) => items.pId === id)
|
|
361
|
+
|
|
362
|
+
if (!productExist) return state // Validar si el producto existe
|
|
363
|
+
|
|
364
|
+
// Validar si el stock es 0
|
|
365
|
+
if (productExist.stock === 0) {
|
|
366
|
+
sendNotification({
|
|
367
|
+
title: 'Sin stock',
|
|
368
|
+
backgroundColor: 'warning',
|
|
369
|
+
description: `El producto ${OneProduct?.pName} está agotado y no puede ser modificado.`
|
|
370
|
+
})
|
|
371
|
+
return state
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
// Si el valor ingresado es menor o igual a 0, eliminar el producto del carrito
|
|
352
375
|
if (value <= 0) {
|
|
353
|
-
// @ts-ignore
|
|
354
376
|
dispatch({ type: 'REMOVE_PRODUCT_TO_CART', payload: OneProduct })
|
|
377
|
+
return state
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
// Validar si se intenta superar el stock disponible
|
|
381
|
+
const finalQuantity = Math.min(value, productExist.stock)
|
|
382
|
+
if (value > productExist.stock) {
|
|
383
|
+
sendNotification({
|
|
384
|
+
title: 'Stock insuficiente',
|
|
385
|
+
backgroundColor: 'warning',
|
|
386
|
+
description: `No puedes agregar más unidades de ${OneProduct?.pName}, stock disponible: ${productExist.stock}`
|
|
387
|
+
})
|
|
355
388
|
}
|
|
356
|
-
|
|
357
|
-
const ARR_PRODUCT = state?.PRODUCT?.map((items, i) =>
|
|
358
|
-
|
|
389
|
+
|
|
390
|
+
const ARR_PRODUCT = state?.PRODUCT?.map((items, i) =>
|
|
391
|
+
i === index
|
|
359
392
|
? {
|
|
360
393
|
...items,
|
|
361
394
|
ProQuantity: finalQuantity,
|
|
362
|
-
ProPrice:
|
|
363
|
-
? value * productExist?.ProPrice
|
|
364
|
-
: productExist?.ProPrice
|
|
395
|
+
ProPrice: finalQuantity * productExist?.ProPrice
|
|
365
396
|
}
|
|
366
397
|
: items
|
|
367
|
-
|
|
398
|
+
)
|
|
399
|
+
|
|
368
400
|
return {
|
|
369
401
|
...state,
|
|
370
402
|
PRODUCT: ARR_PRODUCT,
|
|
@@ -373,6 +405,7 @@ export const useSales = ({
|
|
|
373
405
|
},
|
|
374
406
|
[productsFood]
|
|
375
407
|
)
|
|
408
|
+
|
|
376
409
|
const paymentMethod = (state, action) => {
|
|
377
410
|
return {
|
|
378
411
|
...state,
|
|
@@ -380,14 +413,6 @@ export const useSales = ({
|
|
|
380
413
|
}
|
|
381
414
|
}
|
|
382
415
|
const PRODUCT = (state, action) => {
|
|
383
|
-
const productExist = state.PRODUCT.find((items) => {
|
|
384
|
-
return items.pId === action.id
|
|
385
|
-
})
|
|
386
|
-
const OurProduct = productsFood?.find((items) => {
|
|
387
|
-
return items.pId === action.id
|
|
388
|
-
})
|
|
389
|
-
const isFree = productExist?.free
|
|
390
|
-
|
|
391
416
|
switch (action.type) {
|
|
392
417
|
case 'ADD_TO_CART':
|
|
393
418
|
return addToCartFunc(state, action) // https://www.npmjs.com/package/@sourcetoad/vision-camera-plugin-barcode-scanner
|
|
@@ -436,22 +461,46 @@ export const useSales = ({
|
|
|
436
461
|
case 'TOGGLE_EDITING_PRODUCT': {
|
|
437
462
|
return handleToggleEditingStatus(state, action)
|
|
438
463
|
}
|
|
439
|
-
case 'INCREMENT':
|
|
464
|
+
case 'INCREMENT': {
|
|
440
465
|
return {
|
|
441
466
|
...state,
|
|
442
467
|
counter: state.counter + 1,
|
|
443
468
|
PRODUCT: state?.PRODUCT?.map((items) => {
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
469
|
+
if (items.pId === action.id) {
|
|
470
|
+
const OurProduct = productsFood?.find((item) => item.pId === action.id)
|
|
471
|
+
const isFree = items.free
|
|
472
|
+
const newQuantity = items.ProQuantity + 1
|
|
473
|
+
// Validar si el stock es 0
|
|
474
|
+
if (OurProduct?.stock === 0) {
|
|
475
|
+
sendNotification({
|
|
476
|
+
title: 'Sin stock',
|
|
477
|
+
backgroundColor: 'warning',
|
|
478
|
+
description: `El producto ${items.pName} está agotado y no puede ser añadido al carrito.`
|
|
479
|
+
})
|
|
480
|
+
return items // Retornar sin modificar
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
// Validar si se supera el stock
|
|
484
|
+
if (newQuantity > OurProduct?.stock) {
|
|
485
|
+
sendNotification({
|
|
486
|
+
title: 'Stock insuficiente',
|
|
487
|
+
backgroundColor: 'warning',
|
|
488
|
+
description: `No puedes agregar más unidades de ${items.pName}, stock disponible: ${OurProduct?.stock}`
|
|
489
|
+
})
|
|
490
|
+
return items // Retornar el producto sin modificar
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
return {
|
|
494
|
+
...items,
|
|
495
|
+
ProQuantity: newQuantity,
|
|
496
|
+
ProPrice: isFree ? 0 : newQuantity * OurProduct?.ProPrice
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
return items
|
|
453
500
|
})
|
|
454
501
|
}
|
|
502
|
+
}
|
|
503
|
+
|
|
455
504
|
case 'PUT_COMMENT':
|
|
456
505
|
return commentProducts(state, action)
|
|
457
506
|
case 'PUT_EXTRA_PRODUCTS_AND_OPTIONAL_PRODUCT':
|
|
@@ -704,19 +753,45 @@ export const useSales = ({
|
|
|
704
753
|
}
|
|
705
754
|
}
|
|
706
755
|
|
|
756
|
+
function isStockInsufficient (currentQuantity, stock) {
|
|
757
|
+
return currentQuantity >= stock
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
function sendAlertStock (stock) {
|
|
761
|
+
return sendNotification({
|
|
762
|
+
title: 'Stock insuficiente',
|
|
763
|
+
backgroundColor: 'warning',
|
|
764
|
+
description: `Solo hay ${stock} unidades disponibles en el inventario`
|
|
765
|
+
})
|
|
766
|
+
}
|
|
767
|
+
|
|
707
768
|
function addToCartFunc (state, action) {
|
|
708
769
|
const {
|
|
709
770
|
pId,
|
|
710
771
|
pName,
|
|
711
772
|
getOneTags,
|
|
773
|
+
stock,
|
|
712
774
|
ProDescription,
|
|
713
775
|
ProImage,
|
|
714
776
|
ProPrice
|
|
715
|
-
} = action.payload
|
|
777
|
+
} = action.payload ?? {}
|
|
778
|
+
if (stock === 0) {
|
|
779
|
+
sendNotification({
|
|
780
|
+
title: 'Sin stock',
|
|
781
|
+
backgroundColor: 'warning',
|
|
782
|
+
description: 'Producto sin stock disponible en tu inventario'
|
|
783
|
+
})
|
|
784
|
+
return state
|
|
785
|
+
}
|
|
716
786
|
|
|
717
787
|
const productExist = state?.PRODUCT.find((item) => item.pId === pId)
|
|
718
788
|
const OurProduct = productsFood?.find((item) => item.pId === pId)
|
|
719
789
|
const isFree = productExist?.free
|
|
790
|
+
const currentQuantity = productExist?.ProQuantity || 0
|
|
791
|
+
if (productExist?.manageStock && isStockInsufficient(currentQuantity, stock)) {
|
|
792
|
+
sendAlertStock(stock)
|
|
793
|
+
return state
|
|
794
|
+
}
|
|
720
795
|
|
|
721
796
|
const updatedProduct = {
|
|
722
797
|
pId,
|
|
@@ -724,9 +799,11 @@ export const useSales = ({
|
|
|
724
799
|
editing: false,
|
|
725
800
|
getOneTags,
|
|
726
801
|
unitPrice: OurProduct?.ProPrice,
|
|
802
|
+
manageStock: OurProduct?.manageStock ?? false,
|
|
727
803
|
ProDescription,
|
|
728
804
|
ProImage,
|
|
729
805
|
ProPrice,
|
|
806
|
+
stock,
|
|
730
807
|
ProQuantity: 1
|
|
731
808
|
}
|
|
732
809
|
|
|
@@ -857,7 +934,7 @@ export const useSales = ({
|
|
|
857
934
|
const arrayProduct = data?.PRODUCT?.length > 0
|
|
858
935
|
? data?.PRODUCT?.map((product) => {
|
|
859
936
|
const filteredDataExtra =
|
|
860
|
-
|
|
937
|
+
product?.dataExtra?.map(({ __typename, ...rest }) => rest) ?? []
|
|
861
938
|
const dataOptional = product?.dataOptional?.map(
|
|
862
939
|
({ __typename, ...product }) => {
|
|
863
940
|
const { ExtProductFoodsSubOptionalAll, ...rest } = product
|
|
@@ -991,6 +1068,15 @@ export const useSales = ({
|
|
|
991
1068
|
pickUp: 1,
|
|
992
1069
|
discount: discount.discount || 0,
|
|
993
1070
|
totalProductsPrice: convertInteger(totalProductsPrice) || 0
|
|
1071
|
+
},
|
|
1072
|
+
update (cache) {
|
|
1073
|
+
cache.modify({
|
|
1074
|
+
fields: {
|
|
1075
|
+
productFoodsAll (existingProductFoodsAll = []) {
|
|
1076
|
+
return existingProductFoodsAll
|
|
1077
|
+
}
|
|
1078
|
+
}
|
|
1079
|
+
})
|
|
994
1080
|
}
|
|
995
1081
|
})
|
|
996
1082
|
.then((responseRegisterR) => {
|
|
@@ -1082,9 +1168,9 @@ export const useSales = ({
|
|
|
1082
1168
|
? existOptionalCookies
|
|
1083
1169
|
?.map((obj) => {
|
|
1084
1170
|
const filteredSubOptions =
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1171
|
+
obj.ExtProductFoodsSubOptionalAll.filter(
|
|
1172
|
+
(subObj) => subObj.check === true
|
|
1173
|
+
)
|
|
1088
1174
|
// Excluya todo el objeto padre si filteredSubOptions está vacío
|
|
1089
1175
|
if (filteredSubOptions.length === 0) {
|
|
1090
1176
|
return null
|
|
@@ -1232,13 +1318,16 @@ export const useSales = ({
|
|
|
1232
1318
|
dataOptional: dataOptional || [],
|
|
1233
1319
|
dataExtra: dataExtra || [],
|
|
1234
1320
|
fetchMore,
|
|
1321
|
+
pagination,
|
|
1235
1322
|
discount,
|
|
1236
1323
|
datCat: categories,
|
|
1324
|
+
currentPage,
|
|
1237
1325
|
loadingProduct: loading,
|
|
1238
1326
|
handleChangeCheck,
|
|
1239
1327
|
errors,
|
|
1240
1328
|
handleUpdateAllExtra,
|
|
1241
1329
|
dispatch,
|
|
1330
|
+
handlePageChange,
|
|
1242
1331
|
handleComment,
|
|
1243
1332
|
setModalItem,
|
|
1244
1333
|
handleChangeFilter,
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { useMutation } from '@apollo/client'
|
|
2
|
+
import { UPDATE_IMAGE_PRODUCT_FOOD } from './queries'
|
|
3
|
+
|
|
4
|
+
const useSetImageProducts = () => {
|
|
5
|
+
const [setImageProducts, { data, loading, error }] = useMutation(UPDATE_IMAGE_PRODUCT_FOOD)
|
|
6
|
+
|
|
7
|
+
const updateImageProducts = async (variables) => {
|
|
8
|
+
try {
|
|
9
|
+
const response = await setImageProducts({
|
|
10
|
+
variables: {
|
|
11
|
+
input: {
|
|
12
|
+
...variables
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
})
|
|
16
|
+
return response
|
|
17
|
+
} catch (err) {
|
|
18
|
+
console.error('Error updating image products:', err)
|
|
19
|
+
throw err
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return [updateImageProducts, {
|
|
24
|
+
data,
|
|
25
|
+
loading,
|
|
26
|
+
error
|
|
27
|
+
}]
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export default useSetImageProducts
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export const fillMissingDates = (data, days = 7) => {
|
|
2
|
+
const today = new Date()
|
|
3
|
+
const filledData = []
|
|
4
|
+
|
|
5
|
+
for (let i = days - 1; i >= 0; i--) {
|
|
6
|
+
const date = new Date()
|
|
7
|
+
date.setDate(today.getDate() - i)
|
|
8
|
+
|
|
9
|
+
const formattedDate = date.toLocaleDateString('es-ES') // "dd/mm/yyyy"
|
|
10
|
+
const existingData = data.find(item => item.date === formattedDate)
|
|
11
|
+
|
|
12
|
+
filledData.push(existingData || { date: formattedDate, TotalIn: 0, TotalOut: 0 })
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return filledData
|
|
16
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { useState, useEffect } from 'react'
|
|
2
|
+
import { useQuery, gql } from '@apollo/client'
|
|
3
|
+
import { fillMissingDates } from './helpers'
|
|
4
|
+
|
|
5
|
+
const GET_STOCK_MOVEMENTS = gql`
|
|
6
|
+
query {
|
|
7
|
+
getStockMovementsByDay {
|
|
8
|
+
date
|
|
9
|
+
total_in
|
|
10
|
+
total_out
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
`
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Custom hook to fetch stock movements data for visualization.
|
|
17
|
+
* @returns {Object} { data, loading, error }
|
|
18
|
+
*/
|
|
19
|
+
export const useStockMovements = () => {
|
|
20
|
+
const { data, loading, error } = useQuery(GET_STOCK_MOVEMENTS)
|
|
21
|
+
const [chartData, setChartData] = useState([])
|
|
22
|
+
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
if (data && data.getStockMovementsByDay) {
|
|
25
|
+
// Transform data to be compatible with Recharts
|
|
26
|
+
const formattedData = data.getStockMovementsByDay.map(entry => ({
|
|
27
|
+
date: new Date(entry.date).toLocaleDateString(),
|
|
28
|
+
TotalIn: entry.total_in,
|
|
29
|
+
TotalOut: entry.total_out
|
|
30
|
+
}))
|
|
31
|
+
setChartData(formattedData)
|
|
32
|
+
}
|
|
33
|
+
}, [data])
|
|
34
|
+
|
|
35
|
+
return [fillMissingDates(chartData), { loading, error }]
|
|
36
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { useQuery, gql } from '@apollo/client'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* GraphQL query to fetch top-selling products movements
|
|
5
|
+
*/
|
|
6
|
+
const GET_TOP_PRODUCTS_MOVEMENTS = gql`
|
|
7
|
+
query {
|
|
8
|
+
getTopProductsMovements {
|
|
9
|
+
productName
|
|
10
|
+
idProduct
|
|
11
|
+
totalMovements
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
`
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Custom hook to fetch and return the top-selling products movements
|
|
18
|
+
* @returns {Object} - { data, loading, error }
|
|
19
|
+
*/
|
|
20
|
+
export const useTopProductsMovements = () => {
|
|
21
|
+
const { data, loading, error } = useQuery(GET_TOP_PRODUCTS_MOVEMENTS)
|
|
22
|
+
|
|
23
|
+
return [data?.getTopProductsMovements, {
|
|
24
|
+
loading,
|
|
25
|
+
error
|
|
26
|
+
}]
|
|
27
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { useQuery, gql } from '@apollo/client'
|
|
2
|
+
|
|
3
|
+
const GET_TOTAL_SALES = gql`
|
|
4
|
+
query totalSales {
|
|
5
|
+
totalSales {
|
|
6
|
+
success
|
|
7
|
+
message
|
|
8
|
+
totalSales
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
`
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Custom hook to fetch total sales from GraphQL API.
|
|
15
|
+
* @returns {Object} An object containing total sales, loading state, error, and refetch function.
|
|
16
|
+
*/
|
|
17
|
+
export const useTotalAllSales = () => {
|
|
18
|
+
const { data, loading, error, refetch } = useQuery(GET_TOTAL_SALES)
|
|
19
|
+
|
|
20
|
+
return [data?.totalSales?.totalSales, {
|
|
21
|
+
loading,
|
|
22
|
+
error,
|
|
23
|
+
refetch
|
|
24
|
+
}]
|
|
25
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { useQuery, gql } from '@apollo/client'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* GraphQL query to fetch total products in stock.
|
|
5
|
+
*/
|
|
6
|
+
const GET_TOTAL_PRODUCTS_IN_STOCK = gql`
|
|
7
|
+
query getTotalProductsInStock {
|
|
8
|
+
getTotalProductsInStock
|
|
9
|
+
}
|
|
10
|
+
`
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Custom hook to fetch total products in stock.
|
|
14
|
+
* @returns {Object} - { totalProductsInStock, loading, error }
|
|
15
|
+
*/
|
|
16
|
+
export const useTotalProductsInStock = () => {
|
|
17
|
+
const { data, loading, error } = useQuery(GET_TOTAL_PRODUCTS_IN_STOCK)
|
|
18
|
+
|
|
19
|
+
return [data?.getTotalProductsInStock ?? 0, {
|
|
20
|
+
loading,
|
|
21
|
+
error
|
|
22
|
+
}]
|
|
23
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { useQuery, gql } from '@apollo/client'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* GraphQL query to fetch total products sold.
|
|
5
|
+
*/
|
|
6
|
+
const GET_TOTAL_PRODUCTS_SOLD = gql`
|
|
7
|
+
query getTotalSalesSold {
|
|
8
|
+
getTotalSalesSold
|
|
9
|
+
}
|
|
10
|
+
`
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Custom hook to fetch total products sold.
|
|
14
|
+
* @returns {Object} - { totalProductsSold, loading, error }
|
|
15
|
+
*/
|
|
16
|
+
export const useTotalProductsSold = () => {
|
|
17
|
+
const { data, loading, error } = useQuery(GET_TOTAL_PRODUCTS_SOLD)
|
|
18
|
+
|
|
19
|
+
return [data?.getTotalSalesSold || 0, {
|
|
20
|
+
loading,
|
|
21
|
+
error
|
|
22
|
+
}]
|
|
23
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { useQuery, gql } from '@apollo/client'
|
|
2
|
+
|
|
3
|
+
const GET_TOTAL_PRODUCTS_SOLD = gql`
|
|
4
|
+
query {
|
|
5
|
+
getTotalProductsSold
|
|
6
|
+
}
|
|
7
|
+
`
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Custom hook to fetch the total number of products sold.
|
|
11
|
+
* @returns {{ totalSold: number, loading: boolean, error: any }}
|
|
12
|
+
*/
|
|
13
|
+
export const useTotalProductsSolded = () => {
|
|
14
|
+
const { data, loading, error } = useQuery(GET_TOTAL_PRODUCTS_SOLD)
|
|
15
|
+
|
|
16
|
+
return [data?.getTotalProductsSold, {
|
|
17
|
+
loading,
|
|
18
|
+
error
|
|
19
|
+
}]
|
|
20
|
+
}
|
|
@@ -11,25 +11,36 @@ export const useUpdateMultipleProducts = ({
|
|
|
11
11
|
loading,
|
|
12
12
|
error
|
|
13
13
|
}] = useMutation(UPDATE_MULTIPLE_PRODUCTS)
|
|
14
|
+
|
|
14
15
|
const [dataCategoriesProducts] = useCategoriesProduct()
|
|
15
|
-
const findEmptyCategory = dataCategoriesProducts?.find(
|
|
16
|
+
const findEmptyCategory = dataCategoriesProducts?.find(({ pName }) => pName === CATEGORY_EMPTY)
|
|
16
17
|
const updateProducts = async (products) => {
|
|
17
18
|
const newProducts = products.map(product => {
|
|
19
|
+
const {
|
|
20
|
+
PRECIO_AL_PUBLICO: ProPrice,
|
|
21
|
+
DESCRIPCION: ProDescription,
|
|
22
|
+
NOMBRE: pName,
|
|
23
|
+
pCode,
|
|
24
|
+
CANTIDAD: stock = 0,
|
|
25
|
+
'IMPUESTO (%)': vat,
|
|
26
|
+
CODIGO_DE_BARRAS: ProBarCode
|
|
27
|
+
} = product
|
|
18
28
|
return {
|
|
19
29
|
idStore: '',
|
|
20
|
-
ProPrice
|
|
30
|
+
ProPrice,
|
|
21
31
|
ProDescuento: 0,
|
|
22
32
|
ValueDelivery: 0,
|
|
23
|
-
ProDescription
|
|
24
|
-
pName
|
|
25
|
-
pCode
|
|
33
|
+
ProDescription,
|
|
34
|
+
pName,
|
|
35
|
+
pCode,
|
|
26
36
|
carProId: findEmptyCategory?.carProId ?? null,
|
|
27
37
|
pState: 1,
|
|
28
38
|
sTateLogistic: 1,
|
|
29
39
|
ProStar: 0,
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
40
|
+
stock,
|
|
41
|
+
ProImage: '/images/placeholder-image.webp',
|
|
42
|
+
vat,
|
|
43
|
+
ProBarCode: String(ProBarCode) || '',
|
|
33
44
|
ProHeight: null,
|
|
34
45
|
ProWeight: '',
|
|
35
46
|
ProOutstanding: 0,
|
|
@@ -39,6 +50,16 @@ export const useUpdateMultipleProducts = ({
|
|
|
39
50
|
)
|
|
40
51
|
try {
|
|
41
52
|
const response = await updateMultipleProducts({ variables: { input: newProducts } })
|
|
53
|
+
// sendNotification
|
|
54
|
+
for (const { errors } of response.data.updateMultipleProducts) {
|
|
55
|
+
if (errors) {
|
|
56
|
+
sendNotification({
|
|
57
|
+
backgroundColor: 'error',
|
|
58
|
+
description: errors[0].message,
|
|
59
|
+
title: 'Error'
|
|
60
|
+
})
|
|
61
|
+
}
|
|
62
|
+
}
|
|
42
63
|
return response.data.updateMultipleProducts
|
|
43
64
|
} catch (e) {
|
|
44
65
|
sendNotification({
|