npm-pkg-hook 1.1.2 → 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/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "publishConfig": {
8
8
  "registry": "https://registry.npmjs.org/"
9
9
  },
10
- "version": "1.1.2",
10
+ "version": "1.1.3",
11
11
  "description": "description-pkg-hook",
12
12
  "main": "/src/index.jsx",
13
13
  "scripts": {
@@ -1,197 +1,2 @@
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
-
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
+ }
@@ -36,7 +36,11 @@ export const useGetOneUseStoreContacts = ({ sendNotification = () => { return }
36
36
  }
37
37
 
38
38
  export const useEditOneUseStoreContacts = ({ sendNotification = () => { return } } = {}) => {
39
- const [editOneContacts, { data, error, loading }] = useMutation(EDIT_ONE_CONTACT)
39
+ const [editOneContacts, { data, error, loading }] = useMutation(EDIT_ONE_CONTACT, {
40
+ onError: e => {
41
+ console.error(e)
42
+ }
43
+ })
40
44
  return [editOneContacts, { data: data?.editOneContacts, loading, error }]
41
45
  }
42
46