From the owner's page-by-page review (2026-11-20): - every page root is <Page> (scrolls, fills 1080p, 16:9 centred on ultrawides); not yet: products, management/tables, stock (next pass) - /dashboard: more padding in cards (p-card), quieter secondary text, 11px uppercase labels everywhere (text-overline) - day stats: xl dialog, "● Day running · Opened …" as text, the six figures in equal boxes, "On tabs" in the payments bar, shared Tabs - /tables: Segmented List / Map / QR codes (?view=; /online/qr redirects), filter chips + zones multi-select at one height, the card itself opens the table (button removed), cards ~20% wider - /online-orders: shared Tabs with Settings (= the old /online/fees page, which redirects to ?tab=settings); orders fill the width - contacts, customers, expenses: PageHeader + Toolbar + SearchInput + multi-select Dropdowns (kinds; statuses, categories); table cells vertically centred; the Spent tip opens on hover - filterCards / filterContacts / filterExpenses take several values (unit tests added) - docs/DESIGN.md: the design language (CS-20 in the pack README) - tests/e2e/manager_layout.mjs: the page rule at 1920x1080 and 3440x1440; manager.mjs and manager_look.mjs follow the moved pages Verified: manager build + lint (0 errors), unit tests (manager 99, ui 24, i18n 31, api 25, access 8), i18n guard, manager_layout.mjs all passed, manager.mjs 228 checks all passed. Not checked: the waiter app and the terminal by eye (they only get the muted ink-2 token). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
71 lines
4.7 KiB
JavaScript
71 lines
4.7 KiB
JavaScript
// Expenses, the supplier book and tabs as plain data (plan step 6.13a).
|
|
import { test } from 'node:test'
|
|
import assert from 'node:assert/strict'
|
|
import {
|
|
contactBody, contactForm, contactProblems, daysBetween, expenseBody, expenseForm, expenseProblems, expenseTotals,
|
|
filterContacts, filterExpenses, filterTabs, isLate, owedByContact, paymentAmount, tabActions, tabTotals,
|
|
} from '../src/pages/finance/financeLogic.js'
|
|
|
|
const key = iso => iso.slice(0, 10)
|
|
const expenses = [
|
|
{ id: 1, description: 'Γάλα Νοεμβρίου', category: 'supplier', contact_id: 7, contact_name: 'Dairy Nikos', total_amount: 120, paid_amount: 70, due_amount: 50, status: 'partial', due_date: '2026-11-18T22:00:00Z' },
|
|
{ id: 2, description: 'Rent', category: 'rent', contact_id: null, total_amount: 800, paid_amount: 800, due_amount: 0, status: 'paid', due_date: '2026-11-01T00:00:00Z' },
|
|
{ id: 3, description: 'Feta', category: 'supplier', contact_id: 7, contact_name: 'Dairy Nikos', total_amount: 40, paid_amount: 0, due_amount: 40, status: 'due', due_date: null, notes: 'two tins' },
|
|
]
|
|
|
|
test('an expense form: typed amounts with a comma, the due date as a venue date, cleared fields as null', () => {
|
|
const f = expenseForm(expenses[0], key)
|
|
assert.equal(f.due_date, '2026-11-18')
|
|
assert.equal(f.contact_id, '7')
|
|
assert.deepEqual(expenseProblems({ ...f, total_amount: '120,50' }, 70), [])
|
|
assert.deepEqual(expenseProblems({ ...f, description: ' ', total_amount: '0' }), ['description', 'total_amount'])
|
|
assert.deepEqual(expenseProblems({ ...f, total_amount: '60' }, 70), ['below_paid'])
|
|
assert.deepEqual(expenseBody({ ...f, total_amount: '120,50', contact_id: '', due_date: '', notes: ' ' }),
|
|
{ description: 'Γάλα Νοεμβρίου', category: 'supplier', contact_id: null, total_amount: 120.5, due_date: null, notes: null })
|
|
assert.equal(expenseForm(null).category, 'supplier')
|
|
})
|
|
|
|
test('a payment is above zero and no more than what is due', () => {
|
|
assert.equal(paymentAmount('50', 50), 50)
|
|
assert.equal(paymentAmount('20,25', 50), 20.25)
|
|
assert.equal(paymentAmount('50,01', 50), null)
|
|
assert.equal(paymentAmount('0', 50), null)
|
|
assert.equal(paymentAmount('abc', 50), null)
|
|
})
|
|
|
|
test('filters, totals, late ones and what each supplier is owed', () => {
|
|
assert.deepEqual(filterExpenses(expenses, { status: 'unpaid' }).map(e => e.id), [1, 3])
|
|
assert.deepEqual(filterExpenses(expenses, { category: 'rent' }).map(e => e.id), [2])
|
|
assert.deepEqual(filterExpenses(expenses, { status: ['due', 'partial'] }).map(e => e.id), [1, 3]) // multi-select
|
|
assert.deepEqual(filterExpenses(expenses, { status: [], category: ['rent', 'supplier'] }).map(e => e.id), [1, 2, 3])
|
|
assert.deepEqual(filterExpenses(expenses, { q: 'nikos tins' }).map(e => e.id), [3])
|
|
assert.deepEqual(filterExpenses(expenses, { q: 'γάλα' }).map(e => e.id), [1])
|
|
assert.equal(isLate(expenses[0], '2026-11-19', key), true)
|
|
assert.equal(isLate(expenses[1], '2026-11-19', key), false) // paid
|
|
assert.deepEqual(expenseTotals(expenses, '2026-11-19', key), { total: 960, paid: 870, due: 90, unpaid: 2, late: 1 })
|
|
assert.deepEqual(owedByContact(expenses), { 7: { due: 90, count: 2 } })
|
|
})
|
|
|
|
test('a contact: name needed, a wrong e-mail caught, empty fields cleared', () => {
|
|
const f = contactForm(null)
|
|
assert.deepEqual(contactProblems(f), ['name'])
|
|
assert.deepEqual(contactProblems({ ...f, name: 'A', email: 'nope' }), ['email'])
|
|
assert.deepEqual(contactBody({ ...f, name: ' Dairy ', phone: ' ' }), { name: 'Dairy', type: 'supplier', phone: null, email: null, address: null, notes: null })
|
|
const list = [{ id: 1, name: 'Dairy Nikos', type: 'supplier', phone: '2310' }, { id: 2, name: 'DEH', type: 'utility' }]
|
|
assert.deepEqual(filterContacts(list, { type: 'utility' }).map(c => c.id), [2])
|
|
assert.deepEqual(filterContacts(list, { type: ['utility', 'supplier'] }).map(c => c.id), [1, 2])
|
|
assert.deepEqual(filterContacts(list, { q: '2310' }).map(c => c.id), [1])
|
|
})
|
|
|
|
test('tabs: what can be done, days open, search and what is owed', () => {
|
|
const owing = { status: 'open', balance: 12, entries: [{}] }
|
|
assert.deepEqual(tabActions(owing), { pay: true, close: false, forgive: true })
|
|
assert.deepEqual(tabActions({ ...owing, balance: 0 }), { pay: false, close: true, forgive: false })
|
|
assert.deepEqual(tabActions({ ...owing, status: 'closed', balance: 0 }), { pay: false, close: false, forgive: false })
|
|
assert.equal(daysBetween('2026-11-01', '2026-11-19'), 18)
|
|
assert.equal(daysBetween('2026-11-19', '2026-11-19'), 0)
|
|
const tabs = [{ customer_name: 'Kostas «Big K»', customer_phone: '697', balance: 12 }, { customer_name: 'Anna', balance: 3.5 }]
|
|
assert.equal(filterTabs(tabs, 'big').length, 1)
|
|
assert.deepEqual(tabTotals(tabs), { owed: 15.5, count: 2 })
|
|
})
|