diff --git a/src/app/admin/team/report/[userId]/[month]/page.tsx b/src/app/admin/team/report/[userId]/[month]/page.tsx
index de5ccddb6..eab6f691b 100644
--- a/src/app/admin/team/report/[userId]/[month]/page.tsx
+++ b/src/app/admin/team/report/[userId]/[month]/page.tsx
@@ -16,6 +16,7 @@ import { canAccessSection } from '@/lib/permissions'
import { getMonthlyReport, REPORT_MONTH_REGEX } from '@/lib/services/report'
import { getTimecardMonthLabel } from '@/lib/team/timecard-period-label'
import { getDisplayDate } from '@/lib/team/timecard-utils'
+import { SCHEDULE_FILL_DESCRIPTION } from '@/lib/team/schedule'
import { formatTimecardDuration, getTimecardEntryCategoryLabel, getTimecardStatusLabel, isAbsenceCategory } from '@/config/timecards'
import { ORG, LOCATIONS } from '@/config/org'
import { PrintButton } from './PrintButton'
@@ -45,7 +46,12 @@ export default async function MonthlyReportPage({
if (!report) notFound()
const monthLabel = getTimecardMonthLabel(`${month}-01`)
- const entries = report.card?.entries ?? []
+ // Only days up to the as-of date are "worked" — a running month must not
+ // present pre-filled future days as done (they'd also inflate the totals).
+ const allEntries = report.card?.entries ?? []
+ const entries = allEntries.filter(e => e.work_date <= report.asOfDate)
+ const futureCount = allEntries.length - entries.length
+ const asOfLabel = getDisplayDate(report.asOfDate)
const workedMinutes = entries.filter(e => !isAbsenceCategory(e.category)).reduce((s, e) => s + e.duration_minutes, 0)
const absenceMinutes = entries.filter(e => isAbsenceCategory(e.category)).reduce((s, e) => s + e.duration_minutes, 0)
const absenceDaysByCategory = new Map()
@@ -72,6 +78,11 @@ export default async function MonthlyReportPage({
Monatsrapport Arbeitszeit — {monthLabel}
+ {report.isInterim && (
+
+ Zwischenstand per {asOfLabel} — der Monat läuft noch; Zahlen bis zu diesem Tag.
+
+ )}
{/* Person + status */}
@@ -88,15 +99,15 @@ export default async function MonthlyReportPage({
{/* Summary */}
-
Soll (Monat)
+
Soll {report.isInterim ? `(bis ${asOfLabel})` : '(Monat)'}
{report.saldo ? formatTimecardDuration(report.saldo.time.monthSollMinutes) : '—'}
-
Ist (Monat)
+
Ist {report.isInterim ? `(bis ${asOfLabel})` : '(Monat)'}
{report.saldo ? formatTimecardDuration(report.saldo.time.monthIstMinutes) : formatTimecardDuration(workedMinutes + absenceMinutes)}
-
Zeitsaldo (Ende Monat)
+
Zeitsaldo {report.isInterim ? `(per ${asOfLabel})` : '(Ende Monat)'}
{report.saldo
? `${report.saldo.time.saldoMinutes < 0 ? '−' : '+'}${formatTimecardDuration(Math.abs(report.saldo.time.saldoMinutes))}`
@@ -145,11 +156,18 @@ export default async function MonthlyReportPage({
{e.start_time && e.end_time ? `${e.start_time}–${e.end_time}${e.break_minutes ? ` (${e.break_minutes}′ Pause)` : ''}` : '—'}
{formatTimecardDuration(e.duration_minutes)}
-
{e.description ?? ''}
+ {/* The plan-fill source marker is internal noise on a document —
+ show only genuine, hand-written remarks. */}
+
{e.description === SCHEDULE_FILL_DESCRIPTION ? '' : (e.description ?? '')}
))}
+ {futureCount > 0 && (
+
+ {futureCount} geplante {futureCount === 1 ? 'Tag' : 'Tage'} nach dem {asOfLabel} noch nicht berücksichtigt (Monat läuft noch).
+
+ )}
{report.holidays.length > 0 && (
Feiertage im {monthLabel}: {report.holidays.map(h => `${getDisplayDate(h.date)} (${h.name})`).join(', ')} — reduzieren die Sollzeit automatisch.
diff --git a/src/components/admin/timecards/TimecardReviewDrawer.tsx b/src/components/admin/timecards/TimecardReviewDrawer.tsx
index b833b3c34..d8844527b 100644
--- a/src/components/admin/timecards/TimecardReviewDrawer.tsx
+++ b/src/components/admin/timecards/TimecardReviewDrawer.tsx
@@ -1,9 +1,10 @@
'use client'
-import { useEffect, useState } from 'react'
+import { useCallback, useEffect, useState } from 'react'
import { createPortal } from 'react-dom'
import { useTranslations } from 'next-intl'
-import { X, Check, Ban, Pencil, Save, RotateCcw, Send } from 'lucide-react'
+import Link from 'next/link'
+import { X, Check, Ban, Pencil, Save, RotateCcw, Send, FileText } from 'lucide-react'
import { Button } from '@/components/ui/button'
import { Input } from '@/components/ui/input'
import { Select } from '@/components/ui/select'
@@ -69,20 +70,23 @@ export function TimecardReviewDrawer({
const [note, setNote] = useState('')
const [busy, setBusy] = useState(null)
const [error, setError] = useState(null)
+ // Positive acknowledgement after an action — the drawer stays open showing
+ // this + the next step (the report), so the approver never has to hunt for
+ // the card they just acted on.
+ const [flash, setFlash] = useState(null)
// eslint-disable-next-line react-hooks/set-state-in-effect -- portal mount guard (SSR-safe)
useEffect(() => { setMounted(true) }, [])
- useEffect(() => {
- let active = true
- apiFetch(`/api/admin/timecards/${cardId}`).then(r => {
- if (!active) return
- if (r.success && r.data) { setCard(r.data); setEntries(r.data.entries ?? []) }
- else setError(r.error || t('draftLoadError'))
- })
- return () => { active = false }
+ const load = useCallback(async () => {
+ const r = await apiFetch(`/api/admin/timecards/${cardId}`)
+ if (r.success && r.data) { setCard(r.data); setEntries(r.data.entries ?? []) }
+ else setError(r.error || t('draftLoadError'))
}, [cardId, t])
+ // eslint-disable-next-line react-hooks/set-state-in-effect -- async fetch → setState resolves off-render
+ useEffect(() => { void load() }, [load])
+
const total = entries.reduce((s, e) => s + (Number(e.duration_minutes) || 0), 0)
const isApproved = card?.status === 'approved'
const isDraft = card?.status === 'draft' || card?.status === 'rejected'
@@ -95,7 +99,7 @@ export function TimecardReviewDrawer({
const save = async () => {
if (!card) return
- setBusy('save'); setError(null)
+ setBusy('save'); setError(null); setFlash(null)
const r = await apiFetch(`/api/admin/timecards/${cardId}`, {
method: 'PUT',
body: {
@@ -108,41 +112,51 @@ export function TimecardReviewDrawer({
setBusy(null)
if (!r.success) { setError(r.error || t('saveFailed')); return }
setEditing(false)
+ await load()
+ setFlash(t('reviewDoneSaved'))
onChanged()
}
const review = async (status: 'approved' | 'rejected') => {
- setBusy(status); setError(null)
+ setBusy(status); setError(null); setFlash(null)
const r = await apiFetch(`/api/admin/timecards/${cardId}`, {
method: 'PATCH',
body: { status, review_notes: note.trim() || null },
})
setBusy(null)
if (!r.success) { setError(r.error || t('actionFailed')); return }
+ setNote('')
+ await load()
+ setFlash(status === 'approved' ? t('reviewDoneApproved') : t('reviewDoneRejected'))
onChanged()
- onClose()
}
// Proxy path: submit a draft on the owner's behalf (audited, owner notified).
const submitOnBehalf = async () => {
- setBusy('submit'); setError(null)
+ setBusy('submit'); setError(null); setFlash(null)
const r = await apiFetch(`/api/admin/timecards/${cardId}/submit`, { method: 'POST' })
setBusy(null)
if (!r.success) { setError(r.error || t('actionFailed')); return }
+ await load()
+ setFlash(t('reviewDoneSubmitted'))
onChanged()
- onClose()
}
// Un-approve: back to draft so the owner (or approver) can rework it.
const reopen = async () => {
- setBusy('reopen'); setError(null)
+ setBusy('reopen'); setError(null); setFlash(null)
const r = await apiFetch(`/api/admin/timecards/${cardId}/reopen`, { method: 'POST' })
setBusy(null)
if (!r.success) { setError(r.error || t('actionFailed')); return }
+ await load()
+ setFlash(t('reviewDoneReopened'))
onChanged()
- onClose()
}
+ // Monatsrapport for this card's owner + month (the sheet the approver sends
+ // to the social worker) — the concrete next step after approving.
+ const reportHref = card ? `/admin/team/report/${card.user_id}/${card.period_start.slice(0, 7)}` : null
+
if (!mounted) return null
return createPortal(
@@ -179,6 +193,16 @@ export function TimecardReviewDrawer({
{error &&
{error}
}
+ {flash && (
+
+ {flash}
+ {isApproved && reportHref && (
+
+ {t('openReport')}
+
+ )}
+
+ )}
{!card ? (
{t('loading')}
) : entries.length === 0 ? (
@@ -299,6 +323,15 @@ export function TimecardReviewDrawer({
>
)}
+ {!editing && reportHref && (
+
+ {t('openReport')}
+
+ )}
,
diff --git a/src/components/timecards/TimeOffPanel.tsx b/src/components/timecards/TimeOffPanel.tsx
index 7da623712..662844586 100644
--- a/src/components/timecards/TimeOffPanel.tsx
+++ b/src/components/timecards/TimeOffPanel.tsx
@@ -41,6 +41,7 @@ export function TimeOffPanel() {
const [note, setNote] = useState('')
const [submitting, setSubmitting] = useState(false)
const [error, setError] = useState(null)
+ const [success, setSuccess] = useState(null)
const load = useCallback(async () => {
const res = await apiFetch('/api/time-off')
@@ -53,7 +54,7 @@ export function TimeOffPanel() {
}, [open, load])
const submit = async () => {
- setError(null)
+ setError(null); setSuccess(null)
if (!startsOn || !endsOn) {
setError(t('missingDates'))
return
@@ -71,6 +72,7 @@ export function TimeOffPanel() {
setStartsOn('')
setEndsOn('')
setNote('')
+ setSuccess(t('requestSubmitted'))
void load()
}
@@ -98,6 +100,11 @@ export function TimeOffPanel() {
{error}
)}
+ {success && (
+
+ {success}
+
+ )}
{/* Request form */}
diff --git a/src/components/timecards/TimecardMonthGrid.tsx b/src/components/timecards/TimecardMonthGrid.tsx
index 0032d666b..05671e8b7 100644
--- a/src/components/timecards/TimecardMonthGrid.tsx
+++ b/src/components/timecards/TimecardMonthGrid.tsx
@@ -106,6 +106,10 @@ export function TimecardMonthGrid({
return d === 0 ? 6 : d - 1
})()
+ // "Today" in Europe/Zurich (server saldo uses the same tz) — so the grid
+ // marks the real current day, not a UTC-shifted one near midnight.
+ const todayIso = new Intl.DateTimeFormat('en-CA', { timeZone: 'Europe/Zurich' }).format(new Date())
+
return (
{isSelected && (
@@ -204,14 +212,23 @@ export function TimecardMonthGrid({
)}
-
- {String(dayNum).padStart(2, '0')}
-
+ {isToday ? (
+
+
+ {String(dayNum).padStart(2, '0')}
+
+ {t('today')}
+
+ ) : (
+
+ {String(dayNum).padStart(2, '0')}
+
+ )}
{absence ? (
{entryCategoryLabel}
diff --git a/src/lib/services/report.ts b/src/lib/services/report.ts
index 4ab4aeb50..9128c4041 100644
--- a/src/lib/services/report.ts
+++ b/src/lib/services/report.ts
@@ -20,6 +20,12 @@ export interface MonthlyReport {
reviewerName: string | null
saldo: PersonSaldo | null
holidays: { date: string; name: string }[]
+ /** The date the figures are computed through (month-end, or today if the
+ * month is still running). Entries after this are not yet "worked". */
+ asOfDate: string
+ /** True while the month is still in progress — the sheet is a Zwischenstand,
+ * not a final record, and must not present future days as done. */
+ isInterim: boolean
}
function lastDayOfMonth(month: string): string {
@@ -28,6 +34,10 @@ function lastDayOfMonth(month: string): string {
return d.toISOString().slice(0, 10)
}
+function todayIsoZurich(): string {
+ return new Intl.DateTimeFormat('en-CA', { timeZone: 'Europe/Zurich' }).format(new Date())
+}
+
export async function getMonthlyReport(userId: string, month: string): Promise {
const [user] = await db
.select({ name: users.name, email: users.email })
@@ -66,8 +76,14 @@ export async function getMonthlyReport(userId: string, month: string): Promise null)
+ // A finished month reports its closing state (month-end). A month still in
+ // progress reports as of today — otherwise pre-filled future days would show
+ // as "worked" and the Soll/Ist/Saldo would diverge from the live dashboard.
+ const monthEnd = lastDayOfMonth(month)
+ const today = todayIsoZurich()
+ const asOfDate = today < monthEnd ? today : monthEnd
+ const isInterim = asOfDate < monthEnd
+ const saldo = await getPersonSaldo(userId, asOfDate).catch(() => null)
const year = Number(month.slice(0, 4))
const holidays = getPublicHolidays(year).filter(h => h.date.startsWith(month))
@@ -84,6 +100,8 @@ export async function getMonthlyReport(userId: string, month: string): Promise