Fix RR
This commit is contained in:
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -205,8 +205,7 @@ const updateRRRepairOrderWithFullData = async (args) => {
|
||||
|
||||
const { client, opts } = buildClientAndOpts(bodyshop);
|
||||
|
||||
// For full data update after early RO, we still use "Insert" referenceId
|
||||
// because we're inserting the job operations for the first time
|
||||
// For full data update after early RO, use the RR update route.
|
||||
const finalOpts = {
|
||||
...opts,
|
||||
envelope: {
|
||||
@@ -214,7 +213,7 @@ const updateRRRepairOrderWithFullData = async (args) => {
|
||||
sender: {
|
||||
...(opts?.envelope?.sender || {}),
|
||||
task: "BSMRO",
|
||||
referenceId: "Insert"
|
||||
referenceId: "Update"
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -317,32 +316,45 @@ const updateRRRepairOrderWithFullData = async (args) => {
|
||||
opCode
|
||||
});
|
||||
|
||||
// Add roNo for linking to existing RO
|
||||
// Update the existing RO created during the early RO step.
|
||||
payload.finalUpdate = "N";
|
||||
payload.roNo = String(roNo);
|
||||
payload.outsdRoNo = job?.ro_number || job?.id || undefined;
|
||||
|
||||
// Keep rolabor - it's needed to register the job/OpCode accounts in Reynolds
|
||||
// Without this, Reynolds won't recognize the OpCode when we send rogg operations
|
||||
// The rolabor section tells Reynolds "these jobs exist" even with minimal data
|
||||
// RR update rejects placeholder non-labor ROLABOR rows with zero labor prices.
|
||||
// Keep only the actual labor jobs in ROLABOR and let ROGOG carry parts/extras.
|
||||
if (payload.rolabor?.ops?.length && payload.rogg?.ops?.length) {
|
||||
const laborJobNos = new Set(
|
||||
payload.rogg.ops
|
||||
.filter((op) => op?.segmentKind === "laborTaxable" || op?.segmentKind === "laborNonTaxable")
|
||||
.map((op) => String(op.jobNo))
|
||||
);
|
||||
|
||||
CreateRRLogEvent(socket, "INFO", "Preparing full data for early RO (using create with roNo)", {
|
||||
payload.rolabor.ops = payload.rolabor.ops.filter((op) => laborJobNos.has(String(op?.jobNo)));
|
||||
|
||||
if (!payload.rolabor.ops.length) {
|
||||
delete payload.rolabor;
|
||||
}
|
||||
}
|
||||
|
||||
CreateRRLogEvent(socket, "INFO", "Preparing full data update for existing RR RO", {
|
||||
roNo: String(roNo),
|
||||
hasRolabor: !!payload.rolabor,
|
||||
rolaborCount: payload.rolabor?.ops?.length || 0,
|
||||
hasRogg: !!payload.rogg,
|
||||
payload
|
||||
});
|
||||
|
||||
// Use createRepairOrder (not update) with the roNo to link to the existing early RO
|
||||
// Reynolds will merge this with the existing RO header
|
||||
const response = await client.createRepairOrder(payload, finalOpts);
|
||||
const response = await client.updateRepairOrder(payload, finalOpts);
|
||||
|
||||
CreateRRLogEvent(
|
||||
socket,
|
||||
"INFO",
|
||||
"Sending full data for early RO (using create with roNo)",
|
||||
"RR full data update sent for existing RO",
|
||||
withRRRequestXml(response, {
|
||||
roNo: String(roNo),
|
||||
hasRolabor: !!payload.rolabor,
|
||||
rolaborCount: payload.rolabor?.ops?.length || 0,
|
||||
hasRogg: !!payload.rogg,
|
||||
payload,
|
||||
response
|
||||
|
||||
@@ -368,8 +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-specific details (hrs/rate) remain zeroed out, and the
|
||||
* DMS can ignore non-labor ops by virtue of the zero hours/amounts.
|
||||
* 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
|
||||
@@ -388,6 +389,8 @@ const buildRolaborFromRogog = (rogg, { payType = "Cust" } = {}) => {
|
||||
const txFlag = firstLine.custTxblNtxblFlag ?? "N";
|
||||
|
||||
const linePayType = firstLine.custPayTypeFlag || "C";
|
||||
const isLaborSegment = op.segmentKind === "laborTaxable" || op.segmentKind === "laborNonTaxable";
|
||||
const laborAmount = isLaborSegment ? String(firstLine?.amount?.custPrice ?? "0") : "0";
|
||||
|
||||
return {
|
||||
opCode: op.opCode,
|
||||
@@ -403,8 +406,8 @@ const buildRolaborFromRogog = (rogg, { payType = "Cust" } = {}) => {
|
||||
amount: {
|
||||
payType,
|
||||
amtType: "Job",
|
||||
custPrice: "0",
|
||||
totalAmt: "0"
|
||||
custPrice: laborAmount,
|
||||
totalAmt: laborAmount
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user