feature/IO-3357-Reynolds-and-Reynolds-DMS-API-Integration -Full Flow verified

This commit is contained in:
Dave
2025-11-20 14:52:39 -05:00
parent 34f45379a6
commit c3bc29fa9b
7 changed files with 298 additions and 222 deletions

View File

@@ -161,100 +161,6 @@ const buildRolaborFromRogog = (rogg, { payType = "Cust" } = {}) => {
return { ops };
};
/**
* Build a header-level TaxCodeInfo payload from allocations (e.g. PROVINCIAL SALES TAX line).
*
* Shape returned matches what `buildCreateRepairOrder` expects for:
*
* payload.tax = {
* payType,
* taxCode,
* txblGrossAmt,
* grossTaxAmt
* }
*
* NOTE: We are currently NOT wiring this into the payload (see buildRRRepairOrderPayload)
* so that TaxCodeInfo is suppressed in the XML, but we keep this helper around for
* future use.
*
* @param {Array} allocations
* @param {Object} opts
* @param {string} opts.taxCode - RR tax code (configured per dealer)
* @param {string} [opts.payType="Cust"]
* @returns {null|{payType, taxCode, txblGrossAmt, grossTaxAmt}}
*/
const buildTaxFromAllocations = (allocations, { taxCode, payType = "Cust" } = {}) => {
if (!taxCode || !Array.isArray(allocations) || !allocations.length) return null;
const taxAlloc = allocations.find((a) => a && a.tax);
if (!taxAlloc || !taxAlloc.sale) return null;
const grossTaxNum = parseFloat(asN2(taxAlloc.sale));
if (!Number.isFinite(grossTaxNum)) return null;
const rate = typeof taxAlloc.profitCenter?.rate === "number" ? taxAlloc.profitCenter.rate : null;
let taxableGrossNum = grossTaxNum;
if (rate && rate > 0) {
const r = rate / 100;
taxableGrossNum = grossTaxNum / r;
}
return {
payType,
taxCode,
txblGrossAmt: taxableGrossNum.toFixed(2),
grossTaxAmt: grossTaxNum.toFixed(2)
};
};
/**
* Build a minimal Rolabor structure in the new normalized shape.
*
* Useful for tests or for scenarios where you want a single zero-dollar
* Rolabor op but don't have GOG data. Shape matches payload.rolabor for the
* reynolds-rome-client builders.
*
* @param {Object} opts
* @param {string} opts.opCode
* @param {number|string} [opts.jobNo=1]
* @param {string} [opts.payType="Cust"]
* @returns {null|{ops: Array}}
*/
const buildRolaborSkeleton = ({ opCode, jobNo = 1, payType = "Cust" } = {}) => {
if (!opCode) return null;
return {
ops: [
{
opCode,
jobNo: String(jobNo),
custPayTypeFlag: "C",
warrPayTypeFlag: "W",
intrPayTypeFlag: "I",
custTxblNtxblFlag: "N",
warrTxblNtxblFlag: "N",
intrTxblNtxblFlag: "N",
vlrCode: undefined,
bill: {
payType,
jobTotalHrs: "0",
billTime: "0",
billRate: "0"
},
amount: {
payType,
amtType: "Job",
custPrice: "0",
totalAmt: "0"
}
}
]
};
};
// ---------- Public API ----------
/**
* Query job data by ID from GraphQL API.
* @param ctx
@@ -301,8 +207,8 @@ const buildRRRepairOrderPayload = ({
story,
makeOverride,
allocations,
opCode,
taxCode
opCode
// taxCode
} = {}) => {
const customerNo = selectedCustomer?.customerNo
? String(selectedCustomer.customerNo).trim()
@@ -353,7 +259,7 @@ const buildRRRepairOrderPayload = ({
if (haveAllocations) {
const effectiveOpCode = (opCode && String(opCode).trim()) || null;
const effectiveTaxCode = (taxCode && String(taxCode).trim()) || null;
// const effectiveTaxCode = (taxCode && String(taxCode).trim()) || null;
if (effectiveOpCode) {
// Build RO.GOG and RO.LABOR in the new normalized shape
@@ -493,6 +399,20 @@ const normalizeVehicleCandidates = (res) => {
});
};
/**
* Build a minimal Rolabor structure in the new normalized shape.
*
* Useful for tests or for scenarios where you want a single zero-dollar
* Rolabor op but don't have GOG data. Shape matches payload.rolabor for the
* reynolds-rome-client builders.
*
* @param {Object} opts
* @param {string} opts.opCode
* @param {number|string} [opts.jobNo=1]
* @param {string} [opts.payType="Cust"]
* @returns {null|{ops: Array}}
*/
module.exports = {
QueryJobData,
buildRRRepairOrderPayload,
@@ -500,9 +420,6 @@ module.exports = {
makeVehicleSearchPayloadFromJob,
normalizeCustomerCandidates,
normalizeVehicleCandidates,
// exporting these so you can unit-test them directly if you want
buildRogogFromAllocations,
buildTaxFromAllocations,
buildRolaborSkeleton,
buildRolaborFromRogog
};