IO-233 Additional CDK Posting
This commit is contained in:
@@ -27,9 +27,10 @@ export function DmsAllocationsSummary({ socket, bodyshop, jobId }) {
|
||||
|
||||
useEffect(() => {
|
||||
if (socket.connected) {
|
||||
socket.emit("cdk-calculate-allocations", jobId, (ack) =>
|
||||
setAllocationsSummary(ack)
|
||||
);
|
||||
socket.emit("cdk-calculate-allocations", jobId, (ack) => {
|
||||
setAllocationsSummary(ack);
|
||||
socket.allocationsSummary = ack;
|
||||
});
|
||||
}
|
||||
}, [socket, socket.connected, jobId]);
|
||||
|
||||
|
||||
@@ -265,9 +265,24 @@ export function DmsPostForm({ bodyshop, socket, job }) {
|
||||
Dinero({ amount: Math.round((payer?.amount || 0) * 100) })
|
||||
);
|
||||
});
|
||||
const discrep = Dinero(job.job_totals.totals.total_repairs).subtract(
|
||||
totalAllocated
|
||||
);
|
||||
|
||||
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(),
|
||||
}
|
||||
);
|
||||
const discrep = totals
|
||||
? totals.totalSale.subtract(totalAllocated)
|
||||
: Dinero();
|
||||
return (
|
||||
<Space>
|
||||
<Statistic
|
||||
@@ -276,7 +291,7 @@ export function DmsPostForm({ bodyshop, socket, job }) {
|
||||
/>
|
||||
<Statistic
|
||||
title={t("jobs.labels.subtotal")}
|
||||
value={Dinero(job.job_totals.totals.total_repairs).toFormat()}
|
||||
value={(totals ? totals.totalSale : Dinero()).toFormat()}
|
||||
/>
|
||||
<Statistic
|
||||
title={t("jobs.labels.dms.notallocated")}
|
||||
|
||||
@@ -47,7 +47,7 @@ export const socket = SocketIO(
|
||||
|
||||
export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader }) {
|
||||
const { t } = useTranslation();
|
||||
const [logLevel, setLogLevel] = useState("TRACE");
|
||||
const [logLevel, setLogLevel] = useState("DEBUG");
|
||||
const [logs, setLogs] = useState([]);
|
||||
const search = queryString.parse(useLocation().search);
|
||||
const { jobId } = search;
|
||||
@@ -69,9 +69,7 @@ export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader }) {
|
||||
}, [t, setBreadcrumbs, setSelectedHeader]);
|
||||
|
||||
useEffect(() => {
|
||||
socket.on("connected", () => {
|
||||
console.log("Connected again.");
|
||||
});
|
||||
socket.on("connect", () => socket.emit("set-log-level", logLevel));
|
||||
socket.on("reconnect", () => {
|
||||
setLogs((logs) => {
|
||||
return [
|
||||
@@ -90,10 +88,6 @@ export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader }) {
|
||||
return [...logs, payload];
|
||||
});
|
||||
});
|
||||
|
||||
socket.connect();
|
||||
socket.emit("set-log-level", logLevel);
|
||||
|
||||
return () => {
|
||||
socket.removeAllListeners();
|
||||
socket.disconnect();
|
||||
|
||||
Reference in New Issue
Block a user