import React, { Component } from 'react'; import { Box, Paper, Typography, Select, MenuItem, FormControl, InputLabel, Grid, Button, ListSubheader, Divider, } from '@mui/material'; import { Download as DownloadIcon, CalendarToday as CalendarIcon, DateRange as QuarterIcon, Event as YearIcon, } from '@mui/icons-material'; class SummaryHeader extends Component { formatAmount = (amount) => { return new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(amount); }; getMonthName = (monthYear) => { if (!monthYear) return ''; const [year, month] = monthYear.split('-'); const date = new Date(year, month - 1); return date.toLocaleDateString('de-DE', { month: 'long', year: 'numeric' }); }; getQuarterName = (year, quarter) => { return `Q${quarter} ${year}`; }; getYearName = (year) => { return `Jahr ${year}`; }; generateTimeRangeOptions = (months) => { if (!months || months.length === 0) return { months: [], quarters: [], years: [] }; // Extract years from months const years = [...new Set(months.map(month => month.split('-')[0]))].sort().reverse(); // Generate quarters const quarters = []; years.forEach(year => { for (let q = 4; q >= 1; q--) { const quarterMonths = this.getQuarterMonths(year, q); // Only include quarter if we have data for at least one month in it if (quarterMonths.some(month => months.includes(month))) { quarters.push({ year, quarter: q, value: `${year}-Q${q}` }); } } }); return { months: months, quarters: quarters, years: years.map(year => ({ year, value: year })) }; }; getQuarterMonths = (year, quarter) => { const startMonth = (quarter - 1) * 3 + 1; return [ `${year}-${startMonth.toString().padStart(2, '0')}`, `${year}-${(startMonth + 1).toString().padStart(2, '0')}`, `${year}-${(startMonth + 2).toString().padStart(2, '0')}` ]; }; getSelectedDisplayName = (selectedValue, timeRangeOptions) => { if (!selectedValue) return ''; if (selectedValue.includes('-Q')) { const [year, quarterPart] = selectedValue.split('-Q'); return this.getQuarterName(year, quarterPart); } else if (selectedValue.length === 4) { return this.getYearName(selectedValue); } else { return this.getMonthName(selectedValue); } }; render() { const { months, selectedMonth, summary, loading, onMonthChange } = this.props; if (!summary) return null; const timeRangeOptions = this.generateTimeRangeOptions(months); return ( Zeitraum Transaktionen {summary.totalTransactions} Einnahmen {this.formatAmount(summary.totalIncome)} Ausgaben {this.formatAmount(summary.totalExpenses)} Nettobetrag = 0 ? '#388e3c' : '#d32f2f', fontSize: { xs: '0.9rem', sm: '1.25rem' } }} > {this.formatAmount(summary.netAmount)} JTL ✓ {summary.jtlMatches === undefined ? '?' : summary.jtlMatches} ); } } export default SummaryHeader;