Summen-Statistik der Kategorien

Eigenes 'Löschen' PopUp
This commit is contained in:
2026-03-01 11:48:24 +00:00
parent ed6bc21248
commit 2a9ae7e806
6 changed files with 181 additions and 117 deletions

View File

@@ -56,6 +56,21 @@ export async function GET(request: Request) {
const data = rows[0] || {};
// Per-category breakdown
const [katRows] = await pool.query<RowDataPacket[]>(
`SELECT Kat, SUM(Wieviel) as total
FROM Ausgaben
WHERE YEAR(Datum) = ? AND MONTH(Datum) = ? AND TYP = ?
GROUP BY Kat
HAVING total > 0
ORDER BY total DESC`,
[year, month, parseInt(typ)]
);
const katStats: Record<string, number> = {};
for (const row of katRows) {
katStats[row.Kat] = parseFloat(row.total) || 0;
}
// Convert string values from MySQL to numbers
const parsedData: any = {
totalAusgaben: parseFloat(data.totalAusgaben) || 0,
@@ -77,7 +92,7 @@ export async function GET(request: Request) {
return NextResponse.json({
success: true,
data: parsedData,
data: { ...parsedData, katStats },
});
} catch (error) {
console.error('Database error:', error);