Compare commits
1 Commits
feature/IO
...
feature/IO
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
587f4a4492 |
@@ -134,11 +134,96 @@ export function BillDetailEditcontainer({ insertAuditTrail, bodyshop }) {
|
||||
|
||||
await Promise.all(updates);
|
||||
|
||||
const details = (() => {
|
||||
const original = data?.bills_by_pk ?? {};
|
||||
const updated = { ...bill, billlines };
|
||||
|
||||
const fmtVal = (key, val) =>
|
||||
val == null || val === ""
|
||||
? "<<empty>>"
|
||||
: typeof val === "number" && key.toLowerCase().includes("price")
|
||||
? `$${val.toFixed(2)}`
|
||||
: val;
|
||||
|
||||
const keysToTrack = ["line_desc", "quantity", "actual_price", "actual_cost", "cost_center"];
|
||||
const lineVals = (obj) => keysToTrack.map((k) => fmtVal(k, obj[k])).join(", ");
|
||||
|
||||
const changed = Object.entries(updated)
|
||||
.filter(([k, v]) => v != null && v !== "" && k !== "billlines" && k !== "__typename")
|
||||
.map(([k, v]) => {
|
||||
const orig = original[k];
|
||||
if (k === "date") {
|
||||
const a = orig ? dayjs(orig) : null;
|
||||
const b = v ? (dayjs.isDayjs(v) ? v : dayjs(v)) : null;
|
||||
return (a && b && a.isSame(b, "day")) || (!a && !b)
|
||||
? null
|
||||
: `date: ${a?.format("YYYY-MM-DD") ?? "<<empty>>"} → ${b?.format("YYYY-MM-DD") ?? "<<empty>>"}`;
|
||||
}
|
||||
return typeof orig === "object" || typeof v === "object" || String(orig) === String(v)
|
||||
? null
|
||||
: `${k}: ${fmtVal(k, orig)} → ${fmtVal(k, v)}`;
|
||||
})
|
||||
.filter(Boolean);
|
||||
|
||||
const origLines = original.billlines ?? [];
|
||||
const updLines = updated.billlines ?? [];
|
||||
|
||||
const addedObjs = updLines
|
||||
.filter((l) => !l.id)
|
||||
.map((u) => ({ label: u.line_desc || u.description || "new line", vals: lineVals(u), handled: false }));
|
||||
|
||||
const removedObjs = origLines
|
||||
.filter((o) => !updLines.some((u) => u.id === o.id))
|
||||
.map((o) => ({
|
||||
label: o.line_desc || o.description || o.id || "removed line",
|
||||
vals: lineVals(o),
|
||||
handled: false
|
||||
}));
|
||||
|
||||
const labelToAdded = addedObjs.reduce((m, a) => m.set(a.label, [...(m.get(a.label) ?? []), a]), new Map());
|
||||
|
||||
const modified = [
|
||||
...removedObjs.reduce((acc, r) => {
|
||||
const candidates = labelToAdded.get(r.label) ?? [];
|
||||
const exact = candidates.find((c) => c.vals === r.vals && !c.handled);
|
||||
if (exact) {
|
||||
exact.handled = r.handled = true;
|
||||
return acc;
|
||||
} // identical → cancel out
|
||||
const diff = candidates.find((c) => c.vals !== r.vals && !c.handled);
|
||||
if (diff) {
|
||||
diff.handled = r.handled = true;
|
||||
acc.push(`${r.label}: ${r.vals} → ${diff.vals}`);
|
||||
}
|
||||
return acc;
|
||||
}, []),
|
||||
...updLines
|
||||
.filter((u) => u.id)
|
||||
.flatMap((u) => {
|
||||
const o = origLines.find((x) => x.id === u.id);
|
||||
if (!o) return [];
|
||||
const diffs = keysToTrack
|
||||
.filter((k) => String(o[k]) !== String(u[k]))
|
||||
.map((k) => `${fmtVal(k, o[k])} → ${fmtVal(k, u[k])}`);
|
||||
return diffs.length ? [`${u.line_desc || u.description || u.id}: ${diffs.join("; ")}`] : [];
|
||||
})
|
||||
];
|
||||
|
||||
[
|
||||
["added", addedObjs.filter((a) => !a.handled).map((a) => `+${a.label} (${a.vals})`)],
|
||||
["removed", removedObjs.filter((r) => !r.handled).map((r) => `-${r.label} (${r.vals})`)],
|
||||
["modified", modified]
|
||||
].forEach(([type, items]) => {
|
||||
if (items.length) changed.push(`billlines ${type}: ${items.join(" | ")}`);
|
||||
});
|
||||
|
||||
return changed.length ? changed.join("; ") : bill.invoice_number || "No changes";
|
||||
})();
|
||||
|
||||
insertAuditTrail({
|
||||
jobid: bill.jobid,
|
||||
billid: search.billid,
|
||||
operation: AuditTrailMapping.billupdated(bill.invoice_number),
|
||||
type: "billupdated"
|
||||
operation: AuditTrailMapping.billupdated(bill.invoice_number, details)
|
||||
});
|
||||
|
||||
await refetch();
|
||||
|
||||
@@ -64,7 +64,7 @@ function normalizeJobAllocations(ack) {
|
||||
* RR-specific DMS Allocations Summary
|
||||
* Focused on what we actually send to RR:
|
||||
* - ROGOG (split by taxable / non-taxable segments)
|
||||
* - ROLABOR labor rows with bill hours / rates
|
||||
* - ROLABOR shell
|
||||
*
|
||||
* The heavy lifting (ROGOG/ROLABOR split, cost allocation, tax flags)
|
||||
* is now done on the backend via buildRogogFromAllocations/buildRolaborFromRogog.
|
||||
@@ -181,30 +181,21 @@ export function RrAllocationsSummary({ socket, bodyshop, jobId, title, onAllocat
|
||||
const rolaborRows = useMemo(() => {
|
||||
if (!rolaborPreview || !Array.isArray(rolaborPreview.ops)) return [];
|
||||
|
||||
return rolaborPreview.ops
|
||||
.filter((op) =>
|
||||
[op.bill?.jobTotalHrs, op.bill?.billTime, op.bill?.billRate, op.amount?.custPrice, op.amount?.totalAmt]
|
||||
.map((value) => Number.parseFloat(value ?? "0"))
|
||||
.some((value) => !Number.isNaN(value) && value !== 0)
|
||||
)
|
||||
.map((op, idx) => {
|
||||
const rowOpCode = opCode || op.opCode;
|
||||
return rolaborPreview.ops.map((op, idx) => {
|
||||
const rowOpCode = opCode || op.opCode;
|
||||
|
||||
return {
|
||||
key: `${op.jobNo}-${idx}`,
|
||||
opCode: rowOpCode,
|
||||
jobNo: op.jobNo,
|
||||
custPayTypeFlag: op.custPayTypeFlag,
|
||||
custTxblNtxblFlag: op.custTxblNtxblFlag,
|
||||
payType: op.bill?.payType,
|
||||
jobTotalHrs: op.bill?.jobTotalHrs,
|
||||
billTime: op.bill?.billTime,
|
||||
billRate: op.bill?.billRate,
|
||||
amtType: op.amount?.amtType,
|
||||
custPrice: op.amount?.custPrice,
|
||||
totalAmt: op.amount?.totalAmt
|
||||
};
|
||||
});
|
||||
return {
|
||||
key: `${op.jobNo}-${idx}`,
|
||||
opCode: rowOpCode,
|
||||
jobNo: op.jobNo,
|
||||
custPayTypeFlag: op.custPayTypeFlag,
|
||||
custTxblNtxblFlag: op.custTxblNtxblFlag,
|
||||
payType: op.bill?.payType,
|
||||
amtType: op.amount?.amtType,
|
||||
custPrice: op.amount?.custPrice,
|
||||
totalAmt: op.amount?.totalAmt
|
||||
};
|
||||
});
|
||||
}, [rolaborPreview, opCode]);
|
||||
|
||||
// Totals for ROGOG (sum custPrice + dlrCost over all lines)
|
||||
@@ -254,9 +245,6 @@ export function RrAllocationsSummary({ socket, bodyshop, jobId, title, onAllocat
|
||||
{ title: "CustPayType", dataIndex: "custPayTypeFlag", key: "custPayTypeFlag" },
|
||||
{ title: "CustTxblFlag", dataIndex: "custTxblNtxblFlag", key: "custTxblNtxblFlag" },
|
||||
{ title: "PayType", dataIndex: "payType", key: "payType" },
|
||||
{ title: "JobTotalHrs", dataIndex: "jobTotalHrs", key: "jobTotalHrs" },
|
||||
{ title: "BillTime", dataIndex: "billTime", key: "billTime" },
|
||||
{ title: "BillRate", dataIndex: "billRate", key: "billRate" },
|
||||
{ title: "AmtType", dataIndex: "amtType", key: "amtType" },
|
||||
{ title: "CustPrice", dataIndex: "custPrice", key: "custPrice" },
|
||||
{ title: "TotalAmt", dataIndex: "totalAmt", key: "totalAmt" }
|
||||
@@ -329,13 +317,12 @@ export function RrAllocationsSummary({ socket, bodyshop, jobId, title, onAllocat
|
||||
children: (
|
||||
<>
|
||||
<Typography.Paragraph type="secondary" style={{ marginBottom: 8 }}>
|
||||
This mirrors the labor rows RR will receive, including weighted bill hours and rates derived from the
|
||||
job's labor lines.
|
||||
This mirrors the shell that would be sent for ROLABOR when all financials are carried in GOG.
|
||||
</Typography.Paragraph>
|
||||
<ResponsiveTable
|
||||
pagination={false}
|
||||
columns={rolaborColumns}
|
||||
mobileColumnKeys={["jobNo", "opCode", "billRate", "custPrice"]}
|
||||
mobileColumnKeys={["jobNo", "opCode", "breakOut", "itemType"]}
|
||||
rowKey="key"
|
||||
dataSource={rolaborRows}
|
||||
locale={{ emptyText: "No ROLABOR lines would be generated." }}
|
||||
|
||||
@@ -14,16 +14,19 @@ import CriticalPartsScan from "../../utils/criticalPartsScan";
|
||||
import UndefinedToNull from "../../utils/undefinedtonull";
|
||||
import JobLinesUpdsertModal from "./job-lines-upsert-modal.component";
|
||||
import { useNotification } from "../../contexts/Notifications/notificationContext.jsx";
|
||||
import AuditTrailMapping from "../../utils/AuditTrailMappings.js";
|
||||
import { insertAuditTrail } from "../../redux/application/application.actions.js";
|
||||
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
jobLineEditModal: selectJobLineEditModal,
|
||||
bodyshop: selectBodyshop
|
||||
});
|
||||
const mapDispatchToProps = (dispatch) => ({
|
||||
toggleModalVisible: () => dispatch(toggleModalVisible("jobLineEdit"))
|
||||
toggleModalVisible: () => dispatch(toggleModalVisible("jobLineEdit")),
|
||||
insertAuditTrail: ({ jobid, operation, type }) => dispatch(insertAuditTrail({ jobid, operation, type }))
|
||||
});
|
||||
|
||||
function JobLinesUpsertModalContainer({ jobLineEditModal, toggleModalVisible, bodyshop }) {
|
||||
function JobLinesUpsertModalContainer({ jobLineEditModal, toggleModalVisible, bodyshop, insertAuditTrail }) {
|
||||
const {
|
||||
treatments: { CriticalPartsScanning }
|
||||
} = useTreatmentsWithConfig({
|
||||
@@ -74,6 +77,16 @@ function JobLinesUpsertModalContainer({ jobLineEditModal, toggleModalVisible, bo
|
||||
notification.success({
|
||||
title: t("joblines.successes.created")
|
||||
});
|
||||
insertAuditTrail({
|
||||
jobid: jobLineEditModal.context.jobid,
|
||||
operation: AuditTrailMapping.jobmanuallineinsert(
|
||||
Object.entries(values)
|
||||
.filter(([k, v]) => v != null && v !== "" && k !== "ah_detail_line" && k !== "prt_dsmk_p")
|
||||
.map(([k, v]) => `${k}: ${v}`)
|
||||
.join("; ")
|
||||
),
|
||||
type: "jobmanuallineinsert"
|
||||
});
|
||||
} else {
|
||||
notification.error({
|
||||
title: t("joblines.errors.creating", {
|
||||
@@ -103,6 +116,29 @@ function JobLinesUpsertModalContainer({ jobLineEditModal, toggleModalVisible, bo
|
||||
notification.success({
|
||||
title: t("joblines.successes.updated")
|
||||
});
|
||||
insertAuditTrail({
|
||||
jobid: jobLineEditModal.context.jobid,
|
||||
operation: AuditTrailMapping.joblineupdate(
|
||||
(() => {
|
||||
const original = jobLineEditModal.context || {};
|
||||
const changed = Object.entries(values)
|
||||
.filter(([k, v]) => v != null && v !== "" && k !== "ah_detail_line" && k !== "prt_dsmk_p")
|
||||
.map(([k, v]) => {
|
||||
const orig = original[k];
|
||||
if (String(orig) === String(v)) return null;
|
||||
const fmt = (key, val) => {
|
||||
if (val == null || val === "") return "<<empty>>";
|
||||
if (typeof val === "number" && key.toLowerCase().includes("price")) return `$${val.toFixed(2)}`;
|
||||
return val;
|
||||
};
|
||||
return `${k}: ${fmt(k, orig)} → ${fmt(k, v)}`;
|
||||
})
|
||||
.filter(Boolean);
|
||||
return changed.length ? changed.join("; ") : "No changes";
|
||||
})()
|
||||
),
|
||||
type: "joblineupdate"
|
||||
});
|
||||
} else {
|
||||
notification.success({
|
||||
title: t("joblines.errors.updating", {
|
||||
|
||||
@@ -58,7 +58,6 @@ export function ProductionColumnsComponent({
|
||||
|
||||
const columnKeys = columns.map((i) => i.key);
|
||||
const cols = dataSource({
|
||||
bodyshop,
|
||||
technician,
|
||||
data,
|
||||
state: tableState,
|
||||
|
||||
@@ -609,19 +609,7 @@ const productionListColumnsData = ({ technician, state, activeStatuses, data, bo
|
||||
ellipsis: true,
|
||||
|
||||
render: (text, record) => <TimeFormatter>{record.date_repairstarted}</TimeFormatter>
|
||||
},
|
||||
...(bodyshop && bodyshop.rr_dealerid
|
||||
? [
|
||||
{
|
||||
title: i18n.t("jobs.fields.dms.id"),
|
||||
dataIndex: "dms_id",
|
||||
key: "dms_id",
|
||||
ellipsis: true,
|
||||
sorter: (a, b) => alphaSort(a.dms_id, b.dms_id),
|
||||
sortOrder: state.sortedInfo.columnKey === "dms_id" && state.sortedInfo.order
|
||||
}
|
||||
]
|
||||
: []),
|
||||
}
|
||||
];
|
||||
};
|
||||
export default productionListColumnsData;
|
||||
|
||||
@@ -244,7 +244,6 @@ export function ProductionListConfigManager({
|
||||
nextConfig.columns.columnKeys.map((k) => {
|
||||
return {
|
||||
...ProductionListColumns({
|
||||
bodyshop,
|
||||
technician,
|
||||
state: ensureDefaultState(state),
|
||||
refetch,
|
||||
@@ -271,7 +270,6 @@ export function ProductionListConfigManager({
|
||||
activeConfig.columns.columnKeys.map((k) => {
|
||||
return {
|
||||
...ProductionListColumns({
|
||||
bodyshop,
|
||||
technician,
|
||||
state: ensureDefaultState(state),
|
||||
refetch,
|
||||
|
||||
@@ -2,7 +2,7 @@ import { PageHeader } from "@ant-design/pro-layout";
|
||||
import { useMutation, useQuery } from "@apollo/client/react";
|
||||
import { useTreatmentsWithConfig } from "@splitsoftware/splitio-react";
|
||||
import { Button, Form, Modal, Space } from "antd";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useEffect, useState, useRef } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { connect } from "react-redux";
|
||||
import { createStructuredSelector } from "reselect";
|
||||
@@ -15,21 +15,26 @@ import { selectBodyshop } from "../../redux/user/user.selectors";
|
||||
import dayjs from "../../utils/day";
|
||||
import TimeTicketsCommitToggleComponent from "../time-tickets-commit-toggle/time-tickets-commit-toggle.component";
|
||||
import TimeTicketModalComponent from "./time-ticket-modal.component";
|
||||
import { insertAuditTrail } from "../../redux/application/application.actions.js";
|
||||
import AuditTrailMapping from "../../utils/AuditTrailMappings";
|
||||
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
timeTicketModal: selectTimeTicket,
|
||||
bodyshop: selectBodyshop
|
||||
});
|
||||
const mapDispatchToProps = (dispatch) => ({
|
||||
toggleModalVisible: () => dispatch(toggleModalVisible("timeTicket"))
|
||||
toggleModalVisible: () => dispatch(toggleModalVisible("timeTicket")),
|
||||
insertAuditTrail: ({ jobid, operation, type }) => dispatch(insertAuditTrail({ jobid, operation, type }))
|
||||
});
|
||||
|
||||
export function TimeTicketModalContainer({ timeTicketModal, toggleModalVisible, bodyshop }) {
|
||||
export function TimeTicketModalContainer({ timeTicketModal, toggleModalVisible, bodyshop, insertAuditTrail }) {
|
||||
const [form] = Form.useForm();
|
||||
const [loading, setLoading] = useState(false);
|
||||
const { t } = useTranslation();
|
||||
const [enterAgain, setEnterAgain] = useState(false);
|
||||
|
||||
const lastSubmittedRef = useRef(null);
|
||||
|
||||
const [lineTicketRefreshKey, setLineTicketRefreshKey] = useState(0);
|
||||
|
||||
const [insertTicket] = useMutation(INSERT_NEW_TIME_TICKET);
|
||||
@@ -50,6 +55,8 @@ export function TimeTicketModalContainer({ timeTicketModal, toggleModalVisible,
|
||||
});
|
||||
|
||||
const handleFinish = (values) => {
|
||||
// Save submitted values so we can compute audit-trail details after the mutation completes
|
||||
lastSubmittedRef.current = values;
|
||||
setLoading(true);
|
||||
const emps = EmployeeAutoCompleteData?.employees.filter((e) => e.id === values.employeeid);
|
||||
if (timeTicketModal.context.id) {
|
||||
@@ -89,6 +96,44 @@ export function TimeTicketModalContainer({ timeTicketModal, toggleModalVisible,
|
||||
title: t("timetickets.successes.created")
|
||||
});
|
||||
|
||||
const timeticket = timeTicketModal.context?.timeticket ?? {};
|
||||
const original = timeticket || {};
|
||||
const submitted = lastSubmittedRef.current || {};
|
||||
|
||||
const fmt = (key, val) => {
|
||||
if (val == null || val === "") return "<<empty>>";
|
||||
const k = key.toLowerCase();
|
||||
if (dayjs.isDayjs?.(val)) return dayjs(val).format(k.includes("clock") ? "YYYY-MM-DD HH:mm" : "YYYY-MM-DD");
|
||||
if (typeof val === "number")
|
||||
return k.includes("hrs")
|
||||
? val.toFixed(1)
|
||||
: k.includes("rate") || k.includes("price")
|
||||
? `$${val.toFixed(2)}`
|
||||
: String(val);
|
||||
if (key === "employeeid") {
|
||||
const emp = EmployeeAutoCompleteData?.employees?.find(({ id }) => id === val);
|
||||
return emp ? `${emp.first_name} ${emp.last_name}` : String(val);
|
||||
}
|
||||
return String(val);
|
||||
};
|
||||
|
||||
const changed = Object.entries(submitted)
|
||||
.filter(([, v]) => v != null && v !== "")
|
||||
.map(([k, v]) => {
|
||||
const origVal = k === "jobid" ? (original.job?.id ?? original.jobid ?? original[k]) : original[k];
|
||||
return String(fmt(k, origVal)) !== String(fmt(k, v)) ? `${k}: ${fmt(k, origVal)} → ${fmt(k, v)}` : null;
|
||||
})
|
||||
.filter(Boolean);
|
||||
|
||||
insertAuditTrail({
|
||||
jobid: timeticket.job?.id ?? timeticket.jobid,
|
||||
operation: AuditTrailMapping.timeticketupdated(
|
||||
[original.employee.first_name, original.employee.last_name].filter(Boolean).join(" "),
|
||||
original.date ? dayjs(original.date).format("YYYY-MM-DD") : "<<empty>>",
|
||||
changed.length ? changed.join("; ") : "No changes"
|
||||
)
|
||||
});
|
||||
|
||||
// Refresh parent screens (Job Labor tab, etc.)
|
||||
if (timeTicketModal.actions.refetch) timeTicketModal.actions.refetch();
|
||||
|
||||
|
||||
@@ -197,7 +197,6 @@ export const QUERY_EXACT_JOB_IN_PRODUCTION = gql`
|
||||
employee_prep
|
||||
employee_csr
|
||||
date_repairstarted
|
||||
dms_id
|
||||
joblines_status {
|
||||
part_type
|
||||
status
|
||||
@@ -270,7 +269,6 @@ export const QUERY_EXACT_JOBS_IN_PRODUCTION = gql`
|
||||
employee_prep
|
||||
employee_csr
|
||||
date_repairstarted
|
||||
dms_id
|
||||
joblines_status {
|
||||
part_type
|
||||
status
|
||||
@@ -2673,7 +2671,6 @@ export const QUERY_JOBS_IN_PRODUCTION = gql`
|
||||
suspended
|
||||
job_totals
|
||||
date_repairstarted
|
||||
dms_id
|
||||
joblines_status {
|
||||
part_type
|
||||
status
|
||||
|
||||
@@ -8,13 +8,14 @@ import { createStructuredSelector } from "reselect";
|
||||
import RbacWrapper from "../../components/rbac-wrapper/rbac-wrapper.component";
|
||||
import { INSERT_NEW_JOB } from "../../graphql/jobs.queries";
|
||||
import { QUERY_OWNER_FOR_JOB_CREATION } from "../../graphql/owners.queries";
|
||||
import { setBreadcrumbs, setSelectedHeader } from "../../redux/application/application.actions";
|
||||
import { insertAuditTrail, setBreadcrumbs, setSelectedHeader } from "../../redux/application/application.actions";
|
||||
import { selectBodyshop, selectCurrentUser } from "../../redux/user/user.selectors";
|
||||
import InstanceRenderManager from "../../utils/instanceRenderMgr";
|
||||
import JobsCreateComponent from "./jobs-create.component";
|
||||
import JobCreateContext from "./jobs-create.context";
|
||||
import { useNotification } from "../../contexts/Notifications/notificationContext.jsx";
|
||||
import { logImEXEvent } from "../../firebase/firebase.utils";
|
||||
import AuditTrailMapping from "../../utils/AuditTrailMappings.js";
|
||||
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
bodyshop: selectBodyshop,
|
||||
@@ -22,10 +23,11 @@ const mapStateToProps = createStructuredSelector({
|
||||
});
|
||||
const mapDispatchToProps = (dispatch) => ({
|
||||
setBreadcrumbs: (breadcrumbs) => dispatch(setBreadcrumbs(breadcrumbs)),
|
||||
setSelectedHeader: (key) => dispatch(setSelectedHeader(key))
|
||||
setSelectedHeader: (key) => dispatch(setSelectedHeader(key)),
|
||||
insertAuditTrail: ({ jobid, operation, type }) => dispatch(insertAuditTrail({ jobid, operation, type }))
|
||||
});
|
||||
|
||||
function JobsCreateContainer({ bodyshop, setBreadcrumbs, setSelectedHeader, currentUser }) {
|
||||
function JobsCreateContainer({ bodyshop, setBreadcrumbs, setSelectedHeader, currentUser, insertAuditTrail }) {
|
||||
const { t } = useTranslation();
|
||||
const notification = useNotification();
|
||||
|
||||
@@ -84,6 +86,11 @@ function JobsCreateContainer({ bodyshop, setBreadcrumbs, setSelectedHeader, curr
|
||||
newJobId: resp.data.insert_jobs.returning[0].id
|
||||
});
|
||||
logImEXEvent("manual_job_create_completed", {});
|
||||
insertAuditTrail({
|
||||
jobid: resp.data.insert_jobs.returning[0].id,
|
||||
operation: AuditTrailMapping.jobmanualcreate(),
|
||||
type: "jobmanualcreate"
|
||||
});
|
||||
setIsSubmitting(false);
|
||||
})
|
||||
.catch((error) => {
|
||||
|
||||
@@ -122,7 +122,7 @@
|
||||
"billdeleted": "Bill with invoice number {{invoice_number}} deleted.",
|
||||
"billmarkforreexport": "Bill with invoice number {{invoice_number}} marked for re-export.",
|
||||
"billposted": "Bill with invoice number {{invoice_number}} posted.",
|
||||
"billupdated": "Bill with invoice number {{invoice_number}} updated.",
|
||||
"billupdated": "Bill with invoice number {{invoice_number}} updated with the following details: {{values}}.",
|
||||
"failedpayment": "Failed payment attempt.",
|
||||
"jobassignmentchange": "Employee {{name}} assigned to {{operation}}",
|
||||
"jobassignmentremoved": "Employee assignment removed for {{operation}}",
|
||||
@@ -137,6 +137,9 @@
|
||||
"jobintake": "Job intake completed. Status set to {{status}}. Scheduled completion is {{scheduled_completion}}.",
|
||||
"jobinvoiced": "Job has been invoiced.",
|
||||
"jobioucreated": "IOU Created.",
|
||||
"joblineupdate": "Job line {{line_desc}} updated.",
|
||||
"jobmanualcreate": "Job manually created.",
|
||||
"jobmanuallineinsert": "Job line manually added with the following details: {{values}}.",
|
||||
"jobmodifylbradj": "Labor adjustments modified {{mod_lbr_ty}} / {{hours}}.",
|
||||
"jobnoteadded": "Note added to Job.",
|
||||
"jobnotedeleted": "Note deleted from Job.",
|
||||
@@ -152,7 +155,8 @@
|
||||
"tasks_deleted": "Task '{{title}}' deleted by {{deletedBy}}",
|
||||
"tasks_uncompleted": "Task '{{title}}' uncompleted by {{uncompletedBy}}",
|
||||
"tasks_undeleted": "Task '{{title}}' undeleted by {{undeletedBy}}",
|
||||
"tasks_updated": "Task '{{title}}' updated by {{updatedBy}}"
|
||||
"tasks_updated": "Task '{{title}}' updated by {{updatedBy}}",
|
||||
"timeticketupdated": "Time Ticket for {{employee}} on {{date}} updated with the following details: {{details}}"
|
||||
}
|
||||
},
|
||||
"billlines": {
|
||||
|
||||
@@ -137,6 +137,9 @@
|
||||
"jobintake": "",
|
||||
"jobinvoiced": "",
|
||||
"jobioucreated": "",
|
||||
"joblineupdate": "",
|
||||
"jobmanualcreate": "",
|
||||
"jobmanuallineinsert": "",
|
||||
"jobmodifylbradj": "",
|
||||
"jobnoteadded": "",
|
||||
"jobnotedeleted": "",
|
||||
@@ -152,7 +155,8 @@
|
||||
"tasks_deleted": "",
|
||||
"tasks_uncompleted": "",
|
||||
"tasks_undeleted": "",
|
||||
"tasks_updated": ""
|
||||
"tasks_updated": "",
|
||||
"timeticketupdated": ""
|
||||
}
|
||||
},
|
||||
"billlines": {
|
||||
|
||||
@@ -137,6 +137,9 @@
|
||||
"jobintake": "",
|
||||
"jobinvoiced": "",
|
||||
"jobioucreated": "",
|
||||
"joblineupdate": "",
|
||||
"jobmanualcreate": "",
|
||||
"jobmanuallineinsert": "",
|
||||
"jobmodifylbradj": "",
|
||||
"jobnoteadded": "",
|
||||
"jobnotedeleted": "",
|
||||
@@ -152,7 +155,8 @@
|
||||
"tasks_deleted": "",
|
||||
"tasks_uncompleted": "",
|
||||
"tasks_undeleted": "",
|
||||
"tasks_updated": ""
|
||||
"tasks_updated": "",
|
||||
"timeticketupdated": ""
|
||||
}
|
||||
},
|
||||
"billlines": {
|
||||
|
||||
@@ -10,7 +10,7 @@ const AuditTrailMapping = {
|
||||
billdeleted: (invoice_number) => i18n.t("audit_trail.messages.billdeleted", { invoice_number }),
|
||||
billmarkforreexport: (invoice_number) => i18n.t("audit_trail.messages.billmarkforreexport", { invoice_number }),
|
||||
billposted: (invoice_number) => i18n.t("audit_trail.messages.billposted", { invoice_number }),
|
||||
billupdated: (invoice_number) => i18n.t("audit_trail.messages.billupdated", { invoice_number }),
|
||||
billupdated: (invoice_number, values) => i18n.t("audit_trail.messages.billupdated", { invoice_number, values }),
|
||||
jobassignmentchange: (operation, name) => i18n.t("audit_trail.messages.jobassignmentchange", { operation, name }),
|
||||
jobassignmentremoved: (operation) => i18n.t("audit_trail.messages.jobassignmentremoved", { operation }),
|
||||
jobchecklist: (type, inproduction, status) =>
|
||||
@@ -26,6 +26,9 @@ const AuditTrailMapping = {
|
||||
jobinproductionchange: (inproduction) => i18n.t("audit_trail.messages.jobinproductionchange", { inproduction }),
|
||||
jobinvoiced: () => i18n.t("audit_trail.messages.jobinvoiced"),
|
||||
jobclosedwithbypass: () => i18n.t("audit_trail.messages.jobclosedwithbypass"),
|
||||
joblineupdate: (line_desc) => i18n.t("audit_trail.messages.joblineupdate", { line_desc }),
|
||||
jobmanualcreate: () => i18n.t("audit_trail.messages.jobmanualcreate"),
|
||||
jobmanuallineinsert: (values) => i18n.t("audit_trail.messages.jobmanuallineinsert", { values }),
|
||||
jobmodifylbradj: ({ mod_lbr_ty, hours }) => i18n.t("audit_trail.messages.jobmodifylbradj", { mod_lbr_ty, hours }),
|
||||
jobnoteadded: () => i18n.t("audit_trail.messages.jobnoteadded"),
|
||||
jobnoteupdated: () => i18n.t("audit_trail.messages.jobnoteupdated"),
|
||||
@@ -72,7 +75,8 @@ const AuditTrailMapping = {
|
||||
i18n.t("audit_trail.messages.tasks_uncompleted", {
|
||||
title,
|
||||
uncompletedBy
|
||||
})
|
||||
}),
|
||||
timeticketupdated: (employee, date, details) => i18n.t("audit_trail.messages.timeticketupdated", { employee, date, details })
|
||||
};
|
||||
|
||||
export default AuditTrailMapping;
|
||||
|
||||
@@ -1,17 +1,20 @@
|
||||
const { SecretsManagerClient, GetSecretValueCommand } = require("@aws-sdk/client-secrets-manager");
|
||||
const { defaultProvider } = require("@aws-sdk/credential-provider-node");
|
||||
const { InstanceRegion, InstanceIsLocalStackEnabled, InstanceLocalStackEndpoint } = require("../utils/instanceMgr");
|
||||
const { isString, isEmpty } = require("lodash");
|
||||
|
||||
const CHATTER_BASE_URL = process.env.CHATTER_API_BASE_URL || "https://api.chatterresearch.com";
|
||||
const AWS_REGION = process.env.AWS_REGION || "ca-central-1";
|
||||
|
||||
// Configure SecretsManager client with localstack support
|
||||
const secretsClientOptions = {
|
||||
region: InstanceRegion(),
|
||||
region: AWS_REGION,
|
||||
credentials: defaultProvider()
|
||||
};
|
||||
|
||||
if (InstanceIsLocalStackEnabled()) {
|
||||
secretsClientOptions.endpoint = InstanceLocalStackEndpoint();
|
||||
const isLocal = isString(process.env?.LOCALSTACK_HOSTNAME) && !isEmpty(process.env?.LOCALSTACK_HOSTNAME);
|
||||
|
||||
if (isLocal) {
|
||||
secretsClientOptions.endpoint = `http://${process.env.LOCALSTACK_HOSTNAME}:4566`;
|
||||
}
|
||||
|
||||
const secretsClient = new SecretsManagerClient(secretsClientOptions);
|
||||
|
||||
@@ -3,7 +3,7 @@ const Dinero = require("dinero.js");
|
||||
const moment = require("moment-timezone");
|
||||
const logger = require("../utils/logger");
|
||||
const InstanceManager = require("../utils/instanceMgr").default;
|
||||
const { InstanceIsLocalStackEnabled } = require("../utils/instanceMgr");
|
||||
const { isString, isEmpty } = require("lodash");
|
||||
const fs = require("fs");
|
||||
const client = require("../graphql-client/graphql-client").client;
|
||||
const { sendServerEmail, sendMexicoBillingEmail } = require("../email/sendemail");
|
||||
@@ -35,9 +35,10 @@ const S3_BUCKET_NAME = InstanceManager({
|
||||
rome: "rome-carfax-uploads"
|
||||
});
|
||||
const region = InstanceManager.InstanceRegion;
|
||||
const isLocal = isString(process.env?.LOCALSTACK_HOSTNAME) && !isEmpty(process.env?.LOCALSTACK_HOSTNAME);
|
||||
|
||||
const uploadToS3 = (jsonObj, bucketName = S3_BUCKET_NAME) => {
|
||||
const webPath = InstanceIsLocalStackEnabled()
|
||||
const webPath = isLocal
|
||||
? `https://${bucketName}.s3.localhost.localstack.cloud:4566/${jsonObj.filename}`
|
||||
: `https://${bucketName}.s3.${region}.amazonaws.com/${jsonObj.filename}`;
|
||||
|
||||
|
||||
@@ -5,8 +5,7 @@ const logger = require("../utils/logger");
|
||||
const fs = require("fs");
|
||||
const { SecretsManagerClient, GetSecretValueCommand } = require("@aws-sdk/client-secrets-manager");
|
||||
const { defaultProvider } = require("@aws-sdk/credential-provider-node");
|
||||
const { InstanceIsLocalStackEnabled, InstanceLocalStackEndpoint } = require("../utils/instanceMgr");
|
||||
|
||||
const { isString, isEmpty } = require("lodash");
|
||||
let Client = require("ssh2-sftp-client");
|
||||
|
||||
const client = require("../graphql-client/graphql-client").client;
|
||||
@@ -152,8 +151,10 @@ async function getPrivateKey() {
|
||||
credentials: defaultProvider()
|
||||
};
|
||||
|
||||
if (InstanceIsLocalStackEnabled()) {
|
||||
secretsClientOptions.endpoint = InstanceLocalStackEndpoint();
|
||||
const isLocal = isString(process.env?.LOCALSTACK_HOSTNAME) && !isEmpty(process.env?.LOCALSTACK_HOSTNAME);
|
||||
|
||||
if (isLocal) {
|
||||
secretsClientOptions.endpoint = `http://${process.env.LOCALSTACK_HOSTNAME}:4566`;
|
||||
}
|
||||
|
||||
const client = new SecretsManagerClient(secretsClientOptions);
|
||||
|
||||
@@ -1,17 +1,20 @@
|
||||
const { isString, isEmpty } = require("lodash");
|
||||
const { defaultProvider } = require("@aws-sdk/credential-provider-node");
|
||||
const { InstanceRegion, InstanceIsLocalStackEnabled, InstanceLocalStackEndpoint } = require("../utils/instanceMgr");
|
||||
const { InstanceRegion } = require("../utils/instanceMgr");
|
||||
const aws = require("@aws-sdk/client-ses");
|
||||
const nodemailer = require("nodemailer");
|
||||
const logger = require("../utils/logger");
|
||||
|
||||
const isLocal = isString(process.env?.LOCALSTACK_HOSTNAME) && !isEmpty(process.env?.LOCALSTACK_HOSTNAME);
|
||||
|
||||
const sesConfig = {
|
||||
apiVersion: "latest",
|
||||
credentials: defaultProvider(),
|
||||
region: InstanceRegion()
|
||||
};
|
||||
|
||||
if (InstanceIsLocalStackEnabled()) {
|
||||
sesConfig.endpoint = InstanceLocalStackEndpoint();
|
||||
if (isLocal) {
|
||||
sesConfig.endpoint = `http://${process.env.LOCALSTACK_HOSTNAME}:4566`;
|
||||
logger.logger.debug(`SES Mailer set to LocalStack end point: ${sesConfig.endpoint}`);
|
||||
}
|
||||
|
||||
|
||||
@@ -46,11 +46,6 @@ const summarizeAllocationsArray = (arr) =>
|
||||
cost: summarizeMoney(a.cost)
|
||||
}));
|
||||
|
||||
const toFiniteNumber = (value) => {
|
||||
const parsed = Number.parseFloat(value);
|
||||
return Number.isFinite(parsed) ? parsed : 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* Internal per-center bucket shape for *sales*.
|
||||
* We keep separate buckets for RR so we can split
|
||||
@@ -67,8 +62,6 @@ function emptyCenterBucket() {
|
||||
// Labor
|
||||
laborTaxableSale: zero, // labor that should be taxed in RR
|
||||
laborNonTaxableSale: zero, // labor that should NOT be taxed in RR
|
||||
laborTaxableHours: 0,
|
||||
laborNonTaxableHours: 0,
|
||||
|
||||
// Extras (MAPA/MASH/towing/PAO/etc)
|
||||
extrasSale: zero, // total extras (taxable + non-taxable)
|
||||
@@ -460,7 +453,6 @@ function buildProfitCenterHash(job, debugLog, taxContext) {
|
||||
|
||||
const rateKey = `rate_${val.mod_lbr_ty.toLowerCase()}`;
|
||||
const rate = job[rateKey];
|
||||
const lineHours = toFiniteNumber(val.mod_lb_hrs);
|
||||
|
||||
const laborAmount = Dinero({
|
||||
amount: Math.round(rate * 100)
|
||||
@@ -468,10 +460,8 @@ function buildProfitCenterHash(job, debugLog, taxContext) {
|
||||
|
||||
if (isLaborTaxable(val, taxContext)) {
|
||||
bucket.laborTaxableSale = bucket.laborTaxableSale.add(laborAmount);
|
||||
bucket.laborTaxableHours += lineHours;
|
||||
} else {
|
||||
bucket.laborNonTaxableSale = bucket.laborNonTaxableSale.add(laborAmount);
|
||||
bucket.laborNonTaxableHours += lineHours;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -488,8 +478,6 @@ function buildProfitCenterHash(job, debugLog, taxContext) {
|
||||
partsNonTaxable: summarizeMoney(b.partsNonTaxableSale),
|
||||
laborTaxable: summarizeMoney(b.laborTaxableSale),
|
||||
laborNonTaxable: summarizeMoney(b.laborNonTaxableSale),
|
||||
laborTaxableHours: b.laborTaxableHours,
|
||||
laborNonTaxableHours: b.laborNonTaxableHours,
|
||||
extras: summarizeMoney(b.extrasSale),
|
||||
extrasTaxable: summarizeMoney(b.extrasTaxableSale),
|
||||
extrasNonTaxable: summarizeMoney(b.extrasNonTaxableSale)
|
||||
@@ -928,8 +916,6 @@ function buildJobAllocations(bodyshop, profitCenterHash, costCenterHash, debugLo
|
||||
// Labor
|
||||
laborTaxableSale: bucket.laborTaxableSale,
|
||||
laborNonTaxableSale: bucket.laborNonTaxableSale,
|
||||
laborTaxableHours: bucket.laborTaxableHours,
|
||||
laborNonTaxableHours: bucket.laborNonTaxableHours,
|
||||
|
||||
// Extras
|
||||
extrasSale,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const { buildRRRepairOrderPayload, buildMinimalRolaborFromJob } = require("./rr-job-helpers");
|
||||
const { buildRRRepairOrderPayload } = require("./rr-job-helpers");
|
||||
const { buildClientAndOpts } = require("./rr-lookup");
|
||||
const CreateRRLogEvent = require("./rr-logger-event");
|
||||
const { withRRRequestXml } = require("./rr-log-xml");
|
||||
@@ -56,27 +56,6 @@ const deriveRRStatus = (rrRes = {}) => {
|
||||
};
|
||||
};
|
||||
|
||||
const resolveRROpCode = (bodyshop, txEnvelope = {}) => {
|
||||
const resolvedBaseOpCode = resolveRROpCodeFromBodyshop(bodyshop);
|
||||
let opCodeOverride = txEnvelope?.opCode || txEnvelope?.opcode || txEnvelope?.op_code || null;
|
||||
|
||||
if (!opCodeOverride) {
|
||||
const opPrefix = txEnvelope?.opPrefix ?? txEnvelope?.op_prefix ?? null;
|
||||
const opBase = txEnvelope?.opBase ?? txEnvelope?.op_base ?? null;
|
||||
const opSuffix = txEnvelope?.opSuffix ?? txEnvelope?.op_suffix ?? null;
|
||||
|
||||
if (opPrefix || opBase || opSuffix) {
|
||||
const combined = `${opPrefix || ""}${opBase || ""}${opSuffix || ""}`.trim();
|
||||
if (combined) {
|
||||
opCodeOverride = combined;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!opCodeOverride && !resolvedBaseOpCode) return null;
|
||||
return String(opCodeOverride || resolvedBaseOpCode).trim() || null;
|
||||
};
|
||||
|
||||
/**
|
||||
* Early RO Creation: Create a minimal RR Repair Order with basic info (customer, advisor, mileage, story).
|
||||
* Used when creating RO from convert button or admin page before full job export.
|
||||
@@ -114,9 +93,7 @@ const createMinimalRRRepairOrder = async (args) => {
|
||||
const story = txEnvelope?.story ? String(txEnvelope.story).trim() : null;
|
||||
const makeOverride = txEnvelope?.makeOverride ? String(txEnvelope.makeOverride).trim() : null;
|
||||
|
||||
// Build minimal RO payload for early review mode.
|
||||
// We keep it lightweight, but include a single labor row when we can so Ignite
|
||||
// exposes the labor subsection for editing.
|
||||
// Build minimal RO payload - just header, no allocations/parts/labor
|
||||
const cleanVin =
|
||||
(job?.v_vin || "")
|
||||
.toString()
|
||||
@@ -139,12 +116,6 @@ const createMinimalRRRepairOrder = async (args) => {
|
||||
resolvedMileageIn: mileageIn
|
||||
});
|
||||
|
||||
const earlyRoOpCode = resolveRROpCode(bodyshop, txEnvelope);
|
||||
const earlyRoLabor = buildMinimalRolaborFromJob(job, {
|
||||
opCode: earlyRoOpCode,
|
||||
payType: "Cust"
|
||||
});
|
||||
|
||||
const payload = {
|
||||
customerNo: String(selected),
|
||||
advisorNo: String(advisorNo),
|
||||
@@ -170,14 +141,9 @@ const createMinimalRRRepairOrder = async (args) => {
|
||||
if (makeOverride) {
|
||||
payload.makeOverride = makeOverride;
|
||||
}
|
||||
if (earlyRoLabor) {
|
||||
payload.rolabor = earlyRoLabor;
|
||||
}
|
||||
|
||||
CreateRRLogEvent(socket, "INFO", "Creating minimal RR Repair Order (early creation)", {
|
||||
payload,
|
||||
earlyRoOpCode,
|
||||
hasRolabor: !!earlyRoLabor
|
||||
payload
|
||||
});
|
||||
|
||||
const response = await client.createRepairOrder(payload, finalOpts);
|
||||
@@ -255,10 +221,15 @@ const updateRRRepairOrderWithFullData = async (args) => {
|
||||
const story = txEnvelope?.story ? String(txEnvelope.story).trim() : null;
|
||||
const makeOverride = txEnvelope?.makeOverride ? String(txEnvelope.makeOverride).trim() : null;
|
||||
|
||||
// Optional RR OpCode segments coming from the FE (RRPostForm)
|
||||
const opPrefix = txEnvelope?.opPrefix ?? txEnvelope?.op_prefix ?? null;
|
||||
const opBase = txEnvelope?.opBase ?? txEnvelope?.op_base ?? null;
|
||||
const opSuffix = txEnvelope?.opSuffix ?? txEnvelope?.op_suffix ?? null;
|
||||
|
||||
// RR-only extras
|
||||
let rrCentersConfig = null;
|
||||
let allocations = null;
|
||||
const opCode = resolveRROpCode(bodyshop, txEnvelope);
|
||||
let opCode = null;
|
||||
|
||||
// 1) Responsibility center config (for visibility / debugging)
|
||||
try {
|
||||
@@ -309,9 +280,28 @@ const updateRRRepairOrderWithFullData = async (args) => {
|
||||
allocations = [];
|
||||
}
|
||||
|
||||
const resolvedBaseOpCode = resolveRROpCodeFromBodyshop(bodyshop);
|
||||
|
||||
let opCodeOverride = txEnvelope?.opCode || txEnvelope?.opcode || txEnvelope?.op_code || null;
|
||||
|
||||
// If the FE only sends segments, combine them here.
|
||||
if (!opCodeOverride && (opPrefix || opBase || opSuffix)) {
|
||||
const combined = `${opPrefix || ""}${opBase || ""}${opSuffix || ""}`.trim();
|
||||
if (combined) {
|
||||
opCodeOverride = combined;
|
||||
}
|
||||
}
|
||||
|
||||
if (opCodeOverride || resolvedBaseOpCode) {
|
||||
opCode = String(opCodeOverride || resolvedBaseOpCode).trim() || null;
|
||||
}
|
||||
|
||||
CreateRRLogEvent(socket, "SILLY", "RR OP config resolved", {
|
||||
opCode,
|
||||
baseFromConfig: resolveRROpCodeFromBodyshop(bodyshop)
|
||||
baseFromConfig: resolvedBaseOpCode,
|
||||
opPrefix,
|
||||
opBase,
|
||||
opSuffix
|
||||
});
|
||||
|
||||
// Build full RO payload for update with allocations
|
||||
@@ -436,10 +426,15 @@ const exportJobToRR = async (args) => {
|
||||
const story = txEnvelope?.story ? String(txEnvelope.story).trim() : null;
|
||||
const makeOverride = txEnvelope?.makeOverride ? String(txEnvelope.makeOverride).trim() : null;
|
||||
|
||||
// Optional RR OpCode segments coming from the FE (RRPostForm)
|
||||
const opPrefix = txEnvelope?.opPrefix ?? txEnvelope?.op_prefix ?? null;
|
||||
const opBase = txEnvelope?.opBase ?? txEnvelope?.op_base ?? null;
|
||||
const opSuffix = txEnvelope?.opSuffix ?? txEnvelope?.op_suffix ?? null;
|
||||
|
||||
// RR-only extras
|
||||
let rrCentersConfig = null;
|
||||
let allocations = null;
|
||||
const opCode = resolveRROpCode(bodyshop, txEnvelope);
|
||||
let opCode = null;
|
||||
|
||||
// 1) Responsibility center config (for visibility / debugging)
|
||||
try {
|
||||
@@ -482,9 +477,28 @@ const exportJobToRR = async (args) => {
|
||||
allocations = [];
|
||||
}
|
||||
|
||||
const resolvedBaseOpCode = resolveRROpCodeFromBodyshop(bodyshop);
|
||||
|
||||
let opCodeOverride = txEnvelope?.opCode || txEnvelope?.opcode || txEnvelope?.op_code || null;
|
||||
|
||||
// If the FE only sends segments, combine them here.
|
||||
if (!opCodeOverride && (opPrefix || opBase || opSuffix)) {
|
||||
const combined = `${opPrefix || ""}${opBase || ""}${opSuffix || ""}`.trim();
|
||||
if (combined) {
|
||||
opCodeOverride = combined;
|
||||
}
|
||||
}
|
||||
|
||||
if (opCodeOverride || resolvedBaseOpCode) {
|
||||
opCode = String(opCodeOverride || resolvedBaseOpCode).trim() || null;
|
||||
}
|
||||
|
||||
CreateRRLogEvent(socket, "SILLY", "RR OP config resolved", {
|
||||
opCode,
|
||||
baseFromConfig: resolveRROpCodeFromBodyshop(bodyshop)
|
||||
baseFromConfig: resolvedBaseOpCode,
|
||||
opPrefix,
|
||||
opBase,
|
||||
opSuffix
|
||||
});
|
||||
|
||||
// Build RO payload for create.
|
||||
|
||||
@@ -52,19 +52,6 @@ const asN2 = (dineroLike) => {
|
||||
return amount.toFixed(2);
|
||||
};
|
||||
|
||||
const toFiniteNumber = (value) => {
|
||||
if (typeof value === "number") {
|
||||
return Number.isFinite(value) ? value : 0;
|
||||
}
|
||||
|
||||
if (typeof value === "string") {
|
||||
const parsed = Number.parseFloat(value);
|
||||
return Number.isFinite(parsed) ? parsed : 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* Normalize various "money-like" shapes to integer cents.
|
||||
* Supports:
|
||||
@@ -113,100 +100,6 @@ const toMoneyCents = (value) => {
|
||||
|
||||
const asN2FromCents = (cents) => asN2({ amount: Number.isFinite(cents) ? cents : 0, precision: 2 });
|
||||
|
||||
const formatDecimal = (value, maxDecimals = 2) => {
|
||||
const factor = Math.pow(10, maxDecimals);
|
||||
const rounded = Math.round(Math.max(0, toFiniteNumber(value)) * factor) / factor;
|
||||
if (!Number.isFinite(rounded)) return "0";
|
||||
return rounded.toFixed(maxDecimals).replace(/\.?0+$/, "") || "0";
|
||||
};
|
||||
|
||||
const buildRolaborBillFields = ({ amountUnits = 0, hours = 0, rate = 0 } = {}) => {
|
||||
const normalizedAmount = toFiniteNumber(amountUnits);
|
||||
|
||||
if (normalizedAmount <= 0) {
|
||||
return {
|
||||
jobTotalHrs: "0",
|
||||
billTime: "0",
|
||||
billRate: "0"
|
||||
};
|
||||
}
|
||||
|
||||
let resolvedHours = toFiniteNumber(hours);
|
||||
let resolvedRate = toFiniteNumber(rate);
|
||||
|
||||
if (resolvedHours > 0 && resolvedRate <= 0) {
|
||||
resolvedRate = normalizedAmount / resolvedHours;
|
||||
} else if (resolvedRate > 0 && resolvedHours <= 0) {
|
||||
resolvedHours = normalizedAmount / resolvedRate;
|
||||
} else if (resolvedHours <= 0 && resolvedRate <= 0) {
|
||||
// Keep the math internally consistent even if the source job has dollars but no usable hours.
|
||||
resolvedHours = 1;
|
||||
resolvedRate = normalizedAmount;
|
||||
}
|
||||
|
||||
return {
|
||||
jobTotalHrs: formatDecimal(resolvedHours),
|
||||
billTime: formatDecimal(resolvedHours),
|
||||
billRate: resolvedRate.toFixed(2)
|
||||
};
|
||||
};
|
||||
|
||||
const buildMinimalRolaborFromJob = (job, { opCode, payType = "Cust" } = {}) => {
|
||||
const trimmedOpCode = opCode != null ? String(opCode).trim() : "";
|
||||
if (!job || !trimmedOpCode) return null;
|
||||
|
||||
let totalHours = 0;
|
||||
let totalAmountUnits = 0;
|
||||
|
||||
for (const line of job?.joblines || []) {
|
||||
const laborType = typeof line?.mod_lbr_ty === "string" ? line.mod_lbr_ty.trim() : "";
|
||||
if (!laborType) continue;
|
||||
|
||||
const lineHours = toFiniteNumber(line?.mod_lb_hrs ?? line?.db_hrs);
|
||||
const configuredRate = toFiniteNumber(job?.[`rate_${laborType.toLowerCase()}`]);
|
||||
let lineAmountUnits = toFiniteNumber(line?.lbr_amt);
|
||||
|
||||
if (lineAmountUnits <= 0 && lineHours > 0 && configuredRate > 0) {
|
||||
lineAmountUnits = lineHours * configuredRate;
|
||||
}
|
||||
|
||||
if (lineAmountUnits <= 0 && lineHours <= 0) continue;
|
||||
|
||||
totalHours += lineHours;
|
||||
totalAmountUnits += lineAmountUnits;
|
||||
}
|
||||
|
||||
if (totalAmountUnits <= 0 && totalHours <= 0) return null;
|
||||
|
||||
const bill = buildRolaborBillFields({
|
||||
amountUnits: totalAmountUnits,
|
||||
hours: totalHours,
|
||||
rate: totalHours > 0 ? totalAmountUnits / totalHours : 0
|
||||
});
|
||||
const formattedAmount = totalAmountUnits.toFixed(2);
|
||||
|
||||
return {
|
||||
ops: [
|
||||
{
|
||||
opCode: trimmedOpCode,
|
||||
jobNo: "1",
|
||||
custPayTypeFlag: "C",
|
||||
custTxblNtxblFlag: toFiniteNumber(job?.tax_lbr_rt) > 0 ? "T" : "N",
|
||||
bill: {
|
||||
payType,
|
||||
...bill
|
||||
},
|
||||
amount: {
|
||||
payType,
|
||||
amtType: "Job",
|
||||
custPrice: formattedAmount,
|
||||
totalAmt: formattedAmount
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Build RR estimate block from allocation totals.
|
||||
* @param {Array} allocations
|
||||
@@ -433,13 +326,6 @@ const buildRogogFromAllocations = (allocations, { opCode, payType = "Cust", roNo
|
||||
// Each segment becomes its own op / JobNo with a single line
|
||||
segments.forEach((seg, idx) => {
|
||||
const jobNo = String(ops.length + 1); // global, 1-based JobNo across all centers/segments
|
||||
const isLaborSegment = seg.kind === "laborTaxable" || seg.kind === "laborNonTaxable";
|
||||
const segmentHours = isLaborSegment
|
||||
? seg.kind === "laborTaxable"
|
||||
? toFiniteNumber(alloc.laborTaxableHours)
|
||||
: toFiniteNumber(alloc.laborNonTaxableHours)
|
||||
: 0;
|
||||
const segmentBillRate = isLaborSegment && segmentHours > 0 ? seg.saleCents / 100 / segmentHours : 0;
|
||||
|
||||
const line = {
|
||||
breakOut,
|
||||
@@ -463,9 +349,7 @@ const buildRogogFromAllocations = (allocations, { opCode, payType = "Cust", roNo
|
||||
// Extra metadata for UI / debugging
|
||||
segmentKind: seg.kind,
|
||||
segmentIndex: idx,
|
||||
segmentCount,
|
||||
segmentHours,
|
||||
segmentBillRate
|
||||
segmentCount
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -484,9 +368,9 @@ const buildRogogFromAllocations = (allocations, { opCode, payType = "Cust", roNo
|
||||
*
|
||||
* We still keep a 1:1 mapping with GOG ops: each op gets a corresponding
|
||||
* OpCodeLaborInfo entry using the same JobNo and the same tax flag as its
|
||||
* GOG line. Labor sale amounts are mirrored into ROLABOR and, when hours
|
||||
* are available from allocations, weighted bill hours/rates are also
|
||||
* populated so the labor subsection is editable in Ignite.
|
||||
* GOG line. Labor-specific hours/rate remain zeroed out, but actual labor
|
||||
* sale amounts are mirrored into ROLABOR for labor segments so RR receives
|
||||
* the expected labor pricing on updates. Non-labor ops remain zeroed.
|
||||
*
|
||||
* @param {Object} rogg - result of buildRogogFromAllocations
|
||||
* @param {Object} opts
|
||||
@@ -507,17 +391,6 @@ const buildRolaborFromRogog = (rogg, { payType = "Cust" } = {}) => {
|
||||
const linePayType = firstLine.custPayTypeFlag || "C";
|
||||
const isLaborSegment = op.segmentKind === "laborTaxable" || op.segmentKind === "laborNonTaxable";
|
||||
const laborAmount = isLaborSegment ? String(firstLine?.amount?.custPrice ?? "0") : "0";
|
||||
const laborBill = isLaborSegment
|
||||
? buildRolaborBillFields({
|
||||
amountUnits: laborAmount,
|
||||
hours: op.segmentHours,
|
||||
rate: op.segmentBillRate
|
||||
})
|
||||
: {
|
||||
jobTotalHrs: "0",
|
||||
billTime: "0",
|
||||
billRate: "0"
|
||||
};
|
||||
|
||||
return {
|
||||
opCode: op.opCode,
|
||||
@@ -526,7 +399,9 @@ const buildRolaborFromRogog = (rogg, { payType = "Cust" } = {}) => {
|
||||
custTxblNtxblFlag: txFlag,
|
||||
bill: {
|
||||
payType,
|
||||
...laborBill
|
||||
jobTotalHrs: "0",
|
||||
billTime: "0",
|
||||
billRate: "0"
|
||||
},
|
||||
amount: {
|
||||
payType,
|
||||
@@ -811,6 +686,5 @@ module.exports = {
|
||||
normalizeCustomerCandidates,
|
||||
normalizeVehicleCandidates,
|
||||
buildRogogFromAllocations,
|
||||
buildRolaborFromRogog,
|
||||
buildMinimalRolaborFromJob
|
||||
buildRolaborFromRogog
|
||||
};
|
||||
|
||||
@@ -1,118 +0,0 @@
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import { createRequire } from "node:module";
|
||||
|
||||
const require = createRequire(import.meta.url);
|
||||
const mock = require("mock-require");
|
||||
|
||||
const graphClientModuleId = require.resolve("../graphql-client/graphql-client");
|
||||
const queriesModuleId = require.resolve("../graphql-client/queries");
|
||||
const helpersModuleId = require.resolve("./rr-job-helpers");
|
||||
|
||||
const loadHelpers = () => {
|
||||
mock.stopAll();
|
||||
mock(graphClientModuleId, { client: { request: async () => ({}) } });
|
||||
mock(queriesModuleId, { GET_JOB_BY_PK: "GET_JOB_BY_PK" });
|
||||
delete require.cache[helpersModuleId];
|
||||
return require(helpersModuleId);
|
||||
};
|
||||
|
||||
afterEach(() => {
|
||||
mock.stopAll();
|
||||
delete require.cache[helpersModuleId];
|
||||
});
|
||||
|
||||
describe("server/rr/rr-job-helpers", () => {
|
||||
it("builds a single early-RO labor row from aggregated job labor", () => {
|
||||
const { buildMinimalRolaborFromJob } = loadHelpers();
|
||||
|
||||
const rolabor = buildMinimalRolaborFromJob(
|
||||
{
|
||||
tax_lbr_rt: 13,
|
||||
joblines: [
|
||||
{ mod_lbr_ty: "LAB", mod_lb_hrs: 2, lbr_amt: 200 },
|
||||
{ mod_lbr_ty: "LAD", mod_lb_hrs: 1.5, lbr_amt: 180 }
|
||||
]
|
||||
},
|
||||
{ opCode: "51DOZ" }
|
||||
);
|
||||
|
||||
expect(rolabor).toEqual({
|
||||
ops: [
|
||||
{
|
||||
opCode: "51DOZ",
|
||||
jobNo: "1",
|
||||
custPayTypeFlag: "C",
|
||||
custTxblNtxblFlag: "T",
|
||||
bill: {
|
||||
payType: "Cust",
|
||||
jobTotalHrs: "3.5",
|
||||
billTime: "3.5",
|
||||
billRate: "108.57"
|
||||
},
|
||||
amount: {
|
||||
payType: "Cust",
|
||||
amtType: "Job",
|
||||
custPrice: "380.00",
|
||||
totalAmt: "380.00"
|
||||
}
|
||||
}
|
||||
]
|
||||
});
|
||||
});
|
||||
|
||||
it("populates labor bill fields from allocation hours on the full RR payload", () => {
|
||||
const { buildRRRepairOrderPayload } = loadHelpers();
|
||||
|
||||
const payload = buildRRRepairOrderPayload({
|
||||
job: {
|
||||
id: "job-1",
|
||||
ro_number: "RO-123",
|
||||
v_vin: "1HGBH41JXMN109186"
|
||||
},
|
||||
selectedCustomer: { customerNo: "1134485" },
|
||||
advisorNo: "70754",
|
||||
allocations: [
|
||||
{
|
||||
center: "Body Labor",
|
||||
partsSale: { amount: 0, precision: 2 },
|
||||
laborTaxableSale: { amount: 24000, precision: 2 },
|
||||
laborNonTaxableSale: { amount: 0, precision: 2 },
|
||||
extrasSale: { amount: 0, precision: 2 },
|
||||
totalSale: { amount: 24000, precision: 2 },
|
||||
cost: { amount: 12000, precision: 2 },
|
||||
laborTaxableHours: 2,
|
||||
laborNonTaxableHours: 0,
|
||||
profitCenter: {
|
||||
rr_gogcode: "BL",
|
||||
rr_item_type: "G",
|
||||
accountdesc: "BODY LABOR"
|
||||
}
|
||||
}
|
||||
],
|
||||
opCode: "51DOZ"
|
||||
});
|
||||
|
||||
expect(payload.rolabor).toEqual({
|
||||
ops: [
|
||||
{
|
||||
opCode: "51DOZ",
|
||||
jobNo: "1",
|
||||
custPayTypeFlag: "C",
|
||||
custTxblNtxblFlag: "T",
|
||||
bill: {
|
||||
payType: "Cust",
|
||||
jobTotalHrs: "2",
|
||||
billTime: "2",
|
||||
billRate: "120.00"
|
||||
},
|
||||
amount: {
|
||||
payType: "Cust",
|
||||
amtType: "Job",
|
||||
custPrice: "240.00",
|
||||
totalAmt: "240.00"
|
||||
}
|
||||
}
|
||||
]
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -7,24 +7,14 @@
|
||||
* @property { string | object | function } promanager Return this prop if Rome.
|
||||
* @property { string | object | function } imex Return this prop if Rome.
|
||||
*/
|
||||
const { isString, isEmpty } = require("lodash");
|
||||
|
||||
/**
|
||||
* InstanceManager is a utility function that determines which property to return based on the current instance type.
|
||||
* @param param0
|
||||
* @param param0.args
|
||||
* @param param0.instance
|
||||
* @param param0.debug
|
||||
* @param param0.executeFunction
|
||||
* @param param0.rome
|
||||
* @param param0.promanager
|
||||
* @param param0.imex
|
||||
* @returns {*|null}
|
||||
* @constructor
|
||||
*/
|
||||
const InstanceManager = ({ args, instance, debug, executeFunction, rome, promanager, imex }) => {
|
||||
function InstanceManager({ args, instance, debug, executeFunction, rome, promanager, imex }) {
|
||||
let propToReturn = null;
|
||||
|
||||
//TODO: Remove after debugging.
|
||||
if (promanager) {
|
||||
console.trace("ProManager Prop was used");
|
||||
}
|
||||
switch (instance || process.env.INSTANCE) {
|
||||
case "IMEX":
|
||||
propToReturn = imex;
|
||||
@@ -60,42 +50,15 @@ const InstanceManager = ({ args, instance, debug, executeFunction, rome, promana
|
||||
}
|
||||
if (executeFunction && typeof propToReturn === "function") return propToReturn(...args);
|
||||
return propToReturn === undefined ? null : propToReturn;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the AWS region to be used for the current instance, which is determined by the INSTANCE environment variable.
|
||||
* @returns {*}
|
||||
* @constructor
|
||||
*/
|
||||
const InstanceRegion = () =>
|
||||
exports.InstanceRegion = () =>
|
||||
InstanceManager({
|
||||
imex: "ca-central-1",
|
||||
rome: "us-east-2"
|
||||
});
|
||||
|
||||
/**
|
||||
* Checks if the instance is configured to use LocalStack by verifying the presence of the LOCALSTACK_HOSTNAME
|
||||
* environment variable.
|
||||
* @returns {boolean}
|
||||
* @constructor
|
||||
*/
|
||||
const InstanceIsLocalStackEnabled = () =>
|
||||
isString(process.env?.LOCALSTACK_HOSTNAME) && !isEmpty(process.env?.LOCALSTACK_HOSTNAME);
|
||||
|
||||
/**
|
||||
* Returns the LocalStack endpoint URL based on the LOCALSTACK_HOSTNAME environment variable.
|
||||
* @returns {`http://${*}:4566`}
|
||||
* @constructor
|
||||
*/
|
||||
const InstanceLocalStackEndpoint = () => `http://${process.env.LOCALSTACK_HOSTNAME}:4566`;
|
||||
|
||||
/**
|
||||
* Returns the appropriate endpoints for the current instance, which can be used for making API calls or other network
|
||||
* requests.
|
||||
* @returns {*|null}
|
||||
* @constructor
|
||||
*/
|
||||
const InstanceEndpoints = () =>
|
||||
exports.InstanceEndpoints = () =>
|
||||
InstanceManager({
|
||||
imex:
|
||||
process.env?.NODE_ENV === "development"
|
||||
@@ -111,11 +74,4 @@ const InstanceEndpoints = () =>
|
||||
: "https://romeonline.io"
|
||||
});
|
||||
|
||||
module.exports = {
|
||||
InstanceManager,
|
||||
InstanceRegion,
|
||||
InstanceIsLocalStackEnabled,
|
||||
InstanceLocalStackEndpoint,
|
||||
InstanceEndpoints,
|
||||
default: InstanceManager
|
||||
};
|
||||
exports.default = InstanceManager;
|
||||
|
||||
@@ -2,9 +2,10 @@
|
||||
const InstanceManager = require("../utils/instanceMgr").default;
|
||||
const winston = require("winston");
|
||||
const WinstonCloudWatch = require("winston-cloudwatch");
|
||||
const { isString, isEmpty } = require("lodash");
|
||||
const { uploadFileToS3 } = require("./s3");
|
||||
const { v4 } = require("uuid");
|
||||
const { InstanceRegion, InstanceIsLocalStackEnabled, InstanceLocalStackEndpoint } = require("./instanceMgr");
|
||||
const { InstanceRegion } = require("./instanceMgr");
|
||||
const getHostNameOrIP = require("./getHostNameOrIP");
|
||||
const client = require("../graphql-client/graphql-client").client;
|
||||
const queries = require("../graphql-client/queries");
|
||||
@@ -47,7 +48,7 @@ const normalizeLevel = (level) => (level ? level.toLowerCase() : LOG_LEVELS.debu
|
||||
|
||||
const createLogger = () => {
|
||||
try {
|
||||
const isLocal = InstanceIsLocalStackEnabled();
|
||||
const isLocal = isString(process.env?.LOCALSTACK_HOSTNAME) && !isEmpty(process.env?.LOCALSTACK_HOSTNAME);
|
||||
const logGroupName = isLocal ? "development" : process.env.CLOUDWATCH_LOG_GROUP;
|
||||
|
||||
const winstonCloudwatchTransportDefaults = {
|
||||
@@ -59,7 +60,7 @@ const createLogger = () => {
|
||||
};
|
||||
|
||||
if (isLocal) {
|
||||
winstonCloudwatchTransportDefaults.awsOptions.endpoint = InstanceLocalStackEndpoint();
|
||||
winstonCloudwatchTransportDefaults.awsOptions.endpoint = `http://${process.env.LOCALSTACK_HOSTNAME}:4566`;
|
||||
}
|
||||
|
||||
const levelFilter = (levels) => {
|
||||
|
||||
@@ -7,7 +7,8 @@ const {
|
||||
CopyObjectCommand
|
||||
} = require("@aws-sdk/client-s3");
|
||||
const { defaultProvider } = require("@aws-sdk/credential-provider-node");
|
||||
const { InstanceRegion, InstanceIsLocalStackEnabled, InstanceLocalStackEndpoint } = require("./instanceMgr");
|
||||
const { InstanceRegion } = require("./instanceMgr");
|
||||
const { isString, isEmpty } = require("lodash");
|
||||
const { getSignedUrl } = require("@aws-sdk/s3-request-presigner");
|
||||
|
||||
const createS3Client = () => {
|
||||
@@ -16,8 +17,10 @@ const createS3Client = () => {
|
||||
credentials: defaultProvider()
|
||||
};
|
||||
|
||||
if (InstanceIsLocalStackEnabled()) {
|
||||
S3Options.endpoint = InstanceLocalStackEndpoint();
|
||||
const isLocal = isString(process.env?.LOCALSTACK_HOSTNAME) && !isEmpty(process.env?.LOCALSTACK_HOSTNAME);
|
||||
|
||||
if (isLocal) {
|
||||
S3Options.endpoint = `http://${process.env.LOCALSTACK_HOSTNAME}:4566`;
|
||||
S3Options.forcePathStyle = true; // Needed for LocalStack to avoid bucket name as hostname
|
||||
}
|
||||
|
||||
@@ -102,7 +105,7 @@ const createS3Client = () => {
|
||||
});
|
||||
const presignedUrl = await getSignedUrl(s3Client, command, { expiresIn: 360 });
|
||||
return presignedUrl;
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
uploadFileToS3,
|
||||
@@ -116,4 +119,7 @@ const createS3Client = () => {
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
module.exports = createS3Client();
|
||||
|
||||
Reference in New Issue
Block a user