Loading…

Or call ' + PHONE + '
'; $('#dx', w).onclick = closeDock; var nc = $('#dnoc', w); if (nc) nc.onclick = function (e) { e.preventDefault(); DOCK.car = null; openDock(); }; var ta = $('#cb', w); ta.oninput = function () { ta.style.height = 'auto'; ta.style.height = Math.min(120, ta.scrollHeight) + 'px'; }; var paint = async function () { var th = $('#th'); if (!th) { clearInterval(CHT); return; } var d = await rpc('trade_chat_get', { p_token: tok }), atEnd = th.scrollHeight - th.scrollTop - th.clientHeight < 40; th.innerHTML = (d.msgs || []).length ? d.msgs.map(function (m) { return m.from === 'system' ? '
' + esc(m.body) + ' · ' + esc(when(m.at)) + '
' : '
' + esc(m.body) + '' + (m.from === 'staff' ? esc(m.by || 'UCB') + ' · ' : '') + esc(when(m.at)) + (m.reg ? ' · ' + esc(regFmt(m.reg)) : '') + '
'; }).join('') : '
' + ic('chat') + '
Ask us anything

About a car, delivery, or what you\'re looking for. We\'ll keep an eye out.

'; if (atEnd) th.scrollTop = th.scrollHeight; if (D.unread) { D.unread = 0; nav(); } }; clearInterval(CHT); await paint(); $('#th').scrollTop = 1e6; CHT = setInterval(paint, 6000); ta.focus(); var send = async function () { var b = $('#cs'), t = ta.value.trim(); if (!t) return; b.disabled = true; try { var r = await rpc('trade_chat_send', { p_token: tok, p_body: t, p_car: DOCK.car ? DOCK.car.id : null }); if (r.error) throw new Error(r.error); ta.value = ''; ta.style.height = 'auto'; fn({ action: 'notify', token: tok, kind: 'chat' }).catch(function () { }); await paint(); $('#th').scrollTop = 1e6; } catch (e) { toast(e.message); } b.disabled = false; ta.focus(); }; $('#cs', w).onclick = send; ta.onkeydown = function (e) { if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); send(); } }; } /* ---------------- invoice link (no sign-in needed: the link itself is the key) */ async function invoicePage(app, t) { app.innerHTML = '

Loading your invoice…

'; var i = await rpc('trade_invoice_get', { p_token: t }); if (!i || i.error) { app.innerHTML = '

Invoice not found

Please call ' + PHONE + '.

'; return; } var se = i.seller || {}, bu = i.buyer || {}, ve = i.vehicle || {}, TL = i.issuer === 'tl'; app.innerHTML = '

' + (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 ''; }).join('') + '
' + esc(l.text) + '' + gbp(Number(l.net) + v, 2) + (v ? '
inc VAT ' + gbp(v, 2) + '' : '') + '
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')) + '
' : '

Accept the terms

The car is released once it\'s paid for and these terms are accepted.

' + '' + '' + '' + '

') + '
'; 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 = '

Something went wrong

' + esc(e.message) + '

Back to the stock

'; }); } window.addEventListener('hashchange', route); nav(); route(); setInterval(function () { if (tok && document.visibilityState === 'visible' && !DOCK.open) rpc('trade_stock', { p_token: tok }).then(function (d) { D.unread = d.unread || 0; nav(); fabPaint(); }).catch(function () { }); }, 60000); })();