feat: adicionada a coluna de percentual total no final da coluna
This commit is contained in:
parent
8132942532
commit
6e201cfbaa
|
|
@ -53,6 +53,7 @@ interface HierarchicalRow {
|
||||||
isExpanded?: boolean;
|
isExpanded?: boolean;
|
||||||
valoresPorMes?: Record<string, number>;
|
valoresPorMes?: Record<string, number>;
|
||||||
percentuaisPorMes?: Record<string, number>;
|
percentuaisPorMes?: Record<string, number>;
|
||||||
|
percentualTotal?: number;
|
||||||
isCalculado?: boolean;
|
isCalculado?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -163,6 +164,21 @@ const TableRow = memo(({
|
||||||
);
|
);
|
||||||
})()}
|
})()}
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
|
{/* Coluna Percentual Total */}
|
||||||
|
<td
|
||||||
|
className="px-2 py-1 text-center font-medium cursor-pointer hover:bg-blue-50/50 transition-colors duration-200 whitespace-nowrap overflow-hidden w-[100px] min-w-[100px]"
|
||||||
|
onClick={() => handleRowClick(row)}
|
||||||
|
title={
|
||||||
|
row.percentualTotal !== undefined
|
||||||
|
? `${row.percentualTotal.toFixed(1)}%`
|
||||||
|
: "-"
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{row.percentualTotal !== undefined
|
||||||
|
? `${row.percentualTotal.toFixed(1)}%`
|
||||||
|
: "-"}
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
@ -920,15 +936,17 @@ export default function Teste() {
|
||||||
|
|
||||||
// Calcular total do grupo
|
// Calcular total do grupo
|
||||||
const totalCalculado = Object.values(valoresGrupoPorMes).reduce((sum, valor) => sum + valor, 0);
|
const totalCalculado = Object.values(valoresGrupoPorMes).reduce((sum, valor) => sum + valor, 0);
|
||||||
|
const totalFinal = isCalculado ? totalCalculado : totalGrupo;
|
||||||
|
|
||||||
// Linha do grupo (Level 0)
|
// Linha do grupo (Level 0)
|
||||||
rows.push({
|
rows.push({
|
||||||
type: "grupo",
|
type: "grupo",
|
||||||
level: 0,
|
level: 0,
|
||||||
grupo,
|
grupo,
|
||||||
total: isCalculado ? totalCalculado : totalGrupo,
|
total: totalFinal,
|
||||||
valoresPorMes: valoresGrupoPorMes,
|
valoresPorMes: valoresGrupoPorMes,
|
||||||
percentuaisPorMes: calcularPercentuaisPorMes(valoresGrupoPorMes, grupo),
|
percentuaisPorMes: calcularPercentuaisPorMes(valoresGrupoPorMes, grupo),
|
||||||
|
percentualTotal: calcularPercentualTotal(totalFinal, grupo),
|
||||||
isCalculado: isCalculado,
|
isCalculado: isCalculado,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -969,6 +987,7 @@ export default function Teste() {
|
||||||
total: totalConta,
|
total: totalConta,
|
||||||
valoresPorMes: valoresContaPorMes,
|
valoresPorMes: valoresContaPorMes,
|
||||||
percentuaisPorMes: calcularPercentuaisPorMes(valoresContaPorMes, grupo),
|
percentuaisPorMes: calcularPercentuaisPorMes(valoresContaPorMes, grupo),
|
||||||
|
percentualTotal: calcularPercentualTotal(totalConta, grupo),
|
||||||
});
|
});
|
||||||
|
|
||||||
// Agrupar por centro de custo dentro da conta
|
// Agrupar por centro de custo dentro da conta
|
||||||
|
|
@ -1006,6 +1025,7 @@ export default function Teste() {
|
||||||
total: totalCentro,
|
total: totalCentro,
|
||||||
valoresPorMes: valoresCentroPorMes,
|
valoresPorMes: valoresCentroPorMes,
|
||||||
percentuaisPorMes: calcularPercentuaisPorMes(valoresCentroPorMes, grupo),
|
percentuaisPorMes: calcularPercentuaisPorMes(valoresCentroPorMes, grupo),
|
||||||
|
percentualTotal: calcularPercentualTotal(totalCentro, grupo),
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
@ -1046,6 +1066,7 @@ export default function Teste() {
|
||||||
total: totalCentro,
|
total: totalCentro,
|
||||||
valoresPorMes: valoresCentroPorMes,
|
valoresPorMes: valoresCentroPorMes,
|
||||||
percentuaisPorMes: calcularPercentuaisPorMes(valoresCentroPorMes, grupo),
|
percentuaisPorMes: calcularPercentuaisPorMes(valoresCentroPorMes, grupo),
|
||||||
|
percentualTotal: calcularPercentualTotal(totalCentro, grupo),
|
||||||
});
|
});
|
||||||
|
|
||||||
// Agrupar por conta dentro do centro de custo
|
// Agrupar por conta dentro do centro de custo
|
||||||
|
|
@ -1083,6 +1104,7 @@ export default function Teste() {
|
||||||
total: totalConta,
|
total: totalConta,
|
||||||
valoresPorMes: valoresContaPorMes,
|
valoresPorMes: valoresContaPorMes,
|
||||||
percentuaisPorMes: calcularPercentuaisPorMes(valoresContaPorMes, grupo),
|
percentuaisPorMes: calcularPercentuaisPorMes(valoresContaPorMes, grupo),
|
||||||
|
percentualTotal: calcularPercentualTotal(totalConta, grupo),
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
@ -1642,6 +1664,33 @@ export default function Teste() {
|
||||||
return percentuais;
|
return percentuais;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Função para calcular percentual do total baseado no grupo 03 como referência
|
||||||
|
const calcularPercentualTotal = (
|
||||||
|
total: number,
|
||||||
|
grupo: string
|
||||||
|
): number => {
|
||||||
|
// Se for o grupo 03, retorna 100%
|
||||||
|
if (grupo.includes("03")) {
|
||||||
|
return 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calcular o total do grupo 03
|
||||||
|
const grupo03Items = data.filter((item) =>
|
||||||
|
item.grupo.includes("03")
|
||||||
|
);
|
||||||
|
|
||||||
|
const totalGrupo03 = grupo03Items.reduce(
|
||||||
|
(sum, item) => sum + parseFloat(item.valor),
|
||||||
|
0
|
||||||
|
);
|
||||||
|
|
||||||
|
if (totalGrupo03 !== 0) {
|
||||||
|
return (total / totalGrupo03) * 100;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const buildHierarchicalData = (): HierarchicalRow[] => {
|
const buildHierarchicalData = (): HierarchicalRow[] => {
|
||||||
const rows: HierarchicalRow[] = [];
|
const rows: HierarchicalRow[] = [];
|
||||||
|
|
||||||
|
|
@ -1821,16 +1870,18 @@ export default function Teste() {
|
||||||
|
|
||||||
// Calcular total do grupo
|
// Calcular total do grupo
|
||||||
const totalCalculado = Object.values(valoresPorMes).reduce((sum, valor) => sum + valor, 0);
|
const totalCalculado = Object.values(valoresPorMes).reduce((sum, valor) => sum + valor, 0);
|
||||||
|
const totalFinal = isCalculado ? totalCalculado : totalGrupo;
|
||||||
|
|
||||||
// Linha do grupo
|
// Linha do grupo
|
||||||
rows.push({
|
rows.push({
|
||||||
type: "grupo",
|
type: "grupo",
|
||||||
level: 0,
|
level: 0,
|
||||||
grupo,
|
grupo,
|
||||||
total: isCalculado ? totalCalculado : totalGrupo,
|
total: totalFinal,
|
||||||
isExpanded: expandedGroups.has(grupo),
|
isExpanded: expandedGroups.has(grupo),
|
||||||
valoresPorMes,
|
valoresPorMes,
|
||||||
percentuaisPorMes: calcularPercentuaisPorMes(valoresPorMes, grupo),
|
percentuaisPorMes: calcularPercentuaisPorMes(valoresPorMes, grupo),
|
||||||
|
percentualTotal: calcularPercentualTotal(totalFinal, grupo),
|
||||||
isCalculado: isCalculado,
|
isCalculado: isCalculado,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -1884,6 +1935,7 @@ export default function Teste() {
|
||||||
valoresContaPorMes,
|
valoresContaPorMes,
|
||||||
grupo
|
grupo
|
||||||
),
|
),
|
||||||
|
percentualTotal: calcularPercentualTotal(totalConta, grupo),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (expandedCentros.has(`${grupo}-${conta}`)) {
|
if (expandedCentros.has(`${grupo}-${conta}`)) {
|
||||||
|
|
@ -1933,6 +1985,7 @@ export default function Teste() {
|
||||||
valoresCentroPorMes,
|
valoresCentroPorMes,
|
||||||
grupo
|
grupo
|
||||||
),
|
),
|
||||||
|
percentualTotal: calcularPercentualTotal(totalCentro, grupo),
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -1986,6 +2039,7 @@ export default function Teste() {
|
||||||
valoresCentroPorMes,
|
valoresCentroPorMes,
|
||||||
grupo
|
grupo
|
||||||
),
|
),
|
||||||
|
percentualTotal: calcularPercentualTotal(totalCentro, grupo),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (expandedCentros.has(`${grupo}-${centro}`)) {
|
if (expandedCentros.has(`${grupo}-${centro}`)) {
|
||||||
|
|
@ -2035,6 +2089,7 @@ export default function Teste() {
|
||||||
valoresContaPorMes,
|
valoresContaPorMes,
|
||||||
grupo
|
grupo
|
||||||
),
|
),
|
||||||
|
percentualTotal: calcularPercentualTotal(totalConta, grupo),
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -2633,6 +2688,9 @@ export default function Teste() {
|
||||||
<th className="px-4 py-2 text-right text-xs font-semibold text-gray-700 uppercase tracking-wide w-[120px] min-w-[120px]">
|
<th className="px-4 py-2 text-right text-xs font-semibold text-gray-700 uppercase tracking-wide w-[120px] min-w-[120px]">
|
||||||
Total
|
Total
|
||||||
</th>
|
</th>
|
||||||
|
<th className="px-2 py-2 text-center text-xs font-semibold text-gray-500 uppercase tracking-wide w-[100px] min-w-[100px]">
|
||||||
|
%
|
||||||
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue