feature/IO-3357-Reynolds-and-Reynolds-DMS-API-Integration -Cleaned up DMS key check (consolidated into a helper function), Clean up DMS post form and make it agnostic, same with customer selector.
This commit is contained in:
@@ -7,6 +7,7 @@ import { createStructuredSelector } from "reselect";
|
||||
import { selectBodyshop } from "../../redux/user/user.selectors";
|
||||
import CurrencyInput from "../form-items-formatted/currency-form-item.component";
|
||||
import CiecaSelect from "../../utils/Ciecaselect";
|
||||
import { bodyshopHasDmsKey } from "../../utils/dmsUtils.js";
|
||||
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
bodyshop: selectBodyshop
|
||||
@@ -44,7 +45,7 @@ export function BillFormItemsExtendedFormItem({
|
||||
quantity: record.part_qty || 1,
|
||||
actual_price: record.act_price,
|
||||
cost_center: record.part_type
|
||||
? bodyshop.pbs_serialnumber || bodyshop.cdk_dealerid || bodyshop.rr_dealerid
|
||||
? bodyshopHasDmsKey(bodyshop)
|
||||
? record.part_type
|
||||
: responsibilityCenters.defaults && (responsibilityCenters.defaults.costs[record.part_type] || null)
|
||||
: null
|
||||
@@ -100,7 +101,7 @@ export function BillFormItemsExtendedFormItem({
|
||||
</Form.Item>
|
||||
<Form.Item label={t("billlines.fields.cost_center")} name={["billlineskeys", record.id, "cost_center"]}>
|
||||
<Select showSearch style={{ minWidth: "3rem" }} disabled={disabled}>
|
||||
{bodyshop.cdk_dealerid || bodyshop.pbs_serialnumber || bodyshop.rr_dealerid
|
||||
{bodyshopHasDmsKey(bodyshop)
|
||||
? CiecaSelect(true, false)
|
||||
: responsibilityCenters.costs.map((item) => <Select.Option key={item.name}>{item.name}</Select.Option>)}
|
||||
</Select>
|
||||
|
||||
@@ -22,6 +22,7 @@ import VendorSearchSelect from "../vendor-search-select/vendor-search-select.com
|
||||
import BillFormLines from "./bill-form.lines.component";
|
||||
import { CalculateBillTotal } from "./bill-form.totals.utility";
|
||||
import DateTimePicker from "../form-date-time-picker/form-date-time-picker.component.jsx";
|
||||
import { bodyshopHasDmsKey } from "../../utils/dmsUtils.js";
|
||||
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
bodyshop: selectBodyshop
|
||||
@@ -354,7 +355,7 @@ export function BillFormComponent({
|
||||
<Form.Item span={3} label={t("bills.fields.local_tax_rate")} name="local_tax_rate">
|
||||
<CurrencyInput min={0} />
|
||||
</Form.Item>
|
||||
{bodyshop.pbs_serialnumber || bodyshop.cdk_dealerid || bodyshop.rr_dealerid ? (
|
||||
{bodyshopHasDmsKey(bodyshop) ? (
|
||||
<Form.Item span={2} label={t("bills.labels.federal_tax_exempt")} name="federal_tax_exempt">
|
||||
<Switch onChange={handleFederalTaxExemptSwitchToggle} />
|
||||
</Form.Item>
|
||||
|
||||
@@ -10,6 +10,7 @@ import InstanceRenderManager from "../../utils/instanceRenderMgr";
|
||||
import BillLineSearchSelect from "../bill-line-search-select/bill-line-search-select.component";
|
||||
import BilllineAddInventory from "../billline-add-inventory/billline-add-inventory.component";
|
||||
import CurrencyInput from "../form-items-formatted/currency-form-item.component";
|
||||
import { bodyshopHasDmsKey } from "../../utils/dmsUtils.js";
|
||||
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
//currentUser: selectCurrentUser
|
||||
@@ -90,7 +91,7 @@ export function BillEnterModalLinesComponent({
|
||||
actual_price: opt.cost,
|
||||
original_actual_price: opt.cost,
|
||||
cost_center: opt.part_type
|
||||
? bodyshop.pbs_serialnumber || bodyshop.cdk_dealerid || bodyshop.rr_dealerid
|
||||
? bodyshopHasDmsKey(bodyshop)
|
||||
? opt.part_type !== "PAE"
|
||||
? opt.part_type
|
||||
: null
|
||||
@@ -322,7 +323,7 @@ export function BillEnterModalLinesComponent({
|
||||
},
|
||||
formInput: () => (
|
||||
<Select showSearch style={{ minWidth: "3rem" }} disabled={disabled}>
|
||||
{bodyshop.cdk_dealerid || bodyshop.pbs_serialnumber || bodyshop.rr_dealerid
|
||||
{bodyshopHasDmsKey(bodyshop)
|
||||
? CiecaSelect(true, false)
|
||||
: responsibilityCenters.costs.map((item) => <Select.Option key={item.name}>{item.name}</Select.Option>)}
|
||||
</Select>
|
||||
|
||||
@@ -1,102 +1,97 @@
|
||||
import { Alert, Button, Card, Table, Typography } from "antd";
|
||||
import { useEffect, useState } from "react";
|
||||
import { SyncOutlined } from "@ant-design/icons";
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { connect } from "react-redux";
|
||||
import { createStructuredSelector } from "reselect";
|
||||
import { selectBodyshop } from "../../redux/user/user.selectors";
|
||||
import Dinero from "dinero.js";
|
||||
import { SyncOutlined } from "@ant-design/icons";
|
||||
import { DMS_MAP } from "../../utils/dmsUtils";
|
||||
|
||||
import { selectBodyshop } from "../../redux/user/user.selectors";
|
||||
import { pageLimit } from "../../utils/config";
|
||||
import { useSplitTreatments } from "@splitsoftware/splitio-react";
|
||||
import { useSocket } from "../../contexts/SocketIO/useSocket";
|
||||
import { determineDmsType } from "../../utils/determineDMSType";
|
||||
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
//currentUser: selectCurrentUser
|
||||
bodyshop: selectBodyshop
|
||||
});
|
||||
|
||||
const mapDispatchToProps = () => ({
|
||||
//setUserLanguage: language => dispatch(setUserLanguage(language))
|
||||
});
|
||||
const mapDispatchToProps = () => ({});
|
||||
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(DmsAllocationsSummary);
|
||||
|
||||
export function DmsAllocationsSummary({ socket, bodyshop, jobId, title }) {
|
||||
/**
|
||||
* DMS Allocations Summary component
|
||||
* @param mode
|
||||
* @param socket
|
||||
* @param bodyshop
|
||||
* @param jobId
|
||||
* @param title
|
||||
* @returns {JSX.Element}
|
||||
* @constructor
|
||||
*/
|
||||
export function DmsAllocationsSummary({ mode, socket, bodyshop, jobId, title }) {
|
||||
const { t } = useTranslation();
|
||||
const [allocationsSummary, setAllocationsSummary] = useState([]);
|
||||
const {
|
||||
treatments: { Fortellis }
|
||||
} = useSplitTreatments({
|
||||
attributes: {},
|
||||
names: ["Fortellis"],
|
||||
splitKey: bodyshop.imexshopid
|
||||
});
|
||||
const { socket: wsssocket } = useSocket();
|
||||
|
||||
const dms = determineDmsType(bodyshop);
|
||||
// Resolve event name by mode (PBS reuses the CDK event per existing behavior)
|
||||
const allocationsEvent =
|
||||
mode === DMS_MAP.reynolds
|
||||
? "rr-calculate-allocations"
|
||||
: mode === DMS_MAP.fortellis
|
||||
? "fortellis-calculate-allocations"
|
||||
: /* "cdk" | "pbs" (legacy) */ "cdk-calculate-allocations";
|
||||
|
||||
const fetchAllocations = () => {
|
||||
// ✅ RR takes precedence over Fortellis
|
||||
if (dms === "rr") {
|
||||
wsssocket.emit("rr-calculate-allocations", jobId, (ack) => {
|
||||
console.dir({ ack });
|
||||
setAllocationsSummary(ack);
|
||||
socket.allocationsSummary = ack;
|
||||
});
|
||||
} else if (Fortellis.treatment === "on") {
|
||||
// Fortellis path (unchanged)
|
||||
wsssocket.emit("fortellis-calculate-allocations", jobId, (ack) => {
|
||||
setAllocationsSummary(ack);
|
||||
socket.allocationsSummary = ack;
|
||||
});
|
||||
} else if (socket.connected) {
|
||||
socket.emit("cdk-calculate-allocations", jobId, (ack) => {
|
||||
setAllocationsSummary(ack);
|
||||
socket.allocationsSummary = ack;
|
||||
const fetchAllocations = useCallback(() => {
|
||||
if (!socket || !jobId || !mode) return;
|
||||
|
||||
try {
|
||||
socket.emit(allocationsEvent, jobId, (ack) => {
|
||||
const list = Array.isArray(ack) ? ack : [];
|
||||
setAllocationsSummary(list);
|
||||
// Preserve side-channel used by the post form for discrepancy checks
|
||||
socket.allocationsSummary = list;
|
||||
});
|
||||
} catch {
|
||||
// Best-effort; leave table empty on error
|
||||
setAllocationsSummary([]);
|
||||
socket && (socket.allocationsSummary = []);
|
||||
}
|
||||
};
|
||||
}, [socket, jobId, mode, allocationsEvent]);
|
||||
|
||||
// Initial + whenever mode/socket/jobId changes
|
||||
useEffect(() => {
|
||||
fetchAllocations();
|
||||
}, [socket, socket.connected, jobId, dms, Fortellis?.treatment]);
|
||||
}, [fetchAllocations]);
|
||||
|
||||
const columns = [
|
||||
{
|
||||
title: t("jobs.fields.dms.center"),
|
||||
dataIndex: "center",
|
||||
key: "center"
|
||||
},
|
||||
{ title: t("jobs.fields.dms.center"), dataIndex: "center", key: "center" },
|
||||
{
|
||||
title: t("jobs.fields.dms.sale"),
|
||||
dataIndex: "sale",
|
||||
key: "sale",
|
||||
render: (text, record) => Dinero(record.sale).toFormat()
|
||||
render: (_text, record) => Dinero(record.sale).toFormat()
|
||||
},
|
||||
{
|
||||
title: t("jobs.fields.dms.cost"),
|
||||
dataIndex: "cost",
|
||||
key: "cost",
|
||||
render: (text, record) => Dinero(record.cost).toFormat()
|
||||
render: (_text, record) => Dinero(record.cost).toFormat()
|
||||
},
|
||||
{
|
||||
title: t("jobs.fields.dms.sale_dms_acctnumber"),
|
||||
dataIndex: "sale_dms_acctnumber",
|
||||
key: "sale_dms_acctnumber",
|
||||
render: (text, record) => record.profitCenter?.dms_acctnumber
|
||||
render: (_text, record) => record.profitCenter?.dms_acctnumber
|
||||
},
|
||||
{
|
||||
title: t("jobs.fields.dms.cost_dms_acctnumber"),
|
||||
dataIndex: "cost_dms_acctnumber",
|
||||
key: "cost_dms_acctnumber",
|
||||
render: (text, record) => record.costCenter?.dms_acctnumber
|
||||
render: (_text, record) => record.costCenter?.dms_acctnumber
|
||||
},
|
||||
{
|
||||
title: t("jobs.fields.dms.dms_wip_acctnumber"),
|
||||
dataIndex: "dms_wip_acctnumber",
|
||||
key: "dms_wip_acctnumber",
|
||||
render: (text, record) => record.costCenter?.dms_wip_acctnumber
|
||||
render: (_text, record) => record.costCenter?.dms_wip_acctnumber
|
||||
}
|
||||
];
|
||||
|
||||
@@ -104,7 +99,7 @@ export function DmsAllocationsSummary({ socket, bodyshop, jobId, title }) {
|
||||
<Card
|
||||
title={title}
|
||||
extra={
|
||||
<Button onClick={fetchAllocations}>
|
||||
<Button onClick={fetchAllocations} aria-label={t("general.actions.refresh")}>
|
||||
<SyncOutlined />
|
||||
</Button>
|
||||
}
|
||||
@@ -112,6 +107,7 @@ export function DmsAllocationsSummary({ socket, bodyshop, jobId, title }) {
|
||||
{bodyshop.pbs_configuration?.disablebillwip && (
|
||||
<Alert type="warning" message={t("jobs.labels.dms.disablebillwip")} />
|
||||
)}
|
||||
|
||||
<Table
|
||||
pagination={{ position: "top", defaultPageSize: pageLimit }}
|
||||
columns={columns}
|
||||
@@ -120,34 +116,23 @@ export function DmsAllocationsSummary({ socket, bodyshop, jobId, title }) {
|
||||
locale={{ emptyText: t("dms.labels.refreshallocations") }}
|
||||
scroll={{ x: true }}
|
||||
summary={() => {
|
||||
const totals =
|
||||
allocationsSummary &&
|
||||
allocationsSummary.reduce(
|
||||
(acc, val) => {
|
||||
return {
|
||||
totalSale: acc.totalSale.add(Dinero(val.sale)),
|
||||
totalCost: acc.totalCost.add(Dinero(val.cost))
|
||||
};
|
||||
},
|
||||
{
|
||||
totalSale: Dinero(),
|
||||
totalCost: Dinero()
|
||||
}
|
||||
);
|
||||
const totals = allocationsSummary?.reduce(
|
||||
(acc, val) => ({
|
||||
totalSale: acc.totalSale.add(Dinero(val.sale)),
|
||||
totalCost: acc.totalCost.add(Dinero(val.cost))
|
||||
}),
|
||||
{ totalSale: Dinero(), totalCost: Dinero() }
|
||||
) || { totalSale: Dinero(), totalCost: Dinero() };
|
||||
|
||||
return (
|
||||
<Table.Summary.Row>
|
||||
<Table.Summary.Cell>
|
||||
<Typography.Title level={4}>{t("general.labels.totals")}</Typography.Title>
|
||||
</Table.Summary.Cell>
|
||||
<Table.Summary.Cell>{totals && totals.totalSale.toFormat()}</Table.Summary.Cell>
|
||||
<Table.Summary.Cell>
|
||||
{
|
||||
// totals.totalCost.toFormat()
|
||||
}
|
||||
</Table.Summary.Cell>
|
||||
<Table.Summary.Cell></Table.Summary.Cell>
|
||||
<Table.Summary.Cell></Table.Summary.Cell>
|
||||
<Table.Summary.Cell>{totals.totalSale.toFormat()}</Table.Summary.Cell>
|
||||
<Table.Summary.Cell />
|
||||
<Table.Summary.Cell />
|
||||
<Table.Summary.Cell />
|
||||
</Table.Summary.Row>
|
||||
);
|
||||
}}
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
import { Button, Checkbox, Col, Table } from "antd";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { alphaSort } from "../../utils/sorters";
|
||||
|
||||
export default function CDKCustomerSelector({ bodyshop, socket }) {
|
||||
const { t } = useTranslation();
|
||||
const [open, setOpen] = useState(false);
|
||||
const [customerList, setCustomerList] = useState([]);
|
||||
const [selectedCustomer, setSelectedCustomer] = useState(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (!socket) return;
|
||||
const handleCdkSelectCustomer = (list) => {
|
||||
setOpen(true);
|
||||
setCustomerList(Array.isArray(list) ? list : []);
|
||||
setSelectedCustomer(null);
|
||||
};
|
||||
socket.on("cdk-select-customer", handleCdkSelectCustomer);
|
||||
return () => {
|
||||
socket.off("cdk-select-customer", handleCdkSelectCustomer);
|
||||
};
|
||||
}, [socket]);
|
||||
|
||||
const onUseSelected = () => {
|
||||
if (!selectedCustomer) return;
|
||||
setOpen(false);
|
||||
socket.emit("cdk-selected-customer", selectedCustomer);
|
||||
setSelectedCustomer(null);
|
||||
};
|
||||
|
||||
const onUseGeneric = () => {
|
||||
const generic = bodyshop.cdk_configuration?.generic_customer_number || null;
|
||||
setOpen(false);
|
||||
socket.emit("cdk-selected-customer", generic);
|
||||
setSelectedCustomer(null);
|
||||
};
|
||||
|
||||
const onCreateNew = () => {
|
||||
setOpen(false);
|
||||
socket.emit("cdk-selected-customer", null);
|
||||
setSelectedCustomer(null);
|
||||
};
|
||||
|
||||
if (!open) return null;
|
||||
|
||||
const columns = [
|
||||
{ title: t("jobs.fields.dms.id"), dataIndex: ["id", "value"], key: "id" },
|
||||
{
|
||||
title: t("jobs.fields.dms.vinowner"),
|
||||
dataIndex: "vinOwner",
|
||||
key: "vinOwner",
|
||||
render: (_t, r) => <Checkbox disabled checked={r.vinOwner} />
|
||||
},
|
||||
{
|
||||
title: t("jobs.fields.dms.name1"),
|
||||
dataIndex: ["name1", "fullName"],
|
||||
key: "name1",
|
||||
sorter: (a, b) => alphaSort(a.name1?.fullName, b.name1?.fullName)
|
||||
},
|
||||
{
|
||||
title: t("jobs.fields.dms.address"),
|
||||
key: "address",
|
||||
render: (record) =>
|
||||
`${record.address?.addressLine && record.address.addressLine[0]}, ${record.address?.city} ${
|
||||
record.address?.stateOrProvince
|
||||
} ${record.address?.postalCode}`
|
||||
}
|
||||
];
|
||||
|
||||
const rowKey = (r) => r.id?.value || r.customerId;
|
||||
|
||||
return (
|
||||
<Col span={24}>
|
||||
<Table
|
||||
title={() => (
|
||||
<div style={{ display: "flex", gap: 8, flexWrap: "wrap" }}>
|
||||
<Button onClick={onUseSelected} disabled={!selectedCustomer}>
|
||||
{t("jobs.actions.dms.useselected")}
|
||||
</Button>
|
||||
<Button onClick={onUseGeneric} disabled={!bodyshop.cdk_configuration?.generic_customer_number}>
|
||||
{t("jobs.actions.dms.usegeneric")}
|
||||
</Button>
|
||||
<Button onClick={onCreateNew}>{t("jobs.actions.dms.createnewcustomer")}</Button>
|
||||
</div>
|
||||
)}
|
||||
pagination={{ position: "top" }}
|
||||
columns={columns}
|
||||
rowKey={rowKey}
|
||||
dataSource={customerList}
|
||||
rowSelection={{
|
||||
onSelect: (r) => {
|
||||
const key = r.id?.value || r.customerId;
|
||||
setSelectedCustomer(key ? String(key) : null);
|
||||
},
|
||||
type: "radio",
|
||||
selectedRowKeys: selectedCustomer ? [selectedCustomer] : []
|
||||
}}
|
||||
/>
|
||||
</Col>
|
||||
);
|
||||
}
|
||||
@@ -1,14 +1,14 @@
|
||||
import { useSplitTreatments } from "@splitsoftware/splitio-react";
|
||||
import { Alert, Button, Checkbox, Col, message, Space, Table } from "antd";
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useMemo } from "react";
|
||||
import { connect } from "react-redux";
|
||||
import { createStructuredSelector } from "reselect";
|
||||
import { useSocket } from "../../contexts/SocketIO/useSocket";
|
||||
import { socket } from "../../pages/dms/dms.container";
|
||||
|
||||
import { selectBodyshop } from "../../redux/user/user.selectors";
|
||||
import { alphaSort } from "../../utils/sorters";
|
||||
import { determineDmsType } from "../../utils/determineDMSType";
|
||||
|
||||
import RRCustomerSelector from "./rr-customer-selector";
|
||||
import FortellisCustomerSelector from "./fortellis-customer-selector";
|
||||
import CDKCustomerSelector from "./cdk-customer-selector";
|
||||
import PBSCustomerSelector from "./pbs-customer-selector";
|
||||
import { DMS_MAP } from "../../utils/dmsUtils";
|
||||
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
bodyshop: selectBodyshop
|
||||
@@ -16,479 +16,39 @@ const mapStateToProps = createStructuredSelector({
|
||||
const mapDispatchToProps = () => ({});
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(DmsCustomerSelector);
|
||||
|
||||
// ---------------- Helpers ----------------
|
||||
function normalizeRrList(list) {
|
||||
if (!Array.isArray(list)) return [];
|
||||
return list
|
||||
.map((row) => {
|
||||
const custNo = row.custNo || row.CustomerId || row.customerId || null;
|
||||
const name =
|
||||
row.name ||
|
||||
[row.CustomerName?.FirstName, row.CustomerName?.LastName].filter(Boolean).join(" ").trim() ||
|
||||
(custNo ? String(custNo) : "");
|
||||
if (!custNo) return null;
|
||||
const vinOwner = !!(row.vinOwner ?? row.isVehicleOwner);
|
||||
/**
|
||||
* DMS Customer Selector component that renders the appropriate customer selector
|
||||
* @param props
|
||||
* @returns {JSX.Element|null}
|
||||
* @constructor
|
||||
*/
|
||||
export function DmsCustomerSelector(props) {
|
||||
const { bodyshop, jobid, socket, rrOptions = {} } = props;
|
||||
|
||||
const address =
|
||||
row.address && typeof row.address === "object"
|
||||
? {
|
||||
line1: row.address.line1 ?? row.address.addr1 ?? row.address.Address1 ?? undefined,
|
||||
line2: row.address.line2 ?? row.address.addr2 ?? row.address.Address2 ?? undefined,
|
||||
city: row.address.city ?? undefined,
|
||||
state: row.address.state ?? row.address.stateOrProvince ?? undefined,
|
||||
postalCode: row.address.postalCode ?? row.address.zip ?? undefined,
|
||||
country: row.address.country ?? row.address.countryCode ?? undefined
|
||||
}
|
||||
: undefined;
|
||||
// Centralized "mode" (provider + transport)
|
||||
const mode = props.mode;
|
||||
|
||||
return { custNo: String(custNo), name, vinOwner, address };
|
||||
})
|
||||
.filter(Boolean);
|
||||
}
|
||||
|
||||
function rrAddressToString(addr) {
|
||||
if (!addr) return "";
|
||||
const parts = [
|
||||
addr.line1,
|
||||
addr.line2,
|
||||
[addr.city, addr.state].filter(Boolean).join(" "),
|
||||
addr.postalCode,
|
||||
addr.country
|
||||
].filter(Boolean);
|
||||
return parts.join(", ");
|
||||
}
|
||||
|
||||
export function DmsCustomerSelector({
|
||||
bodyshop,
|
||||
jobid,
|
||||
rrOpenRoLimit = false,
|
||||
onRrOpenRoFinished,
|
||||
rrCashierPending = false,
|
||||
onRrCashierFinished
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const [customerList, setcustomerList] = useState([]);
|
||||
const [open, setOpen] = useState(false);
|
||||
const [selectedCustomer, setSelectedCustomer] = useState(null);
|
||||
const [dmsType, setDmsType] = useState("cdk");
|
||||
const [refreshing, setRefreshing] = useState(false);
|
||||
|
||||
const {
|
||||
treatments: { Fortellis }
|
||||
} = useSplitTreatments({
|
||||
attributes: {},
|
||||
names: ["Fortellis"],
|
||||
splitKey: bodyshop.imexshopid
|
||||
});
|
||||
|
||||
const { socket: wsssocket } = useSocket();
|
||||
const dms = useMemo(() => determineDmsType(bodyshop), [bodyshop]);
|
||||
|
||||
// --- owner set (RR only) ---
|
||||
const rrOwnerSet = useMemo(() => {
|
||||
return new Set(
|
||||
(Array.isArray(customerList) ? customerList : [])
|
||||
.filter((c) => c?.vinOwner || c?.isVehicleOwner)
|
||||
.map((c) => String(c.custNo))
|
||||
);
|
||||
}, [customerList]);
|
||||
const rrHasVinOwner = rrOwnerSet.size > 0;
|
||||
|
||||
// If cashiering is pending, surface this banner by opening selector
|
||||
useEffect(() => {
|
||||
if (dms === "rr" && rrCashierPending) {
|
||||
setOpen(true);
|
||||
setDmsType("rr");
|
||||
}
|
||||
}, [dms, rrCashierPending]);
|
||||
|
||||
useEffect(() => {
|
||||
if (dms === "rr") {
|
||||
const handleRrSelectCustomer = (list) => {
|
||||
const normalized = normalizeRrList(list);
|
||||
setOpen(true);
|
||||
setDmsType("rr");
|
||||
setcustomerList(normalized);
|
||||
const firstOwner = normalized.find((r) => r.vinOwner)?.custNo;
|
||||
setSelectedCustomer(firstOwner ? String(firstOwner) : null);
|
||||
setRefreshing(false); // stop any in-flight refresh spinner
|
||||
};
|
||||
|
||||
wsssocket.on("rr-select-customer", handleRrSelectCustomer);
|
||||
return () => {
|
||||
wsssocket.off("rr-select-customer", handleRrSelectCustomer);
|
||||
};
|
||||
}
|
||||
|
||||
if (Fortellis.treatment === "on") {
|
||||
const handleFortellisSelectCustomer = (list) => {
|
||||
setOpen(true);
|
||||
setDmsType("cdk");
|
||||
setcustomerList(Array.isArray(list) ? list : []);
|
||||
setSelectedCustomer(null);
|
||||
};
|
||||
wsssocket.on("fortellis-select-customer", handleFortellisSelectCustomer);
|
||||
return () => {
|
||||
wsssocket.off("fortellis-select-customer", handleFortellisSelectCustomer);
|
||||
};
|
||||
} else {
|
||||
const handleCdkSelectCustomer = (list) => {
|
||||
setOpen(true);
|
||||
setDmsType("cdk");
|
||||
setcustomerList(Array.isArray(list) ? list : []);
|
||||
setSelectedCustomer(null);
|
||||
};
|
||||
const handlePbsSelectCustomer = (list) => {
|
||||
setOpen(true);
|
||||
setDmsType("pbs");
|
||||
setcustomerList(Array.isArray(list) ? list : []);
|
||||
setSelectedCustomer(null);
|
||||
};
|
||||
socket.on("cdk-select-customer", handleCdkSelectCustomer);
|
||||
socket.on("pbs-select-customer", handlePbsSelectCustomer);
|
||||
return () => {
|
||||
socket.off("cdk-select-customer", handleCdkSelectCustomer);
|
||||
socket.off("pbs-select-customer", handlePbsSelectCustomer);
|
||||
};
|
||||
}
|
||||
}, [dms, Fortellis?.treatment, wsssocket]);
|
||||
|
||||
useEffect(() => {
|
||||
if (dmsType !== "rr" || !rrHasVinOwner) return;
|
||||
const firstOwner = (customerList.find((c) => c.vinOwner) || {}).custNo;
|
||||
if (firstOwner && String(selectedCustomer) !== String(firstOwner)) {
|
||||
setSelectedCustomer(String(firstOwner));
|
||||
}
|
||||
}, [dmsType, rrHasVinOwner, customerList]);
|
||||
|
||||
const onUseSelected = () => {
|
||||
if (!selectedCustomer) {
|
||||
message.warning(t("general.actions.select"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (dmsType === "rr" && rrHasVinOwner && !rrOwnerSet.has(String(selectedCustomer))) {
|
||||
message.warning(
|
||||
"This VIN is already assigned in Reynolds. Only the VIN owner can be selected. To choose a different customer, change ownership in Reynolds first."
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (dmsType === "rr") {
|
||||
// Keep the selector open; server will raise rr-cashiering-required
|
||||
wsssocket.emit("rr-selected-customer", { jobId: jobid, create: true }, (ack) => {
|
||||
if (ack?.ok) {
|
||||
message.success(t("dms.messages.customerCreated"));
|
||||
// Keep dialog open; cashiering banner will appear via `rr-cashiering-required`
|
||||
} else if (ack?.error) {
|
||||
message.error(ack.error);
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
setOpen(false);
|
||||
if (Fortellis.treatment === "on") {
|
||||
wsssocket.emit("fortellis-selected-customer", { selectedCustomerId: selectedCustomer, jobid });
|
||||
} else {
|
||||
socket.emit(`${dmsType}-selected-customer`, selectedCustomer);
|
||||
}
|
||||
setSelectedCustomer(null);
|
||||
};
|
||||
|
||||
const onUseGeneric = () => {
|
||||
if (dmsType === "rr" && rrHasVinOwner) return; // not rendered in RR, but keep guard
|
||||
const generic = bodyshop.cdk_configuration?.generic_customer_number || null;
|
||||
|
||||
if (dmsType === "rr") {
|
||||
return;
|
||||
} else if (Fortellis.treatment === "on") {
|
||||
setOpen(false);
|
||||
wsssocket.emit("fortellis-selected-customer", { selectedCustomerId: generic, jobid });
|
||||
} else {
|
||||
setOpen(false);
|
||||
socket.emit(`${dmsType}-selected-customer`, generic);
|
||||
}
|
||||
setSelectedCustomer(null);
|
||||
};
|
||||
|
||||
const onCreateNew = () => {
|
||||
if (dmsType === "rr" && rrHasVinOwner) return;
|
||||
|
||||
if (dmsType === "rr") {
|
||||
// Keep open; server will raise rr-cashiering-required
|
||||
wsssocket.emit("rr-selected-customer", { jobId: jobid, create: true }, (ack) => {
|
||||
if (ack?.ok) {
|
||||
if (ack.custNo) setSelectedCustomer(String(ack.custNo));
|
||||
message.success(t("dms.messages.customerCreated"));
|
||||
} else if (ack?.error) {
|
||||
message.error(ack.error);
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
setOpen(false);
|
||||
if (Fortellis.treatment === "on") {
|
||||
wsssocket.emit("fortellis-selected-customer", { selectedCustomerId: null, jobid });
|
||||
} else {
|
||||
socket.emit(`${dmsType}-selected-customer`, null);
|
||||
}
|
||||
setSelectedCustomer(null);
|
||||
};
|
||||
|
||||
// NEW: trigger a re-run of the RR combined search
|
||||
const refreshRrSearch = () => {
|
||||
if (dmsType !== "rr") return;
|
||||
setRefreshing(true);
|
||||
|
||||
// Safety timeout so the spinner can't hang forever
|
||||
const to = setTimeout(() => {
|
||||
setRefreshing(false);
|
||||
}, 12000);
|
||||
|
||||
// Stop spinner on either outcome
|
||||
const stop = () => {
|
||||
clearTimeout(to);
|
||||
setRefreshing(false);
|
||||
wsssocket.off("export-failed", stop);
|
||||
wsssocket.off("rr-select-customer", stop);
|
||||
};
|
||||
wsssocket.once("rr-select-customer", stop);
|
||||
wsssocket.once("export-failed", stop);
|
||||
|
||||
// This re-runs the name+VIN multi-search and emits rr-select-customer
|
||||
wsssocket.emit("rr-export-job", { jobId: jobid });
|
||||
};
|
||||
|
||||
const fortellisColumns = [
|
||||
{ title: t("jobs.fields.dms.id"), dataIndex: "customerId", key: "id" },
|
||||
{
|
||||
title: t("jobs.fields.dms.vinowner"),
|
||||
dataIndex: "vinOwner",
|
||||
key: "vinOwner",
|
||||
render: (_t, r) => <Checkbox disabled checked={r.vinOwner} />
|
||||
},
|
||||
{
|
||||
title: t("jobs.fields.dms.name1"),
|
||||
dataIndex: ["customerName", "firstName"],
|
||||
key: "firstName",
|
||||
sorter: (a, b) => alphaSort(a.customerName?.firstName, b.customerName?.firstName)
|
||||
},
|
||||
{
|
||||
title: t("jobs.fields.dms.name1"),
|
||||
dataIndex: ["customerName", "lastName"],
|
||||
key: "lastName",
|
||||
sorter: (a, b) => alphaSort(a.customerName?.lastName, b.customerName?.lastName)
|
||||
},
|
||||
{
|
||||
title: t("jobs.fields.dms.address"),
|
||||
key: "address",
|
||||
render: (record) =>
|
||||
`${record.postalAddress?.addressLine1 || ""}${
|
||||
record.postalAddress?.addressLine2 ? `, ${record.postalAddress.addressLine2}` : ""
|
||||
}, ${record.postalAddress?.city || ""} ${record.postalAddress?.state || ""} ${
|
||||
record.postalAddress?.postalCode || ""
|
||||
} ${record.postalAddress?.country || ""}`
|
||||
}
|
||||
];
|
||||
|
||||
const cdkColumns = [
|
||||
{ title: t("jobs.fields.dms.id"), dataIndex: ["id", "value"], key: "id" },
|
||||
{
|
||||
title: t("jobs.fields.dms.vinowner"),
|
||||
dataIndex: "vinOwner",
|
||||
key: "vinOwner",
|
||||
render: (_t, r) => <Checkbox disabled checked={r.vinOwner} />
|
||||
},
|
||||
{
|
||||
title: t("jobs.fields.dms.name1"),
|
||||
dataIndex: ["name1", "fullName"],
|
||||
key: "name1",
|
||||
sorter: (a, b) => alphaSort(a.name1?.fullName, b.name1?.fullName)
|
||||
},
|
||||
{
|
||||
title: t("jobs.fields.dms.address"),
|
||||
key: "address",
|
||||
render: (record) =>
|
||||
`${record.address?.addressLine && record.address.addressLine[0]}, ${record.address?.city} ${
|
||||
record.address?.stateOrProvince
|
||||
} ${record.address?.postalCode}`
|
||||
}
|
||||
];
|
||||
|
||||
const pbsColumns = [
|
||||
{ title: t("jobs.fields.dms.id"), dataIndex: "ContactId", key: "ContactId" },
|
||||
{
|
||||
title: t("jobs.fields.dms.name1"),
|
||||
key: "name1",
|
||||
sorter: (a, b) => alphaSort(a.LastName, b.LastName),
|
||||
render: (_t, r) => `${r.FirstName || ""} ${r.LastName || ""}`
|
||||
},
|
||||
{
|
||||
title: t("jobs.fields.dms.address"),
|
||||
key: "address",
|
||||
render: (r) => `${r.Address}, ${r.City} ${r.State} ${r.ZipCode}`
|
||||
}
|
||||
];
|
||||
|
||||
const rrColumns = [
|
||||
{ title: t("jobs.fields.dms.id"), dataIndex: "custNo", key: "custNo" },
|
||||
{
|
||||
title: t("jobs.fields.dms.vinowner"),
|
||||
dataIndex: "vinOwner",
|
||||
key: "vinOwner",
|
||||
render: (_t, r) => <Checkbox disabled checked={!!(r.vinOwner ?? r.isVehicleOwner)} />
|
||||
},
|
||||
{
|
||||
title: t("jobs.fields.dms.name1"),
|
||||
dataIndex: "name",
|
||||
key: "name",
|
||||
sorter: (a, b) => alphaSort(a?.name, b?.name)
|
||||
},
|
||||
{
|
||||
title: t("jobs.fields.dms.address"),
|
||||
key: "address",
|
||||
render: (record) => rrAddressToString(record.address)
|
||||
}
|
||||
];
|
||||
|
||||
if (!open) return null;
|
||||
|
||||
const columns =
|
||||
dmsType === "rr"
|
||||
? rrColumns
|
||||
: dmsType === "cdk"
|
||||
? Fortellis.treatment === "on"
|
||||
? fortellisColumns
|
||||
: cdkColumns
|
||||
: pbsColumns;
|
||||
|
||||
const rowKeyFn =
|
||||
dmsType === "rr"
|
||||
? (record) => record.custNo
|
||||
: dmsType === "cdk"
|
||||
? (record) => record.id?.value || record.customerId
|
||||
: (record) => record.ContactId;
|
||||
|
||||
const rrDisableRow = (record) => {
|
||||
if (dmsType !== "rr") return false;
|
||||
if (!rrHasVinOwner) return false;
|
||||
return !rrOwnerSet.has(String(record.custNo));
|
||||
};
|
||||
|
||||
return (
|
||||
<Col span={24}>
|
||||
<Table
|
||||
title={() => (
|
||||
<div style={{ display: "flex", flexDirection: "column", gap: 8 }}>
|
||||
{/* Open RO limit banner (from parent flag) */}
|
||||
{dmsType === "rr" && rrOpenRoLimit && (
|
||||
<Alert
|
||||
type="error"
|
||||
showIcon
|
||||
message="Open RO limit reached in Reynolds"
|
||||
description={
|
||||
<div style={{ display: "flex", flexDirection: "column", gap: 8 }}>
|
||||
<div>
|
||||
Reynolds has reached the maximum number of open Repair Orders for this Customer. Close or finalize
|
||||
an RO in Reynolds, then click <strong>Finished</strong> to continue.
|
||||
</div>
|
||||
<div>
|
||||
<Button type="primary" danger onClick={onRrOpenRoFinished}>
|
||||
Finished
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* NEW: Cashiering required banner */}
|
||||
{dmsType === "rr" && rrCashierPending && (
|
||||
<Alert
|
||||
type="info"
|
||||
showIcon
|
||||
message="Complete cashiering in Reynolds"
|
||||
description={
|
||||
<div style={{ display: "flex", flexDirection: "column", gap: 8 }}>
|
||||
<div>
|
||||
We created the Repair Order in Reynolds. Please complete the cashiering/closeout steps in
|
||||
Reynolds. When done, click <strong>Finished/Close</strong> to finalize and mark this export as
|
||||
complete.
|
||||
</div>
|
||||
<div>
|
||||
<Space>
|
||||
<Button type="primary" onClick={onRrCashierFinished}>
|
||||
Finished / Close
|
||||
</Button>
|
||||
</Space>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
/>
|
||||
)}
|
||||
|
||||
<div style={{ display: "flex", gap: 8, flexWrap: "wrap" }}>
|
||||
<Button onClick={onUseSelected} disabled={!selectedCustomer || (dmsType === "rr" && rrOpenRoLimit)}>
|
||||
{t("jobs.actions.dms.useselected")}
|
||||
</Button>
|
||||
|
||||
{/* Hide "Use Generic" entirely in RR mode */}
|
||||
{dmsType !== "rr" && (
|
||||
<Button onClick={onUseGeneric} disabled={!bodyshop.cdk_configuration?.generic_customer_number}>
|
||||
{t("jobs.actions.dms.usegeneric")}
|
||||
</Button>
|
||||
)}
|
||||
|
||||
<Button onClick={onCreateNew} disabled={dmsType === "rr" ? rrHasVinOwner : false}>
|
||||
{t("jobs.actions.dms.createnewcustomer")}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{/* VIN ownership enforced with Refresh */}
|
||||
{dmsType === "rr" && rrHasVinOwner && (
|
||||
<Alert
|
||||
type="warning"
|
||||
showIcon
|
||||
message="VIN ownership enforced"
|
||||
description={
|
||||
<div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", gap: 12 }}>
|
||||
<div>
|
||||
This VIN is already assigned in Reynolds. Only the VIN owner is selectable here. To use a
|
||||
different customer, please change the vehicle ownership in Reynolds first, then return to complete
|
||||
the export.
|
||||
</div>
|
||||
<Button onClick={refreshRrSearch} loading={refreshing}>
|
||||
Refresh
|
||||
</Button>
|
||||
</div>
|
||||
}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
pagination={{ position: "top" }}
|
||||
columns={columns}
|
||||
rowKey={rowKeyFn}
|
||||
dataSource={customerList}
|
||||
rowSelection={{
|
||||
onSelect: (record) => {
|
||||
const key =
|
||||
dmsType === "rr"
|
||||
? record.custNo
|
||||
: dmsType === "cdk"
|
||||
? record.id?.value || record.customerId
|
||||
: record.ContactId;
|
||||
setSelectedCustomer(key ? String(key) : null);
|
||||
},
|
||||
type: "radio",
|
||||
selectedRowKeys: selectedCustomer ? [selectedCustomer] : [],
|
||||
getCheckboxProps: (record) => ({
|
||||
disabled: rrDisableRow(record)
|
||||
})
|
||||
}}
|
||||
/>
|
||||
</Col>
|
||||
);
|
||||
// Stable base props for children
|
||||
const base = useMemo(() => ({ bodyshop, jobid, socket }), [bodyshop, jobid, socket]);
|
||||
|
||||
switch (mode) {
|
||||
case DMS_MAP.reynolds: {
|
||||
// Map rrOptions to current RR prop shape (you can also just pass rrOptions through and unpack in RR)
|
||||
const rrProps = {
|
||||
rrOpenRoLimit: rrOptions.openRoLimit,
|
||||
onRrOpenRoFinished: rrOptions.onOpenRoFinished,
|
||||
rrCashierPending: rrOptions.cashierPending,
|
||||
onRrCashierFinished: rrOptions.onCashierFinished
|
||||
};
|
||||
return <RRCustomerSelector {...base} {...rrProps} />;
|
||||
}
|
||||
case DMS_MAP.fortellis:
|
||||
return <FortellisCustomerSelector {...base} />;
|
||||
case DMS_MAP.cdk:
|
||||
return <CDKCustomerSelector {...base} />;
|
||||
case DMS_MAP.pbs:
|
||||
return <PBSCustomerSelector {...base} />;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
import { Button, Checkbox, Col, Table } from "antd";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { alphaSort } from "../../utils/sorters";
|
||||
|
||||
export default function FortellisCustomerSelector({ bodyshop, jobid, socket }) {
|
||||
const { t } = useTranslation();
|
||||
const [open, setOpen] = useState(false);
|
||||
const [customerList, setCustomerList] = useState([]);
|
||||
const [selectedCustomer, setSelectedCustomer] = useState(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (!socket) return;
|
||||
const handleFortellisSelectCustomer = (list) => {
|
||||
setOpen(true);
|
||||
setCustomerList(Array.isArray(list) ? list : []);
|
||||
setSelectedCustomer(null);
|
||||
};
|
||||
socket.on("fortellis-select-customer", handleFortellisSelectCustomer);
|
||||
return () => {
|
||||
socket.off("fortellis-select-customer", handleFortellisSelectCustomer);
|
||||
};
|
||||
}, [socket]);
|
||||
|
||||
const onUseSelected = () => {
|
||||
if (!selectedCustomer) return;
|
||||
setOpen(false);
|
||||
socket.emit("fortellis-selected-customer", { selectedCustomerId: selectedCustomer, jobid });
|
||||
setSelectedCustomer(null);
|
||||
};
|
||||
|
||||
const onUseGeneric = () => {
|
||||
const generic = bodyshop.cdk_configuration?.generic_customer_number || null;
|
||||
setOpen(false);
|
||||
socket.emit("fortellis-selected-customer", { selectedCustomerId: generic, jobid });
|
||||
setSelectedCustomer(null);
|
||||
};
|
||||
|
||||
const onCreateNew = () => {
|
||||
setOpen(false);
|
||||
socket.emit("fortellis-selected-customer", { selectedCustomerId: null, jobid });
|
||||
setSelectedCustomer(null);
|
||||
};
|
||||
|
||||
if (!open) return null;
|
||||
|
||||
const columns = [
|
||||
{ title: t("jobs.fields.dms.id"), dataIndex: "customerId", key: "id" },
|
||||
{
|
||||
title: t("jobs.fields.dms.vinowner"),
|
||||
dataIndex: "vinOwner",
|
||||
key: "vinOwner",
|
||||
render: (_t, r) => <Checkbox disabled checked={r.vinOwner} />
|
||||
},
|
||||
{
|
||||
title: t("jobs.fields.dms.name1"),
|
||||
dataIndex: ["customerName", "firstName"],
|
||||
key: "firstName",
|
||||
sorter: (a, b) => alphaSort(a.customerName?.firstName, b.customerName?.firstName)
|
||||
},
|
||||
{
|
||||
title: t("jobs.fields.dms.name1"),
|
||||
dataIndex: ["customerName", "lastName"],
|
||||
key: "lastName",
|
||||
sorter: (a, b) => alphaSort(a.customerName?.lastName, b.customerName?.lastName)
|
||||
},
|
||||
{
|
||||
title: t("jobs.fields.dms.address"),
|
||||
key: "address",
|
||||
render: (record) =>
|
||||
`${record.postalAddress?.addressLine1 || ""}${
|
||||
record.postalAddress?.addressLine2 ? `, ${record.postalAddress.addressLine2}` : ""
|
||||
}, ${record.postalAddress?.city || ""} ${record.postalAddress?.state || ""} ${
|
||||
record.postalAddress?.postalCode || ""
|
||||
} ${record.postalAddress?.country || ""}`
|
||||
}
|
||||
];
|
||||
|
||||
return (
|
||||
<Col span={24}>
|
||||
<Table
|
||||
title={() => (
|
||||
<div style={{ display: "flex", gap: 8, flexWrap: "wrap" }}>
|
||||
<Button onClick={onUseSelected} disabled={!selectedCustomer}>
|
||||
{t("jobs.actions.dms.useselected")}
|
||||
</Button>
|
||||
<Button onClick={onUseGeneric} disabled={!bodyshop.cdk_configuration?.generic_customer_number}>
|
||||
{t("jobs.actions.dms.usegeneric")}
|
||||
</Button>
|
||||
<Button onClick={onCreateNew}>{t("jobs.actions.dms.createnewcustomer")}</Button>
|
||||
</div>
|
||||
)}
|
||||
pagination={{ position: "top" }}
|
||||
columns={columns}
|
||||
rowKey={(r) => r.customerId}
|
||||
dataSource={customerList}
|
||||
rowSelection={{
|
||||
onSelect: (r) => setSelectedCustomer(r?.customerId ? String(r.customerId) : null),
|
||||
type: "radio",
|
||||
selectedRowKeys: selectedCustomer ? [selectedCustomer] : []
|
||||
}}
|
||||
/>
|
||||
</Col>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
import { Button, Col, Table } from "antd";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { alphaSort } from "../../utils/sorters";
|
||||
|
||||
export default function PBSCustomerSelector({ bodyshop, socket }) {
|
||||
const { t } = useTranslation();
|
||||
const [open, setOpen] = useState(false);
|
||||
const [customerList, setCustomerList] = useState([]);
|
||||
const [selectedCustomer, setSelectedCustomer] = useState(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (!socket) return;
|
||||
const handlePbsSelectCustomer = (list) => {
|
||||
setOpen(true);
|
||||
setCustomerList(Array.isArray(list) ? list : []);
|
||||
setSelectedCustomer(null);
|
||||
};
|
||||
socket.on("pbs-select-customer", handlePbsSelectCustomer);
|
||||
return () => {
|
||||
socket.off("pbs-select-customer", handlePbsSelectCustomer);
|
||||
};
|
||||
}, [socket]);
|
||||
|
||||
const onUseSelected = () => {
|
||||
if (!selectedCustomer) return;
|
||||
setOpen(false);
|
||||
socket.emit("pbs-selected-customer", selectedCustomer);
|
||||
setSelectedCustomer(null);
|
||||
};
|
||||
|
||||
// Restores old behavior: reuse the CDK-named generic number for PBS too,
|
||||
// matching the previous single-component implementation.
|
||||
const onUseGeneric = () => {
|
||||
const generic = bodyshop?.cdk_configuration?.generic_customer_number || null;
|
||||
if (!generic) return;
|
||||
setOpen(false);
|
||||
socket.emit("pbs-selected-customer", generic);
|
||||
setSelectedCustomer(null);
|
||||
};
|
||||
|
||||
const onCreateNew = () => {
|
||||
setOpen(false);
|
||||
socket.emit("pbs-selected-customer", null);
|
||||
setSelectedCustomer(null);
|
||||
};
|
||||
|
||||
if (!open) return null;
|
||||
|
||||
const columns = [
|
||||
{ title: t("jobs.fields.dms.id"), dataIndex: "ContactId", key: "ContactId" },
|
||||
{
|
||||
title: t("jobs.fields.dms.name1"),
|
||||
key: "name1",
|
||||
sorter: (a, b) => alphaSort(a.LastName, b.LastName),
|
||||
render: (_t, r) => `${r.FirstName || ""} ${r.LastName || ""}`
|
||||
},
|
||||
{
|
||||
title: t("jobs.fields.dms.address"),
|
||||
key: "address",
|
||||
render: (r) => `${r.Address}, ${r.City} ${r.State} ${r.ZipCode}`
|
||||
}
|
||||
];
|
||||
|
||||
const hasGeneric = !!bodyshop?.cdk_configuration?.generic_customer_number;
|
||||
|
||||
return (
|
||||
<Col span={24}>
|
||||
<Table
|
||||
title={() => (
|
||||
<div style={{ display: "flex", gap: 8, flexWrap: "wrap" }}>
|
||||
<Button onClick={onUseSelected} disabled={!selectedCustomer}>
|
||||
{t("jobs.actions.dms.useselected")}
|
||||
</Button>
|
||||
<Button onClick={onUseGeneric} disabled={!hasGeneric}>
|
||||
{t("jobs.actions.dms.usegeneric")}
|
||||
</Button>
|
||||
<Button onClick={onCreateNew}>{t("jobs.actions.dms.createnewcustomer")}</Button>
|
||||
</div>
|
||||
)}
|
||||
pagination={{ position: "top" }}
|
||||
columns={columns}
|
||||
rowKey={(r) => r.ContactId}
|
||||
dataSource={customerList}
|
||||
rowSelection={{
|
||||
onSelect: (r) => setSelectedCustomer(r?.ContactId ? String(r.ContactId) : null),
|
||||
type: "radio",
|
||||
selectedRowKeys: selectedCustomer ? [selectedCustomer] : []
|
||||
}}
|
||||
/>
|
||||
</Col>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,268 @@
|
||||
import { Alert, Button, Checkbox, Col, message, Space, Table } from "antd";
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { alphaSort } from "../../utils/sorters";
|
||||
|
||||
const normalizeRrList = (list) => {
|
||||
if (!Array.isArray(list)) return [];
|
||||
return list
|
||||
.map((row) => {
|
||||
const custNo = row.custNo || row.CustomerId || row.customerId || null;
|
||||
const name =
|
||||
row.name ||
|
||||
[row.CustomerName?.FirstName, row.CustomerName?.LastName].filter(Boolean).join(" ").trim() ||
|
||||
(custNo ? String(custNo) : "");
|
||||
if (!custNo) return null;
|
||||
const vinOwner = !!(row.vinOwner ?? row.isVehicleOwner);
|
||||
|
||||
const address =
|
||||
row.address && typeof row.address === "object"
|
||||
? {
|
||||
line1: row.address.line1 ?? row.address.addr1 ?? row.address.Address1 ?? undefined,
|
||||
line2: row.address.line2 ?? row.address.addr2 ?? row.address.Address2 ?? undefined,
|
||||
city: row.address.city ?? undefined,
|
||||
state: row.address.state ?? row.address.stateOrProvince ?? undefined,
|
||||
postalCode: row.address.postalCode ?? row.address.zip ?? undefined,
|
||||
country: row.address.country ?? row.address.countryCode ?? undefined
|
||||
}
|
||||
: undefined;
|
||||
|
||||
return { custNo: String(custNo), name, vinOwner, address };
|
||||
})
|
||||
.filter(Boolean);
|
||||
};
|
||||
|
||||
const rrAddressToString = (addr) => {
|
||||
if (!addr) return "";
|
||||
const parts = [
|
||||
addr.line1,
|
||||
addr.line2,
|
||||
[addr.city, addr.state].filter(Boolean).join(" "),
|
||||
addr.postalCode,
|
||||
addr.country
|
||||
].filter(Boolean);
|
||||
return parts.join(", ");
|
||||
};
|
||||
|
||||
export default function RRCustomerSelector({
|
||||
jobid,
|
||||
socket,
|
||||
rrOpenRoLimit = false,
|
||||
onRrOpenRoFinished,
|
||||
rrCashierPending = false,
|
||||
onRrCashierFinished
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const [open, setOpen] = useState(false);
|
||||
const [customerList, setCustomerList] = useState([]);
|
||||
const [selectedCustomer, setSelectedCustomer] = useState(null);
|
||||
const [refreshing, setRefreshing] = useState(false);
|
||||
|
||||
// Show dialog automatically when cashiering is pending
|
||||
useEffect(() => {
|
||||
if (rrCashierPending) setOpen(true);
|
||||
}, [rrCashierPending]);
|
||||
|
||||
// Listen for RR customer selection list
|
||||
useEffect(() => {
|
||||
if (!socket) return;
|
||||
const handleRrSelectCustomer = (list) => {
|
||||
const normalized = normalizeRrList(list);
|
||||
setOpen(true);
|
||||
setCustomerList(normalized);
|
||||
const firstOwner = normalized.find((r) => r.vinOwner)?.custNo;
|
||||
setSelectedCustomer(firstOwner ? String(firstOwner) : null);
|
||||
setRefreshing(false);
|
||||
};
|
||||
socket.on("rr-select-customer", handleRrSelectCustomer);
|
||||
return () => {
|
||||
socket.off("rr-select-customer", handleRrSelectCustomer);
|
||||
};
|
||||
}, [socket]);
|
||||
|
||||
// VIN owner set
|
||||
const rrOwnerSet = useMemo(() => {
|
||||
return new Set(customerList.filter((c) => c?.vinOwner || c?.isVehicleOwner).map((c) => String(c.custNo)));
|
||||
}, [customerList]);
|
||||
const rrHasVinOwner = rrOwnerSet.size > 0;
|
||||
|
||||
// Enforce VIN owner stays selected if present
|
||||
useEffect(() => {
|
||||
if (!rrHasVinOwner) return;
|
||||
const firstOwner = (customerList.find((c) => c.vinOwner) || {}).custNo;
|
||||
if (firstOwner && String(selectedCustomer) !== String(firstOwner)) {
|
||||
setSelectedCustomer(String(firstOwner));
|
||||
}
|
||||
}, [rrHasVinOwner, customerList, selectedCustomer]);
|
||||
|
||||
const onUseSelected = () => {
|
||||
if (!selectedCustomer) {
|
||||
message.warning(t("general.actions.select"));
|
||||
return;
|
||||
}
|
||||
if (rrHasVinOwner && !rrOwnerSet.has(String(selectedCustomer))) {
|
||||
message.warning(
|
||||
"This VIN is already assigned in Reynolds. Only the VIN owner can be selected. To choose a different customer, change ownership in Reynolds first."
|
||||
);
|
||||
return;
|
||||
}
|
||||
socket.emit("rr-selected-customer", { jobId: jobid, custNo: String(selectedCustomer) }, (ack) => {
|
||||
if (ack?.ok) {
|
||||
message.success(t("dms.messages.customerSelected"));
|
||||
} else if (ack?.error) {
|
||||
message.error(ack.error);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const onCreateNew = () => {
|
||||
if (rrHasVinOwner) return;
|
||||
socket.emit("rr-selected-customer", { jobId: jobid, create: true }, (ack) => {
|
||||
if (ack?.ok) {
|
||||
if (ack.custNo) setSelectedCustomer(String(ack.custNo));
|
||||
message.success(t("dms.messages.customerCreated"));
|
||||
} else if (ack?.error) {
|
||||
message.error(ack.error);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const refreshRrSearch = () => {
|
||||
setRefreshing(true);
|
||||
const to = setTimeout(() => setRefreshing(false), 12000);
|
||||
const stop = () => {
|
||||
clearTimeout(to);
|
||||
setRefreshing(false);
|
||||
socket.off("export-failed", stop);
|
||||
socket.off("rr-select-customer", stop);
|
||||
};
|
||||
socket.once("rr-select-customer", stop);
|
||||
socket.once("export-failed", stop);
|
||||
socket.emit("rr-export-job", { jobId: jobid });
|
||||
};
|
||||
|
||||
if (!open) return null;
|
||||
|
||||
const columns = [
|
||||
{ title: t("jobs.fields.dms.id"), dataIndex: "custNo", key: "custNo" },
|
||||
{
|
||||
title: t("jobs.fields.dms.vinowner"),
|
||||
dataIndex: "vinOwner",
|
||||
key: "vinOwner",
|
||||
render: (_t, r) => <Checkbox disabled checked={!!(r.vinOwner ?? r.isVehicleOwner)} />
|
||||
},
|
||||
{
|
||||
title: t("jobs.fields.dms.name1"),
|
||||
dataIndex: "name",
|
||||
key: "name",
|
||||
sorter: (a, b) => alphaSort(a?.name, b?.name)
|
||||
},
|
||||
{
|
||||
title: t("jobs.fields.dms.address"),
|
||||
key: "address",
|
||||
render: (record) => rrAddressToString(record.address)
|
||||
}
|
||||
];
|
||||
|
||||
const rrDisableRow = (record) => {
|
||||
if (!rrHasVinOwner) return false;
|
||||
return !rrOwnerSet.has(String(record.custNo));
|
||||
};
|
||||
|
||||
return (
|
||||
<Col span={24}>
|
||||
<Table
|
||||
title={() => (
|
||||
<div style={{ display: "flex", flexDirection: "column", gap: 8 }}>
|
||||
{/* Open RO limit banner */}
|
||||
{rrOpenRoLimit && (
|
||||
<Alert
|
||||
type="error"
|
||||
showIcon
|
||||
message="Open RO limit reached in Reynolds"
|
||||
description={
|
||||
<div style={{ display: "flex", flexDirection: "column", gap: 8 }}>
|
||||
<div>
|
||||
Reynolds has reached the maximum number of open Repair Orders for this Customer. Close or finalize
|
||||
an RO in Reynolds, then click <strong>Finished</strong> to continue.
|
||||
</div>
|
||||
<div>
|
||||
<Button type="primary" danger onClick={onRrOpenRoFinished}>
|
||||
Finished
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* Cashiering step banner */}
|
||||
{rrCashierPending && (
|
||||
<Alert
|
||||
type="info"
|
||||
showIcon
|
||||
message="Complete cashiering in Reynolds"
|
||||
description={
|
||||
<div style={{ display: "flex", flexDirection: "column", gap: 8 }}>
|
||||
<div>
|
||||
We created the Repair Order in Reynolds. Please complete the cashiering/closeout steps in
|
||||
Reynolds. When done, click <strong>Finished/Close</strong> to finalize and mark this export as
|
||||
complete.
|
||||
</div>
|
||||
<div>
|
||||
<Space>
|
||||
<Button type="primary" onClick={onRrCashierFinished}>
|
||||
Finished / Close
|
||||
</Button>
|
||||
</Space>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
/>
|
||||
)}
|
||||
|
||||
<div style={{ display: "flex", gap: 8, flexWrap: "wrap" }}>
|
||||
<Button onClick={onUseSelected} disabled={!selectedCustomer || rrOpenRoLimit}>
|
||||
{t("jobs.actions.dms.useselected")}
|
||||
</Button>
|
||||
{/* No generic in RR */}
|
||||
<Button onClick={onCreateNew} disabled={rrHasVinOwner}>
|
||||
{t("jobs.actions.dms.createnewcustomer")}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{rrHasVinOwner && (
|
||||
<Alert
|
||||
type="warning"
|
||||
showIcon
|
||||
message="VIN ownership enforced"
|
||||
description={
|
||||
<div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", gap: 12 }}>
|
||||
<div>
|
||||
This VIN is already assigned in Reynolds. Only the VIN owner is selectable here. To use a
|
||||
different customer, please change the vehicle ownership in Reynolds first, then return to complete
|
||||
the export.
|
||||
</div>
|
||||
<Button onClick={refreshRrSearch} loading={refreshing}>
|
||||
Refresh
|
||||
</Button>
|
||||
</div>
|
||||
}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
pagination={{ position: "top" }}
|
||||
columns={columns}
|
||||
rowKey={(r) => r.custNo}
|
||||
dataSource={customerList}
|
||||
rowSelection={{
|
||||
onSelect: (record) => setSelectedCustomer(record?.custNo ? String(record.custNo) : null),
|
||||
type: "radio",
|
||||
selectedRowKeys: selectedCustomer ? [selectedCustomer] : [],
|
||||
getCheckboxProps: (record) => ({ disabled: rrDisableRow(record) })
|
||||
}}
|
||||
/>
|
||||
</Col>
|
||||
);
|
||||
}
|
||||
@@ -3,17 +3,13 @@ import { useEffect, useMemo, useState } from "react";
|
||||
import dayjs from "../../utils/day";
|
||||
import { connect } from "react-redux";
|
||||
import { createStructuredSelector } from "reselect";
|
||||
import { setBreadcrumbs, setSelectedHeader } from "../../redux/application/application.actions";
|
||||
import { selectDarkMode } from "../../redux/application/application.selectors.js";
|
||||
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
isDarkMode: selectDarkMode
|
||||
});
|
||||
|
||||
const mapDispatchToProps = (dispatch) => ({
|
||||
setBreadcrumbs: (breadcrumbs) => dispatch(setBreadcrumbs(breadcrumbs)),
|
||||
setSelectedHeader: (key) => dispatch(setSelectedHeader(key))
|
||||
});
|
||||
const mapDispatchToProps = () => ({});
|
||||
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(DmsLogEvents);
|
||||
|
||||
|
||||
403
client/src/components/dms-post-form/cdklike-dms-post-form.jsx
Normal file
403
client/src/components/dms-post-form/cdklike-dms-post-form.jsx
Normal file
@@ -0,0 +1,403 @@
|
||||
import { DeleteFilled, DownOutlined } from "@ant-design/icons";
|
||||
import {
|
||||
Button,
|
||||
Card,
|
||||
Col,
|
||||
Divider,
|
||||
Dropdown,
|
||||
Form,
|
||||
Input,
|
||||
InputNumber,
|
||||
Row,
|
||||
Select,
|
||||
Space,
|
||||
Statistic,
|
||||
Switch,
|
||||
Tooltip,
|
||||
Typography
|
||||
} from "antd";
|
||||
import Dinero from "dinero.js";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useMemo, useState } from "react";
|
||||
import i18n from "../../translations/i18n";
|
||||
import dayjs from "../../utils/day";
|
||||
import DmsCdkMakes from "../dms-cdk-makes/dms-cdk-makes.component";
|
||||
import DmsCdkMakesRefetch from "../dms-cdk-makes/dms-cdk-makes.refetch.component";
|
||||
import DateTimePicker from "../form-date-time-picker/form-date-time-picker.component.jsx";
|
||||
import CurrencyInput from "../form-items-formatted/currency-form-item.component";
|
||||
import { DMS_MAP } from "../../utils/dmsUtils";
|
||||
|
||||
/**
|
||||
* CDK-like DMS post form:
|
||||
* - CDK / Fortellis / PBS
|
||||
* - CDK vehicle details + make/model selection
|
||||
* - Payer list with discrepancy gating
|
||||
* - Submit: "{mode}-export-job"
|
||||
* @param bodyshop
|
||||
* @param socket
|
||||
* @param job
|
||||
* @param logsRef
|
||||
* @param mode
|
||||
* @returns {JSX.Element}
|
||||
* @constructor
|
||||
*/
|
||||
export default function CdkLikePostForm({ bodyshop, socket, job, logsRef, mode }) {
|
||||
const [form] = Form.useForm();
|
||||
const { t } = useTranslation();
|
||||
const [, /*unused*/ setTick] = useState(0); // handy if you need a forceUpdate later
|
||||
|
||||
const initialValues = useMemo(
|
||||
() => ({
|
||||
story: `${t("jobs.labels.dms.defaultstory", {
|
||||
ro_number: job.ro_number,
|
||||
ownr_nm: `${job.ownr_fn || ""} ${job.ownr_ln || ""} ${job.ownr_co_nm || ""}`.trim(),
|
||||
ins_co_nm: job.ins_co_nm || "N/A",
|
||||
clm_po: `${job.clm_no ? `${job.clm_no} ` : ""}${job.po_number || ""}`
|
||||
}).trim()}.${
|
||||
job.area_of_damage?.impact1
|
||||
? " " +
|
||||
t("jobs.labels.dms.damageto", {
|
||||
area_of_damage: (job.area_of_damage && job.area_of_damage.impact1.padStart(2, "0")) || "UNKNOWN"
|
||||
})
|
||||
: ""
|
||||
}`.slice(0, 239),
|
||||
inservicedate: dayjs(
|
||||
`${
|
||||
(job.v_model_yr &&
|
||||
(job.v_model_yr < 100
|
||||
? job.v_model_yr >= (dayjs().year() + 1) % 100
|
||||
? 1900 + parseInt(job.v_model_yr, 10)
|
||||
: 2000 + parseInt(job.v_model_yr, 10)
|
||||
: job.v_model_yr)) ||
|
||||
2019
|
||||
}-01-01`
|
||||
),
|
||||
journal: bodyshop.cdk_configuration?.default_journal
|
||||
}),
|
||||
[job, bodyshop, t]
|
||||
);
|
||||
|
||||
// Payers helpers
|
||||
const handlePayerSelect = (value, index) => {
|
||||
form.setFieldsValue({
|
||||
payers: (form.getFieldValue("payers") || []).map((payer, mapIndex) => {
|
||||
if (index !== mapIndex) return payer;
|
||||
const cdkPayer =
|
||||
bodyshop.cdk_configuration.payers && bodyshop.cdk_configuration.payers.find((i) => i.name === value);
|
||||
if (!cdkPayer) return payer;
|
||||
return {
|
||||
...cdkPayer,
|
||||
dms_acctnumber: cdkPayer.dms_acctnumber,
|
||||
controlnumber: job?.[cdkPayer.control_type]
|
||||
};
|
||||
})
|
||||
});
|
||||
setTick((n) => n + 1);
|
||||
};
|
||||
|
||||
const handleFinish = (values) => {
|
||||
if (!socket) return;
|
||||
|
||||
if (mode === DMS_MAP.fortellis) {
|
||||
socket.emit("fortellis-export-job", {
|
||||
jobid: job.id,
|
||||
txEnvelope: { ...values, SubscriptionID: bodyshop.cdk_dealerid }
|
||||
});
|
||||
} else {
|
||||
socket.emit(`${mode}-export-job`, { jobid: job.id, txEnvelope: values });
|
||||
}
|
||||
|
||||
logsRef?.current?.scrollIntoView({ behavior: "smooth" });
|
||||
};
|
||||
|
||||
// Totals & discrepancy
|
||||
const totals = socket?.allocationsSummary
|
||||
? socket.allocationsSummary.reduce(
|
||||
(acc, val) => ({
|
||||
totalSale: acc.totalSale.add(Dinero(val.sale)),
|
||||
totalCost: acc.totalCost.add(Dinero(val.cost))
|
||||
}),
|
||||
{ totalSale: Dinero(), totalCost: Dinero() }
|
||||
)
|
||||
: { totalSale: Dinero(), totalCost: Dinero() };
|
||||
|
||||
return (
|
||||
<Card title={t("jobs.labels.dms.postingform")}>
|
||||
<Form
|
||||
form={form}
|
||||
layout="vertical"
|
||||
onFinish={handleFinish}
|
||||
style={{ width: "100%" }}
|
||||
initialValues={initialValues}
|
||||
>
|
||||
{/* TOP ROW */}
|
||||
<Row gutter={[16, 12]} align="bottom">
|
||||
<Col xs={24} sm={12} md={8} lg={6}>
|
||||
<Form.Item name="journal" label={t("jobs.fields.dms.journal")} rules={[{ required: true }]}>
|
||||
<Input />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
|
||||
<Col xs={12} sm={8} md={6} lg={4}>
|
||||
<Form.Item name="kmin" label={t("jobs.fields.kmin")} initialValue={job?.kmin} rules={[{ required: true }]}>
|
||||
<InputNumber style={{ width: "100%" }} disabled />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
|
||||
<Col xs={12} sm={8} md={6} lg={4}>
|
||||
<Form.Item
|
||||
name="kmout"
|
||||
label={t("jobs.fields.kmout")}
|
||||
initialValue={job?.kmout}
|
||||
rules={[{ required: true }]}
|
||||
>
|
||||
<InputNumber style={{ width: "100%" }} disabled />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
{/* CDK vehicle details (kept for CDK/Fortellis paths when dealer id exists) */}
|
||||
{bodyshop.cdk_dealerid && (
|
||||
<>
|
||||
<Row gutter={[16, 12]}>
|
||||
<Col xs={24} sm={12} md={8}>
|
||||
<Form.Item name="dms_make" label={t("jobs.fields.dms.dms_make")} rules={[{ required: true }]}>
|
||||
<Input />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
<Col xs={24} sm={12} md={8}>
|
||||
<Form.Item name="dms_model" label={t("jobs.fields.dms.dms_model")} rules={[{ required: true }]}>
|
||||
<Input />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
<Col xs={24} sm={12} md={8}>
|
||||
<Form.Item name="inservicedate" label={t("jobs.fields.dms.inservicedate")}>
|
||||
<DateTimePicker isDateOnly />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
<Row gutter={[16, 12]} align="middle">
|
||||
<Col>
|
||||
<DmsCdkMakes form={form} job={job} />
|
||||
</Col>
|
||||
<Col>
|
||||
<DmsCdkMakesRefetch />
|
||||
</Col>
|
||||
<Col>
|
||||
<Form.Item name="dms_unsold" label={t("jobs.fields.dms.dms_unsold")} initialValue={false}>
|
||||
<Switch />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
<Col>
|
||||
<Form.Item
|
||||
name="dms_model_override"
|
||||
label={t("jobs.fields.dms.dms_model_override")}
|
||||
initialValue={false}
|
||||
>
|
||||
<Switch />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
</Row>
|
||||
</>
|
||||
)}
|
||||
|
||||
<Row gutter={[16, 12]}>
|
||||
<Col span={24}>
|
||||
<Form.Item name="story" label={t("jobs.fields.dms.story")} rules={[{ required: true }]}>
|
||||
<Input.TextArea maxLength={240} />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
<Divider />
|
||||
|
||||
{/* Totals */}
|
||||
<Space size="large" wrap align="center" style={{ marginBottom: 16 }}>
|
||||
<Statistic
|
||||
title={t("jobs.fields.ded_amt")}
|
||||
value={Dinero(job.job_totals.totals.custPayable.deductible).toFormat()}
|
||||
/>
|
||||
<Statistic
|
||||
title={t("jobs.labels.total_cust_payable")}
|
||||
value={Dinero(job.job_totals.totals.custPayable.total).toFormat()}
|
||||
/>
|
||||
<Statistic
|
||||
title={t("jobs.labels.net_repairs")}
|
||||
value={Dinero(job.job_totals.totals.net_repairs).toFormat()}
|
||||
/>
|
||||
</Space>
|
||||
|
||||
{/* Payers list */}
|
||||
<Divider />
|
||||
<Form.List name={["payers"]}>
|
||||
{(fields, { add, remove }) => (
|
||||
<div>
|
||||
{fields.map((field, index) => (
|
||||
<Card
|
||||
key={field.key}
|
||||
size="small"
|
||||
style={{ marginBottom: 12 }}
|
||||
title={`${t("jobs.fields.dms.payer.payer_type")} #${index + 1}`}
|
||||
extra={
|
||||
<Tooltip title={t("general.actions.remove", "Remove")}>
|
||||
<Button
|
||||
type="text"
|
||||
danger
|
||||
icon={<DeleteFilled />}
|
||||
aria-label={t("general.actions.remove", "Remove")}
|
||||
onClick={() => remove(field.name)}
|
||||
/>
|
||||
</Tooltip>
|
||||
}
|
||||
>
|
||||
<Row gutter={[16, 8]} align="middle">
|
||||
<Col xs={24} sm={12} md={8} lg={6}>
|
||||
<Form.Item
|
||||
label={t("jobs.fields.dms.payer.name")}
|
||||
name={[field.name, "name"]}
|
||||
rules={[{ required: true }]}
|
||||
>
|
||||
<Select style={{ minWidth: "15rem" }} onSelect={(value) => handlePayerSelect(value, index)}>
|
||||
{bodyshop.cdk_configuration?.payers?.map((payer) => (
|
||||
<Select.Option key={payer.name}>{payer.name}</Select.Option>
|
||||
))}
|
||||
</Select>
|
||||
</Form.Item>
|
||||
</Col>
|
||||
|
||||
<Col xs={24} sm={12} md={8} lg={6}>
|
||||
<Form.Item
|
||||
label={t("jobs.fields.dms.payer.dms_acctnumber")}
|
||||
name={[field.name, "dms_acctnumber"]}
|
||||
rules={[{ required: true }]}
|
||||
>
|
||||
<Input disabled />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
|
||||
<Col xs={24} sm={12} md={8} lg={5}>
|
||||
<Form.Item
|
||||
label={t("jobs.fields.dms.payer.amount")}
|
||||
name={[field.name, "amount"]}
|
||||
rules={[{ required: true }]}
|
||||
>
|
||||
<CurrencyInput min={0} />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
|
||||
<Col xs={24} sm={12} md={10} lg={7}>
|
||||
<Form.Item
|
||||
label={
|
||||
<div>
|
||||
{t("jobs.fields.dms.payer.controlnumber")}{" "}
|
||||
<Dropdown
|
||||
trigger={["click"]}
|
||||
menu={{
|
||||
items:
|
||||
bodyshop.cdk_configuration.controllist?.map((key, idx) => ({
|
||||
key: idx,
|
||||
label: key.name,
|
||||
onClick: () => {
|
||||
form.setFieldsValue({
|
||||
payers: (form.getFieldValue("payers") || []).map((row, mapIndex) => {
|
||||
if (index !== mapIndex) return row;
|
||||
return { ...row, controlnumber: key.controlnumber };
|
||||
})
|
||||
});
|
||||
}
|
||||
})) ?? []
|
||||
}}
|
||||
>
|
||||
<a href="#" onClick={(e) => e.preventDefault()}>
|
||||
<DownOutlined />
|
||||
</a>
|
||||
</Dropdown>
|
||||
</div>
|
||||
}
|
||||
name={[field.name, "controlnumber"]}
|
||||
rules={[{ required: true }]}
|
||||
>
|
||||
<Input />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
|
||||
<Col xs={24}>
|
||||
<Form.Item shouldUpdate noStyle>
|
||||
{() => {
|
||||
const payers = form.getFieldValue("payers");
|
||||
const row = payers?.[index];
|
||||
const cdkPayer =
|
||||
bodyshop.cdk_configuration.payers &&
|
||||
bodyshop.cdk_configuration.payers.find((i) => i && row && i.name === row.name);
|
||||
if (i18n.exists(`jobs.fields.${cdkPayer?.control_type}`))
|
||||
return <div>{cdkPayer && t(`jobs.fields.${cdkPayer?.control_type}`)}</div>;
|
||||
else if (i18n.exists(`jobs.fields.dms.control_type.${cdkPayer?.control_type}`)) {
|
||||
return <div>{cdkPayer && t(`jobs.fields.dms.control_type.${cdkPayer?.control_type}`)}</div>;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}}
|
||||
</Form.Item>
|
||||
</Col>
|
||||
</Row>
|
||||
</Card>
|
||||
))}
|
||||
<Form.Item>
|
||||
<Button
|
||||
disabled={!(fields.length < 3)}
|
||||
onClick={() => {
|
||||
if (fields.length < 3) add();
|
||||
}}
|
||||
style={{ width: "100%" }}
|
||||
>
|
||||
{t("jobs.actions.dms.addpayer")}
|
||||
</Button>
|
||||
</Form.Item>
|
||||
</div>
|
||||
)}
|
||||
</Form.List>
|
||||
|
||||
{/* Validation gates & summary */}
|
||||
<Form.Item shouldUpdate>
|
||||
{() => {
|
||||
let totalAllocated = Dinero();
|
||||
const payers = form.getFieldValue("payers") || [];
|
||||
payers.forEach((payer) => {
|
||||
totalAllocated = totalAllocated.add(Dinero({ amount: Math.round((payer?.amount || 0) * 100) }));
|
||||
});
|
||||
|
||||
const discrep = totals ? totals.totalSale.subtract(totalAllocated) : Dinero();
|
||||
|
||||
// gate: must have payers filled + zero discrepancy when we have a summary
|
||||
const payersOk =
|
||||
payers.length > 0 &&
|
||||
payers.every((p) => p?.name && p.dms_acctnumber && (p.amount ?? "") !== "" && p.controlnumber);
|
||||
const nonRrDiscrepancyGate = socket?.allocationsSummary ? discrep.getAmount() !== 0 : true;
|
||||
const disablePost = !payersOk || nonRrDiscrepancyGate;
|
||||
|
||||
return (
|
||||
<Space size="large" wrap align="center">
|
||||
<Statistic
|
||||
title={t("jobs.labels.subtotal")}
|
||||
value={(totals ? totals.totalSale : Dinero()).toFormat()}
|
||||
/>
|
||||
<Typography.Title>-</Typography.Title>
|
||||
<Statistic title={t("jobs.labels.dms.totalallocated")} value={totalAllocated.toFormat()} />
|
||||
<Typography.Title>=</Typography.Title>
|
||||
<Statistic
|
||||
title={t("jobs.labels.dms.notallocated")}
|
||||
valueStyle={{ color: discrep.getAmount() === 0 ? "green" : "red" }}
|
||||
value={discrep.toFormat()}
|
||||
/>
|
||||
<Button disabled={disablePost} htmlType="submit">
|
||||
{t("jobs.actions.dms.post")}
|
||||
</Button>
|
||||
</Space>
|
||||
);
|
||||
}}
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
@@ -1,532 +1,40 @@
|
||||
import { DeleteFilled, DownOutlined, ReloadOutlined } from "@ant-design/icons";
|
||||
import {
|
||||
Button,
|
||||
Card,
|
||||
Col,
|
||||
Divider,
|
||||
Dropdown,
|
||||
Form,
|
||||
Input,
|
||||
InputNumber,
|
||||
Row,
|
||||
Select,
|
||||
Space,
|
||||
Statistic,
|
||||
Switch,
|
||||
Tooltip,
|
||||
Typography
|
||||
} from "antd";
|
||||
import Dinero from "dinero.js";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { connect } from "react-redux";
|
||||
import { createStructuredSelector } from "reselect";
|
||||
import { determineDmsType } from "../../utils/determineDMSType";
|
||||
import { selectBodyshop } from "../../redux/user/user.selectors";
|
||||
import i18n from "../../translations/i18n";
|
||||
import dayjs from "../../utils/day";
|
||||
import DmsCdkMakes from "../dms-cdk-makes/dms-cdk-makes.component";
|
||||
import DmsCdkMakesRefetch from "../dms-cdk-makes/dms-cdk-makes.refetch.component";
|
||||
import DateTimePicker from "../form-date-time-picker/form-date-time-picker.component.jsx";
|
||||
import CurrencyInput from "../form-items-formatted/currency-form-item.component";
|
||||
import { useSocket } from "../../contexts/SocketIO/useSocket";
|
||||
import { useSplitTreatments } from "@splitsoftware/splitio-react";
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { DMS_MAP } from "../../utils/dmsUtils";
|
||||
import RRPostForm from "./rr-dms-post-form";
|
||||
import CdkLikePostForm from "./cdklike-dms-post-form";
|
||||
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
bodyshop: selectBodyshop
|
||||
});
|
||||
const mapDispatchToProps = () => ({});
|
||||
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(DmsPostForm);
|
||||
|
||||
export function DmsPostForm({ bodyshop, socket, job, logsRef }) {
|
||||
const {
|
||||
treatments: { Fortellis }
|
||||
} = useSplitTreatments({
|
||||
attributes: {},
|
||||
names: ["Fortellis"],
|
||||
splitKey: bodyshop.imexshopid
|
||||
});
|
||||
/**
|
||||
* DMS Post Form component that renders the appropriate post form
|
||||
* @param mode
|
||||
* @param bodyshop
|
||||
* @param socket
|
||||
* @param job
|
||||
* @param logsRef
|
||||
* @returns {JSX.Element|null}
|
||||
* @constructor
|
||||
*/
|
||||
export function DmsPostForm({ mode, bodyshop, socket, job, logsRef }) {
|
||||
switch (mode) {
|
||||
case DMS_MAP.reynolds:
|
||||
return <RRPostForm bodyshop={bodyshop} socket={socket} job={job} logsRef={logsRef} />;
|
||||
|
||||
const [form] = Form.useForm();
|
||||
const { t } = useTranslation();
|
||||
const { socket: wsssocket } = useSocket();
|
||||
// CDK (legacy /ws), Fortellis (CDK-over-WSS), and PBS share the same UI;
|
||||
// we pass mode down so the child can choose the correct event name.
|
||||
case DMS_MAP.fortellis:
|
||||
case DMS_MAP.cdk:
|
||||
case DMS_MAP.pbs:
|
||||
return <CdkLikePostForm mode={mode} bodyshop={bodyshop} socket={socket} job={job} logsRef={logsRef} />;
|
||||
|
||||
// Figure out DMS once and reuse
|
||||
const dms = useMemo(() => determineDmsType(bodyshop), [bodyshop]);
|
||||
|
||||
// ---------------- RR Advisors (unchanged behavior) ----------------
|
||||
const [advisors, setAdvisors] = useState([]);
|
||||
const [advLoading, setAdvLoading] = useState(false);
|
||||
|
||||
// Normalize advisor fields coming from various shapes
|
||||
const getAdvisorNumber = (a) => a?.advisorId;
|
||||
const getAdvisorLabel = (a) => `${a?.firstName || ""} ${a?.lastName || ""}`.trim();
|
||||
|
||||
const fetchRrAdvisors = (refresh = false) => {
|
||||
if (!wsssocket) return;
|
||||
setAdvLoading(true);
|
||||
|
||||
// Listen for the server's broadcast
|
||||
const onResult = (payload) => {
|
||||
try {
|
||||
const list = payload?.result ?? payload ?? [];
|
||||
setAdvisors(Array.isArray(list) ? list : []);
|
||||
} finally {
|
||||
setAdvLoading(false);
|
||||
wsssocket.off("rr-get-advisors:result", onResult);
|
||||
}
|
||||
};
|
||||
|
||||
wsssocket.once("rr-get-advisors:result", onResult);
|
||||
|
||||
// Emit with refresh flag: server will bypass/rebuild cache when true
|
||||
wsssocket.emit("rr-get-advisors", { departmentType: "B", refresh }, (ack) => {
|
||||
if (ack?.ok) {
|
||||
const list = ack.result ?? [];
|
||||
setAdvisors(Array.isArray(list) ? list : []);
|
||||
} else if (ack) {
|
||||
// Preserve original logging semantics
|
||||
console.error("Something went wrong fetching DMS Advisors");
|
||||
}
|
||||
setAdvLoading(false);
|
||||
wsssocket.off("rr-get-advisors:result", onResult);
|
||||
});
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (dms === "rr") fetchRrAdvisors(false);
|
||||
}, [dms, bodyshop?.id]);
|
||||
|
||||
// ---------------- Payers helpers (non-RR) ----------------
|
||||
const handlePayerSelect = (value, index) => {
|
||||
form.setFieldsValue({
|
||||
payers: (form.getFieldValue("payers") || []).map((payer, mapIndex) => {
|
||||
if (index !== mapIndex) return payer;
|
||||
const cdkPayer =
|
||||
bodyshop.cdk_configuration.payers && bodyshop.cdk_configuration.payers.find((i) => i.name === value);
|
||||
if (!cdkPayer) return payer;
|
||||
|
||||
return {
|
||||
...cdkPayer,
|
||||
dms_acctnumber: cdkPayer.dms_acctnumber,
|
||||
controlnumber: job?.[cdkPayer.control_type]
|
||||
};
|
||||
})
|
||||
});
|
||||
};
|
||||
|
||||
// ---------------- Submit (RR precedence preserved) ----------------
|
||||
const handleFinish = (values) => {
|
||||
// RR takes precedence regardless of Fortellis split
|
||||
if (dms === "rr") {
|
||||
// values will include advisorNo (and makeOverride if provided)
|
||||
wsssocket.emit("rr-export-job", {
|
||||
bodyshopId: bodyshop?.id,
|
||||
jobId: job.id,
|
||||
job,
|
||||
txEnvelope: values
|
||||
});
|
||||
} else if (Fortellis.treatment === "on") {
|
||||
// Fallback to existing Fortellis behavior
|
||||
wsssocket.emit("fortellis-export-job", {
|
||||
jobid: job.id,
|
||||
txEnvelope: { ...values, SubscriptionID: bodyshop.cdk_dealerid }
|
||||
});
|
||||
} else {
|
||||
// CDK/PBS/etc.
|
||||
socket.emit(`${dms}-export-job`, { jobid: job.id, txEnvelope: values });
|
||||
}
|
||||
|
||||
// Scroll logs into view (original behavior)
|
||||
logsRef?.current?.scrollIntoView({ behavior: "smooth" });
|
||||
};
|
||||
|
||||
return (
|
||||
<Card title={t("jobs.labels.dms.postingform")}>
|
||||
<Form
|
||||
form={form}
|
||||
layout="vertical"
|
||||
onFinish={handleFinish}
|
||||
style={{ width: "100%" }}
|
||||
initialValues={{
|
||||
story: `${t("jobs.labels.dms.defaultstory", {
|
||||
ro_number: job.ro_number,
|
||||
ownr_nm: `${job.ownr_fn || ""} ${job.ownr_ln || ""} ${job.ownr_co_nm || ""}`.trim(),
|
||||
ins_co_nm: job.ins_co_nm || "N/A",
|
||||
clm_po: `${job.clm_no ? `${job.clm_no} ` : ""}${job.po_number || ""}`
|
||||
}).trim()}.${
|
||||
job.area_of_damage?.impact1
|
||||
? " " +
|
||||
t("jobs.labels.dms.damageto", {
|
||||
area_of_damage: (job.area_of_damage && job.area_of_damage.impact1.padStart(2, "0")) || "UNKNOWN"
|
||||
})
|
||||
: ""
|
||||
}`.slice(0, 239),
|
||||
inservicedate: dayjs(
|
||||
`${
|
||||
(job.v_model_yr &&
|
||||
(job.v_model_yr < 100
|
||||
? job.v_model_yr >= (dayjs().year() + 1) % 100
|
||||
? 1900 + parseInt(job.v_model_yr, 10)
|
||||
: 2000 + parseInt(job.v_model_yr, 10)
|
||||
: job.v_model_yr)) ||
|
||||
2019
|
||||
}-01-01`
|
||||
)
|
||||
}}
|
||||
>
|
||||
{/* TOP ROW — bottom-aligned so the Refresh button sits flush */}
|
||||
<Row gutter={[16, 12]} align="bottom">
|
||||
{dms !== "rr" && (
|
||||
<Col xs={24} sm={12} md={8} lg={6}>
|
||||
<Form.Item
|
||||
name="journal"
|
||||
label={t("jobs.fields.dms.journal")}
|
||||
initialValue={bodyshop.cdk_configuration?.default_journal}
|
||||
rules={[{ required: true }]}
|
||||
>
|
||||
<Input />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
)}
|
||||
|
||||
{dms === "rr" && (
|
||||
<>
|
||||
{/* Advisor + inline Refresh (binding fixed via inner noStyle Form.Item) */}
|
||||
<Col xs={24} sm={24} md={12} lg={8}>
|
||||
<Form.Item label={t("jobs.fields.dms.advisor")} required>
|
||||
<Space.Compact block>
|
||||
<Form.Item
|
||||
name="advisorNo"
|
||||
noStyle
|
||||
rules={[{ required: true, message: t("general.validation.required") }]}
|
||||
>
|
||||
<Select
|
||||
style={{ flex: 1 }}
|
||||
loading={advLoading}
|
||||
allowClear
|
||||
placeholder={t("general.actions.select", "Select...")}
|
||||
popupMatchSelectWidth
|
||||
options={advisors
|
||||
.map((a) => {
|
||||
const value = getAdvisorNumber(a);
|
||||
if (value == null) return null;
|
||||
return { value: String(value), label: getAdvisorLabel(a) || String(value) };
|
||||
})
|
||||
.filter(Boolean)}
|
||||
notFoundContent={advLoading ? t("general.labels.loading") : t("general.labels.none")}
|
||||
/>
|
||||
</Form.Item>
|
||||
<Tooltip title={t("general.actions.refresh")}>
|
||||
<Button
|
||||
aria-label={t("general.actions.refresh")}
|
||||
icon={<ReloadOutlined />}
|
||||
onClick={() => fetchRrAdvisors(true)}
|
||||
loading={advLoading}
|
||||
/>
|
||||
</Tooltip>
|
||||
</Space.Compact>
|
||||
</Form.Item>
|
||||
</Col>
|
||||
|
||||
{/* Make Override (RR only, beside Advisor) */}
|
||||
<Col xs={24} sm={12} md={12} lg={8}>
|
||||
<Form.Item name="makeOverride" label={t("jobs.fields.dms.make_override")}>
|
||||
<Input allowClear placeholder={t("general.actions.optional")} />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
</>
|
||||
)}
|
||||
|
||||
<Col xs={12} sm={8} md={6} lg={4}>
|
||||
<Form.Item name="kmin" label={t("jobs.fields.kmin")} initialValue={job?.kmin} rules={[{ required: true }]}>
|
||||
<InputNumber style={{ width: "100%" }} disabled />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
|
||||
<Col xs={12} sm={8} md={6} lg={4}>
|
||||
<Form.Item
|
||||
name="kmout"
|
||||
label={t("jobs.fields.kmout")}
|
||||
initialValue={job?.kmout}
|
||||
rules={[{ required: true }]}
|
||||
>
|
||||
<InputNumber style={{ width: "100%" }} disabled />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
{/* CDK vehicle details (unchanged behavior) */}
|
||||
{bodyshop.cdk_dealerid && (
|
||||
<>
|
||||
<Row gutter={[16, 12]}>
|
||||
<Col xs={24} sm={12} md={8}>
|
||||
<Form.Item name="dms_make" label={t("jobs.fields.dms.dms_make")} rules={[{ required: true }]}>
|
||||
<Input />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
<Col xs={24} sm={12} md={8}>
|
||||
<Form.Item name="dms_model" label={t("jobs.fields.dms.dms_model")} rules={[{ required: true }]}>
|
||||
<Input />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
<Col xs={24} sm={12} md={8}>
|
||||
<Form.Item name="inservicedate" label={t("jobs.fields.dms.inservicedate")}>
|
||||
<DateTimePicker isDateOnly />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
<Row gutter={[16, 12]} align="middle">
|
||||
<Col>
|
||||
<DmsCdkMakes form={form} job={job} />
|
||||
</Col>
|
||||
<Col>
|
||||
<DmsCdkMakesRefetch />
|
||||
</Col>
|
||||
<Col>
|
||||
<Form.Item name="dms_unsold" label={t("jobs.fields.dms.dms_unsold")} initialValue={false}>
|
||||
<Switch />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
<Col>
|
||||
<Form.Item
|
||||
name="dms_model_override"
|
||||
label={t("jobs.fields.dms.dms_model_override")}
|
||||
initialValue={false}
|
||||
>
|
||||
<Switch />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
</Row>
|
||||
</>
|
||||
)}
|
||||
|
||||
<Row gutter={[16, 12]}>
|
||||
<Col span={24}>
|
||||
<Form.Item name="story" label={t("jobs.fields.dms.story")} rules={[{ required: true }]}>
|
||||
<Input.TextArea maxLength={240} />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
<Divider />
|
||||
|
||||
{/* Totals (unchanged) */}
|
||||
<Space size="large" wrap align="center" style={{ marginBottom: 16 }}>
|
||||
<Statistic
|
||||
title={t("jobs.fields.ded_amt")}
|
||||
value={Dinero(job.job_totals.totals.custPayable.deductible).toFormat()}
|
||||
/>
|
||||
<Statistic
|
||||
title={t("jobs.labels.total_cust_payable")}
|
||||
value={Dinero(job.job_totals.totals.custPayable.total).toFormat()}
|
||||
/>
|
||||
<Statistic
|
||||
title={t("jobs.labels.net_repairs")}
|
||||
value={Dinero(job.job_totals.totals.net_repairs).toFormat()}
|
||||
/>
|
||||
</Space>
|
||||
|
||||
{/* Non-RR payers list (parity with original) */}
|
||||
{dms !== "rr" && (
|
||||
<>
|
||||
<Divider />
|
||||
<Form.List name={["payers"]}>
|
||||
{(fields, { add, remove }) => (
|
||||
<div>
|
||||
{fields.map((field, index) => (
|
||||
<Card
|
||||
key={field.key}
|
||||
size="small"
|
||||
style={{ marginBottom: 12 }}
|
||||
title={`${t("jobs.fields.dms.payer.payer_type")} #${index + 1}`}
|
||||
extra={
|
||||
<Tooltip title={t("general.actions.remove", "Remove")}>
|
||||
<Button
|
||||
type="text"
|
||||
danger
|
||||
icon={<DeleteFilled />}
|
||||
aria-label={t("general.actions.remove", "Remove")}
|
||||
onClick={() => remove(field.name)}
|
||||
/>
|
||||
</Tooltip>
|
||||
}
|
||||
>
|
||||
<Row gutter={[16, 8]} align="middle">
|
||||
<Col xs={24} sm={12} md={8} lg={6}>
|
||||
<Form.Item
|
||||
label={t("jobs.fields.dms.payer.name")}
|
||||
name={[field.name, "name"]}
|
||||
rules={[{ required: true }]}
|
||||
>
|
||||
<Select style={{ minWidth: "15rem" }} onSelect={(value) => handlePayerSelect(value, index)}>
|
||||
{bodyshop.cdk_configuration?.payers?.map((payer) => (
|
||||
<Select.Option key={payer.name}>{payer.name}</Select.Option>
|
||||
))}
|
||||
</Select>
|
||||
</Form.Item>
|
||||
</Col>
|
||||
|
||||
<Col xs={24} sm={12} md={8} lg={6}>
|
||||
<Form.Item
|
||||
label={t("jobs.fields.dms.payer.dms_acctnumber")}
|
||||
name={[field.name, "dms_acctnumber"]}
|
||||
rules={[{ required: true }]}
|
||||
>
|
||||
<Input disabled />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
|
||||
<Col xs={24} sm={12} md={8} lg={5}>
|
||||
<Form.Item
|
||||
label={t("jobs.fields.dms.payer.amount")}
|
||||
name={[field.name, "amount"]}
|
||||
rules={[{ required: true }]}
|
||||
>
|
||||
<CurrencyInput min={0} />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
|
||||
<Col xs={24} sm={12} md={10} lg={7}>
|
||||
<Form.Item
|
||||
label={
|
||||
<div>
|
||||
{t("jobs.fields.dms.payer.controlnumber")}{" "}
|
||||
<Dropdown
|
||||
trigger={["click"]}
|
||||
menu={{
|
||||
items:
|
||||
bodyshop.cdk_configuration.controllist?.map((key, idx) => ({
|
||||
key: idx,
|
||||
label: key.name,
|
||||
onClick: () => {
|
||||
form.setFieldsValue({
|
||||
payers: (form.getFieldValue("payers") || []).map((row, mapIndex) => {
|
||||
if (index !== mapIndex) return row;
|
||||
return { ...row, controlnumber: key.controlnumber };
|
||||
})
|
||||
});
|
||||
}
|
||||
})) ?? []
|
||||
}}
|
||||
>
|
||||
{/* Anchor trigger */}
|
||||
<a href="#" onClick={(e) => e.preventDefault()}>
|
||||
<DownOutlined />
|
||||
</a>
|
||||
</Dropdown>
|
||||
</div>
|
||||
}
|
||||
name={[field.name, "controlnumber"]}
|
||||
rules={[{ required: true }]}
|
||||
>
|
||||
<Input />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
|
||||
<Col xs={24}>
|
||||
<Form.Item shouldUpdate noStyle>
|
||||
{() => {
|
||||
const payers = form.getFieldValue("payers");
|
||||
const row = payers?.[index];
|
||||
const cdkPayer =
|
||||
bodyshop.cdk_configuration.payers &&
|
||||
bodyshop.cdk_configuration.payers.find((i) => i && row && i.name === row.name);
|
||||
if (i18n.exists(`jobs.fields.${cdkPayer?.control_type}`))
|
||||
return <div>{cdkPayer && t(`jobs.fields.${cdkPayer?.control_type}`)}</div>;
|
||||
else if (i18n.exists(`jobs.fields.dms.control_type.${cdkPayer?.control_type}`)) {
|
||||
return (
|
||||
<div>{cdkPayer && t(`jobs.fields.dms.control_type.${cdkPayer?.control_type}`)}</div>
|
||||
);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}}
|
||||
</Form.Item>
|
||||
</Col>
|
||||
</Row>
|
||||
</Card>
|
||||
))}
|
||||
<Form.Item>
|
||||
<Button
|
||||
disabled={!(fields.length < 3)}
|
||||
onClick={() => {
|
||||
if (fields.length < 3) add();
|
||||
}}
|
||||
style={{ width: "100%" }}
|
||||
>
|
||||
{t("jobs.actions.dms.addpayer")}
|
||||
</Button>
|
||||
</Form.Item>
|
||||
</div>
|
||||
)}
|
||||
</Form.List>
|
||||
</>
|
||||
)}
|
||||
|
||||
{/* Validation gates & summary (unchanged logic) */}
|
||||
<Form.Item shouldUpdate>
|
||||
{() => {
|
||||
// 1) Sum allocated payers
|
||||
let totalAllocated = Dinero();
|
||||
const payers = form.getFieldValue("payers") || [];
|
||||
payers.forEach((payer) => {
|
||||
totalAllocated = totalAllocated.add(Dinero({ amount: Math.round((payer?.amount || 0) * 100) }));
|
||||
});
|
||||
|
||||
// 2) Subtotal from socket.allocationsSummary (existing behavior)
|
||||
const totals =
|
||||
socket && socket.allocationsSummary
|
||||
? socket.allocationsSummary.reduce(
|
||||
(acc, val) => ({
|
||||
totalSale: acc.totalSale.add(Dinero(val.sale)),
|
||||
totalCost: acc.totalCost.add(Dinero(val.cost))
|
||||
}),
|
||||
{ totalSale: Dinero(), totalCost: Dinero() }
|
||||
)
|
||||
: { totalSale: Dinero(), totalCost: Dinero() };
|
||||
|
||||
const discrep = totals ? totals.totalSale.subtract(totalAllocated) : Dinero();
|
||||
|
||||
// 3) Validation gates
|
||||
const advisorOk = dms !== "rr" || !!form.getFieldValue("advisorNo");
|
||||
|
||||
// Require at least one complete payer row for non-RR
|
||||
const payersOk =
|
||||
dms === "rr" ||
|
||||
(payers.length > 0 &&
|
||||
payers.every((p) => p?.name && p.dms_acctnumber && (p.amount ?? "") !== "" && p.controlnumber));
|
||||
|
||||
// 4) Disable rules:
|
||||
// - For non-RR: must have summary and zero discrepancy
|
||||
// - For RR: ignore discrepancy rule, but require advisor
|
||||
const nonRrDiscrepancyGate = dms !== "rr" && (socket.allocationsSummary ? discrep.getAmount() !== 0 : true);
|
||||
|
||||
const disablePost = !advisorOk || !payersOk || nonRrDiscrepancyGate;
|
||||
|
||||
return (
|
||||
<Space size="large" wrap align="center">
|
||||
<Statistic
|
||||
title={t("jobs.labels.subtotal")}
|
||||
value={(totals ? totals.totalSale : Dinero()).toFormat()}
|
||||
/>
|
||||
<Typography.Title>-</Typography.Title>
|
||||
<Statistic title={t("jobs.labels.dms.totalallocated")} value={totalAllocated.toFormat()} />
|
||||
<Typography.Title>=</Typography.Title>
|
||||
<Statistic
|
||||
title={t("jobs.labels.dms.notallocated")}
|
||||
valueStyle={{ color: discrep.getAmount() === 0 ? "green" : "red" }}
|
||||
value={discrep.toFormat()}
|
||||
/>
|
||||
<Button disabled={disablePost} htmlType="submit">
|
||||
{t("jobs.actions.dms.post")}
|
||||
</Button>
|
||||
</Space>
|
||||
);
|
||||
}}
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Card>
|
||||
);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
242
client/src/components/dms-post-form/rr-dms-post-form.jsx
Normal file
242
client/src/components/dms-post-form/rr-dms-post-form.jsx
Normal file
@@ -0,0 +1,242 @@
|
||||
import { ReloadOutlined } from "@ant-design/icons";
|
||||
import {
|
||||
Button,
|
||||
Card,
|
||||
Col,
|
||||
Divider,
|
||||
Form,
|
||||
Input,
|
||||
InputNumber,
|
||||
Row,
|
||||
Select,
|
||||
Space,
|
||||
Statistic,
|
||||
Tooltip,
|
||||
Typography
|
||||
} from "antd";
|
||||
import Dinero from "dinero.js";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import dayjs from "../../utils/day";
|
||||
|
||||
/**
|
||||
* RR DMS Post Form component
|
||||
* Submit: "rr-export-job"
|
||||
* @param bodyshop
|
||||
* @param socket
|
||||
* @param job
|
||||
* @param logsRef
|
||||
* @returns {JSX.Element}
|
||||
* @constructor
|
||||
*/
|
||||
export default function RRPostForm({ bodyshop, socket, job, logsRef }) {
|
||||
const [form] = Form.useForm();
|
||||
const { t } = useTranslation();
|
||||
|
||||
// Advisors
|
||||
const [advisors, setAdvisors] = useState([]);
|
||||
const [advLoading, setAdvLoading] = useState(false);
|
||||
|
||||
const getAdvisorNumber = (a) => a?.advisorId;
|
||||
|
||||
const getAdvisorLabel = (a) => `${a?.firstName || ""} ${a?.lastName || ""}`.trim();
|
||||
|
||||
const fetchRrAdvisors = (refresh = false) => {
|
||||
if (!socket) return;
|
||||
setAdvLoading(true);
|
||||
|
||||
const onResult = (payload) => {
|
||||
try {
|
||||
const list = payload?.result ?? payload ?? [];
|
||||
setAdvisors(Array.isArray(list) ? list : []);
|
||||
} finally {
|
||||
setAdvLoading(false);
|
||||
socket.off("rr-get-advisors:result", onResult);
|
||||
}
|
||||
};
|
||||
|
||||
socket.once("rr-get-advisors:result", onResult);
|
||||
socket.emit("rr-get-advisors", { departmentType: "B", refresh }, (ack) => {
|
||||
if (ack?.ok) {
|
||||
const list = ack.result ?? [];
|
||||
setAdvisors(Array.isArray(list) ? list : []);
|
||||
} else if (ack) {
|
||||
console.error("Something went wrong fetching DMS Advisors");
|
||||
}
|
||||
setAdvLoading(false);
|
||||
socket.off("rr-get-advisors:result", onResult);
|
||||
});
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
fetchRrAdvisors(false);
|
||||
}, [bodyshop?.id, socket]);
|
||||
|
||||
const initialValues = useMemo(
|
||||
() => ({
|
||||
story: `${t("jobs.labels.dms.defaultstory", {
|
||||
ro_number: job.ro_number,
|
||||
ownr_nm: `${job.ownr_fn || ""} ${job.ownr_ln || ""} ${job.ownr_co_nm || ""}`.trim(),
|
||||
ins_co_nm: job.ins_co_nm || "N/A",
|
||||
clm_po: `${job.clm_no ? `${job.clm_no} ` : ""}${job.po_number || ""}`
|
||||
}).trim()}.${
|
||||
job.area_of_damage?.impact1
|
||||
? " " +
|
||||
t("jobs.labels.dms.damageto", {
|
||||
area_of_damage: (job.area_of_damage && job.area_of_damage.impact1.padStart(2, "0")) || "UNKNOWN"
|
||||
})
|
||||
: ""
|
||||
}`.slice(0, 239),
|
||||
inservicedate: dayjs(
|
||||
`${
|
||||
(job.v_model_yr &&
|
||||
(job.v_model_yr < 100
|
||||
? job.v_model_yr >= (dayjs().year() + 1) % 100
|
||||
? 1900 + parseInt(job.v_model_yr, 10)
|
||||
: 2000 + parseInt(job.v_model_yr, 10)
|
||||
: job.v_model_yr)) ||
|
||||
2019
|
||||
}-01-01`
|
||||
)
|
||||
}),
|
||||
[job, t]
|
||||
);
|
||||
|
||||
const handleFinish = (values) => {
|
||||
if (!socket) return;
|
||||
socket.emit("rr-export-job", {
|
||||
bodyshopId: bodyshop?.id,
|
||||
jobId: job.id,
|
||||
job,
|
||||
txEnvelope: values
|
||||
});
|
||||
logsRef?.current?.scrollIntoView({ behavior: "smooth" });
|
||||
};
|
||||
|
||||
// Discrepancy is ignored for RR; we still show totals for operator context
|
||||
const totals = socket?.allocationsSummary
|
||||
? socket.allocationsSummary.reduce(
|
||||
(acc, val) => ({
|
||||
totalSale: acc.totalSale.add(Dinero(val.sale)),
|
||||
totalCost: acc.totalCost.add(Dinero(val.cost))
|
||||
}),
|
||||
{ totalSale: Dinero(), totalCost: Dinero() }
|
||||
)
|
||||
: { totalSale: Dinero(), totalCost: Dinero() };
|
||||
|
||||
return (
|
||||
<Card title={t("jobs.labels.dms.postingform")}>
|
||||
<Form
|
||||
form={form}
|
||||
layout="vertical"
|
||||
onFinish={handleFinish}
|
||||
style={{ width: "100%" }}
|
||||
initialValues={initialValues}
|
||||
>
|
||||
<Row gutter={[16, 12]} align="bottom">
|
||||
{/* Advisor + inline Refresh */}
|
||||
<Col xs={24} sm={24} md={12} lg={8}>
|
||||
<Form.Item label={t("jobs.fields.dms.advisor")} required>
|
||||
<Space.Compact block>
|
||||
<Form.Item
|
||||
name="advisorNo"
|
||||
noStyle
|
||||
rules={[{ required: true, message: t("general.validation.required") }]}
|
||||
>
|
||||
<Select
|
||||
style={{ flex: 1 }}
|
||||
loading={advLoading}
|
||||
allowClear
|
||||
placeholder={t("general.actions.select", "Select...")}
|
||||
popupMatchSelectWidth
|
||||
options={advisors
|
||||
.map((a) => {
|
||||
const value = getAdvisorNumber(a);
|
||||
if (value == null) return null;
|
||||
return { value: String(value), label: getAdvisorLabel(a) || String(value) };
|
||||
})
|
||||
.filter(Boolean)}
|
||||
notFoundContent={advLoading ? t("general.labels.loading") : t("general.labels.none")}
|
||||
/>
|
||||
</Form.Item>
|
||||
<Tooltip title={t("general.actions.refresh")}>
|
||||
<Button
|
||||
aria-label={t("general.actions.refresh")}
|
||||
icon={<ReloadOutlined />}
|
||||
onClick={() => fetchRrAdvisors(true)}
|
||||
loading={advLoading}
|
||||
/>
|
||||
</Tooltip>
|
||||
</Space.Compact>
|
||||
</Form.Item>
|
||||
</Col>
|
||||
|
||||
{/* Make Override */}
|
||||
<Col xs={24} sm={12} md={12} lg={8}>
|
||||
<Form.Item name="makeOverride" label={t("jobs.fields.dms.make_override")}>
|
||||
<Input allowClear placeholder={t("general.actions.optional")} />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
|
||||
<Col xs={12} sm={8} md={6} lg={4}>
|
||||
<Form.Item name="kmin" label={t("jobs.fields.kmin")} initialValue={job?.kmin} rules={[{ required: true }]}>
|
||||
<InputNumber style={{ width: "100%" }} disabled />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
|
||||
<Col xs={12} sm={8} md={6} lg={4}>
|
||||
<Form.Item
|
||||
name="kmout"
|
||||
label={t("jobs.fields.kmout")}
|
||||
initialValue={job?.kmout}
|
||||
rules={[{ required: true }]}
|
||||
>
|
||||
<InputNumber style={{ width: "100%" }} disabled />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
<Row gutter={[16, 12]}>
|
||||
<Col span={24}>
|
||||
<Form.Item name="story" label={t("jobs.fields.dms.story")} rules={[{ required: true }]}>
|
||||
<Input.TextArea maxLength={240} />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
<Divider />
|
||||
|
||||
<Space size="large" wrap align="center" style={{ marginBottom: 16 }}>
|
||||
<Statistic
|
||||
title={t("jobs.fields.ded_amt")}
|
||||
value={Dinero(job.job_totals.totals.custPayable.deductible).toFormat()}
|
||||
/>
|
||||
<Statistic
|
||||
title={t("jobs.labels.total_cust_payable")}
|
||||
value={Dinero(job.job_totals.totals.custPayable.total).toFormat()}
|
||||
/>
|
||||
<Statistic
|
||||
title={t("jobs.labels.net_repairs")}
|
||||
value={Dinero(job.job_totals.totals.net_repairs).toFormat()}
|
||||
/>
|
||||
</Space>
|
||||
|
||||
{/* Validation */}
|
||||
<Form.Item shouldUpdate>
|
||||
{() => {
|
||||
const advisorOk = !!form.getFieldValue("advisorNo");
|
||||
return (
|
||||
<Space size="large" wrap align="center">
|
||||
<Statistic title={t("jobs.labels.subtotal")} value={totals.totalSale.toFormat()} />
|
||||
<Typography.Title>=</Typography.Title>
|
||||
<Button disabled={!advisorOk} htmlType="submit">
|
||||
{t("jobs.actions.dms.post")}
|
||||
</Button>
|
||||
</Space>
|
||||
);
|
||||
}}
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import { createStructuredSelector } from "reselect";
|
||||
import { logImEXEvent } from "../../firebase/firebase.utils";
|
||||
import { selectBodyshop } from "../../redux/user/user.selectors";
|
||||
import InstanceRenderManager from "../../utils/instanceRenderMgr";
|
||||
import { bodyshopHasDmsKey } from "../../utils/dmsUtils.js";
|
||||
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
bodyshop: selectBodyshop
|
||||
@@ -14,6 +15,8 @@ const mapStateToProps = createStructuredSelector({
|
||||
export function JobsCloseAutoAllocate({ bodyshop, joblines, form, disabled }) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const hasDmsKey = bodyshopHasDmsKey(bodyshop);
|
||||
|
||||
const handleAllocate = (defaults) => {
|
||||
form.setFieldsValue({
|
||||
joblines: joblines.map((jl) => {
|
||||
@@ -64,21 +67,20 @@ export function JobsCloseAutoAllocate({ bodyshop, joblines, form, disabled }) {
|
||||
handleAllocate(bodyshop.md_responsibility_centers.dms_defaults.find((x) => x.name === key));
|
||||
};
|
||||
|
||||
const menu =
|
||||
bodyshop.cdk_dealerid || bodyshop.pbs_serialnumber || bodyshop.rr_dealerid
|
||||
? {
|
||||
items: bodyshop.md_responsibility_centers.dms_defaults.map((mapping) => ({
|
||||
key: mapping.name,
|
||||
label: mapping.name,
|
||||
disabled: disabled
|
||||
})),
|
||||
onClick: handleMenuClick
|
||||
}
|
||||
: {
|
||||
items: []
|
||||
};
|
||||
const menu = hasDmsKey
|
||||
? {
|
||||
items: bodyshop.md_responsibility_centers.dms_defaults.map((mapping) => ({
|
||||
key: mapping.name,
|
||||
label: mapping.name,
|
||||
disabled: disabled
|
||||
})),
|
||||
onClick: handleMenuClick
|
||||
}
|
||||
: {
|
||||
items: []
|
||||
};
|
||||
|
||||
return bodyshop.cdk_dealerid || bodyshop.pbs_serialnumber || bodyshop.rr_dealerid ? (
|
||||
return hasDmsKey ? (
|
||||
<Dropdown menu={menu}>
|
||||
<Button disabled={disabled}>{t("jobs.actions.dmsautoallocate")}</Button>
|
||||
</Dropdown>
|
||||
|
||||
@@ -10,6 +10,7 @@ import { auth, logImEXEvent } from "../../firebase/firebase.utils";
|
||||
import { INSERT_EXPORT_LOG } from "../../graphql/accounting.queries";
|
||||
import { UPDATE_JOB } from "../../graphql/jobs.queries";
|
||||
import { insertAuditTrail } from "../../redux/application/application.actions";
|
||||
import { bodyshopHasDmsKey } from "../../utils/dmsUtils.js";
|
||||
import { selectBodyshop, selectCurrentUser } from "../../redux/user/user.selectors";
|
||||
import AuditTrailMapping from "../../utils/AuditTrailMappings";
|
||||
import client from "../../utils/GraphQLClient";
|
||||
@@ -45,7 +46,7 @@ export function JobsCloseExportButton({ bodyshop, currentUser, jobId, disabled,
|
||||
|
||||
const handleQbxml = async () => {
|
||||
//Check if it's a CDK setup.
|
||||
if (bodyshop.cdk_dealerid || bodyshop.pbs_serialnumber || bodyshop.rr_dealerid) {
|
||||
if (bodyshopHasDmsKey(bodyshop)) {
|
||||
history(`/manage/dms?jobId=${jobId}`);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ import ProductionListColumnProductionNote from "../production-list-columns/produ
|
||||
import VehicleVinDisplay from "../vehicle-vin-display/vehicle-vin-display.component";
|
||||
import "./jobs-detail-header.styles.scss";
|
||||
import getPartsBasePath from "../../utils/getPartsBasePath.js";
|
||||
import { bodyshopHasDmsKey } from "../../utils/dmsUtils.js";
|
||||
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
jobRO: selectJobReadOnly,
|
||||
@@ -309,7 +310,7 @@ export function JobsDetailHeader({ job, bodyshop, disabled, insertAuditTrail, is
|
||||
</DataLabel>
|
||||
<DataLabel key="4" label={t("vehicles.fields.v_vin")}>
|
||||
<VehicleVinDisplay>{`${job.v_vin || t("general.labels.na")}`}</VehicleVinDisplay>
|
||||
{bodyshop.pbs_serialnumber || bodyshop.cdk_dealerid || bodyshop.rr_dealerid ? (
|
||||
{bodyshopHasDmsKey(bodyshop) ? (
|
||||
job.v_vin?.length !== 17 ? (
|
||||
<WarningFilled style={{ color: "tomato", marginLeft: ".3rem" }} />
|
||||
) : null
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import i18next from "i18next";
|
||||
import { bodyshopHasDmsKey } from "../../utils/dmsUtils.js";
|
||||
|
||||
export const CalculateAllocationsTotals = (bodyshop, joblines, timetickets, adjustments = []) => {
|
||||
const responsibilitycenters = bodyshop.md_responsibility_centers;
|
||||
@@ -14,10 +15,9 @@ export const CalculateAllocationsTotals = (bodyshop, joblines, timetickets, adju
|
||||
const r = allCodes.reduce((acc, value) => {
|
||||
const r = {
|
||||
opcode: value,
|
||||
cost_center:
|
||||
bodyshop.cdk_dealerid || bodyshop.pbs_serialnumber || bodyshop.rr_dealerid
|
||||
? i18next.t(`joblines.fields.lbr_types.${value && value.toUpperCase()}`)
|
||||
: responsibilitycenters.defaults.costs[value],
|
||||
cost_center: bodyshopHasDmsKey(bodyshop)
|
||||
? i18next.t(`joblines.fields.lbr_types.${value && value.toUpperCase()}`)
|
||||
: responsibilitycenters.defaults.costs[value],
|
||||
mod_lbr_ty: value,
|
||||
total: joblines.reduce((acc2, val2) => {
|
||||
return val2.mod_lbr_ty === value ? acc2 + val2.mod_lb_hrs : acc2;
|
||||
|
||||
@@ -28,6 +28,7 @@ import PartsOrderDeleteLine from "../parts-order-delete-line/parts-order-delete-
|
||||
import PartsOrderLineBackorderButton from "../parts-order-line-backorder-button/parts-order-line-backorder-button.component";
|
||||
import PartsReceiveModalContainer from "../parts-receive-modal/parts-receive-modal.container";
|
||||
import PrintWrapper from "../print-wrapper/print-wrapper.component";
|
||||
import { bodyshopHasDmsKey } from "../../utils/dmsUtils.js";
|
||||
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
jobRO: selectJobReadOnly,
|
||||
@@ -196,7 +197,7 @@ export function PartsOrderListTableDrawerComponent({
|
||||
quantity: pol.quantity,
|
||||
actual_price: pol.act_price,
|
||||
cost_center: pol.jobline?.part_type
|
||||
? bodyshop.pbs_serialnumber || bodyshop.cdk_dealerid || bodyshop.rr_dealerid
|
||||
? bodyshopHasDmsKey(bodyshop)
|
||||
? pol.jobline.part_type !== "PAE"
|
||||
? pol.jobline.part_type
|
||||
: null
|
||||
|
||||
@@ -20,6 +20,7 @@ import PartsReceiveModalContainer from "../parts-receive-modal/parts-receive-mod
|
||||
import PrintWrapper from "../print-wrapper/print-wrapper.component";
|
||||
import PartsOrderDrawer from "./parts-order-list-table-drawer.component";
|
||||
import ShareToTeamsButton from "../share-to-teams/share-to-teams.component.jsx";
|
||||
import { bodyshopHasDmsKey } from "../../utils/dmsUtils.js";
|
||||
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
jobRO: selectJobReadOnly,
|
||||
@@ -69,6 +70,7 @@ export function PartsOrderListTableComponent({
|
||||
|
||||
const parts_orders = billsQuery.data ? billsQuery.data.parts_orders : [];
|
||||
const { refetch } = billsQuery;
|
||||
|
||||
const recordActions = (record, showView = false) => (
|
||||
<Space direction="horizontal" wrap>
|
||||
<ShareToTeamsButton
|
||||
@@ -172,7 +174,7 @@ export function PartsOrderListTableComponent({
|
||||
actual_price: pol.act_price,
|
||||
|
||||
cost_center: pol.jobline?.part_type
|
||||
? bodyshop.pbs_serialnumber || bodyshop.cdk_dealerid || bodyshop.rr_dealerid
|
||||
? bodyshopHasDmsKey(bodyshop)
|
||||
? pol.jobline.part_type !== "PAE"
|
||||
? pol.jobline.part_type
|
||||
: null
|
||||
|
||||
@@ -15,6 +15,7 @@ import LayoutFormRow from "../layout-form-row/layout-form-row.component";
|
||||
import RbacWrapper from "../rbac-wrapper/rbac-wrapper.component";
|
||||
import ShopInfoResponsibilitycentersTaxesComponent from "./shop-info.responsibilitycenters.taxes.component";
|
||||
import ShopInfoRRConfigurationComponent from "./shop-info.rr-configuration.component";
|
||||
import { bodyshopHasDmsKey } from "../../utils/dmsUtils.js";
|
||||
|
||||
const SelectorDiv = styled.div`
|
||||
.ant-form-item .ant-select {
|
||||
@@ -34,12 +35,14 @@ export default connect(mapStateToProps, mapDispatchToProps)(ShopInfoResponsibili
|
||||
export function ShopInfoResponsibilityCenterComponent({ bodyshop, form }) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const hasDMSKey = bodyshopHasDmsKey(bodyshop);
|
||||
|
||||
const {
|
||||
treatments: { Qb_Multi_Ar, DmsAp }
|
||||
} = useSplitTreatments({
|
||||
attributes: {},
|
||||
names: ["Qb_Multi_Ar", "DmsAp"],
|
||||
splitKey: bodyshop && bodyshop.imexshopid
|
||||
splitKey: bodyshop?.imexshopid
|
||||
});
|
||||
|
||||
const [costOptions, setCostOptions] = useState([
|
||||
@@ -62,7 +65,7 @@ export function ShopInfoResponsibilityCenterComponent({ bodyshop, form }) {
|
||||
return (
|
||||
<div>
|
||||
<RbacWrapper action="shop:responsibilitycenter">
|
||||
{(bodyshop.cdk_dealerid || bodyshop.pbs_serialnumber || bodyshop.rr_dealerid) && (
|
||||
{hasDMSKey && (
|
||||
<>
|
||||
{bodyshop.rr_dealerid && <ShopInfoRRConfigurationComponent form={form} />}
|
||||
|
||||
@@ -396,7 +399,7 @@ export function ShopInfoResponsibilityCenterComponent({ bodyshop, form }) {
|
||||
>
|
||||
<Input onBlur={handleBlur} />
|
||||
</Form.Item> */}
|
||||
{(bodyshop.cdk_dealerid || bodyshop.pbs_serialnumber || bodyshop.rr_dealerid) && (
|
||||
{hasDMSKey && (
|
||||
<Form.Item
|
||||
label={t("bodyshop.fields.dms.dms_acctnumber")}
|
||||
key={`${index}dms_acctnumber`}
|
||||
@@ -410,7 +413,7 @@ export function ShopInfoResponsibilityCenterComponent({ bodyshop, form }) {
|
||||
<Input onBlur={handleBlur} />
|
||||
</Form.Item>
|
||||
)}
|
||||
{(bodyshop.cdk_dealerid || bodyshop.pbs_serialnumber || bodyshop.rr_dealerid) && (
|
||||
{hasDMSKey && (
|
||||
<Form.Item
|
||||
label={t("bodyshop.fields.dms.dms_wip_acctnumber")}
|
||||
key={`${index}dms_wip_acctnumber`}
|
||||
@@ -537,7 +540,7 @@ export function ShopInfoResponsibilityCenterComponent({ bodyshop, form }) {
|
||||
>
|
||||
<Input onBlur={handleBlur} />
|
||||
</Form.Item>
|
||||
{(bodyshop.cdk_dealerid || bodyshop.pbs_serialnumber || bodyshop.rr_dealerid) && (
|
||||
{hasDMSKey && (
|
||||
<Form.Item
|
||||
label={t("bodyshop.fields.dms.dms_acctnumber")}
|
||||
key={`${index}dms_acctnumber`}
|
||||
@@ -588,7 +591,7 @@ export function ShopInfoResponsibilityCenterComponent({ bodyshop, form }) {
|
||||
</Form.List>
|
||||
</LayoutFormRow>
|
||||
<SelectorDiv>
|
||||
{(bodyshop.cdk_dealerid || bodyshop.pbs_serialnumber || bodyshop.rr_dealerid) && (
|
||||
{hasDMSKey && (
|
||||
<>
|
||||
<LayoutFormRow id="mappingname" header={t("bodyshop.labels.dms.dms_allocations")}>
|
||||
<Form.List name={["md_responsibility_centers", "dms_defaults"]}>
|
||||
@@ -3802,7 +3805,7 @@ export function ShopInfoResponsibilityCenterComponent({ bodyshop, form }) {
|
||||
>
|
||||
<Input />
|
||||
</Form.Item>
|
||||
{(bodyshop.cdk_dealerid || bodyshop.pbs_serialnumber || bodyshop.rr_dealerid) && (
|
||||
{hasDMSKey && (
|
||||
<Form.Item
|
||||
label={t("bodyshop.fields.dms.dms_acctnumber")}
|
||||
rules={[
|
||||
@@ -3901,7 +3904,7 @@ export function ShopInfoResponsibilityCenterComponent({ bodyshop, form }) {
|
||||
>
|
||||
<Input />
|
||||
</Form.Item>
|
||||
{(bodyshop.cdk_dealerid || bodyshop.pbs_serialnumber || bodyshop.rr_dealerid) && (
|
||||
{hasDMSKey && (
|
||||
<Form.Item
|
||||
label={t("bodyshop.fields.dms.dms_acctnumber")}
|
||||
rules={[
|
||||
@@ -3997,7 +4000,7 @@ export function ShopInfoResponsibilityCenterComponent({ bodyshop, form }) {
|
||||
>
|
||||
<Input />
|
||||
</Form.Item>
|
||||
{(bodyshop.cdk_dealerid || bodyshop.pbs_serialnumber || bodyshop.rr_dealerid) && (
|
||||
{hasDMSKey && (
|
||||
<Form.Item
|
||||
label={t("bodyshop.fields.dms.dms_acctnumber")}
|
||||
rules={[
|
||||
@@ -4348,7 +4351,7 @@ export function ShopInfoResponsibilityCenterComponent({ bodyshop, form }) {
|
||||
{InstanceRenderManager({
|
||||
rome: (
|
||||
<LayoutFormRow header={<div>Adjustments</div>} id="refund">
|
||||
{bodyshop.cdk_dealerid || bodyshop.pbs_serialnumber || bodyshop.rr_dealerid ? (
|
||||
{hasDMSKey ? (
|
||||
<>
|
||||
<Form.Item
|
||||
label={t("bodyshop.labels.responsibilitycenters.ttl_adjustment")}
|
||||
|
||||
@@ -5,6 +5,7 @@ import { createStructuredSelector } from "reselect";
|
||||
import { selectBodyshop } from "../../redux/user/user.selectors";
|
||||
import InstanceRenderManager from "../../utils/instanceRenderMgr";
|
||||
import LayoutFormRow from "../layout-form-row/layout-form-row.component";
|
||||
import { bodyshopHasDmsKey } from "../../utils/dmsUtils.js";
|
||||
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
//currentUser: selectCurrentUser
|
||||
@@ -2126,7 +2127,7 @@ function TaxFormItems({ typeNum, typeNumIterator, rootElements, bodyshop }) {
|
||||
>
|
||||
<Input />
|
||||
</Form.Item>
|
||||
{(bodyshop.cdk_dealerid || bodyshop.pbs_serialnumber || bodyshop.rr_dealerid) && (
|
||||
{bodyshopHasDmsKey(bodyshop) && (
|
||||
<Form.Item
|
||||
label={t("bodyshop.fields.dms.dms_acctnumber")}
|
||||
rules={[
|
||||
|
||||
@@ -16,6 +16,7 @@ import TechJobClockoutDelete from "../tech-job-clock-out-delete/tech-job-clock-o
|
||||
import { LaborAllocationContainer } from "../time-ticket-modal/time-ticket-modal.component";
|
||||
import { useSplitTreatments } from "@splitsoftware/splitio-react";
|
||||
import { useNotification } from "../../contexts/Notifications/notificationContext.jsx";
|
||||
import { bodyshopHasDmsKey } from "../../utils/dmsUtils.js";
|
||||
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
bodyshop: selectBodyshop,
|
||||
@@ -53,7 +54,9 @@ export function TechClockOffButton({
|
||||
nextFetchPolicy: "network-only"
|
||||
});
|
||||
const { t } = useTranslation();
|
||||
const emps = bodyshop.employees.filter((e) => e.id === (technician && technician.id))[0];
|
||||
|
||||
const emps = bodyshop.employees.filter((e) => e.id === technician?.id)[0];
|
||||
const hasDmsKey = bodyshopHasDmsKey(bodyshop);
|
||||
|
||||
const handleFinish = async (values) => {
|
||||
logImEXEvent("tech_clock_out_job");
|
||||
@@ -167,10 +170,7 @@ export function TechClockOffButton({
|
||||
lineTicketData.jobs_by_pk.lbr_adjustments
|
||||
);
|
||||
|
||||
const fieldTypeToCheck =
|
||||
bodyshop.cdk_dealerid || bodyshop.pbs_serialnumber || bodyshop.rr_dealerid
|
||||
? "mod_lbr_ty"
|
||||
: "cost_center";
|
||||
const fieldTypeToCheck = hasDmsKey ? "mod_lbr_ty" : "cost_center";
|
||||
|
||||
const costCenterDiff =
|
||||
Math.round(
|
||||
@@ -210,7 +210,7 @@ export function TechClockOffButton({
|
||||
<Select.Option key={item.cost_center}>
|
||||
{item.cost_center === "timetickets.labels.shift"
|
||||
? t(item.cost_center)
|
||||
: bodyshop.cdk_dealerid || bodyshop.pbs_serialnumber || bodyshop.rr_dealerid
|
||||
: hasDmsKey
|
||||
? t(`joblines.fields.lbr_types.${item.cost_center.toUpperCase()}`)
|
||||
: item.cost_center}
|
||||
</Select.Option>
|
||||
|
||||
@@ -14,6 +14,7 @@ import {
|
||||
import JobSearchSelect from "../job-search-select/job-search-select.component";
|
||||
import LaborAllocationsTable from "../labor-allocations-table/labor-allocations-table.component";
|
||||
import { CalculateAllocationsTotals } from "../labor-allocations-table/labor-allocations-table.utility";
|
||||
import { bodyshopHasDmsKey } from "../../utils/dmsUtils.js";
|
||||
import LayoutFormRow from "../layout-form-row/layout-form-row.component";
|
||||
import LoadingSkeleton from "../loading-skeleton/loading-skeleton.component";
|
||||
import { HasRbacAccess } from "../rbac-wrapper/rbac-wrapper.component";
|
||||
@@ -127,7 +128,7 @@ export function TimeTicketModalComponent({
|
||||
onSelect={(value) => {
|
||||
const emps = employeeAutoCompleteOptions && employeeAutoCompleteOptions.filter((e) => e.id === value)[0];
|
||||
|
||||
form.setFieldsValue({ flat_rate: emps && emps.flat_rate });
|
||||
form.setFieldsValue({ flat_rate: emps?.flat_rate });
|
||||
}}
|
||||
/>
|
||||
</Form.Item>
|
||||
@@ -189,10 +190,7 @@ export function TimeTicketModalComponent({
|
||||
lineTicketData.jobs_by_pk.lbr_adjustments
|
||||
);
|
||||
|
||||
const fieldTypeToCheck =
|
||||
bodyshop.cdk_dealerid || bodyshop.pbs_serialnumber || bodyshop.rr_dealerid
|
||||
? "mod_lbr_ty"
|
||||
: "cost_center";
|
||||
const fieldTypeToCheck = bodyshopHasDmsKey(bodyshop) ? "mod_lbr_ty" : "cost_center";
|
||||
|
||||
const costCenterDiff =
|
||||
Math.round(
|
||||
@@ -266,7 +264,7 @@ export function TimeTicketModalComponent({
|
||||
if (!value) return Promise.resolve();
|
||||
if (!clockon && value) return Promise.reject(t("timetickets.validation.clockoffwithoutclockon"));
|
||||
// TODO - Verify this exists
|
||||
if (value && value.isSameOrAfter && !value.isSameOrAfter(clockon))
|
||||
if (value?.isSameOrAfter && !value.isSameOrAfter(clockon))
|
||||
return Promise.reject(t("timetickets.validation.clockoffmustbeafterclockon"));
|
||||
|
||||
return Promise.resolve();
|
||||
|
||||
Reference in New Issue
Block a user