/* eslint-disable */ /* © 2026 K2B NETWORK SOLUTIONS LLC. All rights reserved. Proprietary and confidential. Unauthorized copying, distribution, or use of this file, via any medium, is strictly prohibited. Original work product. */ // JBREWS DMS — Pay-Plan Engine. Salesperson commission calculated live off // each deal's gross: commissionable front gross (after pack & over-allowance), // commission %, mini floor, and per-product bonuses (VSC / GAP / appearance), // with a funded-only payout gate. Plan settings are editable and persist. // RC28 fix round (audit FU6): cents are shown when there are any ($150.50 was shown — and paid — as $151) const ppMoney = (n) => { const v = Math.round((Number(n) || 0) * 100) / 100; return (v < 0 ? "−$" : "$") + Math.abs(v).toLocaleString("en-US", { minimumFractionDigits: Math.abs(v) % 1 ? 2 : 0, maximumFractionDigits: 2 }); }; const PayPlan = ({ onClose, go }) => { const D = window.DMS; const [, force] = React.useReducer(n => n + 1, 0); React.useEffect(() => (D && D.subscribe) ? D.subscribe(force) : undefined, []); const act = (r) => { window.k2bToast && window.k2bToast(r.msg, r.ok ? "ok" : "warn", 3000); return r; }; const deals = (D && D.deals) ? D.deals().filter(d => (+d.salePrice || 0) > 0) : []; const cfg = D.payPlanConfig ? D.payPlanConfig() : {}; const [selId, setSelId] = React.useState(null); const [cfgOpen, setCfgOpen] = React.useState(false); React.useEffect(() => { if (selId && deals.find(d => d.id === selId)) return; if (deals[0]) setSelId(deals[0].id); }, [deals.length]); const sel = deals.find(d => d.id === selId) || null; const pp = sel ? D.dealPayPlan(sel.id) : null; const totalPayable = deals.reduce((s, d) => { const p = D.dealPayPlan(d.id); return s + (p.found && p.eligible ? p.total : 0); }, 0); const pendingPayable = deals.reduce((s, d) => { const p = D.dealPayPlan(d.id); return s + (p.found && !p.eligible ? p.total : 0); }, 0); return (
Payable (funded)
{ppMoney(totalPayable)}
Pending (not funded)
{ppMoney(pendingPayable)}
{Math.round(cfg.usedPct * 10000) / 100}% used · {Math.round(cfg.newPct * 10000) / 100}% new · mini {ppMoney(cfg.miniFloor)}{cfg.fundedOnly ? " · funded-only" : ""} · plan v{cfg.version || 0}{cfg.version ? "" : " (shipped default)"}
{deals.length === 0 &&
No deals with a sale price yet.
} {deals.map(d => { const p = D.dealPayPlan(d.id); const on = d.id === selId; return (
setSelId(d.id)} style={{ padding: "10px 14px", borderBottom: "1px solid var(--jb-border)", cursor: "pointer", background: on ? "var(--jb-blue-tint, #E5EFFA)" : "transparent", borderLeft: on ? "3px solid var(--jb-blue)" : "3px solid transparent" }}>
{d.id}
{ppMoney(p.total)}
{d.salesperson || "—"} · {d.buyer}
{d.status}{p.unwound ? " · unwound — commission reversed" : (p.isMini ? " · MINI" : "") + (!p.eligible ? " · holds for funding" : "")}
); })}
{sel && pp ? (
{sel.id}
{pp.salesperson} · {sel.buyer}
{sel.vehicle} · {pp.isNew ? "New" : "Used"} · {sel.status}
{/* breakdown */}
{pp.pack > 0 && } {pp.tradeOverallow > 0 && } {pp.frontAdds > 0 && } {pp.isMini && } {pp.bonuses.map((b, i) => )}
{/* eligibility */}
{pp.eligible ? "Payable Now" : "Holds for Funding"}
{ppMoney(pp.total)}
{pp.eligible ? "Deal funded — commission released." : (pp.fundedOnly ? "Funded-only plan: pays when the lender funds." : "Eligible.")}
) :
Select a deal.
}
ESC-Close go && go("deal")}>Deals go && go("payroll")}>Payroll
{cfgOpen && setCfgOpen(false)} />}
); }; const PpRow = ({ label, value, bold, big, green, amber }) => (
{label} {value}
); const PpFlag = ({ label, ok }) => (
{ok ? "✓" : "○"} {label}
); // RC28 (fx, the reviewer's finding 3): the plan is the SERVER's — one stored configuration, VERSIONED with an effective date and audited // (GET / POST /api/pay-plan). Saving makes a NEW version (the owner, Admin / F&I or the Office Manager); every other login reads it. // The desk, the posting, the chargebacks and this screen all use it; a posted deal keeps the version it was posted with. const PayPlanConfig = ({ cfg, act, onClose }) => { const D = window.DMS; const pp = (D && D.payPlanCached) ? D.payPlanCached() : {}; const may = !!pp.mayEdit; const today = (() => { const t = new Date(); return t.getFullYear() + "-" + String(t.getMonth() + 1).padStart(2, "0") + "-" + String(t.getDate()).padStart(2, "0"); })(); const pctTxt = (x) => String(Math.round((+x || 0) * 10000) / 100); const [f, setF] = React.useState({ usedPct: pctTxt(cfg.usedPct), newPct: pctTxt(cfg.newPct), miniFloor: (+cfg.miniFloor || 0).toFixed(2), vscBonus: (+cfg.vscBonus || 0).toFixed(2), gapBonus: (+cfg.gapBonus || 0).toFixed(2), appearanceBonus: (+cfg.appearanceBonus || 0).toFixed(2), fundedOnly: cfg.fundedOnly !== false, packCounts: cfg.packCounts !== false, effectiveOn: today, reason: "", }); const [busy, setBusy] = React.useState(false); const [msg, setMsg] = React.useState(null); const set = (k, v) => setF(s => ({ ...s, [k]: v })); const save = async () => { setBusy(true); setMsg(null); const r = await D.setPayPlanConfig({ usedPctText: f.usedPct, newPctText: f.newPct, miniFloor: f.miniFloor, vscBonus: f.vscBonus, gapBonus: f.gapBonus, appearanceBonus: f.appearanceBonus, fundedOnly: !!f.fundedOnly, packCounts: !!f.packCounts }, { effectiveOn: f.effectiveOn, reason: f.reason }); setBusy(false); if (r.ok) { if (window.k2bToast) window.k2bToast(r.msg, /still scheduled/.test(r.msg || "") ? "warn" : "ok", /still scheduled/.test(r.msg || "") ? 12000 : 3000); onClose(); } else setMsg(r.msg); }; const versions = (pp.versions || []).slice().reverse(); // RC28 fix round (audit FU4): each version says when it is in effect — the one in effect today, the ones still to come (each on its own day) const vState = (v) => (v.version === (cfg.version || 0) ? "IN EFFECT" : v.effectiveOn > (pp.today || "") ? "takes effect " + v.effectiveOn : ""); return ( {may ? "Cancel" : "Close"}{may && {busy ? "Saving…" : "Save as a new version"}}}>
In effect today: version {cfg.version || 0}{cfg.version ? " (from " + cfg.effectiveOn + ")" : " — the shipped default plan; the store's own plan has not been saved yet. Check it matches your real pay plan before the next deal posts."}
The desk, the posting, the product chargebacks and this screen all use this plan. A deal already posted keeps the version it was posted with.
{!may &&
Only the owner, Admin / F&I or the Office Manager can save a new version of the pay plan — your login can read it.
}
{may &&
} {msg &&
{msg}
}
Versions {versions.map(v =>
v{v.version}{v.version ? v.effectiveOn : "shipped"}{vState(v)} {(v.plan.newPctBp / 100)}% new · {(v.plan.usedPctBp / 100)}% used · mini ${(v.plan.miniFloorCents / 100).toFixed(2)}{v.byName ? " · " + v.byName : ""}{v.reason && v.version ? " · " + v.reason : ""}
)}
); }; const ppInpStyle = { width: "100%", boxSizing: "border-box", padding: "7px 9px", border: "1px solid #C8CCD2", borderRadius: 4, fontSize: 13, fontFamily: "var(--jb-mono)" }; const PpCfgFld = ({ label, k, suffix, f, set, dis }) => ( ); Object.assign(window, { PayPlan });