npm-pkg-hook 1.3.7 → 1.3.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 +38 -38
- package/.eslintrc.json +127 -127
- package/.github/pull_request_template.md +17 -17
- package/.github/workflows/pepeline.yaml +29 -29
- package/package.json +46 -46
- package/script.txt +6 -6
- package/src/config/client/index.js +1 -1
- package/src/hooks/getCategoriesWithProduct/helpers/index.js +7 -7
- package/src/hooks/getCategoriesWithProduct/index.js +62 -62
- package/src/hooks/getSession/index.js +18 -18
- package/src/hooks/useAnimationFrame/index.js +45 -45
- package/src/hooks/useAsideCart/index.js +155 -155
- package/src/hooks/useAsideCart/queries.js +10 -10
- package/src/hooks/useCart/index.js +2 -2
- package/src/hooks/useCart/queries.js +164 -164
- package/src/hooks/useCart/useCart/helpers/index.js +75 -75
- package/src/hooks/useCart/useCart/index.js +410 -410
- package/src/hooks/useCart/useGetCart/index.js +31 -31
- package/src/hooks/useCatWithProductClient/index.js +56 -56
- package/src/hooks/useCatWithProductClient/queries.js +55 -55
- package/src/hooks/useCategoriesProduct/index.js +12 -12
- package/src/hooks/useCategoriesProduct/queries.js +16 -16
- package/src/hooks/useCategoryInStore/queries.js +78 -78
- package/src/hooks/useChartData/useChartData/index.js +199 -199
- package/src/hooks/useChartData/useChartDataAllOrders/index.js +94 -94
- package/src/hooks/useCheckbox/index.js +115 -115
- package/src/hooks/useCreateProduct/helpers/manageCacheDataCatProduct/index.js +52 -0
- package/src/hooks/useCreateProduct/index.js +8 -3
- package/src/hooks/useDeleteSubProductOptional/index.js +30 -30
- package/src/hooks/useDeleteSubProductOptional/queries.js +10 -10
- package/src/hooks/useDessert/helpers/index.js +51 -51
- package/src/hooks/useDevices/index.js +35 -35
- package/src/hooks/useDevices/queries.js +19 -19
- package/src/hooks/useDropzone/index.js +94 -94
- package/src/hooks/useDynamicAuth/index.js +13 -13
- package/src/hooks/useDynamicAuth/queries.js +24 -24
- package/src/hooks/useEditSubProductOptional/queries.js +10 -10
- package/src/hooks/useEvent/index.js +33 -33
- package/src/hooks/useFavoriteStores/index.js +19 -19
- package/src/hooks/useFavoriteStores/queries.js +47 -47
- package/src/hooks/useFetchJson/index.js +25 -25
- package/src/hooks/useFingerprintjs/index.js +172 -172
- package/src/hooks/useFullScreenMode/index.js +65 -65
- package/src/hooks/useGenerateNumberArray/index.js +17 -17
- package/src/hooks/useGetExtProductFoodsSubOptionalAll/index.js +14 -14
- package/src/hooks/useGetFoodRecomended/index.js +32 -33
- package/src/hooks/useGetFoodRecomended/queries.js +47 -47
- package/src/hooks/useGetMinPrice/index.js +12 -12
- package/src/hooks/useGetMinPrice/queries.js +7 -7
- package/src/hooks/useGetOneStoreRating/index.js +40 -40
- package/src/hooks/useGetOneStoreRating/queries.js +18 -18
- package/src/hooks/useGoogleLogin/index.js +160 -160
- package/src/hooks/useGoogleLogin/loadScript.js +15 -15
- package/src/hooks/useGoogleLogin/removeScript.js +7 -7
- package/src/hooks/useHover/index.js +29 -29
- package/src/hooks/useImagesStore/index.js +5 -4
- package/src/hooks/useInnerHtml/index.js +39 -39
- package/src/hooks/useKeypress/index.js +28 -28
- package/src/hooks/useLocationNavigate/index.js +54 -54
- package/src/hooks/useLogout/index.js +29 -21
- package/src/hooks/useManageQueryParams/index.js +37 -36
- package/src/hooks/useMobile/index.js +39 -39
- package/src/hooks/useOrderClient/index.js +5 -5
- package/src/hooks/useProviders/index.js +3 -3
- package/src/hooks/useProviders/queries.js +31 -31
- package/src/hooks/useProviders/useProvidersCreateStore/index.js +12 -12
- 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 -54
- package/src/hooks/useRatingArrayData/queries.js +19 -19
- package/src/hooks/useRemoveExtraProductFoodsOptional/index.js +23 -23
- package/src/hooks/useRemoveExtraProductFoodsOptional/queries.js +48 -48
- package/src/hooks/useRestaurant/index.js +19 -19
- package/src/hooks/useRestaurant/queries.js +80 -80
- package/src/hooks/useSales/useGetAllSales/index.js +25 -25
- package/src/hooks/useSchedule/index.js +72 -72
- package/src/hooks/useSchedule/index.jsx +22 -22
- package/src/hooks/useSchedule/queries.js +43 -43
- package/src/hooks/useScheduleData/index.js +123 -123
- package/src/hooks/useScroll/index.js +56 -56
- package/src/hooks/useScrollRotate/index.js +16 -16
- package/src/hooks/useStatusOpenStore/helpers/index.js +101 -101
- package/src/hooks/useStatusOpenStore/index.js +172 -172
- package/src/hooks/useStatusOrdersClient/queries.js +80 -80
- package/src/hooks/useStore/queries.js +163 -163
- package/src/hooks/useStoreCalendar/index.js +5 -5
- package/src/hooks/useStoreContacts/queries.js +1 -1
- package/src/hooks/useTimeAgo/useTimeAgo.js +39 -39
- package/src/hooks/useUpdateExtProductFoodsSubOptional/index.js +38 -38
- package/src/hooks/useWindowSize/index.js +38 -38
- package/src/mock/dessert/index.js +16 -16
- package/src/mock/index.js +1 -1
- package/.vscode/extensions.json +0 -6
- package/.vscode/settings.json +0 -8
|
@@ -1,199 +1,199 @@
|
|
|
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'
|
|
5
|
-
|
|
6
|
-
// Función para calcular el total de ventas por mes
|
|
7
|
-
const calculateSalesByMonth = (salesData) => {
|
|
8
|
-
try {
|
|
9
|
-
const result = Array.from({ length: 12 }, (_, mes) => ({
|
|
10
|
-
Mes: mes,
|
|
11
|
-
Year: new Date().getFullYear(),
|
|
12
|
-
totalProductsPrice: 0
|
|
13
|
-
}))
|
|
14
|
-
|
|
15
|
-
salesData?.forEach((value) => {
|
|
16
|
-
const mes = new Date(value.pDatCre).getMonth()
|
|
17
|
-
result[mes].totalProductsPrice += value.totalProductsPrice
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
return result
|
|
21
|
-
} catch (error) {
|
|
22
|
-
return []
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// Función para llenar los meses faltantes
|
|
27
|
-
const fillMissingMonths = (data) => {
|
|
28
|
-
try {
|
|
29
|
-
const allMonths = Array.from({ length: 12 }, (_, i) => i)
|
|
30
|
-
const missingMonths = allMonths.filter(month => !data.some(data => data.Mes === month))
|
|
31
|
-
return data.concat(
|
|
32
|
-
missingMonths.map(element => ({
|
|
33
|
-
Mes: element,
|
|
34
|
-
totalProductsPrice: 0,
|
|
35
|
-
Year: ''
|
|
36
|
-
}))
|
|
37
|
-
).sort((a, b) => a.Mes - b.Mes)
|
|
38
|
-
} catch (error) {
|
|
39
|
-
return []
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
// eslint-disable-next-line prefer-const
|
|
43
|
-
let chartTypeYear = ''
|
|
44
|
-
// Función para obtener los datos del gráfico
|
|
45
|
-
const getChartData = (asFilter, newResult, result, chartType) => ({
|
|
46
|
-
labels: asFilter
|
|
47
|
-
? newResult.map(data => SPANISH_MONTHS[data.Mes])
|
|
48
|
-
: result.map(data => SPANISH_MONTHS[data.Mes]),
|
|
49
|
-
datasets: [
|
|
50
|
-
{
|
|
51
|
-
label: `Ventas por meses del año ${asFilter ? chartTypeYear : ''}`,
|
|
52
|
-
data: asFilter
|
|
53
|
-
? newResult.map(data => data.totalProductsPrice)
|
|
54
|
-
: result.map(data => data.totalProductsPrice),
|
|
55
|
-
backgroundColor: [
|
|
56
|
-
'rgba(255, 99, 132, 0.2)',
|
|
57
|
-
'rgba(54, 162, 235, 0.2)',
|
|
58
|
-
'rgba(255, 206, 86, 0.2)',
|
|
59
|
-
'rgba(75, 192, 192, 0.2)',
|
|
60
|
-
'rgba(153, 102, 255, 0.2)',
|
|
61
|
-
'rgba(255, 159, 64, 0.2)'
|
|
62
|
-
],
|
|
63
|
-
borderColor: chartType === 'bar'
|
|
64
|
-
? [
|
|
65
|
-
'rgba(255, 99, 132, 1)',
|
|
66
|
-
'rgba(54, 162, 235, 1)',
|
|
67
|
-
'rgba(255, 206, 86, 1)',
|
|
68
|
-
'rgba(75, 192, 192, 1)',
|
|
69
|
-
'rgba(153, 102, 255, 1)',
|
|
70
|
-
'rgba(255, 159, 64, 1)'
|
|
71
|
-
]
|
|
72
|
-
: 'rgb(255 0 0)',
|
|
73
|
-
tension: 0.6,
|
|
74
|
-
fill: false,
|
|
75
|
-
borderWidth: 1,
|
|
76
|
-
barPercentage: 1,
|
|
77
|
-
barThickness: 50,
|
|
78
|
-
minBarLength: 3
|
|
79
|
-
}
|
|
80
|
-
]
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
// Función para agrupar los datos por año
|
|
84
|
-
const groupSalesByYear = (salesData = []) => {
|
|
85
|
-
const groupedData = {}
|
|
86
|
-
try {
|
|
87
|
-
salesData?.forEach((item) => {
|
|
88
|
-
const year = new Date(item.pDatCre).getFullYear()
|
|
89
|
-
if (!groupedData[year]) {
|
|
90
|
-
groupedData[year] = []
|
|
91
|
-
}
|
|
92
|
-
groupedData[year].push(item)
|
|
93
|
-
})
|
|
94
|
-
return groupedData
|
|
95
|
-
} catch (error) {
|
|
96
|
-
return groupedData
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// Función para obtener años únicos
|
|
101
|
-
const getUniqueYears = (salesData = []) => {
|
|
102
|
-
try {
|
|
103
|
-
const years = []
|
|
104
|
-
salesData?.forEach((item) => {
|
|
105
|
-
const y = new Date(item.pDatCre).getFullYear()
|
|
106
|
-
if (!years.includes(y)) {
|
|
107
|
-
years.push(y)
|
|
108
|
-
}
|
|
109
|
-
})
|
|
110
|
-
return years.sort((a, b) => b - a)
|
|
111
|
-
} catch (error) {
|
|
112
|
-
return []
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
export const useChartData = ({ year }) => {
|
|
117
|
-
const { data, loading } = useQuery(GET_ALL_SALES)
|
|
118
|
-
const [chartType, setChartType] = useState('Line')
|
|
119
|
-
const [chartTypeYear, setChartTypeYear] = useState(new Date().getFullYear())
|
|
120
|
-
const [asFilter, setFilter] = useState(false)
|
|
121
|
-
const [newResult, setNewResult] = useState([])
|
|
122
|
-
|
|
123
|
-
const result = calculateSalesByMonth(data?.getAllSalesStore)
|
|
124
|
-
|
|
125
|
-
const filledResult = fillMissingMonths(result)
|
|
126
|
-
|
|
127
|
-
const dataChart = getChartData(asFilter, newResult, filledResult, chartType)
|
|
128
|
-
|
|
129
|
-
// eslint-disable-next-line no-unused-vars
|
|
130
|
-
const groupedData = groupSalesByYear(data?.getAllSalesStore)
|
|
131
|
-
const years = getUniqueYears(data?.getAllSalesStore)
|
|
132
|
-
|
|
133
|
-
const handleChangeYear = (value) => {
|
|
134
|
-
setFilter(true)
|
|
135
|
-
const currentYear = parseInt(value)
|
|
136
|
-
setChartTypeYear(currentYear || '')
|
|
137
|
-
|
|
138
|
-
if (filledResult?.length > 0) {
|
|
139
|
-
const filterToYear = filledResult.filter((elem) => elem?.Year === currentYear)
|
|
140
|
-
// eslint-disable-next-line no-undef
|
|
141
|
-
const missingNewMonths = allMonths?.filter(month => !filterToYear.some(data => data.Mes === month))
|
|
142
|
-
|
|
143
|
-
const newFilteredResult = filterToYear.concat(
|
|
144
|
-
missingNewMonths.map(element => ({
|
|
145
|
-
Mes: element,
|
|
146
|
-
totalProductsPrice: 0,
|
|
147
|
-
Year: ''
|
|
148
|
-
}))
|
|
149
|
-
).sort((a, b) => a.Mes - b.Mes)
|
|
150
|
-
|
|
151
|
-
setNewResult(newFilteredResult)
|
|
152
|
-
return newFilteredResult
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
const cleanFilter = () => {
|
|
157
|
-
setFilter(false)
|
|
158
|
-
setChartTypeYear(new Date().getFullYear())
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
const sortYear = () => years.sort((a, b) => b - a)
|
|
162
|
-
const labelTitle = `Ventas por meses del año ${asFilter ? chartTypeYear : ''}`
|
|
163
|
-
const organiceYears = sortYear()
|
|
164
|
-
const options = {
|
|
165
|
-
interaction: {
|
|
166
|
-
mode: 'index',
|
|
167
|
-
intersect: false
|
|
168
|
-
},
|
|
169
|
-
scales: {
|
|
170
|
-
x: {
|
|
171
|
-
stacked: true
|
|
172
|
-
},
|
|
173
|
-
y: {
|
|
174
|
-
stacked: true
|
|
175
|
-
}
|
|
176
|
-
},
|
|
177
|
-
plugins: {
|
|
178
|
-
title: {
|
|
179
|
-
display: true,
|
|
180
|
-
text: labelTitle
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
return {
|
|
185
|
-
handleChangeYear,
|
|
186
|
-
setFilter,
|
|
187
|
-
cleanFilter,
|
|
188
|
-
setChartType,
|
|
189
|
-
years: organiceYears,
|
|
190
|
-
asFilter,
|
|
191
|
-
chartTypeYear,
|
|
192
|
-
options,
|
|
193
|
-
chartType,
|
|
194
|
-
labelTitle,
|
|
195
|
-
result: filledResult,
|
|
196
|
-
dataChart,
|
|
197
|
-
loading
|
|
198
|
-
}
|
|
199
|
-
}
|
|
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'
|
|
5
|
+
|
|
6
|
+
// Función para calcular el total de ventas por mes
|
|
7
|
+
const calculateSalesByMonth = (salesData) => {
|
|
8
|
+
try {
|
|
9
|
+
const result = Array.from({ length: 12 }, (_, mes) => ({
|
|
10
|
+
Mes: mes,
|
|
11
|
+
Year: new Date().getFullYear(),
|
|
12
|
+
totalProductsPrice: 0
|
|
13
|
+
}))
|
|
14
|
+
|
|
15
|
+
salesData?.forEach((value) => {
|
|
16
|
+
const mes = new Date(value.pDatCre).getMonth()
|
|
17
|
+
result[mes].totalProductsPrice += value.totalProductsPrice
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
return result
|
|
21
|
+
} catch (error) {
|
|
22
|
+
return []
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Función para llenar los meses faltantes
|
|
27
|
+
const fillMissingMonths = (data) => {
|
|
28
|
+
try {
|
|
29
|
+
const allMonths = Array.from({ length: 12 }, (_, i) => i)
|
|
30
|
+
const missingMonths = allMonths.filter(month => !data.some(data => data.Mes === month))
|
|
31
|
+
return data.concat(
|
|
32
|
+
missingMonths.map(element => ({
|
|
33
|
+
Mes: element,
|
|
34
|
+
totalProductsPrice: 0,
|
|
35
|
+
Year: ''
|
|
36
|
+
}))
|
|
37
|
+
).sort((a, b) => a.Mes - b.Mes)
|
|
38
|
+
} catch (error) {
|
|
39
|
+
return []
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
// eslint-disable-next-line prefer-const
|
|
43
|
+
let chartTypeYear = ''
|
|
44
|
+
// Función para obtener los datos del gráfico
|
|
45
|
+
const getChartData = (asFilter, newResult, result, chartType) => ({
|
|
46
|
+
labels: asFilter
|
|
47
|
+
? newResult.map(data => SPANISH_MONTHS[data.Mes])
|
|
48
|
+
: result.map(data => SPANISH_MONTHS[data.Mes]),
|
|
49
|
+
datasets: [
|
|
50
|
+
{
|
|
51
|
+
label: `Ventas por meses del año ${asFilter ? chartTypeYear : ''}`,
|
|
52
|
+
data: asFilter
|
|
53
|
+
? newResult.map(data => data.totalProductsPrice)
|
|
54
|
+
: result.map(data => data.totalProductsPrice),
|
|
55
|
+
backgroundColor: [
|
|
56
|
+
'rgba(255, 99, 132, 0.2)',
|
|
57
|
+
'rgba(54, 162, 235, 0.2)',
|
|
58
|
+
'rgba(255, 206, 86, 0.2)',
|
|
59
|
+
'rgba(75, 192, 192, 0.2)',
|
|
60
|
+
'rgba(153, 102, 255, 0.2)',
|
|
61
|
+
'rgba(255, 159, 64, 0.2)'
|
|
62
|
+
],
|
|
63
|
+
borderColor: chartType === 'bar'
|
|
64
|
+
? [
|
|
65
|
+
'rgba(255, 99, 132, 1)',
|
|
66
|
+
'rgba(54, 162, 235, 1)',
|
|
67
|
+
'rgba(255, 206, 86, 1)',
|
|
68
|
+
'rgba(75, 192, 192, 1)',
|
|
69
|
+
'rgba(153, 102, 255, 1)',
|
|
70
|
+
'rgba(255, 159, 64, 1)'
|
|
71
|
+
]
|
|
72
|
+
: 'rgb(255 0 0)',
|
|
73
|
+
tension: 0.6,
|
|
74
|
+
fill: false,
|
|
75
|
+
borderWidth: 1,
|
|
76
|
+
barPercentage: 1,
|
|
77
|
+
barThickness: 50,
|
|
78
|
+
minBarLength: 3
|
|
79
|
+
}
|
|
80
|
+
]
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
// Función para agrupar los datos por año
|
|
84
|
+
const groupSalesByYear = (salesData = []) => {
|
|
85
|
+
const groupedData = {}
|
|
86
|
+
try {
|
|
87
|
+
salesData?.forEach((item) => {
|
|
88
|
+
const year = new Date(item.pDatCre).getFullYear()
|
|
89
|
+
if (!groupedData[year]) {
|
|
90
|
+
groupedData[year] = []
|
|
91
|
+
}
|
|
92
|
+
groupedData[year].push(item)
|
|
93
|
+
})
|
|
94
|
+
return groupedData
|
|
95
|
+
} catch (error) {
|
|
96
|
+
return groupedData
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Función para obtener años únicos
|
|
101
|
+
const getUniqueYears = (salesData = []) => {
|
|
102
|
+
try {
|
|
103
|
+
const years = []
|
|
104
|
+
salesData?.forEach((item) => {
|
|
105
|
+
const y = new Date(item.pDatCre).getFullYear()
|
|
106
|
+
if (!years.includes(y)) {
|
|
107
|
+
years.push(y)
|
|
108
|
+
}
|
|
109
|
+
})
|
|
110
|
+
return years.sort((a, b) => b - a)
|
|
111
|
+
} catch (error) {
|
|
112
|
+
return []
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export const useChartData = ({ year }) => {
|
|
117
|
+
const { data, loading } = useQuery(GET_ALL_SALES)
|
|
118
|
+
const [chartType, setChartType] = useState('Line')
|
|
119
|
+
const [chartTypeYear, setChartTypeYear] = useState(new Date().getFullYear())
|
|
120
|
+
const [asFilter, setFilter] = useState(false)
|
|
121
|
+
const [newResult, setNewResult] = useState([])
|
|
122
|
+
|
|
123
|
+
const result = calculateSalesByMonth(data?.getAllSalesStore)
|
|
124
|
+
|
|
125
|
+
const filledResult = fillMissingMonths(result)
|
|
126
|
+
|
|
127
|
+
const dataChart = getChartData(asFilter, newResult, filledResult, chartType)
|
|
128
|
+
|
|
129
|
+
// eslint-disable-next-line no-unused-vars
|
|
130
|
+
const groupedData = groupSalesByYear(data?.getAllSalesStore)
|
|
131
|
+
const years = getUniqueYears(data?.getAllSalesStore)
|
|
132
|
+
|
|
133
|
+
const handleChangeYear = (value) => {
|
|
134
|
+
setFilter(true)
|
|
135
|
+
const currentYear = parseInt(value)
|
|
136
|
+
setChartTypeYear(currentYear || '')
|
|
137
|
+
|
|
138
|
+
if (filledResult?.length > 0) {
|
|
139
|
+
const filterToYear = filledResult.filter((elem) => elem?.Year === currentYear)
|
|
140
|
+
// eslint-disable-next-line no-undef
|
|
141
|
+
const missingNewMonths = allMonths?.filter(month => !filterToYear.some(data => data.Mes === month))
|
|
142
|
+
|
|
143
|
+
const newFilteredResult = filterToYear.concat(
|
|
144
|
+
missingNewMonths.map(element => ({
|
|
145
|
+
Mes: element,
|
|
146
|
+
totalProductsPrice: 0,
|
|
147
|
+
Year: ''
|
|
148
|
+
}))
|
|
149
|
+
).sort((a, b) => a.Mes - b.Mes)
|
|
150
|
+
|
|
151
|
+
setNewResult(newFilteredResult)
|
|
152
|
+
return newFilteredResult
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const cleanFilter = () => {
|
|
157
|
+
setFilter(false)
|
|
158
|
+
setChartTypeYear(new Date().getFullYear())
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const sortYear = () => years.sort((a, b) => b - a)
|
|
162
|
+
const labelTitle = `Ventas por meses del año ${asFilter ? chartTypeYear : ''}`
|
|
163
|
+
const organiceYears = sortYear()
|
|
164
|
+
const options = {
|
|
165
|
+
interaction: {
|
|
166
|
+
mode: 'index',
|
|
167
|
+
intersect: false
|
|
168
|
+
},
|
|
169
|
+
scales: {
|
|
170
|
+
x: {
|
|
171
|
+
stacked: true
|
|
172
|
+
},
|
|
173
|
+
y: {
|
|
174
|
+
stacked: true
|
|
175
|
+
}
|
|
176
|
+
},
|
|
177
|
+
plugins: {
|
|
178
|
+
title: {
|
|
179
|
+
display: true,
|
|
180
|
+
text: labelTitle
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return {
|
|
185
|
+
handleChangeYear,
|
|
186
|
+
setFilter,
|
|
187
|
+
cleanFilter,
|
|
188
|
+
setChartType,
|
|
189
|
+
years: organiceYears,
|
|
190
|
+
asFilter,
|
|
191
|
+
chartTypeYear,
|
|
192
|
+
options,
|
|
193
|
+
chartType,
|
|
194
|
+
labelTitle,
|
|
195
|
+
result: filledResult,
|
|
196
|
+
dataChart,
|
|
197
|
+
loading
|
|
198
|
+
}
|
|
199
|
+
}
|
|
@@ -1,94 +1,94 @@
|
|
|
1
|
-
import { useGetAllSales } from '../../useSales/useGetAllSales'
|
|
2
|
-
|
|
3
|
-
export const useChartDataAllOrders = ({
|
|
4
|
-
onScreen = false
|
|
5
|
-
} = {}) => {
|
|
6
|
-
const { data, loading } = useGetAllSales({
|
|
7
|
-
onScreen
|
|
8
|
-
})
|
|
9
|
-
|
|
10
|
-
// Objeto para mapear los códigos de estado a sus nombres
|
|
11
|
-
const statusMap = {
|
|
12
|
-
1: 'ACEPTA',
|
|
13
|
-
2: 'PROCESSING',
|
|
14
|
-
3: 'READY',
|
|
15
|
-
4: 'CONCLUDES',
|
|
16
|
-
5: 'RECHAZADOS'
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
// Objeto para almacenar los totales por estado
|
|
20
|
-
const totalsByStatus = {}
|
|
21
|
-
|
|
22
|
-
// Inicializar totales en 0 para todos los estados
|
|
23
|
-
for (const status in statusMap) {
|
|
24
|
-
totalsByStatus[status] = 0
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// Procesar los datos y acumular los totales por estado
|
|
28
|
-
data?.forEach(item => {
|
|
29
|
-
const status = item.pSState
|
|
30
|
-
const totalPrice = item.totalProductsPrice
|
|
31
|
-
totalsByStatus[status] += totalPrice
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
// Preparar los datos en el formato requerido por Chart.js
|
|
35
|
-
const chartLabels = []
|
|
36
|
-
const chartData = []
|
|
37
|
-
|
|
38
|
-
// Iterar a través del statusMap para llenar los datos
|
|
39
|
-
for (const status in statusMap) {
|
|
40
|
-
const statusLabel = statusMap[status]
|
|
41
|
-
chartLabels?.push(statusLabel)
|
|
42
|
-
chartData?.push(totalsByStatus[status] || 0)
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const chartJsData = {
|
|
46
|
-
labels: chartLabels,
|
|
47
|
-
datasets: [{
|
|
48
|
-
tension: 2,
|
|
49
|
-
fill: false,
|
|
50
|
-
borderWidth: 1,
|
|
51
|
-
barPercentage: 1,
|
|
52
|
-
barThickness: 50,
|
|
53
|
-
minBarLength: 3,
|
|
54
|
-
label: '',
|
|
55
|
-
data: chartData,
|
|
56
|
-
backgroundColor: [
|
|
57
|
-
'#FF5733', // Reddish color
|
|
58
|
-
'#FFC300', // Yellowish color
|
|
59
|
-
'#FF8C42', // Orange color
|
|
60
|
-
'#138D75', // Gold color
|
|
61
|
-
'#ff0000' // Tomato color
|
|
62
|
-
]
|
|
63
|
-
}]
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const defaultOptions = {
|
|
67
|
-
animation: {
|
|
68
|
-
animateRotate: true,
|
|
69
|
-
animateScale: true
|
|
70
|
-
},
|
|
71
|
-
responsive: true,
|
|
72
|
-
maintainAspectRatio: false,
|
|
73
|
-
legend: {
|
|
74
|
-
position: 'bottom'
|
|
75
|
-
},
|
|
76
|
-
tooltips: {
|
|
77
|
-
callbacks: {
|
|
78
|
-
label: (tooltipItem, data) => {
|
|
79
|
-
const dataset = data?.datasets[tooltipItem.datasetIndex]
|
|
80
|
-
const total = dataset?.data?.reduce((previousValue, currentValue) => previousValue + currentValue)
|
|
81
|
-
const currentValue = dataset?.data[tooltipItem?.index]
|
|
82
|
-
const percentage = ((currentValue / total) * 100).toFixed(2)
|
|
83
|
-
return `${data?.labels[tooltipItem?.index]}: ${currentValue} (${percentage}%)`
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return {
|
|
90
|
-
loading,
|
|
91
|
-
data: loading ? [] : chartJsData,
|
|
92
|
-
option: loading ? [] : defaultOptions
|
|
93
|
-
}
|
|
94
|
-
}
|
|
1
|
+
import { useGetAllSales } from '../../useSales/useGetAllSales'
|
|
2
|
+
|
|
3
|
+
export const useChartDataAllOrders = ({
|
|
4
|
+
onScreen = false
|
|
5
|
+
} = {}) => {
|
|
6
|
+
const { data, loading } = useGetAllSales({
|
|
7
|
+
onScreen
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
// Objeto para mapear los códigos de estado a sus nombres
|
|
11
|
+
const statusMap = {
|
|
12
|
+
1: 'ACEPTA',
|
|
13
|
+
2: 'PROCESSING',
|
|
14
|
+
3: 'READY',
|
|
15
|
+
4: 'CONCLUDES',
|
|
16
|
+
5: 'RECHAZADOS'
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Objeto para almacenar los totales por estado
|
|
20
|
+
const totalsByStatus = {}
|
|
21
|
+
|
|
22
|
+
// Inicializar totales en 0 para todos los estados
|
|
23
|
+
for (const status in statusMap) {
|
|
24
|
+
totalsByStatus[status] = 0
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Procesar los datos y acumular los totales por estado
|
|
28
|
+
data?.forEach(item => {
|
|
29
|
+
const status = item.pSState
|
|
30
|
+
const totalPrice = item.totalProductsPrice
|
|
31
|
+
totalsByStatus[status] += totalPrice
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
// Preparar los datos en el formato requerido por Chart.js
|
|
35
|
+
const chartLabels = []
|
|
36
|
+
const chartData = []
|
|
37
|
+
|
|
38
|
+
// Iterar a través del statusMap para llenar los datos
|
|
39
|
+
for (const status in statusMap) {
|
|
40
|
+
const statusLabel = statusMap[status]
|
|
41
|
+
chartLabels?.push(statusLabel)
|
|
42
|
+
chartData?.push(totalsByStatus[status] || 0)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const chartJsData = {
|
|
46
|
+
labels: chartLabels,
|
|
47
|
+
datasets: [{
|
|
48
|
+
tension: 2,
|
|
49
|
+
fill: false,
|
|
50
|
+
borderWidth: 1,
|
|
51
|
+
barPercentage: 1,
|
|
52
|
+
barThickness: 50,
|
|
53
|
+
minBarLength: 3,
|
|
54
|
+
label: '',
|
|
55
|
+
data: chartData,
|
|
56
|
+
backgroundColor: [
|
|
57
|
+
'#FF5733', // Reddish color
|
|
58
|
+
'#FFC300', // Yellowish color
|
|
59
|
+
'#FF8C42', // Orange color
|
|
60
|
+
'#138D75', // Gold color
|
|
61
|
+
'#ff0000' // Tomato color
|
|
62
|
+
]
|
|
63
|
+
}]
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const defaultOptions = {
|
|
67
|
+
animation: {
|
|
68
|
+
animateRotate: true,
|
|
69
|
+
animateScale: true
|
|
70
|
+
},
|
|
71
|
+
responsive: true,
|
|
72
|
+
maintainAspectRatio: false,
|
|
73
|
+
legend: {
|
|
74
|
+
position: 'bottom'
|
|
75
|
+
},
|
|
76
|
+
tooltips: {
|
|
77
|
+
callbacks: {
|
|
78
|
+
label: (tooltipItem, data) => {
|
|
79
|
+
const dataset = data?.datasets[tooltipItem.datasetIndex]
|
|
80
|
+
const total = dataset?.data?.reduce((previousValue, currentValue) => previousValue + currentValue)
|
|
81
|
+
const currentValue = dataset?.data[tooltipItem?.index]
|
|
82
|
+
const percentage = ((currentValue / total) * 100).toFixed(2)
|
|
83
|
+
return `${data?.labels[tooltipItem?.index]}: ${currentValue} (${percentage}%)`
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return {
|
|
90
|
+
loading,
|
|
91
|
+
data: loading ? [] : chartJsData,
|
|
92
|
+
option: loading ? [] : defaultOptions
|
|
93
|
+
}
|
|
94
|
+
}
|