feat(backend,manager): the business day opens and closes by itself (opening hours, a time, or only an alert)

- services/day_auto.py: a minute loop (venue time, offline) opens the day when the opening
  hours start (or at business_day.auto_open_time) and closes it when they end (or at
  auto_close_time); 'alert' only tells the managers. Offsets before / after, one day across
  the break or one per span, spans past midnight belong to the day they start, a day closed
  by hand isn't reopened in the same span, a restart catches up the open (until the business
  date changes for 'time') and alerts a missed close instead of doing it late.
- The close runs only when no order of the day is unclosed (Q-10): otherwise a sticky alert
  and a new try every 15 minutes. A locked / expired license turns the open into an alert.
- Sticky notifications: notifications.resolved_at + core.notifications.resolve(); the
  alerts resolve when the day opens / closes (by hand or by itself).
- services/business_days.py: the one open / close path (the routes and the loop); days opened
  or closed by the system have no opener / closer and opened_auto / closed_auto (Alembic 0052).
- Manager: Settings -> Operation "Opening and closing the day"; the bell's action buttons
  ("Open now", "Go to the overview"); Reports -> Days marks days opened / closed by itself.

Plan platform-v2 6F.8.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-23 13:17:15 +02:00
co-authored by Claude Opus 5.5
parent 7706bf2470
commit 096bd53dbd
21 changed files with 856 additions and 117 deletions
@@ -5,10 +5,15 @@
// `platform_notification` {id} and after every reconnect ('ready').
// - A NEW warning/critical one also pops up as a toast.
// - Opening an item marks it read; "Mark all as read" does the rest.
// - 6F.8: an item whose params carry an `action` gets a button: 'open_day' opens the business
// day here (POST /api/business-day/open), 'overview' goes to the overview. Those alerts stay
// until their cause is gone (the backend resolves them; a live event refreshes the list).
// Not staff chat (/api/notifications, the chat module), which stays separate.
import { useCallback, useEffect, useRef, useState } from 'react'
import toast from 'react-hot-toast'
import { useNavigate } from 'react-router-dom'
import { Bell, CheckCheck } from 'lucide-react'
import { errorMessage } from '@xenia/api'
import { useTranslation, useFormat } from '@xenia/i18n'
import client from '../api/client'
import { useLiveEvent } from '../live/useLiveEvent'
@@ -22,6 +27,7 @@ export default function NotificationBell() {
const [data, setData] = useState({ items: [], unread: 0 })
const [open, setOpen] = useState(false)
const ref = useRef(null)
const navigate = useNavigate()
const asked = useRef(0)
const load = useCallback(async () => {
@@ -74,6 +80,20 @@ export default function NotificationBell() {
load()
}
async function act(n) {
await markRead(n)
if (n.params?.action === 'overview') { setOpen(false); navigate('/'); return }
if (n.params?.action === 'open_day') {
try {
await client.post('/api/business-day/open', {})
toast.success(t('notifications.dayOpened'))
} catch (err) {
toast.error(errorMessage(err, t))
}
load()
}
}
const badge = data.unread > 9 ? '9+' : String(data.unread)
return (
@@ -109,11 +129,17 @@ export default function NotificationBell() {
: (
<ul className="max-h-[60vh] overflow-y-auto divide-y divide-line">
{data.items.map(n => (
<li key={n.id}>
<li key={n.id} className="relative">
{n.params?.action && (
<button onClick={() => act(n)} data-testid={`notif-action-${n.id}`}
className="absolute right-3 top-3 z-10 rounded-control border border-line bg-surface px-2.5 py-1 text-caption font-medium text-accent-ink hover:bg-surface-2">
{t(`notifications.actions.${n.params.action}`, { defaultValue: n.params.action })}
</button>
)}
<button onClick={() => markRead(n)} className={`w-full text-left flex gap-3 px-4 py-3 hover:bg-surface-2 ${n.read ? '' : 'bg-accent-soft/40'}`}
data-testid={`notif-${n.id}`} data-read={n.read ? 'true' : 'false'}>
<span className={`mt-1.5 h-2 w-2 shrink-0 rounded-full ${DOT[n.severity] || DOT.info}`} />
<span className="flex-1 min-w-0">
<span className={`flex-1 min-w-0 ${n.params?.action ? 'pr-28' : ''}`}>
<span className={`block text-label ${n.read ? 'text-ink-2' : 'text-ink font-medium'}`}>{n.message}</span>
<span className="block text-caption text-ink-3 mt-0.5">
{f.formatRelative(n.last_at)}