Summen-Statistik der Kategorien
Eigenes 'Löschen' PopUp
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user