npm-pkg-hook 1.1.5 → 1.1.8
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/.eslintrc.js +19 -113
- package/.eslintrc.json +127 -108
- package/next.config.js +2 -5
- package/package.json +27 -24
- package/src/config/client/errors.js +14 -14
- package/src/config/client/index.js +1 -1
- package/src/hooks/getCategoriesWithProduct/helpers/index.js +7 -0
- package/src/hooks/getCategoriesWithProduct/index.js +62 -0
- package/src/hooks/getSession/index.js +18 -18
- package/src/hooks/index.js +13 -9
- package/src/hooks/useAcumulateDate/index.js +1 -1
- package/src/hooks/useAnimationFrame/index.js +45 -45
- package/src/hooks/useAsideCart/helpers/index.js +22 -0
- package/src/hooks/useAsideCart/index.js +156 -0
- package/src/hooks/useAsideCart/queries.js +10 -0
- package/src/hooks/useBanner/index.js +11 -11
- package/src/hooks/useCart/index.js +2 -0
- package/src/hooks/useCart/queries.js +164 -0
- package/src/hooks/useCart/useCart/helpers/index.js +75 -0
- package/src/hooks/useCart/useCart/index.js +411 -0
- package/src/hooks/useCart/useGetCart/index.js +31 -0
- package/src/hooks/useCatWithProduct/index.js +15 -15
- package/src/hooks/useCatWithProduct/queries.js +1 -1
- package/src/hooks/useCatWithProductClient/index.js +48 -0
- package/src/hooks/useCatWithProductClient/queries.js +55 -0
- package/src/hooks/useCategoriesProduct/index.js +12 -12
- package/src/hooks/useCategoriesProduct/queries.js +16 -16
- package/src/hooks/useCategoryInStore/index.js +39 -36
- package/src/hooks/useCategoryInStore/queries.js +78 -78
- package/src/hooks/useCategoryStore/index.js +2 -2
- package/src/hooks/useChartData/index.js +159 -156
- package/src/hooks/useChartData/useChartData/index.js +199 -197
- package/src/hooks/useChartData/useChartDataAllOrders/index.js +94 -94
- package/src/hooks/useCheckbox/index.js +115 -115
- package/src/hooks/useClients/index.js +12 -14
- package/src/hooks/useClients/queries.js +1 -1
- package/src/hooks/useConnection/index.js +20 -21
- package/src/hooks/useCreateProduct/helpers/useEditImageProduct/index.js +6 -2
- package/src/hooks/useCreateProduct/index.js +22 -19
- package/src/hooks/useDeleteSubProductOptional/index.js +31 -30
- package/src/hooks/useDeleteSubProductOptional/queries.js +10 -10
- package/src/hooks/useDessert/helpers/index.js +51 -51
- package/src/hooks/useDessert/index.js +56 -65
- package/src/hooks/useDevices/index.js +35 -36
- package/src/hooks/useDevices/queries.js +19 -19
- package/src/hooks/useDropzone/index.js +94 -79
- package/src/hooks/useDynamicAuth/index.js +13 -13
- package/src/hooks/useDynamicAuth/queries.js +24 -24
- package/src/hooks/useEmployee/queries.js +1 -1
- package/src/hooks/useEvent/index.js +33 -33
- package/src/hooks/useFavoriteStores/index.js +19 -0
- package/src/hooks/useFavoriteStores/queries.js +47 -0
- package/src/hooks/useFetchJson/index.js +25 -25
- package/src/hooks/useFingerprintjs/index.js +172 -176
- package/src/hooks/useFormTools/index.js +12 -11
- package/src/hooks/useFormatDate/index.js +20 -21
- package/src/hooks/useFormatNumberPhone/index.js +9 -9
- package/src/hooks/useFullScreenMode/index.js +65 -65
- package/src/hooks/useGenerateNumberArray/index.js +17 -17
- package/src/hooks/useGetExtProductFoodsSubOptionalAll/index.js +14 -0
- package/src/hooks/useGetFoodRecomended/index.js +33 -0
- package/src/hooks/useGetFoodRecomended/queries.js +47 -0
- package/src/hooks/useGetMinPrice/index.js +8 -0
- package/src/hooks/useGetMinPrice/queries.js +7 -0
- package/src/hooks/useGetOneStoreRating/index.js +40 -0
- package/src/hooks/useGetOneStoreRating/queries.js +18 -0
- package/src/hooks/useGoogleLogin/index.js +160 -161
- package/src/hooks/useHover/index.js +29 -29
- package/src/hooks/useImageOptimization/index.js +15 -15
- package/src/hooks/useImageWeight/index.js +18 -19
- package/src/hooks/useImagesStore/index.js +139 -140
- package/src/hooks/useImagesStore/queries.js +19 -18
- package/src/hooks/useInnerHtml/index.js +39 -38
- package/src/hooks/useIntersection/index.js +4 -4
- package/src/hooks/useKeypress/index.js +28 -28
- package/src/hooks/useLazyScript/index.js +35 -36
- package/src/hooks/useLocalSorage/index.js +2 -2
- package/src/hooks/useLogout/index.js +23 -23
- package/src/hooks/useManageQueryParams/index.js +36 -37
- package/src/hooks/useMobile/index.js +39 -38
- package/src/hooks/useMutateHeight/index.js +15 -16
- package/src/hooks/useOrderClient/index.js +5 -0
- package/src/hooks/useOrders/index.js +10 -16
- package/src/hooks/useOrders/queries.js +1 -1
- package/src/hooks/useProductsFood/index.js +32 -32
- package/src/hooks/useProductsFood/queriesStore.js +49 -48
- package/src/hooks/useProductsFood/useEditProduct.js +2 -4
- package/src/hooks/useProductsFood/usetagsProducts.js +83 -83
- package/src/hooks/useProviders/index.js +3 -3
- package/src/hooks/useProviders/queries.js +31 -31
- package/src/hooks/useProviders/useProvidersCreateStore/index.js +12 -13
- package/src/hooks/useProviders/useProvidersDataStore/index.js +24 -24
- package/src/hooks/useProvidersStore/index.js +24 -24
- package/src/hooks/useProvidersStore/queries.js +31 -31
- package/src/hooks/useRatingArrayData/index.js +54 -0
- package/src/hooks/{useRatingData → useRatingArrayData}/queries.js +19 -18
- package/src/hooks/useReactToPrint/index.js +1120 -1098
- package/src/hooks/useRemoveExtraProductFoodsOptional/index.js +23 -23
- package/src/hooks/useRemoveExtraProductFoodsOptional/queries.js +48 -48
- package/src/hooks/useReport/index.js +9 -9
- package/src/hooks/useReport/queries.js +1 -1
- package/src/hooks/useRestaurant/index.js +19 -19
- package/src/hooks/useRestaurant/queries.js +80 -80
- package/src/hooks/useSales/index.js +476 -451
- package/src/hooks/useSales/queries.js +14 -15
- package/src/hooks/useSales/useGetAllSales/index.js +25 -25
- package/src/hooks/useSales/useTotalSales.js +18 -18
- package/src/hooks/useSaveAvailableProduct/helpers/index.js +29 -29
- package/src/hooks/useSaveAvailableProduct/index.js +16 -16
- package/src/hooks/useSaveAvailableProduct/queries.js +1 -1
- package/src/hooks/useSchedule/index.js +33 -36
- package/src/hooks/useSchedule/index.jsx +22 -22
- package/src/hooks/useSchedule/queries.js +34 -35
- package/src/hooks/useScheduleData/index.js +123 -171
- package/src/hooks/useScroll/index.js +56 -57
- package/src/hooks/useScrollRotate/index.js +16 -14
- package/src/hooks/useSetSession/index.js +16 -16
- package/src/hooks/useSetState/index.js +3 -3
- package/src/hooks/useStatusOpenStore/helpers/index.js +101 -102
- package/src/hooks/useStatusOpenStore/index.js +172 -173
- package/src/hooks/useStatusOrdersClient/helpers/index.js +14 -0
- package/src/hooks/useStatusOrdersClient/index.js +17 -0
- package/src/hooks/useStatusOrdersClient/queries.js +80 -0
- package/src/hooks/useStore/index.js +40 -25
- package/src/hooks/useStore/queries.js +162 -136
- package/src/hooks/useStoreCalendar/index.js +5 -7
- package/src/hooks/useStoreContacts/index.js +16 -16
- package/src/hooks/useStoreContacts/queries.js +1 -1
- package/src/hooks/useTimeAgo/useTimeAgo.js +39 -39
- package/src/hooks/useUpdateCart/index.js +34 -28
- package/src/hooks/useUpdateExistingOrders/index.js +35 -35
- package/src/hooks/useUpdateExtProductFoodsSubOptional/index.js +38 -37
- package/src/hooks/useUser/index.js +1 -1
- package/src/hooks/useUser/queries.js +1 -1
- package/src/hooks/useWindowSize/index.js +38 -38
- package/src/mock/dessert/index.js +16 -16
- package/src/mock/index.js +1 -2
- package/src/utils/index.js +42 -45
- package/src/hooks/useRatingData/index.js +0 -53
- package/src/hooks/useSalesClient/index.js +0 -1
|
@@ -1,23 +1,26 @@
|
|
|
1
|
-
import { useMutation, useQuery } from '@apollo/client'
|
|
2
|
-
import { useState } from 'react'
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { useMutation, useQuery } from '@apollo/client'
|
|
2
|
+
import { useState } from 'react'
|
|
3
|
+
import {
|
|
4
|
+
DELETE_ONE_CAT_PRODUCTS,
|
|
5
|
+
GET_ULTIMATE_CATEGORY_PRODUCTS,
|
|
6
|
+
UPDATE_CAT_IN_PRODUCT
|
|
7
|
+
} from '../useProductsFood/queriesStore'
|
|
8
|
+
import { GET_ONE_STORE_IN_CATEGORY } from './queries'
|
|
6
9
|
|
|
7
|
-
export const useCategoryInStore = ({ catStoreId }) => {
|
|
10
|
+
export const useCategoryInStore = ({ catStoreId, setAlertBox = () => {} } = {}) => {
|
|
8
11
|
// STATES
|
|
9
12
|
const [categories, setOneCategoryInStore] = useState([])
|
|
10
13
|
const [deleteCatOfProducts] = useMutation(DELETE_ONE_CAT_PRODUCTS, {
|
|
11
14
|
onError: (e) => {
|
|
12
15
|
setAlertBox({
|
|
13
16
|
message: e.graphQLErrors[0].message,
|
|
14
|
-
color:
|
|
17
|
+
color: 'error'
|
|
15
18
|
})
|
|
16
19
|
},
|
|
17
|
-
update(cache) {
|
|
20
|
+
update (cache) {
|
|
18
21
|
cache.modify({
|
|
19
22
|
fields: {
|
|
20
|
-
catProductsAll(dataOld = []) {
|
|
23
|
+
catProductsAll (dataOld = []) {
|
|
21
24
|
return cache.writeQuery({ query: GET_ULTIMATE_CATEGORY_PRODUCTS, data: dataOld })
|
|
22
25
|
}
|
|
23
26
|
}
|
|
@@ -28,13 +31,13 @@ export const useCategoryInStore = ({ catStoreId }) => {
|
|
|
28
31
|
onError: (e) => {
|
|
29
32
|
console.log({
|
|
30
33
|
message: e.graphQLErrors[0].message,
|
|
31
|
-
color:
|
|
34
|
+
color: 'error'
|
|
32
35
|
})
|
|
33
36
|
},
|
|
34
|
-
update(cache) {
|
|
37
|
+
update (cache) {
|
|
35
38
|
cache.modify({
|
|
36
39
|
fields: {
|
|
37
|
-
catProductsAll(dataOld = []) {
|
|
40
|
+
catProductsAll (dataOld = []) {
|
|
38
41
|
return cache.writeQuery({ query: GET_ULTIMATE_CATEGORY_PRODUCTS, data: dataOld })
|
|
39
42
|
}
|
|
40
43
|
}
|
|
@@ -57,32 +60,33 @@ export const useCategoryInStore = ({ catStoreId }) => {
|
|
|
57
60
|
setOneCategoryInStore(data.getOneCatStore)
|
|
58
61
|
}
|
|
59
62
|
})
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
63
|
+
// HANDLESS
|
|
64
|
+
const handlerDeleteCategoryInStore = (category) => {
|
|
65
|
+
const { pState, idPc } = category || {}
|
|
66
|
+
if (!idPc || !pState) return
|
|
67
|
+
return deleteCatOfProducts({
|
|
68
|
+
variables: { idPc, pState },
|
|
69
|
+
update (cache) {
|
|
70
|
+
cache.modify({
|
|
71
|
+
fields: {
|
|
72
|
+
catProductsAll (dataOld = []) {
|
|
73
|
+
return cache.writeQuery({ query: GET_ULTIMATE_CATEGORY_PRODUCTS, data: dataOld })
|
|
71
74
|
}
|
|
72
|
-
})
|
|
73
|
-
}
|
|
74
|
-
})
|
|
75
|
-
}
|
|
76
|
-
const handleUpdateCatInProduct = async ({ data }) => {
|
|
77
|
-
await updatedCatWithProducts({
|
|
78
|
-
variables: {
|
|
79
|
-
input: {
|
|
80
|
-
setData: data?.map(x => { return { idProduct: x.pId } }),
|
|
81
|
-
idCat: idCat
|
|
82
75
|
}
|
|
76
|
+
})
|
|
77
|
+
}
|
|
78
|
+
})
|
|
79
|
+
}
|
|
80
|
+
const handleUpdateCatInProduct = async ({ data }) => {
|
|
81
|
+
await updatedCatWithProducts({
|
|
82
|
+
variables: {
|
|
83
|
+
input: {
|
|
84
|
+
setData: data?.map(x => { return { idProduct: x.pId } }),
|
|
85
|
+
idCat: ''
|
|
83
86
|
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
87
|
+
}
|
|
88
|
+
})
|
|
89
|
+
}
|
|
86
90
|
return {
|
|
87
91
|
categories,
|
|
88
92
|
data: data?.catProductsAll || [],
|
|
@@ -92,4 +96,3 @@ export const useCategoryInStore = ({ catStoreId }) => {
|
|
|
92
96
|
handleUpdateCatInProduct
|
|
93
97
|
}
|
|
94
98
|
}
|
|
95
|
-
|
|
@@ -1,78 +1,78 @@
|
|
|
1
|
-
import { gql } from
|
|
2
|
-
|
|
3
|
-
export const GET_ONE_STORE_IN_CATEGORY = gql`
|
|
4
|
-
query getOneCatStore($catStore: ID){
|
|
5
|
-
getOneCatStore(catStore: $catStore){
|
|
6
|
-
catStore
|
|
7
|
-
idUser
|
|
8
|
-
cName
|
|
9
|
-
cState
|
|
10
|
-
cDatCre
|
|
11
|
-
cPathImage
|
|
12
|
-
cDatMod
|
|
13
|
-
csDescription
|
|
14
|
-
getAllStore {
|
|
15
|
-
idStore
|
|
16
|
-
cId
|
|
17
|
-
id
|
|
18
|
-
dId
|
|
19
|
-
ctId
|
|
20
|
-
catStore
|
|
21
|
-
neighborhoodStore
|
|
22
|
-
Viaprincipal
|
|
23
|
-
storeOwner
|
|
24
|
-
storeName
|
|
25
|
-
emailStore
|
|
26
|
-
storePhone
|
|
27
|
-
socialRaz
|
|
28
|
-
Image
|
|
29
|
-
banner
|
|
30
|
-
documentIdentifier
|
|
31
|
-
uPhoNum
|
|
32
|
-
ULocation
|
|
33
|
-
upLat
|
|
34
|
-
upLon
|
|
35
|
-
uState
|
|
36
|
-
siteWeb
|
|
37
|
-
description
|
|
38
|
-
NitStore
|
|
39
|
-
typeRegiments
|
|
40
|
-
typeContribute
|
|
41
|
-
secVia
|
|
42
|
-
addressStore
|
|
43
|
-
createdAt
|
|
44
|
-
pais {
|
|
45
|
-
cId
|
|
46
|
-
cName
|
|
47
|
-
cCalCod
|
|
48
|
-
cState
|
|
49
|
-
cDatCre
|
|
50
|
-
cDatMod
|
|
51
|
-
}
|
|
52
|
-
city {
|
|
53
|
-
ctId
|
|
54
|
-
dId
|
|
55
|
-
cName
|
|
56
|
-
cState
|
|
57
|
-
cDatCre
|
|
58
|
-
cDatMod
|
|
59
|
-
}
|
|
60
|
-
department {
|
|
61
|
-
dId
|
|
62
|
-
cId
|
|
63
|
-
dName
|
|
64
|
-
dState
|
|
65
|
-
dDatCre
|
|
66
|
-
dDatMod
|
|
67
|
-
}
|
|
68
|
-
getAllRatingStar {
|
|
69
|
-
rSId
|
|
70
|
-
rScore
|
|
71
|
-
idStore
|
|
72
|
-
createAt
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
`
|
|
1
|
+
import { gql } from '@apollo/client'
|
|
2
|
+
|
|
3
|
+
export const GET_ONE_STORE_IN_CATEGORY = gql`
|
|
4
|
+
query getOneCatStore($catStore: ID){
|
|
5
|
+
getOneCatStore(catStore: $catStore){
|
|
6
|
+
catStore
|
|
7
|
+
idUser
|
|
8
|
+
cName
|
|
9
|
+
cState
|
|
10
|
+
cDatCre
|
|
11
|
+
cPathImage
|
|
12
|
+
cDatMod
|
|
13
|
+
csDescription
|
|
14
|
+
getAllStore {
|
|
15
|
+
idStore
|
|
16
|
+
cId
|
|
17
|
+
id
|
|
18
|
+
dId
|
|
19
|
+
ctId
|
|
20
|
+
catStore
|
|
21
|
+
neighborhoodStore
|
|
22
|
+
Viaprincipal
|
|
23
|
+
storeOwner
|
|
24
|
+
storeName
|
|
25
|
+
emailStore
|
|
26
|
+
storePhone
|
|
27
|
+
socialRaz
|
|
28
|
+
Image
|
|
29
|
+
banner
|
|
30
|
+
documentIdentifier
|
|
31
|
+
uPhoNum
|
|
32
|
+
ULocation
|
|
33
|
+
upLat
|
|
34
|
+
upLon
|
|
35
|
+
uState
|
|
36
|
+
siteWeb
|
|
37
|
+
description
|
|
38
|
+
NitStore
|
|
39
|
+
typeRegiments
|
|
40
|
+
typeContribute
|
|
41
|
+
secVia
|
|
42
|
+
addressStore
|
|
43
|
+
createdAt
|
|
44
|
+
pais {
|
|
45
|
+
cId
|
|
46
|
+
cName
|
|
47
|
+
cCalCod
|
|
48
|
+
cState
|
|
49
|
+
cDatCre
|
|
50
|
+
cDatMod
|
|
51
|
+
}
|
|
52
|
+
city {
|
|
53
|
+
ctId
|
|
54
|
+
dId
|
|
55
|
+
cName
|
|
56
|
+
cState
|
|
57
|
+
cDatCre
|
|
58
|
+
cDatMod
|
|
59
|
+
}
|
|
60
|
+
department {
|
|
61
|
+
dId
|
|
62
|
+
cId
|
|
63
|
+
dName
|
|
64
|
+
dState
|
|
65
|
+
dDatCre
|
|
66
|
+
dDatMod
|
|
67
|
+
}
|
|
68
|
+
getAllRatingStar {
|
|
69
|
+
rSId
|
|
70
|
+
rScore
|
|
71
|
+
idStore
|
|
72
|
+
createAt
|
|
73
|
+
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
`
|
|
@@ -1,171 +1,174 @@
|
|
|
1
|
-
import { useQuery } from '@apollo/client'
|
|
2
|
-
import { useState } from 'react'
|
|
3
|
-
import { SPANISH_MONTHS } from
|
|
4
|
-
import { GET_ALL_SALES } from
|
|
5
|
-
export * from './useChartData'
|
|
1
|
+
import { useQuery } from '@apollo/client'
|
|
2
|
+
import { useState } from 'react'
|
|
3
|
+
import { SPANISH_MONTHS } from '../../utils/index'
|
|
4
|
+
import { GET_ALL_SALES } from '../useReport/queries'
|
|
6
5
|
export * from './useChartDataAllOrders'
|
|
7
6
|
|
|
8
7
|
export const useChartData = ({ year }) => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
result.push(res[mes])
|
|
8
|
+
// Construcción del nuevo array:
|
|
9
|
+
const { data, loading } = useQuery(GET_ALL_SALES)
|
|
10
|
+
const [chartType, setChartType] = useState('bar')
|
|
11
|
+
const [chartTypeYear, setChartTypeYear] = useState(new Date().getFullYear())
|
|
12
|
+
const [asFilter, setFilter] = useState(false)
|
|
13
|
+
const [newResult, setNewResult] = useState([])
|
|
14
|
+
const result = []
|
|
15
|
+
data?.getAllSalesStore?.length > 0 && data?.getAllSalesStore.reduce(function (res, value) {
|
|
16
|
+
// Creamos la posición del array para cada mes
|
|
17
|
+
const mes = new Date(value.pDatCre).getMonth()
|
|
18
|
+
const Year = new Date(value.pDatCre).getFullYear()
|
|
19
|
+
if (!res[mes]) {
|
|
20
|
+
res[mes] = { Mes: mes, Year }
|
|
21
|
+
// Inicializamos a 0 el valor de cada key
|
|
22
|
+
Object.keys(value).forEach((key) => {
|
|
23
|
+
if (key !== 'pDatCre') {
|
|
24
|
+
res[mes][key] = 0
|
|
30
25
|
}
|
|
31
|
-
|
|
32
|
-
Object.keys(value).forEach(function (key) {
|
|
33
|
-
if (key != 'pDatCre') {
|
|
34
|
-
res[mes]['totalProductsPrice'] += value['totalProductsPrice']
|
|
35
|
-
}
|
|
36
|
-
})
|
|
37
|
-
return res
|
|
38
|
-
}, {})
|
|
39
|
-
|
|
40
|
-
let allMonths = Array.from({ length: 12 }, (_, i) => { return i })
|
|
41
|
-
let missingMonths = allMonths.filter(month => { return !result.some(data => { return data.Mes === month }) })
|
|
26
|
+
})
|
|
42
27
|
|
|
43
|
-
|
|
44
|
-
result.push({
|
|
45
|
-
'Mes': element,
|
|
46
|
-
'totalProductsPrice': 0,
|
|
47
|
-
'Year': ''
|
|
48
|
-
})
|
|
28
|
+
result.push(res[mes])
|
|
49
29
|
}
|
|
30
|
+
// Sumamos el valor de cada clave dentro de un bucle
|
|
31
|
+
Object.keys(value).forEach(function (key) {
|
|
32
|
+
if (key !== 'pDatCre') {
|
|
33
|
+
res[mes].totalProductsPrice += value.totalProductsPrice
|
|
34
|
+
}
|
|
35
|
+
})
|
|
36
|
+
return res
|
|
37
|
+
}, {})
|
|
50
38
|
|
|
51
|
-
|
|
39
|
+
const allMonths = Array.from({ length: 12 }, (_, i) => { return i })
|
|
40
|
+
const missingMonths = allMonths.filter(month => { return !result.some(data => { return data.Mes === month }) })
|
|
52
41
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
102
|
-
},
|
|
103
|
-
plugins: {
|
|
104
|
-
title: {
|
|
105
|
-
display: true,
|
|
106
|
-
text: labelTitle
|
|
107
|
-
},
|
|
108
|
-
}
|
|
42
|
+
for (const element of missingMonths) {
|
|
43
|
+
result.push({
|
|
44
|
+
Mes: element,
|
|
45
|
+
totalProductsPrice: 0,
|
|
46
|
+
Year: ''
|
|
47
|
+
})
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
result.sort((a, b) => { return a.Mes - b.Mes })
|
|
51
|
+
|
|
52
|
+
const labelTitle = `Ventas por meses del año ${asFilter ? chartTypeYear : ''}`
|
|
53
|
+
// Resultado:
|
|
54
|
+
const dataChart = {
|
|
55
|
+
labels: asFilter
|
|
56
|
+
? newResult.map(data => {
|
|
57
|
+
return SPANISH_MONTHS[data.Mes]
|
|
58
|
+
})
|
|
59
|
+
: result.map(data => {
|
|
60
|
+
return SPANISH_MONTHS[data.Mes]
|
|
61
|
+
}),
|
|
62
|
+
datasets: [
|
|
63
|
+
{
|
|
64
|
+
label: labelTitle,
|
|
65
|
+
data: asFilter ? newResult.map(data => { return data.totalProductsPrice }) : result.map(data => { return data.totalProductsPrice }),
|
|
66
|
+
backgroundColor: [
|
|
67
|
+
'rgba(255, 99, 132, 0.2)',
|
|
68
|
+
'rgba(54, 162, 235, 0.2)',
|
|
69
|
+
'rgba(255, 206, 86, 0.2)',
|
|
70
|
+
'rgba(75, 192, 192, 0.2)',
|
|
71
|
+
'rgba(153, 102, 255, 0.2)',
|
|
72
|
+
'rgba(255, 159, 64, 0.2)'
|
|
73
|
+
],
|
|
74
|
+
borderColor: chartType === 'bar'
|
|
75
|
+
? [
|
|
76
|
+
'rgba(255, 99, 132, 1)',
|
|
77
|
+
'rgba(54, 162, 235, 1)',
|
|
78
|
+
'rgba(255, 206, 86, 1)',
|
|
79
|
+
'rgba(75, 192, 192, 1)',
|
|
80
|
+
'rgba(153, 102, 255, 1)',
|
|
81
|
+
'rgba(255, 159, 64, 1)'
|
|
82
|
+
]
|
|
83
|
+
: 'rgb(255 0 0)',
|
|
84
|
+
tension: 0.6,
|
|
85
|
+
fill: false,
|
|
86
|
+
borderWidth: 1,
|
|
87
|
+
barPercentage: 1,
|
|
88
|
+
barThickness: 50,
|
|
89
|
+
minBarLength: 3
|
|
109
90
|
}
|
|
110
|
-
|
|
91
|
+
]
|
|
92
|
+
}
|
|
93
|
+
const options = {
|
|
94
|
+
interaction: {
|
|
95
|
+
mode: 'index',
|
|
96
|
+
intersect: false
|
|
97
|
+
},
|
|
98
|
+
scales: {
|
|
99
|
+
x: {
|
|
100
|
+
stacked: true
|
|
101
|
+
},
|
|
102
|
+
y: {
|
|
103
|
+
stacked: true
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
plugins: {
|
|
107
|
+
title: {
|
|
108
|
+
display: true,
|
|
109
|
+
text: labelTitle
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
const groupedData = {}
|
|
111
114
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
}
|
|
117
|
-
groupedData[year].push(item)
|
|
118
|
-
})
|
|
119
|
-
const years = []
|
|
120
|
-
data && data.getAllSalesStore.forEach((item) => {
|
|
121
|
-
const y = new Date(item.pDatCre).getFullYear()
|
|
122
|
-
if (!years.includes(y)) {
|
|
123
|
-
years.push(y)
|
|
124
|
-
}
|
|
125
|
-
})
|
|
126
|
-
const handleChangeYear = (value) => {
|
|
127
|
-
setFilter(true)
|
|
128
|
-
const currentYear = parseInt(value)
|
|
129
|
-
setChartTypeYear(currentYear || '')
|
|
130
|
-
if (result?.length > 0) {
|
|
131
|
-
const filterToYear = result.filter((elem) => {
|
|
132
|
-
return elem?.Year == currentYear
|
|
133
|
-
})
|
|
134
|
-
let missingNewMonths = allMonths.filter(month => { return !filterToYear.some(data => { return data.Mes === month }) })
|
|
135
|
-
for (const element of missingNewMonths) {
|
|
136
|
-
filterToYear.push({
|
|
137
|
-
'Mes': element,
|
|
138
|
-
'totalProductsPrice': 0,
|
|
139
|
-
'Year': ''
|
|
140
|
-
})
|
|
141
|
-
}
|
|
142
|
-
filterToYear.sort((a, b) => { return a.Mes - b.Mes })
|
|
143
|
-
setNewResult(filterToYear)
|
|
144
|
-
return filterToYear
|
|
145
|
-
}
|
|
115
|
+
data && data.getAllSalesStore.forEach((item) => {
|
|
116
|
+
const year = new Date(item.pDatCre).getFullYear()
|
|
117
|
+
if (!groupedData[year]) {
|
|
118
|
+
groupedData[year] = []
|
|
146
119
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
120
|
+
groupedData[year].push(item)
|
|
121
|
+
})
|
|
122
|
+
const years = []
|
|
123
|
+
data && data.getAllSalesStore.forEach((item) => {
|
|
124
|
+
const y = new Date(item.pDatCre).getFullYear()
|
|
125
|
+
if (!years.includes(y)) {
|
|
126
|
+
years.push(y)
|
|
150
127
|
}
|
|
151
|
-
|
|
152
|
-
|
|
128
|
+
})
|
|
129
|
+
const handleChangeYear = (value) => {
|
|
130
|
+
setFilter(true)
|
|
131
|
+
const currentYear = parseInt(value)
|
|
132
|
+
setChartTypeYear(currentYear || '')
|
|
133
|
+
if (result?.length > 0) {
|
|
134
|
+
const filterToYear = result.filter((elem) => {
|
|
135
|
+
return elem?.Year === currentYear
|
|
136
|
+
})
|
|
137
|
+
const missingNewMonths = allMonths.filter(month => { return !filterToYear.some(data => { return data.Mes === month }) })
|
|
138
|
+
for (const element of missingNewMonths) {
|
|
139
|
+
filterToYear.push({
|
|
140
|
+
Mes: element,
|
|
141
|
+
totalProductsPrice: 0,
|
|
142
|
+
Year: ''
|
|
143
|
+
})
|
|
144
|
+
}
|
|
145
|
+
filterToYear.sort((a, b) => { return a.Mes - b.Mes })
|
|
146
|
+
setNewResult(filterToYear)
|
|
147
|
+
return filterToYear
|
|
153
148
|
}
|
|
149
|
+
}
|
|
150
|
+
const cleanFilter = () => {
|
|
151
|
+
setFilter(false)
|
|
152
|
+
setChartTypeYear(new Date().getFullYear())
|
|
153
|
+
}
|
|
154
|
+
const sortYear = () => {
|
|
155
|
+
return years.sort((a, b) => { return b - a })
|
|
156
|
+
}
|
|
154
157
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
158
|
+
const organiceYears = sortYear()
|
|
159
|
+
return {
|
|
160
|
+
handleChangeYear,
|
|
161
|
+
setFilter,
|
|
162
|
+
cleanFilter,
|
|
163
|
+
setChartType,
|
|
164
|
+
years: organiceYears,
|
|
165
|
+
asFilter,
|
|
166
|
+
chartTypeYear,
|
|
167
|
+
options,
|
|
168
|
+
chartType,
|
|
169
|
+
labelTitle,
|
|
170
|
+
result,
|
|
171
|
+
dataChart,
|
|
172
|
+
loading
|
|
173
|
+
}
|
|
171
174
|
}
|