'use strict'; // O2C module pack UI (MOCK Oracle Fusion-style Order-to-Cash; NOT Oracle software; synthetic data only). // Page/label names follow the O2C case YAML steps; automation keeps the mapping in automation/src/modules/o2c/labels.ts. const S = require('./store'); const EXT = require('./extensions'); const { STATUS, LINE_STATUS, TRX_STATUS, RCPT_STATUS } = require('./rest'); const U = require('../../core/ui'); const { AppError } = require('../../core/errors'); const { esc, inp, sel, hid, btn, form, table, tr, money, dl, T, back, layout } = U; const page = (fn) => U.page(fn, 'o2c'); const act = (fn) => U.act(fn, 'o2c'); const guard = (role, action) => { if (!S.can(role, action)) throw new AppError(403, 'FORBIDDEN', `You are not authorized to access this page (persona ${role} lacks ${action}).`); }; const today = () => new Date().toISOString().slice(0, 10); const MEMO_LINES = ['ZZ Consulting Services (MOCK)', 'ZZ Support Fee (MOCK)']; const SOURCES_MANUAL = ['ZZ Manual (MOCK)']; const ACTIVITIES = ['ZZ Small Balance Adjustment (MOCK)']; const TASKS = [ ['Create Order', '/o2c/orders/new', (r) => S.can(r, 'order.create') && r !== 'integration_user'], ['Manage Orders', '/o2c/orders', (r) => ['order_entry', 'credit_manager'].includes(r)], ['Manage Credit Holds', '/o2c/credit-holds', (r) => S.can(r, 'credit.release')], ['Confirm Pick Slips', '/o2c/pick-slips', (r) => S.can(r, 'ship.pick')], ['Manage Shipments', '/o2c/shipments', (r) => S.can(r, 'ship.confirm')], ['Create Transaction', '/o2c/transactions/new', (r) => S.can(r, 'trx.create')], ['Manage Transactions', '/o2c/transactions', (r) => ['billing_specialist', 'ar_specialist', 'ar_manager'].includes(r)], ['Create Adjustment', '/o2c/adjustments/new', (r) => S.can(r, 'adj.create')], ['Approve Adjustments', '/o2c/adjustments', (r) => S.can(r, 'adj.approve')], ['Create Receipt', '/o2c/receipts/new', (r) => S.can(r, 'receipt.create')], ['Manage Receipts', '/o2c/receipts', (r) => ['ar_specialist', 'ar_manager'].includes(r)], ['Manage Customers', '/o2c/customers', (r) => S.can(r, 'customer.view')], ['Manage Credit Memo Requests', '/o2c/cmrs', (r) => S.can(r, 'cm.create') || S.can(r, 'cmr.approve')], ['Collections workbench', '/o2c/collections', (r) => S.can(r, 'collections')], ['Manage Price Lists', '/o2c/pricing/price-lists', (r) => S.can(r, 'pricing.admin')], ['Manage Pricing Strategies', '/o2c/pricing/strategies', (r) => S.can(r, 'pricing.admin')], ]; const chk = (name, label) => ``; const custOpts = (role) => S.list('customers').filter((c) => S.buOk(role, c.bu) && c.status === 'ACTIVE').map((c) => c.name); const journal = (lines) => table('Journal Lines', ['Line', 'Side', 'Account Class', 'Amount'], lines.map((l) => tr([l.lineNum, l.side, esc(l.accountClass), money(l.amount)], `data-testid="journal-line"`)), 'journal-lines'); // Tabs are links with role="tab" (server-rendered; the selected tab's panel is the only one rendered). const tabs = (base, list, cur) => `
No results found.
'); function mount(app) { // ---------------- customers (O2C-SEC-005; bank accounts stored masked; ASSUMED SoD in store.js PERMS) app.get('/o2c/customers', page((req, role) => { guard(role, 'customer.view'); const q = req.query.name || ''; const rows = req.query.name !== undefined ? S.customersFor(role, q) : []; return layout(req, role, 'Manage Customers', (S.can(role, 'customer.create') ? `Create` : '') + form('/o2c/customers', inp('name', 'Organization Name', { value: q }) + btn('Search'), 'get') + (req.query.name !== undefined ? table('Customers', ['Organization Name', 'Account Number', 'Business Unit', 'Status'], rows.map((c) => tr([`${esc(c.name)}`, esc(c.accountNumber), esc(c.bu), Tt(c.status)]))) + none(rows) : '')); })); app.get('/o2c/customers/new', page((req, role) => { guard(role, 'customer.create'); return layout(req, role, 'Create Customer', form('/o2c/customers/new', inp('name', 'Organization Name') + inp('accountNumber', 'Account Number') + inp('addressLine1', 'Address Line 1') + `` + back('/o2c/customers/new') + btn('Save and Close'))); })); app.post('/o2c/customers/new', act((req, role) => { const c = S.createCustomer(role, req.body); return [`/o2c/customers?name=${encodeURIComponent(c.name)}`, `Customer ${c.name} created: account ${c.accountNumber}, site uses ${c.siteUses.map((u) => (u === 'BILL_TO' ? 'Bill-to' : 'Ship-to')).join(', ')}.`]; })); app.post('/o2c/customers/:id/payment', act((req, role) => { const c = S.setPaymentDetails(role, req.params.id, req.body); return [`/o2c/customers/${c.id}?tab=Payment%20Details`, `Payment details saved: terms ${c.paymentTerms}, receipt method ${c.receiptMethod || 'none'}.`]; })); app.get('/o2c/customers/:id', page((req, role) => { guard(role, 'customer.view'); const c = S.customersFor(role).find((x) => x.id === req.params.id); if (!c) throw new AppError(404, 'NOT_FOUND', `Customer ${req.params.id} not found.`); const base = `/o2c/customers/${c.id}`; const edit = S.can(role, 'customer.bank.edit'); const cur = req.query.tab; return layout(req, role, `Customer ${c.name}`, dl([['Organization Name', esc(c.name), 'o2c-cust-name'], ['Account Number', esc(c.accountNumber), 'o2c-cust-account']]) + tabs(base, ['Payment Details'], cur) + (cur === 'Payment Details' ? panel('Payment Details', dl([['Payment Terms', esc(c.paymentTerms), 'o2c-cust-terms'], ['Receipt Method', esc(c.receiptMethod || ''), 'o2c-cust-receipt-method']]) + (edit ? form(`${base}/payment`, sel('paymentTerms', 'Payment Terms', S.config().paymentTermsList, { value: c.paymentTerms }) + sel('receiptMethod', 'Receipt Method', ['', ...S.RECEIPT_METHODS, S.config().cardReceiptMethod], { value: c.receiptMethod || '' }) + btn('Save and Close')) : '') + table('Cards', ['Card Number', 'Token'], (c.cards || []).map((k) => tr([`************${esc(k.last4)}`, esc(k.token)])), 'cust-cards') + table('Bank Accounts', ['Bank', 'Account Number', 'Currency', 'Primary'], c.bankAccounts.map((a) => tr([esc(a.bank), esc(a.accountMasked), esc(a.currency), a.primary ? 'Yes' : 'No'])), 'cust-bank-accounts') + (edit ? (req.query.create ? dialog('Create Bank Account', form(`${base}/bank-accounts`, inp('bank', 'Bank') + inp('accountNumber', 'Account Number') + hid('__back', base) + btn('Save'))) : `Create`) : '')) : '')); })); app.post('/o2c/customers/:id/bank-accounts', act((req, role) => { const c = S.addCustomerBankAccount(role, req.params.id, req.body); return [`/o2c/customers/${c.id}?tab=Payment%20Details`, `Bank account ${c.bankAccounts[c.bankAccounts.length - 1].accountMasked} created.`]; })); // ---------------- orders app.get('/o2c/orders/new', page((req, role) => { guard(role, 'order.create'); return layout(req, role, 'Create Order', form('/o2c/orders/new', sel('customerName', 'Customer', custOpts(role)) + sel('bu', 'Business Unit', S.PERSONAS[role].bus) + inp('customerPO', 'Purchase Order') + EXT.PAGE_EXTENSIONS.map((f) => sel(f.field, f.label, ['', ...f.values])).join('') + inp('item', 'Search Item', { type: 'search' }) + inp('quantity', 'Quantity', { type: 'number' }) + back('/o2c/orders/new') + btn('Add'))); })); app.post('/o2c/orders/new', act((req, role) => { const b = req.body; const o = S.createOrder(role, { customerName: b.customerName, bu: b.bu, customerPO: b.customerPO, ...Object.fromEntries(EXT.PAGE_EXTENSIONS.map((f) => [f.field, b[f.field]])), lines: [{ item: b.item, quantity: b.quantity }] }); return [`/o2c/orders/${o.id}`, `Line added: item ${b.item}, quantity ${b.quantity}. Order ${o.number} saved as draft.`]; })); app.post('/o2c/orders/:id/lines', act((req, role) => { const o = S.addOrderLine(role, req.params.id, req.body); return [`/o2c/orders/${o.id}`, `Line added: item ${req.body.item}, quantity ${req.body.quantity}.`]; })); app.post('/o2c/orders/:id/submit', act((req, role) => { const o = S.submitOrder(role, req.params.id); return [`/o2c/orders/${o.id}`, `Order ${o.number} submitted. Status ${STATUS[o.status]}.`]; })); app.get('/o2c/orders/:id', page((req, role) => { guard(role, 'order.view'); const o = S.findOrder(role, req.params.id); const ln = req.query.line ? o.lines.find((l) => String(l.lineNum) === String(req.query.line)) : null; const draft = o.status === 'DRAFT' && S.can(role, 'order.create'); const base = `/o2c/orders/${o.id}`; const revising = req.query.revise && S.can(role, 'order.revise') && o.status === 'PROCESSING'; const view = req.query.view; const menu = [...(S.can(role, 'hold.apply') && o.status === 'PROCESSING' ? [['Apply Hold', 'apply-hold']] : []), ...(S.can(role, 'hold.release') && o.holds.some((h) => h.active && h.code === 'MANUAL') ? [['Release Hold', 'release-hold']] : [])]; return layout(req, role, `Order ${o.number}`, dl([['Order', esc(o.number), 'o2c-order-number'], ['Status', STATUS[o.status], 'o2c-order-status'], ['Business Unit', esc(o.bu)], ['Customer', esc(o.customerName), 'o2c-order-customer'], ['Bill-to Site', esc(o.billToSite), 'o2c-bill-to'], ['Ship-to Site', esc(o.shipToSite), 'o2c-ship-to'], ['Purchase Order', esc(o.customerPO)], ['Shipping Instructions', esc(o.shippingInstructions || ''), 'o2c-ship-instructions'], ...EXT.PAGE_EXTENSIONS.map((f) => [f.label, esc((o.ext || {})[f.field] || ''), `o2c-ext-${f.field}`]), ['Subtotal', money(o.subtotal), 'o2c-order-subtotal'], ['Estimated Tax', money(o.tax), 'o2c-order-tax'], ['Total', money(o.total), 'o2c-order-total'], ['Version', String((o.revision || 0) + 1), 'o2c-order-version']]) + (S.can(role, 'order.revise') && o.status === 'PROCESSING' && !revising && o.lines.some((l) => l.status === 'AWAITING_SHIPPING') ? `Revise` : '') + (revising ? `Revising order ${esc(o.number)}: version ${(o.revision || 0) + 2}.
` : '') + (menu.length ? actions(base, menu) : '') + (view === 'apply-hold' && S.can(role, 'hold.apply') ? dialog('Apply Hold', form(`${base}/hold`, sel('holdName', 'Hold Name', S.config().manualHolds) + inp('comments', 'Comments') + btn('OK'))) : '') + (view === 'release-hold' && S.can(role, 'hold.release') ? dialog('Release Hold', form(`${base}/release-hold`, inp('comments', 'Comments') + btn('OK'))) : '') + table('Order Lines', ['Line', 'Item', 'Quantity', 'Unit List Price', 'Discount', 'Unit Selling Price', 'Extended Amount', 'Status', 'Fulfilled'], o.lines.map((l) => tr([`Line ${l.lineNum}`, esc(l.item), l.quantity, money(l.listPrice), money(l.discountPerUnit), money(l.unitSellingPrice), money(l.extendedAmount), LINE_STATUS[l.status], l.fulfilledQty], `data-testid="order-line-${l.lineNum}"`)), 'order-lines') + (ln && revising ? `` : '') + (ln && !revising ? `Find the transaction, then use Create Adjustment on it.
' + trxSearch(req, role, 'Transactions', '/o2c/adjustments/new')); })); app.get('/o2c/adjustments', page((req, role) => { guard(role, 'adj.approve'); const n = (req.query.trx || '').trim(); const rows = S.list('adjustments').filter((a) => a.status === 'PENDING_APPROVAL' && (!n || a.invoiceNumber === n) && S.buOk(role, S.findInvoice(null, a.invoiceId).bu)); return layout(req, role, 'Approve Adjustments', form('/o2c/adjustments', inp('trx', 'Transaction Number', { value: n }) + btn('Search'), 'get') + table('Pending Adjustments', ['Adjustment', 'Transaction', 'Activity', 'Amount', 'Created By', ''], rows.map((a) => tr([esc(a.number), esc(a.invoiceNumber), esc(a.activity), money(a.amount), esc(a.createdBy), form(`/o2c/adjustments/${a.id}/approve`, btn('Approve'))])), 'pending-adjustments') + none(rows)); })); app.post('/o2c/adjustments/:id/approve', act((req, role) => { const a = S.approveAdjustment(role, req.params.id); const i = S.findInvoice(null, a.invoiceId); return [`/o2c/adjustments?trx=${a.invoiceNumber}`, `Adjustment ${a.number} approved; transaction ${i.number} balance ${money(i.balance)}.`]; })); // ---------------- receipts app.get('/o2c/receipts/new', page((req, role) => { guard(role, 'receipt.create'); return layout(req, role, 'Create Receipt', form('/o2c/receipts/new', sel('bu', 'Business Unit', S.PERSONAS[role].bus) + sel('method', 'Receipt Method', S.RECEIPT_METHODS) + inp('number', 'Receipt Number') + inp('amount', 'Entered Amount') + sel('customerName', 'Customer Name', custOpts(role)) + inp('receiptDate', 'Receipt Date', { type: 'date', value: today() }) + back('/o2c/receipts/new') + btn('Save'))); })); app.post('/o2c/receipts/new', act((req, role) => { const b = req.body; const r = S.createReceipt(role, { bu: b.bu, method: b.method, number: b.number || undefined, amount: Number(b.amount), customerName: b.customerName, receiptDate: b.receiptDate }); return [`/o2c/receipts/${r.id}`, `Receipt ${r.number} saved, unapplied ${money(r.unapplied)}.`]; })); app.get('/o2c/receipts/:id', page((req, role) => { guard(role, 'receipt.view'); const r = S.findReceipt(role, req.params.id); const n = (req.query.trx || '').trim(); const so = (req.query.salesOrder || '').trim(); const open = req.query.apply ? S.invoicesFor(role).filter((i) => i.balance > 0 && i.customerId === r.customerId && (!n || i.number === n) && (!so || i.salesOrder === so)) : []; return layout(req, role, `Receipt ${r.number}`, dl([['Receipt Number', esc(r.number), 'o2c-rcpt-number'], ['Status', RCPT_STATUS[r.status], 'o2c-rcpt-status'], ['Customer Name', esc(r.customerName)], ['Receipt Method', esc(r.method)], ['Entered Amount', money(r.amount), 'o2c-rcpt-amount'], ['Unapplied Amount', money(r.unapplied), 'o2c-rcpt-unapplied']]) + table('Applications', ['Transaction', 'Applied Amount'], r.applications.map((a) => tr([esc(a.invoiceNumber), money(a.amount)])), 'applications') + (S.can(role, 'receipt.create') && r.unapplied > 0 ? (req.query.apply ? `` : form(`/o2c/receipts/${r.id}`, hid('apply', '1') + btn('Add Open Receivables'), 'get')) : '') + (S.can(role, 'receipt.create') && r.unapplied > 0 && !req.query.apply ? (req.query.onAccount ? dialog('Apply On Account', form(`/o2c/receipts/${r.id}/on-account`, inp('amount', 'Applied Amount', { value: r.unapplied.toFixed(2) }) + btn('OK'))) : form(`/o2c/receipts/${r.id}`, hid('onAccount', '1') + btn('Apply On Account'), 'get')) : '') + (r.onAccount ? dl([['On-Account Amount', money(r.onAccount), 'o2c-rcpt-on-account']]) : '') + (S.can(role, 'receipt.create') ? form(`/o2c/receipts/${r.id}/close`, btn('Save and Close')) : '') + actions(`/o2c/receipts/${r.id}`, [['View Accounting', 'accounting']]) + (req.query.view === 'accounting' ? dialog('View Accounting', journal(S.accountingFor('Receipt', r.id))) : '')); })); app.post('/o2c/receipts/:id/apply', act((req, role) => { const r = S.applyReceipt(role, req.params.id, req.body.invoiceId, req.body.amount !== undefined && req.body.amount !== '' ? Number(req.body.amount) : undefined); const a = r.applications[r.applications.length - 1]; return [`/o2c/receipts/${r.id}`, `Applied ${money(a.amount)} to ${a.invoiceNumber}; unapplied ${money(r.unapplied)}.`]; })); app.post('/o2c/receipts/:id/on-account', act((req, role) => { const r = S.applyOnAccount(role, req.params.id, Number(req.body.amount)); return [`/o2c/receipts/${r.id}`, `On-account ${money(r.onAccount)}; unapplied ${money(r.unapplied)}.`]; })); app.post('/o2c/receipts/:id/close', act((req, role) => { const r = S.findReceipt(role, req.params.id); return [`/o2c/receipts?receipt=${encodeURIComponent(r.number)}`, `Receipt ${r.number} saved: applied ${money(r.amount - r.unapplied)}, unapplied ${money(r.unapplied)}.`]; })); app.get('/o2c/receipts', page((req, role) => { guard(role, 'receipt.view'); const q = (req.query.receipt || '').trim(); const rows = S.list('receipts').filter((r) => S.buOk(role, r.bu) && (!q || r.number === q)); return layout(req, role, 'Manage Receipts', form('/o2c/receipts', inp('receipt', 'Receipt Number', { value: q }) + btn('Search'), 'get') + table('Receipts', ['Receipt Number', 'Customer', 'Amount', 'Unapplied', 'Status'], rows.map((r) => tr([`${esc(r.number)}`, esc(r.customerName), money(r.amount), money(r.unapplied), RCPT_STATUS[r.status]])), 'receipts') + none(rows)); })); // ---------------- credit memo requests (O2C-CM-004; threshold ASSUMED) app.get('/o2c/cmrs', page((req, role) => { if (!S.can(role, 'cm.create') && !S.can(role, 'cmr.approve')) guard(role, 'cm.create'); const rows = S.list('cmrs'); return layout(req, role, 'Manage Credit Memo Requests', (S.can(role, 'cm.create') ? (req.query.create ? `` : `Create`) : '') + table('Credit Memo Requests', ['Request', 'Transaction', 'Amount', 'Status', 'Approver', 'Credit Memo'], rows.map((r) => tr([`${esc(r.number)}`, esc(r.invoiceNumber), money(r.amount), Tt(r.status), esc(r.approver || ''), esc(r.creditMemo || '')])), 'cmrs') + none(rows)); })); app.post('/o2c/cmrs', act((req, role) => { const r = S.createCmr(role, { transactionNumber: req.body.transactionNumber, amount: Number(req.body.amount) }); return [`/o2c/cmrs/${r.id}`, r.status === 'PENDING_APPROVAL' ? `Credit memo request ${r.number} ${money(r.amount)} routed for approval to ${r.approver}.` : `Credit memo request ${r.number} approved automatically; credit memo ${r.creditMemo}.`]; })); app.get('/o2c/cmrs/:id', page((req, role) => { if (!S.can(role, 'cm.create') && !S.can(role, 'cmr.approve')) guard(role, 'cm.create'); const r = S.list('cmrs').find((x) => x.id === req.params.id); if (!r) throw new AppError(404, 'NOT_FOUND', 'Credit memo request not found.'); const i = S.findInvoice(null, r.invoiceId); return layout(req, role, `Credit Memo Request ${r.number}`, dl([['Request', esc(r.number), 'o2c-cmr-number'], ['Status', Tt(r.status), 'o2c-cmr-status'], ['Transaction', esc(r.invoiceNumber), 'o2c-cmr-trx'], ['Customer', esc(r.customerName)], ['Amount', money(r.amount), 'o2c-cmr-amount'], ['Reason', esc(r.reason)], ['Requested By', esc(r.requestedBy)], ['Credit Memo', esc(r.creditMemo || ''), 'o2c-cmr-cm'], ['Transaction Balance Due', money(i.balance), 'o2c-cmr-trx-balance']]) + table('Transaction Lines', ['Line', 'Description', 'Quantity', 'Unit Price', 'Amount'], i.lines.map((l) => tr([l.lineNum, esc(l.description || l.item), l.quantity, money(l.unitPrice), money(l.amount)])), 'cmr-trx-lines') + (r.status === 'PENDING_APPROVAL' && r.approver === role ? form(`/o2c/cmrs/${r.id}/approve`, btn('Approve')) : '')); })); app.post('/o2c/cmrs/:id/approve', act((req, role) => { const r = S.approveCmr(role, req.params.id); const i = S.findInvoice(null, r.invoiceId); return [`/o2c/cmrs/${r.id}`, `Approved ${r.number}; credit memo ${r.creditMemo} ${money(r.amount)} created; transaction ${i.number} balance ${money(i.balance)}.`]; })); // ---------------- collections (O2C-COL-002) app.get('/o2c/collections', page((req, role) => { guard(role, 'collections'); const q = (req.query.customer || '').trim(); const searched = req.query.customer !== undefined; const inv = searched ? S.openInvoicesOf(q).filter((i) => S.buOk(role, i.bu)) : []; const t = today(); const dpd = (i) => Math.round((new Date(`${t}T00:00:00`) - new Date(`${i.dueDate}T00:00:00`)) / 86400000); const b = `/o2c/collections?customer=${encodeURIComponent(q)}`; return layout(req, role, 'Collections', form('/o2c/collections', inp('customer', 'Customer', { value: q }) + btn('Search'), 'get') + (searched ? table('Open Transactions', ['Transaction', 'Due Date', 'Days Past Due', 'Balance Due', 'Disputed Amount'], inv.map((i) => tr([esc(i.number), esc(i.dueDate), Math.max(0, dpd(i)), money(i.balance), money(S.disputedOf(i.id))])), 'collections-trx') + none(inv) + (inv.length ? (req.query.view === 'promise' ? dialog('Record Promise to Pay', form('/o2c/collections/promise', hid('customer', q) + inp('amount', 'Amount') + inp('promiseDate', 'Promise Date', { type: 'date' }) + btn('Save'))) : req.query.view === 'dispute' ? dialog('Create Dispute', form('/o2c/collections/dispute', hid('customer', q) + inp('amount', 'Amount') + btn('Submit'))) : `Record Promise to Pay Create Dispute`) : '') + table('Promises to Pay', ['Transaction', 'Amount', 'Promise Date', 'Broken Promise Check', 'Status'], S.list('promises').filter((p) => p.customer === q).map((p) => tr([esc(p.invoiceNumber), money(p.amount), esc(p.promiseDate), esc(p.brokenPromiseCheck), Tt(p.status)])), 'promises') + table('Disputes', ['Dispute', 'Transaction', 'Amount', 'Status', 'Approver'], S.list('disputes').filter((d) => d.customer === q).map((d) => tr([esc(d.number), esc(d.invoiceNumber), money(d.amount), Tt(d.status), esc(d.approver || '')])), 'disputes') : '')); })); app.post('/o2c/collections/promise', act((req, role) => { const p = S.recordPromise(role, { customer: req.body.customer, amount: Number(req.body.amount), promiseDate: req.body.promiseDate }); return [`/o2c/collections?customer=${encodeURIComponent(p.customer)}`, `Promise to pay ${money(p.amount)} recorded for ${p.invoiceNumber}; broken-promise check dated ${p.brokenPromiseCheck}.`]; })); app.post('/o2c/collections/dispute', act((req, role) => { const d = S.createDispute(role, { customer: req.body.customer, amount: Number(req.body.amount) }); return [`/o2c/collections?customer=${encodeURIComponent(d.customer)}`, `Dispute ${d.number} ${money(d.amount)} created for ${d.invoiceNumber}; routed for approval to ${d.approver}.`]; })); // ---------------- pricing administration (O2C-PRC-005; read-only views) app.get('/o2c/pricing/price-lists', page((req, role) => { guard(role, 'pricing.admin'); const c = S.config(); const q = (req.query.priceList || '').trim(); const searched = req.query.priceList !== undefined; const rows = searched && c.priceList.toLowerCase().includes(q.toLowerCase()) ? [c.priceList] : []; return layout(req, role, 'Manage Price Lists', form('/o2c/pricing/price-lists', inp('priceList', 'Price List', { value: q }) + btn('Search'), 'get') + (searched ? table('Price Lists', ['Price List', 'Currency', 'Status'], rows.map((n) => tr([`${esc(n)}`, esc(c.currency), 'Active'])), 'price-lists') + none(rows) : '')); })); app.get('/o2c/pricing/price-lists/view', page((req, role) => { guard(role, 'pricing.admin'); const c = S.config(); if (req.query.name !== c.priceList) throw new AppError(404, 'NOT_FOUND', 'Price list not found.'); const items = S.list('items'); return layout(req, role, `Price List ${c.priceList}`, table('Price List Items', ['Item', 'Base Price', 'Currency', 'Start Date', 'Status'], items.map((it) => tr([esc(it.number), money(it.listPrice), esc(c.currency), esc(it.priceStart || '2026-01-01'), 'Active'])), 'price-list-items')); })); app.get('/o2c/pricing/strategies', page((req, role) => { guard(role, 'pricing.admin'); const c = S.config(); const q = (req.query.name || '').trim(); const searched = req.query.name !== undefined; const rows = searched ? S.list('strategyAssignments').filter((a) => a.strategy.toLowerCase().includes(q.toLowerCase())) : []; return layout(req, role, 'Manage Pricing Strategies', form('/o2c/pricing/strategies', inp('name', 'Name', { value: q }) + btn('Search'), 'get') + (searched ? table('Pricing Strategies', ['Strategy', 'Price List', 'Customer', 'Status'], rows.map((a) => tr([esc(a.strategy), esc(a.priceList), esc(a.customer), 'Active'])), 'pricing-strategies') + none(rows) : '')); })); } module.exports = { TASKS, mount };