/* 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 — Report / Print Selection dialog (shared, both Sales & Service). // Modeled on the classic DMS "Report Selection" + "Select a Printer" screens: // • A checklist of documents to print, each with a copies stepper and a // destination (Screen ▸ preview, or Printer). // • "Remember selection" persists the checklist per context to localStorage. // • OK runs every checked doc's print fn in sequence. // Imperative API (event-driven host, same pattern as K2BToastHost): // window.k2bPrintSelect({ title, context, subtitle, docs:[{ key,label,checked, // copies,dest,note,print(opts) }] }) // A must be mounted once (done in app.jsx). const PS_KEY = (ctx) => `jbrews-printsel-${ctx || "default"}`; function psLoadPrefs(ctx) { try { return JSON.parse(localStorage.getItem(PS_KEY(ctx)) || "{}"); } catch (e) { return {}; } } function psSavePrefs(ctx, prefs) { try { localStorage.setItem(PS_KEY(ctx), JSON.stringify(prefs)); } catch (e) {} } const K2BPrintSelectHost = () => { const [cfg, setCfg] = React.useState(null); React.useEffect(() => { window.k2bPrintSelect = (c) => setCfg(c && c.docs && c.docs.length ? c : null); return () => { delete window.k2bPrintSelect; }; }, []); if (!cfg) return null; return setCfg(null)} />; }; const PrintSelectDialog = ({ cfg, onClose }) => { const prefs = psLoadPrefs(cfg.context); // Merge saved prefs (checked/copies/dest) onto the supplied docs by key. const [rows, setRows] = React.useState(() => cfg.docs.map(d => { const p = prefs[d.key] || {}; return { ...d, checked: p.checked != null ? p.checked : (d.checked !== false), copies: p.copies != null ? p.copies : (d.copies || 1), dest: p.dest || d.dest || "screen", }; })); const [remember, setRemember] = React.useState(prefs.__remember || false); const setRow = (i, patch) => setRows(rs => rs.map((r, j) => j === i ? { ...r, ...patch } : r)); const checkedCount = rows.filter(r => r.checked).length; const run = () => { if (remember) { const out = { __remember: true }; rows.forEach(r => { out[r.key] = { checked: r.checked, copies: r.copies, dest: r.dest }; }); psSavePrefs(cfg.context, out); } const sel = rows.filter(r => r.checked); if (!sel.length) { window.k2bToast && window.k2bToast("No documents selected.", "warn"); return; } onClose(); // Run prints sequentially with a short stagger so multiple preview tabs/ // windows don't collide. sel.forEach((r, idx) => { setTimeout(() => { try { r.print && r.print({ copies: r.copies, dest: r.dest }); } catch (e) { console.error(e); } }, idx * 350); }); const screenN = sel.filter(r => r.dest === "screen").length; const printerN = sel.length - screenN; window.k2bToast && window.k2bToast( `${sel.length} document${sel.length !== 1 ? "s" : ""} sent` + (printerN ? ` · ${printerN} to printer` : "") + (screenN ? ` · ${screenN} to screen` : "") + ".", "ok", 3600); }; const Stepper = ({ value, onChange }) => (
{value}
); return ( setRows(rs => rs.map(r => ({ ...r, checked: false })))}>Clear All Cancel ✓ Print ({checkedCount}) }>
{cfg.subtitle || "Check the reports you want to print. Set copies and destination per document."}
DocumentCopiesDestination
{rows.map((r, i) => (
setRow(i, { copies: v })} />
{[["screen", "🖥 Screen"], ["printer", "🖨 Printer"]].map(([val, lab]) => ( ))}
))}
); }; const psStepBtn = { width: 26, height: 26, border: 0, background: "var(--jb-surface-2)", cursor: "pointer", fontSize: 15, fontWeight: 700, color: "var(--jb-text-dim)", lineHeight: 1 }; // ── Convenience builders ────────────────────────────────────────────── // Service RO packet (the DealerBuilt "Report Selection" screen). window.k2bPrintSelectRO = function(ro) { if (!ro) { window.k2bToast && window.k2bToast("No repair order selected.", "warn"); return; } const isWarr = ro.payType === "Warranty"; const docs = [ { key: "workorder", label: "Work Order", checked: true, copies: 2, dest: "screen", print: () => window.k2bPrintRO(ro, "workorder") }, { key: "estimate", label: "Customer Estimate", checked: false, copies: 1, dest: "screen", print: () => window.k2bPrintRO(ro, "estimate") }, // RC28 (svc): the customer-facing estimate (with the Sunbit box) { key: "invoice", label: "Customer Invoice", checked: !isWarr, copies: 1, dest: "screen", print: () => window.k2bPrintRO(ro, "invoice") }, { key: "warranty", label: "Int / War / SC Invoice", checked: isWarr, copies: 1, dest: "screen", print: () => window.k2bPrintRO(ro, "warranty") }, { key: "lube", label: "Quick Lube Checklist", checked: false, copies: 1, dest: "screen", print: () => window.k2bPrintRO(ro, "lube") }, { key: "history", label: "Work Order History", checked: false, copies: 1, dest: "screen", print: () => window.k2bPrintRO(ro, "history") }, { key: "wo2", label: "2nd W/O Copy", checked: false, copies: 1, dest: "printer", print: () => window.k2bPrintRO(ro, "workorder") }, { key: "rental", label: "Car Rental Agreement", checked: false, copies: 1, dest: "printer", note: "Loaner / rental terms", print: () => window.k2bPrintRO(ro, "invoice") }, ]; // RC32 (lane ros): the store's print packets (Service Setup X5) — which documents are ticked and how many copies for an open / a closed // RO, and documents hidden (the "Car Rental Agreement" prints the invoice until it has its own form). Missing settings = today's packet. let pk = null; try { pk = window.DMS && DMS.svcSettings ? (DMS.svcSettings().ro || {}).texts.packets : null; } catch (e) { pk = null; } const when = pk ? (ro.status === "Closed" ? pk.closed : pk.open) : null; const ticked = (v) => v === true ? true : v === false ? false : v === "warranty" ? isWarr : v === "notWarranty" ? !isWarr : null; const shown = docs.filter(d => !(pk && Array.isArray(pk.hide) && pk.hide.includes(d.key))).map(d => { const w = when && when[d.key]; if (!w) return d; const t = ticked(w.on); return { ...d, checked: t == null ? d.checked : t, copies: w.copies != null && +w.copies >= 1 ? +w.copies : d.copies }; }); window.k2bPrintSelect({ title: "Report Selection — " + ro.id, context: "ro", subtitle: `${ro.customer} · ${ro.vehicle || ""}`, docs: shown, }); }; // Sales deal packet — driven by the Forms Sequencing engine (jbForms.resolve). window.k2bPrintSelectDeal = function(ctx = {}) { const seq = (window.jbForms && window.jbForms.resolve) ? window.jbForms.resolve(ctx) : []; const printerFor = (f) => { if (window.K2BForms && window.K2BForms.owns(f.printKey)) return () => window.K2BForms.print(f.printKey); // RC37 (forms37): the dealership's own forms switch (f.printKey) { case "billOfSale": return () => window.k2bPrintBillOfSale && window.k2bPrintBillOfSale(); case "odometer": return () => window.k2bPrintOdometer && window.k2bPrintOdometer(); case "privacy": return () => window.k2bPrintPrivacy && window.k2bPrintPrivacy(); case "asIs": return () => window.k2bPrintAsIs && window.k2bPrintAsIs(); case "releaseTrade": return () => window.k2bPrintRelease && window.k2bPrintRelease({ mode: "trade" }); case "release": return () => window.k2bPrintRelease && window.k2bPrintRelease(); // Lease packet + retail contract prep (B-03): print functions live in printables.jsx. case "leaseWorksheet": return () => window.k2bPrintLeaseWorksheet && window.k2bPrintLeaseWorksheet(); case "leaseDisclosure": return () => window.k2bPrintLeaseDisclosure && window.k2bPrintLeaseDisclosure(); case "gmfLeaseOdometer": return () => window.k2bPrintGmfLeaseOdometer && window.k2bPrintGmfLeaseOdometer(window.loadJbForm ? window.loadJbForm("buyersOrder") : {}); case "contractPrep": return () => window.k2bPrintContractPrep && window.k2bPrintContractPrep(window.loadJbForm ? window.loadJbForm("contractPrep") : {}); case "buyersOrder": default: return () => window.k2bPrintBuyersOrder && window.k2bPrintBuyersOrder(); } }; const docs = seq.length ? seq.map(f => ({ key: f.id, label: f.name, note: f.group + (f.banks.length ? " · " + f.banks.join("/") : "") + (f.states.length ? " · " + f.states.join("/") : ""), checked: true, copies: f.copies, dest: f.dest, print: printerFor(f), })) : [ { key: "bo", label: "Vehicle Buyer's Order", checked: true, copies: 2, dest: "screen", print: () => window.k2bPrintBuyersOrder && window.k2bPrintBuyersOrder() }, ]; // RC27 (dsk): a deal with WE-OWE lines (desk › Profit panel) prints its DUE BILL with the deal documents (customer copy, signature lines, no amounts) try { let id = ctx.dealId || null; if (!id) { try { id = localStorage.getItem("jb_fw_deal"); } catch (e) {} } const deal = id && window.DMS && window.DMS.deals ? (window.DMS.deals() || []).find(x => x && x.id === id) : null; const wo = deal && Array.isArray(deal.costAdds) ? deal.costAdds.filter(l => l && (l.type === "weOwe" || l.weOwe === true) && l.type !== "dpa" && l.type !== "lenderFee") : []; // RC37 (forms37): listed but not ticked when the packet has the dealership's We Owe form (it lists the same we-owe lines) const woForm = seq.some(f => f.printKey === "weOweYouOwe"); if (wo.length) docs.push({ key: "duebill", label: "Due Bill — We Owe (" + wo.length + " item" + (wo.length === 1 ? "" : "s") + ")", note: "customer signs · no amounts" + (woForm ? " · the We Owe form is in this packet" : ""), checked: !woForm, copies: 2, dest: "screen", print: () => window.k2bPrintDueBill && window.k2bPrintDueBill(deal) }); } catch (e) { /* the packet prints without it */ } window.k2bPrintSelect({ title: "Deal Forms — Print Packet", context: "deal", subtitle: `${ctx.dealType || "Used"} deal${ctx.bank ? " · " + ctx.bank : ""}${ctx.state ? " · " + ctx.state : ""} — forms auto-selected by sequencing rules.`, docs, }); }; Object.assign(window, { K2BPrintSelectHost, PrintSelectDialog });