From 309c2b456aca66cc2bb2a7b418676e1df183f282 Mon Sep 17 00:00:00 2001 From: joseCorte-exe Date: Thu, 20 Oct 2022 10:33:19 -0300 Subject: [PATCH] add: add percentage in mensal chart --- .../administrativeTables/ClientsTable.tsx | 210 +++++++++++++++++- .../grossMensalChart/GrossMensalChart.tsx | 142 +++++++++--- src/pages/administrative/clients/index.tsx | 6 + src/pages/dashboard/index.tsx | 6 +- src/pages/economy/index.tsx | 1 + src/pages/pld/index.tsx | 2 +- 6 files changed, 332 insertions(+), 35 deletions(-) diff --git a/src/components/administrativeTables/ClientsTable.tsx b/src/components/administrativeTables/ClientsTable.tsx index 90ccfaf..8ff3228 100644 --- a/src/components/administrativeTables/ClientsTable.tsx +++ b/src/components/administrativeTables/ClientsTable.tsx @@ -12,14 +12,21 @@ import TableSortLabel from '@mui/material/TableSortLabel'; import { visuallyHidden } from '@mui/utils'; import React, { useState, useEffect } from 'react'; +import Image from 'next/image' + import Snackbar from '@mui/material/Snackbar'; import MuiAlert, { AlertProps } from '@mui/material/Alert'; import Modal from '@mui/material/Modal'; +import FormData from 'form-data' +import { InputUploadView } from '../inputUploadImg/inputUploadView' +import { FormControl, InputLabel, MenuItem, Select, TextField, Typography } from '@mui/material' import { TableView, StyledStatus } from './TableView'; import { api } from '../../services/api'; +import FaqButton1 from '../buttons/faqButton/FaqButton1'; +import FaqButton2 from '../buttons/faqButton/FaqButton2'; const style = { position: 'absolute' as const, @@ -276,6 +283,65 @@ export default function ClientTable({clients, onChange}: ClientsTableInterface) const emptyRows = page > 0 ? Math.max(0, (1 + page) * rowsPerPage - clients.length) : 0; + const formData = new FormData() + + const [clientEdit, setClientEdit] = useState({ + name: String, + email: String, + password: String, + password_confirmation: String, + client_id: Number + }) + const [logo, setLogo] = useState(false) + const [imageURLS, setImageURLs] = useState([]) + const [images, setImages] = useState([] as any) + const [nivelAcess, setnivelAcess] = useState(2); + const [openEditUserModal, setOpenEditUserModal] = useState(2); + + const [selectedClient, setSelectedClient] = useState(2); + + useEffect(() => { + if (images.length < 1) return + const newImageUrls: any = [] + images.forEach((image: any) => + newImageUrls.push(URL.createObjectURL(image)) + ) + setImageURLs(newImageUrls) + }, [images]) + + function onImageChange(e: any) { + setImages([...e.target.files]) + setLogo(e.target.files[0]) + } + + const [openSnackSuccess, setOpenSnackSuccess] = useState(false) + + function handleUpdateClient({ + name, + email, + password, + password_confirmation, + client_id + }, id) { + formData.append('name', name) + formData.append('email', email) + formData.append('password', password) + formData.append('password_confirmation', password_confirmation) + formData.append('client_id', client_id) + formData.append('profile_picture', logo) + formData.append('role', nivelAcess) + + api.put(`/user/${id}`, formData) + .then((res) => { + setOpenSnackSuccess(true) + setOpenModalInativar(false) + window.location.reload() + }) + .catch((res) => { + setOpenSnackError(true) + }) + } + return ( @@ -332,10 +398,15 @@ export default function ClientTable({clients, onChange}: ClientsTableInterface) > Client - {row.client_id} - {row.name} + { + setOpenEditUserModal(true) + setSelectedClient(row) + setClientEdit(row) + }}>{row.name} { setOpen(true) getClientUnits(row.client_id) + setSelectedClient(row) }}>clique aqui para ver as unidades {row.deleted_at? 'inativo' : 'ativo'} @@ -363,6 +434,143 @@ export default function ClientTable({clients, onChange}: ClientsTableInterface) onRowsPerPageChange={handleChangeRowsPerPage} /> + setOpenEditUserModal(false)} + aria-labelledby="modal-modal-title" + aria-describedby="modal-modal-description" + > + +

Editar Cliente - {selectedClient.name}

