- 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>
53 lines
3.6 KiB
JavaScript
53 lines
3.6 KiB
JavaScript
// The report kit's plain data (plan step 6.12a).
|
|
import { test } from 'node:test'
|
|
import assert from 'node:assert/strict'
|
|
import {
|
|
addDays, csvText, dayChoices, defaultPeriod, hourSeries, margin, orderTotals, periodParams, periodSlug, printBody, quickRange, rangeProblem, ratio, sortRows,
|
|
} from '../src/pages/reports/kit/reportLogic.js'
|
|
|
|
test('periods: the default, quick ranges, the parameters sent (venue time), file names', () => {
|
|
assert.deepEqual(defaultPeriod('2026-11-19'), { mode: 'range', from: '2026-10-21', to: '2026-11-19', dayId: '' })
|
|
assert.deepEqual(quickRange('week', '2026-11-19'), { from: '2026-11-13', to: '2026-11-19' })
|
|
assert.deepEqual(quickRange('month', '2026-11-19'), { from: '2026-11-01', to: '2026-11-19' })
|
|
assert.equal(addDays('2026-03-01', -1), '2026-02-28')
|
|
assert.deepEqual(periodParams({ mode: 'range', from: '2026-11-01', to: '2026-11-19' }), { from: '2026-11-01T00:00:00', to: '2026-11-19T23:59:59' })
|
|
assert.deepEqual(periodParams({ mode: 'day', dayId: '12' }), { business_day_id: '12' })
|
|
assert.deepEqual(periodParams({ mode: 'day', dayId: '' }), {})
|
|
assert.equal(periodSlug({ mode: 'range', from: '2026-11-01', to: '2026-11-19' }), '2026-11-01_2026-11-19')
|
|
assert.equal(rangeProblem({ mode: 'range', from: '2026-11-19', to: '2026-11-01' }), 'order')
|
|
assert.equal(rangeProblem({ mode: 'range', from: '2024-01-01', to: '2026-11-01' }), 'long')
|
|
assert.equal(rangeProblem({ mode: 'day' }), null)
|
|
})
|
|
|
|
test('numbers: ratios, margins, sorting (numbers, text, empty last, stable)', () => {
|
|
assert.equal(ratio(1, 4), 0.25)
|
|
assert.equal(ratio(1, 0), 0)
|
|
assert.equal(margin(6, 13), 6 / 13)
|
|
assert.equal(margin(0, 0), null)
|
|
const rows = [{ n: 'b', v: 2 }, { n: 'a', v: null }, { n: 'c', v: 10 }, { n: 'd', v: 2 }]
|
|
assert.deepEqual(sortRows(rows, 'v').map(r => r.n), ['c', 'b', 'd', 'a'])
|
|
assert.deepEqual(sortRows(rows, 'v', 'asc').map(r => r.n), ['b', 'd', 'c', 'a'])
|
|
assert.deepEqual(sortRows(rows, 'n', 'asc').map(r => r.n), ['a', 'b', 'c', 'd'])
|
|
assert.deepEqual(sortRows(rows, r => r.n.charCodeAt(0), 'desc').map(r => r.n), ['d', 'c', 'b', 'a'])
|
|
})
|
|
|
|
test('a day by the hour, an order\'s totals, business days newest first', () => {
|
|
const s = hourSeries([{ hour: 12, revenue: 30, orders: 2 }, { hour: 3, revenue: 5 }], { from: 11, to: 13 })
|
|
assert.deepEqual(s.map(h => [h.hour, h.revenue]), [[3, 5], ...Array.from({ length: 7 }, (_, i) => [4 + i, 0]), [11, 0], [12, 30], [13, 0]]) // widened to 03:00
|
|
assert.equal(orderTotals({ totals: { revenue: 13, fees: 2.5 } }).fees, 2.5)
|
|
assert.equal(orderTotals({ items: [{ status: 'paid', unit_price: 4, price_adjustment: -1, quantity: 2 }, { status: 'cancelled', unit_price: 9, quantity: 1 }] }).revenue, 6)
|
|
assert.deepEqual(dayChoices([{ id: 1, opened_at: '2026-11-17' }, { id: 2, opened_at: '2026-11-19' }]).map(d => d.id), [2, 1])
|
|
})
|
|
|
|
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: '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'])
|
|
})
|