feat: major dashboard & waiter PWA overhaul
- Manager dashboard: replaced monolithic DashboardTab/OperationsPage with new DashboardPage; added OrderDetailModal, ShiftDetailModal, DeleteConfirmModal, PaymentMethodModal; updated Sidebar routing and App navigation - Reports: reworked WorkDaySummary, OrderHistory, ShiftsOverview with detail modals - Backend routers: extended orders, reports, shifts, products, business_day endpoints; updated cloud_sync service - Waiter PWA: refreshed app icons, improved ConnectionLostModal UX, updated TableCard, SSEContext, connectionStore; added useProductCache hook; vite config tweaks Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -69,6 +69,7 @@ export default function ReportsPage() {
|
||||
restaurant: 'today',
|
||||
ops: 'printer-history',
|
||||
})
|
||||
const [subProps, setSubProps] = useState({})
|
||||
|
||||
const parent = PARENT_TABS.find(t => t.id === activeParent)
|
||||
const activeSubId = activeSubByParent[activeParent]
|
||||
@@ -76,15 +77,26 @@ export default function ReportsPage() {
|
||||
const { Component: SubComponent } = sub
|
||||
|
||||
function setActiveSub(id) {
|
||||
setSubProps({})
|
||||
setActiveSubByParent(prev => ({ ...prev, [activeParent]: id }))
|
||||
}
|
||||
|
||||
function navigateTo({ parent: parentId, sub: subId, ...props }) {
|
||||
setSubProps(props)
|
||||
setActiveSubByParent(prev => ({ ...prev, [parentId]: subId }))
|
||||
setActiveParent(parentId)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex flex-col h-full min-h-0">
|
||||
<TabGroup tabs={PARENT_TABS} active={activeParent} onChange={setActiveParent} />
|
||||
<TabBar tabs={parent.subTabs} active={activeSubId} onChange={setActiveSub} />
|
||||
<div className="flex-1 min-h-0 flex flex-col">
|
||||
<SubComponent />
|
||||
<SubComponent
|
||||
key={`${activeParent}-${activeSubId}-${JSON.stringify(subProps)}`}
|
||||
onNavigate={navigateTo}
|
||||
{...subProps}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -3,7 +3,7 @@ import { useQuery } from '@tanstack/react-query'
|
||||
import client from '../../../api/client'
|
||||
import { FilterBar, FilterSelect, FilterDateInput, WorkDayDateToggle } from '../shared/FilterBar'
|
||||
import { Panel, DataTable, THead, TH, TR, TD, StatusBadge, WaiterAvatar, ChartTooltip } from '../shared/TablePrimitives'
|
||||
import DrillDownModal from '../shared/DrillDownModal'
|
||||
import OrderDetailModal from '../shared/OrderDetailModal'
|
||||
import EmptyState from '../shared/EmptyState'
|
||||
import SkeletonTable from '../shared/SkeletonTable'
|
||||
import ExportButton from '../shared/ExportButton'
|
||||
@@ -20,11 +20,11 @@ const STATUS_OPTIONS = [
|
||||
{ value: 'cancelled', label: 'Ακυρωμένη' },
|
||||
]
|
||||
|
||||
export default function OrderHistory() {
|
||||
const [mode, setMode] = useState('range')
|
||||
export default function OrderHistory({ initialBusinessDayId } = {}) {
|
||||
const [mode, setMode] = useState(initialBusinessDayId ? 'workday' : 'range')
|
||||
const [from, setFrom] = useState(monthAgo())
|
||||
const [to, setTo] = useState(today())
|
||||
const [businessDayId, setBusinessDayId] = useState('all')
|
||||
const [businessDayId, setBusinessDayId] = useState(initialBusinessDayId ? String(initialBusinessDayId) : 'all')
|
||||
const [statusF, setStatusF] = useState('all')
|
||||
const [waiterF, setWaiterF] = useState('all')
|
||||
const [tableF, setTableF] = useState('all')
|
||||
@@ -95,12 +95,12 @@ export default function OrderHistory() {
|
||||
</THead>
|
||||
<tbody>
|
||||
{orders.slice(0, 200).map(o => {
|
||||
const total = (o.items || []).filter(i => ['active', 'paid'].includes(i.status)).reduce((s, i) => s + i.unit_price * i.quantity, 0)
|
||||
const total = (o.items || []).filter(i => i.status !== 'cancelled').reduce((s, i) => s + i.unit_price * i.quantity, 0)
|
||||
const isCancelled = o.status === 'cancelled'
|
||||
return (
|
||||
<TR key={o.id} striped className={isCancelled ? 'opacity-50' : ''}>
|
||||
<TD mono>#{o.id}</TD>
|
||||
<TD>{o.table_id}</TD>
|
||||
<TD>{o.table_name ?? o.table_id}</TD>
|
||||
<TD mono>{fmtDateTime(o.opened_at)}</TD>
|
||||
<TD mono>{fmtDateTime(o.closed_at)}</TD>
|
||||
<TD><StatusBadge status={o.status} /></TD>
|
||||
@@ -130,45 +130,7 @@ export default function OrderHistory() {
|
||||
</div>
|
||||
|
||||
{drillOrder && (
|
||||
<DrillDownModal
|
||||
title={`Order #${drillOrder.id}`}
|
||||
subtitle={`${fmtDateTime(drillOrder.opened_at)} · Τραπέζι ${drillOrder.table_id}`}
|
||||
onClose={() => setDrillOrder(null)}
|
||||
>
|
||||
<div className="flex-1 overflow-y-auto p-6">
|
||||
<div className="mb-4 flex items-center gap-3">
|
||||
<StatusBadge status={drillOrder.status} />
|
||||
{drillOrder.notes && (
|
||||
<span className="rounded bg-amber-50 px-2 py-0.5 text-[11px] text-amber-800 ring-1 ring-inset ring-amber-200">
|
||||
Σημείωση: {drillOrder.notes}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<DataTable>
|
||||
<THead>
|
||||
<TH>Προϊόν</TH><TH align="right">Ποσ.</TH><TH align="right">Τιμή</TH><TH align="right">Υποσύνολο</TH><TH>Κατάσταση</TH>
|
||||
</THead>
|
||||
<tbody>
|
||||
{(drillOrder.items || []).map((item, i) => (
|
||||
<TR key={i} striped>
|
||||
<TD className="font-medium">{item.product?.name ?? `#${item.product_id}`}</TD>
|
||||
<TD mono align="right">×{item.quantity}</TD>
|
||||
<TD mono align="right">{fmtEUR(item.unit_price)}</TD>
|
||||
<TD mono align="right" className="font-semibold">{fmtEUR(item.unit_price * item.quantity)}</TD>
|
||||
<TD><StatusBadge status={item.status} /></TD>
|
||||
</TR>
|
||||
))}
|
||||
<tr className="bg-slate-50">
|
||||
<TD colSpan={3} className="py-3 text-right text-[11px] font-semibold uppercase tracking-wider text-slate-500">Σύνολο</TD>
|
||||
<TD mono align="right" className="py-3 text-base font-semibold text-slate-900">
|
||||
{fmtEUR((drillOrder.items || []).filter(i => ['active', 'paid'].includes(i.status)).reduce((s, i) => s + i.unit_price * i.quantity, 0))}
|
||||
</TD>
|
||||
<TD />
|
||||
</tr>
|
||||
</tbody>
|
||||
</DataTable>
|
||||
</div>
|
||||
</DrillDownModal>
|
||||
<OrderDetailModal order={drillOrder} onClose={() => setDrillOrder(null)} />
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -1,39 +1,208 @@
|
||||
import { useState } from 'react'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
import { Trash2 } from 'lucide-react'
|
||||
import toast from 'react-hot-toast'
|
||||
import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer } from 'recharts'
|
||||
import client from '../../../api/client'
|
||||
import { FilterBar, FilterDateInput } from '../shared/FilterBar'
|
||||
import { Panel, DataTable, THead, TH, TR, TD, StatusBadge, ChartTooltip } from '../shared/TablePrimitives'
|
||||
import { Panel, DataTable, THead, TH, TR, TD, StatusBadge, WaiterAvatar, ChartTooltip } from '../shared/TablePrimitives'
|
||||
import DrillDownModal from '../shared/DrillDownModal'
|
||||
import OrderDetailModal from '../shared/OrderDetailModal'
|
||||
import ShiftDetailModal from '../shared/ShiftDetailModal'
|
||||
import DeleteConfirmModal from '../../../ui/DeleteConfirmModal'
|
||||
import EmptyState from '../shared/EmptyState'
|
||||
import SkeletonTable from '../shared/SkeletonTable'
|
||||
import ExportButton from '../shared/ExportButton'
|
||||
import { fmtEUR, fmtNum, fmtDate, fmtTime, fmtDuration } from '../shared/reportDesignTokens'
|
||||
import { fmtEUR, fmtNum, fmtDate, fmtTime, fmtDuration, fmtDateTime } from '../shared/reportDesignTokens'
|
||||
|
||||
function today() { return new Date().toISOString().slice(0, 10) }
|
||||
function monthAgo() { const d = new Date(); d.setDate(d.getDate() - 30); return d.toISOString().slice(0, 10) }
|
||||
|
||||
// ── Workday drill-down modal ────────────────────────────────────────────────
|
||||
function WorkDayModal({ day, onClose, onDeleteShift }) {
|
||||
const [tab, setTab] = useState('orders')
|
||||
const [drillOrder, setDrillOrder] = useState(null)
|
||||
const [detailShift, setDetailShift] = useState(null)
|
||||
|
||||
const { data: ordersData } = useQuery({
|
||||
queryKey: ['business-day-orders', day.id],
|
||||
queryFn: () => client.get('/api/reports/orders/history', { params: { business_day_id: day.id, page_size: 200 } }).then(r => r.data),
|
||||
staleTime: 0,
|
||||
})
|
||||
|
||||
const { data: shiftsData } = useQuery({
|
||||
queryKey: ['shifts-for-day', day.id],
|
||||
queryFn: () => client.get('/api/reports/shifts', { params: { business_day_id: day.id } }).then(r => r.data),
|
||||
staleTime: 0,
|
||||
})
|
||||
|
||||
const orders = Array.isArray(ordersData) ? ordersData : []
|
||||
const shifts = shiftsData?.shifts || []
|
||||
|
||||
const TABS = [
|
||||
{ key: 'orders', label: `Παραγγελίες (${orders.length})` },
|
||||
{ key: 'shifts', label: `Βάρδιες (${shifts.length})` },
|
||||
]
|
||||
|
||||
return (
|
||||
<>
|
||||
<DrillDownModal
|
||||
title={`Εργάσιμη Μέρα · ${fmtDate(day.opened_at)}`}
|
||||
subtitle={`${fmtEUR(day.revenue)} έσοδα · ${fmtTime(day.opened_at)} – ${day.closed_at ? fmtTime(day.closed_at) : 'ανοιχτή'}`}
|
||||
onClose={onClose}
|
||||
>
|
||||
{/* Tabs */}
|
||||
<div className="flex border-b border-slate-200 px-6">
|
||||
{TABS.map(t => (
|
||||
<button
|
||||
key={t.key}
|
||||
onClick={() => setTab(t.key)}
|
||||
className={`px-4 py-2.5 text-[13px] font-medium border-b-2 transition-colors ${tab === t.key ? 'border-slate-800 text-slate-900' : 'border-transparent text-slate-500 hover:text-slate-700'}`}
|
||||
>
|
||||
{t.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* Orders tab */}
|
||||
{tab === 'orders' && (
|
||||
orders.length === 0
|
||||
? <div className="py-12 text-center text-slate-400 text-sm">Δεν βρέθηκαν παραγγελίες</div>
|
||||
: <DataTable>
|
||||
<THead>
|
||||
<TH>#</TH><TH>Τραπέζι</TH><TH>Άνοιξε</TH><TH>Έκλεισε</TH>
|
||||
<TH align="right">Είδη</TH><TH align="right">Σύνολο</TH><TH>Κατάσταση</TH>
|
||||
</THead>
|
||||
<tbody>
|
||||
{orders.map(o => {
|
||||
const total = (o.items || []).filter(i => i.status !== 'cancelled').reduce((s, i) => s + i.unit_price * i.quantity, 0)
|
||||
return (
|
||||
<TR key={o.id} striped onClick={() => setDrillOrder(o)} className="cursor-pointer">
|
||||
<TD mono>#{o.id}</TD>
|
||||
<TD>{o.table_name ?? o.table_id}</TD>
|
||||
<TD mono>{fmtDateTime(o.opened_at)}</TD>
|
||||
<TD mono>{o.closed_at ? fmtDateTime(o.closed_at) : '—'}</TD>
|
||||
<TD mono align="right">{(o.items || []).length}</TD>
|
||||
<TD mono align="right" className="font-semibold text-slate-900">{fmtEUR(total)}</TD>
|
||||
<TD><StatusBadge status={o.status} /></TD>
|
||||
</TR>
|
||||
)
|
||||
})}
|
||||
</tbody>
|
||||
</DataTable>
|
||||
)}
|
||||
|
||||
{/* Shifts tab */}
|
||||
{tab === 'shifts' && (
|
||||
shifts.length === 0
|
||||
? <div className="py-12 text-center text-slate-400 text-sm">Δεν βρέθηκαν βάρδιες</div>
|
||||
: <DataTable>
|
||||
<THead>
|
||||
<TH>Σερβιτόρος</TH>
|
||||
<TH>Έναρξη</TH>
|
||||
<TH>Λήξη</TH>
|
||||
<TH align="right">Διάρκεια</TH>
|
||||
<TH align="right">Εισπράχθηκαν</TH>
|
||||
<TH>Κατάσταση</TH>
|
||||
<TH className="w-20" />
|
||||
</THead>
|
||||
<tbody>
|
||||
{shifts.map(s => (
|
||||
<TR key={s.id} striped onClick={() => setDetailShift(s)} className="cursor-pointer">
|
||||
<TD><WaiterAvatar name={s.waiter_name} id={s.waiter_id} /></TD>
|
||||
<TD mono>{fmtDateTime(s.started_at)}</TD>
|
||||
<TD mono>{s.ended_at ? fmtDateTime(s.ended_at) : <span className="text-sky-600 font-medium">— ενεργή —</span>}</TD>
|
||||
<TD mono align="right">{fmtDuration(s.started_at, s.ended_at)}</TD>
|
||||
<TD mono align="right">{fmtEUR(s.total_collected)}</TD>
|
||||
<TD><StatusBadge status={s.is_active ? 'active' : 'closed'} pulse /></TD>
|
||||
<TD align="right">
|
||||
<div className="flex items-center justify-end gap-2">
|
||||
<button
|
||||
onClick={e => { e.stopPropagation(); setDetailShift(s) }}
|
||||
className="rounded border border-slate-200 bg-white px-2 py-0.5 text-[11px] font-medium text-slate-600 hover:bg-slate-50"
|
||||
>
|
||||
Λεπτομέρειες
|
||||
</button>
|
||||
{!s.is_active && (
|
||||
<button
|
||||
onClick={e => { e.stopPropagation(); onDeleteShift(s) }}
|
||||
className="rounded border border-red-200 bg-white p-0.5 text-red-400 hover:bg-red-50 hover:text-red-600"
|
||||
title="Διαγραφή βάρδιας"
|
||||
>
|
||||
<Trash2 size={13} />
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</TD>
|
||||
</TR>
|
||||
))}
|
||||
</tbody>
|
||||
</DataTable>
|
||||
)}
|
||||
</DrillDownModal>
|
||||
|
||||
{drillOrder && (
|
||||
<OrderDetailModal order={drillOrder} onClose={() => setDrillOrder(null)} />
|
||||
)}
|
||||
|
||||
{detailShift && (
|
||||
<ShiftDetailModal
|
||||
shiftId={detailShift.id}
|
||||
shiftWaiterId={detailShift.waiter_id}
|
||||
onClose={() => setDetailShift(null)}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
// ── Main page ───────────────────────────────────────────────────────────────
|
||||
export default function WorkDaySummary() {
|
||||
const [from, setFrom] = useState(monthAgo())
|
||||
const [to, setTo] = useState(today())
|
||||
const [drillId, setDrillId] = useState(null)
|
||||
const [drillDay, setDrillDay] = useState(null)
|
||||
const [deleteDay, setDeleteDay] = useState(null)
|
||||
const [deleteShift, setDeleteShift] = useState(null)
|
||||
|
||||
const qc = useQueryClient()
|
||||
|
||||
const { data, isLoading, isError, refetch } = useQuery({
|
||||
queryKey: ['business-days', from, to],
|
||||
queryFn: () => client.get('/api/reports/business-days', { params: { from: from + 'T00:00:00', to: to + 'T23:59:59' } }).then(r => r.data),
|
||||
staleTime: 60 * 1000,
|
||||
staleTime: 0,
|
||||
})
|
||||
|
||||
const { data: drillData } = useQuery({
|
||||
queryKey: ['business-day-orders', drillId],
|
||||
queryFn: () => client.get('/api/reports/orders/history', { params: { business_day_id: drillId, page_size: 200 } }).then(r => r.data),
|
||||
enabled: !!drillId,
|
||||
staleTime: 60 * 1000,
|
||||
const deleteDayMutation = useMutation({
|
||||
mutationFn: (id) => client.delete(`/api/business-day/${id}`),
|
||||
onSuccess: () => {
|
||||
toast.success('Η εργάσιμη μέρα διαγράφηκε')
|
||||
qc.invalidateQueries({ queryKey: ['business-days'] })
|
||||
qc.invalidateQueries({ queryKey: ['business-days-list'] })
|
||||
setDeleteDay(null)
|
||||
},
|
||||
onError: (err) => {
|
||||
toast.error(err?.response?.data?.detail || 'Σφάλμα διαγραφής εργάσιμης μέρας')
|
||||
setDeleteDay(null)
|
||||
},
|
||||
})
|
||||
|
||||
const deleteShiftMutation = useMutation({
|
||||
mutationFn: (id) => client.delete(`/api/shifts/${id}`),
|
||||
onSuccess: () => {
|
||||
toast.success('Η βάρδια και οι παραγγελίες της διαγράφηκαν')
|
||||
qc.invalidateQueries({ queryKey: ['shifts'] })
|
||||
qc.invalidateQueries({ queryKey: ['shifts-for-day'] })
|
||||
qc.invalidateQueries({ queryKey: ['business-days'] })
|
||||
qc.invalidateQueries({ queryKey: ['business-days-list'] })
|
||||
setDeleteShift(null)
|
||||
},
|
||||
onError: (err) => {
|
||||
toast.error(err?.response?.data?.detail || 'Σφάλμα διαγραφής βάρδιας')
|
||||
setDeleteShift(null)
|
||||
},
|
||||
})
|
||||
|
||||
const days = data?.business_days || []
|
||||
const drillDay = drillId ? days.find(d => d.id === drillId) : null
|
||||
const drillOrders = Array.isArray(drillData) ? drillData : []
|
||||
|
||||
const chartData = [...days].reverse().map(d => ({
|
||||
date: fmtDate(d.opened_at),
|
||||
@@ -90,10 +259,11 @@ export default function WorkDaySummary() {
|
||||
<TH align="right">Ακυρώσεις</TH>
|
||||
<TH align="right">Σερβιτόροι</TH>
|
||||
<TH>Κατάσταση</TH>
|
||||
<TH className="w-10" />
|
||||
</THead>
|
||||
<tbody>
|
||||
{days.map(d => (
|
||||
<TR key={d.id} onClick={() => setDrillId(d.id)} striped>
|
||||
<TR key={d.id} onClick={() => setDrillDay(d)} striped>
|
||||
<TD className="font-medium text-slate-900">{fmtDate(d.opened_at)}</TD>
|
||||
<TD mono>{fmtTime(d.opened_at)}</TD>
|
||||
<TD mono>{d.closed_at ? fmtTime(d.closed_at) : '—'}</TD>
|
||||
@@ -103,6 +273,18 @@ export default function WorkDaySummary() {
|
||||
<TD mono align="right">{fmtNum(d.cancellation_count)}</TD>
|
||||
<TD mono align="right">{fmtNum(d.waiter_count)}</TD>
|
||||
<TD><StatusBadge status={d.status} pulse /></TD>
|
||||
<TD align="right">
|
||||
{d.status === 'closed' && (
|
||||
<button
|
||||
onClick={e => { e.stopPropagation(); setDeleteDay(d) }}
|
||||
className={`rounded border p-0.5 bg-white ${(d.shift_count ?? 0) === 0 ? 'border-red-200 text-red-400 hover:bg-red-50 hover:text-red-600' : 'border-slate-200 text-slate-300 cursor-not-allowed'}`}
|
||||
title={(d.shift_count ?? 0) === 0 ? 'Διαγραφή εργάσιμης μέρας' : `Έχει ${d.shift_count} βάρδιες — διαγράψτε τες πρώτα`}
|
||||
disabled={(d.shift_count ?? 0) > 0}
|
||||
>
|
||||
<Trash2 size={13} />
|
||||
</button>
|
||||
)}
|
||||
</TD>
|
||||
</TR>
|
||||
))}
|
||||
</tbody>
|
||||
@@ -113,32 +295,29 @@ export default function WorkDaySummary() {
|
||||
</div>
|
||||
|
||||
{drillDay && (
|
||||
<DrillDownModal
|
||||
title={`Εργάσιμη Μέρα · ${fmtDate(drillDay.opened_at)}`}
|
||||
subtitle={`${drillOrders.length} παραγγελίες · ${fmtEUR(drillDay.revenue)} έσοδα`}
|
||||
onClose={() => setDrillId(null)}
|
||||
>
|
||||
<DataTable>
|
||||
<THead>
|
||||
<TH>#</TH><TH>Τραπέζι</TH><TH>Άνοιξε</TH><TH>Έκλεισε</TH><TH align="right">Σύνολο</TH><TH>Κατάσταση</TH>
|
||||
</THead>
|
||||
<tbody>
|
||||
{drillOrders.map(o => {
|
||||
const total = (o.items || []).filter(i => ['active', 'paid'].includes(i.status)).reduce((s, i) => s + i.unit_price * i.quantity, 0)
|
||||
return (
|
||||
<TR key={o.id} striped>
|
||||
<TD mono>#{o.id}</TD>
|
||||
<TD>{o.table_id}</TD>
|
||||
<TD mono>{fmtDate(o.opened_at)} {fmtTime(o.opened_at)}</TD>
|
||||
<TD mono>{o.closed_at ? fmtTime(o.closed_at) : '—'}</TD>
|
||||
<TD mono align="right" className="font-semibold">{fmtEUR(total)}</TD>
|
||||
<TD><StatusBadge status={o.status} /></TD>
|
||||
</TR>
|
||||
)
|
||||
})}
|
||||
</tbody>
|
||||
</DataTable>
|
||||
</DrillDownModal>
|
||||
<WorkDayModal
|
||||
day={drillDay}
|
||||
onClose={() => setDrillDay(null)}
|
||||
onDeleteShift={s => setDeleteShift(s)}
|
||||
/>
|
||||
)}
|
||||
|
||||
{deleteDay && (
|
||||
<DeleteConfirmModal
|
||||
title={`Διαγραφή Εργάσιμης Μέρας #${deleteDay.id}`}
|
||||
description={`Η εργάσιμη μέρα της ${fmtDate(deleteDay.opened_at)} θα διαγραφεί μόνιμα. Δεν έχει βάρδιες.`}
|
||||
onConfirm={() => deleteDayMutation.mutate(deleteDay.id)}
|
||||
onCancel={() => setDeleteDay(null)}
|
||||
/>
|
||||
)}
|
||||
|
||||
{deleteShift && (
|
||||
<DeleteConfirmModal
|
||||
title={`Διαγραφή Βάρδιας #${deleteShift.id}`}
|
||||
description={`Η βάρδια του ${deleteShift.waiter_name} (${fmtDateTime(deleteShift.started_at)}) και ΟΛΕΣ οι παραγγελίες της θα διαγραφούν μόνιμα.`}
|
||||
onConfirm={() => deleteShiftMutation.mutate(deleteShift.id)}
|
||||
onCancel={() => setDeleteShift(null)}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -0,0 +1,286 @@
|
||||
import { useState } from 'react'
|
||||
import { X } from 'lucide-react'
|
||||
import { fmtEUR, fmtDateTime } from './reportDesignTokens'
|
||||
|
||||
// ── Status badge ────────────────────────────────────────────────────────────
|
||||
const STATUS_META = {
|
||||
active: { label: 'Ενεργό', bg: '#eff6ff', text: '#1d4ed8' },
|
||||
paid: { label: 'Πληρωμένο', bg: '#f0fdf4', text: '#15803d' },
|
||||
cancelled: { label: 'Ακυρωμένο', bg: '#fef2f2', text: '#b91c1c' },
|
||||
closed: { label: 'Κλειστό (απλήρωτο)', bg: '#fffbeb', text: '#b45309' },
|
||||
open: { label: 'Ανοιχτή', bg: '#eff6ff', text: '#1d4ed8' },
|
||||
partially_paid: { label: 'Μερική πλ.', bg: '#fffbeb', text: '#b45309' },
|
||||
}
|
||||
function StatusPill({ status }) {
|
||||
const m = STATUS_META[status] || { label: status, bg: '#f9fafb', text: '#374151' }
|
||||
return (
|
||||
<span style={{ fontSize: 10, fontWeight: 700, padding: '2px 7px', borderRadius: 20, background: m.bg, color: m.text }}>
|
||||
{m.label}
|
||||
</span>
|
||||
)
|
||||
}
|
||||
|
||||
// ── Payment method chip ─────────────────────────────────────────────────────
|
||||
const PAY_METHOD_STYLES = {
|
||||
cash: { label: 'ΜΕΤΡΗΤΑ', color: '#15803d', bg: '#f0fdf4', border: '#86efac' },
|
||||
card: { label: 'ΚΑΡΤΑ', color: '#1d4ed8', bg: '#eff6ff', border: '#93c5fd' },
|
||||
transfer: { label: 'ΤΡΑΠΕΖΙΚΗ', color: '#6d28d9', bg: '#f5f3ff', border: '#c4b5fd' },
|
||||
treat: { label: 'ΚΕΡΑΣΤΗΚΕ', color: '#b45309', bg: '#fffbeb', border: '#fcd34d' },
|
||||
comp: { label: 'ΚΕΡΑΣΤΗΚΕ', color: '#b45309', bg: '#fffbeb', border: '#fcd34d' },
|
||||
}
|
||||
function PayMethodChip({ method }) {
|
||||
if (!method) return <span style={{ color: '#b8bdc4', fontSize: 12 }}>—</span>
|
||||
const s = PAY_METHOD_STYLES[method] || { label: method.toUpperCase(), color: '#374151', bg: '#f3f4f6', border: '#d1d5db' }
|
||||
return (
|
||||
<span style={{ fontSize: 10, fontWeight: 700, padding: '2px 7px', borderRadius: 6, background: s.bg, color: s.color, border: `1px solid ${s.border}`, letterSpacing: 0.3, whiteSpace: 'nowrap' }}>
|
||||
{s.label}
|
||||
</span>
|
||||
)
|
||||
}
|
||||
|
||||
// ── Audit event labels ──────────────────────────────────────────────────────
|
||||
const EVENT_LABELS = {
|
||||
ORDER_OPENED: { label: 'Άνοιγμα', bg: '#eff6ff', text: '#1d4ed8' },
|
||||
ITEMS_ADDED: { label: 'Προσθήκη', bg: '#eff6ff', text: '#1d4ed8' },
|
||||
PAYMENT: { label: 'Πληρωμή', bg: '#f0fdf4', text: '#15803d' },
|
||||
PAYMENT_OFFLINE: { label: 'Πληρωμή (Offline)', bg: '#fffbeb', text: '#b45309' },
|
||||
ORDER_CLOSED: { label: 'Κλείσιμο', bg: '#f9fafb', text: '#374151' },
|
||||
ORDER_CANCELLED: { label: 'Ακύρωση', bg: '#fef2f2', text: '#b91c1c' },
|
||||
ITEM_CANCELLED: { label: 'Ακύρωση αντ.', bg: '#fef2f2', text: '#b91c1c' },
|
||||
}
|
||||
|
||||
function AuditTimeline({ logs, itemsById }) {
|
||||
if (!logs || logs.length === 0) {
|
||||
return <p style={{ color: '#b8bdc4', fontSize: 13, textAlign: 'center', padding: '16px 0' }}>Δεν υπάρχουν εγγραφές</p>
|
||||
}
|
||||
return (
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 0 }}>
|
||||
{logs.map(log => {
|
||||
const meta = EVENT_LABELS[log.event_type] || { label: log.event_type, bg: '#f9fafb', text: '#374151' }
|
||||
const isDuplicate = log.is_duplicate === 1 || log.is_duplicate === true
|
||||
const displayTime = log.offline_at ? fmtDateTime(log.offline_at) : fmtDateTime(log.created_at)
|
||||
|
||||
let itemNames = []
|
||||
if (log.item_ids && itemsById) {
|
||||
try {
|
||||
const ids = JSON.parse(log.item_ids)
|
||||
itemNames = ids.map(id => {
|
||||
const item = itemsById[id]
|
||||
return item ? `${item.product?.name ?? `#${item.product_id}`} ×${item.quantity}` : null
|
||||
}).filter(Boolean)
|
||||
} catch { /* ignore */ }
|
||||
}
|
||||
|
||||
return (
|
||||
<div key={log.id} style={{
|
||||
display: 'flex', alignItems: 'flex-start', gap: 10, padding: '8px 0',
|
||||
borderBottom: '1px solid #f4f4f2',
|
||||
background: isDuplicate ? '#fef2f2' : 'transparent',
|
||||
}}>
|
||||
<div style={{ flexShrink: 0, paddingTop: 2 }}>
|
||||
<span style={{ fontSize: 10, fontWeight: 700, padding: '2px 7px', borderRadius: 10, background: isDuplicate ? '#fecaca' : meta.bg, color: isDuplicate ? '#b91c1c' : meta.text }}>
|
||||
{meta.label}
|
||||
</span>
|
||||
{isDuplicate && <div style={{ fontSize: 10, color: '#dc2626', fontWeight: 700, marginTop: 2 }}>ΔΙΠΛΗ</div>}
|
||||
</div>
|
||||
<div style={{ flex: 1, minWidth: 0 }}>
|
||||
<div style={{ fontSize: 13, color: '#374151', fontWeight: 500, display: 'flex', alignItems: 'center', gap: 6, flexWrap: 'wrap' }}>
|
||||
<span>{log.waiter_name ?? (log.waiter_id ? `#${log.waiter_id}` : '—')}</span>
|
||||
{log.amount != null && (
|
||||
<span style={{ fontWeight: 700, color: isDuplicate ? '#dc2626' : '#2f9e5e' }}>
|
||||
{fmtEUR(log.amount)}
|
||||
</span>
|
||||
)}
|
||||
{log.payment_method && <PayMethodChip method={log.payment_method} />}
|
||||
</div>
|
||||
{itemNames.length > 0 && (
|
||||
<div style={{ marginTop: 3, display: 'flex', flexWrap: 'wrap', gap: 4 }}>
|
||||
{itemNames.map((name, i) => (
|
||||
<span key={i} style={{ fontSize: 11, background: '#f3f4f6', color: '#374151', padding: '1px 6px', borderRadius: 4 }}>
|
||||
{name}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div style={{ fontSize: 11, color: '#9ca3af', textAlign: 'right', flexShrink: 0 }}>
|
||||
{displayTime}
|
||||
{log.offline_at && <div style={{ fontSize: 10, color: '#f59e0b' }}>offline</div>}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ── Items tab ───────────────────────────────────────────────────────────────
|
||||
function ItemsTab({ order }) {
|
||||
const itemsFiltered = order.items || []
|
||||
const billableItems = itemsFiltered.filter(i => i.status !== 'cancelled')
|
||||
const closedTotal = billableItems.filter(i => i.status === 'closed').reduce((s, i) => s + i.unit_price * i.quantity, 0)
|
||||
const total = billableItems.reduce((s, i) => s + i.unit_price * i.quantity, 0)
|
||||
|
||||
if (itemsFiltered.length === 0) {
|
||||
return <p style={{ color: '#b8bdc4', fontSize: 13, textAlign: 'center', padding: '12px 0' }}>Κανένα αντικείμενο</p>
|
||||
}
|
||||
|
||||
// Column widths: [item info] [ordered by] [paid by] [pay type] [total]
|
||||
const GRID = '1fr 150px 150px 110px 80px'
|
||||
|
||||
return (
|
||||
<div style={{ borderRadius: 10, border: '1px solid #edeff1', overflow: 'hidden', marginBottom: 16 }}>
|
||||
{/* Header */}
|
||||
<div style={{ display: 'grid', gridTemplateColumns: GRID, background: '#f9fafb', padding: '6px 14px', fontSize: 10, fontWeight: 700, color: '#8a9099', textTransform: 'uppercase', letterSpacing: 0.4, gap: 12 }}>
|
||||
<span>Προϊόν</span>
|
||||
<span>Παρήγγειλε</span>
|
||||
<span>Πλήρωσε</span>
|
||||
<span>Τρόπος</span>
|
||||
<span style={{ textAlign: 'right' }}>Σύνολο</span>
|
||||
</div>
|
||||
|
||||
{itemsFiltered.map(item => {
|
||||
const isCancelled = item.status === 'cancelled'
|
||||
return (
|
||||
<div key={item.id} style={{
|
||||
display: 'grid', gridTemplateColumns: GRID, gap: 12,
|
||||
padding: '9px 14px', borderTop: '1px solid #f4f4f2',
|
||||
opacity: isCancelled ? 0.45 : 1,
|
||||
background: isCancelled ? '#fef2f2' : item.status === 'closed' ? '#fffbeb' : 'white',
|
||||
}}>
|
||||
{/* Item info */}
|
||||
<div>
|
||||
<div style={{ fontSize: 13, fontWeight: 600, color: '#111315', textDecoration: isCancelled ? 'line-through' : 'none' }}>
|
||||
{item.product?.name ?? `#${item.product_id}`}
|
||||
</div>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 6, marginTop: 3, flexWrap: 'wrap' }}>
|
||||
<span style={{ fontSize: 12, color: '#8a9099', fontFamily: 'ui-monospace,monospace' }}>×{item.quantity}</span>
|
||||
<span style={{ fontSize: 12, color: '#374151', fontFamily: 'ui-monospace,monospace' }}>{fmtEUR(item.unit_price)}</span>
|
||||
<StatusPill status={item.status} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Ordered by */}
|
||||
<div style={{ fontSize: 11, paddingTop: 2 }}>
|
||||
<div style={{ fontWeight: 600, color: '#374151' }}>{item.added_by_name ?? '—'}</div>
|
||||
{item.added_at && <div style={{ color: '#9ca3af', marginTop: 1 }}>{fmtDateTime(item.added_at)}</div>}
|
||||
</div>
|
||||
|
||||
{/* Paid by */}
|
||||
<div style={{ fontSize: 11, paddingTop: 2 }}>
|
||||
{item.paid_by_name
|
||||
? <>
|
||||
<div style={{ fontWeight: 600, color: '#15803d' }}>{item.paid_by_name}</div>
|
||||
{item.paid_at && <div style={{ color: '#9ca3af', marginTop: 1 }}>{fmtDateTime(item.paid_at)}</div>}
|
||||
</>
|
||||
: <span style={{ color: '#b8bdc4' }}>—</span>
|
||||
}
|
||||
</div>
|
||||
|
||||
{/* Pay type */}
|
||||
<div style={{ paddingTop: 2 }}>
|
||||
<PayMethodChip method={item.payment_method} />
|
||||
</div>
|
||||
|
||||
{/* Total */}
|
||||
<div style={{ fontSize: 13, fontWeight: 700, color: '#111315', textAlign: 'right', fontFamily: 'ui-monospace,monospace', paddingTop: 2 }}>
|
||||
{fmtEUR(item.unit_price * item.quantity)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
|
||||
{/* Totals footer */}
|
||||
<div style={{ display: 'flex', justifyContent: 'flex-end', padding: '8px 14px', background: '#f9fafb', borderTop: '1px solid #edeff1', gap: 16, alignItems: 'center', flexWrap: 'wrap' }}>
|
||||
{closedTotal > 0 && (
|
||||
<span style={{ fontSize: 11, color: '#b45309' }}>
|
||||
Απλήρωτα κλειστά: <span style={{ fontWeight: 700 }}>{fmtEUR(closedTotal)}</span>
|
||||
</span>
|
||||
)}
|
||||
<span style={{ fontSize: 11, fontWeight: 700, color: '#8a9099', textTransform: 'uppercase', letterSpacing: 0.4 }}>Σύνολο</span>
|
||||
<span style={{ fontSize: 15, fontWeight: 700, color: '#111315', fontFamily: 'ui-monospace,monospace' }}>{fmtEUR(total)}</span>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ── Main modal ──────────────────────────────────────────────────────────────
|
||||
export default function OrderDetailModal({ order, onClose }) {
|
||||
const [tab, setTab] = useState('items')
|
||||
if (!order) return null
|
||||
|
||||
const itemsById = Object.fromEntries((order.items || []).map(i => [i.id, i]))
|
||||
|
||||
const TABS = [
|
||||
{ key: 'items', label: `Αντικείμενα (${(order.items || []).length})` },
|
||||
{ key: 'audit', label: 'Ιστορικό Συναλλαγών' },
|
||||
]
|
||||
|
||||
return (
|
||||
<div
|
||||
style={{ position: 'fixed', inset: 0, background: 'rgba(0,0,0,0.5)', zIndex: 9999, display: 'flex', alignItems: 'center', justifyContent: 'center', padding: 20 }}
|
||||
onClick={onClose}
|
||||
>
|
||||
<div
|
||||
style={{ background: 'white', borderRadius: 20, width: '100%', maxWidth: 1032, maxHeight: '92vh', display: 'flex', flexDirection: 'column', boxShadow: '0 24px 64px rgba(0,0,0,0.25)' }}
|
||||
onClick={e => e.stopPropagation()}
|
||||
>
|
||||
{/* Header */}
|
||||
<div style={{ padding: '18px 24px', borderBottom: '1px solid #edeff1', flexShrink: 0, display: 'flex', justifyContent: 'space-between', alignItems: 'flex-start' }}>
|
||||
<div>
|
||||
<div style={{ fontSize: 17, fontWeight: 700, color: '#111315', display: 'flex', alignItems: 'center', gap: 10 }}>
|
||||
Παραγγελία #{order.id}
|
||||
<StatusPill status={order.status} />
|
||||
</div>
|
||||
<div style={{ fontSize: 13, color: '#5a6169', marginTop: 3 }}>
|
||||
{order.table_name ? `Τραπέζι ${order.table_name}` : order.table_id ? `Τραπέζι #${order.table_id}` : ''}
|
||||
{order.notes && <span style={{ marginLeft: 8, color: '#d97706' }}>· Σημ: {order.notes}</span>}
|
||||
</div>
|
||||
</div>
|
||||
<button onClick={onClose} style={{ background: 'none', border: 'none', cursor: 'pointer', color: '#8a9099', padding: 4 }}>
|
||||
<X size={18} />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Opener / closer strip */}
|
||||
<div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 1, background: '#edeff1', borderBottom: '1px solid #edeff1', flexShrink: 0 }}>
|
||||
{[
|
||||
{ label: 'Άνοιξε', name: order.opened_by_name, time: order.opened_at },
|
||||
{ label: 'Έκλεισε', name: order.closed_by_name, time: order.closed_at },
|
||||
].map(cell => (
|
||||
<div key={cell.label} style={{ background: 'white', padding: '10px 20px' }}>
|
||||
<div style={{ fontSize: 10, fontWeight: 700, color: '#8a9099', textTransform: 'uppercase', letterSpacing: 0.5, marginBottom: 2 }}>{cell.label}</div>
|
||||
<div style={{ fontSize: 13, fontWeight: 600, color: cell.name ? '#111315' : '#b8bdc4' }}>{cell.name ?? '—'}</div>
|
||||
{cell.time && <div style={{ fontSize: 11, color: '#9ca3af', marginTop: 1 }}>{fmtDateTime(cell.time)}</div>}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* Tabs */}
|
||||
<div style={{ display: 'flex', gap: 0, borderBottom: '1px solid #edeff1', flexShrink: 0, padding: '0 24px' }}>
|
||||
{TABS.map(t => (
|
||||
<button
|
||||
key={t.key}
|
||||
onClick={() => setTab(t.key)}
|
||||
style={{
|
||||
padding: '10px 16px', fontSize: 12, fontWeight: 600,
|
||||
color: tab === t.key ? '#111315' : '#8a9099',
|
||||
borderBottom: tab === t.key ? '2px solid #111315' : '2px solid transparent',
|
||||
background: 'none', border: 'none', borderBottom: tab === t.key ? '2px solid #111315' : '2px solid transparent',
|
||||
cursor: 'pointer', transition: 'color 0.15s',
|
||||
}}
|
||||
>
|
||||
{t.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* Tab content */}
|
||||
<div style={{ flex: 1, overflowY: 'auto', padding: '16px 24px' }}>
|
||||
{tab === 'items' && <ItemsTab order={order} />}
|
||||
{tab === 'audit' && <AuditTimeline logs={order.audit_logs} itemsById={itemsById} />}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,263 @@
|
||||
import { useState } from 'react'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { X } from 'lucide-react'
|
||||
import client from '../../../api/client'
|
||||
import { fmtEUR, fmtDateTime, fmtTime, fmtDate } from './reportDesignTokens'
|
||||
|
||||
// ── colour rules ────────────────────────────────────────────────────────────
|
||||
// Given the shift's waiter_id and one item, return { key, label, colors }
|
||||
function classify(item, shiftWaiterId) {
|
||||
const orderedByMe = item.added_by_id === shiftWaiterId
|
||||
const paidToMe = item.paid_by_id === shiftWaiterId
|
||||
const isPaid = item.status === 'paid'
|
||||
|
||||
if (orderedByMe && paidToMe && isPaid)
|
||||
return { key: 'both', label: 'Παρήγγειλε + Πληρώθηκε', dot: '#16a34a', bg: '#f0fdf4', border: '#bbf7d0', text: '#15803d' }
|
||||
if (!orderedByMe && paidToMe && isPaid)
|
||||
return { key: 'paid', label: 'Πληρώθηκε (άλλος παρήγγειλε)', dot: '#2563eb', bg: '#eff6ff', border: '#bfdbfe', text: '#1d4ed8' }
|
||||
if (orderedByMe && isPaid && !paidToMe)
|
||||
return { key: 'ordered', label: 'Παρήγγειλε (Πληρώθηκε άλλος)', dot: '#ca8a04', bg: '#fefce8', border: '#fef08a', text: '#854d0e' }
|
||||
if (orderedByMe && !isPaid)
|
||||
return { key: 'unpaid', label: 'Παρήγγειλε (απλήρωτο)', dot: '#ea580c', bg: '#fff7ed', border: '#fed7aa', text: '#c2410c' }
|
||||
// fallback: paid to me but status not 'paid' — data anomaly
|
||||
return { key: 'anomaly', label: 'Ανωμαλία δεδομένων', dot: '#dc2626', bg: '#fef2f2', border: '#fecaca', text: '#b91c1c' }
|
||||
}
|
||||
|
||||
const FILTER_OPTIONS = [
|
||||
{ key: 'all', label: 'Όλα' },
|
||||
{ key: 'both', label: 'Παρήγγειλε + Πληρώθηκε' },
|
||||
{ key: 'paid', label: 'Πληρώθηκε (ξένη παραγγελία)' },
|
||||
{ key: 'ordered', label: 'Παρήγγειλε (Πληρώθηκε άλλος)' },
|
||||
{ key: 'unpaid', label: 'Απλήρωτα' },
|
||||
]
|
||||
|
||||
function fmtMins(mins) {
|
||||
if (mins == null) return '—'
|
||||
const h = Math.floor(mins / 60)
|
||||
const m = mins % 60
|
||||
return h > 0 ? `${h}ω ${m}λ` : `${m}λ`
|
||||
}
|
||||
|
||||
function ItemRow({ item, shiftWaiterId }) {
|
||||
const c = classify(item, shiftWaiterId)
|
||||
return (
|
||||
<div style={{
|
||||
display: 'flex', alignItems: 'flex-start', gap: 10, padding: '7px 14px',
|
||||
borderTop: '1px solid #f4f4f2', background: c.bg,
|
||||
}}>
|
||||
{/* colour dot */}
|
||||
<div style={{ width: 8, height: 8, borderRadius: '50%', background: c.dot, flexShrink: 0, marginTop: 5 }} />
|
||||
<div style={{ flex: 1, minWidth: 0 }}>
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'baseline', gap: 8 }}>
|
||||
<span style={{ fontSize: 13, fontWeight: 600, color: '#111315' }}>
|
||||
{item.product_name}
|
||||
<span style={{ fontWeight: 400, color: '#8a9099', marginLeft: 4 }}>×{item.quantity}</span>
|
||||
</span>
|
||||
<span style={{ fontSize: 13, fontWeight: 700, color: '#111315', flexShrink: 0 }}>{fmtEUR(item.subtotal)}</span>
|
||||
</div>
|
||||
<div style={{ display: 'flex', flexWrap: 'wrap', gap: '2px 12px', marginTop: 2 }}>
|
||||
<span style={{ fontSize: 11, color: '#5a6169' }}>
|
||||
Παρήγγειλε: <span style={{ fontWeight: 600, color: '#374151' }}>{item.added_by_name ?? '—'}</span>
|
||||
{item.added_at ? <span style={{ color: '#9ca3af' }}> · {fmtDateTime(item.added_at)}</span> : null}
|
||||
</span>
|
||||
<span style={{ fontSize: 11, color: '#5a6169' }}>
|
||||
Πληρώθηκε: <span style={{ fontWeight: 600, color: item.paid_by_name ? '#374151' : '#9ca3af' }}>{item.paid_by_name ?? '—'}</span>
|
||||
{item.paid_at ? <span style={{ color: '#9ca3af' }}> · {fmtDateTime(item.paid_at)}</span> : null}
|
||||
{item.payment_method ? <span style={{ color: '#9ca3af' }}> ({item.payment_method})</span> : null}
|
||||
</span>
|
||||
</div>
|
||||
<div style={{ marginTop: 2 }}>
|
||||
<span style={{
|
||||
fontSize: 10, fontWeight: 600, padding: '1px 6px', borderRadius: 4,
|
||||
background: c.border, color: c.text, border: `1px solid ${c.border}`,
|
||||
}}>{c.label}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function OrderGroup({ order, shiftWaiterId, activeFilter }) {
|
||||
const visibleItems = order.items.filter(item => {
|
||||
if (activeFilter === 'all') return true
|
||||
return classify(item, shiftWaiterId).key === activeFilter
|
||||
})
|
||||
if (visibleItems.length === 0) return null
|
||||
|
||||
const groupTotal = visibleItems
|
||||
.filter(i => i.status === 'paid')
|
||||
.reduce((s, i) => s + i.subtotal, 0)
|
||||
|
||||
return (
|
||||
<div style={{ borderRadius: 10, border: '1px solid #edeff1', marginBottom: 8, overflow: 'hidden' }}>
|
||||
{/* Order header */}
|
||||
<div style={{ padding: '8px 14px', background: '#f9fafb', display: 'flex', justifyContent: 'space-between', alignItems: 'center', flexWrap: 'wrap', gap: 4 }}>
|
||||
<div style={{ fontSize: 12, fontWeight: 600, color: '#374151' }}>
|
||||
Παραγγελία #{order.order_id}
|
||||
{order.table_name && <span style={{ color: '#8a9099', fontWeight: 400, marginLeft: 6 }}>· Τραπέζι {order.table_name}</span>}
|
||||
</div>
|
||||
<div style={{ display: 'flex', gap: 12, flexWrap: 'wrap' }}>
|
||||
{order.opener_name && (
|
||||
<span style={{ fontSize: 11, color: '#5a6169' }}>
|
||||
Άνοιξε: <span style={{ fontWeight: 600, color: '#374151' }}>{order.opener_name}</span>
|
||||
{order.opened_at ? <span style={{ color: '#9ca3af' }}> {fmtTime(order.opened_at)}</span> : null}
|
||||
</span>
|
||||
)}
|
||||
{order.closer_name && (
|
||||
<span style={{ fontSize: 11, color: '#5a6169' }}>
|
||||
Έκλεισε: <span style={{ fontWeight: 600, color: '#374151' }}>{order.closer_name}</span>
|
||||
{order.closed_at ? <span style={{ color: '#9ca3af' }}> {fmtTime(order.closed_at)}</span> : null}
|
||||
</span>
|
||||
)}
|
||||
{groupTotal > 0 && (
|
||||
<span style={{ fontSize: 12, fontWeight: 700, color: '#2f9e5e' }}>{fmtEUR(groupTotal)}</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
{visibleItems.map(item => (
|
||||
<ItemRow key={item.id} item={item} shiftWaiterId={shiftWaiterId} />
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default function ShiftDetailModal({ shiftId, shiftWaiterId, onClose }) {
|
||||
const [activeFilter, setActiveFilter] = useState('all')
|
||||
|
||||
const { data: summary, isLoading, isError } = useQuery({
|
||||
queryKey: ['shift-detail', shiftId],
|
||||
queryFn: () => client.get(`/api/shifts/${shiftId}/summary`).then(r => r.data),
|
||||
staleTime: 30 * 1000,
|
||||
})
|
||||
|
||||
// Count items per filter key for badge counts
|
||||
const counts = { all: 0, both: 0, paid: 0, ordered: 0, unpaid: 0 }
|
||||
const waiterIdToUse = shiftWaiterId ?? summary?.waiter_id
|
||||
if (summary?.orders) {
|
||||
for (const o of summary.orders) {
|
||||
for (const item of o.items) {
|
||||
counts.all++
|
||||
const key = classify(item, waiterIdToUse).key
|
||||
if (key in counts) counts[key]++
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div style={{
|
||||
position: 'fixed', inset: 0, background: 'rgba(0,0,0,0.5)', zIndex: 9999,
|
||||
display: 'flex', alignItems: 'center', justifyContent: 'center', padding: 20,
|
||||
}}
|
||||
onClick={onClose}
|
||||
>
|
||||
<div style={{
|
||||
background: 'white', borderRadius: 20, width: '100%', maxWidth: 900,
|
||||
maxHeight: '92vh', display: 'flex', flexDirection: 'column',
|
||||
boxShadow: '0 24px 64px rgba(0,0,0,0.25)',
|
||||
}}
|
||||
onClick={e => e.stopPropagation()}
|
||||
>
|
||||
{/* Header */}
|
||||
<div style={{ padding: '18px 24px', borderBottom: '1px solid #edeff1', flexShrink: 0, display: 'flex', justifyContent: 'space-between', alignItems: 'flex-start' }}>
|
||||
<div>
|
||||
<div style={{ fontSize: 17, fontWeight: 700, color: '#111315' }}>Λεπτομέρειες Βάρδιας</div>
|
||||
{summary && (
|
||||
<div style={{ fontSize: 13, color: '#5a6169', marginTop: 2 }}>
|
||||
{summary.waiter_name} · {fmtDate(summary.started_at)} · {fmtTime(summary.started_at)}–{summary.ended_at ? fmtTime(summary.ended_at) : 'ενεργή'}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<button onClick={onClose} style={{ background: 'none', border: 'none', cursor: 'pointer', color: '#8a9099', padding: 4 }}>
|
||||
<X size={18} />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{isLoading && <div style={{ padding: 40, textAlign: 'center', color: '#8a9099' }}>Φόρτωση…</div>}
|
||||
{isError && <div style={{ padding: 40, textAlign: 'center', color: '#dc2626' }}>Σφάλμα φόρτωσης δεδομένων</div>}
|
||||
|
||||
{summary && (
|
||||
<>
|
||||
{/* KPI row */}
|
||||
<div style={{ display: 'grid', gridTemplateColumns: 'repeat(4,1fr)', gap: 10, padding: '14px 24px', borderBottom: '1px solid #edeff1', flexShrink: 0 }}>
|
||||
{[
|
||||
{ label: 'Διάρκεια', value: fmtMins(summary.duration_minutes) },
|
||||
{ label: 'Αρχικά μετρητά', value: summary.starting_cash != null ? fmtEUR(summary.starting_cash) : '—' },
|
||||
{ label: 'Είσπραξη', value: fmtEUR(summary.total_collected), accent: '#2f9e5e' },
|
||||
{ label: 'Προς παράδοση', value: fmtEUR(summary.net_to_deliver), accent: '#3758c9' },
|
||||
].map(k => (
|
||||
<div key={k.label} style={{ background: '#f9fafb', borderRadius: 10, padding: '10px 12px', textAlign: 'center' }}>
|
||||
<div style={{ fontSize: 10, fontWeight: 700, color: '#8a9099', textTransform: 'uppercase', letterSpacing: 0.5 }}>{k.label}</div>
|
||||
<div style={{ fontSize: 18, fontWeight: 700, color: k.accent || '#111315', fontFamily: 'ui-monospace,monospace', marginTop: 4 }}>{k.value}</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* Colour legend */}
|
||||
<div style={{ display: 'flex', gap: 12, padding: '8px 24px', background: '#fafafa', borderBottom: '1px solid #edeff1', flexShrink: 0, flexWrap: 'wrap' }}>
|
||||
{[
|
||||
{ dot: '#16a34a', label: 'Παρήγγειλε + Πληρώθηκε' },
|
||||
{ dot: '#2563eb', label: 'Πληρώθηκε (παρήγγηλε άλλος)' },
|
||||
{ dot: '#ca8a04', label: 'Παρήγγειλε (Πληρώθηκε άλλος)' },
|
||||
{ dot: '#ea580c', label: 'Παρήγγειλε (απλήρωτο)' },
|
||||
{ dot: '#dc2626', label: 'Πρόβλημα Δεδομένων' },
|
||||
].map(l => (
|
||||
<div key={l.dot} style={{ display: 'flex', alignItems: 'center', gap: 5, fontSize: 11, color: '#5a6169' }}>
|
||||
<div style={{ width: 8, height: 8, borderRadius: '50%', background: l.dot, flexShrink: 0 }} />
|
||||
{l.label}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* Filter bar */}
|
||||
<div style={{ display: 'flex', gap: 6, padding: '10px 24px', borderBottom: '1px solid #edeff1', flexShrink: 0, overflowX: 'auto' }}>
|
||||
{FILTER_OPTIONS.map(opt => (
|
||||
<button
|
||||
key={opt.key}
|
||||
onClick={() => setActiveFilter(opt.key)}
|
||||
style={{
|
||||
padding: '4px 12px', borderRadius: 20, fontSize: 12, fontWeight: 600, cursor: 'pointer', whiteSpace: 'nowrap',
|
||||
border: activeFilter === opt.key ? '1.5px solid #3758c9' : '1.5px solid #e5e7eb',
|
||||
background: activeFilter === opt.key ? '#eff6ff' : 'white',
|
||||
color: activeFilter === opt.key ? '#3758c9' : '#5a6169',
|
||||
}}
|
||||
>
|
||||
{opt.label}
|
||||
{counts[opt.key] > 0 && (
|
||||
<span style={{
|
||||
marginLeft: 5, padding: '1px 5px', borderRadius: 8, fontSize: 10,
|
||||
background: activeFilter === opt.key ? '#3758c9' : '#e5e7eb',
|
||||
color: activeFilter === opt.key ? 'white' : '#5a6169',
|
||||
}}>
|
||||
{counts[opt.key]}
|
||||
</span>
|
||||
)}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* Orders + items */}
|
||||
<div style={{ flex: 1, overflowY: 'auto', padding: '14px 24px' }}>
|
||||
{summary.orders.length === 0 ? (
|
||||
<p style={{ color: '#b8bdc4', fontSize: 13, textAlign: 'center', padding: '24px 0' }}>
|
||||
Δεν υπάρχουν αντικείμενα για αυτή τη βάρδια
|
||||
</p>
|
||||
) : (
|
||||
summary.orders.map(o => (
|
||||
<OrderGroup key={o.order_id} order={o} shiftWaiterId={waiterIdToUse} activeFilter={activeFilter} />
|
||||
))
|
||||
)}
|
||||
{summary.orders.length > 0 &&
|
||||
!summary.orders.some(o => o.items.some(i =>
|
||||
activeFilter === 'all' || classify(i, waiterIdToUse).key === activeFilter
|
||||
)) && (
|
||||
<p style={{ color: '#b8bdc4', fontSize: 13, textAlign: 'center', padding: '24px 0' }}>
|
||||
Δεν υπάρχουν αντικείμενα για αυτό το φίλτρο
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,6 +1,9 @@
|
||||
import { useState } from 'react'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { UserRoundX, ChevronRight } from 'lucide-react'
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
import { UserRoundX, ChevronRight, ExternalLink, Trash2 } from 'lucide-react'
|
||||
import toast from 'react-hot-toast'
|
||||
import ShiftDetailModal from '../shared/ShiftDetailModal'
|
||||
import DeleteConfirmModal from '../../../ui/DeleteConfirmModal'
|
||||
import { BarChart, Bar, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer, LabelList } from 'recharts'
|
||||
import client from '../../../api/client'
|
||||
import { FilterBar, FilterSelect, FilterDateInput } from '../shared/FilterBar'
|
||||
@@ -9,18 +12,22 @@ import StatCard from '../shared/StatCard'
|
||||
import EmptyState from '../shared/EmptyState'
|
||||
import SkeletonTable from '../shared/SkeletonTable'
|
||||
import ExportButton from '../shared/ExportButton'
|
||||
import { fmtEUR, fmtDateTime, fmtDuration } from '../shared/reportDesignTokens'
|
||||
import { fmtEUR, fmtDateTime, fmtDuration, fmtDate, fmtTime } from '../shared/reportDesignTokens'
|
||||
|
||||
function today() { return new Date().toISOString().slice(0, 10) }
|
||||
function monthAgo() {
|
||||
const d = new Date(); d.setDate(d.getDate() - 30); return d.toISOString().slice(0, 10)
|
||||
}
|
||||
|
||||
export default function ShiftsOverview() {
|
||||
export default function ShiftsOverview({ onNavigate } = {}) {
|
||||
const [waiterId, setWaiterId] = useState('all')
|
||||
const [from, setFrom] = useState(monthAgo())
|
||||
const [to, setTo] = useState(today())
|
||||
const [expanded, setExpanded] = useState(null)
|
||||
const [detailShift, setDetailShift] = useState(null) // { id, waiter_id }
|
||||
const [deleteShift, setDeleteShift] = useState(null) // shift object to delete
|
||||
|
||||
const qc = useQueryClient()
|
||||
|
||||
const { data: waitersData } = useQuery({
|
||||
queryKey: ['meta-waiters'],
|
||||
@@ -28,6 +35,14 @@ export default function ShiftsOverview() {
|
||||
staleTime: 5 * 60 * 1000,
|
||||
})
|
||||
|
||||
const { data: bdData } = useQuery({
|
||||
queryKey: ['business-days-list'],
|
||||
queryFn: () => client.get('/api/reports/business-days').then(r => r.data),
|
||||
staleTime: 60 * 1000,
|
||||
})
|
||||
|
||||
const bdById = Object.fromEntries((bdData?.business_days || []).map(bd => [String(bd.id), bd]))
|
||||
|
||||
const { data, isLoading, isError, refetch } = useQuery({
|
||||
queryKey: ['shifts', waiterId, from, to],
|
||||
queryFn: () => client.get('/api/reports/shifts', {
|
||||
@@ -37,7 +52,21 @@ export default function ShiftsOverview() {
|
||||
to: to + 'T23:59:59',
|
||||
},
|
||||
}).then(r => r.data),
|
||||
staleTime: 60 * 1000,
|
||||
staleTime: 0,
|
||||
})
|
||||
|
||||
const deleteShiftMutation = useMutation({
|
||||
mutationFn: (id) => client.delete(`/api/shifts/${id}`),
|
||||
onSuccess: () => {
|
||||
toast.success('Η βάρδια διαγράφηκε')
|
||||
qc.invalidateQueries({ queryKey: ['shifts'] })
|
||||
qc.invalidateQueries({ queryKey: ['business-days-list'] })
|
||||
setDeleteShift(null)
|
||||
},
|
||||
onError: (err) => {
|
||||
toast.error(err?.response?.data?.detail || 'Σφάλμα διαγραφής βάρδιας')
|
||||
setDeleteShift(null)
|
||||
},
|
||||
})
|
||||
|
||||
const waiterOptions = [
|
||||
@@ -94,7 +123,7 @@ export default function ShiftsOverview() {
|
||||
<TH align="right">Εισπράχθηκαν</TH>
|
||||
<TH align="right">Οφείλει</TH>
|
||||
<TH>Κατάσταση</TH>
|
||||
<TH className="w-10" />
|
||||
<TH className="w-28" />
|
||||
</THead>
|
||||
<tbody>
|
||||
{shifts.map(s => {
|
||||
@@ -119,14 +148,49 @@ export default function ShiftsOverview() {
|
||||
<TD mono align="right" className="font-semibold text-slate-900">{fmtEUR(s.net_to_deliver)}</TD>
|
||||
<TD><StatusBadge status={s.is_active ? 'active' : 'closed'} pulse /></TD>
|
||||
<TD align="right">
|
||||
<ChevronRight className={`h-4 w-4 text-slate-400 transition-transform ${isOpen ? 'rotate-90' : ''}`} />
|
||||
<div className="flex items-center justify-end gap-2">
|
||||
<button
|
||||
onClick={e => { e.stopPropagation(); setDetailShift({ id: s.id, waiter_id: s.waiter_id }) }}
|
||||
className="rounded border border-slate-200 bg-white px-2 py-0.5 text-[11px] font-medium text-slate-600 hover:bg-slate-50"
|
||||
>
|
||||
Λεπτομέρειες
|
||||
</button>
|
||||
{!s.is_active && (
|
||||
<button
|
||||
onClick={e => { e.stopPropagation(); setDeleteShift(s) }}
|
||||
className="rounded border border-red-200 bg-white p-0.5 text-red-400 hover:bg-red-50 hover:text-red-600"
|
||||
title="Διαγραφή βάρδιας"
|
||||
>
|
||||
<Trash2 size={13} />
|
||||
</button>
|
||||
)}
|
||||
<ChevronRight className={`h-4 w-4 text-slate-400 transition-transform ${isOpen ? 'rotate-90' : ''}`} />
|
||||
</div>
|
||||
</TD>
|
||||
</TR>,
|
||||
isOpen && (
|
||||
<tr key={`${s.id}-detail`}>
|
||||
<td colSpan={9} className="border-b border-slate-100 bg-slate-50/60 px-6 py-3">
|
||||
<div className="text-[12px] text-slate-500">
|
||||
Εργάσιμη Μέρα ID: {s.business_day_id ?? '—'} · Σημειώσεις: {s.notes || '—'}
|
||||
<div className="flex items-center gap-4 text-[12px] text-slate-500">
|
||||
<span>
|
||||
{'Εργάσιμη Μέρα: '}
|
||||
{s.business_day_id ? (() => {
|
||||
const bd = bdById[String(s.business_day_id)]
|
||||
const label = bd
|
||||
? `#${s.business_day_id} · ${fmtDate(bd.opened_at)} ${fmtTime(bd.opened_at)}`
|
||||
: `#${s.business_day_id}`
|
||||
return onNavigate ? (
|
||||
<button
|
||||
onClick={e => { e.stopPropagation(); onNavigate({ parent: 'restaurant', sub: 'orders', initialBusinessDayId: s.business_day_id }) }}
|
||||
className="inline-flex items-center gap-1 text-sky-600 hover:text-sky-700 hover:underline font-medium"
|
||||
>
|
||||
{label}
|
||||
<ExternalLink className="h-3 w-3" />
|
||||
</button>
|
||||
) : <span>{label}</span>
|
||||
})() : '—'}
|
||||
</span>
|
||||
<span>Σημειώσεις: {s.notes || '—'}</span>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
@@ -138,6 +202,23 @@ export default function ShiftsOverview() {
|
||||
)}
|
||||
</Panel>
|
||||
</div>
|
||||
|
||||
{detailShift && (
|
||||
<ShiftDetailModal
|
||||
shiftId={detailShift.id}
|
||||
shiftWaiterId={detailShift.waiter_id}
|
||||
onClose={() => setDetailShift(null)}
|
||||
/>
|
||||
)}
|
||||
|
||||
{deleteShift && (
|
||||
<DeleteConfirmModal
|
||||
title={`Διαγραφή Βάρδιας #${deleteShift.id}`}
|
||||
description={`Η βάρδια του ${deleteShift.waiter_name} (${fmtDateTime(deleteShift.started_at)} – ${fmtDateTime(deleteShift.ended_at)}) θα διαγραφεί μόνιμα.`}
|
||||
onConfirm={() => deleteShiftMutation.mutate(deleteShift.id)}
|
||||
onCancel={() => setDeleteShift(null)}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user