/* 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 — Fulfillment Center Sold Orders (FCSO). // Request in-stock GM Fulfillment Center units for CUSTOMER SOLD ORDERS (not // dealer stock). Enforces the GM FCSO requirements gate before submission, // tracks dealer FCSO allotment, runs validation, and — once the unit is // delivered — stocks it into DMS inventory. Per GM rules: once submitted, only // the CUSTOMER can cancel (via MyAccount). Requests persist to localStorage. const FCSO_KEY = "jbrews-fcso-v1"; const FCSO_ALLOT_KEY = "jbrews-fcso-allotment"; function fcsoLoad() { try { return JSON.parse(localStorage.getItem(FCSO_KEY) || "[]"); } catch (e) { return []; } } function fcsoSave(list) { try { localStorage.setItem(FCSO_KEY, JSON.stringify(list)); } catch (e) {} window.dispatchEvent(new CustomEvent("fcso-change")); } function fcsoAllot() { try { const v = localStorage.getItem(FCSO_ALLOT_KEY); return v == null ? 8 : +v; } catch (e) { return 8; } } function fcsoSetAllot(n) { try { localStorage.setItem(FCSO_ALLOT_KEY, String(n)); } catch (e) {} } const FCSO_REQS = [ { k: "myAccount", label: "Customer has a validated MyAccount" }, { k: "license", label: "Copy of customer's valid driver's license collected" }, { k: "custInfo", label: "Legal first/last name, address, phone & email on file" }, { k: "deposit", label: "Refundable deposit collected" }, { k: "vda", label: "Vehicle Deposit Agreement (VDA) / purchase or lease agreement signed" }, { k: "titling", label: "Titling information captured (orig. customer / family / small business)" }, { k: "soldOrder", label: "This is a customer SOLD order (not dealer stock)" }, ]; const FCSO_STATUS_TONE = { Draft: { bg: "#EDEFF3", fg: "#5A6472" }, Submitted: { bg: "var(--jb-blue-tint,#E5EFFA)", fg: "var(--jb-blue,#1B66A8)" }, "Validation Pending": { bg: "#E7F0FB", fg: "#1456A0" }, Validated: { bg: "#E7F0FB", fg: "#1456A0" }, Allocated: { bg: "var(--jb-green-tint,#E6F7EC)", fg: "var(--jb-green,#16A34A)" }, Delivered: { bg: "var(--jb-green-tint,#E6F7EC)", fg: "#0E7A37" }, "Validation Failed": { bg: "#FBE9E7", fg: "#B23A2E" }, "Customer Cancelled": { bg: "#F6E2C5", fg: "#9A6700" }, }; const FcsoBadge = ({ s }) => { const t = FCSO_STATUS_TONE[s] || FCSO_STATUS_TONE.Draft; return {s}; }; const fcMoney = (n) => "$" + (Number(n) || 0).toLocaleString("en-US", { maximumFractionDigits: 0 }); const FCSO = ({ onClose, go }) => { const [, force] = React.useReducer(n => n + 1, 0); React.useEffect(() => { const h = () => force(); const hs = (e) => { if (e.key === FCSO_KEY || e.key === FCSO_ALLOT_KEY) force(); }; window.addEventListener("fcso-change", h); window.addEventListener("storage", hs); // cross-tab real-time return () => { window.removeEventListener("fcso-change", h); window.removeEventListener("storage", hs); }; }, []); const list = fcsoLoad(); const allot = fcsoAllot(); const used = list.filter(r => ["Submitted", "Validation Pending", "Validated", "Allocated", "Delivered"].includes(r.status)).length; const remaining = Math.max(0, allot - used); const [edit, setEdit] = React.useState(null); const act = (m, ok = true) => window.k2bToast && window.k2bToast(m, ok ? "ok" : "warn", 3600); const blank = () => ({ id: "FCSO-" + String(Date.now()).slice(-6), status: "Draft", fcUnit: "", yr: new Date().getFullYear() + 1, mk: "Chevrolet", mdl: "", vin: "", fc: "", price: "", customer: "", phone: "", email: "", deposit: "", reqs: {}, created: new Date().toISOString() }); const submit = (r) => { if (remaining <= 0 && r.status === "Draft") { act("No FCSO allotment remaining. Check OWB for available requests.", false); return; } const allChecked = FCSO_REQS.every(q => r.reqs && r.reqs[q.k]); if (!allChecked) { act("All FCSO requirements must be met before submission.", false); return; } if (!r.customer || !r.fcUnit) { act("Customer and FC unit are required.", false); return; } update({ ...r, status: "Submitted", submittedDate: new Date().toISOString() }); act(`${r.id} submitted to GM. Once submitted, only the customer can cancel via MyAccount.`); }; const update = (r) => { const all = fcsoLoad(); const i = all.findIndex(x => x.id === r.id); if (i >= 0) all[i] = r; else all.unshift(r); fcsoSave(all); setEdit(null); }; const runValidation = (r) => { // Simulate GM validation against the captured MyAccount/customer data const ok = !!(r.reqs.myAccount && r.customer && r.email); update({ ...r, status: ok ? "Validated" : "Validation Failed", validatedDate: new Date().toISOString() }); act(ok ? `${r.id} passed validation.` : `${r.id} failed validation — customer & dealer must resolve MyAccount/data mismatch.`, ok); }; const allocate = (r) => { update({ ...r, status: "Allocated", allocatedDate: new Date().toISOString() }); act(`${r.id} allocated — unit reserved at ${r.fc || "FC"}.`); }; const deliver = async (r) => { // RC33 (mpx): the stock-in is a SERVER command — await the committed answer // Stock the delivered FC unit into DMS inventory as a customer sold order. if (window.DMS && window.DMS.stockInVehicle) { const stock = "FC-" + String(r.id).slice(-5); const res = await window.DMS.stockInVehicle({ stock, vin: r.vin, yr: r.yr, mk: r.mk, mdl: r.mdl, type: "N", cost: +r.price || 0, asking: +r.price || 0 }); update({ ...r, status: "Delivered", deliveredDate: new Date().toISOString(), stock }); act(res.ok ? `${r.id} delivered — stocked into inventory as ${stock}.` : `${r.id} delivered. ${res.msg}`, res.ok); } else { update({ ...r, status: "Delivered", deliveredDate: new Date().toISOString() }); act(`${r.id} delivered.`); } }; const custCancel = (r) => { if (!window.confirm("Record a CUSTOMER cancellation (via MyAccount)?\n\nThe refundable deposit must be returned to the customer.")) return; update({ ...r, status: "Customer Cancelled", cancelledDate: new Date().toISOString() }); act(`${r.id} cancelled by customer — refund the deposit.`); }; return (
{}} onMax={() => {}} />
{[["FCSO Allotment", allot, "var(--jb-navy)"], ["Used", used, "var(--jb-blue)"], ["Remaining", remaining, remaining ? "var(--jb-green)" : "var(--jb-red)"], ["Delivered", list.filter(r => r.status === "Delivered").length, "var(--jb-green)"]].map(([lab, val, c], i) => (
{lab}
{val}
))}
FCSOs are for customer sold orders only, never dealer stock. Once submitted, only the customer can cancel (via MyAccount); the dealer must refund the deposit.
{["Request", "FC Unit", "Vehicle", "Customer", "FC", "Price", "Status", ""].map((h, i) => )} {list.map((r, i) => ( setEdit({ ...r, reqs: { ...r.reqs } })} style={{ background: i % 2 ? "var(--jb-surface-2)" : "#fff", cursor: "pointer" }}> ))} {list.length === 0 && }
{h}
{r.id} {r.fcUnit || "—"} {[r.yr, r.mk, r.mdl].filter(Boolean).join(" ")} {r.customer || "—"} {r.fc || "—"} {r.price ? fcMoney(r.price) : "—"} open ›
No FCSO requests yet. Start one with “+ New FCSO Request.”
{edit && setEdit(null)} onSaveDraft={(r) => update(r)} onSubmit={submit} onValidate={runValidation} onAllocate={allocate} onDeliver={deliver} onCustCancel={custCancel} />}
); }; const FcsoEditor = ({ rec, remaining, onClose, onSaveDraft, onSubmit, onValidate, onAllocate, onDeliver, onCustCancel }) => { const [r, setR] = React.useState({ ...rec, reqs: { ...rec.reqs } }); const fcTyped = React.useRef(new Set()); const set = (k, v) => { fcTyped.current.add(k); setR(p => ({ ...p, [k]: v })); }; const setReq = (k, v) => setR(p => ({ ...p, reqs: { ...p.reqs, [k]: v } })); const isDraft = r.status === "Draft"; // A 17-character VIN typed / pasted into a draft fills the still-blank Year / Make / Model from our server (window.DMS.vin: // MarketCheck -> NHTSA -> the VIN itself). What the person typed is never overwritten; Undo puts the filled values back. // A new request starts with next year / Chevrolet as defaults: untouched, they count as blank (the VIN says what the unit really is). const fcDefault = (k, v) => !fcTyped.current.has(k) && (k === "yr" ? String(v) === String(new Date().getFullYear() + 1) : k === "mk" ? /^chevrolet$/i.test(String(v || "")) : false); const vinFill = (typeof VlUseVinFill === "function") ? VlUseVinFill({ vin: r.vin, enabled: isDraft, keys: { yr: "year", mk: "make", mdl: "model" }, read: () => r, write: (p) => setR(s => ({ ...s, ...p })), typed: () => fcTyped.current, shape: { yr: (n) => String(n) }, isBlank: fcDefault, }) : null; const reqCount = FCSO_REQS.filter(q => r.reqs[q.k]).length; return ( {isDraft && onSaveDraft(r)}>Save Draft} {isDraft && onSubmit(r)}>Submit to GM →} {(r.status === "Submitted") && onValidate(r)}>Run Validation} {(r.status === "Validated") && onAllocate(r)}>Allocate Unit} {(r.status === "Allocated") && onDeliver(r)}>Deliver → Stock In} {["Submitted", "Validation Pending", "Validated", "Allocated"].includes(r.status) && onCustCancel(r)}>Customer Cancel} Close }>
{vinFill && typeof VlVinNote === "function" &&
}
Customer (sold order)
FCSO Requirements
{reqCount}/{FCSO_REQS.length}
{FCSO_REQS.map(q => ( ))}
{!isDraft && (
{r.status === "Submitted" && "Submitted to GM — awaiting validation. The dealer can no longer cancel; only the customer may cancel via MyAccount."} {r.status === "Validation Failed" && "⚠ Validation failed — customer and dealer must resolve the MyAccount / data mismatch, then resubmit."} {r.status === "Delivered" && r.stock && <>Delivered and stocked into inventory as {r.stock}.} {r.status === "Customer Cancelled" && "Cancelled by the customer — refund the deposit and document in the deal jacket."}
)}
); }; const FcFld = ({ label, k, w, mono, r, set, isDraft }) => ( ); Object.assign(window, { FCSO });