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 { selectBodyshop } from "../../redux/user/user.selectors";
|
||||||
import CurrencyInput from "../form-items-formatted/currency-form-item.component";
|
import CurrencyInput from "../form-items-formatted/currency-form-item.component";
|
||||||
import CiecaSelect from "../../utils/Ciecaselect";
|
import CiecaSelect from "../../utils/Ciecaselect";
|
||||||
|
import { bodyshopHasDmsKey } from "../../utils/dmsUtils.js";
|
||||||
|
|
||||||
const mapStateToProps = createStructuredSelector({
|
const mapStateToProps = createStructuredSelector({
|
||||||
bodyshop: selectBodyshop
|
bodyshop: selectBodyshop
|
||||||
@@ -44,7 +45,7 @@ export function BillFormItemsExtendedFormItem({
|
|||||||
quantity: record.part_qty || 1,
|
quantity: record.part_qty || 1,
|
||||||
actual_price: record.act_price,
|
actual_price: record.act_price,
|
||||||
cost_center: record.part_type
|
cost_center: record.part_type
|
||||||
? bodyshop.pbs_serialnumber || bodyshop.cdk_dealerid || bodyshop.rr_dealerid
|
? bodyshopHasDmsKey(bodyshop)
|
||||||
? record.part_type
|
? record.part_type
|
||||||
: responsibilityCenters.defaults && (responsibilityCenters.defaults.costs[record.part_type] || null)
|
: responsibilityCenters.defaults && (responsibilityCenters.defaults.costs[record.part_type] || null)
|
||||||
: null
|
: null
|
||||||
@@ -100,7 +101,7 @@ export function BillFormItemsExtendedFormItem({
|
|||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item label={t("billlines.fields.cost_center")} name={["billlineskeys", record.id, "cost_center"]}>
|
<Form.Item label={t("billlines.fields.cost_center")} name={["billlineskeys", record.id, "cost_center"]}>
|
||||||
<Select showSearch style={{ minWidth: "3rem" }} disabled={disabled}>
|
<Select showSearch style={{ minWidth: "3rem" }} disabled={disabled}>
|
||||||
{bodyshop.cdk_dealerid || bodyshop.pbs_serialnumber || bodyshop.rr_dealerid
|
{bodyshopHasDmsKey(bodyshop)
|
||||||
? CiecaSelect(true, false)
|
? CiecaSelect(true, false)
|
||||||
: responsibilityCenters.costs.map((item) => <Select.Option key={item.name}>{item.name}</Select.Option>)}
|
: responsibilityCenters.costs.map((item) => <Select.Option key={item.name}>{item.name}</Select.Option>)}
|
||||||
</Select>
|
</Select>
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import VendorSearchSelect from "../vendor-search-select/vendor-search-select.com
|
|||||||
import BillFormLines from "./bill-form.lines.component";
|
import BillFormLines from "./bill-form.lines.component";
|
||||||
import { CalculateBillTotal } from "./bill-form.totals.utility";
|
import { CalculateBillTotal } from "./bill-form.totals.utility";
|
||||||
import DateTimePicker from "../form-date-time-picker/form-date-time-picker.component.jsx";
|
import DateTimePicker from "../form-date-time-picker/form-date-time-picker.component.jsx";
|
||||||
|
import { bodyshopHasDmsKey } from "../../utils/dmsUtils.js";
|
||||||
|
|
||||||
const mapStateToProps = createStructuredSelector({
|
const mapStateToProps = createStructuredSelector({
|
||||||
bodyshop: selectBodyshop
|
bodyshop: selectBodyshop
|
||||||
@@ -354,7 +355,7 @@ export function BillFormComponent({
|
|||||||
<Form.Item span={3} label={t("bills.fields.local_tax_rate")} name="local_tax_rate">
|
<Form.Item span={3} label={t("bills.fields.local_tax_rate")} name="local_tax_rate">
|
||||||
<CurrencyInput min={0} />
|
<CurrencyInput min={0} />
|
||||||
</Form.Item>
|
</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">
|
<Form.Item span={2} label={t("bills.labels.federal_tax_exempt")} name="federal_tax_exempt">
|
||||||
<Switch onChange={handleFederalTaxExemptSwitchToggle} />
|
<Switch onChange={handleFederalTaxExemptSwitchToggle} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import InstanceRenderManager from "../../utils/instanceRenderMgr";
|
|||||||
import BillLineSearchSelect from "../bill-line-search-select/bill-line-search-select.component";
|
import BillLineSearchSelect from "../bill-line-search-select/bill-line-search-select.component";
|
||||||
import BilllineAddInventory from "../billline-add-inventory/billline-add-inventory.component";
|
import BilllineAddInventory from "../billline-add-inventory/billline-add-inventory.component";
|
||||||
import CurrencyInput from "../form-items-formatted/currency-form-item.component";
|
import CurrencyInput from "../form-items-formatted/currency-form-item.component";
|
||||||
|
import { bodyshopHasDmsKey } from "../../utils/dmsUtils.js";
|
||||||
|
|
||||||
const mapStateToProps = createStructuredSelector({
|
const mapStateToProps = createStructuredSelector({
|
||||||
//currentUser: selectCurrentUser
|
//currentUser: selectCurrentUser
|
||||||
@@ -90,7 +91,7 @@ export function BillEnterModalLinesComponent({
|
|||||||
actual_price: opt.cost,
|
actual_price: opt.cost,
|
||||||
original_actual_price: opt.cost,
|
original_actual_price: opt.cost,
|
||||||
cost_center: opt.part_type
|
cost_center: opt.part_type
|
||||||
? bodyshop.pbs_serialnumber || bodyshop.cdk_dealerid || bodyshop.rr_dealerid
|
? bodyshopHasDmsKey(bodyshop)
|
||||||
? opt.part_type !== "PAE"
|
? opt.part_type !== "PAE"
|
||||||
? opt.part_type
|
? opt.part_type
|
||||||
: null
|
: null
|
||||||
@@ -322,7 +323,7 @@ export function BillEnterModalLinesComponent({
|
|||||||
},
|
},
|
||||||
formInput: () => (
|
formInput: () => (
|
||||||
<Select showSearch style={{ minWidth: "3rem" }} disabled={disabled}>
|
<Select showSearch style={{ minWidth: "3rem" }} disabled={disabled}>
|
||||||
{bodyshop.cdk_dealerid || bodyshop.pbs_serialnumber || bodyshop.rr_dealerid
|
{bodyshopHasDmsKey(bodyshop)
|
||||||
? CiecaSelect(true, false)
|
? CiecaSelect(true, false)
|
||||||
: responsibilityCenters.costs.map((item) => <Select.Option key={item.name}>{item.name}</Select.Option>)}
|
: responsibilityCenters.costs.map((item) => <Select.Option key={item.name}>{item.name}</Select.Option>)}
|
||||||
</Select>
|
</Select>
|
||||||
|
|||||||
@@ -1,102 +1,97 @@
|
|||||||
import { Alert, Button, Card, Table, Typography } from "antd";
|
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 { useTranslation } from "react-i18next";
|
||||||
import { connect } from "react-redux";
|
import { connect } from "react-redux";
|
||||||
import { createStructuredSelector } from "reselect";
|
import { createStructuredSelector } from "reselect";
|
||||||
import { selectBodyshop } from "../../redux/user/user.selectors";
|
|
||||||
import Dinero from "dinero.js";
|
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 { pageLimit } from "../../utils/config";
|
||||||
import { useSplitTreatments } from "@splitsoftware/splitio-react";
|
|
||||||
import { useSocket } from "../../contexts/SocketIO/useSocket";
|
|
||||||
import { determineDmsType } from "../../utils/determineDMSType";
|
|
||||||
|
|
||||||
const mapStateToProps = createStructuredSelector({
|
const mapStateToProps = createStructuredSelector({
|
||||||
//currentUser: selectCurrentUser
|
|
||||||
bodyshop: selectBodyshop
|
bodyshop: selectBodyshop
|
||||||
});
|
});
|
||||||
|
const mapDispatchToProps = () => ({});
|
||||||
const mapDispatchToProps = () => ({
|
|
||||||
//setUserLanguage: language => dispatch(setUserLanguage(language))
|
|
||||||
});
|
|
||||||
|
|
||||||
export default connect(mapStateToProps, mapDispatchToProps)(DmsAllocationsSummary);
|
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 { t } = useTranslation();
|
||||||
const [allocationsSummary, setAllocationsSummary] = useState([]);
|
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 = () => {
|
const fetchAllocations = useCallback(() => {
|
||||||
// ✅ RR takes precedence over Fortellis
|
if (!socket || !jobId || !mode) return;
|
||||||
if (dms === "rr") {
|
|
||||||
wsssocket.emit("rr-calculate-allocations", jobId, (ack) => {
|
try {
|
||||||
console.dir({ ack });
|
socket.emit(allocationsEvent, jobId, (ack) => {
|
||||||
setAllocationsSummary(ack);
|
const list = Array.isArray(ack) ? ack : [];
|
||||||
socket.allocationsSummary = ack;
|
setAllocationsSummary(list);
|
||||||
});
|
// Preserve side-channel used by the post form for discrepancy checks
|
||||||
} else if (Fortellis.treatment === "on") {
|
socket.allocationsSummary = list;
|
||||||
// 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;
|
|
||||||
});
|
});
|
||||||
|
} catch {
|
||||||
|
// Best-effort; leave table empty on error
|
||||||
|
setAllocationsSummary([]);
|
||||||
|
socket && (socket.allocationsSummary = []);
|
||||||
}
|
}
|
||||||
};
|
}, [socket, jobId, mode, allocationsEvent]);
|
||||||
|
|
||||||
|
// Initial + whenever mode/socket/jobId changes
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchAllocations();
|
fetchAllocations();
|
||||||
}, [socket, socket.connected, jobId, dms, Fortellis?.treatment]);
|
}, [fetchAllocations]);
|
||||||
|
|
||||||
const columns = [
|
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"),
|
title: t("jobs.fields.dms.sale"),
|
||||||
dataIndex: "sale",
|
dataIndex: "sale",
|
||||||
key: "sale",
|
key: "sale",
|
||||||
render: (text, record) => Dinero(record.sale).toFormat()
|
render: (_text, record) => Dinero(record.sale).toFormat()
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: t("jobs.fields.dms.cost"),
|
title: t("jobs.fields.dms.cost"),
|
||||||
dataIndex: "cost",
|
dataIndex: "cost",
|
||||||
key: "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"),
|
title: t("jobs.fields.dms.sale_dms_acctnumber"),
|
||||||
dataIndex: "sale_dms_acctnumber",
|
dataIndex: "sale_dms_acctnumber",
|
||||||
key: "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"),
|
title: t("jobs.fields.dms.cost_dms_acctnumber"),
|
||||||
dataIndex: "cost_dms_acctnumber",
|
dataIndex: "cost_dms_acctnumber",
|
||||||
key: "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"),
|
title: t("jobs.fields.dms.dms_wip_acctnumber"),
|
||||||
dataIndex: "dms_wip_acctnumber",
|
dataIndex: "dms_wip_acctnumber",
|
||||||
key: "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
|
<Card
|
||||||
title={title}
|
title={title}
|
||||||
extra={
|
extra={
|
||||||
<Button onClick={fetchAllocations}>
|
<Button onClick={fetchAllocations} aria-label={t("general.actions.refresh")}>
|
||||||
<SyncOutlined />
|
<SyncOutlined />
|
||||||
</Button>
|
</Button>
|
||||||
}
|
}
|
||||||
@@ -112,6 +107,7 @@ export function DmsAllocationsSummary({ socket, bodyshop, jobId, title }) {
|
|||||||
{bodyshop.pbs_configuration?.disablebillwip && (
|
{bodyshop.pbs_configuration?.disablebillwip && (
|
||||||
<Alert type="warning" message={t("jobs.labels.dms.disablebillwip")} />
|
<Alert type="warning" message={t("jobs.labels.dms.disablebillwip")} />
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<Table
|
<Table
|
||||||
pagination={{ position: "top", defaultPageSize: pageLimit }}
|
pagination={{ position: "top", defaultPageSize: pageLimit }}
|
||||||
columns={columns}
|
columns={columns}
|
||||||
@@ -120,34 +116,23 @@ export function DmsAllocationsSummary({ socket, bodyshop, jobId, title }) {
|
|||||||
locale={{ emptyText: t("dms.labels.refreshallocations") }}
|
locale={{ emptyText: t("dms.labels.refreshallocations") }}
|
||||||
scroll={{ x: true }}
|
scroll={{ x: true }}
|
||||||
summary={() => {
|
summary={() => {
|
||||||
const totals =
|
const totals = allocationsSummary?.reduce(
|
||||||
allocationsSummary &&
|
(acc, val) => ({
|
||||||
allocationsSummary.reduce(
|
totalSale: acc.totalSale.add(Dinero(val.sale)),
|
||||||
(acc, val) => {
|
totalCost: acc.totalCost.add(Dinero(val.cost))
|
||||||
return {
|
}),
|
||||||
totalSale: acc.totalSale.add(Dinero(val.sale)),
|
{ totalSale: Dinero(), totalCost: Dinero() }
|
||||||
totalCost: acc.totalCost.add(Dinero(val.cost))
|
) || { totalSale: Dinero(), totalCost: Dinero() };
|
||||||
};
|
|
||||||
},
|
|
||||||
{
|
|
||||||
totalSale: Dinero(),
|
|
||||||
totalCost: Dinero()
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Table.Summary.Row>
|
<Table.Summary.Row>
|
||||||
<Table.Summary.Cell>
|
<Table.Summary.Cell>
|
||||||
<Typography.Title level={4}>{t("general.labels.totals")}</Typography.Title>
|
<Typography.Title level={4}>{t("general.labels.totals")}</Typography.Title>
|
||||||
</Table.Summary.Cell>
|
</Table.Summary.Cell>
|
||||||
<Table.Summary.Cell>{totals && totals.totalSale.toFormat()}</Table.Summary.Cell>
|
<Table.Summary.Cell>{totals.totalSale.toFormat()}</Table.Summary.Cell>
|
||||||
<Table.Summary.Cell>
|
<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>
|
|
||||||
</Table.Summary.Row>
|
</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 { useMemo } from "react";
|
||||||
import { Alert, Button, Checkbox, Col, message, Space, Table } from "antd";
|
|
||||||
import { useEffect, useMemo, useState } from "react";
|
|
||||||
import { useTranslation } from "react-i18next";
|
|
||||||
import { connect } from "react-redux";
|
import { connect } from "react-redux";
|
||||||
import { createStructuredSelector } from "reselect";
|
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 { 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({
|
const mapStateToProps = createStructuredSelector({
|
||||||
bodyshop: selectBodyshop
|
bodyshop: selectBodyshop
|
||||||
@@ -16,479 +16,39 @@ const mapStateToProps = createStructuredSelector({
|
|||||||
const mapDispatchToProps = () => ({});
|
const mapDispatchToProps = () => ({});
|
||||||
export default connect(mapStateToProps, mapDispatchToProps)(DmsCustomerSelector);
|
export default connect(mapStateToProps, mapDispatchToProps)(DmsCustomerSelector);
|
||||||
|
|
||||||
// ---------------- Helpers ----------------
|
/**
|
||||||
function normalizeRrList(list) {
|
* DMS Customer Selector component that renders the appropriate customer selector
|
||||||
if (!Array.isArray(list)) return [];
|
* @param props
|
||||||
return list
|
* @returns {JSX.Element|null}
|
||||||
.map((row) => {
|
* @constructor
|
||||||
const custNo = row.custNo || row.CustomerId || row.customerId || null;
|
*/
|
||||||
const name =
|
export function DmsCustomerSelector(props) {
|
||||||
row.name ||
|
const { bodyshop, jobid, socket, rrOptions = {} } = props;
|
||||||
[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 =
|
// Centralized "mode" (provider + transport)
|
||||||
row.address && typeof row.address === "object"
|
const mode = props.mode;
|
||||||
? {
|
|
||||||
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 };
|
// Stable base props for children
|
||||||
})
|
const base = useMemo(() => ({ bodyshop, jobid, socket }), [bodyshop, jobid, socket]);
|
||||||
.filter(Boolean);
|
|
||||||
}
|
switch (mode) {
|
||||||
|
case DMS_MAP.reynolds: {
|
||||||
function rrAddressToString(addr) {
|
// Map rrOptions to current RR prop shape (you can also just pass rrOptions through and unpack in RR)
|
||||||
if (!addr) return "";
|
const rrProps = {
|
||||||
const parts = [
|
rrOpenRoLimit: rrOptions.openRoLimit,
|
||||||
addr.line1,
|
onRrOpenRoFinished: rrOptions.onOpenRoFinished,
|
||||||
addr.line2,
|
rrCashierPending: rrOptions.cashierPending,
|
||||||
[addr.city, addr.state].filter(Boolean).join(" "),
|
onRrCashierFinished: rrOptions.onCashierFinished
|
||||||
addr.postalCode,
|
};
|
||||||
addr.country
|
return <RRCustomerSelector {...base} {...rrProps} />;
|
||||||
].filter(Boolean);
|
}
|
||||||
return parts.join(", ");
|
case DMS_MAP.fortellis:
|
||||||
}
|
return <FortellisCustomerSelector {...base} />;
|
||||||
|
case DMS_MAP.cdk:
|
||||||
export function DmsCustomerSelector({
|
return <CDKCustomerSelector {...base} />;
|
||||||
bodyshop,
|
case DMS_MAP.pbs:
|
||||||
jobid,
|
return <PBSCustomerSelector {...base} />;
|
||||||
rrOpenRoLimit = false,
|
default:
|
||||||
onRrOpenRoFinished,
|
return null;
|
||||||
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>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 dayjs from "../../utils/day";
|
||||||
import { connect } from "react-redux";
|
import { connect } from "react-redux";
|
||||||
import { createStructuredSelector } from "reselect";
|
import { createStructuredSelector } from "reselect";
|
||||||
import { setBreadcrumbs, setSelectedHeader } from "../../redux/application/application.actions";
|
|
||||||
import { selectDarkMode } from "../../redux/application/application.selectors.js";
|
import { selectDarkMode } from "../../redux/application/application.selectors.js";
|
||||||
|
|
||||||
const mapStateToProps = createStructuredSelector({
|
const mapStateToProps = createStructuredSelector({
|
||||||
isDarkMode: selectDarkMode
|
isDarkMode: selectDarkMode
|
||||||
});
|
});
|
||||||
|
|
||||||
const mapDispatchToProps = (dispatch) => ({
|
const mapDispatchToProps = () => ({});
|
||||||
setBreadcrumbs: (breadcrumbs) => dispatch(setBreadcrumbs(breadcrumbs)),
|
|
||||||
setSelectedHeader: (key) => dispatch(setSelectedHeader(key))
|
|
||||||
});
|
|
||||||
|
|
||||||
export default connect(mapStateToProps, mapDispatchToProps)(DmsLogEvents);
|
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 { connect } from "react-redux";
|
||||||
import { createStructuredSelector } from "reselect";
|
import { createStructuredSelector } from "reselect";
|
||||||
import { determineDmsType } from "../../utils/determineDMSType";
|
|
||||||
import { selectBodyshop } from "../../redux/user/user.selectors";
|
import { selectBodyshop } from "../../redux/user/user.selectors";
|
||||||
import i18n from "../../translations/i18n";
|
import { DMS_MAP } from "../../utils/dmsUtils";
|
||||||
import dayjs from "../../utils/day";
|
import RRPostForm from "./rr-dms-post-form";
|
||||||
import DmsCdkMakes from "../dms-cdk-makes/dms-cdk-makes.component";
|
import CdkLikePostForm from "./cdklike-dms-post-form";
|
||||||
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";
|
|
||||||
|
|
||||||
const mapStateToProps = createStructuredSelector({
|
const mapStateToProps = createStructuredSelector({
|
||||||
bodyshop: selectBodyshop
|
bodyshop: selectBodyshop
|
||||||
});
|
});
|
||||||
const mapDispatchToProps = () => ({});
|
const mapDispatchToProps = () => ({});
|
||||||
|
|
||||||
export default connect(mapStateToProps, mapDispatchToProps)(DmsPostForm);
|
export default connect(mapStateToProps, mapDispatchToProps)(DmsPostForm);
|
||||||
|
|
||||||
export function DmsPostForm({ bodyshop, socket, job, logsRef }) {
|
/**
|
||||||
const {
|
* DMS Post Form component that renders the appropriate post form
|
||||||
treatments: { Fortellis }
|
* @param mode
|
||||||
} = useSplitTreatments({
|
* @param bodyshop
|
||||||
attributes: {},
|
* @param socket
|
||||||
names: ["Fortellis"],
|
* @param job
|
||||||
splitKey: bodyshop.imexshopid
|
* @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();
|
// CDK (legacy /ws), Fortellis (CDK-over-WSS), and PBS share the same UI;
|
||||||
const { t } = useTranslation();
|
// we pass mode down so the child can choose the correct event name.
|
||||||
const { socket: wsssocket } = useSocket();
|
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
|
default:
|
||||||
const dms = useMemo(() => determineDmsType(bodyshop), [bodyshop]);
|
return null;
|
||||||
|
}
|
||||||
// ---------------- 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>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
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 { logImEXEvent } from "../../firebase/firebase.utils";
|
||||||
import { selectBodyshop } from "../../redux/user/user.selectors";
|
import { selectBodyshop } from "../../redux/user/user.selectors";
|
||||||
import InstanceRenderManager from "../../utils/instanceRenderMgr";
|
import InstanceRenderManager from "../../utils/instanceRenderMgr";
|
||||||
|
import { bodyshopHasDmsKey } from "../../utils/dmsUtils.js";
|
||||||
|
|
||||||
const mapStateToProps = createStructuredSelector({
|
const mapStateToProps = createStructuredSelector({
|
||||||
bodyshop: selectBodyshop
|
bodyshop: selectBodyshop
|
||||||
@@ -14,6 +15,8 @@ const mapStateToProps = createStructuredSelector({
|
|||||||
export function JobsCloseAutoAllocate({ bodyshop, joblines, form, disabled }) {
|
export function JobsCloseAutoAllocate({ bodyshop, joblines, form, disabled }) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
const hasDmsKey = bodyshopHasDmsKey(bodyshop);
|
||||||
|
|
||||||
const handleAllocate = (defaults) => {
|
const handleAllocate = (defaults) => {
|
||||||
form.setFieldsValue({
|
form.setFieldsValue({
|
||||||
joblines: joblines.map((jl) => {
|
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));
|
handleAllocate(bodyshop.md_responsibility_centers.dms_defaults.find((x) => x.name === key));
|
||||||
};
|
};
|
||||||
|
|
||||||
const menu =
|
const menu = hasDmsKey
|
||||||
bodyshop.cdk_dealerid || bodyshop.pbs_serialnumber || bodyshop.rr_dealerid
|
? {
|
||||||
? {
|
items: bodyshop.md_responsibility_centers.dms_defaults.map((mapping) => ({
|
||||||
items: bodyshop.md_responsibility_centers.dms_defaults.map((mapping) => ({
|
key: mapping.name,
|
||||||
key: mapping.name,
|
label: mapping.name,
|
||||||
label: mapping.name,
|
disabled: disabled
|
||||||
disabled: disabled
|
})),
|
||||||
})),
|
onClick: handleMenuClick
|
||||||
onClick: handleMenuClick
|
}
|
||||||
}
|
: {
|
||||||
: {
|
items: []
|
||||||
items: []
|
};
|
||||||
};
|
|
||||||
|
|
||||||
return bodyshop.cdk_dealerid || bodyshop.pbs_serialnumber || bodyshop.rr_dealerid ? (
|
return hasDmsKey ? (
|
||||||
<Dropdown menu={menu}>
|
<Dropdown menu={menu}>
|
||||||
<Button disabled={disabled}>{t("jobs.actions.dmsautoallocate")}</Button>
|
<Button disabled={disabled}>{t("jobs.actions.dmsautoallocate")}</Button>
|
||||||
</Dropdown>
|
</Dropdown>
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import { auth, logImEXEvent } from "../../firebase/firebase.utils";
|
|||||||
import { INSERT_EXPORT_LOG } from "../../graphql/accounting.queries";
|
import { INSERT_EXPORT_LOG } from "../../graphql/accounting.queries";
|
||||||
import { UPDATE_JOB } from "../../graphql/jobs.queries";
|
import { UPDATE_JOB } from "../../graphql/jobs.queries";
|
||||||
import { insertAuditTrail } from "../../redux/application/application.actions";
|
import { insertAuditTrail } from "../../redux/application/application.actions";
|
||||||
|
import { bodyshopHasDmsKey } from "../../utils/dmsUtils.js";
|
||||||
import { selectBodyshop, selectCurrentUser } from "../../redux/user/user.selectors";
|
import { selectBodyshop, selectCurrentUser } from "../../redux/user/user.selectors";
|
||||||
import AuditTrailMapping from "../../utils/AuditTrailMappings";
|
import AuditTrailMapping from "../../utils/AuditTrailMappings";
|
||||||
import client from "../../utils/GraphQLClient";
|
import client from "../../utils/GraphQLClient";
|
||||||
@@ -45,7 +46,7 @@ export function JobsCloseExportButton({ bodyshop, currentUser, jobId, disabled,
|
|||||||
|
|
||||||
const handleQbxml = async () => {
|
const handleQbxml = async () => {
|
||||||
//Check if it's a CDK setup.
|
//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}`);
|
history(`/manage/dms?jobId=${jobId}`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import ProductionListColumnProductionNote from "../production-list-columns/produ
|
|||||||
import VehicleVinDisplay from "../vehicle-vin-display/vehicle-vin-display.component";
|
import VehicleVinDisplay from "../vehicle-vin-display/vehicle-vin-display.component";
|
||||||
import "./jobs-detail-header.styles.scss";
|
import "./jobs-detail-header.styles.scss";
|
||||||
import getPartsBasePath from "../../utils/getPartsBasePath.js";
|
import getPartsBasePath from "../../utils/getPartsBasePath.js";
|
||||||
|
import { bodyshopHasDmsKey } from "../../utils/dmsUtils.js";
|
||||||
|
|
||||||
const mapStateToProps = createStructuredSelector({
|
const mapStateToProps = createStructuredSelector({
|
||||||
jobRO: selectJobReadOnly,
|
jobRO: selectJobReadOnly,
|
||||||
@@ -309,7 +310,7 @@ export function JobsDetailHeader({ job, bodyshop, disabled, insertAuditTrail, is
|
|||||||
</DataLabel>
|
</DataLabel>
|
||||||
<DataLabel key="4" label={t("vehicles.fields.v_vin")}>
|
<DataLabel key="4" label={t("vehicles.fields.v_vin")}>
|
||||||
<VehicleVinDisplay>{`${job.v_vin || t("general.labels.na")}`}</VehicleVinDisplay>
|
<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 ? (
|
job.v_vin?.length !== 17 ? (
|
||||||
<WarningFilled style={{ color: "tomato", marginLeft: ".3rem" }} />
|
<WarningFilled style={{ color: "tomato", marginLeft: ".3rem" }} />
|
||||||
) : null
|
) : null
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import i18next from "i18next";
|
import i18next from "i18next";
|
||||||
|
import { bodyshopHasDmsKey } from "../../utils/dmsUtils.js";
|
||||||
|
|
||||||
export const CalculateAllocationsTotals = (bodyshop, joblines, timetickets, adjustments = []) => {
|
export const CalculateAllocationsTotals = (bodyshop, joblines, timetickets, adjustments = []) => {
|
||||||
const responsibilitycenters = bodyshop.md_responsibility_centers;
|
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 = allCodes.reduce((acc, value) => {
|
||||||
const r = {
|
const r = {
|
||||||
opcode: value,
|
opcode: value,
|
||||||
cost_center:
|
cost_center: bodyshopHasDmsKey(bodyshop)
|
||||||
bodyshop.cdk_dealerid || bodyshop.pbs_serialnumber || bodyshop.rr_dealerid
|
? i18next.t(`joblines.fields.lbr_types.${value && value.toUpperCase()}`)
|
||||||
? i18next.t(`joblines.fields.lbr_types.${value && value.toUpperCase()}`)
|
: responsibilitycenters.defaults.costs[value],
|
||||||
: responsibilitycenters.defaults.costs[value],
|
|
||||||
mod_lbr_ty: value,
|
mod_lbr_ty: value,
|
||||||
total: joblines.reduce((acc2, val2) => {
|
total: joblines.reduce((acc2, val2) => {
|
||||||
return val2.mod_lbr_ty === value ? acc2 + val2.mod_lb_hrs : acc2;
|
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 PartsOrderLineBackorderButton from "../parts-order-line-backorder-button/parts-order-line-backorder-button.component";
|
||||||
import PartsReceiveModalContainer from "../parts-receive-modal/parts-receive-modal.container";
|
import PartsReceiveModalContainer from "../parts-receive-modal/parts-receive-modal.container";
|
||||||
import PrintWrapper from "../print-wrapper/print-wrapper.component";
|
import PrintWrapper from "../print-wrapper/print-wrapper.component";
|
||||||
|
import { bodyshopHasDmsKey } from "../../utils/dmsUtils.js";
|
||||||
|
|
||||||
const mapStateToProps = createStructuredSelector({
|
const mapStateToProps = createStructuredSelector({
|
||||||
jobRO: selectJobReadOnly,
|
jobRO: selectJobReadOnly,
|
||||||
@@ -196,7 +197,7 @@ export function PartsOrderListTableDrawerComponent({
|
|||||||
quantity: pol.quantity,
|
quantity: pol.quantity,
|
||||||
actual_price: pol.act_price,
|
actual_price: pol.act_price,
|
||||||
cost_center: pol.jobline?.part_type
|
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 !== "PAE"
|
||||||
? pol.jobline.part_type
|
? pol.jobline.part_type
|
||||||
: null
|
: null
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import PartsReceiveModalContainer from "../parts-receive-modal/parts-receive-mod
|
|||||||
import PrintWrapper from "../print-wrapper/print-wrapper.component";
|
import PrintWrapper from "../print-wrapper/print-wrapper.component";
|
||||||
import PartsOrderDrawer from "./parts-order-list-table-drawer.component";
|
import PartsOrderDrawer from "./parts-order-list-table-drawer.component";
|
||||||
import ShareToTeamsButton from "../share-to-teams/share-to-teams.component.jsx";
|
import ShareToTeamsButton from "../share-to-teams/share-to-teams.component.jsx";
|
||||||
|
import { bodyshopHasDmsKey } from "../../utils/dmsUtils.js";
|
||||||
|
|
||||||
const mapStateToProps = createStructuredSelector({
|
const mapStateToProps = createStructuredSelector({
|
||||||
jobRO: selectJobReadOnly,
|
jobRO: selectJobReadOnly,
|
||||||
@@ -69,6 +70,7 @@ export function PartsOrderListTableComponent({
|
|||||||
|
|
||||||
const parts_orders = billsQuery.data ? billsQuery.data.parts_orders : [];
|
const parts_orders = billsQuery.data ? billsQuery.data.parts_orders : [];
|
||||||
const { refetch } = billsQuery;
|
const { refetch } = billsQuery;
|
||||||
|
|
||||||
const recordActions = (record, showView = false) => (
|
const recordActions = (record, showView = false) => (
|
||||||
<Space direction="horizontal" wrap>
|
<Space direction="horizontal" wrap>
|
||||||
<ShareToTeamsButton
|
<ShareToTeamsButton
|
||||||
@@ -172,7 +174,7 @@ export function PartsOrderListTableComponent({
|
|||||||
actual_price: pol.act_price,
|
actual_price: pol.act_price,
|
||||||
|
|
||||||
cost_center: pol.jobline?.part_type
|
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 !== "PAE"
|
||||||
? pol.jobline.part_type
|
? pol.jobline.part_type
|
||||||
: null
|
: null
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import LayoutFormRow from "../layout-form-row/layout-form-row.component";
|
|||||||
import RbacWrapper from "../rbac-wrapper/rbac-wrapper.component";
|
import RbacWrapper from "../rbac-wrapper/rbac-wrapper.component";
|
||||||
import ShopInfoResponsibilitycentersTaxesComponent from "./shop-info.responsibilitycenters.taxes.component";
|
import ShopInfoResponsibilitycentersTaxesComponent from "./shop-info.responsibilitycenters.taxes.component";
|
||||||
import ShopInfoRRConfigurationComponent from "./shop-info.rr-configuration.component";
|
import ShopInfoRRConfigurationComponent from "./shop-info.rr-configuration.component";
|
||||||
|
import { bodyshopHasDmsKey } from "../../utils/dmsUtils.js";
|
||||||
|
|
||||||
const SelectorDiv = styled.div`
|
const SelectorDiv = styled.div`
|
||||||
.ant-form-item .ant-select {
|
.ant-form-item .ant-select {
|
||||||
@@ -34,12 +35,14 @@ export default connect(mapStateToProps, mapDispatchToProps)(ShopInfoResponsibili
|
|||||||
export function ShopInfoResponsibilityCenterComponent({ bodyshop, form }) {
|
export function ShopInfoResponsibilityCenterComponent({ bodyshop, form }) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
const hasDMSKey = bodyshopHasDmsKey(bodyshop);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
treatments: { Qb_Multi_Ar, DmsAp }
|
treatments: { Qb_Multi_Ar, DmsAp }
|
||||||
} = useSplitTreatments({
|
} = useSplitTreatments({
|
||||||
attributes: {},
|
attributes: {},
|
||||||
names: ["Qb_Multi_Ar", "DmsAp"],
|
names: ["Qb_Multi_Ar", "DmsAp"],
|
||||||
splitKey: bodyshop && bodyshop.imexshopid
|
splitKey: bodyshop?.imexshopid
|
||||||
});
|
});
|
||||||
|
|
||||||
const [costOptions, setCostOptions] = useState([
|
const [costOptions, setCostOptions] = useState([
|
||||||
@@ -62,7 +65,7 @@ export function ShopInfoResponsibilityCenterComponent({ bodyshop, form }) {
|
|||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<RbacWrapper action="shop:responsibilitycenter">
|
<RbacWrapper action="shop:responsibilitycenter">
|
||||||
{(bodyshop.cdk_dealerid || bodyshop.pbs_serialnumber || bodyshop.rr_dealerid) && (
|
{hasDMSKey && (
|
||||||
<>
|
<>
|
||||||
{bodyshop.rr_dealerid && <ShopInfoRRConfigurationComponent form={form} />}
|
{bodyshop.rr_dealerid && <ShopInfoRRConfigurationComponent form={form} />}
|
||||||
|
|
||||||
@@ -396,7 +399,7 @@ export function ShopInfoResponsibilityCenterComponent({ bodyshop, form }) {
|
|||||||
>
|
>
|
||||||
<Input onBlur={handleBlur} />
|
<Input onBlur={handleBlur} />
|
||||||
</Form.Item> */}
|
</Form.Item> */}
|
||||||
{(bodyshop.cdk_dealerid || bodyshop.pbs_serialnumber || bodyshop.rr_dealerid) && (
|
{hasDMSKey && (
|
||||||
<Form.Item
|
<Form.Item
|
||||||
label={t("bodyshop.fields.dms.dms_acctnumber")}
|
label={t("bodyshop.fields.dms.dms_acctnumber")}
|
||||||
key={`${index}dms_acctnumber`}
|
key={`${index}dms_acctnumber`}
|
||||||
@@ -410,7 +413,7 @@ export function ShopInfoResponsibilityCenterComponent({ bodyshop, form }) {
|
|||||||
<Input onBlur={handleBlur} />
|
<Input onBlur={handleBlur} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
)}
|
)}
|
||||||
{(bodyshop.cdk_dealerid || bodyshop.pbs_serialnumber || bodyshop.rr_dealerid) && (
|
{hasDMSKey && (
|
||||||
<Form.Item
|
<Form.Item
|
||||||
label={t("bodyshop.fields.dms.dms_wip_acctnumber")}
|
label={t("bodyshop.fields.dms.dms_wip_acctnumber")}
|
||||||
key={`${index}dms_wip_acctnumber`}
|
key={`${index}dms_wip_acctnumber`}
|
||||||
@@ -537,7 +540,7 @@ export function ShopInfoResponsibilityCenterComponent({ bodyshop, form }) {
|
|||||||
>
|
>
|
||||||
<Input onBlur={handleBlur} />
|
<Input onBlur={handleBlur} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
{(bodyshop.cdk_dealerid || bodyshop.pbs_serialnumber || bodyshop.rr_dealerid) && (
|
{hasDMSKey && (
|
||||||
<Form.Item
|
<Form.Item
|
||||||
label={t("bodyshop.fields.dms.dms_acctnumber")}
|
label={t("bodyshop.fields.dms.dms_acctnumber")}
|
||||||
key={`${index}dms_acctnumber`}
|
key={`${index}dms_acctnumber`}
|
||||||
@@ -588,7 +591,7 @@ export function ShopInfoResponsibilityCenterComponent({ bodyshop, form }) {
|
|||||||
</Form.List>
|
</Form.List>
|
||||||
</LayoutFormRow>
|
</LayoutFormRow>
|
||||||
<SelectorDiv>
|
<SelectorDiv>
|
||||||
{(bodyshop.cdk_dealerid || bodyshop.pbs_serialnumber || bodyshop.rr_dealerid) && (
|
{hasDMSKey && (
|
||||||
<>
|
<>
|
||||||
<LayoutFormRow id="mappingname" header={t("bodyshop.labels.dms.dms_allocations")}>
|
<LayoutFormRow id="mappingname" header={t("bodyshop.labels.dms.dms_allocations")}>
|
||||||
<Form.List name={["md_responsibility_centers", "dms_defaults"]}>
|
<Form.List name={["md_responsibility_centers", "dms_defaults"]}>
|
||||||
@@ -3802,7 +3805,7 @@ export function ShopInfoResponsibilityCenterComponent({ bodyshop, form }) {
|
|||||||
>
|
>
|
||||||
<Input />
|
<Input />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
{(bodyshop.cdk_dealerid || bodyshop.pbs_serialnumber || bodyshop.rr_dealerid) && (
|
{hasDMSKey && (
|
||||||
<Form.Item
|
<Form.Item
|
||||||
label={t("bodyshop.fields.dms.dms_acctnumber")}
|
label={t("bodyshop.fields.dms.dms_acctnumber")}
|
||||||
rules={[
|
rules={[
|
||||||
@@ -3901,7 +3904,7 @@ export function ShopInfoResponsibilityCenterComponent({ bodyshop, form }) {
|
|||||||
>
|
>
|
||||||
<Input />
|
<Input />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
{(bodyshop.cdk_dealerid || bodyshop.pbs_serialnumber || bodyshop.rr_dealerid) && (
|
{hasDMSKey && (
|
||||||
<Form.Item
|
<Form.Item
|
||||||
label={t("bodyshop.fields.dms.dms_acctnumber")}
|
label={t("bodyshop.fields.dms.dms_acctnumber")}
|
||||||
rules={[
|
rules={[
|
||||||
@@ -3997,7 +4000,7 @@ export function ShopInfoResponsibilityCenterComponent({ bodyshop, form }) {
|
|||||||
>
|
>
|
||||||
<Input />
|
<Input />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
{(bodyshop.cdk_dealerid || bodyshop.pbs_serialnumber || bodyshop.rr_dealerid) && (
|
{hasDMSKey && (
|
||||||
<Form.Item
|
<Form.Item
|
||||||
label={t("bodyshop.fields.dms.dms_acctnumber")}
|
label={t("bodyshop.fields.dms.dms_acctnumber")}
|
||||||
rules={[
|
rules={[
|
||||||
@@ -4348,7 +4351,7 @@ export function ShopInfoResponsibilityCenterComponent({ bodyshop, form }) {
|
|||||||
{InstanceRenderManager({
|
{InstanceRenderManager({
|
||||||
rome: (
|
rome: (
|
||||||
<LayoutFormRow header={<div>Adjustments</div>} id="refund">
|
<LayoutFormRow header={<div>Adjustments</div>} id="refund">
|
||||||
{bodyshop.cdk_dealerid || bodyshop.pbs_serialnumber || bodyshop.rr_dealerid ? (
|
{hasDMSKey ? (
|
||||||
<>
|
<>
|
||||||
<Form.Item
|
<Form.Item
|
||||||
label={t("bodyshop.labels.responsibilitycenters.ttl_adjustment")}
|
label={t("bodyshop.labels.responsibilitycenters.ttl_adjustment")}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { createStructuredSelector } from "reselect";
|
|||||||
import { selectBodyshop } from "../../redux/user/user.selectors";
|
import { selectBodyshop } from "../../redux/user/user.selectors";
|
||||||
import InstanceRenderManager from "../../utils/instanceRenderMgr";
|
import InstanceRenderManager from "../../utils/instanceRenderMgr";
|
||||||
import LayoutFormRow from "../layout-form-row/layout-form-row.component";
|
import LayoutFormRow from "../layout-form-row/layout-form-row.component";
|
||||||
|
import { bodyshopHasDmsKey } from "../../utils/dmsUtils.js";
|
||||||
|
|
||||||
const mapStateToProps = createStructuredSelector({
|
const mapStateToProps = createStructuredSelector({
|
||||||
//currentUser: selectCurrentUser
|
//currentUser: selectCurrentUser
|
||||||
@@ -2126,7 +2127,7 @@ function TaxFormItems({ typeNum, typeNumIterator, rootElements, bodyshop }) {
|
|||||||
>
|
>
|
||||||
<Input />
|
<Input />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
{(bodyshop.cdk_dealerid || bodyshop.pbs_serialnumber || bodyshop.rr_dealerid) && (
|
{bodyshopHasDmsKey(bodyshop) && (
|
||||||
<Form.Item
|
<Form.Item
|
||||||
label={t("bodyshop.fields.dms.dms_acctnumber")}
|
label={t("bodyshop.fields.dms.dms_acctnumber")}
|
||||||
rules={[
|
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 { LaborAllocationContainer } from "../time-ticket-modal/time-ticket-modal.component";
|
||||||
import { useSplitTreatments } from "@splitsoftware/splitio-react";
|
import { useSplitTreatments } from "@splitsoftware/splitio-react";
|
||||||
import { useNotification } from "../../contexts/Notifications/notificationContext.jsx";
|
import { useNotification } from "../../contexts/Notifications/notificationContext.jsx";
|
||||||
|
import { bodyshopHasDmsKey } from "../../utils/dmsUtils.js";
|
||||||
|
|
||||||
const mapStateToProps = createStructuredSelector({
|
const mapStateToProps = createStructuredSelector({
|
||||||
bodyshop: selectBodyshop,
|
bodyshop: selectBodyshop,
|
||||||
@@ -53,7 +54,9 @@ export function TechClockOffButton({
|
|||||||
nextFetchPolicy: "network-only"
|
nextFetchPolicy: "network-only"
|
||||||
});
|
});
|
||||||
const { t } = useTranslation();
|
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) => {
|
const handleFinish = async (values) => {
|
||||||
logImEXEvent("tech_clock_out_job");
|
logImEXEvent("tech_clock_out_job");
|
||||||
@@ -167,10 +170,7 @@ export function TechClockOffButton({
|
|||||||
lineTicketData.jobs_by_pk.lbr_adjustments
|
lineTicketData.jobs_by_pk.lbr_adjustments
|
||||||
);
|
);
|
||||||
|
|
||||||
const fieldTypeToCheck =
|
const fieldTypeToCheck = hasDmsKey ? "mod_lbr_ty" : "cost_center";
|
||||||
bodyshop.cdk_dealerid || bodyshop.pbs_serialnumber || bodyshop.rr_dealerid
|
|
||||||
? "mod_lbr_ty"
|
|
||||||
: "cost_center";
|
|
||||||
|
|
||||||
const costCenterDiff =
|
const costCenterDiff =
|
||||||
Math.round(
|
Math.round(
|
||||||
@@ -210,7 +210,7 @@ export function TechClockOffButton({
|
|||||||
<Select.Option key={item.cost_center}>
|
<Select.Option key={item.cost_center}>
|
||||||
{item.cost_center === "timetickets.labels.shift"
|
{item.cost_center === "timetickets.labels.shift"
|
||||||
? t(item.cost_center)
|
? t(item.cost_center)
|
||||||
: bodyshop.cdk_dealerid || bodyshop.pbs_serialnumber || bodyshop.rr_dealerid
|
: hasDmsKey
|
||||||
? t(`joblines.fields.lbr_types.${item.cost_center.toUpperCase()}`)
|
? t(`joblines.fields.lbr_types.${item.cost_center.toUpperCase()}`)
|
||||||
: item.cost_center}
|
: item.cost_center}
|
||||||
</Select.Option>
|
</Select.Option>
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import {
|
|||||||
import JobSearchSelect from "../job-search-select/job-search-select.component";
|
import JobSearchSelect from "../job-search-select/job-search-select.component";
|
||||||
import LaborAllocationsTable from "../labor-allocations-table/labor-allocations-table.component";
|
import LaborAllocationsTable from "../labor-allocations-table/labor-allocations-table.component";
|
||||||
import { CalculateAllocationsTotals } from "../labor-allocations-table/labor-allocations-table.utility";
|
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 LayoutFormRow from "../layout-form-row/layout-form-row.component";
|
||||||
import LoadingSkeleton from "../loading-skeleton/loading-skeleton.component";
|
import LoadingSkeleton from "../loading-skeleton/loading-skeleton.component";
|
||||||
import { HasRbacAccess } from "../rbac-wrapper/rbac-wrapper.component";
|
import { HasRbacAccess } from "../rbac-wrapper/rbac-wrapper.component";
|
||||||
@@ -127,7 +128,7 @@ export function TimeTicketModalComponent({
|
|||||||
onSelect={(value) => {
|
onSelect={(value) => {
|
||||||
const emps = employeeAutoCompleteOptions && employeeAutoCompleteOptions.filter((e) => e.id === value)[0];
|
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>
|
</Form.Item>
|
||||||
@@ -189,10 +190,7 @@ export function TimeTicketModalComponent({
|
|||||||
lineTicketData.jobs_by_pk.lbr_adjustments
|
lineTicketData.jobs_by_pk.lbr_adjustments
|
||||||
);
|
);
|
||||||
|
|
||||||
const fieldTypeToCheck =
|
const fieldTypeToCheck = bodyshopHasDmsKey(bodyshop) ? "mod_lbr_ty" : "cost_center";
|
||||||
bodyshop.cdk_dealerid || bodyshop.pbs_serialnumber || bodyshop.rr_dealerid
|
|
||||||
? "mod_lbr_ty"
|
|
||||||
: "cost_center";
|
|
||||||
|
|
||||||
const costCenterDiff =
|
const costCenterDiff =
|
||||||
Math.round(
|
Math.round(
|
||||||
@@ -266,7 +264,7 @@ export function TimeTicketModalComponent({
|
|||||||
if (!value) return Promise.resolve();
|
if (!value) return Promise.resolve();
|
||||||
if (!clockon && value) return Promise.reject(t("timetickets.validation.clockoffwithoutclockon"));
|
if (!clockon && value) return Promise.reject(t("timetickets.validation.clockoffwithoutclockon"));
|
||||||
// TODO - Verify this exists
|
// 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.reject(t("timetickets.validation.clockoffmustbeafterclockon"));
|
||||||
|
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import FeatureWrapperComponent from "../../components/feature-wrapper/feature-wr
|
|||||||
import InstanceRenderManager from "../../utils/instanceRenderMgr";
|
import InstanceRenderManager from "../../utils/instanceRenderMgr";
|
||||||
import UpsellComponent, { upsellEnum } from "../../components/upsell/upsell.component";
|
import UpsellComponent, { upsellEnum } from "../../components/upsell/upsell.component";
|
||||||
import { Card } from "antd";
|
import { Card } from "antd";
|
||||||
|
import { bodyshopHasDmsKey } from "../../utils/dmsUtils.js";
|
||||||
|
|
||||||
const mapStateToProps = createStructuredSelector({
|
const mapStateToProps = createStructuredSelector({
|
||||||
bodyshop: selectBodyshop,
|
bodyshop: selectBodyshop,
|
||||||
@@ -54,11 +55,7 @@ export function AccountingPayablesContainer({ bodyshop, setBreadcrumbs, setSelec
|
|||||||
if (error) return <AlertComponent message={error.message} type="error" />;
|
if (error) return <AlertComponent message={error.message} type="error" />;
|
||||||
|
|
||||||
const noPath =
|
const noPath =
|
||||||
!partnerVersion?.qbpath &&
|
!partnerVersion?.qbpath && !(bodyshop && (bodyshopHasDmsKey(bodyshop) || bodyshop?.accountingconfig?.qbo));
|
||||||
!(
|
|
||||||
bodyshop &&
|
|
||||||
(bodyshop.cdk_dealerid || bodyshop.pbs_serialnumber || bodyshop.rr_dealerid || bodyshop.accountingconfig.qbo)
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import FeatureWrapperComponent from "../../components/feature-wrapper/feature-wr
|
|||||||
import InstanceRenderManager from "../../utils/instanceRenderMgr";
|
import InstanceRenderManager from "../../utils/instanceRenderMgr";
|
||||||
import UpsellComponent, { upsellEnum } from "../../components/upsell/upsell.component";
|
import UpsellComponent, { upsellEnum } from "../../components/upsell/upsell.component";
|
||||||
import { Card } from "antd";
|
import { Card } from "antd";
|
||||||
|
import { bodyshopHasDmsKey } from "../../utils/dmsUtils.js";
|
||||||
|
|
||||||
const mapStateToProps = createStructuredSelector({
|
const mapStateToProps = createStructuredSelector({
|
||||||
bodyshop: selectBodyshop,
|
bodyshop: selectBodyshop,
|
||||||
@@ -52,12 +53,10 @@ export function AccountingPaymentsContainer({ bodyshop, setBreadcrumbs, setSelec
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (error) return <AlertComponent message={error.message} type="error" />;
|
if (error) return <AlertComponent message={error.message} type="error" />;
|
||||||
|
|
||||||
const noPath =
|
const noPath =
|
||||||
!partnerVersion?.qbpath &&
|
!partnerVersion?.qbpath && !(bodyshop && (bodyshopHasDmsKey(bodyshop) || bodyshop?.accountingconfig?.qbo));
|
||||||
!(
|
|
||||||
bodyshop &&
|
|
||||||
(bodyshop.cdk_dealerid || bodyshop.pbs_serialnumber || bodyshop.rr_dealerid || bodyshop.accountingconfig.qbo)
|
|
||||||
);
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<FeatureWrapperComponent
|
<FeatureWrapperComponent
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import FeatureWrapperComponent from "../../components/feature-wrapper/feature-wr
|
|||||||
import InstanceRenderManager from "../../utils/instanceRenderMgr";
|
import InstanceRenderManager from "../../utils/instanceRenderMgr";
|
||||||
import { Card } from "antd";
|
import { Card } from "antd";
|
||||||
import UpsellComponent, { upsellEnum } from "../../components/upsell/upsell.component";
|
import UpsellComponent, { upsellEnum } from "../../components/upsell/upsell.component";
|
||||||
|
import { bodyshopHasDmsKey } from "../../utils/dmsUtils.js";
|
||||||
|
|
||||||
const mapStateToProps = createStructuredSelector({
|
const mapStateToProps = createStructuredSelector({
|
||||||
bodyshop: selectBodyshop,
|
bodyshop: selectBodyshop,
|
||||||
@@ -57,11 +58,7 @@ export function AccountingReceivablesContainer({ bodyshop, setBreadcrumbs, setSe
|
|||||||
if (error) return <AlertComponent message={error.message} type="error" />;
|
if (error) return <AlertComponent message={error.message} type="error" />;
|
||||||
|
|
||||||
const noPath =
|
const noPath =
|
||||||
!partnerVersion?.qbpath &&
|
!partnerVersion?.qbpath && !(bodyshop && (bodyshopHasDmsKey(bodyshop) || bodyshop?.accountingconfig?.qbo));
|
||||||
!(
|
|
||||||
bodyshop &&
|
|
||||||
(bodyshop.cdk_dealerid || bodyshop.pbs_serialnumber || bodyshop.rr_dealerid || bodyshop.accountingconfig.qbo)
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
|
|||||||
@@ -90,6 +90,7 @@ export function DmsContainer({ setBreadcrumbs, setSelectedHeader }) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (socket.disconnected) socket.connect();
|
if (socket.disconnected) socket.connect();
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
socket.removeAllListeners();
|
socket.removeAllListeners();
|
||||||
socket.disconnect();
|
socket.disconnect();
|
||||||
@@ -139,7 +140,7 @@ export function DmsContainer({ setBreadcrumbs, setSelectedHeader }) {
|
|||||||
</Space>
|
</Space>
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<DmsLogEvents socket={socket} logs={logs} />
|
<DmsLogEvents logs={logs} />
|
||||||
</Card>
|
</Card>
|
||||||
</div>
|
</div>
|
||||||
</Col>
|
</Col>
|
||||||
|
|||||||
@@ -3,27 +3,23 @@ import { Link, useLocation, useNavigate } from "react-router-dom";
|
|||||||
import { connect } from "react-redux";
|
import { connect } from "react-redux";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { createStructuredSelector } from "reselect";
|
import { createStructuredSelector } from "reselect";
|
||||||
import SocketIO from "socket.io-client";
|
|
||||||
import queryString from "query-string";
|
import queryString from "query-string";
|
||||||
import { useQuery } from "@apollo/client";
|
import { useQuery } from "@apollo/client";
|
||||||
import { Button, Card, Col, Result, Row, Select, Space, Switch } from "antd";
|
import { Button, Card, Col, Result, Row, Select, Space, Switch } from "antd";
|
||||||
import { useSplitTreatments } from "@splitsoftware/splitio-react";
|
import { useSplitTreatments } from "@splitsoftware/splitio-react";
|
||||||
|
|
||||||
import { auth } from "../../firebase/firebase.utils";
|
|
||||||
|
|
||||||
import { useSocket } from "../../contexts/SocketIO/useSocket.js";
|
import { useSocket } from "../../contexts/SocketIO/useSocket.js";
|
||||||
import { useNotification } from "../../contexts/Notifications/notificationContext.jsx";
|
import { useNotification } from "../../contexts/Notifications/notificationContext.jsx";
|
||||||
|
|
||||||
import { QUERY_JOB_EXPORT_DMS } from "../../graphql/jobs.queries";
|
import { QUERY_JOB_EXPORT_DMS } from "../../graphql/jobs.queries";
|
||||||
|
|
||||||
import { selectBodyshop } from "../../redux/user/user.selectors";
|
import { selectBodyshop } from "../../redux/user/user.selectors";
|
||||||
import { insertAuditTrail, setBreadcrumbs, setSelectedHeader } from "../../redux/application/application.actions";
|
import { insertAuditTrail, setBreadcrumbs, setSelectedHeader } from "../../redux/application/application.actions";
|
||||||
|
|
||||||
import InstanceRenderManager from "../../utils/instanceRenderMgr";
|
import InstanceRenderManager from "../../utils/instanceRenderMgr";
|
||||||
import AuditTrailMapping from "../../utils/AuditTrailMappings";
|
import AuditTrailMapping from "../../utils/AuditTrailMappings";
|
||||||
import { determineDmsType } from "../../utils/determineDmsType";
|
import { bodyshopHasDmsKey, DMS_MAP, getDmsMode, isWssMode } from "../../utils/dmsUtils.js";
|
||||||
import { OwnerNameDisplayFunction } from "../../components/owner-name-display/owner-name-display.component";
|
import legacySocket from "../../utils/legacySocket";
|
||||||
|
|
||||||
|
import { OwnerNameDisplayFunction } from "../../components/owner-name-display/owner-name-display.component";
|
||||||
import AlertComponent from "../../components/alert/alert.component";
|
import AlertComponent from "../../components/alert/alert.component";
|
||||||
import LoadingSpinner from "../../components/loading-spinner/loading-spinner.component";
|
import LoadingSpinner from "../../components/loading-spinner/loading-spinner.component";
|
||||||
import DmsPostForm from "../../components/dms-post-form/dms-post-form.component";
|
import DmsPostForm from "../../components/dms-post-form/dms-post-form.component";
|
||||||
@@ -43,30 +39,37 @@ const mapDispatchToProps = (dispatch) => ({
|
|||||||
|
|
||||||
export default connect(mapStateToProps, mapDispatchToProps)(DmsContainer);
|
export default connect(mapStateToProps, mapDispatchToProps)(DmsContainer);
|
||||||
|
|
||||||
// Legacy /ws socket (CDK/PBS)
|
const DMS_SOCKET_EVENTS = {
|
||||||
export const socket = SocketIO(import.meta.env.PROD ? import.meta.env.VITE_APP_AXIOS_BASE_API_URL : "", {
|
[DMS_MAP.reynolds]: {
|
||||||
path: "/ws",
|
log: "rr-log-event",
|
||||||
withCredentials: true,
|
partialResult: "rr-export-job:result",
|
||||||
auth: async (callback) => {
|
cashierNeeded: "rr-cashiering-required",
|
||||||
const token = auth.currentUser && (await auth.currentUser.getIdToken());
|
exportSuccess: "export-success",
|
||||||
callback({ token });
|
exportFailed: "export-failed"
|
||||||
|
},
|
||||||
|
[DMS_MAP.fortellis]: {
|
||||||
|
log: "fortellis-log-event",
|
||||||
|
exportSuccess: "export-success",
|
||||||
|
exportFailed: "export-failed"
|
||||||
|
},
|
||||||
|
[DMS_MAP.cdk]: {
|
||||||
|
log: "log-event",
|
||||||
|
exportSuccess: "export-success",
|
||||||
|
exportFailed: "export-failed"
|
||||||
|
},
|
||||||
|
[DMS_MAP.pbs]: {
|
||||||
|
log: "log-event",
|
||||||
|
exportSuccess: "export-success",
|
||||||
|
exportFailed: "export-failed"
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
|
||||||
export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader, insertAuditTrail }) {
|
export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader, insertAuditTrail }) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const dms = determineDmsType(bodyshop);
|
|
||||||
|
|
||||||
const history = useNavigate();
|
const history = useNavigate();
|
||||||
const search = queryString.parse(useLocation().search);
|
const search = queryString.parse(useLocation().search);
|
||||||
|
|
||||||
const [logLevel, setLogLevel] = useState(dms === "pbs" ? "INFO" : "DEBUG");
|
|
||||||
const [logs, setLogs] = useState([]);
|
|
||||||
const [detailsOpen, setDetailsOpen] = useState(false); // false => button shows "Expand All"
|
|
||||||
const [detailsNonce, setDetailsNonce] = useState(0); // forces child to react to toggles
|
|
||||||
const [colorizeJson, setColorizeJson] = useState(false); // default: OFF
|
|
||||||
|
|
||||||
const { jobId } = search;
|
const { jobId } = search;
|
||||||
|
|
||||||
const notification = useNotification();
|
const notification = useNotification();
|
||||||
|
|
||||||
const {
|
const {
|
||||||
@@ -77,11 +80,31 @@ export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader, inse
|
|||||||
splitKey: bodyshop.imexshopid
|
splitKey: bodyshop.imexshopid
|
||||||
});
|
});
|
||||||
|
|
||||||
// New unified wss socket (Fortellis, RR)
|
// Compute a single normalized mode and pick the proper socket
|
||||||
|
const mode = getDmsMode(bodyshop, Fortellis.treatment); // "rr" | "fortellis" | "cdk" | "pbs" | "none"
|
||||||
|
|
||||||
const { socket: wsssocket } = useSocket();
|
const { socket: wsssocket } = useSocket();
|
||||||
const activeSocket = useMemo(() => {
|
const activeSocket = useMemo(() => (isWssMode(mode) ? wsssocket : legacySocket), [mode, wsssocket]);
|
||||||
return dms === "rr" || (dms === "cdk" && Fortellis.treatment === "on") ? wsssocket : socket;
|
|
||||||
}, [dms, Fortellis.treatment, wsssocket, socket]);
|
const [isConnected, setIsConnected] = useState(!!activeSocket?.connected);
|
||||||
|
|
||||||
|
// One place to set log level
|
||||||
|
const [logLevel, setLogLevel] = useState(mode === DMS_MAP.pbs ? "INFO" : "DEBUG");
|
||||||
|
|
||||||
|
const setActiveLogLevel = (level) => {
|
||||||
|
if (!activeSocket) return;
|
||||||
|
activeSocket.emit("set-log-level", level);
|
||||||
|
};
|
||||||
|
|
||||||
|
const [logs, setLogs] = useState([]);
|
||||||
|
const [detailsOpen, setDetailsOpen] = useState(false);
|
||||||
|
const [detailsNonce, setDetailsNonce] = useState(0);
|
||||||
|
const [colorizeJson, setColorizeJson] = useState(false);
|
||||||
|
|
||||||
|
const [rrOpenRoLimit, setRrOpenRoLimit] = useState(false);
|
||||||
|
const clearRrOpenRoLimit = () => setRrOpenRoLimit(false);
|
||||||
|
|
||||||
|
const [rrCashierPending, setRrCashierPending] = useState(false);
|
||||||
|
|
||||||
const { loading, error, data } = useQuery(QUERY_JOB_EXPORT_DMS, {
|
const { loading, error, data } = useQuery(QUERY_JOB_EXPORT_DMS, {
|
||||||
variables: { id: jobId },
|
variables: { id: jobId },
|
||||||
@@ -97,45 +120,51 @@ export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader, inse
|
|||||||
setDetailsNonce((n) => n + 1);
|
setDetailsNonce((n) => n + 1);
|
||||||
};
|
};
|
||||||
|
|
||||||
const [rrOpenRoLimit, setRrOpenRoLimit] = useState(false);
|
// Channel names per mode to avoid branching everywhere
|
||||||
const clearRrOpenRoLimit = () => setRrOpenRoLimit(false);
|
const channels = useMemo(() => DMS_SOCKET_EVENTS[mode] || {}, [mode]);
|
||||||
|
|
||||||
// NEW: RR “cashiering required” UX hold
|
const providerLabel = useMemo(
|
||||||
const [rrCashierPending, setRrCashierPending] = useState(false);
|
() =>
|
||||||
|
({
|
||||||
|
[DMS_MAP.reynolds]: "Reynolds",
|
||||||
|
[DMS_MAP.fortellis]: "Fortellis",
|
||||||
|
[DMS_MAP.cdk]: "CDK",
|
||||||
|
[DMS_MAP.pbs]: "PBS"
|
||||||
|
})[mode] || "DMS",
|
||||||
|
[mode]
|
||||||
|
);
|
||||||
|
|
||||||
|
const transportLabel = isWssMode(mode) ? "App Socket (WSS)" : "Legacy Socket (WS)";
|
||||||
|
|
||||||
|
const bannerMessage = `Posting to ${providerLabel} | ${transportLabel} | ${
|
||||||
|
isConnected ? "Connected" : "Disconnected"
|
||||||
|
}`;
|
||||||
|
|
||||||
const handleExportFailed = (payload = {}) => {
|
const handleExportFailed = (payload = {}) => {
|
||||||
const { title, friendlyMessage, error, severity, errorCode, vendorStatusCode } = payload;
|
const { title, friendlyMessage, error: errText, severity, errorCode, vendorStatusCode } = payload;
|
||||||
|
|
||||||
const msg =
|
const msg =
|
||||||
friendlyMessage ||
|
friendlyMessage ||
|
||||||
error ||
|
errText ||
|
||||||
t("dms.errors.exportfailedgeneric", "We couldn't complete the export. Please try again.");
|
t("dms.errors.exportfailedgeneric", "We couldn't complete the export. Please try again.");
|
||||||
|
|
||||||
const vendorTitle = title || (dms === "rr" ? "Reynolds" : "DMS");
|
const vendorTitle = title || (mode === DMS_MAP.reynolds ? "Reynolds" : "DMS");
|
||||||
|
|
||||||
// Detect the specific RR “max open ROs” case
|
|
||||||
const isRrOpenRoLimit =
|
const isRrOpenRoLimit =
|
||||||
dms === "rr" &&
|
mode === DMS_MAP.reynolds &&
|
||||||
(vendorStatusCode === 507 ||
|
(vendorStatusCode === 507 ||
|
||||||
/MAX_OPEN_ROS/i.test(String(errorCode || "")) ||
|
/MAX_OPEN_ROS/i.test(String(errorCode || "")) ||
|
||||||
/maximum number of open repair orders/i.test(String(msg || "").toLowerCase()));
|
/maximum number of open repair orders/i.test(String(msg || "").toLowerCase()));
|
||||||
|
|
||||||
// Soft/warn default for known cases
|
|
||||||
const sev = severity || (isRrOpenRoLimit ? "warning" : "error");
|
const sev = severity || (isRrOpenRoLimit ? "warning" : "error");
|
||||||
|
|
||||||
// Show toast for *other* failures; for the open RO limit, switch to blocking banner UX instead.
|
|
||||||
if (!isRrOpenRoLimit) {
|
if (!isRrOpenRoLimit) {
|
||||||
const notifyKind = sev === "warning" && typeof notification.warning === "function" ? "warning" : "error";
|
const notifyKind = sev === "warning" && typeof notification.warning === "function" ? "warning" : "error";
|
||||||
notification[notifyKind]({
|
notification[notifyKind]({ message: vendorTitle, description: msg, duration: 10 });
|
||||||
message: vendorTitle,
|
|
||||||
description: msg,
|
|
||||||
duration: 10
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
setRrOpenRoLimit(true);
|
setRrOpenRoLimit(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mirror to the on-screen log card
|
|
||||||
setLogs((prev) => [
|
setLogs((prev) => [
|
||||||
...prev,
|
...prev,
|
||||||
{
|
{
|
||||||
@@ -147,254 +176,218 @@ export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader, inse
|
|||||||
]);
|
]);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// keep this in sync if mode/socket flips
|
||||||
|
useEffect(() => {
|
||||||
|
setIsConnected(!!activeSocket?.connected);
|
||||||
|
}, [activeSocket]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
document.title = t("titles.dms", {
|
document.title = t("titles.dms", {
|
||||||
app: InstanceRenderManager({
|
app: InstanceRenderManager({ imex: "$t(titles.imexonline)", rome: "$t(titles.romeonline)" })
|
||||||
imex: "$t(titles.imexonline)",
|
|
||||||
rome: "$t(titles.romeonline)"
|
|
||||||
})
|
|
||||||
});
|
});
|
||||||
setSelectedHeader("dms");
|
setSelectedHeader("dms");
|
||||||
setBreadcrumbs([
|
setBreadcrumbs([
|
||||||
{
|
{ link: "/manage/accounting/receivables", label: t("titles.bc.accounting-receivables") },
|
||||||
link: "/manage/accounting/receivables",
|
{ link: "/manage/dms", label: t("titles.bc.dms") }
|
||||||
label: t("titles.bc.accounting-receivables")
|
|
||||||
},
|
|
||||||
{
|
|
||||||
link: "/manage/dms",
|
|
||||||
label: t("titles.bc.dms")
|
|
||||||
}
|
|
||||||
]);
|
]);
|
||||||
}, [t, setBreadcrumbs, setSelectedHeader]);
|
}, [t, setBreadcrumbs, setSelectedHeader]);
|
||||||
|
|
||||||
|
// Socket wiring (mode-aware)
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// ✅ RR path uses WSS and has two-step flow
|
if (!activeSocket) return;
|
||||||
if (dms === "rr") {
|
|
||||||
// set log level on connect and immediately
|
|
||||||
wsssocket.emit("set-log-level", logLevel);
|
|
||||||
|
|
||||||
const handleConnect = () => wsssocket.emit("set-log-level", logLevel);
|
// Connect legacy socket if needed
|
||||||
const handleReconnect = () =>
|
if (!isWssMode(mode)) {
|
||||||
setLogs((prev) => [
|
if (activeSocket.disconnected) activeSocket.connect();
|
||||||
...prev,
|
|
||||||
{ timestamp: new Date(), level: "warn", message: "Reconnected to RR Export Service" }
|
|
||||||
]);
|
|
||||||
const handleConnectError = (err) => {
|
|
||||||
console.log(`connect_error due to ${err}`, err);
|
|
||||||
notification.error({ message: err.message });
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleLogEvent = (payload = {}) => {
|
|
||||||
const normalized = {
|
|
||||||
timestamp: payload.timestamp ? new Date(payload.timestamp) : payload.ts ? new Date(payload.ts) : new Date(),
|
|
||||||
level: (payload.level || "INFO").toUpperCase(),
|
|
||||||
message: payload.message || payload.msg || "",
|
|
||||||
// show details regardless of property name
|
|
||||||
meta: payload.meta ?? payload.ctx ?? payload.details ?? null
|
|
||||||
};
|
|
||||||
setLogs((prev) => [...prev, normalized]);
|
|
||||||
};
|
|
||||||
|
|
||||||
// FINAL step only (emitted by server after rr-finalize-repair-order)
|
|
||||||
const handleExportSuccess = (payload) => {
|
|
||||||
const jobId = payload?.jobId ?? payload; // RR sends object; legacy sends raw id
|
|
||||||
notification.success({ message: t("jobs.successes.exported") });
|
|
||||||
setRrCashierPending(false);
|
|
||||||
insertAuditTrail({
|
|
||||||
jobid: jobId,
|
|
||||||
operation: AuditTrailMapping.jobexported(),
|
|
||||||
type: "jobexported"
|
|
||||||
});
|
|
||||||
history("/manage/accounting/receivables");
|
|
||||||
};
|
|
||||||
|
|
||||||
// STEP 1 result (RO created) – DO NOT navigate; wait for cashiering
|
|
||||||
const handleRrExportResult = () => {
|
|
||||||
// Be defensive: if the server didn't already set the banner yet, make it obvious
|
|
||||||
setRrCashierPending(true);
|
|
||||||
setLogs((prev) => [
|
|
||||||
...prev,
|
|
||||||
{
|
|
||||||
timestamp: new Date(),
|
|
||||||
level: "INFO",
|
|
||||||
message:
|
|
||||||
"Repair Order created in Reynolds. Complete cashiering in Reynolds, then click Finished/Close to finalize."
|
|
||||||
}
|
|
||||||
]);
|
|
||||||
notification.info({
|
|
||||||
message: "Reynolds RO created",
|
|
||||||
description:
|
|
||||||
"Complete cashiering in Reynolds, then click Finished/Close to finalize and mark this export complete.",
|
|
||||||
duration: 8
|
|
||||||
});
|
|
||||||
// No routing here — we remain on the page for step 2
|
|
||||||
};
|
|
||||||
|
|
||||||
// NEW: cashier step required (after create, before finalize)
|
|
||||||
const handleCashieringRequired = (payload) => {
|
|
||||||
setRrCashierPending(true);
|
|
||||||
setLogs((prev) => [
|
|
||||||
...prev,
|
|
||||||
{
|
|
||||||
timestamp: new Date(),
|
|
||||||
level: "INFO",
|
|
||||||
message:
|
|
||||||
"Repair Order created in Reynolds. Complete cashiering in Reynolds, then click Finished/Close to finalize.",
|
|
||||||
meta: { payload }
|
|
||||||
}
|
|
||||||
]);
|
|
||||||
};
|
|
||||||
|
|
||||||
wsssocket.on("connect", handleConnect);
|
|
||||||
wsssocket.on("reconnect", handleReconnect);
|
|
||||||
wsssocket.on("connect_error", handleConnectError);
|
|
||||||
|
|
||||||
// RR channels (over wss)
|
|
||||||
wsssocket.on("rr-log-event", handleLogEvent);
|
|
||||||
wsssocket.on("rr-export-job:result", handleRrExportResult);
|
|
||||||
|
|
||||||
wsssocket.on("export-success", handleExportSuccess);
|
|
||||||
wsssocket.on("export-failed", handleExportFailed);
|
|
||||||
|
|
||||||
// NEW
|
|
||||||
wsssocket.on("rr-cashiering-required", handleCashieringRequired);
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
wsssocket.off("connect", handleConnect);
|
|
||||||
wsssocket.off("reconnect", handleReconnect);
|
|
||||||
wsssocket.off("connect_error", handleConnectError);
|
|
||||||
|
|
||||||
wsssocket.off("rr-log-event", handleLogEvent);
|
|
||||||
wsssocket.off("rr-export-job:result", handleRrExportResult);
|
|
||||||
|
|
||||||
wsssocket.off("export-success", handleExportSuccess);
|
|
||||||
wsssocket.off("export-failed", handleExportFailed);
|
|
||||||
|
|
||||||
wsssocket.off("rr-cashiering-required", handleCashieringRequired);
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fortellis / CDK behavior (when not RR)
|
// Set log level now and on connect/reconnect
|
||||||
if (Fortellis.treatment === "on") {
|
setActiveLogLevel(logLevel);
|
||||||
wsssocket.emit("set-log-level", logLevel);
|
|
||||||
|
|
||||||
const handleLogEvent = (payload) => setLogs((prev) => [...prev, payload]);
|
const onConnect = () => {
|
||||||
const handleExportSuccess = (payload) => {
|
setIsConnected(true);
|
||||||
notification.success({ message: t("jobs.successes.exported") });
|
setActiveLogLevel(logLevel);
|
||||||
insertAuditTrail({
|
};
|
||||||
jobid: payload,
|
|
||||||
operation: AuditTrailMapping.jobexported(),
|
|
||||||
type: "jobexported"
|
|
||||||
});
|
|
||||||
history("/manage/accounting/receivables");
|
|
||||||
};
|
|
||||||
|
|
||||||
// Fortellis logs (wss)
|
const onDisconnect = () => setIsConnected(false);
|
||||||
wsssocket.on("fortellis-log-event", handleLogEvent);
|
|
||||||
wsssocket.on("export-success", handleExportSuccess);
|
|
||||||
wsssocket.on("export-failed", handleExportFailed);
|
|
||||||
|
|
||||||
return () => {
|
const onReconnect = () => {
|
||||||
wsssocket.off("fortellis-log-event", handleLogEvent);
|
setIsConnected(true);
|
||||||
wsssocket.off("export-success", handleExportSuccess);
|
setLogs((prev) => [
|
||||||
wsssocket.off("export-failed", handleExportFailed);
|
...prev,
|
||||||
};
|
{
|
||||||
} else {
|
timestamp: new Date(),
|
||||||
// CDK/PBS via legacy /ws socket
|
level: "warn",
|
||||||
socket.on("export-failed", handleExportFailed);
|
message: `Reconnected to ${mode === DMS_MAP.reynolds ? "RR" : mode === DMS_MAP.fortellis ? "Fortellis" : "DMS"} Export Service`
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
};
|
||||||
|
|
||||||
socket.on("connect", () => socket.emit("set-log-level", logLevel));
|
const onConnectError = (err) => {
|
||||||
socket.on("reconnect", () => {
|
// Legacy and WSS both emit this
|
||||||
setLogs((prev) => [
|
console.log(`connect_error due to ${err}`, err);
|
||||||
...prev,
|
notification.error({ message: err.message });
|
||||||
{ timestamp: new Date(), level: "warn", message: "Reconnected to CDK Export Service" }
|
};
|
||||||
]);
|
|
||||||
});
|
activeSocket.on("disconnect", onDisconnect);
|
||||||
socket.on("connect_error", (err) => {
|
activeSocket.on("connect", onConnect);
|
||||||
console.log(`connect_error due to ${err}`, err);
|
activeSocket.on("reconnect", onReconnect);
|
||||||
notification.error({ message: err.message });
|
activeSocket.on("connect_error", onConnectError);
|
||||||
});
|
|
||||||
socket.on("log-event", (payload) => setLogs((prev) => [...prev, payload]));
|
// Logs
|
||||||
socket.on("export-success", (payload) => {
|
const onLog =
|
||||||
notification.success({ message: t("jobs.successes.exported") });
|
mode === DMS_MAP.reynolds
|
||||||
insertAuditTrail({
|
? (payload = {}) => {
|
||||||
jobid: payload,
|
const normalized = {
|
||||||
operation: AuditTrailMapping.jobexported(),
|
timestamp: payload.timestamp
|
||||||
type: "jobexported"
|
? new Date(payload.timestamp)
|
||||||
});
|
: payload.ts
|
||||||
history("/manage/accounting/receivables");
|
? new Date(payload.ts)
|
||||||
|
: new Date(),
|
||||||
|
level: (payload.level || "INFO").toUpperCase(),
|
||||||
|
message: payload.message || payload.msg || "",
|
||||||
|
meta: payload.meta ?? payload.ctx ?? payload.details ?? null
|
||||||
|
};
|
||||||
|
setLogs((prev) => [...prev, normalized]);
|
||||||
|
}
|
||||||
|
: (payload) => setLogs((prev) => [...prev, payload]);
|
||||||
|
|
||||||
|
if (channels.log) activeSocket.on(channels.log, onLog);
|
||||||
|
|
||||||
|
// Success / Failed
|
||||||
|
const onExportSuccess = (payload) => {
|
||||||
|
const jobIdResolved = payload?.jobId ?? payload;
|
||||||
|
notification.success({ message: t("jobs.successes.exported") });
|
||||||
|
|
||||||
|
// Clear RR cashier flag if any
|
||||||
|
setRrCashierPending(false);
|
||||||
|
|
||||||
|
insertAuditTrail({
|
||||||
|
jobid: jobIdResolved,
|
||||||
|
operation: AuditTrailMapping.jobexported(),
|
||||||
|
type: "jobexported"
|
||||||
});
|
});
|
||||||
|
history("/manage/accounting/receivables");
|
||||||
|
};
|
||||||
|
|
||||||
if (socket.disconnected) socket.connect();
|
if (channels.exportSuccess) activeSocket.on(channels.exportSuccess, onExportSuccess);
|
||||||
return () => {
|
if (channels.exportFailed) activeSocket.on(channels.exportFailed, handleExportFailed);
|
||||||
socket.removeAllListeners();
|
|
||||||
socket.disconnect();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}, [dms, Fortellis?.treatment, logLevel, history, insertAuditTrail, notification, t, wsssocket]);
|
|
||||||
|
|
||||||
// NEW: finalize button callback—emit finalize event
|
// RR-only extras
|
||||||
|
|
||||||
|
const onPartialResult = () => {
|
||||||
|
setRrCashierPending(true);
|
||||||
|
setLogs((prev) => [
|
||||||
|
...prev,
|
||||||
|
{
|
||||||
|
timestamp: new Date(),
|
||||||
|
level: "INFO",
|
||||||
|
message:
|
||||||
|
"Repair Order created in Reynolds. Complete cashiering in Reynolds, then click Finished/Close to finalize."
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
notification.info({
|
||||||
|
message: "Reynolds RO created",
|
||||||
|
description:
|
||||||
|
"Complete cashiering in Reynolds, then click Finished/Close to finalize and mark this export complete.",
|
||||||
|
duration: 8
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const onCashierRequired = (payload) => {
|
||||||
|
setRrCashierPending(true);
|
||||||
|
setLogs((prev) => [
|
||||||
|
...prev,
|
||||||
|
{
|
||||||
|
timestamp: new Date(),
|
||||||
|
level: "INFO",
|
||||||
|
message:
|
||||||
|
"Repair Order created in Reynolds. Complete cashiering in Reynolds, then click Finished/Close to finalize.",
|
||||||
|
meta: { payload }
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
};
|
||||||
|
|
||||||
|
if (mode === DMS_MAP.reynolds && channels.partialResult) activeSocket.on(channels.partialResult, onPartialResult);
|
||||||
|
if (mode === DMS_MAP.reynolds && channels.cashierNeeded) activeSocket.on(channels.cashierNeeded, onCashierRequired);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
activeSocket.off("connect", onConnect);
|
||||||
|
activeSocket.off("reconnect", onReconnect);
|
||||||
|
activeSocket.off("connect_error", onConnectError);
|
||||||
|
activeSocket.off("disconnect", onDisconnect);
|
||||||
|
|
||||||
|
if (channels.log) activeSocket.off(channels.log, onLog);
|
||||||
|
if (channels.exportSuccess) activeSocket.off(channels.exportSuccess, onExportSuccess);
|
||||||
|
if (channels.exportFailed) activeSocket.off(channels.exportFailed, handleExportFailed);
|
||||||
|
|
||||||
|
if (mode === DMS_MAP.reynolds && channels.partialResult)
|
||||||
|
activeSocket.off(channels.partialResult, onPartialResult);
|
||||||
|
if (mode === DMS_MAP.reynolds && channels.cashierNeeded)
|
||||||
|
activeSocket.off(channels.cashierNeeded, onCashierRequired);
|
||||||
|
|
||||||
|
// Only tear down legacy socket listeners; don't disconnect WSS from here
|
||||||
|
if (!isWssMode(mode)) {
|
||||||
|
activeSocket.removeAllListeners();
|
||||||
|
activeSocket.disconnect();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}, [mode, activeSocket, channels, logLevel, notification, t, insertAuditTrail, history]);
|
||||||
|
|
||||||
|
// RR finalize callback (unchanged public behavior)
|
||||||
const handleRrCashierFinished = () => {
|
const handleRrCashierFinished = () => {
|
||||||
if (!jobId) return;
|
if (!jobId) return;
|
||||||
wsssocket.emit("rr-finalize-repair-order", { jobId }, (ack) => {
|
if (!isWssMode(mode)) return; // RR is WSS-only
|
||||||
if (ack?.ok) {
|
activeSocket.emit("rr-finalize-repair-order", { jobId }, (ack) => {
|
||||||
// success path handled by export-success listener
|
if (ack?.ok) return;
|
||||||
return;
|
if (ack?.error) notification.error({ message: ack.error });
|
||||||
}
|
|
||||||
if (ack?.error) {
|
|
||||||
notification.error({ message: ack.error });
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
if (loading) return <LoadingSpinner />;
|
if (loading) return <LoadingSpinner />;
|
||||||
if (error) return <AlertComponent message={error.message} type="error" />;
|
if (error) return <AlertComponent message={error.message} type="error" />;
|
||||||
|
|
||||||
if (!jobId || !(bodyshop.cdk_dealerid || bodyshop.pbs_serialnumber || bodyshop.rr_dealerid) || !data?.jobs_by_pk)
|
if (!jobId || !bodyshopHasDmsKey(bodyshop) || !data?.jobs_by_pk)
|
||||||
return <Result status="404" title={t("general.errors.notfound")} />;
|
return <Result status="404" title={t("general.errors.notfound")} />;
|
||||||
|
|
||||||
if (data.jobs_by_pk?.date_exported) return <Result status="warning" title={t("dms.errors.alreadyexported")} />;
|
if (data.jobs_by_pk?.date_exported) return <Result status="warning" title={t("dms.errors.alreadyexported")} />;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<AlertComponent
|
<AlertComponent style={{ marginBottom: 10 }} message={bannerMessage} type="warning" showIcon closable />
|
||||||
style={{ marginBottom: 10 }}
|
|
||||||
message={`Posting to ${determineDmsType(bodyshop)}`}
|
|
||||||
type="warning"
|
|
||||||
showIcon
|
|
||||||
closable
|
|
||||||
/>
|
|
||||||
|
|
||||||
<Row gutter={[16, 16]}>
|
<Row gutter={[16, 16]}>
|
||||||
<Col md={24} lg={10}>
|
<Col md={24} lg={10}>
|
||||||
<DmsAllocationsSummary
|
<DmsAllocationsSummary
|
||||||
title={
|
title={
|
||||||
<span>
|
<span>
|
||||||
<Link to={`/manage/jobs/${data && data.jobs_by_pk.id}`}>{`${
|
<Link
|
||||||
data?.jobs_by_pk && data.jobs_by_pk.ro_number
|
to={`/manage/jobs/${data && data.jobs_by_pk.id}`}
|
||||||
}`}</Link>
|
>{`${data?.jobs_by_pk && data.jobs_by_pk.ro_number}`}</Link>
|
||||||
{` | ${OwnerNameDisplayFunction(data.jobs_by_pk)} | ${
|
{` | ${OwnerNameDisplayFunction(data.jobs_by_pk)} | ${data.jobs_by_pk.v_model_yr || ""} ${data.jobs_by_pk.v_make_desc || ""} ${data.jobs_by_pk.v_model_desc || ""}`}
|
||||||
data.jobs_by_pk.v_model_yr || ""
|
|
||||||
} ${data.jobs_by_pk.v_make_desc || ""} ${data.jobs_by_pk.v_model_desc || ""}`}
|
|
||||||
</span>
|
</span>
|
||||||
}
|
}
|
||||||
socket={activeSocket}
|
socket={activeSocket}
|
||||||
jobId={jobId}
|
jobId={jobId}
|
||||||
|
mode={mode}
|
||||||
/>
|
/>
|
||||||
</Col>
|
</Col>
|
||||||
|
|
||||||
<Col md={24} lg={14}>
|
<Col md={24} lg={14}>
|
||||||
<DmsPostForm socket={activeSocket} job={data?.jobs_by_pk} logsRef={logsRef} />
|
<DmsPostForm socket={activeSocket} job={data?.jobs_by_pk} logsRef={logsRef} mode={mode} />
|
||||||
</Col>
|
</Col>
|
||||||
|
|
||||||
{/* NEW props for two-step RR flow banners */}
|
|
||||||
<DmsCustomerSelector
|
<DmsCustomerSelector
|
||||||
jobid={jobId}
|
jobid={jobId}
|
||||||
rrOpenRoLimit={rrOpenRoLimit}
|
|
||||||
onRrOpenRoFinished={clearRrOpenRoLimit}
|
|
||||||
rrCashierPending={rrCashierPending}
|
|
||||||
onRrCashierFinished={handleRrCashierFinished}
|
|
||||||
bodyshop={bodyshop}
|
bodyshop={bodyshop}
|
||||||
|
socket={activeSocket}
|
||||||
|
mode={mode}
|
||||||
|
rrOptions={{
|
||||||
|
openRoLimit: rrOpenRoLimit,
|
||||||
|
onOpenRoFinished: clearRrOpenRoLimit,
|
||||||
|
cashierPending: rrCashierPending,
|
||||||
|
onCashierFinished: handleRrCashierFinished
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Col span={24}>
|
<Col span={24}>
|
||||||
@@ -415,11 +408,7 @@ export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader, inse
|
|||||||
value={logLevel}
|
value={logLevel}
|
||||||
onChange={(value) => {
|
onChange={(value) => {
|
||||||
setLogLevel(value);
|
setLogLevel(value);
|
||||||
if (dms === "rr" || Fortellis.treatment === "on") {
|
setActiveLogLevel(value);
|
||||||
wsssocket.emit("set-log-level", value);
|
|
||||||
} else {
|
|
||||||
socket.emit("set-log-level", value);
|
|
||||||
}
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Select.Option key="DEBUG">DEBUG</Select.Option>
|
<Select.Option key="DEBUG">DEBUG</Select.Option>
|
||||||
@@ -431,11 +420,11 @@ export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader, inse
|
|||||||
<Button
|
<Button
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setLogs([]);
|
setLogs([]);
|
||||||
if (dms === "rr" || Fortellis.treatment === "on") {
|
if (isWssMode(mode)) {
|
||||||
wsssocket.emit("set-log-level", logLevel);
|
setActiveLogLevel(logLevel);
|
||||||
} else {
|
} else {
|
||||||
socket.disconnect();
|
activeSocket.disconnect();
|
||||||
socket.connect();
|
activeSocket.connect();
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
@@ -445,7 +434,6 @@ export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader, inse
|
|||||||
}
|
}
|
||||||
>
|
>
|
||||||
<DmsLogEvents
|
<DmsLogEvents
|
||||||
socket={socket}
|
|
||||||
logs={logs}
|
logs={logs}
|
||||||
detailsOpen={detailsOpen}
|
detailsOpen={detailsOpen}
|
||||||
detailsNonce={detailsNonce}
|
detailsNonce={detailsNonce}
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ import { setModalContext } from "../../redux/modals/modals.actions.js";
|
|||||||
import { selectBodyshop, selectCurrentUser } from "../../redux/user/user.selectors";
|
import { selectBodyshop, selectCurrentUser } from "../../redux/user/user.selectors";
|
||||||
import AuditTrailMapping from "../../utils/AuditTrailMappings";
|
import AuditTrailMapping from "../../utils/AuditTrailMappings";
|
||||||
import dayjs from "../../utils/day";
|
import dayjs from "../../utils/day";
|
||||||
|
import { bodyshopHasDmsKey } from "../../utils/dmsUtils.js";
|
||||||
|
|
||||||
const mapStateToProps = createStructuredSelector({
|
const mapStateToProps = createStructuredSelector({
|
||||||
bodyshop: selectBodyshop,
|
bodyshop: selectBodyshop,
|
||||||
@@ -69,6 +70,8 @@ export function JobsCloseComponent({ job, bodyshop, jobRO, insertAuditTrail, set
|
|||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const notification = useNotification();
|
const notification = useNotification();
|
||||||
|
|
||||||
|
const hasDMSKey = bodyshopHasDmsKey(bodyshop);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
treatments: { Qb_Multi_Ar, ClosingPeriod }
|
treatments: { Qb_Multi_Ar, ClosingPeriod }
|
||||||
} = useSplitTreatments({
|
} = useSplitTreatments({
|
||||||
@@ -191,7 +194,7 @@ export function JobsCloseComponent({ job, bodyshop, jobRO, insertAuditTrail, set
|
|||||||
{t("general.actions.close")}
|
{t("general.actions.close")}
|
||||||
</Button>
|
</Button>
|
||||||
</Popconfirm>
|
</Popconfirm>
|
||||||
{(bodyshop.pbs_serialnumber || bodyshop.cdk_dealerid || bodyshop.rr_dealerid) && (
|
{bodyshopHasDmsKey(bodyshop) && (
|
||||||
<Link to={`/manage/dms?jobId=${job.id}`}>
|
<Link to={`/manage/dms?jobId=${job.id}`}>
|
||||||
<Button disabled={job.date_exported || !jobRO}>{t("jobs.actions.sendtodms")}</Button>
|
<Button disabled={job.date_exported || !jobRO}>{t("jobs.actions.sendtodms")}</Button>
|
||||||
</Link>
|
</Link>
|
||||||
@@ -311,7 +314,7 @@ export function JobsCloseComponent({ job, bodyshop, jobRO, insertAuditTrail, set
|
|||||||
<Switch />
|
<Switch />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
)}
|
)}
|
||||||
{(bodyshop.cdk_dealerid || bodyshop.pbs_serialnumber || bodyshop.rr_dealerid) && (
|
{hasDMSKey && (
|
||||||
<Form.Item
|
<Form.Item
|
||||||
label={t("jobs.fields.kmin")}
|
label={t("jobs.fields.kmin")}
|
||||||
name="kmin"
|
name="kmin"
|
||||||
@@ -324,7 +327,7 @@ export function JobsCloseComponent({ job, bodyshop, jobRO, insertAuditTrail, set
|
|||||||
<InputNumber precision={0} disabled={jobRO} />
|
<InputNumber precision={0} disabled={jobRO} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
)}
|
)}
|
||||||
{(bodyshop.cdk_dealerid || bodyshop.pbs_serialnumber || bodyshop.rr_dealerid) && (
|
{hasDMSKey && (
|
||||||
<Form.Item
|
<Form.Item
|
||||||
label={t("jobs.fields.kmout")}
|
label={t("jobs.fields.kmout")}
|
||||||
name="kmout"
|
name="kmout"
|
||||||
@@ -348,7 +351,7 @@ export function JobsCloseComponent({ job, bodyshop, jobRO, insertAuditTrail, set
|
|||||||
<InputNumber precision={0} disabled={jobRO} />
|
<InputNumber precision={0} disabled={jobRO} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
)}
|
)}
|
||||||
{(bodyshop.cdk_dealerid || bodyshop.pbs_serialnumber || bodyshop.rr_dealerid) && (
|
{hasDMSKey && (
|
||||||
<Form.Item
|
<Form.Item
|
||||||
label={t("jobs.fields.dms_allocation")}
|
label={t("jobs.fields.dms_allocation")}
|
||||||
name="dms_allocation"
|
name="dms_allocation"
|
||||||
|
|||||||
@@ -1,11 +0,0 @@
|
|||||||
export const determineDmsType = (bodyshop) => {
|
|
||||||
const dmsMapping = {
|
|
||||||
cdk_dealerid: "cdk",
|
|
||||||
pbs_serialnumber: "pbs",
|
|
||||||
rr_dealerid: "rr"
|
|
||||||
};
|
|
||||||
|
|
||||||
return Object.keys(dmsMapping).find((key) => bodyshop[key])
|
|
||||||
? dmsMapping[Object.keys(dmsMapping).find((key) => bodyshop[key])]
|
|
||||||
: "pbs";
|
|
||||||
};
|
|
||||||
72
client/src/utils/dmsUtils.js
Normal file
72
client/src/utils/dmsUtils.js
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
/**
|
||||||
|
* DMS type mapping constants.
|
||||||
|
* CAREFUL: the values here are used as canonical "mode" strings elsewhere in the app.
|
||||||
|
* @type {{reynolds: string, cdk: string, pbs: string, fortellis: string}}
|
||||||
|
*/
|
||||||
|
export const DMS_MAP = {
|
||||||
|
reynolds: "rr",
|
||||||
|
cdk: "cdk",
|
||||||
|
pbs: "pbs",
|
||||||
|
fortellis: "fortellis"
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines the DMS type for a given bodyshop object.
|
||||||
|
* @param bodyshop
|
||||||
|
* @returns {*|string}
|
||||||
|
*/
|
||||||
|
export const determineDMSTypeByBodyshop = (bodyshop) => {
|
||||||
|
const dmsMapping = {
|
||||||
|
cdk_dealerid: DMS_MAP.cdk,
|
||||||
|
pbs_serialnumber: DMS_MAP.pbs,
|
||||||
|
rr_dealerid: DMS_MAP.reynolds
|
||||||
|
};
|
||||||
|
|
||||||
|
return Object.keys(dmsMapping).find((key) => bodyshop[key])
|
||||||
|
? dmsMapping[Object.keys(dmsMapping).find((key) => bodyshop[key])]
|
||||||
|
: DMS_MAP.pbs;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines the translation key for a given DMS type.
|
||||||
|
* @param dmsType
|
||||||
|
* @returns {*|string}
|
||||||
|
*/
|
||||||
|
export const determineDmsTypeTranslationKey = (dmsType) => {
|
||||||
|
const dmsTypeMapping = {
|
||||||
|
[DMS_MAP.cdk]: "bodyshop.labels.dms.cdk",
|
||||||
|
[DMS_MAP.pbs]: "bodyshop.labels.dms.pbs",
|
||||||
|
[DMS_MAP.reynolds]: "bodyshop.labels.dms.rr"
|
||||||
|
};
|
||||||
|
|
||||||
|
return dmsTypeMapping[dmsType] || dmsTypeMapping[DMS_MAP.pbs];
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a normalized "mode" we can switch on:
|
||||||
|
* @param bodyshop
|
||||||
|
* @param fortellisTreatment
|
||||||
|
* @returns {*|string|string}
|
||||||
|
*/
|
||||||
|
export const getDmsMode = (bodyshop, fortellisTreatment) => {
|
||||||
|
const base = determineDMSTypeByBodyshop(bodyshop); // "rr" | "cdk" | "pbs" | undefined
|
||||||
|
if (base === DMS_MAP.cdk && fortellisTreatment === "on") return DMS_MAP.fortellis;
|
||||||
|
return base ?? "none";
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the DMS mode uses WSS.
|
||||||
|
* @param mode
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
|
export const isWssMode = (mode) => {
|
||||||
|
return mode === DMS_MAP.reynolds || mode === DMS_MAP.fortellis;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the bodyshop has any DMS key configured.
|
||||||
|
* @param bodyshop
|
||||||
|
* @returns {*|string}
|
||||||
|
*/
|
||||||
|
export const bodyshopHasDmsKey = (bodyshop) =>
|
||||||
|
bodyshop.cdk_dealerid || bodyshop.pbs_serialnumber || bodyshop.rr_dealerid;
|
||||||
16
client/src/utils/legacySocket.js
Normal file
16
client/src/utils/legacySocket.js
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
// client/src/utils/legacySocket.js
|
||||||
|
import SocketIO from "socket.io-client";
|
||||||
|
import { auth } from "../firebase/firebase.utils";
|
||||||
|
|
||||||
|
// Create once, reuse everywhere.
|
||||||
|
const legacySocket = SocketIO(import.meta.env.PROD ? import.meta.env.VITE_APP_AXIOS_BASE_API_URL : "", {
|
||||||
|
path: "/ws",
|
||||||
|
withCredentials: true,
|
||||||
|
autoConnect: false,
|
||||||
|
auth: async (callback) => {
|
||||||
|
const token = auth.currentUser && (await auth.currentUser.getIdToken());
|
||||||
|
callback({ token });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
export default legacySocket;
|
||||||
Reference in New Issue
Block a user