feat: the staff, cancellations/discounts, technical, prep zones and expenses reports on v2; reports all on v2 (platform-v2 step 6.12c)
- Reports -> Staff (src/pages/reports/staff): shifts (pay, collected, to hand over, the counted difference, cancellations; a shift opens the overview's shift dialog; the owner deletes one), cash handover (starting cash, cash, card, refunds, to hand over, counted), sales by person (orders, units, cancellations, hours, sales net of refunds, per hour, share; ranked) - the v1 activity and leaderboard views merged into it - Reports -> Cancellations and discounts (src/pages/reports/misc), with totals per person; Technical (printing: tickets, failed, printed first time, per printer, every ticket with its error, the receipt-printer summary; logs for the owner) - v1 printer history + printer health merged - Prep zones report (per zone: items, value, products, orders; per-zone Excel downloads built in the browser with the server's Excel rules; print a zone) and Expenses report (period, status, category; split by category or supplier; payments) - its categories now match what Finance saves (the v1 report listed categories that never existed) - kit: csvText() / download(); PrintDialog modes for the printer summary - v1 report kit (reports/shared) and every v1 report view deleted; src/pages/reports is v2 (all but LogsPanel strict) - tests: reports.test.mjs (+1), e2e manager.mjs (every report opens, a shift's details, the ranking) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -47,12 +47,12 @@ import StockPage from './pages/inventory/StockPage'
|
|||||||
// Reports
|
// Reports
|
||||||
import TodayPage from './pages/reports/today/TodayReport'
|
import TodayPage from './pages/reports/today/TodayReport'
|
||||||
import StorePage from './pages/reports/store/StorePage'
|
import StorePage from './pages/reports/store/StorePage'
|
||||||
import StaffReportPage from './pages/reports/StaffReportPage'
|
import StaffReportPage from './pages/reports/staff/StaffReport'
|
||||||
import ProductsReportPage from './pages/reports/products/ProductsReport'
|
import ProductsReportPage from './pages/reports/products/ProductsReport'
|
||||||
import PrepZonesPage from './pages/reports/PrepZonesPage'
|
import PrepZonesPage from './pages/reports/prepzones/PrepZonesReport'
|
||||||
import ExpensesReportPage from './pages/reports/ExpensesReportPage'
|
import ExpensesReportPage from './pages/reports/expenses/ExpensesReport'
|
||||||
import TechnicalPage from './pages/reports/TechnicalPage'
|
import TechnicalPage from './pages/reports/technical/TechnicalReport'
|
||||||
import MiscPage from './pages/reports/MiscPage'
|
import MiscPage from './pages/reports/misc/MiscReport'
|
||||||
|
|
||||||
// Other
|
// Other
|
||||||
import { AppsPage, IntegrationsPage } from './pages/platform/ModulesPage'
|
import { AppsPage, IntegrationsPage } from './pages/platform/ModulesPage'
|
||||||
|
|||||||
@@ -1,439 +0,0 @@
|
|||||||
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>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
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>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -1,524 +0,0 @@
|
|||||||
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>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
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>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
import { useState } from 'react'
|
|
||||||
import { TabBar } from '../../ui/Tabs'
|
|
||||||
import PrinterHistory from './operations/PrinterHistory'
|
|
||||||
import PrinterHealthLog from './operations/PrinterHealthLog'
|
|
||||||
import LogsPanel from './operations/LogsPanel'
|
|
||||||
import { useCan } from '@xenia/access'
|
|
||||||
import { useTranslation } from '@xenia/i18n'
|
|
||||||
|
|
||||||
const TABS = [
|
|
||||||
{ id: 'printer-history', label: 'Ιστορικό Εκτυπωτή', Component: PrinterHistory },
|
|
||||||
{ id: 'printer-health', label: 'Υγεία Εκτυπωτή', Component: PrinterHealthLog },
|
|
||||||
]
|
|
||||||
|
|
||||||
export default function TechnicalPage() {
|
|
||||||
const { t } = useTranslation('manager')
|
|
||||||
const canLogs = useCan('core.settings.manage') // the files carry names and IPs: owner-level
|
|
||||||
const tabs = canLogs ? [...TABS, { id: 'logs', label: t('logs.tab'), Component: LogsPanel }] : TABS
|
|
||||||
const [active, setActive] = useState('printer-history')
|
|
||||||
const tab = tabs.find(x => x.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,96 @@
|
|||||||
|
// Reports → Expenses (plan step 6.12c; replaces the v1 expenses report): what the venue spent in
|
||||||
|
// a period (by the day each expense was entered), paid and still due; split by category or by
|
||||||
|
// supplier; every expense, a tap shows its payments. Entering expenses is Finance → Expenses.
|
||||||
|
import { useState } from 'react'
|
||||||
|
import { useFormat, useTranslation } from '@xenia/i18n'
|
||||||
|
import { Button, Dialog, Select } from '@xenia/ui'
|
||||||
|
import client from '../../../api/client'
|
||||||
|
import { useLiveQuery } from '../../../live/useLiveQuery'
|
||||||
|
import { Pill } from '../../overview/parts'
|
||||||
|
import { BarList } from '../kit/charts'
|
||||||
|
import { Failed, Loading, Panel, ReportPage, Stat, Table } from '../kit/parts'
|
||||||
|
import { PeriodPicker } from '../kit/Period'
|
||||||
|
import { defaultPeriod } from '../kit/reportLogic'
|
||||||
|
|
||||||
|
const STATUS_TONE = { paid: 'success', partial: 'warning', due: 'danger' }
|
||||||
|
const CATEGORIES = ['supplier', 'utilities', 'rent', 'maintenance', 'staff', 'equipment', 'other'] // as Finance → Expenses saves them (models/expenses.py)
|
||||||
|
|
||||||
|
export default function ExpensesReport() {
|
||||||
|
const { t } = useTranslation('manager')
|
||||||
|
return <ReportPage title={t('reports.exp.title')} testId="report-expenses"><Expenses /></ReportPage>
|
||||||
|
}
|
||||||
|
|
||||||
|
function Expenses() {
|
||||||
|
const { t } = useTranslation('manager')
|
||||||
|
const fmt = useFormat()
|
||||||
|
const [period, setPeriod] = useState(() => defaultPeriod(fmt.venueToday()))
|
||||||
|
const [status, setStatus] = useState('')
|
||||||
|
const [category, setCategory] = useState('')
|
||||||
|
const [split, setSplit] = useState('category')
|
||||||
|
const [open, setOpen] = useState(null)
|
||||||
|
const params = { ...(status ? { status } : {}), ...(category ? { category } : {}) }
|
||||||
|
const { data, isPending, error, refetch } = useLiveQuery({ queryKey: ['report-expenses', params], queryFn: () => client.get('/api/expenses/', { params }).then(r => r.data) })
|
||||||
|
const catName = c => t(`reports.exp.categories.${c}`, { defaultValue: c })
|
||||||
|
const inPeriod = e => { const d = fmt.venueDateKey(e.created_at); return (!period.from || d >= period.from) && (!period.to || d <= period.to) }
|
||||||
|
const rows = (data ?? []).filter(inPeriod)
|
||||||
|
const sum = k => rows.reduce((s, e) => s + (e[k] ?? 0), 0)
|
||||||
|
const groups = Object.values(rows.reduce((m, e) => {
|
||||||
|
const k = split === 'category' ? e.category : (e.contact_name || t('reports.exp.noSupplier'))
|
||||||
|
m[k] = m[k] ?? { key: k, label: split === 'category' ? catName(k) : k, value: 0, due: 0 }
|
||||||
|
m[k].value += e.total_amount
|
||||||
|
m[k].due += e.due_amount
|
||||||
|
return m
|
||||||
|
}, {})).sort((a, b) => b.value - a.value)
|
||||||
|
const columns = [
|
||||||
|
{ key: 'created_at', label: t('reports.exp.date'), render: e => fmt.formatDate(e.created_at) },
|
||||||
|
{ key: 'description', label: t('reports.exp.what'), render: e => <span className="font-semibold text-ink">{e.description}</span> },
|
||||||
|
{ key: 'category', label: t('reports.prod.category'), sort: e => catName(e.category), render: e => catName(e.category) },
|
||||||
|
{ key: 'contact_name', label: t('reports.exp.supplier'), render: e => e.contact_name || '' },
|
||||||
|
{ key: 'total_amount', label: t('reports.exp.total'), align: 'right', render: e => fmt.formatMoney(e.total_amount) },
|
||||||
|
{ key: 'due_amount', label: t('reports.exp.due'), align: 'right', render: e => (e.due_amount ? <span className="text-danger-ink">{fmt.formatMoney(e.due_amount)}</span> : '') },
|
||||||
|
{ key: 'status', label: t('reports.status'), render: e => <Pill tone={STATUS_TONE[e.status] ?? 'neutral'}>{t(`reports.exp.status.${e.status}`, { defaultValue: e.status })}</Pill> },
|
||||||
|
]
|
||||||
|
return (
|
||||||
|
<div className="grid gap-4">
|
||||||
|
<PeriodPicker value={period} onChange={setPeriod} allowDay={false} right={<span className="flex gap-2 items-end">
|
||||||
|
<Select size="sm" value={status} onChange={e => setStatus(e.target.value)} aria-label={t('reports.status')}
|
||||||
|
options={[{ value: '', label: t('reports.store.anyStatus') }, ...['due', 'partial', 'paid'].map(s => ({ value: s, label: t(`reports.exp.status.${s}`) }))]} />
|
||||||
|
<Select size="sm" value={category} onChange={e => setCategory(e.target.value)} aria-label={t('reports.prod.category')}
|
||||||
|
options={[{ value: '', label: t('reports.prod.allCategories') }, ...CATEGORIES.map(c => ({ value: c, label: catName(c) }))]} />
|
||||||
|
</span>} />
|
||||||
|
{isPending ? <Loading /> : error ? <Failed error={error} retry={refetch} /> : (<>
|
||||||
|
<div className="grid gap-3 grid-cols-[repeat(auto-fill,minmax(12rem,1fr))]">
|
||||||
|
<Stat label={t('reports.exp.spent')} value={fmt.formatMoney(sum('total_amount'))} sub={t('reports.exp.count', { count: rows.length })} testId="expenses-total" />
|
||||||
|
<Stat label={t('reports.exp.paid')} tone="success" value={fmt.formatMoney(sum('paid_amount'))} />
|
||||||
|
<Stat label={t('reports.exp.due')} tone={sum('due_amount') ? 'danger' : undefined} value={fmt.formatMoney(sum('due_amount'))} />
|
||||||
|
</div>
|
||||||
|
{groups.length > 0 && (
|
||||||
|
<Panel title={t('reports.exp.split')} actions={<span className="flex gap-1">{['category', 'supplier'].map(s => (
|
||||||
|
<Button key={s} size="sm" variant={split === s ? 'primary' : 'ghost'} onClick={() => setSplit(s)}>{t(`reports.exp.by.${s}`)}</Button>))}</span>}>
|
||||||
|
<BarList testId="expenses-split" format={v => fmt.formatMoney(v)} rows={groups.map(g => ({ ...g, sub: g.due ? t('reports.exp.dueSub', { amount: fmt.formatMoney(g.due) }) : undefined }))} />
|
||||||
|
</Panel>
|
||||||
|
)}
|
||||||
|
<Panel padded={false} title={t('reports.exp.list')}>
|
||||||
|
<Table columns={columns} rows={rows} onRow={setOpen} rowTestId="report-expense" initialSort={{ key: 'created_at', dir: 'desc' }} />
|
||||||
|
</Panel>
|
||||||
|
</>)}
|
||||||
|
{open && (
|
||||||
|
<Dialog open size="sm" onClose={() => setOpen(null)} title={open.description}
|
||||||
|
description={`${catName(open.category)}${open.contact_name ? ` · ${open.contact_name}` : ''} · ${fmt.formatDate(open.created_at)}`}
|
||||||
|
footer={<Button variant="secondary" onClick={() => setOpen(null)}>{t('reports.back')}</Button>}>
|
||||||
|
<div className="grid gap-2 text-body">
|
||||||
|
<p>{t('reports.exp.total')}: <b>{fmt.formatMoney(open.total_amount)}</b> · {t('reports.exp.paid')}: <b>{fmt.formatMoney(open.paid_amount)}</b>{open.due_amount ? <> · {t('reports.exp.due')}: <b className="text-danger-ink">{fmt.formatMoney(open.due_amount)}</b></> : null}</p>
|
||||||
|
{open.due_date && <p className="text-label text-ink-2">{t('reports.exp.dueDate', { date: fmt.formatDate(open.due_date) })}</p>}
|
||||||
|
{open.notes && <p className="text-label text-ink-2">{open.notes}</p>}
|
||||||
|
<h3 className="text-caption font-semibold uppercase tracking-wide text-ink-3 mt-2">{t('reports.exp.payments')}</h3>
|
||||||
|
{open.payments?.length ? (
|
||||||
|
<ul className="divide-y divide-line">
|
||||||
|
{open.payments.map(p => <li key={p.id} className="py-1.5 flex justify-between text-label"><span>{fmt.formatDate(p.paid_at)}{p.paid_by_name ? ` · ${p.paid_by_name}` : ''}{p.notes ? ` · ${p.notes}` : ''}</span><b className="tabular-nums">{fmt.formatMoney(p.amount)}</b></li>)}
|
||||||
|
</ul>
|
||||||
|
) : <p className="text-label text-ink-3">{t('reports.exp.noPayments')}</p>}
|
||||||
|
</div>
|
||||||
|
</Dialog>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -85,3 +85,27 @@ export function orderTotals(o) {
|
|||||||
|
|
||||||
/** The business days list → choices for a select, newest first (label filled by the page). */
|
/** The business days list → choices for a select, newest first (label filled by the page). */
|
||||||
export const dayChoices = (days = []) => [...days].sort((a, b) => (b.opened_at ?? '').localeCompare(a.opened_at ?? ''))
|
export const dayChoices = (days = []) => [...days].sort((a, b) => (b.opened_at ?? '').localeCompare(a.opened_at ?? ''))
|
||||||
|
|
||||||
|
/** A CSV built in the browser with the server's Excel rules (services/csv_export.py): a UTF-8
|
||||||
|
* mark; for Greek, ';' between columns and decimal commas. rows: arrays of cells. */
|
||||||
|
export function csvText(header, rows, language = 'en') {
|
||||||
|
const [sep, dec] = language === 'el' ? [';', ','] : [',', '.']
|
||||||
|
const cell = v => {
|
||||||
|
let s = v == null ? '' : typeof v === 'number' ? (Number.isInteger(v) ? String(v) : v.toFixed(2).replace('.', dec)) : String(v)
|
||||||
|
if (s.includes(sep) || s.includes('"') || s.includes('\n')) s = `"${s.replace(/"/g, '""')}"`
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
return String.fromCharCode(0xFEFF) + [header, ...rows].map(r => r.map(cell).join(sep)).join('\r\n')
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Download text as a file. */
|
||||||
|
export function download(text, filename) {
|
||||||
|
const url = URL.createObjectURL(new Blob([text], { type: 'text/csv;charset=utf-8' }))
|
||||||
|
const a = document.createElement('a')
|
||||||
|
a.href = url
|
||||||
|
a.download = filename
|
||||||
|
document.body.appendChild(a)
|
||||||
|
a.click()
|
||||||
|
a.remove()
|
||||||
|
setTimeout(() => URL.revokeObjectURL(url), 1000)
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,104 @@
|
|||||||
|
// Reports → Cancellations and discounts (plan step 6.12c; replaces the v1 "misc" logs): every
|
||||||
|
// cancelled line (what, how much, who sent it, who cancelled it, why) and every discount given
|
||||||
|
// (on what, how much, by whom, why), with totals per person; exports for Excel.
|
||||||
|
import { useState } from 'react'
|
||||||
|
import { useFormat, useTranslation } from '@xenia/i18n'
|
||||||
|
import client from '../../../api/client'
|
||||||
|
import { useLiveQuery } from '../../../live/useLiveQuery'
|
||||||
|
import { BarList } from '../kit/charts'
|
||||||
|
import { ExportButton, Failed, Loading, Panel, ReportPage, Stat, Table } from '../kit/parts'
|
||||||
|
import { PeriodPicker } from '../kit/Period'
|
||||||
|
import { defaultPeriod, periodParams, periodSlug } from '../kit/reportLogic'
|
||||||
|
|
||||||
|
export default function MiscReport() {
|
||||||
|
const { t } = useTranslation('manager')
|
||||||
|
const tabs = [
|
||||||
|
{ id: 'cancellations', label: t('reports.misc.cancellations'), Component: CancellationsTab },
|
||||||
|
{ id: 'discounts', label: t('reports.misc.discounts'), Component: DiscountsTab },
|
||||||
|
]
|
||||||
|
return <ReportPage title={t('reports.misc.title')} tabs={tabs} testId="report-misc" />
|
||||||
|
}
|
||||||
|
|
||||||
|
function CancellationsTab() {
|
||||||
|
const { t } = useTranslation('manager')
|
||||||
|
const fmt = useFormat()
|
||||||
|
const [period, setPeriod] = useState(() => defaultPeriod(fmt.venueToday()))
|
||||||
|
const params = periodParams(period)
|
||||||
|
const { data, isPending, error, refetch } = useLiveQuery({ queryKey: ['report-cancellations', params], queryFn: () => client.get('/api/reports/cancellations', { params }).then(r => r.data) })
|
||||||
|
const rows = data?.cancellations ?? []
|
||||||
|
const byPerson = Object.values(rows.reduce((m, c) => {
|
||||||
|
const k = c.cancelled_by || c.waiter_name || '—'
|
||||||
|
m[k] = m[k] ?? { key: k, label: k, value: 0, n: 0 }
|
||||||
|
m[k].value += c.value
|
||||||
|
m[k].n += 1
|
||||||
|
return m
|
||||||
|
}, {}))
|
||||||
|
const columns = [
|
||||||
|
{ key: 'cancelled_at', label: t('reports.misc.when'), render: c => fmt.formatDateTime(c.cancelled_at, 'datetimeShort') },
|
||||||
|
{ key: 'product_name', label: t('reports.prod.product'), render: c => <span className="font-semibold text-ink">{c.product_name}</span> },
|
||||||
|
{ key: 'quantity', label: t('reports.prod.units'), align: 'right', render: c => fmt.formatNumber(c.quantity, { maxDecimals: 3 }) },
|
||||||
|
{ key: 'value', label: t('reports.misc.value'), align: 'right', render: c => fmt.formatMoney(c.value) },
|
||||||
|
{ key: 'table', label: t('reports.place') },
|
||||||
|
{ key: 'waiter_name', label: t('reports.misc.sentBy') },
|
||||||
|
{ key: 'cancelled_by', label: t('reports.misc.cancelledBy') },
|
||||||
|
{ key: 'cancel_reason', label: t('reports.misc.reason'), render: c => c.cancel_reason || '' },
|
||||||
|
]
|
||||||
|
return (
|
||||||
|
<div className="grid gap-4">
|
||||||
|
<PeriodPicker value={period} onChange={setPeriod} right={<ExportButton endpoint="/api/reports/cancellations/export" params={params} filename={`cancellations-${periodSlug(period)}.csv`} />} />
|
||||||
|
{isPending ? <Loading /> : error ? <Failed error={error} retry={refetch} /> : (<>
|
||||||
|
<div className="grid gap-3 grid-cols-[repeat(auto-fill,minmax(12rem,1fr))]">
|
||||||
|
<Stat label={t('reports.misc.cancelledLines')} value={rows.length} testId="cancellations-count" />
|
||||||
|
<Stat label={t('reports.misc.cancelledValue')} tone="danger" value={fmt.formatMoney(data.total_value)} sub={t('reports.misc.notSales')} />
|
||||||
|
</div>
|
||||||
|
{byPerson.length > 1 && (
|
||||||
|
<Panel title={t('reports.misc.byWhom')}>
|
||||||
|
<BarList format={v => fmt.formatMoney(v)} rows={byPerson.sort((a, b) => b.value - a.value).map(p => ({ ...p, sub: t('reports.misc.lines', { count: p.n }) }))} />
|
||||||
|
</Panel>
|
||||||
|
)}
|
||||||
|
<Panel padded={false} title={t('reports.misc.cancellations')}>
|
||||||
|
<Table columns={columns} rows={rows} rowTestId="report-cancellation" initialSort={{ key: 'cancelled_at', dir: 'desc' }} limit={500} />
|
||||||
|
</Panel>
|
||||||
|
</>)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function DiscountsTab() {
|
||||||
|
const { t } = useTranslation('manager')
|
||||||
|
const fmt = useFormat()
|
||||||
|
const [period, setPeriod] = useState(() => defaultPeriod(fmt.venueToday()))
|
||||||
|
const params = periodParams(period)
|
||||||
|
const { data, isPending, error, refetch } = useLiveQuery({ queryKey: ['report-discounts', params], queryFn: () => client.get('/api/reports/discounts', { params }).then(r => r.data) })
|
||||||
|
const rows = data?.discounts ?? []
|
||||||
|
const columns = [
|
||||||
|
{ key: 'applied_at', label: t('reports.misc.when'), render: d => fmt.formatDateTime(d.applied_at, 'datetimeShort') },
|
||||||
|
{ key: 'order_id', label: '#', render: d => <span className="tabular-nums text-ink-2">#{d.order_id}</span> },
|
||||||
|
{ key: 'table_name', label: t('reports.place'), render: d => d.table_name || t('reports.noTable') },
|
||||||
|
{ key: 'discount_value', label: t('reports.misc.discount'), align: 'right',
|
||||||
|
render: d => (d.discount_type === 'percent' ? `${fmt.formatNumber(d.discount_value, { maxDecimals: 1 })}%` : fmt.formatMoney(d.discount_value)) },
|
||||||
|
{ key: 'discount_amount', label: t('reports.misc.amount'), align: 'right', render: d => <span className="font-semibold">{fmt.formatMoney(d.discount_amount)}</span> },
|
||||||
|
{ key: 'order_total_before', label: t('reports.misc.before'), align: 'right', render: d => (d.order_total_before != null ? fmt.formatMoney(d.order_total_before) : '') },
|
||||||
|
{ key: 'applied_by_name', label: t('reports.misc.givenBy') },
|
||||||
|
{ key: 'reason', label: t('reports.misc.reason'), render: d => d.reason || '' },
|
||||||
|
]
|
||||||
|
return (
|
||||||
|
<div className="grid gap-4">
|
||||||
|
<PeriodPicker value={period} onChange={setPeriod} />
|
||||||
|
{isPending ? <Loading /> : error ? <Failed error={error} retry={refetch} /> : (<>
|
||||||
|
<div className="grid gap-3 grid-cols-[repeat(auto-fill,minmax(12rem,1fr))]">
|
||||||
|
<Stat label={t('reports.misc.discountsGiven')} value={rows.length} sub={t('reports.misc.onOrders', { count: data.order_count })} />
|
||||||
|
<Stat label={t('reports.misc.discountTotal')} tone="warning" value={fmt.formatMoney(data.total_discount_value)} sub={t('reports.misc.alreadyOff')} />
|
||||||
|
</div>
|
||||||
|
{data.by_waiter?.length > 0 && (
|
||||||
|
<Panel title={t('reports.misc.byWhom')}>
|
||||||
|
<BarList format={v => fmt.formatMoney(v)} rows={data.by_waiter.map(w => ({ key: w.waiter_id, label: w.waiter_name, value: w.total_value, sub: t('reports.misc.times', { count: w.count }) }))} />
|
||||||
|
</Panel>
|
||||||
|
)}
|
||||||
|
<Panel padded={false} title={t('reports.misc.discounts')}>
|
||||||
|
<Table columns={columns} rows={rows} rowTestId="report-discount" initialSort={{ key: 'applied_at', dir: 'desc' }} limit={500} />
|
||||||
|
</Panel>
|
||||||
|
</>)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -1,116 +0,0 @@
|
|||||||
import { useState } from 'react'
|
|
||||||
import { useQuery } from '@tanstack/react-query'
|
|
||||||
import { XCircle, TrendingDown, Repeat, CheckCircle2 } from 'lucide-react'
|
|
||||||
import client from '../../../api/client'
|
|
||||||
import { FilterBar, FilterSelect, FilterDateInput, WorkDayDateToggle } from '../shared/FilterBar'
|
|
||||||
import { Panel, DataTable, THead, TH, TR, TD, WaiterAvatar } from '../shared/TablePrimitives'
|
|
||||||
import StatCard from '../shared/StatCard'
|
|
||||||
import EmptyState from '../shared/EmptyState'
|
|
||||||
import SkeletonTable from '../shared/SkeletonTable'
|
|
||||||
import ExportButton from '../shared/ExportButton'
|
|
||||||
import { fmtEUR, fmtNum, fmtDate, fmtTime, 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) }
|
|
||||||
|
|
||||||
export default function CancellationsLog() {
|
|
||||||
const [mode, setMode] = useState('range')
|
|
||||||
const [from, setFrom] = useState(monthAgo())
|
|
||||||
const [to, setTo] = useState(today())
|
|
||||||
const [businessDayId, setBusinessDayId] = useState('all')
|
|
||||||
const [waiterF, setWaiterF] = useState('all')
|
|
||||||
|
|
||||||
const { data: waitersData } = useQuery({ queryKey: ['meta-waiters'], queryFn: () => client.get('/api/reports/meta/waiters').then(r => r.data), 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 queryParams = {
|
|
||||||
...(mode === 'workday' && businessDayId !== 'all' ? { business_day_id: businessDayId } : {}),
|
|
||||||
...(mode === 'range' ? { from: from + 'T00:00:00', to: to + 'T23:59:59' } : {}),
|
|
||||||
...(waiterF !== 'all' ? { waiter_id: waiterF } : {}),
|
|
||||||
}
|
|
||||||
|
|
||||||
const { data, isLoading, isError, refetch } = useQuery({
|
|
||||||
queryKey: ['cancellations', mode, from, to, businessDayId, waiterF],
|
|
||||||
queryFn: () => client.get('/api/reports/cancellations', { params: queryParams }).then(r => r.data),
|
|
||||||
staleTime: 60 * 1000,
|
|
||||||
})
|
|
||||||
|
|
||||||
const waiterOptions = [{ value: 'all', label: 'Όλοι οι Σερβιτόροι' }, ...((waitersData?.waiters || []).map(w => ({ value: String(w.id), label: w.name })))]
|
|
||||||
const bdOptions = [{ value: 'all', label: 'Όλες οι Εργάσιμες Μέρες' }, ...((bdData?.business_days || []).map(bd => ({ value: String(bd.id), label: `${fmtDate(bd.opened_at)} · ${fmtTime(bd.opened_at)}` })))]
|
|
||||||
|
|
||||||
const cancellations = data?.cancellations || []
|
|
||||||
const totalValue = data?.total_value || 0
|
|
||||||
|
|
||||||
const itemCounts = {}
|
|
||||||
cancellations.forEach(c => { itemCounts[c.product_name] = (itemCounts[c.product_name] || 0) + c.quantity })
|
|
||||||
const topItem = Object.entries(itemCounts).sort((a, b) => b[1] - a[1])[0]
|
|
||||||
|
|
||||||
if (isLoading) return <div className="flex-1 overflow-y-auto p-6"><SkeletonTable rows={8} columns={8} /></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 right={
|
|
||||||
<ExportButton endpoint="/api/reports/cancellations/export" params={queryParams} filename={`cancellations-${from}-to-${to}.csv`} />
|
|
||||||
}>
|
|
||||||
<WorkDayDateToggle mode={mode} onChange={setMode} />
|
|
||||||
{mode === 'workday' ? (
|
|
||||||
<FilterSelect value={businessDayId} onChange={setBusinessDayId} options={bdOptions} width="w-72" label="Μέρα" />
|
|
||||||
) : (
|
|
||||||
<>
|
|
||||||
<FilterDateInput value={from} onChange={setFrom} label="Από" />
|
|
||||||
<FilterDateInput value={to} onChange={setTo} label="Έως" />
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
<FilterSelect value={waiterF} onChange={setWaiterF} options={waiterOptions} label="Σερβιτόρος" />
|
|
||||||
</FilterBar>
|
|
||||||
|
|
||||||
<div className="flex-1 overflow-y-auto p-6">
|
|
||||||
<div className="grid grid-cols-3 gap-4 mb-4">
|
|
||||||
<StatCard label="Συνολικές Ακυρώσεις" value={fmtNum(cancellations.length)} sub="ακυρωμένα είδη" icon={XCircle} />
|
|
||||||
<StatCard label="Συνολική Αξία Ακυρώσεων" value={fmtEUR(totalValue)} sub="χαμένα έσοδα" icon={TrendingDown} accent />
|
|
||||||
<StatCard label="Πιο Ακυρωμένο" value={topItem ? topItem[0] : '—'} sub={topItem ? `${topItem[1]} τεμ.` : ''} icon={Repeat} />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<Panel title="Ακυρώσεις" padded={false}>
|
|
||||||
{cancellations.length === 0 ? (
|
|
||||||
<EmptyState icon={CheckCircle2} title="Δεν υπάρχουν ακυρώσεις" description="Δεν ακυρώθηκε τίποτα σε αυτή την περίοδο." />
|
|
||||||
) : (
|
|
||||||
<>
|
|
||||||
<DataTable>
|
|
||||||
<THead>
|
|
||||||
<TH>Ώρα</TH><TH>Παραγγελία #</TH><TH>Τραπέζι</TH><TH>Σερβιτόρος</TH>
|
|
||||||
<TH>Είδος</TH><TH align="right">Αξία</TH><TH>Ακυρώθηκε από</TH><TH>Λόγος</TH>
|
|
||||||
</THead>
|
|
||||||
<tbody>
|
|
||||||
{cancellations.map(c => (
|
|
||||||
<TR key={c.id} striped>
|
|
||||||
<TD mono>{fmtDateTime(c.cancelled_at)}</TD>
|
|
||||||
<TD mono>#{c.order_id}</TD>
|
|
||||||
<TD>{c.table}</TD>
|
|
||||||
<TD><WaiterAvatar name={c.waiter_name} id={c.waiter_id} /></TD>
|
|
||||||
<TD>{c.product_name} <span className="text-slate-400">×{c.quantity}</span></TD>
|
|
||||||
<TD mono align="right" className="font-semibold text-rose-700">{fmtEUR(c.value)}</TD>
|
|
||||||
<TD className="text-slate-600">{c.cancelled_by || <span className="text-slate-300">—</span>}</TD>
|
|
||||||
<TD className="text-slate-500">{c.cancel_reason || <span className="text-slate-300">—</span>}</TD>
|
|
||||||
</TR>
|
|
||||||
))}
|
|
||||||
<tr className="bg-rose-50/40">
|
|
||||||
<TD colSpan={5} 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-rose-700">{fmtEUR(totalValue)}</TD>
|
|
||||||
<TD colSpan={2} />
|
|
||||||
</tr>
|
|
||||||
</tbody>
|
|
||||||
</DataTable>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</Panel>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -1,191 +0,0 @@
|
|||||||
import { useState } from 'react'
|
|
||||||
import { useQuery } from '@tanstack/react-query'
|
|
||||||
import { Tag } from 'lucide-react'
|
|
||||||
import client from '../../../api/client'
|
|
||||||
import { FilterBar, FilterSelect, FilterDateInput, WorkDayDateToggle } from '../shared/FilterBar'
|
|
||||||
import { Panel, DataTable, THead, TH, TR, TD, WaiterAvatar } from '../shared/TablePrimitives'
|
|
||||||
import StatCard from '../shared/StatCard'
|
|
||||||
import EmptyState from '../shared/EmptyState'
|
|
||||||
import SkeletonTable from '../shared/SkeletonTable'
|
|
||||||
import { fmtEUR, fmtNum, fmtDate, fmtTime, fmtDateTime, fmtDateStr } 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 DiscountsLog() {
|
|
||||||
const [mode, setMode] = useState('range')
|
|
||||||
const [from, setFrom] = useState(monthAgo())
|
|
||||||
const [to, setTo] = useState(today())
|
|
||||||
const [businessDayId, setBusinessDayId] = useState('all')
|
|
||||||
const [waiterF, setWaiterF] = useState('all')
|
|
||||||
|
|
||||||
const { data: waitersData } = useQuery({
|
|
||||||
queryKey: ['meta-waiters'],
|
|
||||||
queryFn: () => client.get('/api/reports/meta/waiters').then(r => r.data),
|
|
||||||
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 queryParams = {
|
|
||||||
...(mode === 'workday' && businessDayId !== 'all' ? { business_day_id: businessDayId } : {}),
|
|
||||||
...(mode === 'range' ? { from: from + 'T00:00:00', to: to + 'T23:59:59' } : {}),
|
|
||||||
...(waiterF !== 'all' ? { applied_by: waiterF } : {}),
|
|
||||||
}
|
|
||||||
|
|
||||||
const { data, isLoading, isError, refetch } = useQuery({
|
|
||||||
queryKey: ['discounts', mode, from, to, businessDayId, waiterF],
|
|
||||||
queryFn: () => client.get('/api/reports/discounts', { params: queryParams }).then(r => r.data),
|
|
||||||
staleTime: 60 * 1000,
|
|
||||||
})
|
|
||||||
|
|
||||||
const waiterOptions = [
|
|
||||||
{ value: 'all', label: 'Όλοι' },
|
|
||||||
...((waitersData?.waiters || []).map(w => ({ value: String(w.id), label: w.name }))),
|
|
||||||
]
|
|
||||||
const bdOptions = [
|
|
||||||
{ value: 'all', label: 'Όλες οι Εργάσιμες Μέρες' },
|
|
||||||
...((bdData?.business_days || []).map(bd => ({ value: String(bd.id), label: `${fmtDate(bd.opened_at)} · ${fmtTime(bd.opened_at)}` }))),
|
|
||||||
]
|
|
||||||
|
|
||||||
const discounts = data?.discounts || []
|
|
||||||
const byWaiter = data?.by_waiter || []
|
|
||||||
const totalValue = data?.total_discount_value ?? 0
|
|
||||||
const orderCount = data?.order_count ?? 0
|
|
||||||
|
|
||||||
if (isLoading) return <div className="flex-1 overflow-y-auto p-6"><SkeletonTable rows={8} columns={7} /></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} width="w-72" label="Μέρα" />
|
|
||||||
) : (
|
|
||||||
<>
|
|
||||||
<FilterDateInput value={from} onChange={setFrom} label="Από" />
|
|
||||||
<FilterDateInput value={to} onChange={setTo} label="Έως" />
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
<FilterSelect value={waiterF} onChange={setWaiterF} options={waiterOptions} label="Σερβιτόρος" />
|
|
||||||
</FilterBar>
|
|
||||||
|
|
||||||
<div className="flex-1 overflow-y-auto p-6 space-y-4">
|
|
||||||
{/* Summary cards */}
|
|
||||||
<div className="grid grid-cols-3 gap-4">
|
|
||||||
<StatCard label="Σύνολο Εκπτώσεων" value={fmtEUR(totalValue)} icon={Tag} color="amber" />
|
|
||||||
<StatCard label="Παραγγελίες με Έκπτωση" value={fmtNum(orderCount)} color="slate" />
|
|
||||||
<StatCard label="Αριθμός Εκπτώσεων" value={fmtNum(discounts.length)} color="slate" />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* By waiter summary */}
|
|
||||||
{byWaiter.length > 1 && (
|
|
||||||
<Panel title="Ανά Σερβιτόρο" padded={false}>
|
|
||||||
<DataTable>
|
|
||||||
<THead>
|
|
||||||
<TH>Σερβιτόρος</TH>
|
|
||||||
<TH align="right">Αριθμός</TH>
|
|
||||||
<TH align="right">Σύνολο</TH>
|
|
||||||
<TH align="right">Μέσος / Έκπτωση</TH>
|
|
||||||
</THead>
|
|
||||||
<tbody>
|
|
||||||
{byWaiter.map(w => (
|
|
||||||
<TR key={w.waiter_id} striped>
|
|
||||||
<TD><WaiterAvatar name={w.waiter_name} id={w.waiter_id} /></TD>
|
|
||||||
<TD mono align="right">{fmtNum(w.count)}</TD>
|
|
||||||
<TD mono align="right" className="font-semibold text-amber-700">{fmtEUR(w.total_value)}</TD>
|
|
||||||
<TD mono align="right">{fmtEUR(w.count > 0 ? w.total_value / w.count : 0)}</TD>
|
|
||||||
</TR>
|
|
||||||
))}
|
|
||||||
</tbody>
|
|
||||||
</DataTable>
|
|
||||||
</Panel>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Full log */}
|
|
||||||
<Panel
|
|
||||||
title="Αρχείο Εκπτώσεων"
|
|
||||||
subtitle={`${discounts.length} εγγραφές — μόνο ανάγνωση`}
|
|
||||||
padded={false}
|
|
||||||
>
|
|
||||||
{discounts.length === 0 ? (
|
|
||||||
<EmptyState
|
|
||||||
icon={Tag}
|
|
||||||
title="Δεν βρέθηκαν εκπτώσεις"
|
|
||||||
description="Δεν υπάρχουν εκπτώσεις για την επιλεγμένη περίοδο."
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
<DataTable>
|
|
||||||
<THead>
|
|
||||||
<TH>Ημ/νία</TH>
|
|
||||||
<TH>Παραγγελία</TH>
|
|
||||||
<TH>Σερβιτόρος</TH>
|
|
||||||
<TH align="right">Τύπος</TH>
|
|
||||||
<TH align="right">Τιμή πριν</TH>
|
|
||||||
<TH align="right">Ποσό Έκπτωσης</TH>
|
|
||||||
<TH>Αιτία</TH>
|
|
||||||
</THead>
|
|
||||||
<tbody>
|
|
||||||
{discounts.map(d => {
|
|
||||||
const typeLabel = d.discount_type === 'percent'
|
|
||||||
? `${d.discount_value}%`
|
|
||||||
: fmtEUR(d.discount_value)
|
|
||||||
const isItemLevel = d.item_id != null
|
|
||||||
return (
|
|
||||||
<TR key={d.id} striped>
|
|
||||||
<TD mono className="text-slate-500">{fmtDateTime(d.applied_at)}</TD>
|
|
||||||
<TD>
|
|
||||||
<span className="font-medium text-slate-900">
|
|
||||||
#{d.order_id}
|
|
||||||
{d.table_name && <span className="text-slate-400 font-normal ml-1">· {d.table_name}</span>}
|
|
||||||
</span>
|
|
||||||
{isItemLevel && (
|
|
||||||
<span className="ml-2 text-[10px] font-semibold px-1.5 py-0.5 rounded bg-slate-100 text-slate-500">ΑΝΤΙΚ.</span>
|
|
||||||
)}
|
|
||||||
</TD>
|
|
||||||
<TD><WaiterAvatar name={d.applied_by_name} id={d.applied_by_id} /></TD>
|
|
||||||
<TD mono align="right">
|
|
||||||
<span className={`text-xs font-semibold px-1.5 py-0.5 rounded ${d.discount_type === 'percent' ? 'bg-blue-50 text-blue-700' : 'bg-amber-50 text-amber-700'}`}>
|
|
||||||
{typeLabel}
|
|
||||||
</span>
|
|
||||||
</TD>
|
|
||||||
<TD mono align="right" className="text-slate-500">
|
|
||||||
{d.order_total_before != null ? fmtEUR(d.order_total_before) : '—'}
|
|
||||||
</TD>
|
|
||||||
<TD mono align="right" className="font-semibold text-amber-700">
|
|
||||||
− {fmtEUR(d.discount_amount)}
|
|
||||||
</TD>
|
|
||||||
<TD className="text-slate-500 text-[12px]">
|
|
||||||
{d.reason || <span className="text-slate-300">—</span>}
|
|
||||||
</TD>
|
|
||||||
</TR>
|
|
||||||
)
|
|
||||||
})}
|
|
||||||
</tbody>
|
|
||||||
{discounts.length > 1 && (
|
|
||||||
<tfoot>
|
|
||||||
<TR>
|
|
||||||
<TD colSpan={5} className="font-semibold text-slate-700">Σύνολο</TD>
|
|
||||||
<TD mono align="right" className="font-bold text-amber-700">− {fmtEUR(totalValue)}</TD>
|
|
||||||
<TD />
|
|
||||||
</TR>
|
|
||||||
</tfoot>
|
|
||||||
)}
|
|
||||||
</DataTable>
|
|
||||||
)}
|
|
||||||
</Panel>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -1,110 +0,0 @@
|
|||||||
import { useState } from 'react'
|
|
||||||
import { useQuery } from '@tanstack/react-query'
|
|
||||||
import client from '../../../api/client'
|
|
||||||
import { FilterBar, FilterSelect, FilterDateInput } from '../shared/FilterBar'
|
|
||||||
import { Panel, DataTable, THead, TH, TR, TD, StatusBadge } from '../shared/TablePrimitives'
|
|
||||||
import EmptyState from '../shared/EmptyState'
|
|
||||||
import SkeletonTable from '../shared/SkeletonTable'
|
|
||||||
import ExportButton from '../shared/ExportButton'
|
|
||||||
import { fmtNum, fmtDate, fmtTime, 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) }
|
|
||||||
|
|
||||||
export default function PrinterHealthLog() {
|
|
||||||
const [from, setFrom] = useState(monthAgo())
|
|
||||||
const [to, setTo] = useState(today())
|
|
||||||
const [printerF, setPrinterF] = useState('all')
|
|
||||||
|
|
||||||
const { data: printersData } = useQuery({ queryKey: ['meta-printers'], queryFn: () => client.get('/api/reports/meta/printers').then(r => r.data), staleTime: 5 * 60 * 1000 })
|
|
||||||
|
|
||||||
const queryParams = {
|
|
||||||
from: from + 'T00:00:00',
|
|
||||||
to: to + 'T23:59:59',
|
|
||||||
...(printerF !== 'all' ? { printer_id: printerF } : {}),
|
|
||||||
}
|
|
||||||
|
|
||||||
const { data, isLoading, isError, refetch } = useQuery({
|
|
||||||
queryKey: ['printer-health', from, to, printerF],
|
|
||||||
queryFn: () => client.get('/api/reports/printers/history', { params: queryParams }).then(r => r.data),
|
|
||||||
staleTime: 60 * 1000,
|
|
||||||
})
|
|
||||||
|
|
||||||
const printerOptions = [{ value: 'all', label: 'Όλοι οι Εκτυπωτές' }, ...((printersData?.printers || []).map(p => ({ value: String(p.id), label: p.name })))]
|
|
||||||
|
|
||||||
const logs = data?.logs || []
|
|
||||||
const succeeded = logs.filter(j => j.success).length
|
|
||||||
const failed = logs.filter(j => !j.success).length
|
|
||||||
const rate = logs.length ? (succeeded / logs.length * 100) : 100
|
|
||||||
|
|
||||||
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 right={
|
|
||||||
<ExportButton endpoint="/api/reports/printers/export" params={queryParams} filename={`printer-health-${from}-to-${to}.csv`} />
|
|
||||||
}>
|
|
||||||
<FilterDateInput value={from} onChange={setFrom} label="Από" />
|
|
||||||
<FilterDateInput value={to} onChange={setTo} label="Έως" />
|
|
||||||
<FilterSelect value={printerF} onChange={setPrinterF} options={printerOptions} label="Εκτυπωτής" />
|
|
||||||
</FilterBar>
|
|
||||||
|
|
||||||
<div className="flex-1 overflow-y-auto p-6">
|
|
||||||
<div className="rounded-lg border border-slate-200 bg-white p-5 shadow-[0_1px_0_rgba(15,23,42,0.04)] mb-4">
|
|
||||||
<div className="grid grid-cols-3 divide-x divide-slate-200">
|
|
||||||
<div className="px-2">
|
|
||||||
<div className="text-[11px] font-medium uppercase tracking-[0.1em] text-slate-500">Επιτυχημένες</div>
|
|
||||||
<div className="mt-1 font-mono text-[28px] font-medium tabular-nums text-emerald-600">{fmtNum(succeeded)}</div>
|
|
||||||
</div>
|
|
||||||
<div className="px-6">
|
|
||||||
<div className="text-[11px] font-medium uppercase tracking-[0.1em] text-slate-500">Αποτυχημένες</div>
|
|
||||||
<div className="mt-1 font-mono text-[28px] font-medium tabular-nums text-rose-600">{fmtNum(failed)}</div>
|
|
||||||
</div>
|
|
||||||
<div className="px-6">
|
|
||||||
<div className="text-[11px] font-medium uppercase tracking-[0.1em] text-slate-500">Επιτυχία %</div>
|
|
||||||
<div className="mt-1 font-mono text-[28px] font-medium tabular-nums text-slate-900">{rate.toFixed(1)}%</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<Panel title="Αρχείο Εργασιών" subtitle="Αποτυχημένες σε κόκκινο φόντο" padded={false}>
|
|
||||||
{logs.length === 0 ? (
|
|
||||||
<EmptyState title="Δεν βρέθηκαν εργασίες εκτύπωσης" description="Δοκιμάστε διαφορετικό εύρος ημερομηνιών ή εκτυπωτή." />
|
|
||||||
) : (
|
|
||||||
<>
|
|
||||||
<DataTable>
|
|
||||||
<THead>
|
|
||||||
<TH>Ώρα</TH><TH>Εκτυπωτής</TH><TH>Παραγγελία #</TH><TH>Αποτέλεσμα</TH><TH>Σφάλμα</TH>
|
|
||||||
</THead>
|
|
||||||
<tbody>
|
|
||||||
{logs.slice(0, 100).map(j => (
|
|
||||||
<TR key={j.id} striped className={!j.success ? 'bg-rose-50/40' : ''}>
|
|
||||||
<TD mono>{fmtDateTime(j.printed_at)}</TD>
|
|
||||||
<TD>{j.printer_name}</TD>
|
|
||||||
<TD mono>#{j.order_id}</TD>
|
|
||||||
<TD><StatusBadge status={j.success ? 'success' : 'failed'} /></TD>
|
|
||||||
<TD className="font-mono text-[11px] text-rose-700">
|
|
||||||
{j.error_message || <span className="text-slate-300">—</span>}
|
|
||||||
</TD>
|
|
||||||
</TR>
|
|
||||||
))}
|
|
||||||
</tbody>
|
|
||||||
</DataTable>
|
|
||||||
{logs.length > 100 && (
|
|
||||||
<div className="border-t border-slate-100 bg-slate-50/50 px-4 py-2 text-center text-[11px] text-slate-500">
|
|
||||||
Εμφάνιση πρώτων 100 από {logs.length} εργασίες.
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</Panel>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -1,530 +0,0 @@
|
|||||||
import { useState } from 'react'
|
|
||||||
import { useQuery } from '@tanstack/react-query'
|
|
||||||
import { Printer, AlertCircle, Hash, Euro, FileText, X, ChevronDown, Loader2 } from 'lucide-react'
|
|
||||||
import toast from 'react-hot-toast'
|
|
||||||
import client from '../../../api/client'
|
|
||||||
import { FilterBar, FilterSelect, FilterDateInput, WorkDayDateToggle } from '../shared/FilterBar'
|
|
||||||
import { Panel, DataTable, THead, TH, TR, TD, StatusBadge } from '../shared/TablePrimitives'
|
|
||||||
import StatCard from '../shared/StatCard'
|
|
||||||
import EmptyState from '../shared/EmptyState'
|
|
||||||
import SkeletonTable from '../shared/SkeletonTable'
|
|
||||||
import ExportButton from '../shared/ExportButton'
|
|
||||||
import { fmtNum, fmtEUR, fmtDate, fmtTime, fmtDateTime, fmtDateStr } 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) }
|
|
||||||
|
|
||||||
// ─── Print Summary Modal ────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
const PRINT_TYPES = [
|
|
||||||
{
|
|
||||||
id: 'quick',
|
|
||||||
label: 'Γρήγορη Σύνοψη',
|
|
||||||
desc: 'Συγκεντρωτικά στατιστικά — λίγο χαρτί',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 'orders',
|
|
||||||
label: 'Όλες οι Παραγγελίες',
|
|
||||||
desc: 'Κάθε παραγγελία με σύνολο, χωρίς ανάλυση ειδών',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 'detailed',
|
|
||||||
label: 'Πλήρης Ανάλυση',
|
|
||||||
desc: 'Κάθε παραγγελία + όλα τα είδη — καταναλώνει πολύ χαρτί',
|
|
||||||
},
|
|
||||||
]
|
|
||||||
|
|
||||||
function PrintSummaryModal({ onClose, logs, stats, printers, printerF, queryParams }) {
|
|
||||||
const [printType, setPrintType] = useState('quick')
|
|
||||||
const [targetPrinter, setTargetPrinter] = useState('browser')
|
|
||||||
const [itemBreakdown, setItemBreakdown] = useState(false)
|
|
||||||
const [printing, setPrinting] = useState(false)
|
|
||||||
|
|
||||||
const printerOptions = [
|
|
||||||
{ value: 'browser', label: 'Εκτύπωση μέσω browser' },
|
|
||||||
...printers.map(p => ({ value: String(p.id), label: p.name })),
|
|
||||||
]
|
|
||||||
|
|
||||||
async function handlePrint() {
|
|
||||||
if (targetPrinter !== 'browser') {
|
|
||||||
await handleThermalPrint()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
handleBrowserPrint()
|
|
||||||
}
|
|
||||||
|
|
||||||
async function handleThermalPrint() {
|
|
||||||
const printerTargetId = printerF === 'all' ? 0 : parseInt(printerF, 10)
|
|
||||||
|
|
||||||
const body = {
|
|
||||||
printer_target_id: printerTargetId,
|
|
||||||
printer_id: parseInt(targetPrinter, 10),
|
|
||||||
mode: printType,
|
|
||||||
item_breakdown: itemBreakdown,
|
|
||||||
}
|
|
||||||
|
|
||||||
if (queryParams.business_day_id) {
|
|
||||||
body.business_day_id = parseInt(queryParams.business_day_id, 10)
|
|
||||||
} else {
|
|
||||||
body.from_dt = queryParams.from || (new Date(Date.now() - 30 * 86400000).toISOString().slice(0, 10) + 'T00:00:00')
|
|
||||||
body.to_dt = queryParams.to || (new Date().toISOString().slice(0, 10) + 'T23:59:59')
|
|
||||||
}
|
|
||||||
|
|
||||||
setPrinting(true)
|
|
||||||
try {
|
|
||||||
await client.post('/api/reports/print/printer', body)
|
|
||||||
toast.success('Η εκτύπωση στάλθηκε στον εκτυπωτή')
|
|
||||||
onClose()
|
|
||||||
} catch {
|
|
||||||
toast.error('Αποτυχία αποστολής στον εκτυπωτή')
|
|
||||||
} finally {
|
|
||||||
setPrinting(false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleBrowserPrint() {
|
|
||||||
const win = window.open('', '_blank', 'width=820,height=750')
|
|
||||||
if (!win) { onClose(); return }
|
|
||||||
|
|
||||||
// ── Group logs by printer ──────────────────────────────────────────────
|
|
||||||
// For "all printers" we produce one section per printer.
|
|
||||||
// For a single selected printer the single section is the same format.
|
|
||||||
const printerMap = {}
|
|
||||||
for (const j of logs) {
|
|
||||||
const key = j.printer_name
|
|
||||||
if (!printerMap[key]) {
|
|
||||||
printerMap[key] = { name: key, printJobs: 0, orderIds: new Set(), totalItems: 0, totalValue: 0, orders: [] }
|
|
||||||
}
|
|
||||||
const g = printerMap[key]
|
|
||||||
g.printJobs += 1
|
|
||||||
g.orderIds.add(j.order_id)
|
|
||||||
const itemQty = (j.items || []).reduce((s, i) => s + i.quantity, 0)
|
|
||||||
g.totalItems += itemQty
|
|
||||||
if (j.order_total != null) g.totalValue += j.order_total
|
|
||||||
g.orders.push(j)
|
|
||||||
}
|
|
||||||
|
|
||||||
// De-dup order totals per printer group (same order_id → count once)
|
|
||||||
for (const g of Object.values(printerMap)) {
|
|
||||||
const seen = {}
|
|
||||||
g.totalValue = 0
|
|
||||||
for (const j of g.orders) {
|
|
||||||
if (j.success && j.order_total != null && !seen[j.order_id]) {
|
|
||||||
seen[j.order_id] = true
|
|
||||||
g.totalValue += j.order_total
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const groups = Object.values(printerMap)
|
|
||||||
const filterLabel = printerF === 'all'
|
|
||||||
? 'Όλοι οι Εκτυπωτές'
|
|
||||||
: (printers.find(p => String(p.id) === printerF)?.name || printerF)
|
|
||||||
|
|
||||||
// ── Period label ───────────────────────────────────────────────────────
|
|
||||||
let periodRow = ''
|
|
||||||
if (queryParams.business_day_id) {
|
|
||||||
periodRow = `<div class="row"><span>Εργάσιμη Μέρα</span><span>${stats.periodLabel}</span></div>`
|
|
||||||
} else {
|
|
||||||
const fromStr = queryParams.from ? fmtDateStr(queryParams.from.slice(0, 10)) : '—'
|
|
||||||
const toStr = queryParams.to ? fmtDateStr(queryParams.to.slice(0, 10)) : '—'
|
|
||||||
periodRow = `<div class="row"><span>Από</span><span>${fromStr}</span></div>
|
|
||||||
<div class="row"><span>Έως</span><span>${toStr}</span></div>`
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Titles per mode ────────────────────────────────────────────────────
|
|
||||||
const titles = {
|
|
||||||
quick: 'Γρήγορη Ανάλυση Εκτυπώσεων',
|
|
||||||
orders: 'Ανάλυση Εκτυπώσεων με Παραγγελίες',
|
|
||||||
detailed: 'Αναλυτικό Ιστορικό Εκτυπώσεων',
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Render one printer block ───────────────────────────────────────────
|
|
||||||
function renderPrinterBlock(g) {
|
|
||||||
const orderCount = g.orderIds.size
|
|
||||||
const statsBlock = `
|
|
||||||
<div class="printer-header">
|
|
||||||
<span>Εκτυπωτής</span><span>${g.name}</span>
|
|
||||||
</div>
|
|
||||||
<div class="divider"></div>
|
|
||||||
<div class="row"><span>Εκτυπώσεις</span><span>${fmtNum(g.printJobs)}</span></div>
|
|
||||||
<div class="row"><span>Παραγγελίες</span><span>${fmtNum(orderCount)}</span></div>
|
|
||||||
<div class="row"><span>Είδη</span><span>${fmtNum(g.totalItems)}</span></div>
|
|
||||||
<div class="row value-row"><span>Αξία Ειδών</span><span>${fmtEUR(g.totalValue)}</span></div>
|
|
||||||
`
|
|
||||||
|
|
||||||
if (printType === 'quick') {
|
|
||||||
return `<div class="printer-block">${statsBlock}</div>`
|
|
||||||
}
|
|
||||||
|
|
||||||
if (printType === 'orders') {
|
|
||||||
// Unique orders only
|
|
||||||
const seenOrders = {}
|
|
||||||
const orderLines = g.orders
|
|
||||||
.filter(j => j.success)
|
|
||||||
.filter(j => { if (seenOrders[j.order_id]) return false; seenOrders[j.order_id] = true; return true })
|
|
||||||
.map(j => {
|
|
||||||
const itemQty = (j.items || []).reduce((s, i) => s + i.quantity, 0)
|
|
||||||
return `<div class="order-line">
|
|
||||||
<span class="order-id">#${j.order_id} · ${j.table || '—'}</span>
|
|
||||||
<span class="order-meta">${itemQty} είδη</span>
|
|
||||||
<span class="order-value">${j.order_total != null ? fmtEUR(j.order_total) : '—'}</span>
|
|
||||||
</div>`
|
|
||||||
}).join('')
|
|
||||||
return `<div class="printer-block">${statsBlock}<div class="divider"></div>${orderLines}</div>`
|
|
||||||
}
|
|
||||||
|
|
||||||
// detailed — full log, each entry is a print job
|
|
||||||
const jobBlocks = g.orders.map(j => {
|
|
||||||
const result = j.success ? '✓ Επιτυχία' : '✗ Αποτυχία'
|
|
||||||
const itemRows = (j.items || []).map(i =>
|
|
||||||
`<div class="item-row"><span>${i.name}</span><span>×${i.quantity}</span></div>`
|
|
||||||
).join('')
|
|
||||||
return `
|
|
||||||
<div class="job-block ${!j.success ? 'failed' : ''}">
|
|
||||||
<div class="job-header">
|
|
||||||
<span>#${j.order_id} · ${j.table || '—'}</span>
|
|
||||||
<span>${fmtDateTime(j.printed_at)} · ${result}</span>
|
|
||||||
</div>
|
|
||||||
${itemRows}
|
|
||||||
${j.order_total != null ? `<div class="job-total"><span>Σύνολο Παραγγελίας</span><span>${fmtEUR(j.order_total)}</span></div>` : ''}
|
|
||||||
</div>`
|
|
||||||
}).join('')
|
|
||||||
|
|
||||||
return `<div class="printer-block">${statsBlock}<div class="divider"></div>${jobBlocks}</div>`
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Summary footer (multi-printer only) ───────────────────────────────
|
|
||||||
function renderSummary() {
|
|
||||||
if (groups.length <= 1) return ''
|
|
||||||
const totJobs = groups.reduce((s, g) => s + g.printJobs, 0)
|
|
||||||
const totOrders = groups.reduce((s, g) => s + g.orderIds.size, 0)
|
|
||||||
const totItems = groups.reduce((s, g) => s + g.totalItems, 0)
|
|
||||||
const totValue = groups.reduce((s, g) => s + g.totalValue, 0)
|
|
||||||
return `
|
|
||||||
<div class="summary-block">
|
|
||||||
<div class="summary-title">Σύνολο Όλων των Εκτυπωτών</div>
|
|
||||||
<div class="row"><span>Εκτυπώσεις</span><span>${fmtNum(totJobs)}</span></div>
|
|
||||||
<div class="row"><span>Παραγγελίες</span><span>${fmtNum(totOrders)}</span></div>
|
|
||||||
<div class="row"><span>Είδη</span><span>${fmtNum(totItems)}</span></div>
|
|
||||||
<div class="row value-row"><span>Αξία Ειδών</span><span>${fmtEUR(totValue)}</span></div>
|
|
||||||
</div>`
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Product breakdown (optional) ───────────────────────────────────────
|
|
||||||
function renderItemBreakdown() {
|
|
||||||
if (!itemBreakdown) return ''
|
|
||||||
// Merge item counts across all printer groups
|
|
||||||
const combined = {}
|
|
||||||
for (const g of groups) {
|
|
||||||
for (const j of g.orders) {
|
|
||||||
if (!j.success) continue
|
|
||||||
for (const i of (j.items || [])) {
|
|
||||||
if (!combined[i.name]) combined[i.name] = { qty: 0 }
|
|
||||||
combined[i.name].qty += i.quantity
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!Object.keys(combined).length) return ''
|
|
||||||
const sorted = Object.entries(combined).sort((a, b) => b[1].qty - a[1].qty)
|
|
||||||
return `
|
|
||||||
<div class="breakdown-block">
|
|
||||||
<div class="breakdown-title">Ανάλυση Προϊόντων</div>
|
|
||||||
${sorted.map(([name, d]) => `
|
|
||||||
<div class="breakdown-row">
|
|
||||||
<span class="breakdown-name">${name}</span>
|
|
||||||
<span class="breakdown-qty">${d.qty}</span>
|
|
||||||
</div>`).join('')}
|
|
||||||
</div>`
|
|
||||||
}
|
|
||||||
|
|
||||||
const styles = `
|
|
||||||
<style>
|
|
||||||
* { box-sizing: border-box; margin: 0; padding: 0; }
|
|
||||||
body { font-family: 'Courier New', monospace; font-size: 12px; color: #000; padding: 24px; max-width: 760px; }
|
|
||||||
h1 { font-size: 16px; font-weight: bold; border-bottom: 2px solid #000; padding-bottom: 6px; margin-bottom: 12px; }
|
|
||||||
.meta { margin-bottom: 16px; }
|
|
||||||
.row { display: flex; justify-content: space-between; padding: 3px 0; }
|
|
||||||
.divider { border-top: 1px dashed #999; margin: 6px 0; }
|
|
||||||
.printer-block { border: 1px solid #ccc; border-radius: 4px; padding: 10px; margin-bottom: 14px; }
|
|
||||||
.printer-header { display: flex; justify-content: space-between; font-weight: bold; font-size: 13px; margin-bottom: 4px; }
|
|
||||||
.value-row { font-weight: bold; }
|
|
||||||
.order-line { display: flex; gap: 8px; padding: 2px 0; font-size: 11px; }
|
|
||||||
.order-id { flex: 1; }
|
|
||||||
.order-meta { color: #666; min-width: 60px; text-align: right; }
|
|
||||||
.order-value { min-width: 70px; text-align: right; font-weight: bold; }
|
|
||||||
.job-block { margin-bottom: 8px; padding: 6px 0; border-bottom: 1px dotted #ddd; }
|
|
||||||
.job-block:last-child { border-bottom: none; }
|
|
||||||
.job-block.failed { color: #b00; }
|
|
||||||
.job-header { display: flex; justify-content: space-between; font-weight: bold; font-size: 11px; margin-bottom: 3px; }
|
|
||||||
.item-row { display: flex; justify-content: space-between; padding-left: 12px; font-size: 11px; color: #333; }
|
|
||||||
.job-total { display: flex; justify-content: space-between; padding-left: 12px; font-size: 11px; font-weight: bold; margin-top: 3px; }
|
|
||||||
.summary-block { border: 2px solid #000; border-radius: 4px; padding: 10px; margin-top: 8px; }
|
|
||||||
.summary-title { font-weight: bold; font-size: 13px; margin-bottom: 6px; text-align: center; letter-spacing: 0.04em; }
|
|
||||||
.breakdown-block { border: 1px solid #888; border-radius: 4px; padding: 10px; margin-top: 14px; }
|
|
||||||
.breakdown-title { font-weight: bold; font-size: 13px; margin-bottom: 8px; letter-spacing: 0.04em; }
|
|
||||||
.breakdown-row { display: flex; justify-content: space-between; padding: 2px 0; border-bottom: 1px dotted #ccc; font-size: 12px; }
|
|
||||||
.breakdown-row:last-child { border-bottom: none; }
|
|
||||||
.breakdown-name { flex: 1; }
|
|
||||||
.breakdown-qty { font-weight: bold; min-width: 40px; text-align: right; }
|
|
||||||
@media print { body { padding: 0; } }
|
|
||||||
</style>
|
|
||||||
`
|
|
||||||
|
|
||||||
const htmlBody = `
|
|
||||||
<h1>${titles[printType] || 'Αναφορά Εκτυπωτή'}</h1>
|
|
||||||
<div class="meta">
|
|
||||||
<div class="row"><span>Εκτυπωτής</span><span>${filterLabel}</span></div>
|
|
||||||
${periodRow}
|
|
||||||
<div class="row"><span>Σύνολο Εγγραφών</span><span>${logs.length}</span></div>
|
|
||||||
</div>
|
|
||||||
${groups.map(renderPrinterBlock).join('')}
|
|
||||||
${renderSummary()}
|
|
||||||
${renderItemBreakdown()}
|
|
||||||
`
|
|
||||||
|
|
||||||
win.document.write(`<!DOCTYPE html><html><head><meta charset="UTF-8"><title>Ιστορικό Εκτυπωτή</title>${styles}</head><body>${htmlBody}</body></html>`)
|
|
||||||
win.document.close()
|
|
||||||
win.focus()
|
|
||||||
win.print()
|
|
||||||
onClose()
|
|
||||||
} // end handleBrowserPrint
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div
|
|
||||||
className="fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4"
|
|
||||||
onMouseDown={e => { if (e.target === e.currentTarget) onClose() }}
|
|
||||||
>
|
|
||||||
<div className="relative w-full max-w-md rounded-xl border border-slate-200 bg-white shadow-xl">
|
|
||||||
<div className="flex items-center justify-between border-b border-slate-100 px-5 py-4">
|
|
||||||
<h2 className="text-[15px] font-semibold text-slate-900">Εκτύπωση Σύνοψης</h2>
|
|
||||||
<button onClick={onClose} className="rounded-md p-1 text-slate-400 transition hover:bg-slate-100 hover:text-slate-600">
|
|
||||||
<X className="h-4 w-4" />
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="px-5 py-4 space-y-4 text-[13px] text-slate-700">
|
|
||||||
<div>
|
|
||||||
<div className="mb-2 text-[11px] font-medium uppercase tracking-[0.08em] text-slate-500">Τύπος Εκτύπωσης</div>
|
|
||||||
<div className="space-y-2">
|
|
||||||
{PRINT_TYPES.map(pt => (
|
|
||||||
<label key={pt.id} className={`flex cursor-pointer items-start gap-3 rounded-lg border p-3 transition ${printType === pt.id ? 'border-sky-400 bg-sky-50' : 'border-slate-200 hover:border-slate-300 hover:bg-slate-50'}`}>
|
|
||||||
<input
|
|
||||||
type="radio"
|
|
||||||
name="printType"
|
|
||||||
value={pt.id}
|
|
||||||
checked={printType === pt.id}
|
|
||||||
onChange={() => setPrintType(pt.id)}
|
|
||||||
className="mt-0.5 accent-sky-500"
|
|
||||||
/>
|
|
||||||
<div>
|
|
||||||
<div className="font-medium text-slate-800">{pt.label}</div>
|
|
||||||
<div className="text-[12px] text-slate-500">{pt.desc}</div>
|
|
||||||
</div>
|
|
||||||
</label>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<label className="flex cursor-pointer items-start gap-3 rounded-lg border border-slate-200 p-3 transition hover:border-slate-300 hover:bg-slate-50">
|
|
||||||
<input
|
|
||||||
type="checkbox"
|
|
||||||
checked={itemBreakdown}
|
|
||||||
onChange={e => setItemBreakdown(e.target.checked)}
|
|
||||||
className="mt-0.5 accent-sky-500"
|
|
||||||
/>
|
|
||||||
<div>
|
|
||||||
<div className="font-medium text-slate-800">Ανάλυση Προϊόντων</div>
|
|
||||||
<div className="text-[12px] text-slate-500">Προσθέτει σύνολο τεμαχίων ανά προϊόν στο τέλος</div>
|
|
||||||
</div>
|
|
||||||
</label>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<div className="mb-2 text-[11px] font-medium uppercase tracking-[0.08em] text-slate-500">Εκτυπωτής Προορισμού</div>
|
|
||||||
<div className="relative">
|
|
||||||
<select
|
|
||||||
value={targetPrinter}
|
|
||||||
onChange={e => setTargetPrinter(e.target.value)}
|
|
||||||
className="w-full appearance-none rounded-md border border-slate-200 bg-white py-2 pl-3 pr-8 text-[13px] text-slate-700 shadow-[0_1px_0_rgba(15,23,42,0.04)] focus:border-sky-400 focus:outline-none focus:ring-2 focus:ring-sky-100"
|
|
||||||
>
|
|
||||||
{printerOptions.map(o => <option key={o.value} value={o.value}>{o.label}</option>)}
|
|
||||||
</select>
|
|
||||||
<ChevronDown className="pointer-events-none absolute right-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-slate-400" />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="flex items-center justify-end gap-2 border-t border-slate-100 pt-2">
|
|
||||||
<button
|
|
||||||
onClick={onClose}
|
|
||||||
className="inline-flex items-center justify-center gap-2 rounded-md border border-slate-200 bg-white px-3.5 py-2 text-[13px] font-medium text-slate-700 shadow-[0_1px_0_rgba(15,23,42,0.04)] transition hover:bg-slate-50 hover:border-slate-300"
|
|
||||||
>
|
|
||||||
Ακύρωση
|
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
onClick={handlePrint}
|
|
||||||
disabled={printing}
|
|
||||||
className="inline-flex items-center justify-center gap-2 rounded-md bg-sky-500 px-3.5 py-2 text-[13px] font-medium text-white shadow-[0_1px_0_rgba(15,23,42,0.08)] transition hover:bg-sky-600 active:bg-sky-700 disabled:opacity-60 disabled:pointer-events-none"
|
|
||||||
>
|
|
||||||
{printing ? <Loader2 className="h-3.5 w-3.5 animate-spin" /> : <FileText className="h-3.5 w-3.5" />}
|
|
||||||
{printing ? 'Αποστολή...' : 'Εκτύπωση'}
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ─── Main Component ─────────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
export default function PrinterHistory() {
|
|
||||||
const [mode, setMode] = useState('range')
|
|
||||||
const [from, setFrom] = useState(monthAgo())
|
|
||||||
const [to, setTo] = useState(today())
|
|
||||||
const [businessDayId, setBusinessDayId] = useState('all')
|
|
||||||
const [printerF, setPrinterF] = useState('all')
|
|
||||||
const [showPrintModal, setShowPrintModal] = useState(false)
|
|
||||||
|
|
||||||
const { data: printersData } = useQuery({ queryKey: ['meta-printers'], queryFn: () => client.get('/api/reports/meta/printers').then(r => r.data), 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 queryParams = {
|
|
||||||
...(mode === 'workday' && businessDayId !== 'all' ? { business_day_id: businessDayId } : {}),
|
|
||||||
...(mode === 'range' ? { from: from + 'T00:00:00', to: to + 'T23:59:59' } : {}),
|
|
||||||
...(printerF !== 'all' ? { printer_id: printerF } : {}),
|
|
||||||
}
|
|
||||||
|
|
||||||
const { data, isLoading, isError, refetch } = useQuery({
|
|
||||||
queryKey: ['printer-history', mode, from, to, businessDayId, printerF],
|
|
||||||
queryFn: () => client.get('/api/reports/printers/history', { params: queryParams }).then(r => r.data),
|
|
||||||
staleTime: 60 * 1000,
|
|
||||||
})
|
|
||||||
|
|
||||||
const printers = printersData?.printers || []
|
|
||||||
const printerOptions = [{ value: 'all', label: 'Όλοι οι Εκτυπωτές' }, ...printers.map(p => ({ value: String(p.id), label: p.name }))]
|
|
||||||
const bdOptions = [{ value: 'all', label: 'Όλες οι Εργάσιμες Μέρες' }, ...((bdData?.business_days || []).map(bd => ({ value: String(bd.id), label: `${fmtDate(bd.opened_at)} · ${fmtTime(bd.opened_at)}` })))]
|
|
||||||
|
|
||||||
const logs = data?.logs || []
|
|
||||||
const total = data?.total || 0
|
|
||||||
const failed = data?.failed || 0
|
|
||||||
// total_amount comes pre-computed from the backend (unique orders, no double-counting reprints)
|
|
||||||
const totalAmount = data?.total_amount ?? null
|
|
||||||
|
|
||||||
// Derived stats for StatCards + Print modal
|
|
||||||
const itemCounts = {}
|
|
||||||
const waiterCounts = {}
|
|
||||||
let totalItemQty = 0
|
|
||||||
|
|
||||||
logs.forEach(l => {
|
|
||||||
if (l.waiter) waiterCounts[l.waiter] = (waiterCounts[l.waiter] || 0) + 1
|
|
||||||
;(l.items || []).forEach(i => {
|
|
||||||
itemCounts[i.name] = (itemCounts[i.name] || 0) + i.quantity
|
|
||||||
totalItemQty += i.quantity
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
const topItem = Object.entries(itemCounts).sort((a, b) => b[1] - a[1])[0]
|
|
||||||
const periodLabel = mode === 'workday'
|
|
||||||
? (bdOptions.find(o => o.value === businessDayId)?.label || 'Εργάσιμη Μέρα')
|
|
||||||
: `${fmtDateStr(from)} → ${fmtDateStr(to)}`
|
|
||||||
|
|
||||||
const stats = { total, failed, totalAmount, itemCounts, waiterCounts, totalItemQty, periodLabel, topItem }
|
|
||||||
|
|
||||||
if (isLoading) return <div className="flex-1 overflow-y-auto p-6"><SkeletonTable rows={10} columns={7} /></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 right={
|
|
||||||
<div className="flex items-center gap-2">
|
|
||||||
<button
|
|
||||||
onClick={() => setShowPrintModal(true)}
|
|
||||||
className="inline-flex items-center gap-1.5 rounded-md border border-slate-200 bg-white px-2.5 py-1.5 text-[12px] font-medium text-slate-600 shadow-[0_1px_0_rgba(15,23,42,0.04)] transition hover:border-slate-300 hover:bg-slate-50 hover:text-slate-900"
|
|
||||||
>
|
|
||||||
<FileText className="h-3.5 w-3.5" />
|
|
||||||
Εκτύπωση Σύνοψης
|
|
||||||
</button>
|
|
||||||
<ExportButton endpoint="/api/reports/printers/export" params={queryParams} filename={`printer-history-${from}-to-${to}.csv`} />
|
|
||||||
</div>
|
|
||||||
}>
|
|
||||||
<WorkDayDateToggle mode={mode} onChange={setMode} />
|
|
||||||
{mode === 'workday' ? (
|
|
||||||
<FilterSelect value={businessDayId} onChange={setBusinessDayId} options={bdOptions} width="w-72" label="Μέρα" />
|
|
||||||
) : (
|
|
||||||
<>
|
|
||||||
<FilterDateInput value={from} onChange={setFrom} label="Από" />
|
|
||||||
<FilterDateInput value={to} onChange={setTo} label="Έως" />
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
<FilterSelect value={printerF} onChange={setPrinterF} options={printerOptions} label="Εκτυπωτής" />
|
|
||||||
</FilterBar>
|
|
||||||
|
|
||||||
<div className="flex-1 overflow-y-auto p-6">
|
|
||||||
<div className="grid grid-cols-4 gap-4 mb-4">
|
|
||||||
<StatCard label="Συνολικές Εκτυπώσεις" value={fmtNum(total)} icon={Printer} />
|
|
||||||
<StatCard label="Αποτυχημένες" value={fmtNum(failed)} sub={failed > 0 ? 'ελέγξτε τον εκτυπωτή' : 'όλα καλά'} icon={AlertCircle} />
|
|
||||||
<StatCard label="Παραγγελίες Εκτυπώθηκαν" value={fmtNum(total - failed)} sub="επιτυχείς εκτυπώσεις" icon={Hash} />
|
|
||||||
<StatCard
|
|
||||||
label="Συνολικό Ποσό Παραγγελιών"
|
|
||||||
value={totalAmount != null ? fmtEUR(totalAmount) : '—'}
|
|
||||||
sub={totalAmount == null ? 'μη διαθέσιμο' : undefined}
|
|
||||||
icon={Euro}
|
|
||||||
accent={totalAmount != null}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<Panel title="Εργασίες Εκτύπωσης" padded={false}>
|
|
||||||
{logs.length === 0 ? (
|
|
||||||
<EmptyState title="Δεν βρέθηκαν εργασίες εκτύπωσης" description="Δοκιμάστε διαφορετικό εύρος ημερομηνιών ή εκτυπωτή." />
|
|
||||||
) : (
|
|
||||||
<>
|
|
||||||
<DataTable>
|
|
||||||
<THead>
|
|
||||||
<TH>Ώρα Εκτύπωσης</TH><TH>Εκτυπωτής</TH><TH>Παραγγελία #</TH><TH>Τραπέζι</TH><TH>Είδη</TH><TH>Αποτέλεσμα</TH>
|
|
||||||
</THead>
|
|
||||||
<tbody>
|
|
||||||
{logs.slice(0, 100).map(j => (
|
|
||||||
<TR key={j.id} striped className={!j.success ? 'bg-rose-50/40' : ''}>
|
|
||||||
<TD mono>{fmtDateTime(j.printed_at)}</TD>
|
|
||||||
<TD>{j.printer_name}</TD>
|
|
||||||
<TD mono>#{j.order_id}</TD>
|
|
||||||
<TD>{j.table}</TD>
|
|
||||||
<TD className="text-[12px] text-slate-600">
|
|
||||||
{(j.items || []).slice(0, 3).map((i, idx) => (
|
|
||||||
<span key={idx}>{i.name} ×{i.quantity}{idx < Math.min((j.items || []).length, 3) - 1 ? ', ' : ''}</span>
|
|
||||||
))}
|
|
||||||
{(j.items || []).length > 3 && <span className="text-slate-400"> +{(j.items || []).length - 3} ακόμα</span>}
|
|
||||||
</TD>
|
|
||||||
<TD><StatusBadge status={j.success ? 'success' : 'failed'} /></TD>
|
|
||||||
</TR>
|
|
||||||
))}
|
|
||||||
</tbody>
|
|
||||||
</DataTable>
|
|
||||||
{logs.length > 100 && (
|
|
||||||
<div className="border-t border-slate-100 bg-slate-50/50 px-4 py-2 text-center text-[11px] text-slate-500">
|
|
||||||
Εμφάνιση πρώτων 100 από {logs.length} εργασίες.
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</Panel>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{showPrintModal && (
|
|
||||||
<PrintSummaryModal
|
|
||||||
onClose={() => setShowPrintModal(false)}
|
|
||||||
logs={logs}
|
|
||||||
stats={stats}
|
|
||||||
printers={printers}
|
|
||||||
printerF={printerF}
|
|
||||||
queryParams={queryParams}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,106 @@
|
|||||||
|
// Reports → Prep zones (plan step 6.12c; replaces the v1 prep zones report): what each zone (the
|
||||||
|
// kitchen, the bar…) prepared in a period — items, their value, every product with its count and
|
||||||
|
// every order — so the owner sees each station's load. Download a zone's products or orders for
|
||||||
|
// Excel, or print a zone's summary on a receipt printer.
|
||||||
|
import { useState } from 'react'
|
||||||
|
import { ChevronDown, ChevronRight, Download, Printer } from 'lucide-react'
|
||||||
|
import { useFormat, useTranslation } from '@xenia/i18n'
|
||||||
|
import { Button, cx } from '@xenia/ui'
|
||||||
|
import client from '../../../api/client'
|
||||||
|
import { useLiveQuery } from '../../../live/useLiveQuery'
|
||||||
|
import { Pill } from '../../overview/parts'
|
||||||
|
import { BarList } from '../kit/charts'
|
||||||
|
import { Failed, Loading, Panel, ReportPage, Stat, Table } from '../kit/parts'
|
||||||
|
import { PeriodPicker } from '../kit/Period'
|
||||||
|
import PrintDialog from '../kit/PrintDialog'
|
||||||
|
import { csvText, defaultPeriod, download, periodParams, periodSlug, printBody } from '../kit/reportLogic'
|
||||||
|
|
||||||
|
export default function PrepZonesReport() {
|
||||||
|
const { t } = useTranslation('manager')
|
||||||
|
return <ReportPage title={t('reports.zones.title')} testId="report-prep-zones"><Zones /></ReportPage>
|
||||||
|
}
|
||||||
|
|
||||||
|
function Zones() {
|
||||||
|
const { t } = useTranslation('manager')
|
||||||
|
const fmt = useFormat()
|
||||||
|
const [period, setPeriod] = useState(() => defaultPeriod(fmt.venueToday()))
|
||||||
|
const [only, setOnly] = useState([]) // zone ids shown; [] = all
|
||||||
|
const params = periodParams(period)
|
||||||
|
const { data, isPending, error, refetch } = useLiveQuery({ queryKey: ['report-prep-zones', params], queryFn: () => client.get('/api/reports/prep-zones', { params }).then(r => r.data.zones) })
|
||||||
|
const zones = data ?? []
|
||||||
|
const shown = only.length ? zones.filter(z => only.includes(z.id)) : zones
|
||||||
|
const toggle = id => setOnly(o => (o.includes(id) ? o.filter(x => x !== id) : [...o, id]))
|
||||||
|
return (
|
||||||
|
<div className="grid gap-4">
|
||||||
|
<PeriodPicker value={period} onChange={setPeriod} />
|
||||||
|
{isPending ? <Loading /> : error ? <Failed error={error} retry={refetch} /> : (<>
|
||||||
|
{zones.length > 1 && (
|
||||||
|
<div className="flex flex-wrap gap-1.5" role="group" aria-label={t('reports.zones.which')}>
|
||||||
|
<button type="button" aria-pressed={!only.length} onClick={() => setOnly([])}
|
||||||
|
className={cx('px-3 py-1 rounded-full border text-label', !only.length ? 'border-accent bg-accent-soft text-accent-ink font-semibold' : 'border-line bg-surface text-ink-2')}>{t('reports.zones.all')}</button>
|
||||||
|
{zones.map(z => (
|
||||||
|
<button key={z.id} type="button" aria-pressed={only.includes(z.id)} onClick={() => toggle(z.id)}
|
||||||
|
className={cx('px-3 py-1 rounded-full border text-label', only.includes(z.id) ? 'border-accent bg-accent-soft text-accent-ink font-semibold' : 'border-line bg-surface text-ink-2')}>{z.name}</button>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{zones.length > 1 && (
|
||||||
|
<Panel title={t('reports.zones.load')} tip={t('reports.zones.loadTip')}>
|
||||||
|
<BarList format={v => fmt.formatNumber(v, { maxDecimals: 3 })} rows={shown.map(z => ({ key: z.id, label: z.name, value: z.item_count, sub: fmt.formatMoney(z.total_value) }))} />
|
||||||
|
</Panel>
|
||||||
|
)}
|
||||||
|
{shown.map(z => <ZoneCard key={z.id} zone={z} period={period} />)}
|
||||||
|
</>)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function ZoneCard({ zone: z, period }) {
|
||||||
|
const { t, i18n } = useTranslation('manager')
|
||||||
|
const fmt = useFormat()
|
||||||
|
const [orders, setOrders] = useState(false)
|
||||||
|
const [printing, setPrinting] = useState(false)
|
||||||
|
const lang = i18n.language
|
||||||
|
const slug = `${z.name}-${periodSlug(period)}`.replace(/[^\p{L}\p{N}_-]+/gu, '-')
|
||||||
|
const products = () => download(csvText([t('reports.prod.product'), t('reports.prod.units'), t('reports.misc.value')], z.all_products.map(p => [p.name, p.count, p.value]), lang), `zone-products-${slug}.csv`)
|
||||||
|
const ordersCsv = () => download(csvText(['#', t('reports.place'), t('reports.opened'), t('reports.prod.units'), t('reports.misc.value')],
|
||||||
|
z.all_orders.map(o => [o.order_id, o.table, fmt.formatDateTime(o.opened_at, 'datetimeShort'), o.items_count, o.value]), lang), `zone-orders-${slug}.csv`)
|
||||||
|
const productCols = [
|
||||||
|
{ key: 'name', label: t('reports.prod.product'), render: p => <span className="font-semibold text-ink">{p.name}</span> },
|
||||||
|
{ key: 'count', label: t('reports.prod.units'), align: 'right', render: p => fmt.formatNumber(p.count, { maxDecimals: 3 }) },
|
||||||
|
{ key: 'value', label: t('reports.misc.value'), align: 'right', render: p => fmt.formatMoney(p.value) },
|
||||||
|
]
|
||||||
|
const orderCols = [
|
||||||
|
{ key: 'order_id', label: '#', render: o => <span className="tabular-nums text-ink-2">#{o.order_id}</span> },
|
||||||
|
{ key: 'table', label: t('reports.place') },
|
||||||
|
{ key: 'opened_at', label: t('reports.opened'), render: o => fmt.formatDateTime(o.opened_at, 'datetimeShort') },
|
||||||
|
{ key: 'items_count', label: t('reports.prod.units'), align: 'right', render: o => fmt.formatNumber(o.items_count, { maxDecimals: 3 }) },
|
||||||
|
{ key: 'value', label: t('reports.misc.value'), align: 'right', render: o => fmt.formatMoney(o.value) },
|
||||||
|
]
|
||||||
|
return (
|
||||||
|
<Panel padded={false} testId="report-zone" title={<span className="flex flex-wrap items-center gap-2">{z.name}
|
||||||
|
{z.notification_name && <span className="text-label font-normal text-ink-2">{z.notification_name}</span>}
|
||||||
|
{z.printers.map(p => <Pill key={p.id}><Printer size={12} aria-hidden="true" />{p.name}</Pill>)}</span>}
|
||||||
|
actions={<span className="flex flex-wrap gap-1">
|
||||||
|
<Button size="sm" variant="ghost" icon={<Download size={14} />} onClick={products} disabled={!z.all_products.length}>{t('reports.zones.productsCsv')}</Button>
|
||||||
|
<Button size="sm" variant="ghost" icon={<Download size={14} />} onClick={ordersCsv} disabled={!z.all_orders.length}>{t('reports.zones.ordersCsv')}</Button>
|
||||||
|
<Button size="sm" variant="secondary" icon={<Printer size={14} />} onClick={() => setPrinting(true)}>{t('reports.print.button')}</Button>
|
||||||
|
</span>}>
|
||||||
|
<div className="grid gap-3 p-4 grid-cols-[repeat(auto-fill,minmax(10rem,1fr))]">
|
||||||
|
<Stat label={t('reports.zones.items')} value={fmt.formatNumber(z.item_count, { maxDecimals: 3 })} />
|
||||||
|
<Stat label={t('reports.zones.value')} tip={t('reports.zones.valueTip')} value={fmt.formatMoney(z.total_value)} />
|
||||||
|
<Stat label={t('reports.orders')} value={z.all_orders.length} />
|
||||||
|
</div>
|
||||||
|
<Table columns={productCols} rows={z.all_products} rowKey={p => p.name} initialSort={{ key: 'count', dir: 'desc' }} empty={t('reports.zones.nothing')} />
|
||||||
|
{z.all_orders.length > 0 && (
|
||||||
|
<div className="border-t border-line">
|
||||||
|
<button type="button" onClick={() => setOrders(o => !o)} className="w-full flex items-center gap-1 px-4 py-2 text-label font-semibold text-ink-2 hover:bg-surface-2">
|
||||||
|
{orders ? <ChevronDown size={16} /> : <ChevronRight size={16} />}{t('reports.zones.orders', { count: z.all_orders.length })}
|
||||||
|
</button>
|
||||||
|
{orders && <Table columns={orderCols} rows={z.all_orders} rowKey={o => o.order_id} initialSort={{ key: 'opened_at', dir: 'desc' }} />}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{printing && <PrintDialog endpoint="/api/reports/print/prep-zone" modes={['smart']} body={{ ...printBody(period), zone_id: z.id }} onClose={() => setPrinting(false)} />}
|
||||||
|
</Panel>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
import { useEffect } from 'react'
|
|
||||||
import { X, ChevronLeft } from 'lucide-react'
|
|
||||||
|
|
||||||
export default function DrillDownModal({ title, subtitle, onClose, onBack, children }) {
|
|
||||||
useEffect(() => {
|
|
||||||
const onKey = (e) => { if (e.key === 'Escape') onClose() }
|
|
||||||
window.addEventListener('keydown', onKey)
|
|
||||||
return () => window.removeEventListener('keydown', onKey)
|
|
||||||
}, [onClose])
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div
|
|
||||||
className="fixed inset-0 z-50 flex items-center justify-center bg-slate-900/30 backdrop-blur-sm"
|
|
||||||
onClick={onClose}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
className="relative max-h-[88vh] w-[960px] max-w-[94vw] overflow-hidden rounded-lg bg-white shadow-2xl ring-1 ring-slate-200"
|
|
||||||
onClick={(e) => e.stopPropagation()}
|
|
||||||
>
|
|
||||||
<div className="flex items-start justify-between border-b border-slate-200 px-6 py-4">
|
|
||||||
<div className="flex items-center gap-3">
|
|
||||||
{onBack && (
|
|
||||||
<button
|
|
||||||
onClick={onBack}
|
|
||||||
className="flex items-center gap-1 rounded-md px-2 py-1 text-[12px] text-slate-500 hover:bg-slate-100 hover:text-slate-700"
|
|
||||||
>
|
|
||||||
<ChevronLeft className="h-3.5 w-3.5" />
|
|
||||||
Πίσω
|
|
||||||
</button>
|
|
||||||
)}
|
|
||||||
<div>
|
|
||||||
<div className="text-[15px] font-semibold text-slate-900">{title}</div>
|
|
||||||
{subtitle && <div className="mt-0.5 text-[12px] text-slate-500">{subtitle}</div>}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<button
|
|
||||||
onClick={onClose}
|
|
||||||
className="rounded p-1.5 text-slate-400 hover:bg-slate-100 hover:text-slate-600"
|
|
||||||
>
|
|
||||||
<X className="h-4 w-4" />
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
<div className="max-h-[76vh] overflow-auto">{children}</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
import { Inbox } from 'lucide-react'
|
|
||||||
|
|
||||||
export default function EmptyState({ icon: Icon = Inbox, title, description, action }) {
|
|
||||||
return (
|
|
||||||
<div className="flex min-h-[300px] flex-col items-center justify-center px-6 py-12 text-center">
|
|
||||||
<div className="mb-3 flex h-12 w-12 items-center justify-center rounded-full bg-slate-100">
|
|
||||||
<Icon className="h-5 w-5 text-slate-400" />
|
|
||||||
</div>
|
|
||||||
<div className="text-[14px] font-medium text-slate-900">{title}</div>
|
|
||||||
{description && <div className="mt-1 max-w-sm text-[13px] text-slate-500">{description}</div>}
|
|
||||||
{action && <div className="mt-4">{action}</div>}
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
import { useState } from 'react'
|
|
||||||
import { Download, Loader2 } from 'lucide-react'
|
|
||||||
import toast from 'react-hot-toast'
|
|
||||||
import client from '../../../api/client'
|
|
||||||
|
|
||||||
export default function ExportButton({ endpoint, params = {}, filename = 'export.csv' }) {
|
|
||||||
const [loading, setLoading] = useState(false)
|
|
||||||
|
|
||||||
async function handleClick() {
|
|
||||||
setLoading(true)
|
|
||||||
try {
|
|
||||||
const response = await client.get(endpoint, {
|
|
||||||
params,
|
|
||||||
responseType: 'blob',
|
|
||||||
})
|
|
||||||
const url = URL.createObjectURL(response.data)
|
|
||||||
const a = document.createElement('a')
|
|
||||||
a.href = url
|
|
||||||
a.download = filename
|
|
||||||
a.click()
|
|
||||||
URL.revokeObjectURL(url)
|
|
||||||
} catch {
|
|
||||||
toast.error('Αποτυχία εξαγωγής')
|
|
||||||
} finally {
|
|
||||||
setLoading(false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<button
|
|
||||||
onClick={handleClick}
|
|
||||||
disabled={loading}
|
|
||||||
className="inline-flex items-center gap-1.5 rounded-md border border-slate-200 bg-white px-2.5 py-1.5 text-[12px] font-medium text-slate-600 shadow-[0_1px_0_rgba(15,23,42,0.04)] transition hover:border-slate-300 hover:bg-slate-50 hover:text-slate-900 disabled:opacity-60"
|
|
||||||
>
|
|
||||||
{loading
|
|
||||||
? <Loader2 className="h-3.5 w-3.5 animate-spin" />
|
|
||||||
: <Download className="h-3.5 w-3.5" />
|
|
||||||
}
|
|
||||||
Εξαγωγή CSV
|
|
||||||
</button>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -1,347 +0,0 @@
|
|||||||
import { useState, useRef, useEffect, useCallback } from 'react'
|
|
||||||
import { INPUT_CLASS } from '../../../ui/tokens'
|
|
||||||
|
|
||||||
export function FilterBar({ children, right }) {
|
|
||||||
return (
|
|
||||||
<div className="flex items-center justify-between gap-3 border-b border-slate-200 px-6 py-3 flex-shrink-0">
|
|
||||||
<div className="flex flex-wrap items-center gap-2">{children}</div>
|
|
||||||
{right && <div className="flex items-center gap-2 flex-shrink-0">{right}</div>}
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Searchable custom dropdown ─────────────────────────────────────────────────
|
|
||||||
|
|
||||||
export function FilterSelect({ value, onChange, options, label, icon: Icon }) {
|
|
||||||
const [open, setOpen] = useState(false)
|
|
||||||
const [query, setQuery] = useState('')
|
|
||||||
const containerRef = useRef(null)
|
|
||||||
const inputRef = useRef(null)
|
|
||||||
const listRef = useRef(null)
|
|
||||||
|
|
||||||
const selected = options.find(o => o.value === value)
|
|
||||||
|
|
||||||
const filtered = query.trim()
|
|
||||||
? options.filter(o => o.label.toLowerCase().includes(query.toLowerCase()))
|
|
||||||
: options
|
|
||||||
|
|
||||||
// Close on outside click
|
|
||||||
useEffect(() => {
|
|
||||||
function handler(e) {
|
|
||||||
if (containerRef.current && !containerRef.current.contains(e.target)) {
|
|
||||||
setOpen(false)
|
|
||||||
setQuery('')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (open) document.addEventListener('mousedown', handler)
|
|
||||||
return () => document.removeEventListener('mousedown', handler)
|
|
||||||
}, [open])
|
|
||||||
|
|
||||||
// Focus search input when opening
|
|
||||||
useEffect(() => {
|
|
||||||
if (open && inputRef.current) inputRef.current.focus()
|
|
||||||
}, [open])
|
|
||||||
|
|
||||||
function handleSelect(val) {
|
|
||||||
onChange(val)
|
|
||||||
setOpen(false)
|
|
||||||
setQuery('')
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleKeyDown(e) {
|
|
||||||
if (e.key === 'Escape') { setOpen(false); setQuery('') }
|
|
||||||
}
|
|
||||||
|
|
||||||
// Dropdown position: flip up if near bottom of viewport
|
|
||||||
const [dropUp, setDropUp] = useState(false)
|
|
||||||
const openDropdown = useCallback(() => {
|
|
||||||
if (containerRef.current) {
|
|
||||||
const rect = containerRef.current.getBoundingClientRect()
|
|
||||||
setDropUp(rect.bottom + 280 > window.innerHeight)
|
|
||||||
}
|
|
||||||
setOpen(true)
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div ref={containerRef} className="relative" onKeyDown={handleKeyDown}>
|
|
||||||
{/* Trigger button */}
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
onClick={() => open ? (setOpen(false), setQuery('')) : openDropdown()}
|
|
||||||
className={`flex items-center gap-2 ${INPUT_CLASS} cursor-pointer whitespace-nowrap`}
|
|
||||||
>
|
|
||||||
{Icon && <Icon className="h-3.5 w-3.5 text-slate-400 flex-shrink-0" />}
|
|
||||||
{label && (
|
|
||||||
<span className="text-[11px] font-medium uppercase tracking-wider text-slate-400 flex-shrink-0">
|
|
||||||
{label}
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
<span className="text-[13px] text-slate-700 font-normal">
|
|
||||||
{selected?.label ?? '—'}
|
|
||||||
</span>
|
|
||||||
<svg className="ml-1 h-3.5 w-3.5 text-slate-400 flex-shrink-0 transition-transform" style={{ transform: open ? 'rotate(180deg)' : '' }} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={2}>
|
|
||||||
<polyline points="6 9 12 15 18 9" />
|
|
||||||
</svg>
|
|
||||||
</button>
|
|
||||||
|
|
||||||
{/* Dropdown panel */}
|
|
||||||
{open && (
|
|
||||||
<div
|
|
||||||
className={`absolute z-50 w-64 rounded-lg border border-slate-200 bg-white shadow-lg ring-1 ring-slate-100 ${dropUp ? 'bottom-full mb-1' : 'top-full mt-1'}`}
|
|
||||||
style={{ minWidth: 'max-content' }}
|
|
||||||
>
|
|
||||||
{/* Search box — only shown when there are enough options */}
|
|
||||||
{options.length > 6 && (
|
|
||||||
<div className="border-b border-slate-100 px-3 py-2">
|
|
||||||
<div className="flex items-center gap-2 rounded-md border border-slate-200 bg-slate-50 px-2.5 py-1.5">
|
|
||||||
<svg className="h-3.5 w-3.5 text-slate-400 flex-shrink-0" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={2}>
|
|
||||||
<circle cx="11" cy="11" r="8" /><line x1="21" y1="21" x2="16.65" y2="16.65" />
|
|
||||||
</svg>
|
|
||||||
<input
|
|
||||||
ref={inputRef}
|
|
||||||
type="text"
|
|
||||||
value={query}
|
|
||||||
onChange={e => setQuery(e.target.value)}
|
|
||||||
placeholder="Αναζήτηση…"
|
|
||||||
className="flex-1 bg-transparent text-[12px] text-slate-700 placeholder-slate-400 outline-none"
|
|
||||||
/>
|
|
||||||
{query && (
|
|
||||||
<button onClick={() => setQuery('')} className="text-slate-400 hover:text-slate-600">
|
|
||||||
<svg className="h-3 w-3" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={2.5}>
|
|
||||||
<line x1="18" y1="6" x2="6" y2="18" /><line x1="6" y1="6" x2="18" y2="18" />
|
|
||||||
</svg>
|
|
||||||
</button>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Options list */}
|
|
||||||
<ul ref={listRef} className="max-h-64 overflow-y-auto py-1">
|
|
||||||
{filtered.length === 0 ? (
|
|
||||||
<li className="px-4 py-3 text-[12px] text-slate-400 text-center">Δεν βρέθηκαν αποτελέσματα</li>
|
|
||||||
) : (
|
|
||||||
filtered.map(o => {
|
|
||||||
const isActive = o.value === value
|
|
||||||
return (
|
|
||||||
<li key={o.value}>
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
onClick={() => handleSelect(o.value)}
|
|
||||||
className={`w-full px-4 py-2 text-left text-[13px] transition-colors flex items-center gap-2 ${
|
|
||||||
isActive
|
|
||||||
? 'bg-sky-50 text-sky-700 font-medium'
|
|
||||||
: 'text-slate-700 hover:bg-slate-50'
|
|
||||||
}`}
|
|
||||||
>
|
|
||||||
{isActive && (
|
|
||||||
<svg className="h-3.5 w-3.5 text-sky-500 flex-shrink-0" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={2.5}>
|
|
||||||
<polyline points="20 6 9 17 4 12" />
|
|
||||||
</svg>
|
|
||||||
)}
|
|
||||||
{!isActive && <span className="w-3.5 flex-shrink-0" />}
|
|
||||||
<span className="truncate">{o.label}</span>
|
|
||||||
</button>
|
|
||||||
</li>
|
|
||||||
)
|
|
||||||
})
|
|
||||||
)}
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Date input ─────────────────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
const GR_MONTHS = ['Ιανουάριος','Φεβρουάριος','Μάρτιος','Απρίλιος','Μάιος','Ιούνιος','Ιούλιος','Αύγουστος','Σεπτέμβριος','Οκτώβριος','Νοέμβριος','Δεκέμβριος']
|
|
||||||
const GR_DAYS = ['Κυ','Δε','Τρ','Τε','Πε','Πα','Σα']
|
|
||||||
|
|
||||||
function fmtGR(value) {
|
|
||||||
if (!value) return ''
|
|
||||||
const [y, m, d] = value.split('-')
|
|
||||||
if (!y || !m || !d) return value
|
|
||||||
return `${d}/${m}/${y}`
|
|
||||||
}
|
|
||||||
|
|
||||||
function CalendarDropdown({ value, onCommit, onClose }) {
|
|
||||||
const today = new Date()
|
|
||||||
const initYear = value ? parseInt(value.slice(0, 4)) : today.getFullYear()
|
|
||||||
const initMonth = value ? parseInt(value.slice(5, 7)) - 1 : today.getMonth()
|
|
||||||
|
|
||||||
const [viewYear, setViewYear] = useState(initYear)
|
|
||||||
const [viewMonth, setViewMonth] = useState(initMonth)
|
|
||||||
|
|
||||||
const selectedY = value ? parseInt(value.slice(0, 4)) : null
|
|
||||||
const selectedM = value ? parseInt(value.slice(5, 7)) - 1 : null
|
|
||||||
const selectedD = value ? parseInt(value.slice(8, 10)) : null
|
|
||||||
|
|
||||||
function prevMonth(e) {
|
|
||||||
e.stopPropagation()
|
|
||||||
if (viewMonth === 0) { setViewMonth(11); setViewYear(y => y - 1) }
|
|
||||||
else setViewMonth(m => m - 1)
|
|
||||||
}
|
|
||||||
function nextMonth(e) {
|
|
||||||
e.stopPropagation()
|
|
||||||
if (viewMonth === 11) { setViewMonth(0); setViewYear(y => y + 1) }
|
|
||||||
else setViewMonth(m => m + 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Build grid: first cell = weekday of 1st of month (0=Sun)
|
|
||||||
const firstDow = new Date(viewYear, viewMonth, 1).getDay()
|
|
||||||
const daysInMonth = new Date(viewYear, viewMonth + 1, 0).getDate()
|
|
||||||
const cells = []
|
|
||||||
for (let i = 0; i < firstDow; i++) cells.push(null)
|
|
||||||
for (let d = 1; d <= daysInMonth; d++) cells.push(d)
|
|
||||||
|
|
||||||
function selectDay(e, day) {
|
|
||||||
e.stopPropagation()
|
|
||||||
const mm = String(viewMonth + 1).padStart(2, '0')
|
|
||||||
const dd = String(day).padStart(2, '0')
|
|
||||||
onCommit(`${viewYear}-${mm}-${dd}`)
|
|
||||||
onClose()
|
|
||||||
}
|
|
||||||
|
|
||||||
const todayY = today.getFullYear()
|
|
||||||
const todayM = today.getMonth()
|
|
||||||
const todayD = today.getDate()
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div
|
|
||||||
className="absolute left-0 top-full mt-1 z-50 w-64 rounded-lg border border-slate-200 bg-white shadow-xl ring-1 ring-slate-100 select-none"
|
|
||||||
onMouseDown={e => e.preventDefault()}
|
|
||||||
onClick={e => e.stopPropagation()}
|
|
||||||
>
|
|
||||||
{/* Month navigation */}
|
|
||||||
<div className="flex items-center justify-between px-3 py-2 border-b border-slate-100">
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
onClick={prevMonth}
|
|
||||||
className="rounded p-1 text-slate-400 hover:bg-slate-100 hover:text-slate-700"
|
|
||||||
>
|
|
||||||
<svg className="h-4 w-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={2}><polyline points="15 18 9 12 15 6" /></svg>
|
|
||||||
</button>
|
|
||||||
<span className="text-[13px] font-semibold text-slate-800">
|
|
||||||
{GR_MONTHS[viewMonth]} {viewYear}
|
|
||||||
</span>
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
onClick={nextMonth}
|
|
||||||
className="rounded p-1 text-slate-400 hover:bg-slate-100 hover:text-slate-700"
|
|
||||||
>
|
|
||||||
<svg className="h-4 w-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={2}><polyline points="9 18 15 12 9 6" /></svg>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Day-of-week headers */}
|
|
||||||
<div className="grid grid-cols-7 px-2 pt-2 pb-1">
|
|
||||||
{GR_DAYS.map(d => (
|
|
||||||
<div key={d} className="text-center text-[10px] font-semibold text-slate-400 py-0.5">{d}</div>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Day cells */}
|
|
||||||
<div className="grid grid-cols-7 px-2 pb-2 gap-y-0.5">
|
|
||||||
{cells.map((day, i) => {
|
|
||||||
if (!day) return <div key={`e${i}`} />
|
|
||||||
const isSelected = day === selectedD && viewMonth === selectedM && viewYear === selectedY
|
|
||||||
const isToday = day === todayD && viewMonth === todayM && viewYear === todayY
|
|
||||||
return (
|
|
||||||
<button
|
|
||||||
key={day}
|
|
||||||
type="button"
|
|
||||||
onClick={e => selectDay(e, day)}
|
|
||||||
className={`
|
|
||||||
h-8 w-8 mx-auto rounded-full text-[12px] font-medium transition-colors
|
|
||||||
${isSelected
|
|
||||||
? 'bg-sky-500 text-white'
|
|
||||||
: isToday
|
|
||||||
? 'bg-sky-50 text-sky-700 ring-1 ring-sky-200 hover:bg-sky-100'
|
|
||||||
: 'text-slate-700 hover:bg-slate-100'
|
|
||||||
}
|
|
||||||
`}
|
|
||||||
>
|
|
||||||
{day}
|
|
||||||
</button>
|
|
||||||
)
|
|
||||||
})}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export function FilterDateInput({ value, onChange, label }) {
|
|
||||||
const [open, setOpen] = useState(false)
|
|
||||||
const containerRef = useRef(null)
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!open) return
|
|
||||||
function handler(e) {
|
|
||||||
if (containerRef.current && !containerRef.current.contains(e.target)) {
|
|
||||||
setOpen(false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
document.addEventListener('mousedown', handler)
|
|
||||||
return () => document.removeEventListener('mousedown', handler)
|
|
||||||
}, [open])
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div ref={containerRef} className="relative">
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
onClick={() => setOpen(o => !o)}
|
|
||||||
className={`flex items-center gap-2 ${INPUT_CLASS} cursor-pointer`}
|
|
||||||
>
|
|
||||||
<svg className="h-3.5 w-3.5 text-slate-400 flex-shrink-0" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={2}>
|
|
||||||
<rect x="3" y="4" width="18" height="18" rx="2" ry="2" /><line x1="16" y1="2" x2="16" y2="6" /><line x1="8" y1="2" x2="8" y2="6" /><line x1="3" y1="10" x2="21" y2="10" />
|
|
||||||
</svg>
|
|
||||||
{label && (
|
|
||||||
<span className="text-[11px] font-medium uppercase tracking-wider text-slate-400 flex-shrink-0">
|
|
||||||
{label}
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
<span className="text-[13px] font-normal whitespace-nowrap">
|
|
||||||
{value
|
|
||||||
? <span className="text-slate-700">{fmtGR(value)}</span>
|
|
||||||
: <span className="text-slate-400">ΗΗ/ΜΜ/ΕΕΕΕ</span>
|
|
||||||
}
|
|
||||||
</span>
|
|
||||||
</button>
|
|
||||||
|
|
||||||
{open && (
|
|
||||||
<CalendarDropdown
|
|
||||||
value={value}
|
|
||||||
onCommit={onChange}
|
|
||||||
onClose={() => setOpen(false)}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Work Day / Date Range toggle ───────────────────────────────────────────────
|
|
||||||
|
|
||||||
export function WorkDayDateToggle({ mode, onChange }) {
|
|
||||||
return (
|
|
||||||
<div className="inline-flex items-center rounded-md border border-slate-200 bg-slate-50 p-0.5 shadow-[inset_0_1px_0_rgba(15,23,42,0.04)]">
|
|
||||||
{[
|
|
||||||
{ id: 'workday', label: 'Εργάσιμη Μέρα' },
|
|
||||||
{ id: 'range', label: 'Εύρος Ημερομηνιών' },
|
|
||||||
].map((opt) => (
|
|
||||||
<button
|
|
||||||
key={opt.id}
|
|
||||||
type="button"
|
|
||||||
onClick={() => onChange(opt.id)}
|
|
||||||
className={`flex items-center gap-1.5 rounded px-2.5 py-1 text-[12px] font-medium transition whitespace-nowrap ${
|
|
||||||
mode === opt.id
|
|
||||||
? 'bg-white text-slate-900 shadow-sm ring-1 ring-slate-200'
|
|
||||||
: 'text-slate-500 hover:text-slate-700'
|
|
||||||
}`}
|
|
||||||
>
|
|
||||||
{opt.label}
|
|
||||||
</button>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -1,320 +0,0 @@
|
|||||||
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 = {
|
|
||||||
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' },
|
|
||||||
PAYMENT_REVERTED:{ label: 'Αναίρεση Πληρωμής', bg: '#fffbeb', text: '#b45309' },
|
|
||||||
}
|
|
||||||
|
|
||||||
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, priceEventsMap = {} }) {
|
|
||||||
const itemsFiltered = order.items || []
|
|
||||||
const billableItems = itemsFiltered.filter(i => i.status !== 'cancelled')
|
|
||||||
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>
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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 */}
|
|
||||||
<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'
|
|
||||||
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={{ 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', 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: 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 */}
|
|
||||||
<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: hasPriceAdj ? '#3b82f6' : '#111315', textAlign: 'right', fontFamily: 'ui-monospace,monospace', paddingTop: 2 }}>
|
|
||||||
{fmtEUR(effPrice(item) * item.quantity)}
|
|
||||||
</div>
|
|
||||||
</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')
|
|
||||||
|
|
||||||
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]))
|
|
||||||
|
|
||||||
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} priceEventsMap={priceEventsMap} />}
|
|
||||||
{tab === 'audit' && <AuditTimeline logs={order.audit_logs} itemsById={itemsById} />}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -1,431 +0,0 @@
|
|||||||
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'
|
|
||||||
|
|
||||||
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')
|
|
||||||
return { key: 'cancelled', label: 'Ακυρώθηκε', dot: '#dc2626', bg: '#fef2f2', border: '#fecaca', text: '#991b1b' }
|
|
||||||
|
|
||||||
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' }
|
|
||||||
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: 'Ανοιχτό ακόμη' },
|
|
||||||
{ key: 'cancelled', label: 'Ακυρώθηκε' },
|
|
||||||
{ key: 'anomaly', label: 'Πρόβλημα' },
|
|
||||||
]
|
|
||||||
|
|
||||||
const LEGEND = [
|
|
||||||
{ dot: '#16a34a', label: 'Πλήρης Παραγγελία' },
|
|
||||||
{ dot: '#2563eb', label: 'Μόνο Πληρώθηκε' },
|
|
||||||
{ dot: '#ca8a04', label: 'Μόνο Παρήγγειλε' },
|
|
||||||
{ dot: '#ea580c', label: 'Ανοιχτό ακόμη' },
|
|
||||||
{ dot: '#dc2626', 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)
|
|
||||||
const isCancelled = item.status === 'cancelled'
|
|
||||||
return (
|
|
||||||
<div style={{
|
|
||||||
display: 'flex', alignItems: 'flex-start', gap: 10, padding: '7px 14px',
|
|
||||||
borderTop: '1px solid #f4f4f2', background: c.bg,
|
|
||||||
}}>
|
|
||||||
<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: isCancelled ? '#991b1b' : '#111315' }}>
|
|
||||||
{item.product_name}
|
|
||||||
<span style={{ fontWeight: 400, color: '#8a9099', marginLeft: 4 }}>×{item.quantity}</span>
|
|
||||||
</span>
|
|
||||||
<span style={{ fontSize: 13, fontWeight: 700, color: isCancelled ? '#b91c1c' : '#111315', flexShrink: 0, textDecoration: isCancelled ? 'line-through' : 'none' }}>
|
|
||||||
{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>
|
|
||||||
{!isCancelled && (
|
|
||||||
<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' }}>
|
|
||||||
<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,
|
|
||||||
})
|
|
||||||
|
|
||||||
const counts = { all: 0, both: 0, paid: 0, ordered: 0, unpaid: 0, cancelled: 0, anomaly: 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: 1080,
|
|
||||||
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 grid — 2 rows × 4 cols */}
|
|
||||||
{(() => {
|
|
||||||
const totalOrders = summary.orders?.length ?? 0
|
|
||||||
const durationHours = summary.duration_hours ?? (summary.duration_minutes != null ? summary.duration_minutes / 60 : null)
|
|
||||||
const durationLabel = durationHours != null
|
|
||||||
? (() => { const h = Math.floor(durationHours); const m = Math.round((durationHours - h) * 60); return h > 0 ? `${h}ω ${m}λ` : `${m}λ` })()
|
|
||||||
: fmtMins(summary.duration_minutes)
|
|
||||||
const row1 = [
|
|
||||||
{ label: 'Διάρκεια Βάρδιας', value: durationLabel },
|
|
||||||
{ label: 'Μισθός / Ώρα', value: summary.hourly_rate_snapshot != null ? fmtEUR(summary.hourly_rate_snapshot) : '—' },
|
|
||||||
{ label: 'Πληρωμή Βάρδιας', value: summary.shift_pay != null ? fmtEUR(summary.shift_pay) : 'Δεν παρακολουθείται', accent: summary.shift_pay != null ? '#059669' : undefined },
|
|
||||||
{ label: 'Αρχικά Μετρητά', value: summary.starting_cash != null ? fmtEUR(summary.starting_cash) : '—' },
|
|
||||||
]
|
|
||||||
const discrepancy = summary.cash_discrepancy
|
|
||||||
const discLabel = discrepancy == null
|
|
||||||
? '—'
|
|
||||||
: Math.abs(discrepancy) < 0.005
|
|
||||||
? '✓ Εντάξει'
|
|
||||||
: discrepancy < 0
|
|
||||||
? `Έλλειμμα ${fmtEUR(Math.abs(discrepancy))}`
|
|
||||||
: `Πλεόνασμα +${fmtEUR(discrepancy)}`
|
|
||||||
const discAccent = discrepancy == null
|
|
||||||
? undefined
|
|
||||||
: 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: collectLabel, accent: '#2f9e5e' },
|
|
||||||
{
|
|
||||||
label: 'Ακυρώσεις',
|
|
||||||
value: cancelEvents > 0 ? `${cancelEvents} / ${cancelItemsQty} είδη` : '—',
|
|
||||||
accent: cancelEvents > 0 ? '#dc2626' : undefined,
|
|
||||||
},
|
|
||||||
{ label: 'Ταμείο', value: discLabel, accent: discAccent },
|
|
||||||
]
|
|
||||||
return (
|
|
||||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 6, padding: '14px 24px', borderBottom: '1px solid #edeff1', flexShrink: 0 }}>
|
|
||||||
{[row1, row2].map((row, ri) => (
|
|
||||||
<div key={ri} style={{ display: 'grid', gridTemplateColumns: 'repeat(4,1fr)', gap: 6 }}>
|
|
||||||
{row.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: 16, fontWeight: 700, color: k.accent || '#111315', fontFamily: 'ui-monospace,monospace', marginTop: 4 }}>{k.value}</div>
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</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 */}
|
|
||||||
<div style={{ display: 'flex', gap: 6, padding: '10px 24px', borderBottom: '1px solid #edeff1', flexShrink: 0, overflowX: 'auto' }}>
|
|
||||||
{FILTER_OPTIONS.map(opt => {
|
|
||||||
const isCancelOpt = opt.key === 'cancelled'
|
|
||||||
const isActive = activeFilter === opt.key
|
|
||||||
return (
|
|
||||||
<button
|
|
||||||
key={opt.key}
|
|
||||||
onClick={() => setActiveFilter(opt.key)}
|
|
||||||
style={{
|
|
||||||
padding: '4px 12px', borderRadius: 20, fontSize: 12, fontWeight: 600, cursor: 'pointer', whiteSpace: 'nowrap',
|
|
||||||
border: isActive
|
|
||||||
? isCancelOpt ? '1.5px solid #dc2626' : '1.5px solid #3758c9'
|
|
||||||
: '1.5px solid #e5e7eb',
|
|
||||||
background: isActive
|
|
||||||
? isCancelOpt ? '#fef2f2' : '#eff6ff'
|
|
||||||
: 'white',
|
|
||||||
color: isActive
|
|
||||||
? isCancelOpt ? '#991b1b' : '#3758c9'
|
|
||||||
: '#5a6169',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{opt.label}
|
|
||||||
{counts[opt.key] > 0 && (
|
|
||||||
<span style={{
|
|
||||||
marginLeft: 5, padding: '1px 5px', borderRadius: 8, fontSize: 10,
|
|
||||||
background: isActive
|
|
||||||
? isCancelOpt ? '#dc2626' : '#3758c9'
|
|
||||||
: '#e5e7eb',
|
|
||||||
color: isActive ? '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,30 +0,0 @@
|
|||||||
export default function SkeletonTable({ rows = 8, columns = 5, showChart = false }) {
|
|
||||||
return (
|
|
||||||
<div className="space-y-4">
|
|
||||||
{showChart && (
|
|
||||||
<div className="overflow-hidden rounded-lg border border-slate-200 bg-white p-5 shadow-[0_1px_0_rgba(15,23,42,0.04)]">
|
|
||||||
<div className="mb-3 h-4 w-40 rounded bg-slate-200 animate-pulse" />
|
|
||||||
<div className="h-52 rounded bg-slate-100 animate-pulse" />
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
<div className="overflow-hidden rounded-lg border border-slate-200 bg-white shadow-[0_1px_0_rgba(15,23,42,0.04)]">
|
|
||||||
<div className="border-b border-slate-100 px-5 py-3">
|
|
||||||
<div className="h-4 w-32 rounded bg-slate-200 animate-pulse" />
|
|
||||||
</div>
|
|
||||||
<div className="divide-y divide-slate-100">
|
|
||||||
{Array.from({ length: rows }).map((_, i) => (
|
|
||||||
<div key={i} className="flex items-center gap-4 px-5 py-3">
|
|
||||||
{Array.from({ length: columns }).map((_, j) => (
|
|
||||||
<div
|
|
||||||
key={j}
|
|
||||||
className="h-3 rounded bg-slate-100 animate-pulse"
|
|
||||||
style={{ width: `${60 + ((i * 7 + j * 13) % 40)}px`, animationDelay: `${(i + j) * 50}ms` }}
|
|
||||||
/>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
export default function StatCard({ label, value, sub, icon: Icon, accent, size = 'md' }) {
|
|
||||||
const sizes = {
|
|
||||||
sm: { val: 'text-2xl', pad: 'p-4' },
|
|
||||||
md: { val: 'text-[28px]', pad: 'p-5' },
|
|
||||||
lg: { val: 'text-4xl', pad: 'p-6' },
|
|
||||||
}
|
|
||||||
const s = sizes[size] || sizes.md
|
|
||||||
return (
|
|
||||||
<div className={`relative overflow-hidden rounded-lg border border-slate-200 bg-white ${s.pad} shadow-[0_1px_0_rgba(15,23,42,0.04)]`}>
|
|
||||||
<div className="flex items-start justify-between">
|
|
||||||
<div className="text-[11px] font-medium uppercase tracking-[0.1em] text-slate-500">{label}</div>
|
|
||||||
{Icon && <Icon className="h-4 w-4 text-slate-300" />}
|
|
||||||
</div>
|
|
||||||
<div className={`mt-2 font-mono ${s.val} font-medium tabular-nums tracking-tight ${accent ? 'text-sky-600' : 'text-slate-900'}`}>
|
|
||||||
{value ?? '—'}
|
|
||||||
</div>
|
|
||||||
{sub && <div className="mt-1 text-[12px] text-slate-500">{sub}</div>}
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -1,136 +0,0 @@
|
|||||||
import { STATUS_STYLES, avatarColor } from '../../../ui/tokens'
|
|
||||||
|
|
||||||
export function Panel({ title, subtitle, right, children, padded = true }) {
|
|
||||||
return (
|
|
||||||
<div className="overflow-hidden rounded-lg border border-slate-200 bg-white shadow-[0_1px_0_rgba(15,23,42,0.04)]">
|
|
||||||
{(title || right) && (
|
|
||||||
<div className="flex items-center justify-between border-b border-slate-100 px-5 py-3">
|
|
||||||
<div>
|
|
||||||
{title && <div className="text-[13px] font-semibold text-slate-900">{title}</div>}
|
|
||||||
{subtitle && <div className="text-[12px] text-slate-500">{subtitle}</div>}
|
|
||||||
</div>
|
|
||||||
{right}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
<div className={padded ? 'p-5' : ''}>{children}</div>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export function DataTable({ children, className = '' }) {
|
|
||||||
return (
|
|
||||||
<div className={`overflow-auto ${className}`}>
|
|
||||||
<table className="w-full border-separate border-spacing-0 text-[13px]">
|
|
||||||
{children}
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export function THead({ children }) {
|
|
||||||
return (
|
|
||||||
<thead className="sticky top-0 z-10 bg-slate-50/95 backdrop-blur">
|
|
||||||
<tr>{children}</tr>
|
|
||||||
</thead>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export function TH({ children, className = '', align = 'left' }) {
|
|
||||||
return (
|
|
||||||
<th className={`border-b border-slate-200 px-4 py-2.5 text-${align} text-[10px] font-semibold uppercase tracking-[0.08em] text-slate-500 ${className}`}>
|
|
||||||
{children}
|
|
||||||
</th>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export function TR({ children, onClick, highlight, striped, className = '' }) {
|
|
||||||
return (
|
|
||||||
<tr
|
|
||||||
onClick={onClick}
|
|
||||||
className={`group ${striped ? 'odd:bg-white even:bg-slate-50/40' : 'bg-white'} ${
|
|
||||||
onClick ? 'cursor-pointer' : ''
|
|
||||||
} hover:bg-sky-50/40 transition-colors ${highlight ? 'bg-sky-50/30' : ''} ${className}`}
|
|
||||||
>
|
|
||||||
{children}
|
|
||||||
</tr>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export function TD({ children, className = '', mono, align = 'left', colSpan }) {
|
|
||||||
return (
|
|
||||||
<td
|
|
||||||
colSpan={colSpan}
|
|
||||||
className={`border-b border-slate-100 px-4 py-2.5 text-${align} text-slate-700 ${mono ? 'font-mono tabular-nums' : ''} ${className}`}
|
|
||||||
>
|
|
||||||
{children}
|
|
||||||
</td>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export function StatusBadge({ status, pulse }) {
|
|
||||||
const s = STATUS_STYLES[status] || STATUS_STYLES.closed
|
|
||||||
const label = status ? status.replace('_', ' ').replace('-', ' ') : 'unknown'
|
|
||||||
return (
|
|
||||||
<span className={`inline-flex items-center gap-1.5 rounded-full px-2 py-0.5 text-[10px] font-mono uppercase tracking-[0.08em] ring-1 ring-inset ${s.bg} ${s.text} ${s.ring}`}>
|
|
||||||
<span className={`relative inline-block h-1.5 w-1.5 rounded-full ${s.dot}`}>
|
|
||||||
{pulse && (status === 'active' || status === 'open') && (
|
|
||||||
<span className={`absolute inset-0 rounded-full ${s.dot} animate-ping opacity-75`} />
|
|
||||||
)}
|
|
||||||
</span>
|
|
||||||
{label}
|
|
||||||
</span>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export function WaiterAvatar({ name, id }) {
|
|
||||||
const cls = avatarColor(id ?? name ?? '0')
|
|
||||||
const initials = name
|
|
||||||
? name.split(' ').map(p => p[0]).slice(0, 2).join('').toUpperCase()
|
|
||||||
: '?'
|
|
||||||
return (
|
|
||||||
<div className="flex items-center gap-2.5">
|
|
||||||
<div className={`flex h-7 w-7 items-center justify-center rounded-full text-[11px] font-semibold flex-shrink-0 ${cls}`}>
|
|
||||||
{initials}
|
|
||||||
</div>
|
|
||||||
<span className="font-medium text-slate-900">{name || '—'}</span>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export function ChartTooltip({ active, payload, label, formatter, labelFormatter }) {
|
|
||||||
if (!active || !payload?.length) return null
|
|
||||||
return (
|
|
||||||
<div className="rounded-md border border-slate-200 bg-white px-3 py-2 text-[12px] shadow-lg">
|
|
||||||
{label != null && (
|
|
||||||
<div className="mb-1 text-[11px] font-medium uppercase tracking-wider text-slate-500">
|
|
||||||
{labelFormatter ? labelFormatter(label) : label}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
{payload.map((p, i) => (
|
|
||||||
<div key={i} className="flex items-center gap-2">
|
|
||||||
<span className="h-2 w-2 rounded-sm flex-shrink-0" style={{ backgroundColor: p.color || p.fill }} />
|
|
||||||
<span className="text-slate-600">{p.name}:</span>
|
|
||||||
<span className="font-mono font-medium text-slate-900 tabular-nums">
|
|
||||||
{formatter ? formatter(p.value, p.name) : p.value}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export function ErrorState({ message, onRetry }) {
|
|
||||||
return (
|
|
||||||
<div className="flex min-h-[200px] flex-col items-center justify-center gap-3 px-6 py-10 text-center">
|
|
||||||
<div className="text-[13px] text-slate-600">{message || 'Something went wrong'}</div>
|
|
||||||
{onRetry && (
|
|
||||||
<button
|
|
||||||
onClick={onRetry}
|
|
||||||
className="rounded-md border border-slate-200 bg-white px-3 py-1.5 text-[12px] font-medium text-slate-700 hover:bg-slate-50"
|
|
||||||
>
|
|
||||||
Retry
|
|
||||||
</button>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
// Re-export shim — all tokens have moved to src/ui/tokens.js.
|
|
||||||
// Existing report subpage imports continue to work unchanged.
|
|
||||||
export * from '../../../ui/tokens'
|
|
||||||
@@ -1,275 +0,0 @@
|
|||||||
import { useState, useMemo } from 'react'
|
|
||||||
import { useQuery } from '@tanstack/react-query'
|
|
||||||
import {
|
|
||||||
BarChart, Bar, XAxis, YAxis, CartesianGrid, Tooltip,
|
|
||||||
ResponsiveContainer, Legend, ComposedChart, Line,
|
|
||||||
} from 'recharts'
|
|
||||||
import client from '../../../api/client'
|
|
||||||
import { FilterBar, FilterSelect, FilterDateInput, WorkDayDateToggle } from '../shared/FilterBar'
|
|
||||||
import { Panel, DataTable, THead, TH, TR, TD, WaiterAvatar } from '../shared/TablePrimitives'
|
|
||||||
import EmptyState from '../shared/EmptyState'
|
|
||||||
import SkeletonTable from '../shared/SkeletonTable'
|
|
||||||
import { fmtEUR, fmtNum, 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) }
|
|
||||||
|
|
||||||
const METRICS = [
|
|
||||||
{ key: 'orders', label: 'ΠΑΡΑΓΓΕΛΙΕΣ', color: '#60a5fa' },
|
|
||||||
{ key: 'items', label: 'ΕΙΔΗ', color: '#34d399' },
|
|
||||||
{ key: 'cancellations', label: 'ΑΚΥΡΩΣΕΙΣ', color: '#f87171' },
|
|
||||||
{ key: 'total', label: 'ΕΣΟΔΑ', color: '#a78bfa' },
|
|
||||||
{ key: 'hours_worked', label: 'ΩΡΕΣ', color: '#fb923c', rightAxis: true },
|
|
||||||
]
|
|
||||||
|
|
||||||
function fmtHours(h) {
|
|
||||||
if (h == null) return '—'
|
|
||||||
const hrs = Math.floor(h)
|
|
||||||
const mins = Math.round((h - hrs) * 60)
|
|
||||||
if (mins === 0) return `${hrs}ω`
|
|
||||||
return `${hrs}ω ${mins}λ`
|
|
||||||
}
|
|
||||||
|
|
||||||
function CustomTooltip({ active, payload, label }) {
|
|
||||||
if (!active || !payload?.length) return null
|
|
||||||
return (
|
|
||||||
<div style={{
|
|
||||||
background: '#fff', border: '1px solid #e2e8f0', borderRadius: 8,
|
|
||||||
padding: '10px 14px', fontSize: 12, boxShadow: '0 4px 12px rgba(0,0,0,0.08)',
|
|
||||||
minWidth: 160,
|
|
||||||
}}>
|
|
||||||
<div style={{ fontWeight: 700, color: '#1e293b', marginBottom: 6 }}>{label}</div>
|
|
||||||
{payload.map(p => (
|
|
||||||
<div key={p.dataKey} style={{ display: 'flex', justifyContent: 'space-between', gap: 16, color: '#475569', marginBottom: 2 }}>
|
|
||||||
<span style={{ color: p.color, fontWeight: 600 }}>{p.name}</span>
|
|
||||||
<span style={{ fontWeight: 600, color: '#1e293b' }}>
|
|
||||||
{p.dataKey === 'total' ? fmtEUR(p.value)
|
|
||||||
: p.dataKey === 'hours_worked' ? fmtHours(p.value)
|
|
||||||
: fmtNum(p.value)}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function Activity() {
|
|
||||||
const [waiterId, setWaiterId] = useState('all')
|
|
||||||
const [mode, setMode] = useState('range')
|
|
||||||
const [from, setFrom] = useState(monthAgo())
|
|
||||||
const [to, setTo] = useState(today())
|
|
||||||
const [businessDayId, setBusinessDayId] = useState('all')
|
|
||||||
const [activeMetrics, setActiveMetrics] = useState(new Set(['orders', 'items', 'cancellations', 'total']))
|
|
||||||
const [stacked, setStacked] = useState(false)
|
|
||||||
|
|
||||||
const { data: waitersData } = useQuery({ queryKey: ['meta-waiters'], queryFn: () => client.get('/api/reports/meta/waiters').then(r => r.data), 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 queryParams = {
|
|
||||||
...(waiterId !== 'all' ? { waiter_id: waiterId } : {}),
|
|
||||||
...(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: ['shifts-activity', waiterId, mode, from, to, businessDayId],
|
|
||||||
queryFn: () => client.get('/api/reports/shift/orders', { params: queryParams }).then(r => r.data),
|
|
||||||
staleTime: 60 * 1000,
|
|
||||||
})
|
|
||||||
|
|
||||||
const waiterOptions = [{ value: 'all', label: 'Όλοι οι Σερβιτόροι' }, ...((waitersData?.waiters || []).map(w => ({ value: String(w.id), label: w.name })))]
|
|
||||||
const bdOptions = [{ value: 'all', label: 'Όλες οι Εργάσιμες Μέρες' }, ...((bdData?.business_days || []).map(bd => ({ value: String(bd.id), label: `${fmtDate(bd.opened_at)} · ${fmtTime(bd.opened_at)}` })))]
|
|
||||||
|
|
||||||
const waiters = data?.waiters || []
|
|
||||||
|
|
||||||
const chartData = useMemo(() => waiters.map(w => ({
|
|
||||||
name: w.waiter_name || `#${w.waiter_id}`,
|
|
||||||
shortName: (w.waiter_name || '').split(' ')[0] || `#${w.waiter_id}`,
|
|
||||||
orders: w.orders || 0,
|
|
||||||
items: w.items || 0,
|
|
||||||
cancellations: w.cancellations || 0,
|
|
||||||
total: Math.round((w.total || 0) * 100) / 100,
|
|
||||||
hours_worked: w.hours_worked || 0,
|
|
||||||
})), [waiters])
|
|
||||||
|
|
||||||
function toggleMetric(key) {
|
|
||||||
setActiveMetrics(prev => {
|
|
||||||
const next = new Set(prev)
|
|
||||||
if (next.has(key)) { if (next.size > 1) next.delete(key) }
|
|
||||||
else next.add(key)
|
|
||||||
return next
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
const showRightAxis = activeMetrics.has('hours_worked')
|
|
||||||
const leftMetrics = METRICS.filter(m => !m.rightAxis && activeMetrics.has(m.key))
|
|
||||||
const hasRevenue = activeMetrics.has('total')
|
|
||||||
|
|
||||||
if (isLoading) return <div className="flex-1 overflow-y-auto p-6"><SkeletonTable rows={5} columns={7} showChart /></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={waiterId} onChange={setWaiterId} options={waiterOptions} label="Σερβιτόρος" />
|
|
||||||
<WorkDayDateToggle mode={mode} onChange={setMode} />
|
|
||||||
{mode === 'workday' ? (
|
|
||||||
<FilterSelect value={businessDayId} onChange={setBusinessDayId} options={bdOptions} width="w-72" label="Μέρα" />
|
|
||||||
) : (
|
|
||||||
<>
|
|
||||||
<FilterDateInput value={from} onChange={setFrom} label="Από" />
|
|
||||||
<FilterDateInput value={to} onChange={setTo} label="Έως" />
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</FilterBar>
|
|
||||||
|
|
||||||
<div className="flex-1 overflow-y-auto p-6">
|
|
||||||
{waiters.length > 0 && (
|
|
||||||
<Panel
|
|
||||||
title="Δραστηριότητα ανά Σερβιτόρο"
|
|
||||||
subtitle="Επιλέξτε μετρικές και τύπο γραφήματος"
|
|
||||||
right={
|
|
||||||
<div className="flex items-center gap-1 rounded-md border border-slate-200 p-0.5 bg-slate-50">
|
|
||||||
<button
|
|
||||||
onClick={() => setStacked(false)}
|
|
||||||
className={`rounded px-2.5 py-1 text-[11px] font-semibold transition-colors ${!stacked ? 'bg-white text-slate-800 shadow-sm' : 'text-slate-500 hover:text-slate-700'}`}
|
|
||||||
>
|
|
||||||
Ομαδοποίηση
|
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
onClick={() => setStacked(true)}
|
|
||||||
className={`rounded px-2.5 py-1 text-[11px] font-semibold transition-colors ${stacked ? 'bg-white text-slate-800 shadow-sm' : 'text-slate-500 hover:text-slate-700'}`}
|
|
||||||
>
|
|
||||||
Στοίβαγμα
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
>
|
|
||||||
{/* Metric checkboxes */}
|
|
||||||
<div className="flex flex-wrap gap-2 mb-4">
|
|
||||||
{METRICS.map(m => {
|
|
||||||
const active = activeMetrics.has(m.key)
|
|
||||||
return (
|
|
||||||
<button
|
|
||||||
key={m.key}
|
|
||||||
onClick={() => toggleMetric(m.key)}
|
|
||||||
className="flex items-center gap-1.5 rounded-full border px-3 py-1 text-[11px] font-bold uppercase tracking-wider transition-all"
|
|
||||||
style={{
|
|
||||||
borderColor: active ? m.color : '#e2e8f0',
|
|
||||||
background: active ? m.color + '18' : 'transparent',
|
|
||||||
color: active ? m.color : '#94a3b8',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<span
|
|
||||||
style={{
|
|
||||||
width: 8, height: 8, borderRadius: '50%',
|
|
||||||
background: active ? m.color : '#cbd5e1', flexShrink: 0,
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
{m.label}
|
|
||||||
</button>
|
|
||||||
)
|
|
||||||
})}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div style={{ height: 260 }}>
|
|
||||||
<ResponsiveContainer width="100%" height="100%">
|
|
||||||
<ComposedChart data={chartData} layout="vertical" margin={{ top: 4, right: showRightAxis ? 60 : 24, bottom: 4, left: 8 }}>
|
|
||||||
<CartesianGrid horizontal={false} stroke="#f1f5f9" />
|
|
||||||
<XAxis
|
|
||||||
type="number"
|
|
||||||
tick={{ fontSize: 11, fill: '#94a3b8' }}
|
|
||||||
stroke="#cbd5e1" axisLine={false} tickLine={false}
|
|
||||||
tickFormatter={v => hasRevenue && leftMetrics.length === 1 ? `€${v}` : v}
|
|
||||||
/>
|
|
||||||
{showRightAxis && (
|
|
||||||
<XAxis
|
|
||||||
xAxisId="right"
|
|
||||||
type="number"
|
|
||||||
orientation="top"
|
|
||||||
tick={{ fontSize: 11, fill: '#fb923c' }}
|
|
||||||
stroke="#fed7aa" axisLine={false} tickLine={false}
|
|
||||||
tickFormatter={v => `${v}ω`}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
<YAxis
|
|
||||||
type="category"
|
|
||||||
dataKey="name"
|
|
||||||
tick={{ fontSize: 12, fill: '#475569' }}
|
|
||||||
stroke="#cbd5e1" axisLine={false} tickLine={false}
|
|
||||||
width={90}
|
|
||||||
tickFormatter={v => v.length > 12 ? v.slice(0, 11) + '…' : v}
|
|
||||||
/>
|
|
||||||
<Tooltip content={<CustomTooltip />} cursor={{ fill: '#f1f5f9' }} />
|
|
||||||
{METRICS.filter(m => !m.rightAxis && activeMetrics.has(m.key)).map(m => (
|
|
||||||
<Bar
|
|
||||||
key={m.key}
|
|
||||||
dataKey={m.key}
|
|
||||||
name={m.label}
|
|
||||||
fill={m.color}
|
|
||||||
radius={stacked ? 0 : [0, 3, 3, 0]}
|
|
||||||
barSize={stacked ? 20 : 10}
|
|
||||||
stackId={stacked ? 'stack' : undefined}
|
|
||||||
/>
|
|
||||||
))}
|
|
||||||
{activeMetrics.has('hours_worked') && (
|
|
||||||
<Bar
|
|
||||||
key="hours_worked"
|
|
||||||
xAxisId="right"
|
|
||||||
dataKey="hours_worked"
|
|
||||||
name="ΩΡΕΣ"
|
|
||||||
fill="#fb923c"
|
|
||||||
radius={[0, 3, 3, 0]}
|
|
||||||
barSize={6}
|
|
||||||
opacity={0.7}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</ComposedChart>
|
|
||||||
</ResponsiveContainer>
|
|
||||||
</div>
|
|
||||||
</Panel>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<div className="mt-4">
|
|
||||||
<Panel title="Δραστηριότητα ανά Σερβιτόρο" padded={false}>
|
|
||||||
{waiters.length === 0 ? (
|
|
||||||
<EmptyState title="Δεν βρέθηκε δραστηριότητα" description="Δεν υπάρχουν παραγγελίες στην επιλεγμένη περίοδο." />
|
|
||||||
) : (
|
|
||||||
<DataTable>
|
|
||||||
<THead>
|
|
||||||
<TH>Σερβιτόρος</TH>
|
|
||||||
<TH align="right">Παραγγελίες</TH>
|
|
||||||
<TH align="right">Είδη</TH>
|
|
||||||
<TH align="right">Ακυρώσεις</TH>
|
|
||||||
<TH align="right">Ώρες</TH>
|
|
||||||
<TH align="right">Συνολική Αξία</TH>
|
|
||||||
</THead>
|
|
||||||
<tbody>
|
|
||||||
{[...waiters].sort((a, b) => (b.total || 0) - (a.total || 0)).map(w => (
|
|
||||||
<TR key={w.waiter_id} striped>
|
|
||||||
<TD><WaiterAvatar name={w.waiter_name} id={w.waiter_id} /></TD>
|
|
||||||
<TD mono align="right">{fmtNum(w.orders)}</TD>
|
|
||||||
<TD mono align="right">{fmtNum(w.items)}</TD>
|
|
||||||
<TD mono align="right">
|
|
||||||
{w.cancellations > 0
|
|
||||||
? <span className="text-red-500 font-semibold">{fmtNum(w.cancellations)}</span>
|
|
||||||
: <span className="text-slate-300">—</span>}
|
|
||||||
</TD>
|
|
||||||
<TD mono align="right">{fmtHours(w.hours_worked)}</TD>
|
|
||||||
<TD mono align="right" className="font-semibold text-slate-900">{fmtEUR(w.total)}</TD>
|
|
||||||
</TR>
|
|
||||||
))}
|
|
||||||
</tbody>
|
|
||||||
</DataTable>
|
|
||||||
)}
|
|
||||||
</Panel>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -1,125 +0,0 @@
|
|||||||
import { useState } from 'react'
|
|
||||||
import { useQuery } from '@tanstack/react-query'
|
|
||||||
import { Wallet, HandCoins, Coins } from 'lucide-react'
|
|
||||||
import client from '../../../api/client'
|
|
||||||
import { FilterBar, FilterSelect, FilterDateInput, WorkDayDateToggle } from '../shared/FilterBar'
|
|
||||||
import { Panel, DataTable, THead, TH, TR, TD, StatusBadge, WaiterAvatar } from '../shared/TablePrimitives'
|
|
||||||
import StatCard from '../shared/StatCard'
|
|
||||||
import EmptyState from '../shared/EmptyState'
|
|
||||||
import SkeletonTable from '../shared/SkeletonTable'
|
|
||||||
import ExportButton from '../shared/ExportButton'
|
|
||||||
import { fmtEUR, 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 Payments() {
|
|
||||||
const [waiterId, setWaiterId] = useState('all')
|
|
||||||
const [mode, setMode] = useState('range')
|
|
||||||
const [from, setFrom] = useState(monthAgo())
|
|
||||||
const [to, setTo] = useState(today())
|
|
||||||
const [businessDayId, setBusinessDayId] = useState('all')
|
|
||||||
|
|
||||||
const { data: waitersData } = useQuery({ queryKey: ['meta-waiters'], queryFn: () => client.get('/api/reports/meta/waiters').then(r => r.data), 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 queryParams = {
|
|
||||||
...(waiterId !== 'all' ? { waiter_id: waiterId } : {}),
|
|
||||||
...(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: ['shifts-payments', waiterId, mode, from, to, businessDayId],
|
|
||||||
queryFn: () => client.get('/api/reports/shifts', { params: queryParams }).then(r => r.data),
|
|
||||||
staleTime: 60 * 1000,
|
|
||||||
})
|
|
||||||
|
|
||||||
const waiterOptions = [{ value: 'all', label: 'Όλοι οι Σερβιτόροι' }, ...((waitersData?.waiters || []).map(w => ({ value: String(w.id), label: w.name })))]
|
|
||||||
const bdOptions = [{ value: 'all', label: 'Όλες οι Εργάσιμες Μέρες' }, ...((bdData?.business_days || []).map(bd => ({ value: String(bd.id), label: `${fmtDate(bd.opened_at)} · ${fmtTime(bd.opened_at)}` })))]
|
|
||||||
|
|
||||||
const shifts = data?.shifts || []
|
|
||||||
const totals = shifts.reduce((acc, s) => {
|
|
||||||
acc.starting += s.starting_cash || 0
|
|
||||||
acc.collected += s.total_collected || 0
|
|
||||||
acc.owed += s.net_to_deliver || 0
|
|
||||||
return acc
|
|
||||||
}, { starting: 0, collected: 0, owed: 0 })
|
|
||||||
|
|
||||||
if (isLoading) return <div className="flex-1 overflow-y-auto p-6"><SkeletonTable rows={6} columns={5} /></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 text-slate-700 hover:bg-slate-50">Επανάληψη</button></div>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="flex flex-col flex-1 min-h-0">
|
|
||||||
<FilterBar right={
|
|
||||||
<ExportButton
|
|
||||||
endpoint="/api/reports/shifts/export"
|
|
||||||
params={queryParams}
|
|
||||||
filename={`shift-payments-${from}-to-${to}.csv`}
|
|
||||||
/>
|
|
||||||
}>
|
|
||||||
<FilterSelect value={waiterId} onChange={setWaiterId} options={waiterOptions} label="Σερβιτόρος" />
|
|
||||||
<WorkDayDateToggle mode={mode} onChange={setMode} />
|
|
||||||
{mode === 'workday' ? (
|
|
||||||
<FilterSelect value={businessDayId} onChange={setBusinessDayId} options={bdOptions} width="w-72" label="Μέρα" />
|
|
||||||
) : (
|
|
||||||
<>
|
|
||||||
<FilterDateInput value={from} onChange={setFrom} label="Από" />
|
|
||||||
<FilterDateInput value={to} onChange={setTo} label="Έως" />
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</FilterBar>
|
|
||||||
|
|
||||||
<div className="flex-1 overflow-y-auto p-6">
|
|
||||||
<div className="mb-4 grid grid-cols-3 gap-4">
|
|
||||||
<StatCard label="Αρχικά Μετρητά" value={fmtEUR(totals.starting)} sub={`σε ${shifts.length} βάρδιες`} icon={Wallet} />
|
|
||||||
<StatCard label="Συνολικές Εισπράξεις" value={fmtEUR(totals.collected)} sub="από πληρωμένες παραγγελίες" icon={HandCoins} />
|
|
||||||
<StatCard label="Οφείλεται στον Διαχειριστή" value={fmtEUR(totals.owed)} sub="προς εκκαθάριση" icon={Coins} accent />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<Panel title="Εκκαθάριση ανά Βάρδια" padded={false}>
|
|
||||||
{shifts.length === 0 ? (
|
|
||||||
<EmptyState title="Δεν υπάρχει τίποτα" description="Δεν υπάρχουν βάρδιες στην επιλεγμένη περίοδο." />
|
|
||||||
) : (
|
|
||||||
<DataTable>
|
|
||||||
<THead>
|
|
||||||
<TH>Σερβιτόρος</TH>
|
|
||||||
<TH>Βάρδια</TH>
|
|
||||||
<TH align="right">Αρχικά Μετρητά</TH>
|
|
||||||
<TH align="right">Εισπράχθηκαν</TH>
|
|
||||||
<TH align="right">Σύνολο στην Τσέπη</TH>
|
|
||||||
<TH>Κατάσταση</TH>
|
|
||||||
</THead>
|
|
||||||
<tbody>
|
|
||||||
{shifts.map(s => (
|
|
||||||
<TR key={s.id} highlight={s.is_active} striped>
|
|
||||||
<TD><WaiterAvatar name={s.waiter_name} id={s.waiter_id} /></TD>
|
|
||||||
<TD mono className="text-slate-500">
|
|
||||||
{fmtDate(s.started_at)} · {fmtTime(s.started_at)}–{s.ended_at ? fmtTime(s.ended_at) : 'now'}
|
|
||||||
</TD>
|
|
||||||
<TD mono align="right">{fmtEUR(s.starting_cash)}</TD>
|
|
||||||
<TD mono align="right">{fmtEUR(s.total_collected)}</TD>
|
|
||||||
<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>
|
|
||||||
</TR>
|
|
||||||
))}
|
|
||||||
<tr className="bg-slate-50">
|
|
||||||
<TD colSpan={2} className="py-3 text-[11px] font-semibold uppercase tracking-wider text-slate-500">Σύνολα</TD>
|
|
||||||
<TD mono align="right" className="py-3 font-semibold text-slate-900">{fmtEUR(totals.starting)}</TD>
|
|
||||||
<TD mono align="right" className="py-3 font-semibold text-slate-900">{fmtEUR(totals.collected)}</TD>
|
|
||||||
<TD mono align="right" className="py-3 text-base font-semibold text-sky-700">{fmtEUR(totals.owed)}</TD>
|
|
||||||
<TD />
|
|
||||||
</tr>
|
|
||||||
</tbody>
|
|
||||||
</DataTable>
|
|
||||||
)}
|
|
||||||
</Panel>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -1,277 +0,0 @@
|
|||||||
import { useState } from 'react'
|
|
||||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
|
|
||||||
import { UserRoundX, ChevronRight, ExternalLink, Trash2, Eye } 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'
|
|
||||||
import { Panel, DataTable, THead, TH, TR, TD, StatusBadge, WaiterAvatar, ChartTooltip } from '../shared/TablePrimitives'
|
|
||||||
import StatCard from '../shared/StatCard'
|
|
||||||
import EmptyState from '../shared/EmptyState'
|
|
||||||
import SkeletonTable from '../shared/SkeletonTable'
|
|
||||||
import ExportButton from '../shared/ExportButton'
|
|
||||||
import { fmtEUR, fmtDateTime, fmtDuration, fmtDate, fmtTime, fmtDateStr } 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({ 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'],
|
|
||||||
queryFn: () => client.get('/api/reports/meta/waiters').then(r => r.data),
|
|
||||||
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', {
|
|
||||||
params: {
|
|
||||||
...(waiterId !== 'all' ? { waiter_id: waiterId } : {}),
|
|
||||||
from: from + 'T00:00:00',
|
|
||||||
to: to + 'T23:59:59',
|
|
||||||
},
|
|
||||||
}).then(r => r.data),
|
|
||||||
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 = [
|
|
||||||
{ value: 'all', label: 'Όλοι οι Σερβιτόροι' },
|
|
||||||
...((waitersData?.waiters || []).map(w => ({ value: String(w.id), label: w.name }))),
|
|
||||||
]
|
|
||||||
|
|
||||||
const shifts = data?.shifts || []
|
|
||||||
|
|
||||||
if (isLoading) return <div className="flex-1 overflow-y-auto p-6"><SkeletonTable rows={8} columns={8} /></div>
|
|
||||||
if (isError) return (
|
|
||||||
<div className="flex flex-col flex-1 min-h-0">
|
|
||||||
<FilterBar right={null}><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 text-slate-700 hover:bg-slate-50">Επανάληψη</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="flex flex-col flex-1 min-h-0">
|
|
||||||
<FilterBar right={
|
|
||||||
<ExportButton
|
|
||||||
endpoint="/api/reports/shifts/export"
|
|
||||||
params={{ ...(waiterId !== 'all' ? { waiter_id: waiterId } : {}), from: from + 'T00:00:00', to: to + 'T23:59:59' }}
|
|
||||||
filename={`shifts-${from}-to-${to}.csv`}
|
|
||||||
/>
|
|
||||||
}>
|
|
||||||
<FilterSelect value={waiterId} onChange={setWaiterId} options={waiterOptions} label="Σερβιτόρος" />
|
|
||||||
<FilterDateInput value={from} onChange={setFrom} label="Από" />
|
|
||||||
<FilterDateInput value={to} onChange={setTo} label="Έως" />
|
|
||||||
</FilterBar>
|
|
||||||
|
|
||||||
<div className="flex-1 overflow-y-auto p-6">
|
|
||||||
<Panel
|
|
||||||
title="Όλες οι Βάρδιες"
|
|
||||||
subtitle={`${shifts.length} βάρδιες · ${fmtDateStr(from)} → ${fmtDateStr(to)}`}
|
|
||||||
padded={false}
|
|
||||||
>
|
|
||||||
{shifts.length === 0 ? (
|
|
||||||
<EmptyState
|
|
||||||
icon={UserRoundX}
|
|
||||||
title="Δεν βρέθηκαν βάρδιες"
|
|
||||||
description="Δοκιμάστε να αλλάξετε το εύρος ημερομηνιών ή τον σερβιτόρο."
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
<DataTable>
|
|
||||||
<THead>
|
|
||||||
<TH>Σερβιτόρος</TH>
|
|
||||||
<TH>Έναρξη</TH>
|
|
||||||
<TH>Λήξη</TH>
|
|
||||||
<TH align="right">Διάρκεια</TH>
|
|
||||||
<TH align="right">Αμοιβή/ώρα</TH>
|
|
||||||
<TH align="right">Αποδοχές</TH>
|
|
||||||
<TH align="right">Αρχικά Μετρητά</TH>
|
|
||||||
<TH align="right">Εισπράχθηκαν</TH>
|
|
||||||
<TH align="right">Οφείλει</TH>
|
|
||||||
<TH align="right">Ταμείο</TH>
|
|
||||||
<TH align="right">Ακυρώσεις</TH>
|
|
||||||
<TH align="right">Αξία Ακυρ.</TH>
|
|
||||||
<TH>Κατάσταση</TH>
|
|
||||||
<TH className="w-28" />
|
|
||||||
</THead>
|
|
||||||
<tbody>
|
|
||||||
{shifts.map(s => {
|
|
||||||
const isOpen = expanded === s.id
|
|
||||||
return [
|
|
||||||
<TR
|
|
||||||
key={`${s.id}-row`}
|
|
||||||
onClick={() => setExpanded(isOpen ? null : s.id)}
|
|
||||||
highlight={isOpen}
|
|
||||||
striped
|
|
||||||
>
|
|
||||||
<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">
|
|
||||||
{s.hourly_rate_snapshot != null
|
|
||||||
? fmtEUR(s.hourly_rate_snapshot)
|
|
||||||
: <span className="text-slate-400 text-[11px]">—</span>}
|
|
||||||
</TD>
|
|
||||||
<TD mono align="right">
|
|
||||||
{s.shift_pay != null
|
|
||||||
? <span className="font-semibold text-emerald-700">{fmtEUR(s.shift_pay)}</span>
|
|
||||||
: <span className="text-slate-400 text-[11px]">Δεν παρακολουθείται</span>}
|
|
||||||
</TD>
|
|
||||||
<TD mono align="right">{fmtEUR(s.starting_cash)}</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 ? (() => {
|
|
||||||
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>
|
|
||||||
<TD mono align="right">
|
|
||||||
{s.cancellations > 0
|
|
||||||
? <span className="text-red-600 font-semibold">{s.cancellations}</span>
|
|
||||||
: <span className="text-slate-300">—</span>}
|
|
||||||
</TD>
|
|
||||||
<TD mono align="right">
|
|
||||||
{s.cancellation_value > 0
|
|
||||||
? <span className="text-red-500">{fmtEUR(s.cancellation_value)}</span>
|
|
||||||
: <span className="text-slate-300">—</span>}
|
|
||||||
</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({ id: s.id, waiter_id: s.waiter_id }) }}
|
|
||||||
className="rounded border border-sky-200 bg-white p-0.5 text-sky-400 hover:bg-sky-50 hover:text-sky-600"
|
|
||||||
title="Λεπτομέρειες βάρδιας"
|
|
||||||
>
|
|
||||||
<Eye size={13} />
|
|
||||||
</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={14} className="border-b border-slate-100 bg-slate-50/60 px-6 py-3">
|
|
||||||
<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>
|
|
||||||
),
|
|
||||||
]
|
|
||||||
})}
|
|
||||||
</tbody>
|
|
||||||
</DataTable>
|
|
||||||
)}
|
|
||||||
</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>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -1,150 +0,0 @@
|
|||||||
import { useState, useMemo } from 'react'
|
|
||||||
import { useQuery } from '@tanstack/react-query'
|
|
||||||
import { BarChart, Bar, 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, WaiterAvatar, ChartTooltip } from '../shared/TablePrimitives'
|
|
||||||
import EmptyState from '../shared/EmptyState'
|
|
||||||
import SkeletonTable from '../shared/SkeletonTable'
|
|
||||||
import { fmtEUR, fmtNum, avatarColor, fmtDateStr } 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) }
|
|
||||||
|
|
||||||
const PODIUM_HEIGHTS = ['h-44', 'h-32', 'h-24']
|
|
||||||
const PODIUM_COLORS = [
|
|
||||||
'bg-gradient-to-b from-amber-200 to-amber-100 ring-amber-300',
|
|
||||||
'bg-gradient-to-b from-slate-200 to-slate-100 ring-slate-300',
|
|
||||||
'bg-gradient-to-b from-orange-200 to-orange-100 ring-orange-300',
|
|
||||||
]
|
|
||||||
const MEDAL_LABEL = ['1ος', '2ος', '3ος']
|
|
||||||
const PODIUM_ORDER = [1, 0, 2]
|
|
||||||
|
|
||||||
export default function StaffLeaderboard() {
|
|
||||||
const [from, setFrom] = useState(monthAgo())
|
|
||||||
const [to, setTo] = useState(today())
|
|
||||||
|
|
||||||
const { data, isLoading, isError, refetch } = useQuery({
|
|
||||||
queryKey: ['shifts-leaderboard', from, to],
|
|
||||||
queryFn: () => client.get('/api/reports/shifts', { params: { from: from + 'T00:00:00', to: to + 'T23:59:59' } }).then(r => r.data),
|
|
||||||
staleTime: 60 * 1000,
|
|
||||||
})
|
|
||||||
|
|
||||||
const ranked = useMemo(() => {
|
|
||||||
const shifts = data?.shifts || []
|
|
||||||
const map = new Map()
|
|
||||||
shifts.forEach(s => {
|
|
||||||
const cur = map.get(s.waiter_id) || { waiter_id: s.waiter_id, waiter_name: s.waiter_name, shifts: 0, orders: 0, value: 0 }
|
|
||||||
cur.shifts += 1
|
|
||||||
cur.value += s.total_collected || 0
|
|
||||||
map.set(s.waiter_id, cur)
|
|
||||||
})
|
|
||||||
return [...map.values()]
|
|
||||||
.map(r => ({ ...r, avg_per_shift: r.shifts ? r.value / r.shifts : 0 }))
|
|
||||||
.sort((a, b) => b.value - a.value)
|
|
||||||
}, [data])
|
|
||||||
|
|
||||||
const top3 = ranked.slice(0, 3)
|
|
||||||
|
|
||||||
const chartData = ranked.map(r => ({
|
|
||||||
name: (r.waiter_name || '').split(' ')[0],
|
|
||||||
value: Math.round(r.value),
|
|
||||||
}))
|
|
||||||
|
|
||||||
if (isLoading) return <div className="flex-1 overflow-y-auto p-6"><SkeletonTable rows={8} columns={7} /></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>
|
|
||||||
<FilterDateInput value={from} onChange={setFrom} label="Από" />
|
|
||||||
<FilterDateInput value={to} onChange={setTo} label="Έως" />
|
|
||||||
<span className="ml-2 text-[12px] text-slate-500">{ranked.length} σερβιτόροι · άθροισμα περιόδου</span>
|
|
||||||
</FilterBar>
|
|
||||||
|
|
||||||
<div className="flex-1 overflow-y-auto p-6">
|
|
||||||
<Panel title="Κορυφαίοι" subtitle={`${fmtDateStr(from)} → ${fmtDateStr(to)}`}>
|
|
||||||
{top3.length === 0 ? (
|
|
||||||
<EmptyState title="Δεν υπάρχουν δεδομένα" description="Δεν υπάρχουν βάρδιες σε αυτή την περίοδο." />
|
|
||||||
) : (
|
|
||||||
<div className="flex items-end justify-center gap-6 px-12 pb-2 pt-6">
|
|
||||||
{PODIUM_ORDER.map(rank => {
|
|
||||||
const r = top3[rank]
|
|
||||||
if (!r) return <div key={rank} className="w-44" />
|
|
||||||
const initials = (r.waiter_name || '').split(' ').map(p => p[0]).slice(0, 2).join('').toUpperCase()
|
|
||||||
const cls = avatarColor(r.waiter_id)
|
|
||||||
return (
|
|
||||||
<div key={r.waiter_id} className="flex w-44 flex-col items-center">
|
|
||||||
<div className="mb-3 flex flex-col items-center">
|
|
||||||
<div className={`flex h-14 w-14 items-center justify-center rounded-full text-base font-semibold ring-2 ring-white ${cls}`}>
|
|
||||||
{initials}
|
|
||||||
</div>
|
|
||||||
<div className="mt-2 text-[13px] font-semibold text-slate-900">{r.waiter_name}</div>
|
|
||||||
<div className="font-mono text-[11px] uppercase tracking-wider text-slate-500">{r.shifts} βάρδιες</div>
|
|
||||||
</div>
|
|
||||||
<div className={`flex w-full ${PODIUM_HEIGHTS[rank]} flex-col items-center justify-end rounded-t-md ring-1 ring-inset ${PODIUM_COLORS[rank]} pb-3`}>
|
|
||||||
<div className="font-mono text-[10px] font-semibold uppercase tracking-[0.12em] text-slate-700">{MEDAL_LABEL[rank]}</div>
|
|
||||||
<div className="mt-1 font-mono text-[18px] font-medium tabular-nums text-slate-900">{fmtEUR(r.value)}</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
})}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</Panel>
|
|
||||||
|
|
||||||
<div className="mt-4 grid grid-cols-3 gap-4">
|
|
||||||
<div className="col-span-2">
|
|
||||||
<Panel title="Πλήρης Κατάταξη" padded={false}>
|
|
||||||
<DataTable>
|
|
||||||
<THead>
|
|
||||||
<TH align="center" className="w-12">Θέση</TH>
|
|
||||||
<TH>Σερβιτόρος</TH>
|
|
||||||
<TH align="right">Βάρδιες</TH>
|
|
||||||
<TH align="right">Συνολικά Έσοδα</TH>
|
|
||||||
<TH align="right">Μέσος / Βάρδια</TH>
|
|
||||||
</THead>
|
|
||||||
<tbody>
|
|
||||||
{ranked.map((r, i) => (
|
|
||||||
<TR key={r.waiter_id} striped>
|
|
||||||
<TD align="center" className="w-12">
|
|
||||||
<span className={`inline-flex h-6 w-6 items-center justify-center rounded-full font-mono text-[11px] font-semibold ${
|
|
||||||
i === 0 ? 'bg-amber-100 text-amber-800 ring-1 ring-inset ring-amber-300' :
|
|
||||||
i === 1 ? 'bg-slate-100 text-slate-700 ring-1 ring-inset ring-slate-300' :
|
|
||||||
i === 2 ? 'bg-orange-100 text-orange-800 ring-1 ring-inset ring-orange-300' :
|
|
||||||
'text-slate-400'
|
|
||||||
}`}>{i + 1}</span>
|
|
||||||
</TD>
|
|
||||||
<TD><WaiterAvatar name={r.waiter_name} id={r.waiter_id} /></TD>
|
|
||||||
<TD mono align="right">{r.shifts}</TD>
|
|
||||||
<TD mono align="right" className="font-semibold text-slate-900">{fmtEUR(r.value)}</TD>
|
|
||||||
<TD mono align="right">{fmtEUR(r.avg_per_shift)}</TD>
|
|
||||||
</TR>
|
|
||||||
))}
|
|
||||||
</tbody>
|
|
||||||
</DataTable>
|
|
||||||
</Panel>
|
|
||||||
</div>
|
|
||||||
<Panel title="Έσοδα ανά Σερβιτόρο" subtitle="Φθίνουσα σειρά">
|
|
||||||
<div style={{ height: 320 }}>
|
|
||||||
<ResponsiveContainer width="100%" height="100%">
|
|
||||||
<BarChart data={chartData} layout="vertical" margin={{ top: 4, right: 16, bottom: 4, left: 4 }}>
|
|
||||||
<CartesianGrid horizontal={false} stroke="#f1f5f9" />
|
|
||||||
<XAxis type="number" tick={{ fontSize: 10, fill: '#94a3b8' }} stroke="#cbd5e1" axisLine={false} tickLine={false} />
|
|
||||||
<YAxis type="category" dataKey="name" tick={{ fontSize: 11, fill: '#475569' }} stroke="#cbd5e1" axisLine={false} tickLine={false} width={64} />
|
|
||||||
<Tooltip content={<ChartTooltip formatter={v => fmtEUR(v)} />} cursor={{ fill: '#f1f5f9' }} />
|
|
||||||
<Bar dataKey="value" fill="#60a5fa" radius={[0, 3, 3, 0]} barSize={14} />
|
|
||||||
</BarChart>
|
|
||||||
</ResponsiveContainer>
|
|
||||||
</div>
|
|
||||||
</Panel>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,181 @@
|
|||||||
|
// Reports → Staff (plan step 6.12c; replaces the v1 shifts / payments / activity / leaderboard
|
||||||
|
// views): every shift with its pay and cash; the cash each shift hands over; and sales by person
|
||||||
|
// (counted like every report: net of refunds, the delivery fee apart), ranked.
|
||||||
|
import { useState } from 'react'
|
||||||
|
import { useMutation, useQueryClient } from '@tanstack/react-query'
|
||||||
|
import toast from 'react-hot-toast'
|
||||||
|
import { Trash2 } from 'lucide-react'
|
||||||
|
import { useCan } from '@xenia/access'
|
||||||
|
import { errorMessage } from '@xenia/api'
|
||||||
|
import { useFormat, useTranslation } from '@xenia/i18n'
|
||||||
|
import { Button, Dialog, IconButton, Select } from '@xenia/ui'
|
||||||
|
import client from '../../../api/client'
|
||||||
|
import { useLiveQuery } from '../../../live/useLiveQuery'
|
||||||
|
import { useDuration } from '../../overview/hooks'
|
||||||
|
import { Pill } from '../../overview/parts'
|
||||||
|
import ShiftDialog from '../../overview/ShiftDialog'
|
||||||
|
import { BarList } from '../kit/charts'
|
||||||
|
import { ExportButton, Failed, Loading, Panel, ReportPage, Stat, Table } from '../kit/parts'
|
||||||
|
import { PeriodPicker } from '../kit/Period'
|
||||||
|
import { defaultPeriod, periodParams, periodSlug, ratio } from '../kit/reportLogic'
|
||||||
|
|
||||||
|
export default function StaffReport() {
|
||||||
|
const { t } = useTranslation('manager')
|
||||||
|
const tabs = [
|
||||||
|
{ id: 'shifts', label: t('reports.staff.tabs.shifts'), Component: ShiftsTab },
|
||||||
|
{ id: 'cash', label: t('reports.staff.tabs.cash'), Component: CashTab },
|
||||||
|
{ id: 'people', label: t('reports.staff.tabs.people'), Component: PeopleTab },
|
||||||
|
]
|
||||||
|
return <ReportPage title={t('reports.staff.title')} tabs={tabs} testId="report-staff" />
|
||||||
|
}
|
||||||
|
|
||||||
|
function usePeople() {
|
||||||
|
return useLiveQuery({ queryKey: ['meta-waiters'], queryFn: () => client.get('/api/reports/meta/waiters').then(r => r.data.waiters), staleTime: 300_000 })
|
||||||
|
}
|
||||||
|
|
||||||
|
function PersonFilter({ value, onChange }) {
|
||||||
|
const { t } = useTranslation('manager')
|
||||||
|
const { data: people = [] } = usePeople()
|
||||||
|
return (
|
||||||
|
<Select size="sm" value={value} onChange={e => onChange(e.target.value)} aria-label={t('reports.person')} className="w-56"
|
||||||
|
options={[{ value: '', label: t('reports.store.anyone') }, ...people.map(p => ({ value: String(p.id), label: p.name }))]} />
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function useShifts(params) {
|
||||||
|
return useLiveQuery({ queryKey: ['report-shifts', params], queryFn: () => client.get('/api/reports/shifts', { params }).then(r => r.data.shifts), events: ['shift_changed'] })
|
||||||
|
}
|
||||||
|
|
||||||
|
function ShiftsTab() {
|
||||||
|
const { t } = useTranslation('manager')
|
||||||
|
const fmt = useFormat()
|
||||||
|
const since = useDuration()
|
||||||
|
const qc = useQueryClient()
|
||||||
|
const owner = useCan('core.settings.manage')
|
||||||
|
const [period, setPeriod] = useState(() => defaultPeriod(fmt.venueToday()))
|
||||||
|
const [person, setPerson] = useState('')
|
||||||
|
const [shift, setShift] = useState(null)
|
||||||
|
const [dropping, setDropping] = useState(null)
|
||||||
|
const params = { ...periodParams(period), ...(person ? { waiter_id: person } : {}) }
|
||||||
|
const { data, isPending, error, refetch } = useShifts(params)
|
||||||
|
const remove = useMutation({
|
||||||
|
mutationFn: s => client.delete(`/api/shifts/${s.id}`),
|
||||||
|
onSuccess: () => { setDropping(null); toast.success(t('reports.store.shiftDeleted')); qc.invalidateQueries({ queryKey: ['report-shifts'] }) },
|
||||||
|
onError: err => toast.error(errorMessage(err, t)),
|
||||||
|
})
|
||||||
|
const rows = data ?? []
|
||||||
|
const columns = [
|
||||||
|
{ key: 'waiter_name', label: t('reports.person'), render: s => <span className="font-semibold text-ink">{s.waiter_name}</span> },
|
||||||
|
{ key: 'started_at', label: t('reports.store.from'), render: s => fmt.formatDateTime(s.started_at, 'datetimeShort') },
|
||||||
|
{ key: 'ended_at', label: t('reports.store.to'), render: s => (s.ended_at ? fmt.formatTime(s.ended_at) : <Pill tone="success">{t('reports.store.working')}</Pill>) },
|
||||||
|
{ key: 'duration_hours', label: t('reports.store.length'), align: 'right', render: s => since(s.started_at, s.ended_at ? Date.parse(s.ended_at) : undefined) },
|
||||||
|
{ key: 'shift_pay', label: t('reports.staff.pay'), align: 'right', tip: t('reports.staff.payTip'), render: s => (s.shift_pay != null ? fmt.formatMoney(s.shift_pay) : '') },
|
||||||
|
{ key: 'total_collected', label: t('reports.store.collected'), align: 'right', render: s => fmt.formatMoney(s.total_collected) },
|
||||||
|
{ key: 'net_to_deliver', label: t('reports.staff.handOver'), align: 'right', tip: t('reports.staff.handOverTip'), render: s => fmt.formatMoney(s.net_to_deliver) },
|
||||||
|
{ key: 'cash_discrepancy', label: t('reports.staff.difference'), align: 'right', tip: t('reports.staff.differenceTip'),
|
||||||
|
render: s => (s.cash_discrepancy == null ? '' : <span className={s.cash_discrepancy < 0 ? 'text-danger-ink' : s.cash_discrepancy > 0 ? 'text-success-ink' : ''}>{fmt.formatMoney(s.cash_discrepancy, { signDisplay: 'exceptZero' })}</span>) },
|
||||||
|
{ key: 'cancellations', label: t('reports.store.cancelled'), align: 'right', render: s => (s.cancellations ? `${s.cancellations} · ${fmt.formatMoney(s.cancellation_value ?? 0)}` : '') },
|
||||||
|
...(owner ? [{ key: 'del', label: '', sort: false, render: s => (!s.is_active ? (
|
||||||
|
<IconButton size="sm" variant="ghost" label={t('reports.store.deleteShift')} onClick={e => { e.stopPropagation(); setDropping(s) }}><Trash2 size={14} /></IconButton>) : null) }] : []),
|
||||||
|
]
|
||||||
|
const pay = rows.reduce((s, x) => s + (x.shift_pay ?? 0), 0)
|
||||||
|
return (
|
||||||
|
<div className="grid gap-4">
|
||||||
|
<PeriodPicker value={period} onChange={setPeriod}
|
||||||
|
right={<span className="flex gap-2 items-end"><PersonFilter value={person} onChange={setPerson} />
|
||||||
|
<ExportButton endpoint="/api/reports/shifts/export" params={params} filename={`shifts-${periodSlug(period)}.csv`} /></span>} />
|
||||||
|
{isPending ? <Loading /> : error ? <Failed error={error} retry={refetch} /> : (
|
||||||
|
<Panel padded={false} title={t('reports.staff.shiftsCount', { count: rows.length })}
|
||||||
|
actions={pay > 0 ? <span className="text-label text-ink-2">{t('reports.staff.payTotal', { amount: fmt.formatMoney(pay) })}</span> : null}>
|
||||||
|
<Table columns={columns} rows={rows} onRow={setShift} rowTestId="report-shift" initialSort={{ key: 'started_at', dir: 'desc' }} />
|
||||||
|
</Panel>
|
||||||
|
)}
|
||||||
|
{shift && <ShiftDialog shift={shift} mode="stats" onClose={() => setShift(null)} />}
|
||||||
|
{dropping && (
|
||||||
|
<Dialog open size="sm" onClose={() => setDropping(null)} title={t('reports.store.deleteShiftTitle', { name: dropping.waiter_name })} description={t('reports.store.deleteShiftBody')}
|
||||||
|
footer={<>
|
||||||
|
<Button variant="secondary" onClick={() => setDropping(null)}>{t('reports.back')}</Button>
|
||||||
|
<Button variant="danger" loading={remove.isPending} onClick={() => remove.mutate(dropping)}>{t('reports.store.deleteYes')}</Button>
|
||||||
|
</>} />
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function CashTab() {
|
||||||
|
const { t } = useTranslation('manager')
|
||||||
|
const fmt = useFormat()
|
||||||
|
const [period, setPeriod] = useState(() => defaultPeriod(fmt.venueToday()))
|
||||||
|
const [person, setPerson] = useState('')
|
||||||
|
const [shift, setShift] = useState(null)
|
||||||
|
const params = { ...periodParams(period), ...(person ? { waiter_id: person } : {}) }
|
||||||
|
const { data, isPending, error, refetch } = useShifts(params)
|
||||||
|
const rows = data ?? []
|
||||||
|
const sum = k => rows.reduce((s, x) => s + (x[k] ?? 0), 0)
|
||||||
|
const columns = [
|
||||||
|
{ key: 'waiter_name', label: t('reports.person'), render: s => <span className="font-semibold text-ink">{s.waiter_name}</span> },
|
||||||
|
{ key: 'started_at', label: t('reports.staff.shift'), render: s => `${fmt.formatDateTime(s.started_at, 'datetimeShort')} – ${s.ended_at ? fmt.formatTime(s.ended_at) : '…'}` },
|
||||||
|
{ key: 'starting_cash', label: t('reports.staff.starting'), align: 'right', render: s => fmt.formatMoney(s.starting_cash ?? 0) },
|
||||||
|
{ key: 'cash_sales', label: t('reports.staff.cash'), align: 'right', render: s => fmt.formatMoney(s.cash_sales ?? 0) },
|
||||||
|
{ key: 'card_sales', label: t('reports.staff.card'), align: 'right', render: s => fmt.formatMoney(s.card_sales ?? 0) },
|
||||||
|
{ key: 'refunds', label: t('reports.refunded'), align: 'right', sort: s => (s.cash_refunds ?? 0) + (s.card_refunds ?? 0),
|
||||||
|
render: s => { const r = (s.cash_refunds ?? 0) + (s.card_refunds ?? 0); return r ? <span className="text-danger-ink">{fmt.formatMoney(r)}</span> : '' } },
|
||||||
|
{ key: 'net_to_deliver', label: t('reports.staff.handOver'), align: 'right', render: s => <span className="font-semibold">{fmt.formatMoney(s.net_to_deliver)}</span> },
|
||||||
|
{ key: 'counted_cash_end', label: t('reports.staff.counted'), align: 'right', render: s => (s.counted_cash_end != null ? fmt.formatMoney(s.counted_cash_end) : '') },
|
||||||
|
{ key: 'status', label: t('reports.status'), sort: s => (s.is_active ? 1 : 0), render: s => <Pill tone={s.is_active ? 'success' : 'neutral'}>{t(s.is_active ? 'reports.staff.open' : 'reports.staff.ended')}</Pill> },
|
||||||
|
]
|
||||||
|
return (
|
||||||
|
<div className="grid gap-4">
|
||||||
|
<PeriodPicker value={period} onChange={setPeriod} right={<PersonFilter value={person} onChange={setPerson} />} />
|
||||||
|
{isPending ? <Loading /> : error ? <Failed error={error} retry={refetch} /> : (<>
|
||||||
|
<div className="grid gap-3 grid-cols-[repeat(auto-fill,minmax(12rem,1fr))]">
|
||||||
|
<Stat label={t('reports.staff.starting')} value={fmt.formatMoney(sum('starting_cash'))} sub={t('reports.staff.shiftsCount', { count: rows.length })} />
|
||||||
|
<Stat label={t('reports.staff.cash')} value={fmt.formatMoney(sum('cash_sales'))} />
|
||||||
|
<Stat label={t('reports.staff.card')} value={fmt.formatMoney(sum('card_sales'))} />
|
||||||
|
<Stat label={t('reports.staff.handOver')} tip={t('reports.staff.handOverTip')} tone="accent" value={fmt.formatMoney(sum('net_to_deliver'))} testId="staff-handover" />
|
||||||
|
</div>
|
||||||
|
<Panel padded={false} title={t('reports.staff.cashTitle')}>
|
||||||
|
<Table columns={columns} rows={rows} onRow={setShift} initialSort={{ key: 'started_at', dir: 'desc' }} />
|
||||||
|
</Panel>
|
||||||
|
</>)}
|
||||||
|
{shift && <ShiftDialog shift={shift} mode="stats" onClose={() => setShift(null)} />}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function PeopleTab() {
|
||||||
|
const { t } = useTranslation('manager')
|
||||||
|
const fmt = useFormat()
|
||||||
|
const [period, setPeriod] = useState(() => defaultPeriod(fmt.venueToday()))
|
||||||
|
const params = periodParams(period)
|
||||||
|
const { data, isPending, error, refetch } = useLiveQuery({ queryKey: ['report-people', params], queryFn: () => client.get('/api/reports/shift/orders', { params }).then(r => r.data.waiters) })
|
||||||
|
const rows = (data ?? []).map(p => ({ ...p, orders: p.orders ?? 0, per_hour: p.hours_worked ? p.total / p.hours_worked : null }))
|
||||||
|
const all = rows.reduce((s, p) => s + p.total, 0)
|
||||||
|
const qty = q => fmt.formatNumber(q, { maxDecimals: 3 })
|
||||||
|
const columns = [
|
||||||
|
{ key: 'waiter_name', label: t('reports.person'), render: p => <span className="font-semibold text-ink">{p.waiter_name}</span> },
|
||||||
|
{ key: 'orders', label: t('reports.orders'), align: 'right' },
|
||||||
|
{ key: 'items', label: t('reports.prod.units'), align: 'right', render: p => qty(p.items) },
|
||||||
|
{ key: 'cancellations', label: t('reports.store.cancelled'), align: 'right', render: p => (p.cancellations ? qty(p.cancellations) : '') },
|
||||||
|
{ key: 'hours_worked', label: t('reports.staff.hours'), align: 'right', render: p => (p.hours_worked ? fmt.formatNumber(p.hours_worked, { maxDecimals: 1 }) : '') },
|
||||||
|
{ key: 'total', label: t('reports.staff.sales'), align: 'right', tip: t('reports.staff.salesTip'), render: p => <span className="font-semibold">{fmt.formatMoney(p.total)}</span> },
|
||||||
|
{ key: 'per_hour', label: t('reports.staff.perHour'), align: 'right', render: p => (p.per_hour != null ? fmt.formatMoney(p.per_hour) : '') },
|
||||||
|
{ key: 'share', label: t('reports.prod.share'), align: 'right', sort: p => p.total, render: p => fmt.formatPercent(ratio(p.total, all), { maxDecimals: 1 }) },
|
||||||
|
]
|
||||||
|
return (
|
||||||
|
<div className="grid gap-4">
|
||||||
|
<PeriodPicker value={period} onChange={setPeriod} />
|
||||||
|
{isPending ? <Loading /> : error ? <Failed error={error} retry={refetch} /> : (<>
|
||||||
|
{rows.length > 0 && (
|
||||||
|
<Panel title={t('reports.staff.ranking')} tip={t('reports.staff.salesTip')}>
|
||||||
|
<BarList testId="staff-ranking" format={v => fmt.formatMoney(v)}
|
||||||
|
rows={[...rows].sort((a, b) => b.total - a.total).map(p => ({ key: p.waiter_id, label: p.waiter_name, value: p.total, sub: t('reports.traffic.ordersN', { count: p.orders }) }))} />
|
||||||
|
</Panel>
|
||||||
|
)}
|
||||||
|
<Panel padded={false} title={t('reports.staff.people', { count: rows.length })}>
|
||||||
|
<Table columns={columns} rows={rows} rowKey={p => p.waiter_id} rowTestId="report-person" initialSort={{ key: 'total', dir: 'desc' }} />
|
||||||
|
</Panel>
|
||||||
|
</>)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,88 @@
|
|||||||
|
// Reports → Technical (plan step 6.12c; replaces the v1 printer history + printer health views):
|
||||||
|
// every ticket sent to a printer (when, which printer, which order, what was on it, printed or
|
||||||
|
// failed with the printer's error), how reliable each printer was, a summary on a receipt
|
||||||
|
// printer; and, for the owner, the server's log files (v2 since 2.6f).
|
||||||
|
import { useState } from 'react'
|
||||||
|
import { Printer } from 'lucide-react'
|
||||||
|
import { useCan } from '@xenia/access'
|
||||||
|
import { useFormat, useTranslation } from '@xenia/i18n'
|
||||||
|
import { Button, Select } from '@xenia/ui'
|
||||||
|
import client from '../../../api/client'
|
||||||
|
import { useLiveQuery } from '../../../live/useLiveQuery'
|
||||||
|
import { Pill } from '../../overview/parts'
|
||||||
|
import LogsPanel from '../operations/LogsPanel'
|
||||||
|
import { BarList } from '../kit/charts'
|
||||||
|
import { ExportButton, Failed, Loading, Panel, ReportPage, Stat, Table } from '../kit/parts'
|
||||||
|
import { PeriodPicker } from '../kit/Period'
|
||||||
|
import PrintDialog from '../kit/PrintDialog'
|
||||||
|
import { defaultPeriod, periodParams, periodSlug, printBody, ratio } from '../kit/reportLogic'
|
||||||
|
|
||||||
|
export default function TechnicalReport() {
|
||||||
|
const { t } = useTranslation('manager')
|
||||||
|
const owner = useCan('core.settings.manage') // the files carry names and IPs: owner-level
|
||||||
|
const tabs = [
|
||||||
|
{ id: 'printing', label: t('reports.tech.printing'), Component: PrintingTab },
|
||||||
|
...(owner ? [{ id: 'logs', label: t('logs.tab'), Component: LogsPanel }] : []),
|
||||||
|
]
|
||||||
|
return <ReportPage title={t('reports.tech.title')} tabs={tabs} testId="report-technical" />
|
||||||
|
}
|
||||||
|
|
||||||
|
function PrintingTab() {
|
||||||
|
const { t } = useTranslation('manager')
|
||||||
|
const fmt = useFormat()
|
||||||
|
const [period, setPeriod] = useState(() => defaultPeriod(fmt.venueToday()))
|
||||||
|
const [printer, setPrinter] = useState('')
|
||||||
|
const [printing, setPrinting] = useState(false)
|
||||||
|
const { data: printers = [] } = useLiveQuery({ queryKey: ['meta-printers'], queryFn: () => client.get('/api/reports/meta/printers').then(r => r.data.printers), staleTime: 300_000 })
|
||||||
|
const params = { ...periodParams(period), ...(printer ? { printer_id: printer } : {}) }
|
||||||
|
const { data, isPending, error, refetch } = useLiveQuery({ queryKey: ['report-printing', params], queryFn: () => client.get('/api/reports/printers/history', { params }).then(r => r.data) })
|
||||||
|
const logs = data?.logs ?? []
|
||||||
|
const failed = logs.filter(l => !l.success)
|
||||||
|
const perPrinter = Object.values(logs.reduce((m, l) => {
|
||||||
|
const k = l.printer_name
|
||||||
|
m[k] = m[k] ?? { key: k, label: k, value: 0, failed: 0 }
|
||||||
|
m[k].value += 1
|
||||||
|
if (!l.success) m[k].failed += 1
|
||||||
|
return m
|
||||||
|
}, {}))
|
||||||
|
const columns = [
|
||||||
|
{ key: 'printed_at', label: t('reports.misc.when'), render: l => fmt.formatDateTime(l.printed_at, 'datetimeShort') },
|
||||||
|
{ key: 'printer_name', label: t('reports.print.printer') },
|
||||||
|
{ key: 'order_id', label: '#', render: l => <span className="tabular-nums text-ink-2">#{l.order_id}</span> },
|
||||||
|
{ key: 'table', label: t('reports.place') },
|
||||||
|
{ key: 'items', label: t('reports.tech.items'), sort: false,
|
||||||
|
render: l => (l.items ?? []).map(i => `${fmt.formatNumber(i.quantity, { maxDecimals: 3 })}× ${i.name}`).join(', ') },
|
||||||
|
{ key: 'success', label: t('reports.tech.result'), sort: l => (l.success ? 1 : 0),
|
||||||
|
render: l => (l.success ? <Pill tone="success">{t('reports.tech.printed')}</Pill>
|
||||||
|
: <span className="grid gap-0.5"><Pill tone="danger">{t('reports.tech.failed')}</Pill>{l.error_message && <span className="text-caption text-ink-3">{l.error_message}</span>}</span>) },
|
||||||
|
]
|
||||||
|
return (
|
||||||
|
<div className="grid gap-4">
|
||||||
|
<PeriodPicker value={period} onChange={setPeriod} right={<span className="flex gap-2 items-end">
|
||||||
|
<Select size="sm" value={printer} onChange={e => setPrinter(e.target.value)} aria-label={t('reports.print.printer')} className="w-48"
|
||||||
|
options={[{ value: '', label: t('reports.tech.allPrinters') }, ...printers.map(p => ({ value: String(p.id), label: p.name }))]} />
|
||||||
|
<ExportButton endpoint="/api/reports/printers/export" params={params} filename={`printing-${periodSlug(period)}.csv`} />
|
||||||
|
<Button size="sm" variant="secondary" icon={<Printer size={14} />} onClick={() => setPrinting(true)}>{t('reports.print.button')}</Button>
|
||||||
|
</span>} />
|
||||||
|
{isPending ? <Loading /> : error ? <Failed error={error} retry={refetch} /> : (<>
|
||||||
|
<div className="grid gap-3 grid-cols-[repeat(auto-fill,minmax(12rem,1fr))]">
|
||||||
|
<Stat label={t('reports.tech.tickets')} value={data.total ?? logs.length} testId="printing-total" />
|
||||||
|
<Stat label={t('reports.tech.failedN')} tone={failed.length ? 'danger' : undefined} value={data.failed ?? failed.length}
|
||||||
|
sub={failed.length ? t('reports.tech.checkPrinter') : t('reports.tech.allGood')} />
|
||||||
|
<Stat label={t('reports.tech.reliability')} tip={t('reports.tech.reliabilityTip')} value={logs.length ? fmt.formatPercent(1 - ratio(failed.length, logs.length), { maxDecimals: 1 }) : '—'} />
|
||||||
|
{data.total_amount != null && <Stat label={t('reports.tech.ordersValue')} tip={t('reports.tech.ordersValueTip')} value={fmt.formatMoney(data.total_amount)} />}
|
||||||
|
</div>
|
||||||
|
{perPrinter.length > 0 && (
|
||||||
|
<Panel title={t('reports.tech.perPrinter')}>
|
||||||
|
<BarList rows={perPrinter.map(p => ({ ...p, sub: p.failed ? t('reports.tech.failedSome', { count: p.failed }) : t('reports.tech.noneFailed') }))} />
|
||||||
|
</Panel>
|
||||||
|
)}
|
||||||
|
<Panel padded={false} title={t('reports.tech.jobs', { count: logs.length })}>
|
||||||
|
<Table columns={columns} rows={logs} rowTestId="report-print-job" initialSort={{ key: 'printed_at', dir: 'desc' }} limit={300} />
|
||||||
|
</Panel>
|
||||||
|
</>)}
|
||||||
|
{printing && <PrintDialog endpoint="/api/reports/print/printer" modes={['quick', 'orders', 'detailed']}
|
||||||
|
body={{ ...printBody(period), printer_target_id: printer ? Number(printer) : 0, item_breakdown: false }} onClose={() => setPrinting(false)} />}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
import { test } from 'node:test'
|
import { test } from 'node:test'
|
||||||
import assert from 'node:assert/strict'
|
import assert from 'node:assert/strict'
|
||||||
import {
|
import {
|
||||||
addDays, dayChoices, defaultPeriod, hourSeries, margin, orderTotals, periodParams, periodSlug, printBody, quickRange, rangeProblem, ratio, sortRows,
|
addDays, csvText, dayChoices, defaultPeriod, hourSeries, margin, orderTotals, periodParams, periodSlug, printBody, quickRange, rangeProblem, ratio, sortRows,
|
||||||
} from '../src/pages/reports/kit/reportLogic.js'
|
} from '../src/pages/reports/kit/reportLogic.js'
|
||||||
|
|
||||||
test('periods: the default, quick ranges, the parameters sent (venue time), file names', () => {
|
test('periods: the default, quick ranges, the parameters sent (venue time), file names', () => {
|
||||||
@@ -43,3 +43,10 @@ test('a receipt-printer report gets the same period', () => {
|
|||||||
assert.deepEqual(printBody({ mode: 'day', dayId: '7' }), { business_day_id: 7, from_dt: null, to_dt: null })
|
assert.deepEqual(printBody({ mode: 'day', dayId: '7' }), { business_day_id: 7, from_dt: null, to_dt: null })
|
||||||
assert.deepEqual(printBody({ mode: 'range', from: '2026-11-01', to: '2026-11-02' }), { business_day_id: null, from_dt: '2026-11-01T00:00:00', to_dt: '2026-11-02T23:59:59' })
|
assert.deepEqual(printBody({ mode: 'range', from: '2026-11-01', to: '2026-11-02' }), { business_day_id: null, from_dt: '2026-11-01T00:00:00', to_dt: '2026-11-02T23:59:59' })
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('a CSV built in the browser follows the Excel rules', () => {
|
||||||
|
const en = csvText(['Product', 'Value'], [['Freddo, iced', 3.5], ['Tea', 2]])
|
||||||
|
assert.equal(en.charCodeAt(0), 0xFEFF)
|
||||||
|
assert.deepEqual(en.slice(1).split('\r\n'), ['Product,Value', '"Freddo, iced",3.50', 'Tea,2'])
|
||||||
|
assert.deepEqual(csvText(['Π', 'Τιμή'], [['Φρέντο', 3.5]], 'el').slice(1).split('\r\n'), ['Π;Τιμή', 'Φρέντο;3,50'])
|
||||||
|
})
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
{
|
{
|
||||||
"_comment": "Plan step 6.1: what is on the v2 rules. `paths` (files or folders): `npm run lint` checks them, and tests/v2-guards.test.mjs refuses Greek and colour literals in them. `strict`: also no setState in effects (data loads with useLiveQuery / react-query). Each phase 6 step adds what it converted; 6.14 ends with `src`.",
|
"_comment": "Plan step 6.1: what is on the v2 rules. `paths` (files or folders): `npm run lint` checks them, and tests/v2-guards.test.mjs refuses Greek and colour literals in them. `strict`: also no setState in effects (data loads with useLiveQuery / react-query). Each phase 6 step adds what it converted; 6.14 ends with `src`.",
|
||||||
"paths": [
|
"paths": [
|
||||||
"src/shell", "src/live", "src/pages/platform", "src/pages/online", "src/pages/media", "src/pages/signage", "src/pages/staff", "src/pages/Settings/sections", "src/pages/LoginPage.jsx", "src/components/NotificationBell.jsx", "src/components/PhoneListener.jsx", "src/pages/PhonePage.jsx", "src/store/phoneStore.js", "src/components/UserMenuButton.jsx", "src/pages/reports/operations/LogsPanel.jsx", "src/api/client.js", "src/store/authStore.js", "src/main.jsx", "src/pages/overview", "src/hooks", "src/pages/products", "src/pages/pricing", "src/pages/floor", "src/pages/Management/TablesConfigPage.jsx", "src/pages/orders", "src/pages/printing", "src/pages/schedule", "src/pages/reports/kit", "src/pages/reports/today", "src/pages/reports/store", "src/pages/reports/products"
|
"src/shell", "src/live", "src/pages/platform", "src/pages/online", "src/pages/media", "src/pages/signage", "src/pages/staff", "src/pages/Settings/sections", "src/pages/LoginPage.jsx", "src/components/NotificationBell.jsx", "src/components/PhoneListener.jsx", "src/pages/PhonePage.jsx", "src/store/phoneStore.js", "src/components/UserMenuButton.jsx", "src/api/client.js", "src/store/authStore.js", "src/main.jsx", "src/pages/overview", "src/hooks", "src/pages/products", "src/pages/pricing", "src/pages/floor", "src/pages/Management/TablesConfigPage.jsx", "src/pages/orders", "src/pages/printing", "src/pages/schedule", "src/pages/reports"
|
||||||
],
|
],
|
||||||
"strict": [
|
"strict": [
|
||||||
"src/live", "src/pages/staff/SessionsPage.jsx", "src/pages/overview", "src/pages/online/OnlineOrdersPage.jsx", "src/hooks", "src/pages/products", "src/pages/pricing", "src/pages/floor", "src/pages/orders", "src/pages/printing", "src/pages/staff", "src/pages/schedule", "src/pages/reports/kit", "src/pages/reports/today", "src/pages/reports/store", "src/pages/reports/products"
|
"src/live", "src/pages/staff/SessionsPage.jsx", "src/pages/overview", "src/pages/online/OnlineOrdersPage.jsx", "src/hooks", "src/pages/products", "src/pages/pricing", "src/pages/floor", "src/pages/orders", "src/pages/printing", "src/pages/staff", "src/pages/schedule", "src/pages/reports/kit", "src/pages/reports/today", "src/pages/reports/store", "src/pages/reports/products", "src/pages/reports/staff", "src/pages/reports/misc", "src/pages/reports/technical", "src/pages/reports/prepzones", "src/pages/reports/expenses"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2799,11 +2799,17 @@
|
|||||||
"kind": "Τι τυπώνεται",
|
"kind": "Τι τυπώνεται",
|
||||||
"modes": {
|
"modes": {
|
||||||
"smart": "Σύνοψη",
|
"smart": "Σύνοψη",
|
||||||
"full": "Πλήρης"
|
"full": "Πλήρης",
|
||||||
|
"quick": "Γρήγορη σύνοψη",
|
||||||
|
"orders": "Κάθε παραγγελία",
|
||||||
|
"detailed": "Κάθε παραγγελία και είδος"
|
||||||
},
|
},
|
||||||
"modesHint": {
|
"modesHint": {
|
||||||
"smart": "Μόνο όσα πουλήθηκαν, τα περισσότερα πρώτα.",
|
"smart": "Μόνο όσα πουλήθηκαν, τα περισσότερα πρώτα.",
|
||||||
"full": "Όλα τα προϊόντα, και όσα δεν πουλήθηκαν."
|
"full": "Όλα τα προϊόντα, και όσα δεν πουλήθηκαν.",
|
||||||
|
"quick": "Μόνο σύνολα: λίγο χαρτί.",
|
||||||
|
"orders": "Κάθε παραγγελία με το σύνολό της.",
|
||||||
|
"detailed": "Κάθε παραγγελία με όλα τα είδη: πολύ χαρτί."
|
||||||
},
|
},
|
||||||
"printer": "Εκτυπωτής",
|
"printer": "Εκτυπωτής",
|
||||||
"noPrinters": "Δεν υπάρχουν εκτυπωτές (Ρυθμίσεις → Εκτύπωση).",
|
"noPrinters": "Δεν υπάρχουν εκτυπωτές (Ρυθμίσεις → Εκτύπωση).",
|
||||||
@@ -2922,6 +2928,140 @@
|
|||||||
"all_one": "{{count}} προϊόν",
|
"all_one": "{{count}} προϊόν",
|
||||||
"all_other": "{{count}} προϊόντα",
|
"all_other": "{{count}} προϊόντα",
|
||||||
"shareTitle": "Έσοδα ανά κατηγορία"
|
"shareTitle": "Έσοδα ανά κατηγορία"
|
||||||
|
},
|
||||||
|
"staff": {
|
||||||
|
"title": "Προσωπικό",
|
||||||
|
"tabs": {
|
||||||
|
"shifts": "Βάρδιες",
|
||||||
|
"cash": "Παράδοση ταμείου",
|
||||||
|
"people": "Πωλήσεις ανά άτομο"
|
||||||
|
},
|
||||||
|
"shiftsCount_one": "{{count}} βάρδια",
|
||||||
|
"shiftsCount_other": "{{count}} βάρδιες",
|
||||||
|
"payTotal": "Αμοιβή για αυτές τις βάρδιες: {{amount}}",
|
||||||
|
"pay": "Αμοιβή",
|
||||||
|
"payTip": "Ώρες × η ωριαία αμοιβή τη στιγμή της βάρδιας.",
|
||||||
|
"handOver": "Για παράδοση",
|
||||||
|
"handOverTip": "Αρχικά μετρητά + μετρητά που εισπράχθηκαν − μετρητά που επιστράφηκαν: όσα πρέπει να είναι στο συρτάρι.",
|
||||||
|
"difference": "Διαφορά",
|
||||||
|
"differenceTip": "Όσα μετρήθηκαν στο τέλος μείον όσα έπρεπε να υπάρχουν (− λείπουν, + περισσεύουν).",
|
||||||
|
"shift": "Βάρδια",
|
||||||
|
"starting": "Αρχικά μετρητά",
|
||||||
|
"cash": "Μετρητά",
|
||||||
|
"card": "Κάρτα",
|
||||||
|
"counted": "Μετρήθηκαν",
|
||||||
|
"open": "Ανοιχτή",
|
||||||
|
"ended": "Έληξε",
|
||||||
|
"cashTitle": "Ταμείο ανά βάρδια",
|
||||||
|
"hours": "Ώρες",
|
||||||
|
"sales": "Πωλήσεις",
|
||||||
|
"salesTip": "Όσα έστειλε κάθε άτομο (προϊόντα, μείον επιστροφές· τα έξοδα αποστολής χωριστά), όποιος κι αν πληρώθηκε.",
|
||||||
|
"perHour": "Ανά ώρα",
|
||||||
|
"ranking": "Ποιος πούλησε περισσότερο",
|
||||||
|
"people_one": "{{count}} άτομο",
|
||||||
|
"people_other": "{{count}} άτομα"
|
||||||
|
},
|
||||||
|
"misc": {
|
||||||
|
"title": "Ακυρώσεις και εκπτώσεις",
|
||||||
|
"cancellations": "Ακυρώσεις",
|
||||||
|
"discounts": "Εκπτώσεις",
|
||||||
|
"when": "Πότε",
|
||||||
|
"value": "Αξία",
|
||||||
|
"sentBy": "Το έστειλε",
|
||||||
|
"cancelledBy": "Το ακύρωσε",
|
||||||
|
"reason": "Γιατί",
|
||||||
|
"cancelledLines": "Ακυρωμένες γραμμές",
|
||||||
|
"cancelledValue": "Η αξία τους",
|
||||||
|
"notSales": "δεν μετρούν στις πωλήσεις",
|
||||||
|
"byWhom": "Ανά άτομο",
|
||||||
|
"lines_one": "{{count}} γραμμή",
|
||||||
|
"lines_other": "{{count}} γραμμές",
|
||||||
|
"discount": "Έκπτωση",
|
||||||
|
"amount": "Ποσό",
|
||||||
|
"before": "Παραγγελία πριν",
|
||||||
|
"givenBy": "Την έδωσε",
|
||||||
|
"discountsGiven": "Εκπτώσεις που δόθηκαν",
|
||||||
|
"onOrders_one": "σε {{count}} παραγγελία",
|
||||||
|
"onOrders_other": "σε {{count}} παραγγελίες",
|
||||||
|
"discountTotal": "Σύνολο εκπτώσεων",
|
||||||
|
"alreadyOff": "έχουν ήδη αφαιρεθεί από τα έσοδα",
|
||||||
|
"times_one": "{{count}} φορά",
|
||||||
|
"times_other": "{{count}} φορές"
|
||||||
|
},
|
||||||
|
"tech": {
|
||||||
|
"title": "Τεχνικά",
|
||||||
|
"printing": "Εκτυπώσεις",
|
||||||
|
"allPrinters": "Όλοι οι εκτυπωτές",
|
||||||
|
"items": "Στο δελτίο",
|
||||||
|
"result": "Αποτέλεσμα",
|
||||||
|
"printed": "Τυπώθηκε",
|
||||||
|
"failed": "Απέτυχε",
|
||||||
|
"tickets": "Δελτία που στάλθηκαν",
|
||||||
|
"failedN": "Απέτυχαν",
|
||||||
|
"checkPrinter": "ελέγξτε τον εκτυπωτή",
|
||||||
|
"allGood": "όλα τυπώθηκαν",
|
||||||
|
"reliability": "Τυπώθηκαν με την πρώτη",
|
||||||
|
"reliabilityTip": "Το ποσοστό των προσπαθειών που τυπώθηκαν. Όσα αποτυγχάνουν ξαναδοκιμάζονται μέχρι να τυπωθούν (Ρυθμίσεις → Εκτύπωση).",
|
||||||
|
"ordersValue": "Αξία παραγγελιών",
|
||||||
|
"ordersValueTip": "Η αξία των παραγγελιών αυτών των δελτίων, κάθε παραγγελία μία φορά.",
|
||||||
|
"perPrinter": "Δελτία ανά εκτυπωτή",
|
||||||
|
"failedSome_one": "{{count}} απέτυχε",
|
||||||
|
"failedSome_other": "{{count}} απέτυχαν",
|
||||||
|
"noneFailed": "κανένα δεν απέτυχε",
|
||||||
|
"jobs_one": "{{count}} δελτίο",
|
||||||
|
"jobs_other": "{{count}} δελτία"
|
||||||
|
},
|
||||||
|
"zones": {
|
||||||
|
"title": "Ζώνες προετοιμασίας",
|
||||||
|
"which": "Ζώνες που φαίνονται",
|
||||||
|
"all": "Όλες οι ζώνες",
|
||||||
|
"load": "Τι ετοίμασε κάθε ζώνη",
|
||||||
|
"loadTip": "Είδη που έφτιαξε κάθε ζώνη στην περίοδο (προϊόν σε δύο ζώνες μετράει και στις δύο).",
|
||||||
|
"items": "Είδη",
|
||||||
|
"value": "Η αξία τους",
|
||||||
|
"valueTip": "Η τιμή που πουλήθηκαν αυτά τα είδη.",
|
||||||
|
"nothing": "Τίποτα δεν ετοιμάστηκε εδώ σε αυτή την περίοδο.",
|
||||||
|
"orders_one": "{{count}} παραγγελία",
|
||||||
|
"orders_other": "{{count}} παραγγελίες",
|
||||||
|
"productsCsv": "Προϊόντα (Excel)",
|
||||||
|
"ordersCsv": "Παραγγελίες (Excel)"
|
||||||
|
},
|
||||||
|
"exp": {
|
||||||
|
"title": "Δαπάνες",
|
||||||
|
"spent": "Δαπανήθηκαν",
|
||||||
|
"count_one": "{{count}} δαπάνη",
|
||||||
|
"count_other": "{{count}} δαπάνες",
|
||||||
|
"paid": "Πληρώθηκαν",
|
||||||
|
"due": "Οφείλονται",
|
||||||
|
"split": "Πού πήγαν",
|
||||||
|
"by": {
|
||||||
|
"category": "Ανά κατηγορία",
|
||||||
|
"supplier": "Ανά προμηθευτή"
|
||||||
|
},
|
||||||
|
"dueSub": "οφείλονται {{amount}}",
|
||||||
|
"noSupplier": "Χωρίς προμηθευτή",
|
||||||
|
"list": "Όλες οι δαπάνες",
|
||||||
|
"date": "Καταχωρήθηκε",
|
||||||
|
"what": "Τι",
|
||||||
|
"supplier": "Προμηθευτής",
|
||||||
|
"total": "Σύνολο",
|
||||||
|
"status": {
|
||||||
|
"due": "Οφείλεται",
|
||||||
|
"partial": "Μερικώς",
|
||||||
|
"paid": "Πληρώθηκε"
|
||||||
|
},
|
||||||
|
"categories": {
|
||||||
|
"supplier": "Προμηθευτές",
|
||||||
|
"utilities": "Κοινή χρεία",
|
||||||
|
"rent": "Ενοίκιο",
|
||||||
|
"maintenance": "Συντήρηση",
|
||||||
|
"staff": "Προσωπικό",
|
||||||
|
"equipment": "Εξοπλισμός",
|
||||||
|
"other": "Άλλο"
|
||||||
|
},
|
||||||
|
"dueDate": "Λήξη {{date}}",
|
||||||
|
"payments": "Πληρωμές",
|
||||||
|
"noPayments": "Δεν έχει πληρωθεί τίποτα ακόμα."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2799,11 +2799,17 @@
|
|||||||
"kind": "What to print",
|
"kind": "What to print",
|
||||||
"modes": {
|
"modes": {
|
||||||
"smart": "Summary",
|
"smart": "Summary",
|
||||||
"full": "Full"
|
"full": "Full",
|
||||||
|
"quick": "Quick summary",
|
||||||
|
"orders": "Every order",
|
||||||
|
"detailed": "Every order and item"
|
||||||
},
|
},
|
||||||
"modesHint": {
|
"modesHint": {
|
||||||
"smart": "Only what sold, most first.",
|
"smart": "Only what sold, most first.",
|
||||||
"full": "Every product, unsold ones too."
|
"full": "Every product, unsold ones too.",
|
||||||
|
"quick": "Totals only: little paper.",
|
||||||
|
"orders": "Each order with its total.",
|
||||||
|
"detailed": "Each order with every item: a lot of paper."
|
||||||
},
|
},
|
||||||
"printer": "Printer",
|
"printer": "Printer",
|
||||||
"noPrinters": "No printers (Settings → Printing).",
|
"noPrinters": "No printers (Settings → Printing).",
|
||||||
@@ -2922,6 +2928,140 @@
|
|||||||
"all_one": "{{count}} product",
|
"all_one": "{{count}} product",
|
||||||
"all_other": "{{count}} products",
|
"all_other": "{{count}} products",
|
||||||
"shareTitle": "Revenue by category"
|
"shareTitle": "Revenue by category"
|
||||||
|
},
|
||||||
|
"staff": {
|
||||||
|
"title": "Staff",
|
||||||
|
"tabs": {
|
||||||
|
"shifts": "Shifts",
|
||||||
|
"cash": "Cash handover",
|
||||||
|
"people": "Sales by person"
|
||||||
|
},
|
||||||
|
"shiftsCount_one": "{{count}} shift",
|
||||||
|
"shiftsCount_other": "{{count}} shifts",
|
||||||
|
"payTotal": "Pay for these shifts: {{amount}}",
|
||||||
|
"pay": "Pay",
|
||||||
|
"payTip": "Hours × the hourly pay at the time of the shift.",
|
||||||
|
"handOver": "To hand over",
|
||||||
|
"handOverTip": "Starting cash + cash taken − cash refunded: what should be in the drawer.",
|
||||||
|
"difference": "Difference",
|
||||||
|
"differenceTip": "What was counted at the end minus what should have been there (− short, + over).",
|
||||||
|
"shift": "Shift",
|
||||||
|
"starting": "Starting cash",
|
||||||
|
"cash": "Cash taken",
|
||||||
|
"card": "Card taken",
|
||||||
|
"counted": "Counted",
|
||||||
|
"open": "Open",
|
||||||
|
"ended": "Ended",
|
||||||
|
"cashTitle": "Cash per shift",
|
||||||
|
"hours": "Hours",
|
||||||
|
"sales": "Sales",
|
||||||
|
"salesTip": "What each person sent (products, net of refunds; the delivery fee apart), whoever was paid.",
|
||||||
|
"perHour": "Per hour",
|
||||||
|
"ranking": "Who sold most",
|
||||||
|
"people_one": "{{count}} person",
|
||||||
|
"people_other": "{{count}} people"
|
||||||
|
},
|
||||||
|
"misc": {
|
||||||
|
"title": "Cancellations and discounts",
|
||||||
|
"cancellations": "Cancellations",
|
||||||
|
"discounts": "Discounts",
|
||||||
|
"when": "When",
|
||||||
|
"value": "Value",
|
||||||
|
"sentBy": "Sent by",
|
||||||
|
"cancelledBy": "Cancelled by",
|
||||||
|
"reason": "Why",
|
||||||
|
"cancelledLines": "Lines cancelled",
|
||||||
|
"cancelledValue": "Their value",
|
||||||
|
"notSales": "not counted as sales",
|
||||||
|
"byWhom": "By person",
|
||||||
|
"lines_one": "{{count}} line",
|
||||||
|
"lines_other": "{{count}} lines",
|
||||||
|
"discount": "Discount",
|
||||||
|
"amount": "Amount off",
|
||||||
|
"before": "Order before",
|
||||||
|
"givenBy": "Given by",
|
||||||
|
"discountsGiven": "Discounts given",
|
||||||
|
"onOrders_one": "on {{count}} order",
|
||||||
|
"onOrders_other": "on {{count}} orders",
|
||||||
|
"discountTotal": "Total off",
|
||||||
|
"alreadyOff": "already taken off the revenue",
|
||||||
|
"times_one": "{{count}} time",
|
||||||
|
"times_other": "{{count}} times"
|
||||||
|
},
|
||||||
|
"tech": {
|
||||||
|
"title": "Technical",
|
||||||
|
"printing": "Printing",
|
||||||
|
"allPrinters": "All printers",
|
||||||
|
"items": "On the ticket",
|
||||||
|
"result": "Result",
|
||||||
|
"printed": "Printed",
|
||||||
|
"failed": "Failed",
|
||||||
|
"tickets": "Tickets sent",
|
||||||
|
"failedN": "Failed",
|
||||||
|
"checkPrinter": "check the printer",
|
||||||
|
"allGood": "all printed",
|
||||||
|
"reliability": "Printed first time",
|
||||||
|
"reliabilityTip": "The share of attempts that printed. Failed tickets are tried again until they print (Settings → Printing).",
|
||||||
|
"ordersValue": "Orders' value",
|
||||||
|
"ordersValueTip": "The value of the orders these tickets belong to, each order once.",
|
||||||
|
"perPrinter": "Tickets per printer",
|
||||||
|
"failedSome_one": "{{count}} failed",
|
||||||
|
"failedSome_other": "{{count}} failed",
|
||||||
|
"noneFailed": "none failed",
|
||||||
|
"jobs_one": "{{count}} ticket",
|
||||||
|
"jobs_other": "{{count}} tickets"
|
||||||
|
},
|
||||||
|
"zones": {
|
||||||
|
"title": "Prep zones",
|
||||||
|
"which": "Zones shown",
|
||||||
|
"all": "All zones",
|
||||||
|
"load": "What each zone prepared",
|
||||||
|
"loadTip": "Items made by each zone in the period (a product in two zones counts in both).",
|
||||||
|
"items": "Items",
|
||||||
|
"value": "Their value",
|
||||||
|
"valueTip": "What those items were sold for.",
|
||||||
|
"nothing": "Nothing prepared here in this period.",
|
||||||
|
"orders_one": "{{count}} order",
|
||||||
|
"orders_other": "{{count}} orders",
|
||||||
|
"productsCsv": "Products (Excel)",
|
||||||
|
"ordersCsv": "Orders (Excel)"
|
||||||
|
},
|
||||||
|
"exp": {
|
||||||
|
"title": "Expenses",
|
||||||
|
"spent": "Spent",
|
||||||
|
"count_one": "{{count}} expense",
|
||||||
|
"count_other": "{{count}} expenses",
|
||||||
|
"paid": "Paid",
|
||||||
|
"due": "Still due",
|
||||||
|
"split": "Where it went",
|
||||||
|
"by": {
|
||||||
|
"category": "By category",
|
||||||
|
"supplier": "By supplier"
|
||||||
|
},
|
||||||
|
"dueSub": "{{amount}} due",
|
||||||
|
"noSupplier": "No supplier",
|
||||||
|
"list": "Every expense",
|
||||||
|
"date": "Entered",
|
||||||
|
"what": "What",
|
||||||
|
"supplier": "Supplier",
|
||||||
|
"total": "Total",
|
||||||
|
"status": {
|
||||||
|
"due": "Due",
|
||||||
|
"partial": "Partly paid",
|
||||||
|
"paid": "Paid"
|
||||||
|
},
|
||||||
|
"categories": {
|
||||||
|
"supplier": "Supplies",
|
||||||
|
"utilities": "Utilities",
|
||||||
|
"rent": "Rent",
|
||||||
|
"maintenance": "Maintenance",
|
||||||
|
"staff": "Staff",
|
||||||
|
"equipment": "Equipment",
|
||||||
|
"other": "Other"
|
||||||
|
},
|
||||||
|
"dueDate": "Due by {{date}}",
|
||||||
|
"payments": "Payments",
|
||||||
|
"noPayments": "Nothing paid yet."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1216,6 +1216,27 @@ try {
|
|||||||
await page.getByTestId('report-tab-categories').click()
|
await page.getByTestId('report-tab-categories').click()
|
||||||
r.check(`${rp} Products → Categories opens`, await page.getByTestId('categories-share').waitFor({ timeout: 10_000 }).then(() => true).catch(() => false))
|
r.check(`${rp} Products → Categories opens`, await page.getByTestId('categories-share').waitFor({ timeout: 10_000 }).then(() => true).catch(() => false))
|
||||||
await page.screenshot({ path: path.join(OUT, 'manager-report-categories.png'), fullPage: true })
|
await page.screenshot({ path: path.join(OUT, 'manager-report-categories.png'), fullPage: true })
|
||||||
|
// 6.12c: staff, cancellations and discounts, technical, prep zones, expenses
|
||||||
|
const opens = async (url, testId, what) => {
|
||||||
|
await page.goto(`${APP}${url}`)
|
||||||
|
r.check(`${rp} ${what} opens`, await page.getByTestId(testId).first().waitFor({ timeout: 10_000 }).then(() => true).catch(() => false))
|
||||||
|
}
|
||||||
|
await opens('/reports/staff', 'report-shift', 'Staff → Shifts (rows)')
|
||||||
|
await page.getByTestId('report-shift').first().click()
|
||||||
|
r.check(`${rp} a shift opens its details`, await page.getByTestId('shift-dialog').waitFor({ timeout: 8000 }).then(() => true).catch(() => false))
|
||||||
|
await page.keyboard.press('Escape')
|
||||||
|
await page.getByTestId('report-tab-cash').click()
|
||||||
|
r.check(`${rp} Staff → Cash handover`, await page.getByTestId('staff-handover').waitFor({ timeout: 8000 }).then(() => true).catch(() => false))
|
||||||
|
await page.getByTestId('report-tab-people').click()
|
||||||
|
r.check(`${rp} Staff → Sales by person ranks people`, await page.getByTestId('staff-ranking').waitFor({ timeout: 8000 }).then(() => true).catch(() => false))
|
||||||
|
await page.screenshot({ path: path.join(OUT, 'manager-report-staff.png'), fullPage: true })
|
||||||
|
await opens('/reports/misc', 'cancellations-count', 'Cancellations')
|
||||||
|
await page.getByTestId('report-tab-discounts').click()
|
||||||
|
r.check(`${rp} Discounts opens`, await page.getByTestId('report-period').waitFor({ timeout: 8000 }).then(() => true).catch(() => false))
|
||||||
|
await opens('/reports/technical', 'printing-total', 'Technical → Printing')
|
||||||
|
await opens('/reports/prep-zones', 'report-period', 'Prep zones')
|
||||||
|
await opens('/reports/expenses', 'expenses-total', 'Expenses')
|
||||||
|
await page.screenshot({ path: path.join(OUT, 'manager-report-expenses.png'), fullPage: true })
|
||||||
|
|
||||||
await api('PUT', '/api/platform/modules/connect_orders', { token: boss, body: { enabled: true } })
|
await api('PUT', '/api/platform/modules/connect_orders', { token: boss, body: { enabled: true } })
|
||||||
await page.goto(`${APP}/online-orders`)
|
await page.goto(`${APP}/online-orders`)
|
||||||
|
|||||||
Reference in New Issue
Block a user