+ + Adicionar Cliente Smart Energia + +
+ { + setClientEdit({ + ...clientEdit, + name: value.target.value + }) + }} + variant="outlined" + /> + { + setClientEdit({ + ...clientEdit, + email: value.target.value.toLowerCase() + }) + }} + variant="outlined" + /> + { + setClientEdit({ + ...clientEdit, + password: value.target.value + }) + }} + variant="outlined" + /> + { + setClientEdit({ + ...clientEdit, + password_confirmation: value.target.value + }) + }} + variant="outlined" + /> + { + setClientEdit({ + ...clientEdit, + client_id: value.target.value + }) + }} + variant="outlined" + /> + +
+
+ {imageURLS.map((imageSrc, index) => { + return + })} +
+
+
+
+
+ + +
+
+
+
+ +
+ + + Nivel de acesso + + +
+ + setOpenEditUserModal(false)} /> + handleUpdateClient(clientEdit, selectedClient.id)} + /> +
+
+ { let lastData = '0' - let index=0 + let index = 0 while (index < data1.length) { - data1[index].dad_estimado? lastData=data1[index].economia_acumulada : null + data1[index].dad_estimado + ? (lastData = data1[index].economia_acumulada) + : null index++ - setLastData(`economia acumulada: R$ ${parseFloat(lastData).toLocaleString('pt-br', {minimumFractionDigits: 2})}`) + setLastData( + `economia acumulada: R$ ${parseFloat(lastData).toLocaleString('pt-br', { + minimumFractionDigits: 2 + })}` + ) } }, [data1]) - const options: any = config(miniature) + const options: any = { + responsive: true, + scales: { + x: { + stacked: false, + grid: { + display: false + }, + ticks: { + font: { + size: !miniature ? window.innerWidth / 90 : window.innerWidth / 125 + } + } + }, + y: { + stacked: false, + grid: { + display: false + }, + ticks: { + font: { + size: !miniature ? window.innerWidth / 90 : window.innerWidth / 125 + } + } + } + }, + plugins: { + datalabels: { + display: true, + color: '#255488', + formatter: (value, ctx) => { + let sum = 0 + const dataArr = ctx.chart.data.datasets[0].data + const percentage = + (data1[ctx?.dataIndex]?.econ_percentual * 100).toFixed(0) + '%' + + console.log(percentage) + dataArr.map((data) => { + sum += data + }) + const result = `${percentage}\n${parseFloat( + parseFloat(value).toLocaleString('pt-br') + )}` + + return value == null ? null : result + }, + anchor: 'end', + align: 'end', + font: { + weight: 'bold', + size: !miniature ? window.innerWidth / 80 : window.innerWidth / 125 + } + }, + legend: { + position: 'bottom' as const + }, + title: { + display: true, + text: '' + } + } + } const data: any = { labels: label, @@ -67,7 +145,9 @@ export default function GrossMensalChart({ title, data1, data2, label, subtitle, { type: 'bar', label: 'Consolidado', - data: data1.map(value => !value.dad_estimado? value?.economia_acumulada : null), + data: data1.map((value) => + !value.dad_estimado ? value?.economia_acumulada : null + ), skipNull: true, borderRadius: 8, backgroundColor: '#255488', @@ -76,21 +156,21 @@ export default function GrossMensalChart({ title, data1, data2, label, subtitle, { type: 'bar', label: 'Estimado', - data: data2.map(value => value.dad_estimado? value?.economia_acumulada : null), + data: data2.map((value) => + value.dad_estimado ? value?.economia_acumulada : null + ), skipNull: true, borderRadius: 8, backgroundColor: draw('diagonal-right-left', '#C2d5fb'), stack: '0' - }, - ], + } + ] } return ( - + ) } diff --git a/src/pages/administrative/clients/index.tsx b/src/pages/administrative/clients/index.tsx index c4c7da5..a055fe7 100644 --- a/src/pages/administrative/clients/index.tsx +++ b/src/pages/administrative/clients/index.tsx @@ -152,6 +152,12 @@ export default function clients({ clients, userName }) { setLogo(e.target.files[0]) } + console.table(clients.map(client => { + if (Number.parseInt(client.client_id) === 59641651) return client + return + })) + console.table(clients[417]) + return (
@@ -195,9 +197,9 @@ export const getServerSideProps: GetServerSideProps = async (ctx) => { await apiClient.post('/economy/grossAnnual').then(res => { grossAnualGraph = res.data.data - }).catch(res => { - // console.log(res) }) + .then(console.log) + .catch(console.log) await apiClient.post('/economy/grossMonthly').then(res => { grossMensalGraph = res.data.data diff --git a/src/pages/economy/index.tsx b/src/pages/economy/index.tsx index 5079f7a..d28a187 100644 --- a/src/pages/economy/index.tsx +++ b/src/pages/economy/index.tsx @@ -91,6 +91,7 @@ export default function economy({userName, anual, years, brutaMensal, catLiv, cl useEffect(() => { getChartsWithUnity() + console.log(brutaMensal) }, [unity]) return ( diff --git a/src/pages/pld/index.tsx b/src/pages/pld/index.tsx index ff07ed6..5b23015 100644 --- a/src/pages/pld/index.tsx +++ b/src/pages/pld/index.tsx @@ -76,7 +76,7 @@ export default function pld({tableData, userName, clientMonth}: pldInterface) { function getDataByDay() { api.post('/pld/daily', { "filters": [ - {"type" : "=", "field" : "year_month_formatted", "value": month}, + {"type" : "=", "field" : "year_month_formatted", "value": month, "row": true}, {"type" : "=", "field" : "submarket", "value": select} ], "order": [{ "field": "day_calc", "direction": "asc" }]