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);

View File

@@ -3,6 +3,7 @@
import { useState, useEffect } from 'react';
import AusgabenForm from '@/components/AusgabenForm';
import AusgabenList from '@/components/AusgabenList';
import MonatsStatistik from '@/components/MonatsStatistik';
import LogoutButton from '@/components/LogoutButton';
import { AusgabenEntry } from '@/types/ausgaben';
import packageJson from '@/package.json';
@@ -12,6 +13,7 @@ export default function Home() {
const [entries, setEntries] = useState<AusgabenEntry[]>([]);
const [isLoading, setIsLoading] = useState(true);
const [selectedEntry, setSelectedEntry] = useState<AusgabenEntry | null>(null);
const [statsRefreshKey, setStatsRefreshKey] = useState(0);
const version = packageJson.version;
const buildDate = process.env.NEXT_PUBLIC_BUILD_DATE || new Date().toLocaleDateString('de-DE', { day: '2-digit', month: '2-digit', year: 'numeric' });
@@ -43,6 +45,7 @@ export default function Home() {
const handleSuccess = () => {
setSelectedEntry(null);
setStatsRefreshKey((k) => k + 1);
setTimeout(() => {
fetchRecentEntries();
}, 100);
@@ -50,6 +53,7 @@ export default function Home() {
const handleDelete = (id: number) => {
setEntries(entries.filter(entry => entry.ID !== id));
setStatsRefreshKey((k) => k + 1);
};
const handleEdit = (entry: AusgabenEntry) => {
@@ -93,6 +97,8 @@ export default function Home() {
<h2 className="text-xl font-semibold mb-4">Eingabe</h2>
<AusgabenForm onSuccess={handleSuccess} selectedEntry={selectedEntry} typ={activeTab} />
<MonatsStatistik typ={activeTab} refreshKey={statsRefreshKey} />
<div className="mt-6 bg-white border border-black rounded-lg shadow-md p-6">
<h3 className="text-xl font-semibold mb-4">Letzte 20 Einträge</h3>
{isLoading ? (