From 19dbdbeea72ea3edf8466905dfd08f013627b2b7 Mon Sep 17 00:00:00 2001 From: Dicken Date: Wed, 17 Jun 2026 17:50:47 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20Bestellungen=20nach=20gew=C3=A4hltem=20Z?= =?UTF-8?q?eitraum,=20=C3=9Cbersicht=20reagiert=20auf=20Zeitraum-Wechsel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/tools/statistik.jsx | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/frontend/src/tools/statistik.jsx b/frontend/src/tools/statistik.jsx index 2e80fb6..731fc22 100644 --- a/frontend/src/tools/statistik.jsx +++ b/frontend/src/tools/statistik.jsx @@ -1,4 +1,4 @@ -import { useState, useEffect, useCallback } from 'react'; +import { useState, useEffect } from 'react'; import { BarChart, Bar, LineChart, Line, XAxis, YAxis, Tooltip, ResponsiveContainer, Cell, PieChart, Pie, Legend } from 'recharts'; const api = (path, opts={}) => { @@ -96,23 +96,23 @@ function KPI({ label, value, color, sub }) { ); } -// Bestellungen diesen Monat – eigene Komponente mit eigenem Fetch -function MonthOrders({ currentMonth }) { +// Bestellungen im gewählten Zeitraum +function OrdersInPeriod({ period, custom }) { const [orders, setOrders] = useState(null); useEffect(() => { - const from = currentMonth + '-01'; - const last = new Date(currentMonth.split('-')[0], currentMonth.split('-')[1], 0).getDate(); - const to = currentMonth + '-' + String(last).padStart(2,'0'); - api(`/tools/statistik/month-orders?from=${from}&to=${to}`).then(setOrders).catch(()=>setOrders([])); - }, [currentMonth]); + const { from, to } = periodRange(period, custom); + const q = from ? `?from=${from}&to=${to}` : ''; + api(`/tools/statistik/month-orders${q}`).then(setOrders).catch(()=>setOrders([])); + }, [period, custom]); const statusColor = { warteliste:'#ffe66d', in_arbeit:'#4ecdc4', fertig:'#6bcb77' }; + const periodLabel = period==='week'?'DIESER WOCHE':period==='month'?'DIESEM MONAT':period==='year'?'DIESEM JAHR':period==='all'?'GESAMT':'IM ZEITRAUM'; return (
- BESTELLUNGEN DIESEN MONAT {orders ? `(${orders.length})` : ''} + BESTELLUNGEN {periodLabel} {orders ? `(${orders.length})` : ''}
{!orders ?
Lädt…
@@ -152,12 +152,11 @@ export default function Statistik({ mobile }) { const [data, setData] = useState(null); const [loading,setLoading] = useState(false); const [tab, setTab] = useState('overview'); - // Bestellungen-Tab: immer aktueller Monat - const currentMonth = new Date().toISOString().slice(0,7); + const [expForm,setExpForm] = useState({ date: new Date().toISOString().slice(0,10), category:'Filament', description:'', amount:'' }); const [saving, setSaving] = useState(false); - const load = useCallback(() => { + function load() { setLoading(true); const { from, to } = periodRange(period, custom); const q = from ? `?from=${from}&to=${to}` : ''; @@ -165,9 +164,10 @@ export default function Statistik({ mobile }) { .then(d => setData(d)) .catch(()=>{}) .finally(()=>setLoading(false)); - }, [period, custom]); + } - useEffect(() => { load(); }, [load]); + // Neu laden wenn Zeitraum ändert + useEffect(() => { load(); }, [period, custom.type, custom.month, custom.year]); async function addExpense() { if (!expForm.description || !expForm.amount) return; @@ -470,7 +470,7 @@ export default function Statistik({ mobile }) { {/* ══ BESTELLUNGEN (dieser Monat) ══ */} {tab==='orders' && ( - + )}
);