feature/IO-3357-Reynolds-and-Reynolds-DMS-API-Integration - Checkpoint
This commit is contained in:
@@ -55,7 +55,7 @@ export function DmsAllocationsSummaryAp({ socket, bodyshop, billids, title }) {
|
||||
});
|
||||
}
|
||||
}, [socket, socket.connected, billids]);
|
||||
console.log(allocationsSummary);
|
||||
|
||||
const columns = [
|
||||
{
|
||||
title: t("general.labels.status"),
|
||||
@@ -122,7 +122,7 @@ export function DmsAllocationsSummaryAp({ socket, bodyshop, billids, title }) {
|
||||
<Form.Item
|
||||
name="journal"
|
||||
label={t("jobs.fields.dms.journal")}
|
||||
initialValue={bodyshop.cdk_configuration && bodyshop.cdk_configuration.default_journal}
|
||||
initialValue={bodyshop.cdk_configuration?.default_journal}
|
||||
rules={[
|
||||
{
|
||||
required: true
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useSplitTreatments } from "@splitsoftware/splitio-react";
|
||||
import { Button, Checkbox, Col, Form, Input, message, Modal, Table } from "antd";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { connect } from "react-redux";
|
||||
import { createStructuredSelector } from "reselect";
|
||||
@@ -16,6 +16,22 @@ const mapStateToProps = createStructuredSelector({
|
||||
const mapDispatchToProps = () => ({});
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(DmsCustomerSelector);
|
||||
|
||||
// ---------------- Helpers ----------------
|
||||
|
||||
function normalizeRrList(list) {
|
||||
if (!Array.isArray(list)) return [];
|
||||
return list
|
||||
.map((row) => {
|
||||
const custNo = row.custNo || row.CustomerId || row.customerId || null;
|
||||
const name =
|
||||
row.name ||
|
||||
[row.CustomerName?.FirstName, row.CustomerName?.LastName].filter(Boolean).join(" ").trim() ||
|
||||
(custNo ? String(custNo) : "");
|
||||
return custNo ? { custNo: String(custNo), name } : null;
|
||||
})
|
||||
.filter(Boolean);
|
||||
}
|
||||
|
||||
export function DmsCustomerSelector({ bodyshop, jobid }) {
|
||||
const { t } = useTranslation();
|
||||
const [customerList, setcustomerList] = useState([]);
|
||||
@@ -35,7 +51,7 @@ export function DmsCustomerSelector({ bodyshop, jobid }) {
|
||||
|
||||
const { socket: wsssocket } = useSocket();
|
||||
|
||||
const dms = determineDmsType(bodyshop);
|
||||
const dms = useMemo(() => determineDmsType(bodyshop), [bodyshop]);
|
||||
const bodyshopId = bodyshop?.id || bodyshop?.bodyshopid || bodyshop?.uuid;
|
||||
|
||||
useEffect(() => {
|
||||
@@ -44,28 +60,30 @@ export function DmsCustomerSelector({ bodyshop, jobid }) {
|
||||
const handleRrSelectCustomer = (list) => {
|
||||
setOpen(true);
|
||||
setDmsType("rr");
|
||||
setcustomerList(Array.isArray(list) ? list : []);
|
||||
// Normalize to { custNo, name }
|
||||
setcustomerList(normalizeRrList(list));
|
||||
setSelectedCustomer(null);
|
||||
};
|
||||
|
||||
const handleRrCreateRequired = () => {
|
||||
// Open selector shell + creation form
|
||||
setOpen(true);
|
||||
setDmsType("rr");
|
||||
setcustomerList([]);
|
||||
setOpenCreate(true);
|
||||
};
|
||||
|
||||
const handleRrCustomerCreated = ({ custNo }) => {
|
||||
if (custNo) {
|
||||
message.success(t("dms.messages.customerCreated"));
|
||||
setSelectedCustomer(custNo);
|
||||
setSelectedCustomer(String(custNo));
|
||||
setOpenCreate(false);
|
||||
setOpen(false);
|
||||
}
|
||||
};
|
||||
|
||||
wsssocket.on("rr-select-customer", handleRrSelectCustomer);
|
||||
wsssocket.on("rr-customer-create-required", handleRrCreateRequired);
|
||||
wsssocket.on("rr-customer-created", handleRrCustomerCreated);
|
||||
wsssocket.on("rr-select-customer", handleRrSelectCustomer);
|
||||
|
||||
return () => {
|
||||
wsssocket.off("rr-select-customer", handleRrSelectCustomer);
|
||||
@@ -79,6 +97,7 @@ export function DmsCustomerSelector({ bodyshop, jobid }) {
|
||||
setOpen(true);
|
||||
setDmsType("cdk");
|
||||
setcustomerList(Array.isArray(list) ? list : []);
|
||||
setSelectedCustomer(null);
|
||||
};
|
||||
wsssocket.on("fortellis-select-customer", handleFortellisSelectCustomer);
|
||||
return () => {
|
||||
@@ -89,11 +108,13 @@ export function DmsCustomerSelector({ bodyshop, jobid }) {
|
||||
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);
|
||||
@@ -105,18 +126,25 @@ export function DmsCustomerSelector({ bodyshop, jobid }) {
|
||||
}, [dms, Fortellis?.treatment, wsssocket]);
|
||||
|
||||
const onUseSelected = () => {
|
||||
if (dmsType === "rr") {
|
||||
// Stay open and show creation form
|
||||
setOpen(true);
|
||||
setOpenCreate(true);
|
||||
if (!selectedCustomer) {
|
||||
message.warning(t("general.actions.select"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (dmsType === "rr") {
|
||||
// ✅ RR now behaves like others: use the selected row and close
|
||||
wsssocket.emit("rr-selected-customer", { bodyshopId, custNo: String(selectedCustomer), jobId: jobid });
|
||||
setOpen(false);
|
||||
setSelectedCustomer(null);
|
||||
return;
|
||||
}
|
||||
|
||||
// Non-RR behavior unchanged:
|
||||
setOpen(false);
|
||||
if (Fortellis.treatment === "on") {
|
||||
wsssocket.emit("fortellis-selected-customer", { selectedCustomerId: null, jobid });
|
||||
wsssocket.emit("fortellis-selected-customer", { selectedCustomerId: selectedCustomer, jobid });
|
||||
} else {
|
||||
socket.emit(`${dmsType}-selected-customer`, null);
|
||||
socket.emit(`${dmsType}-selected-customer`, selectedCustomer);
|
||||
}
|
||||
setSelectedCustomer(null);
|
||||
};
|
||||
@@ -124,10 +152,9 @@ export function DmsCustomerSelector({ bodyshop, jobid }) {
|
||||
const onUseGeneric = () => {
|
||||
setOpen(false);
|
||||
const generic = bodyshop.cdk_configuration?.generic_customer_number || null;
|
||||
console.dir({ bodyshop, generic });
|
||||
if (dmsType === "rr") {
|
||||
if (generic) {
|
||||
wsssocket.emit("rr-selected-customer", { bodyshopId, custNo: generic, jobId: jobid });
|
||||
wsssocket.emit("rr-selected-customer", { bodyshopId, custNo: String(generic), jobId: jobid });
|
||||
}
|
||||
} else if (Fortellis.treatment === "on") {
|
||||
wsssocket.emit("fortellis-selected-customer", { selectedCustomerId: generic, jobid });
|
||||
@@ -138,11 +165,15 @@ export function DmsCustomerSelector({ bodyshop, jobid }) {
|
||||
};
|
||||
|
||||
const onCreateNew = () => {
|
||||
setOpen(false);
|
||||
if (dmsType === "rr") {
|
||||
// RR equivalent: signal create intent explicitly
|
||||
wsssocket.emit("rr-selected-customer", { bodyshopId, create: true, jobId: jobid });
|
||||
} else if (Fortellis.treatment === "on") {
|
||||
// RR: open inline creation modal (same as before)
|
||||
setOpen(true);
|
||||
setOpenCreate(true);
|
||||
return;
|
||||
}
|
||||
// Non-RR stays unchanged
|
||||
setOpen(false);
|
||||
if (Fortellis.treatment === "on") {
|
||||
wsssocket.emit("fortellis-selected-customer", { selectedCustomerId: null, jobid });
|
||||
} else {
|
||||
socket.emit(`${dmsType}-selected-customer`, null);
|
||||
@@ -150,12 +181,10 @@ export function DmsCustomerSelector({ bodyshop, jobid }) {
|
||||
setSelectedCustomer(null);
|
||||
};
|
||||
|
||||
// ---------- Columns ----------
|
||||
|
||||
const fortellisColumns = [
|
||||
{
|
||||
title: t("jobs.fields.dms.id"),
|
||||
dataIndex: "customerId",
|
||||
key: "id"
|
||||
},
|
||||
{ title: t("jobs.fields.dms.id"), dataIndex: "customerId", key: "id" },
|
||||
{
|
||||
title: t("jobs.fields.dms.vinowner"),
|
||||
dataIndex: "vinOwner",
|
||||
@@ -187,11 +216,7 @@ export function DmsCustomerSelector({ bodyshop, jobid }) {
|
||||
];
|
||||
|
||||
const cdkColumns = [
|
||||
{
|
||||
title: t("jobs.fields.dms.id"),
|
||||
dataIndex: ["id", "value"],
|
||||
key: "id"
|
||||
},
|
||||
{ title: t("jobs.fields.dms.id"), dataIndex: ["id", "value"], key: "id" },
|
||||
{
|
||||
title: t("jobs.fields.dms.vinowner"),
|
||||
dataIndex: "vinOwner",
|
||||
@@ -215,11 +240,7 @@ export function DmsCustomerSelector({ bodyshop, jobid }) {
|
||||
];
|
||||
|
||||
const pbsColumns = [
|
||||
{
|
||||
title: t("jobs.fields.dms.id"),
|
||||
dataIndex: "ContactId",
|
||||
key: "ContactId"
|
||||
},
|
||||
{ title: t("jobs.fields.dms.id"), dataIndex: "ContactId", key: "ContactId" },
|
||||
{
|
||||
title: t("jobs.fields.dms.name1"),
|
||||
key: "name1",
|
||||
@@ -233,14 +254,10 @@ export function DmsCustomerSelector({ bodyshop, jobid }) {
|
||||
}
|
||||
];
|
||||
|
||||
// RR is normalized to { custNo, name }
|
||||
const rrColumns = [
|
||||
{ title: t("jobs.fields.dms.id"), dataIndex: "custNo", key: "custNo" },
|
||||
{
|
||||
title: t("jobs.fields.dms.name1"),
|
||||
dataIndex: "name",
|
||||
key: "name",
|
||||
sorter: (a, b) => alphaSort(a?.name, b?.name)
|
||||
}
|
||||
{ title: t("jobs.fields.dms.name1"), dataIndex: "name", key: "name", sorter: (a, b) => alphaSort(a?.name, b?.name) }
|
||||
];
|
||||
|
||||
if (!open) return null;
|
||||
@@ -287,12 +304,14 @@ export function DmsCustomerSelector({ bodyshop, jobid }) {
|
||||
: dmsType === "cdk"
|
||||
? record.id?.value || record.customerId
|
||||
: record.ContactId;
|
||||
setSelectedCustomer(key);
|
||||
setSelectedCustomer(key ? String(key) : null);
|
||||
},
|
||||
type: "radio",
|
||||
selectedRowKeys: [selectedCustomer]
|
||||
selectedRowKeys: selectedCustomer ? [selectedCustomer] : []
|
||||
}}
|
||||
/>
|
||||
|
||||
{/* RR inline creation modal (unchanged) */}
|
||||
<Modal
|
||||
open={openCreate}
|
||||
title={t("jobs.actions.dms.createnewcustomer")}
|
||||
@@ -304,7 +323,6 @@ export function DmsCustomerSelector({ bodyshop, jobid }) {
|
||||
form={createForm}
|
||||
layout="vertical"
|
||||
onFinish={(values) => {
|
||||
// Map a few sane defaults; BE tolerates partials
|
||||
const fields = {
|
||||
FirstName: values.FirstName,
|
||||
LastName: values.LastName,
|
||||
@@ -318,7 +336,7 @@ export function DmsCustomerSelector({ bodyshop, jobid }) {
|
||||
wsssocket.emit("rr-create-customer", { jobId: jobid, fields }, (ack) => {
|
||||
if (ack?.ok) {
|
||||
message.success(t("dms.messages.customerCreated"));
|
||||
setSelectedCustomer(ack.custNo);
|
||||
setSelectedCustomer(ack.custNo ? String(ack.custNo) : null);
|
||||
setOpenCreate(false);
|
||||
setOpen(false);
|
||||
} else {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { DeleteFilled, DownOutlined } from "@ant-design/icons";
|
||||
import { DeleteFilled, DownOutlined, ReloadOutlined } from "@ant-design/icons";
|
||||
import {
|
||||
Button,
|
||||
Card,
|
||||
@@ -28,13 +28,12 @@ import CurrencyInput from "../form-items-formatted/currency-form-item.component"
|
||||
import LayoutFormRow from "../layout-form-row/layout-form-row.component";
|
||||
import { useSocket } from "../../contexts/SocketIO/useSocket";
|
||||
import { useSplitTreatments } from "@splitsoftware/splitio-react";
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
bodyshop: selectBodyshop
|
||||
});
|
||||
const mapDispatchToProps = () => ({
|
||||
//setUserLanguage: language => dispatch(setUserLanguage(language))
|
||||
});
|
||||
const mapDispatchToProps = () => ({});
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(DmsPostForm);
|
||||
|
||||
export function DmsPostForm({ bodyshop, socket, job, logsRef }) {
|
||||
@@ -50,6 +49,52 @@ export function DmsPostForm({ bodyshop, socket, job, logsRef }) {
|
||||
const { t } = useTranslation();
|
||||
const { socket: wsssocket } = useSocket();
|
||||
|
||||
// Figure out DMS once and reuse
|
||||
const dms = useMemo(() => determineDmsType(bodyshop), [bodyshop]);
|
||||
|
||||
// RR advisors state
|
||||
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 = () => {
|
||||
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 the correct event name + parse the ack shape
|
||||
wsssocket.emit("rr-get-advisors", { departmentType: "B" }, (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);
|
||||
wsssocket.off("rr-get-advisors:result", onResult);
|
||||
});
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (dms === "rr") fetchRrAdvisors();
|
||||
}, [dms, bodyshop?.id]);
|
||||
|
||||
const handlePayerSelect = (value, index) => {
|
||||
form.setFieldsValue({
|
||||
payers: form.getFieldValue("payers").map((payer, mapIndex) => {
|
||||
@@ -69,10 +114,9 @@ export function DmsPostForm({ bodyshop, socket, job, logsRef }) {
|
||||
};
|
||||
|
||||
const handleFinish = (values) => {
|
||||
const dms = determineDmsType(bodyshop);
|
||||
|
||||
// 1) RR takes precedence regardless of Fortellis split
|
||||
// 1) RR takes precedence regardless of Fortellis split
|
||||
if (dms === "rr") {
|
||||
// values will now include advisorNo from the RR dropdown
|
||||
wsssocket.emit("rr-export-job", {
|
||||
bodyshopId: bodyshop?.id || bodyshop?.bodyshopid || bodyshop?.uuid,
|
||||
jobId: job.id,
|
||||
@@ -81,7 +125,6 @@ export function DmsPostForm({ bodyshop, socket, job, logsRef }) {
|
||||
});
|
||||
} else {
|
||||
// 2) Fallback to existing behavior
|
||||
// TODO: Add this as a split instead.
|
||||
if (Fortellis.treatment === "on") {
|
||||
wsssocket.emit("fortellis-export-job", {
|
||||
jobid: job.id,
|
||||
@@ -91,6 +134,7 @@ export function DmsPostForm({ bodyshop, socket, job, logsRef }) {
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// cdk/pbs/etc.
|
||||
socket.emit(`${dms}-export-job`, {
|
||||
jobid: job.id,
|
||||
txEnvelope: values
|
||||
@@ -98,7 +142,6 @@ export function DmsPostForm({ bodyshop, socket, job, logsRef }) {
|
||||
}
|
||||
}
|
||||
|
||||
// Keep existing auto-scroll-to-logs behavior (fixing "curent" typo)
|
||||
if (logsRef?.current) {
|
||||
logsRef.current.scrollIntoView({ behavior: "smooth" });
|
||||
}
|
||||
@@ -130,70 +173,64 @@ export function DmsPostForm({ bodyshop, socket, job, logsRef }) {
|
||||
}}
|
||||
>
|
||||
<LayoutFormRow grow>
|
||||
<Form.Item
|
||||
name="journal"
|
||||
label={t("jobs.fields.dms.journal")}
|
||||
initialValue={bodyshop.cdk_configuration && bodyshop.cdk_configuration.default_journal}
|
||||
rules={[
|
||||
{
|
||||
required: true
|
||||
//message: t("general.validation.required"),
|
||||
}
|
||||
]}
|
||||
>
|
||||
<Input />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
name="kmin"
|
||||
label={t("jobs.fields.kmin")}
|
||||
initialValue={job && job.kmin}
|
||||
rules={[
|
||||
{
|
||||
required: true
|
||||
//message: t("general.validation.required"),
|
||||
}
|
||||
]}
|
||||
>
|
||||
{dms !== "rr" && (
|
||||
<Form.Item
|
||||
name="journal"
|
||||
label={t("jobs.fields.dms.journal")}
|
||||
initialValue={bodyshop.cdk_configuration?.default_journal}
|
||||
rules={[{ required: true }]}
|
||||
>
|
||||
<Input />
|
||||
</Form.Item>
|
||||
)}
|
||||
|
||||
{/* RR Advisor Number dropdown */}
|
||||
{dms === "rr" && (
|
||||
<Form.Item
|
||||
name="advisorNo"
|
||||
label={t("jobs.fields.dms.advisor")}
|
||||
rules={[{ required: true }]}
|
||||
style={{ minWidth: 260 }}
|
||||
>
|
||||
<Select
|
||||
loading={advLoading}
|
||||
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.loading") : t("general.none")}
|
||||
/>
|
||||
</Form.Item>
|
||||
)}
|
||||
|
||||
<Form.Item name="kmin" label={t("jobs.fields.kmin")} initialValue={job?.kmin} rules={[{ required: true }]}>
|
||||
<InputNumber disabled />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
name="kmout"
|
||||
label={t("jobs.fields.kmout")}
|
||||
initialValue={job && job.kmout}
|
||||
rules={[
|
||||
{
|
||||
required: true
|
||||
//message: t("general.validation.required"),
|
||||
}
|
||||
]}
|
||||
>
|
||||
<Form.Item name="kmout" label={t("jobs.fields.kmout")} initialValue={job?.kmout} rules={[{ required: true }]}>
|
||||
<InputNumber disabled />
|
||||
</Form.Item>
|
||||
|
||||
{dms === "rr" && (
|
||||
<Form.Item label=" " colon={false}>
|
||||
<Button onClick={fetchRrAdvisors} icon={<ReloadOutlined />} loading={advLoading}>
|
||||
{t("general.actions.refresh")}
|
||||
</Button>
|
||||
</Form.Item>
|
||||
)}
|
||||
</LayoutFormRow>
|
||||
|
||||
{bodyshop.cdk_dealerid && (
|
||||
<div>
|
||||
<LayoutFormRow style={{ justifyContent: "center" }} grow>
|
||||
<Form.Item
|
||||
name="dms_make"
|
||||
label={t("jobs.fields.dms.dms_make")}
|
||||
rules={[
|
||||
{
|
||||
required: true
|
||||
}
|
||||
]}
|
||||
>
|
||||
<Form.Item name="dms_make" label={t("jobs.fields.dms.dms_make")} rules={[{ required: true }]}>
|
||||
<Input />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
name="dms_model"
|
||||
label={t("jobs.fields.dms.dms_model")}
|
||||
rules={[
|
||||
{
|
||||
required: true
|
||||
}
|
||||
]}
|
||||
>
|
||||
<Form.Item name="dms_model" label={t("jobs.fields.dms.dms_model")} rules={[{ required: true }]}>
|
||||
<Input />
|
||||
</Form.Item>
|
||||
<Form.Item name="inservicedate" label={t("jobs.fields.dms.inservicedate")}>
|
||||
@@ -212,15 +249,8 @@ export function DmsPostForm({ bodyshop, socket, job, logsRef }) {
|
||||
</Space>
|
||||
</div>
|
||||
)}
|
||||
<Form.Item
|
||||
name="story"
|
||||
label={t("jobs.fields.dms.story")}
|
||||
rules={[
|
||||
{
|
||||
required: true
|
||||
}
|
||||
]}
|
||||
>
|
||||
|
||||
<Form.Item name="story" label={t("jobs.fields.dms.story")} rules={[{ required: true }]}>
|
||||
<Input.TextArea maxLength={240} />
|
||||
</Form.Item>
|
||||
|
||||
@@ -239,64 +269,53 @@ export function DmsPostForm({ bodyshop, socket, job, logsRef }) {
|
||||
value={Dinero(job.job_totals.totals.net_repairs).toFormat()}
|
||||
/>
|
||||
</Space>
|
||||
|
||||
<Form.List name={["payers"]}>
|
||||
{(fields, { add, remove }) => {
|
||||
return (
|
||||
<div>
|
||||
{fields.map((field, index) => (
|
||||
<Form.Item key={field.key}>
|
||||
<Space wrap>
|
||||
<Form.Item
|
||||
label={t("jobs.fields.dms.payer.name")}
|
||||
key={`${index}name`}
|
||||
name={[field.name, "name"]}
|
||||
rules={[
|
||||
{
|
||||
required: true
|
||||
}
|
||||
]}
|
||||
>
|
||||
<Select style={{ minWidth: "15rem" }} onSelect={(value) => handlePayerSelect(value, index)}>
|
||||
{bodyshop.cdk_configuration?.payers &&
|
||||
bodyshop.cdk_configuration.payers.map((payer) => (
|
||||
<Select.Option key={payer.name}>{payer.name}</Select.Option>
|
||||
))}
|
||||
</Select>
|
||||
</Form.Item>
|
||||
{(fields, { add, remove }) => (
|
||||
<div>
|
||||
{fields.map((field, index) => (
|
||||
<Form.Item key={field.key}>
|
||||
<Space wrap>
|
||||
<Form.Item
|
||||
label={t("jobs.fields.dms.payer.name")}
|
||||
key={`${index}name`}
|
||||
name={[field.name, "name"]}
|
||||
rules={[{ required: true }]}
|
||||
>
|
||||
<Select style={{ minWidth: "15rem" }} onSelect={(value) => handlePayerSelect(value, index)}>
|
||||
{bodyshop.cdk_configuration?.payers &&
|
||||
bodyshop.cdk_configuration.payers.map((payer) => (
|
||||
<Select.Option key={payer.name}>{payer.name}</Select.Option>
|
||||
))}
|
||||
</Select>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
label={t("jobs.fields.dms.payer.dms_acctnumber")}
|
||||
key={`${index}dms_acctnumber`}
|
||||
name={[field.name, "dms_acctnumber"]}
|
||||
rules={[
|
||||
{
|
||||
required: true
|
||||
}
|
||||
]}
|
||||
>
|
||||
<Input disabled />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
label={t("jobs.fields.dms.payer.dms_acctnumber")}
|
||||
key={`${index}dms_acctnumber`}
|
||||
name={[field.name, "dms_acctnumber"]}
|
||||
rules={[{ required: true }]}
|
||||
>
|
||||
<Input disabled />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
label={t("jobs.fields.dms.payer.amount")}
|
||||
key={`${index}amount`}
|
||||
name={[field.name, "amount"]}
|
||||
rules={[
|
||||
{
|
||||
required: true
|
||||
}
|
||||
]}
|
||||
>
|
||||
<CurrencyInput min={0} />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
label={t("jobs.fields.dms.payer.amount")}
|
||||
key={`${index}amount`}
|
||||
name={[field.name, "amount"]}
|
||||
rules={[{ required: true }]}
|
||||
>
|
||||
<CurrencyInput min={0} />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
label={
|
||||
<div>
|
||||
{t("jobs.fields.dms.payer.controlnumber")}{" "}
|
||||
<Dropdown
|
||||
menu={{
|
||||
items: bodyshop.cdk_configuration.controllist?.map((key, idx) => ({
|
||||
<Form.Item
|
||||
label={
|
||||
<div>
|
||||
{t("jobs.fields.dms.payer.controlnumber")}{" "}
|
||||
<Dropdown
|
||||
menu={{
|
||||
items:
|
||||
bodyshop.cdk_configuration.controllist?.map((key, idx) => ({
|
||||
key: idx,
|
||||
label: key.name,
|
||||
onClick: () => {
|
||||
@@ -310,93 +329,95 @@ export function DmsPostForm({ bodyshop, socket, job, logsRef }) {
|
||||
})
|
||||
});
|
||||
}
|
||||
}))
|
||||
}}
|
||||
>
|
||||
<a href=" #" onClick={(e) => e.preventDefault()}>
|
||||
<DownOutlined />
|
||||
</a>
|
||||
</Dropdown>
|
||||
</div>
|
||||
})) ?? []
|
||||
}}
|
||||
>
|
||||
<a href=" #" onClick={(e) => e.preventDefault()}>
|
||||
<DownOutlined />
|
||||
</a>
|
||||
</Dropdown>
|
||||
</div>
|
||||
}
|
||||
key={`${index}controlnumber`}
|
||||
name={[field.name, "controlnumber"]}
|
||||
rules={[{ required: true }]}
|
||||
>
|
||||
<Input />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item shouldUpdate>
|
||||
{() => {
|
||||
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;
|
||||
}
|
||||
key={`${index}controlnumber`}
|
||||
name={[field.name, "controlnumber"]}
|
||||
rules={[
|
||||
{
|
||||
required: true
|
||||
}
|
||||
]}
|
||||
>
|
||||
<Input />
|
||||
</Form.Item>
|
||||
}}
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item shouldUpdate>
|
||||
{() => {
|
||||
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>
|
||||
|
||||
<DeleteFilled
|
||||
onClick={() => {
|
||||
remove(field.name);
|
||||
}}
|
||||
/>
|
||||
</Space>
|
||||
</Form.Item>
|
||||
))}
|
||||
<Form.Item>
|
||||
<Button
|
||||
disabled={!(fields.length < 3)}
|
||||
onClick={() => {
|
||||
if (fields.length < 3) add();
|
||||
}}
|
||||
style={{ width: "100%" }}
|
||||
>
|
||||
{t("jobs.actions.dms.addpayer")}
|
||||
</Button>
|
||||
<DeleteFilled onClick={() => remove(field.name)} />
|
||||
</Space>
|
||||
</Form.Item>
|
||||
</div>
|
||||
);
|
||||
}}
|
||||
))}
|
||||
<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>
|
||||
|
||||
<Form.Item shouldUpdate>
|
||||
{() => {
|
||||
//Perform Calculation to determine discrepancy.
|
||||
// 1) Sum allocated payers
|
||||
let totalAllocated = Dinero();
|
||||
|
||||
const payers = form.getFieldValue("payers");
|
||||
payers?.forEach((payer) => {
|
||||
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.allocationsSummary &&
|
||||
socket.allocationsSummary.reduce(
|
||||
(acc, val) => {
|
||||
return {
|
||||
totalSale: acc.totalSale.add(Dinero(val.sale)),
|
||||
totalCost: acc.totalCost.add(Dinero(val.cost))
|
||||
};
|
||||
},
|
||||
{
|
||||
totalSale: Dinero(),
|
||||
totalCost: Dinero()
|
||||
}
|
||||
(acc, val) => ({
|
||||
totalSale: acc.totalSale.add(Dinero(val.sale)),
|
||||
totalCost: acc.totalCost.add(Dinero(val.cost))
|
||||
}),
|
||||
{ totalSale: Dinero(), totalCost: Dinero() }
|
||||
);
|
||||
|
||||
const discrep = totals ? totals.totalSale.subtract(totalAllocated) : Dinero();
|
||||
|
||||
// 3) New: validation gates
|
||||
const advisorOk = dms !== "rr" || !!form.getFieldValue("advisorNo");
|
||||
|
||||
// Require at least one complete payer row
|
||||
const payersOk =
|
||||
payers.length > 0 &&
|
||||
payers.every((p) => p?.name && p.dms_acctnumber && (p.amount ?? "") !== "" && p.controlnumber);
|
||||
|
||||
// 4) Disable rules:
|
||||
// - For non-RR: keep the original discrepancy rule (must have summary and zero discrepancy)
|
||||
// - For RR: ignore discrepancy rule, but require advisor + payer rows
|
||||
const nonRrDiscrepancyGate = dms !== "rr" && (socket.allocationsSummary ? discrep.getAmount() !== 0 : true);
|
||||
|
||||
const disablePost = !advisorOk || !payersOk || nonRrDiscrepancyGate;
|
||||
|
||||
return (
|
||||
<Space size="large" wrap align="center">
|
||||
<Statistic
|
||||
@@ -408,12 +429,10 @@ export function DmsPostForm({ bodyshop, socket, job, logsRef }) {
|
||||
<Typography.Title>=</Typography.Title>
|
||||
<Statistic
|
||||
title={t("jobs.labels.dms.notallocated")}
|
||||
valueStyle={{
|
||||
color: discrep.getAmount() === 0 ? "green" : "red"
|
||||
}}
|
||||
valueStyle={{ color: discrep.getAmount() === 0 ? "green" : "red" }}
|
||||
value={discrep.toFormat()}
|
||||
/>
|
||||
<Button disabled={!socket.allocationsSummary || discrep.getAmount() !== 0} htmlType="submit">
|
||||
<Button disabled={disablePost} htmlType="submit">
|
||||
{t("jobs.actions.dms.post")}
|
||||
</Button>
|
||||
</Space>
|
||||
|
||||
Reference in New Issue
Block a user