npm-pkg-hook 1.1.0 → 1.1.3
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 +132 -132
- package/next.config.js +0 -1
- package/package.json +46 -43
- package/src/config/client/errors.js +2 -1
- package/src/hooks/getSession/index.js +18 -0
- package/src/hooks/index.js +27 -7
- package/src/hooks/useAnimationFrame/index.js +45 -0
- package/src/hooks/useAnimationText/index.jsx +11 -13
- package/src/hooks/useCatWithProduct/index.js +37 -4
- package/src/hooks/useCatWithProduct/queries.js +0 -16
- package/src/hooks/useCategoriesProduct/index.js +12 -0
- package/src/hooks/useCategoriesProduct/queries.js +16 -0
- package/src/hooks/useChartData/index.js +2 -169
- package/src/hooks/useChartData/useChartData/index.js +197 -0
- package/src/hooks/useChartData/useChartDataAllOrders/index.js +89 -0
- package/src/hooks/useCheckbox/index.js +5 -1
- package/src/hooks/useClients/index.js +17 -8
- package/src/hooks/useCreateProduct/index.js +95 -65
- package/src/hooks/useDeleteSubProductOptional/index.js +30 -0
- package/src/hooks/useDeleteSubProductOptional/queries.js +10 -0
- package/src/hooks/useDessert/helpers/index.js +51 -0
- package/src/hooks/useDessert/index.js +319 -121
- package/src/hooks/useDevices/index.js +36 -0
- package/src/hooks/useDevices/queries.js +19 -0
- package/src/hooks/useDrag/index.js +1 -1
- package/src/hooks/useDropzone/index.js +79 -0
- package/src/hooks/useDynamicAuth/index.js +13 -0
- package/src/hooks/useDynamicAuth/queries.js +24 -0
- package/src/hooks/useEmployee/index.js +11 -8
- package/src/hooks/useFingerprintjs/index.js +176 -0
- package/src/hooks/useFormTools/index.js +1 -1
- package/src/hooks/useFullScreenMode/index.js +8 -9
- package/src/hooks/useGenerateNumberArray/index.js +17 -0
- package/src/hooks/useImagesStore/index.js +176 -143
- package/src/hooks/useImagesStore/queries.js +1 -28
- package/src/hooks/useKeypress/index.js +7 -1
- package/src/hooks/useLocalSorage/index.js +1 -1
- package/src/hooks/useLogout/index.js +22 -25
- package/src/hooks/useManageQueryParams/index.js +37 -0
- package/src/hooks/useProductsFood/queriesStore.js +3 -16
- package/src/hooks/useProductsFood/usetagsProducts.js +30 -5
- package/src/hooks/useProviders/index.js +3 -0
- package/src/hooks/useProviders/queries.js +31 -0
- package/src/hooks/useProviders/useProvidersCreateStore/index.js +13 -0
- package/src/hooks/useProviders/useProvidersDataStore/index.js +24 -0
- package/src/hooks/useProvidersStore/index.js +24 -0
- package/src/hooks/useProvidersStore/queries.js +31 -0
- package/src/hooks/useRatingData/index.js +53 -0
- package/src/hooks/useRatingData/queries.js +18 -0
- package/src/hooks/useRemoveExtraProductFoodsOptional/index.js +23 -0
- package/src/hooks/useRemoveExtraProductFoodsOptional/queries.js +48 -0
- package/src/hooks/useReport/index.js +16 -7
- package/src/hooks/useReport/queries.js +47 -32
- package/src/hooks/useSales/index.js +53 -22
- package/src/hooks/useSales/queries.js +48 -38
- package/src/hooks/useSales/useGetAllSales/index.js +25 -0
- package/src/hooks/useSales/useGetSale.js +16 -2
- package/src/hooks/useSchedule/index.js +36 -0
- package/src/hooks/useSchedule/queries.js +35 -0
- package/src/hooks/useScheduleData/index.js +171 -0
- package/src/hooks/useScroll/index.js +57 -0
- package/src/hooks/useScrollRotate/index.js +14 -0
- package/src/hooks/useStatusOpenStore/helpers/index.js +102 -0
- package/src/hooks/useStatusOpenStore/index.js +173 -0
- package/src/hooks/useStoreContacts/index.js +5 -1
- package/src/hooks/useUpdateExistingOrders/index.js +8 -8
- package/src/hooks/useUser/index.js +7 -2
- package/src/hooks/useUser/queries.js +40 -0
- package/src/index.jsx +3 -1
- package/.vscode/extensions.json +0 -6
- package/.vscode/settings.json +0 -8
- package/src/hooks/useSchedule/index.jsx +0 -23
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { gql } from "@apollo/client";
|
|
2
|
+
|
|
3
|
+
export const GET_ULTIMATE_CATEGORY_PRODUCTS = gql`
|
|
4
|
+
query catProductsAll($search: String, $min: Int, $max: Int, $gender: [String], $desc: [String], $categories: [ID], ) {
|
|
5
|
+
catProductsAll(search: $search, min: $min, max: $max, gender: $gender, desc: $desc, categories: $categories,) {
|
|
6
|
+
carProId
|
|
7
|
+
idStore
|
|
8
|
+
pName
|
|
9
|
+
ProDescription
|
|
10
|
+
ProImage
|
|
11
|
+
pState
|
|
12
|
+
pDatCre
|
|
13
|
+
pDatMod
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
`
|
|
@@ -1,169 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { SPANISH_MONTHS } from "../../utils/index";
|
|
4
|
-
import { GET_ALL_SALES } from "../useReport/queries";
|
|
5
|
-
|
|
6
|
-
export const useChartData = ({ year }) => {
|
|
7
|
-
// Construcción del nuevo array:
|
|
8
|
-
const { data, loading } = useQuery(GET_ALL_SALES)
|
|
9
|
-
const [chartType, setChartType] = useState('bar')
|
|
10
|
-
const [chartTypeYear, setChartTypeYear] = useState(new Date().getFullYear())
|
|
11
|
-
const [asFilter, setFilter] = useState(false)
|
|
12
|
-
const [newResult, setNewResult] = useState([])
|
|
13
|
-
let result = []
|
|
14
|
-
data?.getAllSalesStore?.length > 0 && data?.getAllSalesStore.reduce(function (res, value) {
|
|
15
|
-
// Creamos la posición del array para cada mes
|
|
16
|
-
let mes = new Date(value.pDatCre).getMonth()
|
|
17
|
-
let Year = new Date(value.pDatCre).getFullYear()
|
|
18
|
-
if (!res[mes]) {
|
|
19
|
-
res[mes] = { Mes: mes, Year }
|
|
20
|
-
// Inicializamos a 0 el valor de cada key
|
|
21
|
-
Object.keys(value).forEach((key) => {
|
|
22
|
-
if (key != 'pDatCre') {
|
|
23
|
-
res[mes][key] = 0
|
|
24
|
-
}
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
result.push(res[mes])
|
|
28
|
-
}
|
|
29
|
-
// Sumamos el valor de cada clave dentro de un bucle
|
|
30
|
-
Object.keys(value).forEach(function (key) {
|
|
31
|
-
if (key != 'pDatCre') {
|
|
32
|
-
res[mes]['totalProductsPrice'] += value['totalProductsPrice']
|
|
33
|
-
}
|
|
34
|
-
})
|
|
35
|
-
return res
|
|
36
|
-
}, {})
|
|
37
|
-
|
|
38
|
-
let allMonths = Array.from({ length: 12 }, (_, i) => { return i })
|
|
39
|
-
let missingMonths = allMonths.filter(month => { return !result.some(data => { return data.Mes === month }) })
|
|
40
|
-
|
|
41
|
-
for (const element of missingMonths) {
|
|
42
|
-
result.push({
|
|
43
|
-
'Mes': element,
|
|
44
|
-
'totalProductsPrice': 0,
|
|
45
|
-
'Year': ''
|
|
46
|
-
})
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
result.sort((a, b) => { return a.Mes - b.Mes })
|
|
50
|
-
|
|
51
|
-
const labelTitle = `Ventas por meses del año ${asFilter ? chartTypeYear : ''}`
|
|
52
|
-
// Resultado:
|
|
53
|
-
const dataChart = {
|
|
54
|
-
labels: asFilter ? newResult.map(data => {
|
|
55
|
-
return SPANISH_MONTHS[data.Mes]
|
|
56
|
-
}) : result.map(data => {
|
|
57
|
-
return SPANISH_MONTHS[data.Mes]
|
|
58
|
-
}),
|
|
59
|
-
datasets: [
|
|
60
|
-
{
|
|
61
|
-
label: labelTitle,
|
|
62
|
-
data: asFilter ? newResult.map(data => { return data.totalProductsPrice }) : result.map(data => { return data.totalProductsPrice }),
|
|
63
|
-
backgroundColor: [
|
|
64
|
-
'rgba(255, 99, 132, 0.2)',
|
|
65
|
-
'rgba(54, 162, 235, 0.2)',
|
|
66
|
-
'rgba(255, 206, 86, 0.2)',
|
|
67
|
-
'rgba(75, 192, 192, 0.2)',
|
|
68
|
-
'rgba(153, 102, 255, 0.2)',
|
|
69
|
-
'rgba(255, 159, 64, 0.2)'
|
|
70
|
-
],
|
|
71
|
-
borderColor: chartType === 'bar' ? [
|
|
72
|
-
'rgba(255, 99, 132, 1)',
|
|
73
|
-
'rgba(54, 162, 235, 1)',
|
|
74
|
-
'rgba(255, 206, 86, 1)',
|
|
75
|
-
'rgba(75, 192, 192, 1)',
|
|
76
|
-
'rgba(153, 102, 255, 1)',
|
|
77
|
-
'rgba(255, 159, 64, 1)'
|
|
78
|
-
] : 'rgb(255 0 0)',
|
|
79
|
-
tension: 0.6,
|
|
80
|
-
fill: false,
|
|
81
|
-
borderWidth: 1,
|
|
82
|
-
barPercentage: 1,
|
|
83
|
-
barThickness: 50,
|
|
84
|
-
minBarLength: 3,
|
|
85
|
-
}
|
|
86
|
-
]
|
|
87
|
-
}
|
|
88
|
-
const options = {
|
|
89
|
-
interaction: {
|
|
90
|
-
mode: 'index',
|
|
91
|
-
intersect: false,
|
|
92
|
-
},
|
|
93
|
-
scales: {
|
|
94
|
-
x: {
|
|
95
|
-
stacked: true
|
|
96
|
-
},
|
|
97
|
-
y: {
|
|
98
|
-
stacked: true
|
|
99
|
-
}
|
|
100
|
-
},
|
|
101
|
-
plugins: {
|
|
102
|
-
title: {
|
|
103
|
-
display: true,
|
|
104
|
-
text: labelTitle
|
|
105
|
-
},
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
const groupedData = {}
|
|
109
|
-
|
|
110
|
-
data && data.getAllSalesStore.forEach((item) => {
|
|
111
|
-
const year = new Date(item.pDatCre).getFullYear()
|
|
112
|
-
if (!groupedData[year]) {
|
|
113
|
-
groupedData[year] = []
|
|
114
|
-
}
|
|
115
|
-
groupedData[year].push(item)
|
|
116
|
-
})
|
|
117
|
-
const years = []
|
|
118
|
-
data && data.getAllSalesStore.forEach((item) => {
|
|
119
|
-
const y = new Date(item.pDatCre).getFullYear()
|
|
120
|
-
if (!years.includes(y)) {
|
|
121
|
-
years.push(y)
|
|
122
|
-
}
|
|
123
|
-
})
|
|
124
|
-
const handleChangeYear = (value) => {
|
|
125
|
-
setFilter(true)
|
|
126
|
-
const currentYear = parseInt(value)
|
|
127
|
-
setChartTypeYear(currentYear || '')
|
|
128
|
-
if (result?.length > 0) {
|
|
129
|
-
const filterToYear = result.filter((elem) => {
|
|
130
|
-
return elem?.Year == currentYear
|
|
131
|
-
})
|
|
132
|
-
let missingNewMonths = allMonths.filter(month => { return !filterToYear.some(data => { return data.Mes === month }) })
|
|
133
|
-
for (const element of missingNewMonths) {
|
|
134
|
-
filterToYear.push({
|
|
135
|
-
'Mes': element,
|
|
136
|
-
'totalProductsPrice': 0,
|
|
137
|
-
'Year': ''
|
|
138
|
-
})
|
|
139
|
-
}
|
|
140
|
-
filterToYear.sort((a, b) => { return a.Mes - b.Mes })
|
|
141
|
-
setNewResult(filterToYear)
|
|
142
|
-
return filterToYear
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
const cleanFilter = () => {
|
|
146
|
-
setFilter(false)
|
|
147
|
-
setChartTypeYear(new Date().getFullYear())
|
|
148
|
-
}
|
|
149
|
-
const sortYear = () => {
|
|
150
|
-
return years.sort((a, b) => { return b - a });
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
const organiceYears = sortYear()
|
|
154
|
-
return {
|
|
155
|
-
handleChangeYear,
|
|
156
|
-
setFilter,
|
|
157
|
-
cleanFilter,
|
|
158
|
-
setChartType,
|
|
159
|
-
years: organiceYears,
|
|
160
|
-
asFilter,
|
|
161
|
-
chartTypeYear,
|
|
162
|
-
options,
|
|
163
|
-
chartType,
|
|
164
|
-
labelTitle,
|
|
165
|
-
result,
|
|
166
|
-
dataChart,
|
|
167
|
-
loading
|
|
168
|
-
}
|
|
169
|
-
}
|
|
1
|
+
export * from './useChartData'
|
|
2
|
+
export * from './useChartDataAllOrders'
|
|
@@ -0,0 +1,197 @@
|
|
|
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
|
+
|
|
43
|
+
// Función para obtener los datos del gráfico
|
|
44
|
+
const getChartData = (asFilter, newResult, result, chartType) => ({
|
|
45
|
+
labels: asFilter
|
|
46
|
+
? newResult.map(data => SPANISH_MONTHS[data.Mes])
|
|
47
|
+
: result.map(data => SPANISH_MONTHS[data.Mes]),
|
|
48
|
+
datasets: [
|
|
49
|
+
{
|
|
50
|
+
label: `Ventas por meses del año ${asFilter ? chartTypeYear : ''}`,
|
|
51
|
+
data: asFilter
|
|
52
|
+
? newResult.map(data => data.totalProductsPrice)
|
|
53
|
+
: result.map(data => data.totalProductsPrice),
|
|
54
|
+
backgroundColor: [
|
|
55
|
+
'rgba(255, 99, 132, 0.2)',
|
|
56
|
+
'rgba(54, 162, 235, 0.2)',
|
|
57
|
+
'rgba(255, 206, 86, 0.2)',
|
|
58
|
+
'rgba(75, 192, 192, 0.2)',
|
|
59
|
+
'rgba(153, 102, 255, 0.2)',
|
|
60
|
+
'rgba(255, 159, 64, 0.2)'
|
|
61
|
+
],
|
|
62
|
+
borderColor: chartType === 'bar'
|
|
63
|
+
? [
|
|
64
|
+
'rgba(255, 99, 132, 1)',
|
|
65
|
+
'rgba(54, 162, 235, 1)',
|
|
66
|
+
'rgba(255, 206, 86, 1)',
|
|
67
|
+
'rgba(75, 192, 192, 1)',
|
|
68
|
+
'rgba(153, 102, 255, 1)',
|
|
69
|
+
'rgba(255, 159, 64, 1)'
|
|
70
|
+
]
|
|
71
|
+
: 'rgb(255 0 0)',
|
|
72
|
+
tension: 0.6,
|
|
73
|
+
fill: false,
|
|
74
|
+
borderWidth: 1,
|
|
75
|
+
barPercentage: 1,
|
|
76
|
+
barThickness: 50,
|
|
77
|
+
minBarLength: 3
|
|
78
|
+
}
|
|
79
|
+
]
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
// Función para agrupar los datos por año
|
|
83
|
+
const groupSalesByYear = (salesData = []) => {
|
|
84
|
+
const groupedData = {};
|
|
85
|
+
try {
|
|
86
|
+
salesData?.forEach((item) => {
|
|
87
|
+
const year = new Date(item.pDatCre).getFullYear();
|
|
88
|
+
if (!groupedData[year]) {
|
|
89
|
+
groupedData[year] = [];
|
|
90
|
+
}
|
|
91
|
+
groupedData[year].push(item);
|
|
92
|
+
});
|
|
93
|
+
return groupedData;
|
|
94
|
+
} catch (error) {
|
|
95
|
+
return groupedData
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
// Función para obtener años únicos
|
|
100
|
+
const getUniqueYears = (salesData = []) => {
|
|
101
|
+
try {
|
|
102
|
+
const years = [];
|
|
103
|
+
salesData?.forEach((item) => {
|
|
104
|
+
const y = new Date(item.pDatCre).getFullYear();
|
|
105
|
+
if (!years.includes(y)) {
|
|
106
|
+
years.push(y);
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
return years.sort((a, b) => b - a);
|
|
110
|
+
} catch (error) {
|
|
111
|
+
return []
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
export const useChartData = ({ year }) => {
|
|
116
|
+
const { data, loading } = useQuery(GET_ALL_SALES);
|
|
117
|
+
const [chartType, setChartType] = useState('Line');
|
|
118
|
+
const [chartTypeYear, setChartTypeYear] = useState(new Date().getFullYear());
|
|
119
|
+
const [asFilter, setFilter] = useState(false);
|
|
120
|
+
const [newResult, setNewResult] = useState([]);
|
|
121
|
+
|
|
122
|
+
const result = calculateSalesByMonth(data?.getAllSalesStore);
|
|
123
|
+
|
|
124
|
+
const filledResult = fillMissingMonths(result);
|
|
125
|
+
|
|
126
|
+
const dataChart = getChartData(asFilter, newResult, filledResult, chartType);
|
|
127
|
+
|
|
128
|
+
const groupedData = groupSalesByYear(data?.getAllSalesStore);
|
|
129
|
+
const years = getUniqueYears(data?.getAllSalesStore);
|
|
130
|
+
|
|
131
|
+
const handleChangeYear = (value) => {
|
|
132
|
+
setFilter(true);
|
|
133
|
+
const currentYear = parseInt(value);
|
|
134
|
+
setChartTypeYear(currentYear || '');
|
|
135
|
+
|
|
136
|
+
if (filledResult?.length > 0) {
|
|
137
|
+
const filterToYear = filledResult.filter((elem) => elem?.Year === currentYear);
|
|
138
|
+
const missingNewMonths = allMonths.filter(month => !filterToYear.some(data => data.Mes === month));
|
|
139
|
+
|
|
140
|
+
const newFilteredResult = filterToYear.concat(
|
|
141
|
+
missingNewMonths.map(element => ({
|
|
142
|
+
Mes: element,
|
|
143
|
+
totalProductsPrice: 0,
|
|
144
|
+
Year: '',
|
|
145
|
+
}))
|
|
146
|
+
).sort((a, b) => a.Mes - b.Mes);
|
|
147
|
+
|
|
148
|
+
setNewResult(newFilteredResult);
|
|
149
|
+
return newFilteredResult;
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
const cleanFilter = () => {
|
|
154
|
+
setFilter(false);
|
|
155
|
+
setChartTypeYear(new Date().getFullYear());
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
const sortYear = () => years.sort((a, b) => b - a);
|
|
159
|
+
const labelTitle = `Ventas por meses del año ${asFilter ? chartTypeYear : ''}`
|
|
160
|
+
const organiceYears = sortYear();
|
|
161
|
+
const options = {
|
|
162
|
+
interaction: {
|
|
163
|
+
mode: 'index',
|
|
164
|
+
intersect: false,
|
|
165
|
+
},
|
|
166
|
+
scales: {
|
|
167
|
+
x: {
|
|
168
|
+
stacked: true
|
|
169
|
+
},
|
|
170
|
+
y: {
|
|
171
|
+
stacked: true
|
|
172
|
+
}
|
|
173
|
+
},
|
|
174
|
+
plugins: {
|
|
175
|
+
title: {
|
|
176
|
+
display: true,
|
|
177
|
+
text: labelTitle
|
|
178
|
+
},
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return {
|
|
182
|
+
handleChangeYear,
|
|
183
|
+
setFilter,
|
|
184
|
+
cleanFilter,
|
|
185
|
+
setChartType,
|
|
186
|
+
years: organiceYears,
|
|
187
|
+
asFilter,
|
|
188
|
+
chartTypeYear,
|
|
189
|
+
options,
|
|
190
|
+
chartType,
|
|
191
|
+
labelTitle,
|
|
192
|
+
result: filledResult,
|
|
193
|
+
dataChart,
|
|
194
|
+
loading,
|
|
195
|
+
};
|
|
196
|
+
};
|
|
197
|
+
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { useGetAllSales } from "../../useSales/useGetAllSales"
|
|
2
|
+
|
|
3
|
+
export const useChartDataAllOrders = () => {
|
|
4
|
+
const { data, loading } = useGetAllSales({})
|
|
5
|
+
|
|
6
|
+
// Objeto para mapear los códigos de estado a sus nombres
|
|
7
|
+
const statusMap = {
|
|
8
|
+
1: 'ACEPTA',
|
|
9
|
+
2: 'PROCESSING',
|
|
10
|
+
3: 'READY',
|
|
11
|
+
4: 'CONCLUDES',
|
|
12
|
+
5: 'RECHAZADOS'
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
// Objeto para almacenar los totales por estado
|
|
16
|
+
const totalsByStatus = {};
|
|
17
|
+
|
|
18
|
+
// Inicializar totales en 0 para todos los estados
|
|
19
|
+
for (const status in statusMap) {
|
|
20
|
+
totalsByStatus[status] = 0;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Procesar los datos y acumular los totales por estado
|
|
24
|
+
data.forEach(item => {
|
|
25
|
+
const status = item.pSState;
|
|
26
|
+
const totalPrice = item.totalProductsPrice;
|
|
27
|
+
totalsByStatus[status] += totalPrice;
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
// Preparar los datos en el formato requerido por Chart.js
|
|
31
|
+
const chartLabels = [];
|
|
32
|
+
const chartData = [];
|
|
33
|
+
|
|
34
|
+
// Iterar a través del statusMap para llenar los datos
|
|
35
|
+
for (const status in statusMap) {
|
|
36
|
+
const statusLabel = statusMap[status];
|
|
37
|
+
chartLabels.push(statusLabel);
|
|
38
|
+
chartData.push(totalsByStatus[status] || 0);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const chartJsData = {
|
|
42
|
+
labels: chartLabels,
|
|
43
|
+
datasets: [{
|
|
44
|
+
tension: 2,
|
|
45
|
+
fill: false,
|
|
46
|
+
borderWidth: 1,
|
|
47
|
+
barPercentage: 1,
|
|
48
|
+
barThickness: 50,
|
|
49
|
+
minBarLength: 3,
|
|
50
|
+
label: '',
|
|
51
|
+
data: chartData,
|
|
52
|
+
backgroundColor: [
|
|
53
|
+
'#FF5733', // Reddish color
|
|
54
|
+
'#FFC300', // Yellowish color
|
|
55
|
+
'#FF8C42', // Orange color
|
|
56
|
+
'#138D75', // Gold color
|
|
57
|
+
'#ff0000', // Tomato color
|
|
58
|
+
],
|
|
59
|
+
}],
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const defaultOptions = {
|
|
63
|
+
animation: {
|
|
64
|
+
animateRotate: true,
|
|
65
|
+
animateScale: true,
|
|
66
|
+
},
|
|
67
|
+
responsive: true,
|
|
68
|
+
maintainAspectRatio: false,
|
|
69
|
+
legend: {
|
|
70
|
+
position: 'bottom',
|
|
71
|
+
},
|
|
72
|
+
tooltips: {
|
|
73
|
+
callbacks: {
|
|
74
|
+
label: (tooltipItem, data) => {
|
|
75
|
+
const dataset = data.datasets[tooltipItem.datasetIndex];
|
|
76
|
+
const total = dataset.data.reduce((previousValue, currentValue) => previousValue + currentValue);
|
|
77
|
+
const currentValue = dataset.data[tooltipItem.index];
|
|
78
|
+
const percentage = ((currentValue / total) * 100).toFixed(2);
|
|
79
|
+
return `${data.labels[tooltipItem.index]}: ${currentValue} (${percentage}%)`;
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
return {
|
|
86
|
+
data: loading ? [] : chartJsData,
|
|
87
|
+
option: loading ? [] : defaultOptions
|
|
88
|
+
};
|
|
89
|
+
}
|
|
@@ -15,7 +15,7 @@ import { useCallback, useState } from 'react'
|
|
|
15
15
|
* - clearAll (callback)
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
export const useCheckboxState = (elem, selectedIds = [], disabledIds = []) => {
|
|
18
|
+
export const useCheckboxState = (elem, selectedIds = [], disabledIds = [], calBack = () => { return }) => {
|
|
19
19
|
const numTotalItems = elem?.length
|
|
20
20
|
const [checkedItems, setCheckedItems] = useState(new Set(selectedIds))
|
|
21
21
|
const [disabledItems, setDisabledItems] = useState(new Set(disabledIds))
|
|
@@ -23,14 +23,17 @@ export const useCheckboxState = (elem, selectedIds = [], disabledIds = []) => {
|
|
|
23
23
|
const handleChangeCheck = useCallback((event, id) => {
|
|
24
24
|
const target = event.target
|
|
25
25
|
setCheckedItems(prevState => {
|
|
26
|
+
|
|
26
27
|
const newState = new Set(prevState)
|
|
27
28
|
if (target.checked) {
|
|
28
29
|
newState.add(id)
|
|
29
30
|
} else {
|
|
30
31
|
newState.delete(id)
|
|
31
32
|
}
|
|
33
|
+
calBack([...newState])
|
|
32
34
|
return newState
|
|
33
35
|
})
|
|
36
|
+
// eslint-disable-next-line
|
|
34
37
|
}, [])
|
|
35
38
|
|
|
36
39
|
const setAll = useCallback(
|
|
@@ -106,6 +109,7 @@ export const useCheckboxState = (elem, selectedIds = [], disabledIds = []) => {
|
|
|
106
109
|
disabledItems,
|
|
107
110
|
handleChangeCheck,
|
|
108
111
|
toggleAll,
|
|
112
|
+
setCheckedItems,
|
|
109
113
|
selectAll,
|
|
110
114
|
clearAll,
|
|
111
115
|
enableCheckboxes,
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { useQuery, useMutation, useLazyQuery } from '@apollo/client'
|
|
2
|
-
import { useState } from 'react'
|
|
3
2
|
import {
|
|
4
3
|
CREATE_CLIENTS,
|
|
5
4
|
DELETE_ONE_CLIENTS,
|
|
@@ -11,15 +10,25 @@ import {
|
|
|
11
10
|
export const useGetClients = ({
|
|
12
11
|
max,
|
|
13
12
|
search,
|
|
13
|
+
fromDate, // Agrega las variables fromDate y toDate
|
|
14
|
+
toDate,
|
|
14
15
|
sendNotification = () => { return }
|
|
15
16
|
} = {}) => {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
const {
|
|
18
|
+
loading,
|
|
19
|
+
error,
|
|
20
|
+
called,
|
|
21
|
+
data
|
|
22
|
+
} = useQuery(GET_ALL_CLIENTS, {
|
|
23
|
+
variables: {
|
|
24
|
+
search: search,
|
|
25
|
+
fromDate: fromDate, // Usa las variables aquí
|
|
26
|
+
toDate: toDate
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
return [data?.getAllClients || [], { loading: called ? false : loading, error }];
|
|
31
|
+
};
|
|
23
32
|
|
|
24
33
|
export const useDeleteClients = ({ sendNotification = () => { return } } = {}) => {
|
|
25
34
|
const [deleteClient, { loading, error }] = useMutation(DELETE_ONE_CLIENTS)
|