' + (TL ? 'Trade Logistica invoice ' : 'Invoice ') + esc(i.number) + '
' + esc(new Date(i.invoice_date).toLocaleDateString('en-GB')) + ' · ' + (i.status === 'paid' ? 'Paid' : 'To pay' + (i.due_date ? ' by ' + esc(new Date(i.due_date).toLocaleDateString('en-GB')) : '') + '') + '
' + esc(se.name) + '
' + esc([se.trading, se.address, se.postcode].filter(Boolean).join(', ')) + (se.vat_no ? '
VAT ' + esc(se.vat_no) : '') + '
' +
'
Buyer
' + esc(bu.company || '') + '
' + esc([bu.name, bu.address, bu.postcode].filter(Boolean).join(', ')) + '
Vehicle
' + esc(regFmt(ve.reg)) + ' ' + esc([ve.year, ve.make, ve.model].filter(Boolean).join(' ')) + '
' + esc(ve.derivative || '') + (ve.miles ? '
' + Number(ve.miles).toLocaleString('en-GB') + ' miles (not warranted)' : '') + '
' +
'
' + (i.lines || []).map(function (l, n) { var v = (n === 0 && i.vat_mode === 'qualifying') || (n > 0 && l.vat) ? Number(l.net) * 0.2 : 0; return '| ' + esc(l.text) + ' | ' + gbp(Number(l.net) + v, 2) + (v ? ' inc VAT ' + gbp(v, 2) + '' : '') + ' |
'; }).join('') + '| Total | ' + gbp(i.total, 2) + ' |
' +
(!TL && i.vat_mode === 'margin' ? '
Margin scheme – second hand goods. No VAT is shown separately and VAT is not reclaimable.
' : '') +
(TL ? '' : '
Known faults disclosed
' + esc(i.faults || 'None stated') + '
') + (i.conditions ? '
Conditions for this car
' + esc(i.conditions) + '
' : '') +
'
Pay by bank transfer
' + esc([se.account_name ? 'Account name: ' + se.account_name : '', se.bank_name ? 'Bank: ' + se.bank_name : '', se.sort_code ? 'Sort code: ' + se.sort_code : '', se.account_no ? 'Account number: ' + se.account_no : ''].filter(Boolean).join('\n')) + '\nReference: ' + esc(i.number) + '
' + (TL ? 'Please pay before the delivery date.' : 'The car is released once payment has cleared in full.') + '
' +
'
' + (TL ? 'Terms' : 'Trade terms of sale') + '
' + esc(i.terms || '') + '
' +
(TL || i.kind === 'credit' ? '' : i.accepted_at ? '
✓ Terms accepted by ' + esc(i.accepted_by) + ' on ' + esc(new Date(i.accepted_at).toLocaleString('en-GB')) + '
' : '
') + '
';
var ab = $('#ab', app); if (ab) ab.onclick = async function () {
if (!($('#d1', app).checked && $('#d2', app).checked && $('#d3', app).checked)) { $('#ae', app).textContent = 'Please tick all three boxes'; return; }
if (!$('#an', app).value.trim()) { $('#ae', app).textContent = 'Please type your full name'; return; }
this.disabled = true;
var decl = { trader: true, terms: true, authority: true, position: $('#ap', app).value.trim(), company: bu.company || bu.name || '', ua: navigator.userAgent };
var r;
try { r = await rpc('trade_invoice_accept', { p_token: t, p_name: $('#an', app).value, p_ip: '', p_decl: decl }); }
catch (e) {
// before db/2026-11-20 is applied there is only the three-argument version
if (!/function|schema cache|p_decl|could not find/i.test(e.message)) { $('#ae', app).textContent = e.message; this.disabled = false; return; }
try { r = await rpc('trade_invoice_accept', { p_token: t, p_name: $('#an', app).value + ($('#ap', app).value.trim() ? ' (' + $('#ap', app).value.trim() + ')' : ''), p_ip: '' }); } catch (e2) { r = { error: e2.message }; }
}
if (r.error) { $('#ae', app).textContent = r.error; this.disabled = false; return; } invoicePage(app, t); };
}
/* ---------------- router */
function route() {
var h = location.hash.slice(1), app = $('#app'), kv = h.split('='), k = kv[0], val = kv.slice(1).join('=');
clearInterval(CHT); window.scrollTo(0, 0); app.className = 'wrap'; nav();
if (k === 'reset' && val) return resetPage(app, val);
if (k === 'invoice' && val) { fabPaint(); return invoicePage(app, val); }
if (!tok) { closeDock(); if (k === 'car' || k === 'chat' || k === 'account') store('ucb_trade_back', '#' + h); if (k === 'signin' || k === 'signup' || k === 'forgot' || k === 'car' || k === 'chat' || k === 'account') return authPage(app, k === 'signup' ? 'signup' : k === 'forgot' ? 'forgot' : 'signin'); return landing(app); }
if (k === 'signin' || k === 'signup') { location.replace('#stock'); return; }
fabPaint();
var go = k === 'car' ? carPage(app, val) : k === 'account' ? accountPage(app, val) : stockPage(app);
if (k === 'chat') Promise.resolve(go).then(function () { openDock(val || null); });
else if (DOCK.open) setTimeout(function () { openDock(); }, 0);
Promise.resolve(go).catch(function (e) { app.innerHTML = '