feat: bump client-services (accumulated feature work + deploy fixes)
Snapshot of in-progress work across local_backend, manager_dashboard, and waiter_pwa (pricing, chat, fiscal, prep zones, recovery codes, CRM, inventory, permissions), plus the nginx/docker-compose deploy fixes for the Unraid + NPM reverse-proxy setup. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,439 @@
|
||||
import { useState, useMemo } from 'react'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { FileText, AlertCircle, CheckCircle, Clock } from 'lucide-react'
|
||||
import client from '../../api/client'
|
||||
import { FilterBar, FilterSelect } from './shared/FilterBar'
|
||||
import { Panel, DataTable, THead, TH, TR, TD } from './shared/TablePrimitives'
|
||||
import StatCard from './shared/StatCard'
|
||||
import EmptyState from './shared/EmptyState'
|
||||
import SkeletonTable from './shared/SkeletonTable'
|
||||
import { fmtEUR, fmtDate } from './shared/reportDesignTokens'
|
||||
|
||||
const CATEGORY_LABELS = {
|
||||
food: 'Τρόφιμα',
|
||||
beverage: 'Ποτά',
|
||||
supplies: 'Αναλώσιμα',
|
||||
utilities: 'Κοινόχρηστα',
|
||||
rent: 'Ενοίκιο',
|
||||
salary: 'Μισθοί',
|
||||
maintenance: 'Συντήρηση',
|
||||
other: 'Άλλο',
|
||||
}
|
||||
|
||||
const STATUS_META = {
|
||||
due: { label: 'Εκκρεμεί', bg: '#fef2f2', color: '#dc2626' },
|
||||
partial: { label: 'Μερική', bg: '#fff7ed', color: '#c2410c' },
|
||||
paid: { label: 'Πληρώθηκε', bg: '#eef7f0', color: '#1f7042' },
|
||||
}
|
||||
|
||||
// 12 distinct colours for combined view supplier segments
|
||||
const SUPPLIER_COLORS = [
|
||||
'#3b82f6','#10b981','#f59e0b','#ef4444','#8b5cf6',
|
||||
'#06b6d4','#f97316','#84cc16','#ec4899','#14b8a6',
|
||||
'#a78bfa','#fb923c',
|
||||
]
|
||||
|
||||
function fmtCat(cat) {
|
||||
return CATEGORY_LABELS[cat] || cat || '—'
|
||||
}
|
||||
|
||||
// ── Breakdown section ─────────────────────────────────────────────────────────
|
||||
|
||||
const BREAKDOWN_VIEWS = [
|
||||
{ key: 'category', label: 'ΑΝΑ ΚΑΤΗΓΟΡΙΑ' },
|
||||
{ key: 'contact', label: 'ΑΝΑ ΕΠΑΦΗ' },
|
||||
{ key: 'combined', label: 'ΣΥΝΔΙΑΣΤΙΚΑ' },
|
||||
]
|
||||
|
||||
function BreakdownToggle({ value, onChange }) {
|
||||
return (
|
||||
<div style={{
|
||||
display: 'flex', background: '#f1f5f9', borderRadius: 8, padding: 3, gap: 2,
|
||||
}}>
|
||||
{BREAKDOWN_VIEWS.map(v => (
|
||||
<button
|
||||
key={v.key}
|
||||
onClick={() => onChange(v.key)}
|
||||
style={{
|
||||
padding: '4px 10px', borderRadius: 6, border: 'none', cursor: 'pointer',
|
||||
fontSize: 10, fontWeight: 700, letterSpacing: 0.4,
|
||||
transition: 'all 120ms',
|
||||
background: value === v.key ? 'white' : 'transparent',
|
||||
color: value === v.key ? '#0f172a' : '#64748b',
|
||||
boxShadow: value === v.key ? '0 1px 3px rgba(0,0,0,0.12)' : 'none',
|
||||
}}
|
||||
>
|
||||
{v.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function BreakdownByCategoryRow({ cat, total }) {
|
||||
return (
|
||||
<div className="flex items-center gap-4 px-5 py-3">
|
||||
<div className="w-28 text-[13px] text-slate-700 font-medium flex-shrink-0">{fmtCat(cat.category)}</div>
|
||||
<div className="flex-1 h-2 bg-slate-100 rounded-full overflow-hidden">
|
||||
<div className="h-full bg-sky-500 rounded-full transition-all" style={{ width: `${total > 0 ? (cat.total / total) * 100 : 0}%` }} />
|
||||
</div>
|
||||
<div className="text-right flex-shrink-0 w-20">
|
||||
<div className="text-[13px] font-mono font-medium text-slate-900">{fmtEUR(cat.total)}</div>
|
||||
{cat.due > 0 && <div className="text-[11px] text-rose-500">{fmtEUR(cat.due)} εκκρεμεί</div>}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function BreakdownByContactRow({ name, total, due, grandTotal }) {
|
||||
return (
|
||||
<div className="flex items-center gap-4 px-5 py-3">
|
||||
<div style={{ width: 140 }} className="text-[13px] text-slate-700 font-medium flex-shrink-0 truncate">{name}</div>
|
||||
<div className="flex-1 h-2 bg-slate-100 rounded-full overflow-hidden">
|
||||
<div className="h-full rounded-full transition-all" style={{
|
||||
width: `${grandTotal > 0 ? (total / grandTotal) * 100 : 0}%`,
|
||||
background: '#10b981',
|
||||
}} />
|
||||
</div>
|
||||
<div className="text-right flex-shrink-0 w-20">
|
||||
<div className="text-[13px] font-mono font-medium text-slate-900">{fmtEUR(total)}</div>
|
||||
{due > 0 && <div className="text-[11px] text-rose-500">{fmtEUR(due)} εκκρεμεί</div>}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function BreakdownCombinedRow({ cat, segments, supplierColorMap, grandTotal }) {
|
||||
const catTotal = segments.reduce((s, sg) => s + sg.amount, 0)
|
||||
if (catTotal === 0) return null
|
||||
return (
|
||||
<div className="flex items-center gap-4 px-5 py-3">
|
||||
<div className="w-28 text-[13px] text-slate-700 font-medium flex-shrink-0">{fmtCat(cat)}</div>
|
||||
<div className="flex-1 h-4 bg-slate-100 rounded-full overflow-hidden flex">
|
||||
{segments.map(sg => (
|
||||
sg.amount > 0 ? (
|
||||
<div
|
||||
key={sg.name}
|
||||
title={`${sg.name}: ${fmtEUR(sg.amount)}`}
|
||||
style={{
|
||||
width: `${grandTotal > 0 ? (sg.amount / grandTotal) * 100 : 0}%`,
|
||||
background: supplierColorMap[sg.name] || '#94a3b8',
|
||||
transition: 'width 300ms',
|
||||
}}
|
||||
/>
|
||||
) : null
|
||||
))}
|
||||
</div>
|
||||
<div className="text-right flex-shrink-0 w-20">
|
||||
<div className="text-[13px] font-mono font-medium text-slate-900">{fmtEUR(catTotal)}</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function BreakdownSection({ expenses, summary }) {
|
||||
const [view, setView] = useState('category')
|
||||
|
||||
// By contact
|
||||
const byContact = useMemo(() => {
|
||||
const map = {}
|
||||
for (const e of expenses) {
|
||||
const key = e.contact_name || '(χωρίς προμηθευτή)'
|
||||
if (!map[key]) map[key] = { name: key, total: 0, due: 0 }
|
||||
map[key].total += e.total_amount
|
||||
map[key].due += e.due_amount
|
||||
}
|
||||
return Object.values(map).sort((a, b) => b.total - a.total)
|
||||
}, [expenses])
|
||||
|
||||
// By combined (category × contact stacked)
|
||||
const { combinedRows, supplierColorMap, allSuppliers } = useMemo(() => {
|
||||
const catMap = {}
|
||||
const suppSet = new Set()
|
||||
for (const e of expenses) {
|
||||
const cat = e.category || 'other'
|
||||
const supp = e.contact_name || '(χωρίς)'
|
||||
suppSet.add(supp)
|
||||
if (!catMap[cat]) catMap[cat] = {}
|
||||
catMap[cat][supp] = (catMap[cat][supp] || 0) + e.total_amount
|
||||
}
|
||||
const allSupps = [...suppSet]
|
||||
const colorMap = {}
|
||||
allSupps.forEach((s, i) => { colorMap[s] = SUPPLIER_COLORS[i % SUPPLIER_COLORS.length] })
|
||||
|
||||
const rows = Object.entries(catMap)
|
||||
.map(([cat, suppAmounts]) => ({
|
||||
cat,
|
||||
segments: allSupps.map(s => ({ name: s, amount: suppAmounts[s] || 0 })),
|
||||
}))
|
||||
.sort((a, b) => {
|
||||
const ta = a.segments.reduce((s, sg) => s + sg.amount, 0)
|
||||
const tb = b.segments.reduce((s, sg) => s + sg.amount, 0)
|
||||
return tb - ta
|
||||
})
|
||||
|
||||
return { combinedRows: rows, supplierColorMap: colorMap, allSuppliers: allSupps }
|
||||
}, [expenses])
|
||||
|
||||
const grandTotal = expenses.reduce((s, e) => s + e.total_amount, 0)
|
||||
const catGrandTotal = (summary?.by_category || []).reduce((s, c) => s + c.total, 0)
|
||||
|
||||
const hasData = expenses.length > 0 || (summary?.by_category?.length > 0)
|
||||
if (!hasData) return null
|
||||
|
||||
return (
|
||||
<div className="mb-6">
|
||||
<div className="rounded-lg border border-slate-200 bg-white shadow-[0_1px_0_rgba(15,23,42,0.04)] overflow-hidden">
|
||||
<div className="px-5 py-3 border-b border-slate-100 flex items-center justify-between">
|
||||
<div className="text-[11px] font-semibold uppercase tracking-[0.1em] text-slate-500">
|
||||
{view === 'category' ? 'Ανά Κατηγορία' : view === 'contact' ? 'Ανά Επαφή / Προμηθευτή' : 'Συνδιαστική Ανάλυση'}
|
||||
</div>
|
||||
<BreakdownToggle value={view} onChange={setView} />
|
||||
</div>
|
||||
|
||||
{view === 'category' && (
|
||||
<div className="divide-y divide-slate-100">
|
||||
{(summary?.by_category || [])
|
||||
.sort((a, b) => b.total - a.total)
|
||||
.map(cat => (
|
||||
<BreakdownByCategoryRow key={cat.category} cat={cat} total={catGrandTotal} />
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{view === 'contact' && (
|
||||
<div className="divide-y divide-slate-100">
|
||||
{byContact.map(row => (
|
||||
<BreakdownByContactRow
|
||||
key={row.name} name={row.name}
|
||||
total={row.total} due={row.due}
|
||||
grandTotal={grandTotal}
|
||||
/>
|
||||
))}
|
||||
{byContact.length === 0 && (
|
||||
<div className="px-5 py-4 text-[13px] text-slate-400">Δεν υπάρχουν δεδομένα.</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{view === 'combined' && (
|
||||
<>
|
||||
<div className="divide-y divide-slate-100">
|
||||
{combinedRows.map(row => (
|
||||
<BreakdownCombinedRow
|
||||
key={row.cat} cat={row.cat}
|
||||
segments={row.segments}
|
||||
supplierColorMap={supplierColorMap}
|
||||
grandTotal={grandTotal}
|
||||
/>
|
||||
))}
|
||||
{combinedRows.length === 0 && (
|
||||
<div className="px-5 py-4 text-[13px] text-slate-400">Δεν υπάρχουν δεδομένα.</div>
|
||||
)}
|
||||
</div>
|
||||
{allSuppliers.length > 0 && (
|
||||
<div className="px-5 py-3 border-t border-slate-100 flex flex-wrap gap-3">
|
||||
{allSuppliers.map(s => (
|
||||
<div key={s} className="flex items-center gap-1.5">
|
||||
<div style={{ width: 10, height: 10, borderRadius: 3, background: supplierColorMap[s], flexShrink: 0 }} />
|
||||
<span style={{ fontSize: 11, color: '#64748b' }}>{s}</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ── Detail modal ──────────────────────────────────────────────────────────────
|
||||
|
||||
function ExpenseDetailModal({ expense, onClose }) {
|
||||
return (
|
||||
<div
|
||||
style={{ position: 'fixed', inset: 0, background: 'rgba(0,0,0,0.4)', zIndex: 9999, display: 'flex', alignItems: 'center', justifyContent: 'center', padding: 16 }}
|
||||
onClick={e => { if (e.target === e.currentTarget) onClose() }}
|
||||
>
|
||||
<div style={{ background: 'white', borderRadius: 16, width: '100%', maxWidth: 520, maxHeight: '90vh', overflowY: 'auto', boxShadow: '0 20px 60px rgba(0,0,0,0.2)' }}>
|
||||
<div style={{ padding: '20px 24px', borderBottom: '1px solid #edeff1', display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
|
||||
<div>
|
||||
<div style={{ fontSize: 16, fontWeight: 700, color: '#111315' }}>{expense.description}</div>
|
||||
<div style={{ fontSize: 12, color: '#5a6169', marginTop: 2 }}>{fmtCat(expense.category)} · {fmtDate(expense.created_at)}</div>
|
||||
</div>
|
||||
<button onClick={onClose} style={{ width: 30, height: 30, borderRadius: 8, border: '1px solid #edeff1', background: 'white', fontSize: 16, cursor: 'pointer' }}>×</button>
|
||||
</div>
|
||||
<div style={{ padding: '20px 24px', display: 'flex', flexDirection: 'column', gap: 16 }}>
|
||||
<div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr 1fr', gap: 12 }}>
|
||||
{[
|
||||
{ label: 'Σύνολο', value: fmtEUR(expense.total_amount), color: '#111315' },
|
||||
{ label: 'Πληρώθηκε', value: fmtEUR(expense.paid_amount), color: '#1f7042' },
|
||||
{ label: 'Εκκρεμεί', value: fmtEUR(expense.due_amount), color: expense.due_amount > 0 ? '#dc2626' : '#1f7042' },
|
||||
].map(s => (
|
||||
<div key={s.label} style={{ padding: '12px 14px', borderRadius: 10, background: '#fafafa', border: '1px solid #edeff1' }}>
|
||||
<div style={{ fontSize: 11, color: '#8a9099', fontWeight: 600, textTransform: 'uppercase', letterSpacing: 0.5 }}>{s.label}</div>
|
||||
<div style={{ fontSize: 20, fontWeight: 700, color: s.color, fontFamily: 'monospace', marginTop: 4 }}>{s.value}</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{expense.contact_name && (
|
||||
<div style={{ fontSize: 13, color: '#374151' }}>
|
||||
<span style={{ fontWeight: 600 }}>Προμηθευτής:</span> {expense.contact_name}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{expense.due_date && (
|
||||
<div style={{ fontSize: 13, color: '#374151' }}>
|
||||
<span style={{ fontWeight: 600 }}>Ημ. λήξης:</span> {fmtDate(expense.due_date)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{expense.notes && (
|
||||
<div style={{ fontSize: 13, color: '#374151', background: '#f9fafb', borderRadius: 8, padding: '10px 14px' }}>
|
||||
{expense.notes}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{expense.payments.length > 0 && (
|
||||
<div>
|
||||
<div style={{ fontSize: 11, fontWeight: 700, color: '#5a6169', textTransform: 'uppercase', letterSpacing: 0.5, marginBottom: 8 }}>Πληρωμές</div>
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 6 }}>
|
||||
{expense.payments.map(p => (
|
||||
<div key={p.id} style={{ display: 'flex', justifyContent: 'space-between', fontSize: 13, padding: '8px 12px', borderRadius: 8, background: '#eef7f0', border: '1px solid #d1fae5' }}>
|
||||
<span style={{ color: '#374151' }}>{fmtDate(p.paid_at)}{p.paid_by_name ? ` · ${p.paid_by_name}` : ''}</span>
|
||||
<span style={{ fontWeight: 700, color: '#1f7042', fontFamily: 'monospace' }}>{fmtEUR(p.amount)}</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ── Main page ─────────────────────────────────────────────────────────────────
|
||||
|
||||
export default function ExpensesPage() {
|
||||
const [statusF, setStatusF] = useState('all')
|
||||
const [categoryF, setCategoryF] = useState('all')
|
||||
const [selectedExpense, setSelectedExpense] = useState(null)
|
||||
|
||||
const queryParams = {
|
||||
...(statusF !== 'all' ? { status: statusF } : {}),
|
||||
...(categoryF !== 'all' ? { category: categoryF } : {}),
|
||||
}
|
||||
|
||||
const { data: expenses = [], isLoading, isError, refetch } = useQuery({
|
||||
queryKey: ['expenses-report', statusF, categoryF],
|
||||
queryFn: () => client.get('/api/expenses/', { params: queryParams }).then(r => r.data),
|
||||
staleTime: 30_000,
|
||||
})
|
||||
|
||||
const { data: summary } = useQuery({
|
||||
queryKey: ['expenses-summary'],
|
||||
queryFn: () => client.get('/api/expenses/summary').then(r => r.data),
|
||||
staleTime: 30_000,
|
||||
})
|
||||
|
||||
const allCategories = [...new Set(expenses.map(e => e.category).filter(Boolean))]
|
||||
const categoryOptions = [
|
||||
{ value: 'all', label: 'Όλες οι Κατηγορίες' },
|
||||
...allCategories.map(c => ({ value: c, label: fmtCat(c) })),
|
||||
]
|
||||
const statusOptions = [
|
||||
{ value: 'all', label: 'Όλες Κατάσταση' },
|
||||
{ value: 'due', label: 'Εκκρεμείς' },
|
||||
{ value: 'partial', label: 'Μερική Πληρωμή' },
|
||||
{ value: 'paid', label: 'Πληρωμένες' },
|
||||
]
|
||||
|
||||
const totalAmount = expenses.reduce((s, e) => s + e.total_amount, 0)
|
||||
const paidAmount = expenses.reduce((s, e) => s + e.paid_amount, 0)
|
||||
const dueAmount = expenses.reduce((s, e) => s + e.due_amount, 0)
|
||||
const dueCount = expenses.filter(e => e.status !== 'paid').length
|
||||
|
||||
if (isLoading) return <div className="flex-1 overflow-y-auto p-6"><SkeletonTable rows={10} columns={6} /></div>
|
||||
if (isError) return (
|
||||
<div className="flex flex-col flex-1 min-h-0">
|
||||
<FilterBar><span className="text-[12px] text-slate-500">Αδυναμία φόρτωσης δεδομένων</span></FilterBar>
|
||||
<div className="flex flex-1 items-center justify-center">
|
||||
<button onClick={() => refetch()} className="rounded-md border border-slate-200 px-4 py-2 text-sm hover:bg-slate-50">Επανάληψη</button>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
|
||||
return (
|
||||
<div className="flex flex-col flex-1 min-h-0">
|
||||
<FilterBar>
|
||||
<FilterSelect value={statusF} onChange={setStatusF} options={statusOptions} label="Κατάσταση" />
|
||||
<FilterSelect value={categoryF} onChange={setCategoryF} options={categoryOptions} label="Κατηγορία" />
|
||||
</FilterBar>
|
||||
|
||||
<div className="flex-1 overflow-y-auto p-6">
|
||||
{/* Summary stat cards */}
|
||||
<div className="grid grid-cols-4 gap-4 mb-6">
|
||||
<StatCard label="Συνολικές Δαπάνες" value={fmtEUR(totalAmount)} icon={FileText} />
|
||||
<StatCard label="Πληρωμένο" value={fmtEUR(paidAmount)} icon={CheckCircle} accent />
|
||||
<StatCard label="Εκκρεμεί" value={fmtEUR(dueAmount)} icon={AlertCircle} sub={dueCount > 0 ? `${dueCount} εκκρεμείς` : 'όλα πληρωμένα'} />
|
||||
<StatCard label="Αριθμός Δαπανών" value={String(expenses.length)} icon={Clock} />
|
||||
</div>
|
||||
|
||||
<BreakdownSection expenses={expenses} summary={summary} />
|
||||
|
||||
{/* Expense list */}
|
||||
<Panel title="Λίστα Δαπανών" subtitle={`${expenses.length} αποτελέσματα`} padded={false}>
|
||||
{expenses.length === 0 ? (
|
||||
<EmptyState title="Δεν βρέθηκαν δαπάνες" description="Δοκιμάστε διαφορετικά φίλτρα." />
|
||||
) : (
|
||||
<DataTable>
|
||||
<THead>
|
||||
<TH>Περιγραφή</TH>
|
||||
<TH>Κατηγορία</TH>
|
||||
<TH>Προμηθευτής</TH>
|
||||
<TH>Σύνολο</TH>
|
||||
<TH>Εκκρεμεί</TH>
|
||||
<TH>Κατάσταση</TH>
|
||||
<TH>Ημερομηνία</TH>
|
||||
</THead>
|
||||
<tbody>
|
||||
{expenses.map(e => {
|
||||
const meta = STATUS_META[e.status] || STATUS_META.due
|
||||
return (
|
||||
<TR
|
||||
key={e.id}
|
||||
striped
|
||||
className="cursor-pointer hover:bg-sky-50/40"
|
||||
onClick={() => setSelectedExpense(e)}
|
||||
>
|
||||
<TD className="font-medium">{e.description}</TD>
|
||||
<TD>{fmtCat(e.category)}</TD>
|
||||
<TD className="text-slate-500">{e.contact_name || '—'}</TD>
|
||||
<TD mono>{fmtEUR(e.total_amount)}</TD>
|
||||
<TD mono className={e.due_amount > 0 ? 'text-rose-600 font-semibold' : 'text-slate-400'}>
|
||||
{e.due_amount > 0 ? fmtEUR(e.due_amount) : '—'}
|
||||
</TD>
|
||||
<TD>
|
||||
<span style={{ padding: '2px 8px', borderRadius: 999, fontSize: 11, fontWeight: 700, background: meta.bg, color: meta.color }}>
|
||||
{meta.label}
|
||||
</span>
|
||||
</TD>
|
||||
<TD className="text-slate-500 text-[12px]">{fmtDate(e.created_at)}</TD>
|
||||
</TR>
|
||||
)
|
||||
})}
|
||||
</tbody>
|
||||
</DataTable>
|
||||
)}
|
||||
</Panel>
|
||||
</div>
|
||||
|
||||
{selectedExpense && (
|
||||
<ExpenseDetailModal expense={selectedExpense} onClose={() => setSelectedExpense(null)} />
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import { useState } from 'react'
|
||||
import { TabBar } from '../../ui/Tabs'
|
||||
import CancellationsLog from './operations/CancellationsLog'
|
||||
import DiscountsLog from './operations/DiscountsLog'
|
||||
|
||||
const TABS = [
|
||||
{ id: 'cancellations', label: 'Ακυρώσεις', Component: CancellationsLog },
|
||||
{ id: 'discounts', label: 'Εκπτώσεις', Component: DiscountsLog },
|
||||
]
|
||||
|
||||
export default function MiscPage() {
|
||||
const [active, setActive] = useState('cancellations')
|
||||
const tab = TABS.find(t => t.id === active) || TABS[0]
|
||||
const { Component } = tab
|
||||
|
||||
return (
|
||||
<div className="flex flex-col h-full min-h-0">
|
||||
<TabBar tabs={TABS} active={active} onChange={setActive} />
|
||||
<div className="flex-1 min-h-0 flex flex-col">
|
||||
<Component key={active} />
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,524 @@
|
||||
import { useState, useMemo } from 'react'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { ConciergeBell, Printer, Download, PrinterIcon, X, ChevronDown, ChevronUp } from 'lucide-react'
|
||||
import toast from 'react-hot-toast'
|
||||
import client from '../../api/client'
|
||||
import { FilterBar, FilterSelect, FilterDateInput, WorkDayDateToggle } from './shared/FilterBar'
|
||||
import StatCard from './shared/StatCard'
|
||||
import SkeletonTable from './shared/SkeletonTable'
|
||||
import { DataTable, THead, TH, TR, TD } from './shared/TablePrimitives'
|
||||
import { fmtNum, fmtEUR, fmtDate, 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) }
|
||||
|
||||
// ── CSV export (client-side) ──────────────────────────────────────────────────
|
||||
|
||||
function downloadCSV(filename, rows, headers) {
|
||||
const escape = v => `"${String(v ?? '').replace(/"/g, '""')}"`
|
||||
const lines = [
|
||||
headers.map(escape).join(','),
|
||||
...rows.map(r => r.map(escape).join(',')),
|
||||
]
|
||||
const blob = new Blob([lines.join('\n')], { type: 'text/csv;charset=utf-8;' })
|
||||
const url = URL.createObjectURL(blob)
|
||||
const a = document.createElement('a')
|
||||
a.href = url; a.download = filename; a.click()
|
||||
URL.revokeObjectURL(url)
|
||||
}
|
||||
|
||||
// ── Print modal ───────────────────────────────────────────────────────────────
|
||||
|
||||
function PrintModal({ zone, queryParams, periodLabel, onClose }) {
|
||||
const [targetPrinter, setTargetPrinter] = useState('browser')
|
||||
const [printing, setPrinting] = useState(false)
|
||||
|
||||
const { data: printersData } = useQuery({
|
||||
queryKey: ['printers-list'],
|
||||
queryFn: () => client.get('/api/reports/meta/printers').then(r => r.data),
|
||||
staleTime: 60_000,
|
||||
})
|
||||
const printers = printersData?.printers || []
|
||||
|
||||
const printerOptions = [
|
||||
{ value: 'browser', label: 'Εκτύπωση μέσω browser (PDF)' },
|
||||
...printers.map(p => ({ value: String(p.id), label: p.name })),
|
||||
]
|
||||
|
||||
function handleBrowserPrint() {
|
||||
const items = [...zone.all_products].sort((a, b) => b.count - a.count)
|
||||
const totalItems = items.reduce((s, i) => s + i.count, 0)
|
||||
|
||||
const rows = items.map(item => {
|
||||
const dots = '.'.repeat(Math.max(2, 42 - item.name.length - String(item.count).length))
|
||||
return `<tr><td>${item.name}</td><td style="text-align:right;font-family:monospace;white-space:nowrap">${dots} ${item.count}</td></tr>`
|
||||
}).join('')
|
||||
|
||||
const html = `<!DOCTYPE html><html><head><meta charset="UTF-8"><title>Ζώνη: ${zone.name}</title>
|
||||
<style>* { box-sizing: border-box; margin: 0; padding: 0; }
|
||||
body { font-family: Arial,sans-serif; font-size: 12px; color: #000; padding: 24px; max-width: 680px; }
|
||||
h1 { font-size: 15px; font-weight: bold; font-family: 'Courier New',monospace; border-bottom: 2px solid #000; padding-bottom: 6px; margin-bottom: 10px; }
|
||||
.meta { font-size: 11px; color: #555; margin-bottom: 14px; }
|
||||
table { width: 100%; border-collapse: collapse; font-size: 12px; }
|
||||
td { padding: 4px 4px; border-bottom: 1px dotted #ccc; }
|
||||
tfoot td { border-top: 2px solid #000; border-bottom: none; font-weight: bold; padding-top: 8px; }
|
||||
@media print { body { padding: 0; } }</style></head>
|
||||
<body>
|
||||
<h1>ΖΩΝΗ ΠΡΟΕΤΟΙΜΑΣΙΑΣ: ${zone.name.toUpperCase()}</h1>
|
||||
<div class="meta">Περίοδος: ${periodLabel}</div>
|
||||
<table>
|
||||
<thead><tr><th style="text-align:left">Προϊόν</th><th style="text-align:right">Ποσότητα</th></tr></thead>
|
||||
<tbody>${rows}</tbody>
|
||||
<tfoot><tr><td>ΣΥΝΟΛΟ ΕΙΔΩΝ</td><td style="text-align:right">${totalItems}</td></tr></tfoot>
|
||||
</table>
|
||||
</body></html>`
|
||||
|
||||
const win = window.open('', '_blank', 'width=800,height=600')
|
||||
win.document.write(html)
|
||||
win.document.close()
|
||||
win.focus()
|
||||
win.print()
|
||||
onClose()
|
||||
}
|
||||
|
||||
async function handleThermalPrint() {
|
||||
setPrinting(true)
|
||||
try {
|
||||
const body = {
|
||||
printer_id: parseInt(targetPrinter, 10),
|
||||
zone_id: zone.id,
|
||||
...queryParams,
|
||||
}
|
||||
await client.post('/api/reports/print/prep-zone', body)
|
||||
toast.success(`Αποστολή στον εκτυπωτή…`)
|
||||
onClose()
|
||||
} catch {
|
||||
toast.error('Αποτυχία εκτύπωσης')
|
||||
} finally {
|
||||
setPrinting(false)
|
||||
}
|
||||
}
|
||||
|
||||
const isBrowser = targetPrinter === 'browser'
|
||||
|
||||
return (
|
||||
<div
|
||||
style={{ position: 'fixed', inset: 0, background: 'rgba(0,0,0,0.45)', zIndex: 9999, display: 'flex', alignItems: 'center', justifyContent: 'center', padding: 16 }}
|
||||
onClick={e => { if (e.target === e.currentTarget) onClose() }}
|
||||
>
|
||||
<div style={{ background: 'white', borderRadius: 16, width: '100%', maxWidth: 460, boxShadow: '0 20px 60px rgba(0,0,0,0.2)' }}>
|
||||
<div style={{ padding: '18px 22px', borderBottom: '1px solid #edeff1', display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
|
||||
<div>
|
||||
<div style={{ fontSize: 15, fontWeight: 700 }}>Εκτύπωση Σύνοψης</div>
|
||||
<div style={{ fontSize: 12, color: '#5a6169', marginTop: 2 }}>Ζώνη: {zone.name} · {periodLabel}</div>
|
||||
</div>
|
||||
<button onClick={onClose} style={{ width: 28, height: 28, borderRadius: 8, border: '1px solid #edeff1', background: 'white', cursor: 'pointer', display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
|
||||
<X size={14} />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div style={{ padding: '18px 22px', display: 'flex', flexDirection: 'column', gap: 14 }}>
|
||||
{/* Preview of shopping list */}
|
||||
<div style={{ background: '#f8fafc', borderRadius: 10, border: '1px solid #e2e8f0', padding: '10px 14px', maxHeight: 180, overflowY: 'auto', fontFamily: 'monospace', fontSize: 12 }}>
|
||||
{zone.all_products.slice(0, 20).map(p => {
|
||||
const dots = '.'.repeat(Math.max(2, 34 - p.name.length - String(p.count).length))
|
||||
return <div key={p.name}>{p.name}{dots}{p.count}</div>
|
||||
})}
|
||||
{zone.all_products.length > 20 && (
|
||||
<div style={{ color: '#94a3b8', marginTop: 4 }}>…+{zone.all_products.length - 20} ακόμα</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Printer target */}
|
||||
<div>
|
||||
<label style={{ display: 'block', fontSize: 11, fontWeight: 700, color: '#5a6169', textTransform: 'uppercase', letterSpacing: 0.5, marginBottom: 6 }}>Προορισμός</label>
|
||||
<select
|
||||
value={targetPrinter}
|
||||
onChange={e => setTargetPrinter(e.target.value)}
|
||||
style={{ width: '100%', border: '1px solid #d1d5db', borderRadius: 8, padding: '8px 10px', fontSize: 13, background: 'white', color: '#374151' }}
|
||||
>
|
||||
{printerOptions.map(o => <option key={o.value} value={o.value}>{o.label}</option>)}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
{/* Action button */}
|
||||
<button
|
||||
onClick={isBrowser ? handleBrowserPrint : handleThermalPrint}
|
||||
disabled={printing}
|
||||
style={{
|
||||
width: '100%', padding: '10px 0', borderRadius: 10, border: 'none', cursor: 'pointer',
|
||||
background: '#3758c9', color: 'white', fontWeight: 700, fontSize: 14,
|
||||
display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 8,
|
||||
opacity: printing ? 0.6 : 1,
|
||||
}}
|
||||
>
|
||||
<PrinterIcon size={16} />
|
||||
{printing ? 'Εκτύπωση…' : isBrowser ? 'Άνοιγμα / Εκτύπωση PDF' : 'Αποστολή στον Εκτυπωτή'}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ── Zone multi-select filter ──────────────────────────────────────────────────
|
||||
|
||||
function ZoneFilter({ zones, selected, onChange }) {
|
||||
const allSelected = selected.length === 0 || selected.length === zones.length
|
||||
|
||||
function toggleAll() { onChange([]) }
|
||||
function toggle(id) {
|
||||
if (allSelected) {
|
||||
onChange([id])
|
||||
} else {
|
||||
const next = selected.includes(id) ? selected.filter(z => z !== id) : [...selected, id]
|
||||
onChange(next.length === zones.length ? [] : next)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 6, flexWrap: 'wrap' }}>
|
||||
<span style={{ fontSize: 11, fontWeight: 600, color: '#8a9099', textTransform: 'uppercase', letterSpacing: 0.5 }}>Ζώνες:</span>
|
||||
<button
|
||||
onClick={toggleAll}
|
||||
style={{
|
||||
padding: '3px 10px', borderRadius: 999, fontSize: 11, fontWeight: 700,
|
||||
border: `1.5px solid ${allSelected ? '#3758c9' : '#d1d5db'}`,
|
||||
background: allSelected ? '#3758c9' : 'white',
|
||||
color: allSelected ? 'white' : '#374151',
|
||||
cursor: 'pointer',
|
||||
}}
|
||||
>
|
||||
Όλες
|
||||
</button>
|
||||
{zones.map(z => {
|
||||
const on = !allSelected && selected.includes(z.id)
|
||||
return (
|
||||
<button
|
||||
key={z.id}
|
||||
onClick={() => toggle(z.id)}
|
||||
style={{
|
||||
padding: '3px 10px', borderRadius: 999, fontSize: 11, fontWeight: 700,
|
||||
border: `1.5px solid ${on ? '#3758c9' : '#d1d5db'}`,
|
||||
background: on ? '#3758c9' : 'white',
|
||||
color: on ? 'white' : '#374151',
|
||||
cursor: 'pointer',
|
||||
}}
|
||||
>
|
||||
{z.name}
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ── Zone detail card ──────────────────────────────────────────────────────────
|
||||
|
||||
function ZoneDetailCard({ zone, queryParams, periodLabel }) {
|
||||
const [showPrintModal, setShowPrintModal] = useState(false)
|
||||
const [ordersExpanded, setOrdersExpanded] = useState(false)
|
||||
|
||||
function handleCSVItems() {
|
||||
downloadCSV(
|
||||
`prep-zone-${zone.name}-items.csv`,
|
||||
zone.all_products.map(p => [p.name, p.count, p.value]),
|
||||
['Προϊόν', 'Ποσότητα', 'Αξία (€)'],
|
||||
)
|
||||
}
|
||||
|
||||
function handleCSVOrders() {
|
||||
downloadCSV(
|
||||
`prep-zone-${zone.name}-orders.csv`,
|
||||
zone.all_orders.map(o => [o.order_id, o.table, o.opened_at ? new Date(o.opened_at).toLocaleString('el-GR') : '', o.items_count, o.value]),
|
||||
['Αρ. Παραγγελίας', 'Τραπέζι', 'Ώρα', 'Τεμάχια', 'Αξία (€)'],
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<div style={{
|
||||
border: '1px solid #e2e8f0', borderRadius: 14, overflow: 'hidden',
|
||||
background: 'white', boxShadow: '0 1px 3px rgba(0,0,0,0.06)',
|
||||
marginBottom: 16,
|
||||
}}>
|
||||
{/* Zone header bar */}
|
||||
<div style={{
|
||||
padding: '16px 20px', background: '#fafbff', borderBottom: '1px solid #e2e8f0',
|
||||
display: 'flex', alignItems: 'center', justifyContent: 'space-between', flexWrap: 'wrap', gap: 12,
|
||||
}}>
|
||||
<div>
|
||||
<div style={{ fontSize: 16, fontWeight: 700, color: '#111315', display: 'flex', alignItems: 'center', gap: 8 }}>
|
||||
<ConciergeBell size={16} style={{ color: '#3758c9' }} />
|
||||
{zone.name}
|
||||
{zone.notification_name && zone.notification_name !== zone.name && (
|
||||
<span style={{ fontSize: 12, color: '#8a9099', fontWeight: 500 }}>({zone.notification_name})</span>
|
||||
)}
|
||||
</div>
|
||||
{zone.printers.length > 0 && (
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 4, marginTop: 4 }}>
|
||||
<Printer size={11} style={{ color: '#8a9099' }} />
|
||||
<span style={{ fontSize: 11, color: '#8a9099' }}>{zone.printers.map(p => p.name).join(', ')}</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 16 }}>
|
||||
{/* Stats */}
|
||||
<div style={{ textAlign: 'right' }}>
|
||||
<div style={{ fontSize: 10, color: '#8a9099', fontWeight: 600, textTransform: 'uppercase', letterSpacing: 0.5 }}>Συνολικά Είδη</div>
|
||||
<div style={{ fontSize: 24, fontWeight: 700, color: '#111315', fontFamily: 'monospace' }}>{fmtNum(zone.item_count)}</div>
|
||||
</div>
|
||||
<div style={{ textAlign: 'right' }}>
|
||||
<div style={{ fontSize: 10, color: '#8a9099', fontWeight: 600, textTransform: 'uppercase', letterSpacing: 0.5 }}>Αξία</div>
|
||||
<div style={{ fontSize: 24, fontWeight: 700, color: '#3758c9', fontFamily: 'monospace' }}>{fmtEUR(zone.total_value)}</div>
|
||||
</div>
|
||||
|
||||
{/* Actions */}
|
||||
<div style={{ display: 'flex', gap: 6 }}>
|
||||
<button
|
||||
onClick={() => setShowPrintModal(true)}
|
||||
style={{
|
||||
display: 'flex', alignItems: 'center', gap: 5,
|
||||
padding: '6px 12px', borderRadius: 8, border: '1.5px solid #3758c9',
|
||||
background: '#3758c9', color: 'white',
|
||||
fontSize: 12, fontWeight: 700, cursor: 'pointer',
|
||||
}}
|
||||
>
|
||||
<PrinterIcon size={13} />
|
||||
Εκτύπωση
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{zone.item_count === 0 ? (
|
||||
<div style={{ padding: '32px 20px', textAlign: 'center', color: '#94a3b8', fontSize: 13 }}>
|
||||
Δεν βρέθηκαν παραγγελίες για αυτή την ζώνη στο επιλεγμένο διάστημα.
|
||||
</div>
|
||||
) : (
|
||||
<div style={{ padding: '0 0 4px' }}>
|
||||
{/* Items table */}
|
||||
<div style={{ padding: '14px 20px 8px', display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
|
||||
<div style={{ fontSize: 12, fontWeight: 700, color: '#374151', textTransform: 'uppercase', letterSpacing: 0.5 }}>
|
||||
Είδη ({zone.all_products.length})
|
||||
</div>
|
||||
<button
|
||||
onClick={handleCSVItems}
|
||||
style={{
|
||||
display: 'flex', alignItems: 'center', gap: 4,
|
||||
padding: '4px 10px', borderRadius: 6, border: '1px solid #d1d5db',
|
||||
background: 'white', color: '#374151', fontSize: 11, fontWeight: 600, cursor: 'pointer',
|
||||
}}
|
||||
>
|
||||
<Download size={11} />
|
||||
CSV Ειδών
|
||||
</button>
|
||||
</div>
|
||||
<DataTable>
|
||||
<THead>
|
||||
<TH>Προϊόν</TH>
|
||||
<TH>Ποσότητα</TH>
|
||||
<TH>Αξία</TH>
|
||||
</THead>
|
||||
<tbody>
|
||||
{zone.all_products.map((p, i) => (
|
||||
<TR key={p.name} striped>
|
||||
<TD className="font-medium">{p.name}</TD>
|
||||
<TD mono>{fmtNum(p.count)}</TD>
|
||||
<TD mono className="text-slate-500">{fmtEUR(p.value)}</TD>
|
||||
</TR>
|
||||
))}
|
||||
</tbody>
|
||||
</DataTable>
|
||||
|
||||
{/* Orders section */}
|
||||
<div style={{ padding: '14px 20px 8px', display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
|
||||
<button
|
||||
onClick={() => setOrdersExpanded(v => !v)}
|
||||
style={{
|
||||
display: 'flex', alignItems: 'center', gap: 6,
|
||||
background: 'none', border: 'none', cursor: 'pointer', padding: 0,
|
||||
fontSize: 12, fontWeight: 700, color: '#374151', textTransform: 'uppercase', letterSpacing: 0.5,
|
||||
}}
|
||||
>
|
||||
{ordersExpanded ? <ChevronUp size={14} /> : <ChevronDown size={14} />}
|
||||
Παραγγελίες ({zone.all_orders.length})
|
||||
</button>
|
||||
{ordersExpanded && (
|
||||
<button
|
||||
onClick={handleCSVOrders}
|
||||
style={{
|
||||
display: 'flex', alignItems: 'center', gap: 4,
|
||||
padding: '4px 10px', borderRadius: 6, border: '1px solid #d1d5db',
|
||||
background: 'white', color: '#374151', fontSize: 11, fontWeight: 600, cursor: 'pointer',
|
||||
}}
|
||||
>
|
||||
<Download size={11} />
|
||||
CSV Παραγγελιών
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
{ordersExpanded && (
|
||||
<DataTable>
|
||||
<THead>
|
||||
<TH>#</TH>
|
||||
<TH>Τραπέζι</TH>
|
||||
<TH>Ώρα</TH>
|
||||
<TH>Τεμάχια</TH>
|
||||
<TH>Αξία</TH>
|
||||
</THead>
|
||||
<tbody>
|
||||
{zone.all_orders.map(o => (
|
||||
<TR key={o.order_id} striped>
|
||||
<TD mono className="text-slate-400 text-[11px]">#{o.order_id}</TD>
|
||||
<TD className="font-medium">{o.table}</TD>
|
||||
<TD className="text-slate-500 text-[12px]">
|
||||
{o.opened_at ? new Date(o.opened_at).toLocaleTimeString('el-GR', { hour: '2-digit', minute: '2-digit' }) : '—'}
|
||||
</TD>
|
||||
<TD mono>{fmtNum(o.items_count)}</TD>
|
||||
<TD mono className="text-slate-500">{fmtEUR(o.value)}</TD>
|
||||
</TR>
|
||||
))}
|
||||
</tbody>
|
||||
</DataTable>
|
||||
)}
|
||||
<div style={{ height: 8 }} />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{showPrintModal && (
|
||||
<PrintModal
|
||||
zone={zone}
|
||||
queryParams={queryParams}
|
||||
periodLabel={periodLabel}
|
||||
onClose={() => setShowPrintModal(false)}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
// ── Main page ─────────────────────────────────────────────────────────────────
|
||||
|
||||
export default function PrepZonesPage() {
|
||||
const [mode, setMode] = useState('range')
|
||||
const [from, setFrom] = useState(monthAgo())
|
||||
const [to, setTo] = useState(today())
|
||||
const [businessDayId, setBusinessDayId] = useState('all')
|
||||
const [selectedZoneIds, setSelectedZoneIds] = useState([]) // [] = all
|
||||
|
||||
const { data: bdData } = useQuery({
|
||||
queryKey: ['business-days-list'],
|
||||
queryFn: () => client.get('/api/reports/business-days').then(r => r.data),
|
||||
staleTime: 60_000,
|
||||
})
|
||||
|
||||
const queryParams = {
|
||||
...(mode === 'workday' && businessDayId !== 'all' ? { business_day_id: businessDayId } : {}),
|
||||
...(mode === 'range' ? { from: from + 'T00:00:00', to: to + 'T23:59:59' } : {}),
|
||||
}
|
||||
|
||||
const { data, isLoading, isError, refetch } = useQuery({
|
||||
queryKey: ['prep-zones-report', mode, from, to, businessDayId],
|
||||
queryFn: () => client.get('/api/reports/prep-zones', { params: queryParams }).then(r => r.data),
|
||||
staleTime: 60_000,
|
||||
})
|
||||
|
||||
const bdOptions = [
|
||||
{ value: 'all', label: 'Όλες οι Εργάσιμες Μέρες' },
|
||||
...((bdData?.business_days || []).map(bd => ({
|
||||
value: String(bd.id),
|
||||
label: `${fmtDate(bd.opened_at)}`,
|
||||
}))),
|
||||
]
|
||||
|
||||
const allZones = data?.zones || []
|
||||
|
||||
const visibleZones = useMemo(() => {
|
||||
if (selectedZoneIds.length === 0) return allZones
|
||||
return allZones.filter(z => selectedZoneIds.includes(z.id))
|
||||
}, [allZones, selectedZoneIds])
|
||||
|
||||
const totalItems = visibleZones.reduce((s, z) => s + z.item_count, 0)
|
||||
const totalValue = visibleZones.reduce((s, z) => s + z.total_value, 0)
|
||||
const busyZone = visibleZones.reduce((best, z) => (!best || z.item_count > best.item_count ? z : best), null)
|
||||
|
||||
const periodLabel = useMemo(() => {
|
||||
if (mode === 'workday' && businessDayId !== 'all') {
|
||||
const bd = (bdData?.business_days || []).find(b => String(b.id) === businessDayId)
|
||||
return bd ? fmtDate(bd.opened_at) : `Εργάσιμη #${businessDayId}`
|
||||
}
|
||||
return `${from} – ${to}`
|
||||
}, [mode, businessDayId, from, to, bdData])
|
||||
|
||||
if (isLoading) return <div className="flex-1 overflow-y-auto p-6"><SkeletonTable rows={6} columns={4} /></div>
|
||||
if (isError) return (
|
||||
<div className="flex flex-col flex-1 min-h-0">
|
||||
<FilterBar><span className="text-[12px] text-slate-500">Αδυναμία φόρτωσης δεδομένων</span></FilterBar>
|
||||
<div className="flex flex-1 items-center justify-center">
|
||||
<button onClick={() => refetch()} className="rounded-md border border-slate-200 px-4 py-2 text-sm hover:bg-slate-50">Επανάληψη</button>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
|
||||
return (
|
||||
<div className="flex flex-col flex-1 min-h-0">
|
||||
<FilterBar>
|
||||
<WorkDayDateToggle mode={mode} onChange={setMode} />
|
||||
{mode === 'workday' ? (
|
||||
<FilterSelect value={businessDayId} onChange={setBusinessDayId} options={bdOptions} label="Μέρα" />
|
||||
) : (
|
||||
<>
|
||||
<FilterDateInput value={from} onChange={setFrom} label="Από" />
|
||||
<FilterDateInput value={to} onChange={setTo} label="Έως" />
|
||||
</>
|
||||
)}
|
||||
</FilterBar>
|
||||
|
||||
{/* Zone multi-select */}
|
||||
{allZones.length > 1 && (
|
||||
<div style={{ padding: '10px 20px', borderBottom: '1px solid #e2e8f0', background: 'white' }}>
|
||||
<ZoneFilter
|
||||
zones={allZones}
|
||||
selected={selectedZoneIds}
|
||||
onChange={setSelectedZoneIds}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="flex-1 overflow-y-auto p-6">
|
||||
{/* Summary stats */}
|
||||
<div className="grid grid-cols-3 gap-4 mb-6">
|
||||
<StatCard label="Συνολικά Είδη" value={fmtNum(totalItems)} icon={ConciergeBell} />
|
||||
<StatCard label="Συνολική Αξία" value={fmtEUR(totalValue)} icon={ConciergeBell} accent />
|
||||
<StatCard
|
||||
label="Πιο Απασχολημένη Ζώνη"
|
||||
value={busyZone?.name || '—'}
|
||||
sub={busyZone ? `${fmtNum(busyZone.item_count)} είδη` : undefined}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{allZones.length === 0 ? (
|
||||
<div className="flex flex-col items-center justify-center py-20 gap-3 text-slate-400">
|
||||
<ConciergeBell size={36} className="opacity-40" />
|
||||
<p className="text-[15px] font-semibold text-slate-500">Δεν βρέθηκαν ζώνες προετοιμασίας</p>
|
||||
<p className="text-[13px]">Δημιουργήστε ζώνες από το Management → Prep Zones.</p>
|
||||
</div>
|
||||
) : (
|
||||
<div>
|
||||
{visibleZones.map(zone => (
|
||||
<ZoneDetailCard
|
||||
key={zone.id}
|
||||
zone={zone}
|
||||
queryParams={queryParams}
|
||||
periodLabel={periodLabel}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import { useState } from 'react'
|
||||
import { TabBar } from '../../ui/Tabs'
|
||||
import ProductPerformance from './restaurant/ProductPerformance'
|
||||
import CategoryPerformance from './restaurant/CategoryPerformance'
|
||||
|
||||
const TABS = [
|
||||
{ id: 'products', label: 'Απόδοση Προϊόντων', Component: ProductPerformance },
|
||||
{ id: 'categories', label: 'Κατηγορίες', Component: CategoryPerformance },
|
||||
]
|
||||
|
||||
export default function ProductsReportPage() {
|
||||
const [active, setActive] = useState('products')
|
||||
const tab = TABS.find(t => t.id === active) || TABS[0]
|
||||
const { Component } = tab
|
||||
|
||||
return (
|
||||
<div className="flex flex-col h-full min-h-0">
|
||||
<TabBar tabs={TABS} active={active} onChange={setActive} />
|
||||
<div className="flex-1 min-h-0 flex flex-col">
|
||||
<Component key={active} />
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
import { useState } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { TabBar } from '../../ui/Tabs'
|
||||
import ShiftsOverview from './staff/ShiftsOverview'
|
||||
import Payments from './staff/Payments'
|
||||
import Activity from './staff/Activity'
|
||||
import StaffLeaderboard from './staff/StaffLeaderboard'
|
||||
|
||||
const TABS = [
|
||||
{ id: 'shifts', label: 'Βάρδιες', Component: ShiftsOverview },
|
||||
{ id: 'payments', label: 'Πληρωμές', Component: Payments },
|
||||
{ id: 'activity', label: 'Δραστηριότητα', Component: Activity },
|
||||
{ id: 'leaderboard', label: 'Κατάταξη', Component: StaffLeaderboard },
|
||||
]
|
||||
|
||||
export default function StaffReportPage() {
|
||||
const [active, setActive] = useState('shifts')
|
||||
const navigate = useNavigate()
|
||||
const tab = TABS.find(t => t.id === active) || TABS[0]
|
||||
const { Component } = tab
|
||||
|
||||
// ShiftsOverview uses onNavigate to drill into order history — redirect to Store page
|
||||
function handleNavigate({ parent, sub, ...rest }) {
|
||||
if (parent === 'restaurant' && sub === 'orders') {
|
||||
navigate('/reports/store')
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex flex-col h-full min-h-0">
|
||||
<TabBar tabs={TABS} active={active} onChange={setActive} />
|
||||
<div className="flex-1 min-h-0 flex flex-col">
|
||||
<Component key={active} onNavigate={handleNavigate} />
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
import { useState } from 'react'
|
||||
import { TabBar } from '../../ui/Tabs'
|
||||
import WorkDaySummary from './restaurant/WorkDaySummary'
|
||||
import OrderHistory from './restaurant/OrderHistory'
|
||||
import TrafficAnalytics from './restaurant/TrafficAnalytics'
|
||||
import RevenueTrends from './restaurant/RevenueTrends'
|
||||
import TableAnalytics from './restaurant/TableAnalytics'
|
||||
|
||||
const TABS = [
|
||||
{ id: 'workday', label: 'Ημέρες Λειτουργίας', Component: WorkDaySummary },
|
||||
{ id: 'orders', label: 'Ιστορικό Παραγγελιών', Component: OrderHistory },
|
||||
{ id: 'traffic', label: 'Κίνηση', Component: TrafficAnalytics },
|
||||
{ id: 'trends', label: 'Τάσεις Εσόδων', Component: RevenueTrends },
|
||||
{ id: 'tables', label: 'Τραπέζια', Component: TableAnalytics },
|
||||
]
|
||||
|
||||
export default function StorePage() {
|
||||
const [active, setActive] = useState('workday')
|
||||
const tab = TABS.find(t => t.id === active) || TABS[0]
|
||||
const { Component } = tab
|
||||
|
||||
return (
|
||||
<div className="flex flex-col h-full min-h-0">
|
||||
<TabBar tabs={TABS} active={active} onChange={setActive} />
|
||||
<div className="flex-1 min-h-0 flex flex-col">
|
||||
<Component key={active} />
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import { useState } from 'react'
|
||||
import { TabBar } from '../../ui/Tabs'
|
||||
import PrinterHistory from './operations/PrinterHistory'
|
||||
import PrinterHealthLog from './operations/PrinterHealthLog'
|
||||
|
||||
const TABS = [
|
||||
{ id: 'printer-history', label: 'Ιστορικό Εκτυπωτή', Component: PrinterHistory },
|
||||
{ id: 'printer-health', label: 'Υγεία Εκτυπωτή', Component: PrinterHealthLog },
|
||||
]
|
||||
|
||||
export default function TechnicalPage() {
|
||||
const [active, setActive] = useState('printer-history')
|
||||
const tab = TABS.find(t => t.id === active) || TABS[0]
|
||||
const { Component } = tab
|
||||
|
||||
return (
|
||||
<div className="flex flex-col h-full min-h-0">
|
||||
<TabBar tabs={TABS} active={active} onChange={setActive} />
|
||||
<div className="flex-1 min-h-0 flex flex-col">
|
||||
<Component key={active} />
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import Today from './restaurant/Today'
|
||||
|
||||
export default function TodayPage() {
|
||||
return (
|
||||
<div className="flex flex-col h-full min-h-0">
|
||||
<Today />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -83,7 +83,19 @@ export default function OrderHistory({ initialBusinessDayId } = {}) {
|
||||
</FilterBar>
|
||||
|
||||
<div className="flex-1 overflow-y-auto p-6">
|
||||
<Panel title="Παραγγελίες" subtitle={`${orders.length} αποτελέσματα`} padded={false}>
|
||||
<Panel
|
||||
padded={false}
|
||||
title={
|
||||
<span className="flex items-center gap-1.5">
|
||||
<span>Παραγγελίες</span>
|
||||
<span className="text-slate-300">·</span>
|
||||
<span className="font-normal text-slate-500">{orders.length} αποτελέσματα</span>
|
||||
</span>
|
||||
}
|
||||
right={
|
||||
<span className="text-[11px] text-slate-400 italic">Κάντε Click για Λεπτομέρειες Παραγγελίας</span>
|
||||
}
|
||||
>
|
||||
{orders.length === 0 ? (
|
||||
<EmptyState title="Δεν βρέθηκαν παραγγελίες" description="Δοκιμάστε διαφορετικό εύρος ημερομηνιών ή φίλτρο κατάστασης." />
|
||||
) : (
|
||||
@@ -91,7 +103,7 @@ export default function OrderHistory({ initialBusinessDayId } = {}) {
|
||||
<DataTable>
|
||||
<THead>
|
||||
<TH>#</TH><TH>Τραπέζι</TH><TH>Άνοιξε</TH><TH>Έκλεισε</TH>
|
||||
<TH>Κατάσταση</TH><TH align="right">Είδη</TH><TH align="right">Ακυρώσεις</TH><TH align="right">Σύνολο</TH><TH align="right" className="w-24"></TH>
|
||||
<TH>Κατάσταση</TH><TH align="right">Είδη</TH><TH align="right">Ακυρώσεις</TH><TH align="right">Σύνολο</TH>
|
||||
</THead>
|
||||
<tbody>
|
||||
{orders.slice(0, 200).map(o => {
|
||||
@@ -100,10 +112,10 @@ export default function OrderHistory({ initialBusinessDayId } = {}) {
|
||||
const cancelledItems = allItems.filter(i => i.status === 'cancelled')
|
||||
const totalQty = allItems.reduce((s, i) => s + (i.quantity || 1), 0)
|
||||
const cancelledQty = cancelledItems.reduce((s, i) => s + (i.quantity || 1), 0)
|
||||
const total = activeItems.reduce((s, i) => s + i.unit_price * i.quantity, 0)
|
||||
const total = activeItems.reduce((s, i) => s + ((i.unit_price ?? 0) + (i.price_adjustment ?? 0)) * i.quantity, 0)
|
||||
const isCancelled = o.status === 'cancelled'
|
||||
return (
|
||||
<TR key={o.id} striped className={isCancelled ? 'opacity-50' : ''}>
|
||||
<TR key={o.id} striped onClick={() => setDrillOrder(o)} className={isCancelled ? 'opacity-50' : ''}>
|
||||
<TD mono>#{o.id}</TD>
|
||||
<TD>{o.table_name ?? o.table_id}</TD>
|
||||
<TD mono>{fmtDateTime(o.opened_at)}</TD>
|
||||
@@ -116,14 +128,6 @@ export default function OrderHistory({ initialBusinessDayId } = {}) {
|
||||
: <span className="text-slate-300">—</span>}
|
||||
</TD>
|
||||
<TD mono align="right" className="font-semibold text-slate-900">{fmtEUR(total)}</TD>
|
||||
<TD align="right">
|
||||
<button
|
||||
onClick={() => setDrillOrder(o)}
|
||||
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>
|
||||
</TD>
|
||||
</TR>
|
||||
)
|
||||
})}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { useState } from 'react'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { BarChart, Bar, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer, Cell } from 'recharts'
|
||||
import { TrendingUp, ReceiptText, Clock, Users, Trophy, XCircle, Package, Sunset, PiggyBank, ShoppingBag } from 'lucide-react'
|
||||
@@ -8,9 +9,12 @@ import StatCard from '../shared/StatCard'
|
||||
import EmptyState from '../shared/EmptyState'
|
||||
import SkeletonTable from '../shared/SkeletonTable'
|
||||
import ExportButton from '../shared/ExportButton'
|
||||
import OrderDetailModal from '../shared/OrderDetailModal'
|
||||
import { fmtEUR, fmtNum, fmtTime, fmtDateTime } from '../shared/reportDesignTokens'
|
||||
|
||||
export default function Today() {
|
||||
const [drillOrder, setDrillOrder] = useState(null)
|
||||
|
||||
const { data: bdData, isLoading: bdLoading } = useQuery({
|
||||
queryKey: ['business-day-current'],
|
||||
queryFn: () => client.get('/api/reports/business-days/current').then(r => r.data),
|
||||
@@ -164,13 +168,26 @@ export default function Today() {
|
||||
</div>
|
||||
|
||||
<div className="mt-4">
|
||||
<Panel title="Παραγγελίες Σήμερα" subtitle={`${orders.length} συνολικά`} padded={false} right={
|
||||
<ExportButton
|
||||
endpoint="/api/reports/orders/export"
|
||||
params={{ business_day_id: bd.id }}
|
||||
filename={`today-orders-${bd.id}.csv`}
|
||||
/>
|
||||
}>
|
||||
<Panel
|
||||
padded={false}
|
||||
title={
|
||||
<span className="flex items-center gap-1.5">
|
||||
<span>Παραγγελίες Σήμερα</span>
|
||||
<span className="text-slate-300">·</span>
|
||||
<span className="font-normal text-slate-500">{orders.length} συνολικά</span>
|
||||
</span>
|
||||
}
|
||||
right={
|
||||
<div className="flex items-center gap-3">
|
||||
<span className="text-[11px] text-slate-400 italic">Κάντε Click για Λεπτομέρειες Παραγγελίας</span>
|
||||
<ExportButton
|
||||
endpoint="/api/reports/orders/export"
|
||||
params={{ business_day_id: bd.id }}
|
||||
filename={`today-orders-${bd.id}.csv`}
|
||||
/>
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<DataTable>
|
||||
<THead>
|
||||
<TH>#</TH><TH>Τραπέζι</TH><TH>Άνοιξε</TH><TH>Έκλεισε</TH>
|
||||
@@ -179,14 +196,14 @@ export default function Today() {
|
||||
<tbody>
|
||||
{orders.slice(0, 30).map(o => {
|
||||
const activeItems = (o.items || []).filter(i => ['active', 'paid'].includes(i.status))
|
||||
const total = activeItems.reduce((s, i) => s + i.unit_price * i.quantity, 0)
|
||||
const total = activeItems.reduce((s, i) => s + ((i.unit_price ?? 0) + (i.price_adjustment ?? 0)) * i.quantity, 0)
|
||||
const costedItems = activeItems.filter(i => i.unit_cost != null)
|
||||
const orderProfit = costedItems.length > 0
|
||||
? costedItems.reduce((s, i) => s + (i.unit_price - i.unit_cost) * i.quantity, 0)
|
||||
? costedItems.reduce((s, i) => s + ((i.unit_price ?? 0) + (i.price_adjustment ?? 0) - (i.unit_cost ?? 0)) * i.quantity, 0)
|
||||
: null
|
||||
const isCancelled = o.status === 'cancelled'
|
||||
return (
|
||||
<TR key={o.id} striped className={isCancelled ? 'opacity-50' : ''}>
|
||||
<TR key={o.id} striped onClick={() => setDrillOrder(o)} className={isCancelled ? 'opacity-50' : ''}>
|
||||
<TD mono>#{o.id}</TD>
|
||||
<TD>{o.table_id}</TD>
|
||||
<TD mono>{fmtDateTime(o.opened_at)}</TD>
|
||||
@@ -208,6 +225,10 @@ export default function Today() {
|
||||
</Panel>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{drillOrder && (
|
||||
<OrderDetailModal order={drillOrder} onClose={() => setDrillOrder(null)} />
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useState } from 'react'
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
import { Trash2 } from 'lucide-react'
|
||||
import { Trash2, Pencil, Check, X as XIcon } from 'lucide-react'
|
||||
import toast from 'react-hot-toast'
|
||||
import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer, Legend } from 'recharts'
|
||||
import client from '../../../api/client'
|
||||
@@ -18,8 +18,73 @@ import { fmtEUR, fmtNum, fmtDate, fmtTime, fmtDuration, fmtDateTime, fmtDateStr
|
||||
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) }
|
||||
|
||||
// ── Edit close-time inline control ─────────────────────────────────────────
|
||||
function EditCloseTime({ day, onSaved }) {
|
||||
const [editing, setEditing] = useState(false)
|
||||
const [value, setValue] = useState('')
|
||||
const qc = useQueryClient()
|
||||
|
||||
function startEdit() {
|
||||
// pre-fill with current closed_at in local datetime-local format
|
||||
const d = day.closed_at ? new Date(day.closed_at) : new Date()
|
||||
const pad = n => String(n).padStart(2, '0')
|
||||
const local = `${d.getFullYear()}-${pad(d.getMonth()+1)}-${pad(d.getDate())}T${pad(d.getHours())}:${pad(d.getMinutes())}`
|
||||
setValue(local)
|
||||
setEditing(true)
|
||||
}
|
||||
|
||||
const mut = useMutation({
|
||||
mutationFn: (iso) => client.patch(`/api/business-day/${day.id}`, { closed_at: iso }).then(r => r.data),
|
||||
onSuccess: (data) => {
|
||||
toast.success('Ώρα κλεισίματος ενημερώθηκε')
|
||||
qc.invalidateQueries({ queryKey: ['business-days'] })
|
||||
setEditing(false)
|
||||
onSaved && onSaved(data)
|
||||
},
|
||||
onError: (err) => toast.error(err?.response?.data?.detail || 'Σφάλμα ενημέρωσης'),
|
||||
})
|
||||
|
||||
if (!editing) {
|
||||
return (
|
||||
<button
|
||||
onClick={startEdit}
|
||||
title="Επεξεργασία ώρας κλεισίματος"
|
||||
className="ml-1 rounded p-0.5 text-slate-400 hover:text-slate-700 hover:bg-slate-100"
|
||||
>
|
||||
<Pencil size={13} />
|
||||
</button>
|
||||
)
|
||||
}
|
||||
|
||||
function handleSave() {
|
||||
if (!value) return
|
||||
const iso = new Date(value).toISOString()
|
||||
mut.mutate(iso)
|
||||
}
|
||||
|
||||
return (
|
||||
<span className="inline-flex items-center gap-1 ml-1">
|
||||
<input
|
||||
type="datetime-local"
|
||||
value={value}
|
||||
onChange={e => setValue(e.target.value)}
|
||||
className="rounded border border-slate-300 px-1 py-0 text-[11px] font-mono text-slate-700 focus:outline-none focus:ring-1 focus:ring-slate-400"
|
||||
style={{ height: 22 }}
|
||||
max={new Date().toISOString().slice(0, 16)}
|
||||
/>
|
||||
<button onClick={handleSave} disabled={mut.isPending} className="rounded p-0.5 text-emerald-600 hover:bg-emerald-50" title="Αποθήκευση">
|
||||
<Check size={14} />
|
||||
</button>
|
||||
<button onClick={() => setEditing(false)} className="rounded p-0.5 text-slate-400 hover:bg-slate-100" title="Ακύρωση">
|
||||
<XIcon size={14} />
|
||||
</button>
|
||||
</span>
|
||||
)
|
||||
}
|
||||
|
||||
// ── Workday drill-down modal ────────────────────────────────────────────────
|
||||
function WorkDayModal({ day, onClose, onDeleteShift }) {
|
||||
function WorkDayModal({ day: initialDay, onClose, onDeleteShift }) {
|
||||
const [day, setDay] = useState(initialDay)
|
||||
const [tab, setTab] = useState('orders')
|
||||
const [drillOrder, setDrillOrder] = useState(null)
|
||||
const [detailShift, setDetailShift] = useState(null)
|
||||
@@ -44,11 +109,44 @@ function WorkDayModal({ day, onClose, onDeleteShift }) {
|
||||
{ key: 'shifts', label: `Βάρδιες (${shifts.length})` },
|
||||
]
|
||||
|
||||
const hasCost = (day.total_cost || 0) > 0
|
||||
const hasProfit = (day.trackable_profit || 0) > 0
|
||||
|
||||
// Build the rich subtitle
|
||||
const openDate = fmtDate(day.opened_at)
|
||||
const closeDate = day.closed_at ? fmtDate(day.closed_at) : null
|
||||
const openTime = fmtTime(day.opened_at)
|
||||
const closeTime = day.closed_at ? fmtTime(day.closed_at) : null
|
||||
const spansDays = closeDate && closeDate !== openDate
|
||||
|
||||
const subtitleParts = [
|
||||
`${fmtEUR(day.revenue)} έσοδα`,
|
||||
hasCost ? `${fmtEUR(day.total_cost)} Έξοδα` : null,
|
||||
hasProfit ? `${fmtEUR(day.trackable_profit)} Κέρδος` : null,
|
||||
].filter(Boolean)
|
||||
|
||||
const openLabel = spansDays ? `${openDate} ${openTime}` : openTime
|
||||
const closeLabel = day.closed_at
|
||||
? (spansDays ? `${closeDate} ${closeTime}` : closeTime)
|
||||
: 'ανοιχτή'
|
||||
|
||||
const subtitle = subtitleParts.join(' · ')
|
||||
const timeRange = `${openLabel} – ${closeLabel}`
|
||||
|
||||
return (
|
||||
<>
|
||||
<DrillDownModal
|
||||
title={`Εργάσιμη Μέρα · ${fmtDate(day.opened_at)}`}
|
||||
subtitle={`${fmtEUR(day.revenue)} έσοδα · ${fmtTime(day.opened_at)} – ${day.closed_at ? fmtTime(day.closed_at) : 'ανοιχτή'}`}
|
||||
subtitle={
|
||||
<span>
|
||||
{subtitle}
|
||||
<span className="text-slate-400 mx-1">·</span>
|
||||
{timeRange}
|
||||
{day.status === 'closed' && (
|
||||
<EditCloseTime day={day} onSaved={updated => setDay(d => ({ ...d, closed_at: updated.closed_at }))} />
|
||||
)}
|
||||
</span>
|
||||
}
|
||||
onClose={onClose}
|
||||
>
|
||||
{/* Tabs */}
|
||||
@@ -80,7 +178,7 @@ function WorkDayModal({ day, onClose, onDeleteShift }) {
|
||||
const cancelledItems = allItems.filter(i => i.status === 'cancelled')
|
||||
const totalQty = allItems.reduce((s, i) => s + (i.quantity || 1), 0)
|
||||
const cancelledQty = cancelledItems.reduce((s, i) => s + (i.quantity || 1), 0)
|
||||
const total = activeItems.reduce((s, i) => s + i.unit_price * i.quantity, 0)
|
||||
const total = activeItems.reduce((s, i) => s + ((i.unit_price ?? 0) + (i.price_adjustment ?? 0)) * i.quantity, 0)
|
||||
return (
|
||||
<TR key={o.id} striped onClick={() => setDrillOrder(o)} className="cursor-pointer">
|
||||
<TD mono>#{o.id}</TD>
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { useState } from 'react'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { X } from 'lucide-react'
|
||||
import { fmtEUR, fmtDateTime } from './reportDesignTokens'
|
||||
import client from '../../../api/client'
|
||||
|
||||
// ── Status badge ────────────────────────────────────────────────────────────
|
||||
const STATUS_META = {
|
||||
@@ -47,6 +49,7 @@ const EVENT_LABELS = {
|
||||
ORDER_CLOSED: { label: 'Κλείσιμο', bg: '#f9fafb', text: '#374151' },
|
||||
ORDER_CANCELLED: { label: 'Ακύρωση', bg: '#fef2f2', text: '#b91c1c' },
|
||||
ITEM_CANCELLED: { label: 'Ακύρωση αντ.', bg: '#fef2f2', text: '#b91c1c' },
|
||||
PAYMENT_REVERTED:{ label: 'Αναίρεση Πληρωμής', bg: '#fffbeb', text: '#b45309' },
|
||||
}
|
||||
|
||||
function AuditTimeline({ logs, itemsById }) {
|
||||
@@ -115,11 +118,12 @@ function AuditTimeline({ logs, itemsById }) {
|
||||
}
|
||||
|
||||
// ── Items tab ───────────────────────────────────────────────────────────────
|
||||
function ItemsTab({ order }) {
|
||||
function ItemsTab({ order, priceEventsMap = {} }) {
|
||||
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)
|
||||
const effPrice = i => (i.unit_price ?? 0) + (i.price_adjustment ?? 0)
|
||||
const closedTotal = billableItems.filter(i => i.status === 'closed').reduce((s, i) => s + effPrice(i) * i.quantity, 0)
|
||||
const total = billableItems.reduce((s, i) => s + effPrice(i) * i.quantity, 0)
|
||||
|
||||
if (itemsFiltered.length === 0) {
|
||||
return <p style={{ color: '#b8bdc4', fontSize: 13, textAlign: 'center', padding: '12px 0' }}>Κανένα αντικείμενο</p>
|
||||
@@ -128,6 +132,8 @@ function ItemsTab({ order }) {
|
||||
// Column widths: [item info] [ordered by] [paid by] [pay type] [total]
|
||||
const GRID = '1fr 150px 150px 110px 80px'
|
||||
|
||||
const EVENT_COLORS = { modifier_applied: '#2563eb', waiter_discount: '#7c3aed', free_item_added: '#16a34a' }
|
||||
|
||||
return (
|
||||
<div style={{ borderRadius: 10, border: '1px solid #edeff1', overflow: 'hidden', marginBottom: 16 }}>
|
||||
{/* Header */}
|
||||
@@ -141,23 +147,37 @@ function ItemsTab({ order }) {
|
||||
|
||||
{itemsFiltered.map(item => {
|
||||
const isCancelled = item.status === 'cancelled'
|
||||
const hasPriceAdj = !!(item.price_adjustment && item.price_adjustment !== 0)
|
||||
const isDealItem = !!item.deal_id
|
||||
const itemEvents = (priceEventsMap[item.id] ?? []).filter(ev => ['modifier_applied','waiter_discount','free_item_added'].includes(ev.event_type))
|
||||
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',
|
||||
}}>
|
||||
<div key={item.id} style={{ borderTop: '1px solid #f4f4f2', opacity: isCancelled ? 0.45 : 1, background: isCancelled ? '#fef2f2' : item.status === 'closed' ? '#fffbeb' : 'white' }}>
|
||||
<div style={{ display: 'grid', gridTemplateColumns: GRID, gap: 12, padding: '9px 14px' }}>
|
||||
{/* Item info */}
|
||||
<div>
|
||||
<div style={{ fontSize: 13, fontWeight: 600, color: '#111315', textDecoration: isCancelled ? 'line-through' : 'none' }}>
|
||||
<div style={{ fontSize: 13, fontWeight: 600, color: '#111315', textDecoration: isCancelled ? 'line-through' : 'none', display: 'flex', alignItems: 'center', gap: 5, flexWrap: 'wrap' }}>
|
||||
{item.product?.name ?? `#${item.product_id}`}
|
||||
{isDealItem && <span style={{ fontSize: 10, fontWeight: 700, padding: '1px 5px', borderRadius: 4, background: 'rgba(167,139,250,0.12)', color: '#7c3aed', border: '1px solid rgba(167,139,250,0.3)' }}>ΔΩΡΕΑΝ</span>}
|
||||
</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>
|
||||
<span style={{ fontSize: 12, color: hasPriceAdj ? '#3b82f6' : '#374151', fontFamily: 'ui-monospace,monospace' }}>{fmtEUR(effPrice(item))}</span>
|
||||
{hasPriceAdj && (
|
||||
<span style={{ fontSize: 10, color: '#9ca3af', fontFamily: 'ui-monospace,monospace', textDecoration: 'line-through' }}>{fmtEUR(item.unit_price)}</span>
|
||||
)}
|
||||
<StatusPill status={item.status} />
|
||||
</div>
|
||||
{itemEvents.map((ev, ei) => {
|
||||
const evColor = EVENT_COLORS[ev.event_type] || '#8a9099'
|
||||
const evLabel = ev.modifier_name || ev.deal_name || (ev.event_type === 'waiter_discount' ? 'Έκπτωση' : ev.event_type === 'free_item_added' ? 'Δωρεάν' : ev.event_type)
|
||||
return (
|
||||
<div key={ei} style={{ display: 'flex', alignItems: 'center', gap: 4, marginTop: 2, fontSize: 11, color: evColor }}>
|
||||
<span style={{ opacity: 0.6 }}>↳</span>
|
||||
<span style={{ flex: 1 }}>{evLabel}</span>
|
||||
{ev.delta_amount != null && <span style={{ fontWeight: 600 }}>{ev.delta_amount > 0 ? '+' : ''}{ev.delta_amount.toFixed(2)} €</span>}
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
|
||||
{/* Ordered by */}
|
||||
@@ -183,8 +203,9 @@ function ItemsTab({ order }) {
|
||||
</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 style={{ fontSize: 13, fontWeight: 700, color: hasPriceAdj ? '#3b82f6' : '#111315', textAlign: 'right', fontFamily: 'ui-monospace,monospace', paddingTop: 2 }}>
|
||||
{fmtEUR(effPrice(item) * item.quantity)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
@@ -207,6 +228,19 @@ function ItemsTab({ order }) {
|
||||
// ── Main modal ──────────────────────────────────────────────────────────────
|
||||
export default function OrderDetailModal({ order, onClose }) {
|
||||
const [tab, setTab] = useState('items')
|
||||
|
||||
const { data: rawPriceEvents = [] } = useQuery({
|
||||
queryKey: ['price-events', order?.id],
|
||||
queryFn: () => client.get(`/api/pricing/events/order/${order.id}`).then(r => r.data),
|
||||
enabled: !!order?.id,
|
||||
staleTime: 60_000,
|
||||
})
|
||||
const priceEventsMap = rawPriceEvents.reduce((acc, ev) => {
|
||||
if (!acc[ev.order_item_id]) acc[ev.order_item_id] = []
|
||||
acc[ev.order_item_id].push(ev)
|
||||
return acc
|
||||
}, {})
|
||||
|
||||
if (!order) return null
|
||||
|
||||
const itemsById = Object.fromEntries((order.items || []).map(i => [i.id, i]))
|
||||
@@ -277,7 +311,7 @@ export default function OrderDetailModal({ order, onClose }) {
|
||||
|
||||
{/* Tab content */}
|
||||
<div style={{ flex: 1, overflowY: 'auto', padding: '16px 24px' }}>
|
||||
{tab === 'items' && <ItemsTab order={order} />}
|
||||
{tab === 'items' && <ItemsTab order={order} priceEventsMap={priceEventsMap} />}
|
||||
{tab === 'audit' && <AuditTimeline logs={order.audit_logs} itemsById={itemsById} />}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -4,6 +4,101 @@ import { X } from 'lucide-react'
|
||||
import client from '../../../api/client'
|
||||
import { fmtEUR, fmtDateTime, fmtTime, fmtDate } from './reportDesignTokens'
|
||||
|
||||
function fmtDur(ms) {
|
||||
const totalMin = Math.round(ms / 60000)
|
||||
const h = Math.floor(totalMin / 60)
|
||||
const m = totalMin % 60
|
||||
return h > 0 ? `${h}ω ${m}λ` : `${m}λ`
|
||||
}
|
||||
|
||||
// ── Breaks timeline bar ──────────────────────────────────────────────────────
|
||||
function BreaksTimeline({ started_at, ended_at, breaks }) {
|
||||
if (!breaks || breaks.length === 0) return null
|
||||
|
||||
const start = new Date(started_at).getTime()
|
||||
const end = ended_at ? new Date(ended_at).getTime() : Date.now()
|
||||
const total = end - start
|
||||
if (total <= 0) return null
|
||||
|
||||
return (
|
||||
<div style={{ padding: '10px 24px 12px', background: '#fafafa', borderBottom: '1px solid #edeff1', flexShrink: 0 }}>
|
||||
<div style={{ fontSize: 10, fontWeight: 700, color: '#8a9099', textTransform: 'uppercase', letterSpacing: 0.6, marginBottom: 6 }}>
|
||||
Διαλείμματα
|
||||
</div>
|
||||
<div style={{ position: 'relative', height: 8, borderRadius: 4, background: '#e2e8f0', overflow: 'hidden' }}>
|
||||
{/* work = whole bar base */}
|
||||
{breaks.map((b, i) => {
|
||||
const bs = new Date(b.started_at).getTime()
|
||||
const be = b.ended_at ? new Date(b.ended_at).getTime() : Date.now()
|
||||
const left = Math.max(0, ((bs - start) / total) * 100)
|
||||
const width = Math.min(100 - left, ((be - bs) / total) * 100)
|
||||
return (
|
||||
<div
|
||||
key={b.id}
|
||||
title={`Διάλειμμα ${fmtTime(b.started_at)} – ${b.ended_at ? fmtTime(b.ended_at) : 'ενεργό'} · Διάρκεια: ${fmtDur(be - bs)}`}
|
||||
style={{
|
||||
position: 'absolute', top: 0, height: '100%',
|
||||
left: `${left}%`, width: `${width}%`,
|
||||
background: '#f59e0b', borderRadius: 2,
|
||||
}}
|
||||
/>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
<div style={{ display: 'flex', flexWrap: 'wrap', gap: '4px 16px', marginTop: 6 }}>
|
||||
{breaks.map(b => {
|
||||
const bs = new Date(b.started_at).getTime()
|
||||
const be = b.ended_at ? new Date(b.ended_at).getTime() : Date.now()
|
||||
return (
|
||||
<span key={b.id} style={{ fontSize: 11, color: '#5a6169' }}>
|
||||
<span style={{ color: '#b45309', fontWeight: 700 }}>◼</span>{' '}
|
||||
{fmtTime(b.started_at)} – {b.ended_at ? fmtTime(b.ended_at) : 'ενεργό'} · {fmtDur(be - bs)}
|
||||
</span>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ── Order-status distribution bar ───────────────────────────────────────────
|
||||
function StatusDistributionBar({ counts }) {
|
||||
const total = counts.all || 1
|
||||
const segments = [
|
||||
{ key: 'both', color: '#16a34a', label: 'Πλήρης' },
|
||||
{ key: 'paid', color: '#2563eb', label: 'Πληρώθηκε' },
|
||||
{ key: 'ordered', color: '#ca8a04', label: 'Παρήγγειλε' },
|
||||
{ key: 'unpaid', color: '#ea580c', label: 'Ανοιχτό' },
|
||||
{ key: 'cancelled', color: '#dc2626', label: 'Ακύρωση' },
|
||||
].filter(s => counts[s.key] > 0)
|
||||
|
||||
if (segments.length === 0) return null
|
||||
|
||||
return (
|
||||
<div style={{ marginTop: 10 }}>
|
||||
{/* bar */}
|
||||
<div style={{ display: 'flex', height: 8, borderRadius: 4, overflow: 'hidden', gap: 1 }}>
|
||||
{segments.map(s => (
|
||||
<div
|
||||
key={s.key}
|
||||
title={`${s.label}: ${counts[s.key]} (${Math.round(counts[s.key] / total * 100)}%)`}
|
||||
style={{ flex: counts[s.key], background: s.color, minWidth: 2 }}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
{/* legend with % */}
|
||||
<div style={{ display: 'flex', flexWrap: 'wrap', gap: '4px 14px', marginTop: 6 }}>
|
||||
{segments.map(s => (
|
||||
<span key={s.key} style={{ fontSize: 10, color: '#5a6169', display: 'flex', alignItems: 'center', gap: 4 }}>
|
||||
<span style={{ width: 7, height: 7, borderRadius: '50%', background: s.color, flexShrink: 0, display: 'inline-block' }} />
|
||||
{s.label}: {counts[s.key]} ({Math.round(counts[s.key] / total * 100)}%)
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ── colour rules ────────────────────────────────────────────────────────────
|
||||
function classify(item, shiftWaiterId) {
|
||||
if (item.status === 'cancelled')
|
||||
@@ -210,19 +305,30 @@ export default function ShiftDetailModal({ shiftId, shiftWaiterId, onClose }) {
|
||||
? '✓ Εντάξει'
|
||||
: discrepancy < 0
|
||||
? `Έλλειμμα ${fmtEUR(Math.abs(discrepancy))}`
|
||||
: `Πλεόνασμα ${fmtEUR(discrepancy)}`
|
||||
: `Πλεόνασμα +${fmtEUR(discrepancy)}`
|
||||
const discAccent = discrepancy == null
|
||||
? undefined
|
||||
: Math.abs(discrepancy) < 0.005 ? '#16a34a' : '#dc2626'
|
||||
: Math.abs(discrepancy) < 0.005
|
||||
? '#16a34a'
|
||||
: discrepancy > 0
|
||||
? '#16a34a' // surplus → green
|
||||
: '#dc2626' // shortage → red
|
||||
|
||||
const cancelEvents = summary.cancellation_events ?? 0
|
||||
const cancelItemsQty = summary.orders
|
||||
? summary.orders.reduce((s, o) => s + o.items.filter(i => i.status === 'cancelled').reduce((ss, i) => ss + i.quantity, 0), 0)
|
||||
: 0
|
||||
|
||||
const cashSales = summary.cash_sales ?? summary.total_collected ?? 0
|
||||
const cardSales = summary.card_sales ?? 0
|
||||
const totalRev = cashSales + cardSales
|
||||
const collectLabel = cardSales > 0
|
||||
? `${fmtEUR(cashSales)} + ${fmtEUR(cardSales)}`
|
||||
: fmtEUR(cashSales)
|
||||
|
||||
const row2 = [
|
||||
{ label: 'Σύνολο Παραγγελιών', value: String(totalOrders) },
|
||||
{ label: 'Εισπράξεις', value: fmtEUR(summary.total_collected), accent: '#2f9e5e' },
|
||||
{ label: 'Εισπράξεις (μετρητά + κάρτα)', value: collectLabel, accent: '#2f9e5e' },
|
||||
{
|
||||
label: 'Ακυρώσεις',
|
||||
value: cancelEvents > 0 ? `${cancelEvents} / ${cancelItemsQty} είδη` : '—',
|
||||
@@ -246,14 +352,16 @@ export default function ShiftDetailModal({ shiftId, shiftWaiterId, onClose }) {
|
||||
)
|
||||
})()}
|
||||
|
||||
{/* Colour legend */}
|
||||
<div style={{ display: 'flex', gap: 12, padding: '8px 24px', background: '#fafafa', borderBottom: '1px solid #edeff1', flexShrink: 0, flexWrap: 'wrap' }}>
|
||||
{LEGEND.map(l => (
|
||||
<div key={l.label} 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>
|
||||
))}
|
||||
{/* Breaks timeline (hidden when no breaks) */}
|
||||
<BreaksTimeline
|
||||
started_at={summary.started_at}
|
||||
ended_at={summary.ended_at}
|
||||
breaks={summary.breaks || []}
|
||||
/>
|
||||
|
||||
{/* Status distribution bar */}
|
||||
<div style={{ padding: '8px 24px 10px', background: '#fafafa', borderBottom: '1px solid #edeff1', flexShrink: 0 }}>
|
||||
<StatusDistributionBar counts={counts} />
|
||||
</div>
|
||||
|
||||
{/* Filter bar */}
|
||||
|
||||
@@ -159,23 +159,32 @@ export default function ShiftsOverview({ onNavigate } = {}) {
|
||||
: <span className="text-slate-400 text-[11px]">Δεν παρακολουθείται</span>}
|
||||
</TD>
|
||||
<TD mono align="right">{fmtEUR(s.starting_cash)}</TD>
|
||||
<TD mono align="right">{fmtEUR(s.total_collected)}</TD>
|
||||
<TD mono align="right">
|
||||
<span className="font-semibold text-emerald-700">{fmtEUR(s.cash_sales ?? s.total_collected)}</span>
|
||||
{(s.card_sales ?? 0) > 0 && (
|
||||
<span className="block text-[10px] text-slate-400">+{fmtEUR(s.card_sales)} κάρτα</span>
|
||||
)}
|
||||
</TD>
|
||||
<TD mono align="right" className="font-semibold text-slate-900">{fmtEUR(s.net_to_deliver)}</TD>
|
||||
<TD mono align="right">
|
||||
{s.counted_cash_end != null ? (
|
||||
<span className={
|
||||
s.cash_discrepancy == null || Math.abs(s.cash_discrepancy) < 0.005
|
||||
? 'text-emerald-600 font-semibold'
|
||||
: 'text-red-600 font-semibold'
|
||||
}>
|
||||
{fmtEUR(s.counted_cash_end)}
|
||||
{s.cash_discrepancy != null && Math.abs(s.cash_discrepancy) >= 0.005 && (
|
||||
<span className="block text-[10px] font-medium">
|
||||
{s.cash_discrepancy > 0 ? '+' : ''}{fmtEUR(s.cash_discrepancy)}
|
||||
</span>
|
||||
)}
|
||||
</span>
|
||||
) : (
|
||||
{s.counted_cash_end != null ? (() => {
|
||||
const d = s.cash_discrepancy
|
||||
const isClean = d == null || Math.abs(d) < 0.005
|
||||
const isSurplus = d != null && d > 0.005
|
||||
const colorClass = isClean ? 'text-emerald-600 font-semibold'
|
||||
: isSurplus ? 'text-emerald-600 font-semibold'
|
||||
: 'text-red-600 font-semibold'
|
||||
return (
|
||||
<span className={colorClass}>
|
||||
{fmtEUR(s.counted_cash_end)}
|
||||
{d != null && Math.abs(d) >= 0.005 && (
|
||||
<span className="block text-[10px] font-medium">
|
||||
{isSurplus ? `+${fmtEUR(d)}` : `−${fmtEUR(Math.abs(d))}`}
|
||||
</span>
|
||||
)}
|
||||
</span>
|
||||
)
|
||||
})() : (
|
||||
<span className="text-slate-400 text-[11px]">—</span>
|
||||
)}
|
||||
</TD>
|
||||
|
||||
Reference in New Issue
Block a user