// Reports → Moves (plan 6F.4, owner 2026-11-23): every move between tables and orders in a period:
// a whole table moved, lines moved to another table, tables joined; from / to, who, the lines
// with their quantities and value; counts per kind and per person; export for Excel.
// GET /api/reports/moves (+ /export).
import { useState } from 'react'
import { useFormat, useTranslation } from '@xenia/i18n'
import { Dropdown, Toolbar } from '@xenia/ui'
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'
const KINDS = ['table_transfer', 'items_moved', 'orders_merged']
export default function MovesReport() {
const { t } = useTranslation('manager')
return
}
function MovesBody() {
const { t } = useTranslation('manager')
const fmt = useFormat()
const [period, setPeriod] = useState(() => defaultPeriod(fmt.venueToday()))
const [kinds, setKinds] = useState([])
const params = { ...periodParams(period), ...(kinds.length === 1 ? { kind: kinds[0] } : {}) }
const { data, isPending, error, refetch } = useLiveQuery({ queryKey: ['report-moves', params], queryFn: () => client.get('/api/reports/moves', { params }).then(r => r.data) })
const rows = (data?.moves ?? []).filter(m => !kinds.length || kinds.includes(m.kind))
const columns = [
{ key: 'at', label: t('reports.misc.when'), render: m => fmt.formatDateTime(m.at, 'datetimeShort') },
{ key: 'kind', label: t('reports.moves.kind'), render: m => t(`reports.moves.kinds.${m.kind}`) },
{ key: 'from_table', label: t('reports.moves.from'), render: m => {m.from_table || t('reports.noTable')} },
{ key: 'to_table', label: t('reports.moves.to'), render: m => {m.to_table || t('reports.noTable')} },
{ key: 'items', label: t('reports.moves.lines'), sortable: false,
render: m => {m.items.map(i => `${i.name ?? `#${i.item_id}`}${i.quantity != null ? ` ×${fmt.formatNumber(i.quantity, { maxDecimals: 3 })}` : ''}`).join(', ')} },
{ key: 'value', label: t('reports.misc.value'), align: 'right', render: m => fmt.formatMoney(m.value) },
{ key: 'by', label: t('reports.moves.by'), render: m => m.by || '' },
{ key: 'orders', label: '#', sortable: false, render: m => #{m.from_order_id}{m.to_order_id !== m.from_order_id ? ` → #${m.to_order_id}` : ''} },
]
return (
} />
({ value: k, label: t(`reports.moves.kinds.${k}`) }))} data-testid="moves-kind" />
{isPending ?
: error ?
: (<>
{KINDS.map(k => )}
{data.by_person.length > 1 && (
fmt.formatNumber(v)} rows={data.by_person.map(p => ({ key: p.user_id ?? '—', label: p.name ?? '—', value: p.count }))} />
)}
>)}
)
}