feature/IO-3255-simplified-parts-management - Checkpoint
This commit is contained in:
@@ -1,3 +1,8 @@
|
||||
// no-dd-sa:javascript-code-style/assignment-name
|
||||
// The above disables camel case inspection for the file,
|
||||
// CamelCase is used for GraphQL and database fields, and it is easier
|
||||
// to maintain consistency with the existing codebase.
|
||||
|
||||
const xml2js = require("xml2js");
|
||||
const client = require("../../graphql-client/graphql-client").client;
|
||||
|
||||
@@ -21,13 +26,15 @@ const INSERT_PARTS_ORDERS = `
|
||||
|
||||
/**
|
||||
* Handles incoming VehicleDamageEstimateAddRq XML,
|
||||
* parses every known field, inserts a Job + nested JobLines,
|
||||
* parses every known field (including estimator, adjuster,
|
||||
* repair facility), nests Vehicle and JobLines inserts,
|
||||
* then any PartsOrders (grouped per SupplierRefNum).
|
||||
*/
|
||||
const partsManagementVehicleDamageEstimateAddRq = async (req, res) => {
|
||||
const { logger } = req;
|
||||
const xml = req.body;
|
||||
|
||||
// ── PARSE XML ────────────────────────────────────────────────────────────────
|
||||
let payload;
|
||||
try {
|
||||
payload = await xml2js.parseStringPromise(xml, {
|
||||
@@ -37,6 +44,7 @@ const partsManagementVehicleDamageEstimateAddRq = async (req, res) => {
|
||||
logger.log("parts-xml-parse", "debug", null, null, { success: true });
|
||||
} catch (err) {
|
||||
logger.log("parts-xml-parse-error", "error", null, null, { error: err });
|
||||
console.dir(err);
|
||||
return res.status(400).send("Invalid XML");
|
||||
}
|
||||
|
||||
@@ -47,89 +55,118 @@ const partsManagementVehicleDamageEstimateAddRq = async (req, res) => {
|
||||
}
|
||||
|
||||
try {
|
||||
//
|
||||
// ── SHOP ID ───────────────────────────────────────────────────────────────────
|
||||
//
|
||||
// pulled directly from <ShopID> in your XML
|
||||
//
|
||||
// ── SHOP ID ────────────────────────────────────────────────────────────────
|
||||
const shopId = rq.ShopID || rq.shopId;
|
||||
if (!shopId) {
|
||||
throw { status: 400, message: "Missing <ShopID> in XML" };
|
||||
}
|
||||
|
||||
//
|
||||
// ── DOCUMENT INFO ─────────────────────────────────────────────────────────────
|
||||
//
|
||||
const { RqUID, RefClaimNum } = rq;
|
||||
// ── DOCUMENT INFO ──────────────────────────────────────────────────────────
|
||||
const { RefClaimNum } = rq;
|
||||
const doc = rq.DocumentInfo || {};
|
||||
const comment = doc.Comment || null;
|
||||
const transmitDate = doc.TransmitDateTime || null;
|
||||
const date_exported = doc.TransmitDateTime || null;
|
||||
|
||||
// capture all <DocumentVer> entries
|
||||
const docVers = doc.DocumentVer ? (Array.isArray(doc.DocumentVer) ? doc.DocumentVer : [doc.DocumentVer]) : [];
|
||||
const documentVersions = docVers.map((dv) => ({
|
||||
code: dv.DocumentVerCode,
|
||||
num: dv.DocumentVerNum
|
||||
}));
|
||||
|
||||
// pull out any OtherReferenceInfo (RO Number + Job UUID)
|
||||
const otherRefs = doc.ReferenceInfo?.OtherReferenceInfo
|
||||
? Array.isArray(doc.ReferenceInfo.OtherReferenceInfo)
|
||||
? doc.ReferenceInfo.OtherReferenceInfo
|
||||
: [doc.ReferenceInfo.OtherReferenceInfo]
|
||||
: [];
|
||||
const originalRoNumber = otherRefs.find((r) => r.OtherReferenceName === "RO Number")?.OtherRefNum;
|
||||
const originalJobUuid = otherRefs.find((r) => r.OtherReferenceName === "Job UUID")?.OtherRefNum;
|
||||
|
||||
//
|
||||
// ── EVENT INFO ────────────────────────────────────────────────────────────────
|
||||
//
|
||||
// ── EVENT INFO ──────────────────────────────────────────────────────────────
|
||||
const ev = rq.EventInfo || {};
|
||||
const assignEv = ev.AssignmentEvent || {};
|
||||
const assignmentEvent = {
|
||||
number: assignEv.AssignmentNumber,
|
||||
type: assignEv.AssignmentType,
|
||||
date: assignEv.AssignmentDate,
|
||||
createdAt: assignEv.CreateDateTime
|
||||
};
|
||||
const repairEv = ev.RepairEvent || {};
|
||||
const scheduled_completion = repairEv.TargetCompletionDateTime || null;
|
||||
const scheduled_in = repairEv.RequestedPickUpDateTime || null;
|
||||
const asgn = ev.AssignmentEvent || {};
|
||||
const asgn_no = asgn.AssignmentNumber || null;
|
||||
const asgn_type = asgn.AssignmentType || null;
|
||||
const asgn_date = asgn.AssignmentDate || null;
|
||||
const scheduled_completion = ev.RepairEvent?.TargetCompletionDateTime || null;
|
||||
const scheduled_in = ev.RepairEvent?.RequestedPickUpDateTime || null;
|
||||
|
||||
//
|
||||
// ── CLAIM INFO ────────────────────────────────────────────────────────────────
|
||||
//
|
||||
// ── CLAIM INFO ──────────────────────────────────────────────────────────────
|
||||
const ci = rq.ClaimInfo || {};
|
||||
const clm_no = ci.ClaimNum;
|
||||
const ClaimStatus = ci.ClaimStatus || null;
|
||||
const clm_no = ci.ClaimNum || null;
|
||||
const status = ci.ClaimStatus || null;
|
||||
const policy_no = ci.PolicyInfo?.PolicyNum || null;
|
||||
const ded_amt = parseFloat(ci.PolicyInfo?.CoverageInfo?.Coverage?.DeductibleInfo?.DeductibleAmt || 0);
|
||||
// if your XML ever has a `<Cieca_ttl>` you'd parse it here
|
||||
const clm_total = parseFloat(ci.Cieca_ttl || 0);
|
||||
|
||||
//
|
||||
// ── OWNER ─────────────────────────────────────────────────────────────────────
|
||||
//
|
||||
const ownerParty = rq.AdminInfo?.Owner?.Party || {};
|
||||
const ownerName = ownerParty.PersonInfo?.PersonName || {};
|
||||
const ownerOrg = ownerParty.OrgInfo || {};
|
||||
const ownerAddr = ownerParty.PersonInfo?.Communications?.Address || {};
|
||||
const ownerComms = ownerParty.ContactInfo?.Communications
|
||||
// ── ADMIN / OWNER INFO ──────────────────────────────────────────────────────
|
||||
const admin = rq.AdminInfo || {};
|
||||
|
||||
// Owner
|
||||
const ownerParty = admin.Owner?.Party || {};
|
||||
const ownr_fn = ownerParty.PersonInfo?.PersonName?.FirstName || null;
|
||||
const ownr_ln = ownerParty.PersonInfo?.PersonName?.LastName || null;
|
||||
const ownr_co_nm = ownerParty.OrgInfo?.CompanyName || null;
|
||||
const adr = ownerParty.PersonInfo?.Communications?.Address || {};
|
||||
const ownr_addr1 = adr.Address1 || null;
|
||||
const ownr_addr2 = adr.Address2 || null;
|
||||
const ownr_city = adr.City || null;
|
||||
const ownr_st = adr.StateProvince || null;
|
||||
const ownr_zip = adr.PostalCode || null;
|
||||
const ownr_ctry = adr.Country || null;
|
||||
|
||||
const ownrComms = ownerParty.ContactInfo?.Communications
|
||||
? Array.isArray(ownerParty.ContactInfo.Communications)
|
||||
? ownerParty.ContactInfo.Communications
|
||||
: [ownerParty.ContactInfo.Communications]
|
||||
: [];
|
||||
let ownerPhone = null,
|
||||
ownerEmail = null;
|
||||
ownerComms.forEach((c) => {
|
||||
if (c.CommQualifier === "CP") ownerPhone = c.CommPhone;
|
||||
if (c.CommQualifier === "EM") ownerEmail = c.CommEmail;
|
||||
let ownr_ph1 = null,
|
||||
ownr_ph2 = null,
|
||||
ownr_fax = null,
|
||||
ownr_ea = null;
|
||||
ownrComms.forEach((c) => {
|
||||
if (c.CommQualifier === "CP") ownr_ph1 = c.CommPhone;
|
||||
if (c.CommQualifier === "WP") ownr_ph2 = c.CommPhone;
|
||||
if (c.CommQualifier === "FX") ownr_fax = c.CommPhone;
|
||||
if (c.CommQualifier === "EM") ownr_ea = c.CommEmail;
|
||||
});
|
||||
const ownerPrefContact = ownerParty.PreferredContactMethod || null;
|
||||
const preferred_contact = ownerParty.PreferredContactMethod || null;
|
||||
|
||||
//
|
||||
// ── VEHICLE INFO ──────────────────────────────────────────────────────────────
|
||||
//
|
||||
// Estimator → map to est_… fields
|
||||
const estParty = admin.Estimator?.Party || {};
|
||||
const est_fn = estParty.PersonInfo?.PersonName?.FirstName || null;
|
||||
const est_ln = estParty.PersonInfo?.PersonName?.LastName || null;
|
||||
const est_aff = admin.Estimator?.Affiliation || null;
|
||||
const estComms = estParty.ContactInfo?.Communications
|
||||
? Array.isArray(estParty.ContactInfo.Communications)
|
||||
? estParty.ContactInfo.Communications
|
||||
: [estParty.ContactInfo.Communications]
|
||||
: [];
|
||||
const est_ea = estComms.find((c) => c.CommQualifier === "EM")?.CommEmail || null;
|
||||
|
||||
// Adjuster → map to agt_… fields
|
||||
const adjParty = admin.Adjuster?.Party || {};
|
||||
const agt_ct_fn = adjParty.PersonInfo?.PersonName?.FirstName || null;
|
||||
const agt_ct_ln = adjParty.PersonInfo?.PersonName?.LastName || null;
|
||||
const adjComms = adjParty.ContactInfo?.Communications
|
||||
? Array.isArray(adjParty.ContactInfo.Communications)
|
||||
? adjParty.ContactInfo.Communications
|
||||
: [adjParty.ContactInfo.Communications]
|
||||
: [];
|
||||
const agt_ct_ph = adjComms.find((c) => c.CommQualifier === "CP")?.CommPhone || null;
|
||||
const agt_ea = adjComms.find((c) => c.CommQualifier === "EM")?.CommEmail || null;
|
||||
|
||||
// Repair Facility → map to servicing_dealer, servicing_dealer_contact
|
||||
const rfParty = admin.RepairFacility?.Party || {};
|
||||
const servicing_dealer = rfParty.OrgInfo?.CompanyName || null;
|
||||
const rfAdr = rfParty.OrgInfo?.Communications?.Address || {};
|
||||
const servicing_dealer_addr1 = rfAdr.Address1 || null;
|
||||
const servicing_dealer_city = rfAdr.City || null;
|
||||
const servicing_dealer_st = rfAdr.StateProvince || null;
|
||||
const servicing_dealer_zip = rfAdr.PostalCode || null;
|
||||
const servicing_dealer_ctry = rfAdr.Country || null;
|
||||
const rfComms = rfParty.ContactInfo?.Communications
|
||||
? Array.isArray(rfParty.ContactInfo.Communications)
|
||||
? rfParty.ContactInfo.Communications
|
||||
: [rfParty.ContactInfo.Communications]
|
||||
: [];
|
||||
const servicing_dealer_contact =
|
||||
rfComms.find((c) => c.CommQualifier === "WP")?.CommPhone ||
|
||||
rfComms.find((c) => c.CommQualifier === "FX")?.CommPhone ||
|
||||
null;
|
||||
|
||||
// ── VEHICLE INFO (nested relationship) ──────────────────────────────────────
|
||||
const vin = rq.VehicleInfo?.VINInfo?.VINNum || null;
|
||||
const plate_no = rq.VehicleInfo?.License?.LicensePlateNum || null;
|
||||
const plate_st = rq.VehicleInfo?.License?.LicensePlateStateProvince || null;
|
||||
@@ -137,32 +174,44 @@ const partsManagementVehicleDamageEstimateAddRq = async (req, res) => {
|
||||
const v_model_yr = desc.ModelYear || null;
|
||||
const v_make_desc = desc.MakeDesc || null;
|
||||
const v_model_desc = desc.ModelName || null;
|
||||
const v_color = rq.VehicleInfo?.Paint?.Exterior?.ColorName || null;
|
||||
const body_style = desc.BodyStyle || null;
|
||||
const engine_desc = desc.EngineDesc || null;
|
||||
const production_date = desc.ProductionDate || null;
|
||||
const sub_model_desc = desc.SubModelDesc || null;
|
||||
const fuel_type = desc.FuelType || null;
|
||||
const v_color = rq.VehicleInfo?.Paint?.Exterior?.ColorName || null;
|
||||
const drivable = rq.VehicleInfo?.Condition?.DrivableInd === "Y";
|
||||
const v_options = desc.SubModelDesc || null;
|
||||
const v_type = desc.FuelType || null;
|
||||
const driveable = rq.VehicleInfo?.Condition?.DrivableInd === "Y";
|
||||
|
||||
//
|
||||
// ── PROFILE & RATES ───────────────────────────────────────────────────────────
|
||||
//
|
||||
const vehicleData = {
|
||||
shopid: shopId,
|
||||
vin,
|
||||
plate_no,
|
||||
plate_st,
|
||||
year: v_model_yr,
|
||||
make: v_make_desc,
|
||||
model: v_model_desc,
|
||||
color: v_color,
|
||||
bstyle: body_style,
|
||||
engine: engine_desc,
|
||||
prod_dt: production_date,
|
||||
options: v_options,
|
||||
type: v_type,
|
||||
condition: driveable
|
||||
};
|
||||
|
||||
// ── PROFILE & RATES ─────────────────────────────────────────────────────────
|
||||
const rateInfos = rq.ProfileInfo?.RateInfo
|
||||
? Array.isArray(rq.ProfileInfo.RateInfo)
|
||||
? rq.ProfileInfo.RateInfo
|
||||
: [rq.ProfileInfo.RateInfo]
|
||||
: [];
|
||||
const rates = {}; // main { rate_lab, rate_laf, … }
|
||||
const rateTier = {}; // e.g. { MA2S: [ {tier, pct}, … ] }
|
||||
const materialCalc = {}; // e.g. { LAR: { CalcMethodCode, CalcMaxHours }, … }
|
||||
|
||||
const rates = {},
|
||||
rateTier = {},
|
||||
materialCalc = {};
|
||||
rateInfos.forEach((r) => {
|
||||
if (!r || !r.RateType) return;
|
||||
const t = r.RateType;
|
||||
// main per‐unit rate
|
||||
if (r.Rate) rates[`rate_${t.toLowerCase()}`] = parseFloat(r.Rate) || 0;
|
||||
// any tier settings
|
||||
if (!r.RateType) return;
|
||||
const t = r.RateType.toLowerCase();
|
||||
if (r.Rate) rates[`rate_${t}`] = parseFloat(r.Rate) || 0;
|
||||
if (r.RateTierInfo) {
|
||||
const tiers = Array.isArray(r.RateTierInfo) ? r.RateTierInfo : [r.RateTierInfo];
|
||||
rateTier[t] = tiers.map((ti) => ({
|
||||
@@ -170,15 +219,12 @@ const partsManagementVehicleDamageEstimateAddRq = async (req, res) => {
|
||||
pct: parseFloat(ti.Percentage) || 0
|
||||
}));
|
||||
}
|
||||
// any material‐calc limits
|
||||
if (r.MaterialCalcSettings) {
|
||||
materialCalc[t] = r.MaterialCalcSettings;
|
||||
}
|
||||
});
|
||||
|
||||
//
|
||||
// ── DAMAGE LINES → joblinesData ─────────────────────────────────────────────
|
||||
//
|
||||
// ── DAMAGE LINES → joblinesData ────────────────────────────────────────────
|
||||
const damageLines = Array.isArray(rq.DamageLineInfo) ? rq.DamageLineInfo : [rq.DamageLineInfo];
|
||||
const joblinesData = damageLines.map((line) => ({
|
||||
line_no: parseInt(line.LineNum, 10),
|
||||
@@ -190,25 +236,21 @@ const partsManagementVehicleDamageEstimateAddRq = async (req, res) => {
|
||||
line_desc: line.LineDesc || null,
|
||||
|
||||
// parts
|
||||
part_type: line.PartInfo.PartType || null,
|
||||
part_qty: parseInt(line.PartInfo.Quantity || 0, 10),
|
||||
db_price: parseFloat(line.PartInfo.PartPrice || 0),
|
||||
act_price: parseFloat(line.PartInfo.PartPrice || 0),
|
||||
oem_partno: line.PartInfo.OEMPartNum || null,
|
||||
part_type: line.PartInfo?.PartType || null,
|
||||
part_qty: parseInt(line.PartInfo?.Quantity || 0, 10),
|
||||
db_price: parseFloat(line.PartInfo?.PartPrice || 0),
|
||||
act_price: parseFloat(line.PartInfo?.PartPrice || 0),
|
||||
oem_partno: line.PartInfo?.OEMPartNum || null,
|
||||
|
||||
// non-OEM block
|
||||
non_oem_part_num: line.PartInfo?.NonOEM?.NonOEMPartNum || null,
|
||||
non_oem_part_price: parseFloat(line.PartInfo?.NonOEM?.NonOEMPartPrice || 0),
|
||||
supplier_ref_num: line.PartInfo?.NonOEM?.SupplierRefNum || null,
|
||||
part_selected_ind: line.PartInfo?.NonOEM?.PartSelectedInd === "1",
|
||||
// non-OEM → not persisted at jobline level
|
||||
|
||||
after_market_usage: line.PartInfo.AfterMarketUsage || null,
|
||||
certification_type: line.PartInfo.CertificationType || null,
|
||||
tax_part: line.PartInfo.TaxableInd === "1",
|
||||
glass_flag: line.PartInfo.GlassPartInd === "1",
|
||||
after_market_usage: line.PartInfo?.AfterMarketUsage || null,
|
||||
certification_type: line.PartInfo?.CertificationType || null,
|
||||
tax_part: line.PartInfo?.TaxableInd === "1",
|
||||
glass_flag: line.PartInfo?.GlassPartInd === "1",
|
||||
price_j: line.PriceJudgmentInd === "1",
|
||||
price_inc: line.PriceInclInd === "1",
|
||||
order_by_application_ind: String(line.PartInfo.OrderByApplicationInd).toLowerCase() === "true",
|
||||
order_by_application_ind: String(line.PartInfo?.OrderByApplicationInd).toLowerCase() === "true",
|
||||
|
||||
// labor
|
||||
mod_lbr_ty: line.LaborInfo?.LaborType || null,
|
||||
@@ -216,103 +258,101 @@ const partsManagementVehicleDamageEstimateAddRq = async (req, res) => {
|
||||
lbr_op: line.LaborInfo?.LaborOperation || null,
|
||||
lbr_amt: parseFloat(line.LaborInfo?.LaborAmt || 0),
|
||||
|
||||
// linkage & memo
|
||||
parent_line_no: line.ParentLineNum ? parseInt(line.ParentLineNum, 10) : null,
|
||||
notes: line.LineMemo || null
|
||||
}));
|
||||
|
||||
//
|
||||
// ── BUILD & INSERT THE JOB ───────────────────────────────────────────────────
|
||||
//
|
||||
// ── BUILD & INSERT THE JOB ──────────────────────────────────────────────────
|
||||
const jobInput = {
|
||||
shopid: shopId,
|
||||
|
||||
// identifiers
|
||||
ro_number: RefClaimNum,
|
||||
original_ro_number: originalRoNumber,
|
||||
original_job_uuid: originalJobUuid,
|
||||
|
||||
// claim & policy
|
||||
clm_no,
|
||||
status: ClaimStatus,
|
||||
status,
|
||||
clm_total,
|
||||
policy_no,
|
||||
ded_amt,
|
||||
|
||||
// timestamps & comments
|
||||
comment,
|
||||
date_exported: transmitDate,
|
||||
date_exported,
|
||||
asgn_no,
|
||||
asgn_type,
|
||||
asgn_date,
|
||||
scheduled_completion,
|
||||
scheduled_in,
|
||||
|
||||
// owner
|
||||
ownr_fn: ownerName.FirstName || null,
|
||||
ownr_ln: ownerName.LastName || null,
|
||||
ownr_co_nm: ownerOrg.CompanyName || null,
|
||||
ownr_addr1: ownerAddr.Address1 || null,
|
||||
ownr_city: ownerAddr.City || null,
|
||||
ownr_st: ownerAddr.StateProvince || null,
|
||||
ownr_zip: ownerAddr.PostalCode || null,
|
||||
ownr_country: ownerAddr.Country || null,
|
||||
ownr_ph1: ownerPhone,
|
||||
ownr_ea: ownerEmail,
|
||||
ownr_pref_contact: ownerPrefContact,
|
||||
ownr_fn,
|
||||
ownr_ln,
|
||||
ownr_co_nm,
|
||||
ownr_addr1,
|
||||
ownr_addr2,
|
||||
ownr_city,
|
||||
ownr_st,
|
||||
ownr_zip,
|
||||
ownr_ctry,
|
||||
ownr_ph1,
|
||||
ownr_ph2,
|
||||
ownr_fax,
|
||||
ownr_ea,
|
||||
preferred_contact,
|
||||
|
||||
// vehicle
|
||||
v_vin: vin,
|
||||
plate_no,
|
||||
plate_st,
|
||||
v_model_yr,
|
||||
v_make_desc,
|
||||
v_model_desc,
|
||||
v_color,
|
||||
body_style,
|
||||
engine_desc,
|
||||
production_date,
|
||||
sub_model_desc,
|
||||
fuel_type,
|
||||
drivable,
|
||||
est_co_id: est_aff,
|
||||
est_ct_fn: est_fn,
|
||||
est_ct_ln: est_ln,
|
||||
est_ea,
|
||||
|
||||
agt_ct_fn,
|
||||
agt_ct_ln,
|
||||
agt_ct_ph,
|
||||
agt_ea,
|
||||
|
||||
servicing_dealer,
|
||||
servicing_dealer_addr1,
|
||||
servicing_dealer_city,
|
||||
servicing_dealer_st,
|
||||
servicing_dealer_zip,
|
||||
servicing_dealer_ctry,
|
||||
servicing_dealer_contact,
|
||||
|
||||
// labor & material rates
|
||||
...rates,
|
||||
|
||||
// everything extra in one JSON column
|
||||
production_vars: {
|
||||
rqUid: RqUID,
|
||||
documentVersions,
|
||||
assignmentEvent,
|
||||
scheduled_completion,
|
||||
scheduled_in,
|
||||
rateTier,
|
||||
materialCalc
|
||||
},
|
||||
|
||||
// nested joblines
|
||||
vehicle: { data: vehicleData },
|
||||
joblines: { data: joblinesData }
|
||||
};
|
||||
|
||||
logger.log("parts-insert-job", "debug", null, null, { jobInput });
|
||||
const jobResp = await client.request(INSERT_JOB_WITH_LINES, {
|
||||
job: jobInput
|
||||
});
|
||||
const newJob = jobResp.insert_jobs_one;
|
||||
const { insert_jobs_one: newJob } = await client.request(INSERT_JOB_WITH_LINES, { job: jobInput });
|
||||
const jobId = newJob.id;
|
||||
logger.log("parts-job-created", "info", jobId, null);
|
||||
|
||||
//
|
||||
// ── BUILD & INSERT PARTS ORDERS ────────────────────────────────────────────
|
||||
//
|
||||
// group lines by their SupplierRefNum
|
||||
const insertedMap = newJob.joblines.reduce((m, ln) => {
|
||||
m[ln.unq_seq] = ln.id;
|
||||
return m;
|
||||
const seqToId = newJob.joblines.reduce((map, ln) => {
|
||||
map[ln.unq_seq] = ln.id;
|
||||
return map;
|
||||
}, {});
|
||||
|
||||
const currentDate = new Date().toISOString().slice(0, 10);
|
||||
// TODO: we should not need to capture the order status from the XML,
|
||||
const defaultStatus = process.env.DEFAULT_PARTS_ORDER_STATUS || "";
|
||||
|
||||
// TODO: This will be the username of the bodyshop user used for the integration.
|
||||
const userEmail = req.headers["x-hasura-user-id"] || "system@example.com";
|
||||
|
||||
// group by vendor
|
||||
const poGroups = {};
|
||||
damageLines.forEach((line) => {
|
||||
const pt = line.PartInfo.PartType;
|
||||
const qty = parseInt(line.PartInfo.Quantity || 0, 10);
|
||||
const pt = line.PartInfo?.PartType;
|
||||
const qty = parseInt(line.PartInfo?.Quantity || 0, 10);
|
||||
if (["PAN", "PAC", "PAM", "PAA"].includes(pt) && qty > 0) {
|
||||
const vendorid = line.PartInfo?.NonOEM?.SupplierRefNum || process.env.DEFAULT_VENDOR_ID;
|
||||
if (!poGroups[vendorid]) poGroups[vendorid] = [];
|
||||
poGroups[vendorid].push({
|
||||
// TODO: We should not need to capture the vendor ID from the XML
|
||||
const vid = line.PartInfo?.NonOEM?.SupplierRefNum || process.env.DEFAULT_VENDOR_ID || null;
|
||||
(poGroups[vid] = poGroups[vid] || []).push({
|
||||
line,
|
||||
unq_seq: parseInt(line.UniqueSequenceNum, 10)
|
||||
});
|
||||
@@ -323,18 +363,27 @@ const partsManagementVehicleDamageEstimateAddRq = async (req, res) => {
|
||||
jobid: jobId,
|
||||
vendorid,
|
||||
order_number: `${clm_no}-${entries[0].line.LineNum}`,
|
||||
order_date: currentDate,
|
||||
orderedby: "XML-API",
|
||||
user_email: userEmail,
|
||||
status: defaultStatus,
|
||||
parts_order_lines: {
|
||||
data: entries.map(({ line, unq_seq }) => ({
|
||||
job_line_id: insertedMap[unq_seq],
|
||||
part_type: line.PartInfo.PartType,
|
||||
quantity: parseInt(line.PartInfo.Quantity || 0, 10),
|
||||
act_price: parseFloat(line.PartInfo.PartPrice || 0),
|
||||
db_price: parseFloat(line.PartInfo.PartPrice || 0),
|
||||
line_desc: line.LineDesc,
|
||||
non_oem_part_num: line.PartInfo?.NonOEM?.NonOEMPartNum || null,
|
||||
non_oem_part_price: parseFloat(line.PartInfo?.NonOEM?.NonOEMPartPrice || 0),
|
||||
part_selected_ind: line.PartInfo?.NonOEM?.PartSelectedInd === "1"
|
||||
}))
|
||||
data: entries.map(({ line, unq_seq }) => {
|
||||
const pi = line.PartInfo || {};
|
||||
const nonOEM = pi.NonOEM || {};
|
||||
return {
|
||||
job_line_id: seqToId[unq_seq],
|
||||
line_desc: line.LineDesc || null,
|
||||
oem_partno: pi.OEMPartNum || null,
|
||||
db_price: parseFloat(pi.PartPrice || 0),
|
||||
act_price: parseFloat(pi.PartPrice || 0),
|
||||
line_remarks: line.LineMemo || null,
|
||||
quantity: parseInt(pi.Quantity || 1, 10),
|
||||
part_type: pi.PartType || null,
|
||||
cost: nonOEM.NonOEMPartPrice ? parseFloat(nonOEM.NonOEMPartPrice) : null,
|
||||
cm_received: null
|
||||
};
|
||||
})
|
||||
}
|
||||
}));
|
||||
|
||||
|
||||
340
server/integrations/partsManagement/sampleBody.xml
Normal file
340
server/integrations/partsManagement/sampleBody.xml
Normal file
@@ -0,0 +1,340 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<VehicleDamageEstimateAddRq xmlns="http://www.cieca.com/BMS">
|
||||
<!-- Shop identifier -->
|
||||
<ShopID>12345</ShopID>
|
||||
|
||||
<!-- Request & Claim -->
|
||||
<RqUID>17e5ccc4-cdfb-4cf3-a08d-ecfa8d145d6f</RqUID>
|
||||
<RefClaimNum>CLM123</RefClaimNum>
|
||||
|
||||
<!-- Document metadata -->
|
||||
<DocumentInfo>
|
||||
<DocumentVer>
|
||||
<DocumentVerCode>SV</DocumentVerCode>
|
||||
<DocumentVerNum>1</DocumentVerNum>
|
||||
</DocumentVer>
|
||||
<DocumentVer>
|
||||
<DocumentVerCode>VN</DocumentVerCode>
|
||||
<DocumentVerNum>1</DocumentVerNum>
|
||||
</DocumentVer>
|
||||
<ReferenceInfo>
|
||||
<OtherReferenceInfo>
|
||||
<OtherReferenceName>RO Number</OtherReferenceName>
|
||||
<OtherRefNum>RO-987</OtherRefNum>
|
||||
</OtherReferenceInfo>
|
||||
<OtherReferenceInfo>
|
||||
<OtherReferenceName>Job UUID</OtherReferenceName>
|
||||
<OtherRefNum>abcde-12345-uuid</OtherRefNum>
|
||||
</OtherReferenceInfo>
|
||||
</ReferenceInfo>
|
||||
<Comment>Include OEM where possible</Comment>
|
||||
<TransmitDateTime>2025-06-18T12:00:00Z</TransmitDateTime>
|
||||
</DocumentInfo>
|
||||
|
||||
<!-- Event classification -->
|
||||
<EventInfo>
|
||||
<AssignmentEvent>
|
||||
<AssignmentNumber>1</AssignmentNumber>
|
||||
<AssignmentType>Estimate</AssignmentType>
|
||||
<AssignmentDate>2025-06-18T11:30:00Z</AssignmentDate>
|
||||
<CreateDateTime>2025-06-18T11:29:00Z</CreateDateTime>
|
||||
</AssignmentEvent>
|
||||
<RepairEvent>
|
||||
<TargetCompletionDateTime>2025-06-25T17:00:00Z</TargetCompletionDateTime>
|
||||
<RequestedPickUpDateTime>2025-06-22T09:00:00Z</RequestedPickUpDateTime>
|
||||
</RepairEvent>
|
||||
</EventInfo>
|
||||
|
||||
<!-- Claim & Policy -->
|
||||
<ClaimInfo>
|
||||
<ClaimNum>CLM123</ClaimNum>
|
||||
<ClaimStatus>Open</ClaimStatus>
|
||||
<PolicyInfo>
|
||||
<PolicyNum>POL456</PolicyNum>
|
||||
<CoverageInfo>
|
||||
<Coverage>
|
||||
<DeductibleInfo>
|
||||
<DeductibleAmt>500.00</DeductibleAmt>
|
||||
</DeductibleInfo>
|
||||
</Coverage>
|
||||
</CoverageInfo>
|
||||
</PolicyInfo>
|
||||
<Cieca_ttl>1500.50</Cieca_ttl>
|
||||
</ClaimInfo>
|
||||
|
||||
<!-- Administrative Parties -->
|
||||
<AdminInfo>
|
||||
<!-- Owner -->
|
||||
<Owner>
|
||||
<Party>
|
||||
<PersonInfo>
|
||||
<PersonName>
|
||||
<FirstName>John</FirstName>
|
||||
<LastName>Doe</LastName>
|
||||
</PersonName>
|
||||
<Communications>
|
||||
<CommQualifier>AL</CommQualifier>
|
||||
<Address>
|
||||
<Address1>100 Main St</Address1>
|
||||
<City>Metropolis</City>
|
||||
<StateProvince>NY</StateProvince>
|
||||
<PostalCode>10001</PostalCode>
|
||||
<Country>USA</Country>
|
||||
</Address>
|
||||
</Communications>
|
||||
</PersonInfo>
|
||||
<ContactInfo>
|
||||
<Communications>
|
||||
<CommQualifier>CP</CommQualifier>
|
||||
<CommPhone>5551234567</CommPhone>
|
||||
</Communications>
|
||||
<Communications>
|
||||
<CommQualifier>EM</CommQualifier>
|
||||
<CommEmail>john.doe@example.com</CommEmail>
|
||||
</Communications>
|
||||
</ContactInfo>
|
||||
</Party>
|
||||
</Owner>
|
||||
|
||||
<!-- Estimator -->
|
||||
<Estimator>
|
||||
<Party>
|
||||
<PersonInfo>
|
||||
<PersonName>
|
||||
<FirstName>Jane</FirstName>
|
||||
<LastName>Smith</LastName>
|
||||
</PersonName>
|
||||
</PersonInfo>
|
||||
<ContactInfo>
|
||||
<Communications>
|
||||
<CommQualifier>EM</CommQualifier>
|
||||
<CommEmail>jane.smith@example.com</CommEmail>
|
||||
</Communications>
|
||||
</ContactInfo>
|
||||
</Party>
|
||||
<Affiliation>EST001</Affiliation>
|
||||
</Estimator>
|
||||
|
||||
<!-- Repair Facility -->
|
||||
<RepairFacility>
|
||||
<Party>
|
||||
<OrgInfo>
|
||||
<CompanyName>AutoFix</CompanyName>
|
||||
<Communications>
|
||||
<CommQualifier>AL</CommQualifier>
|
||||
<Address>
|
||||
<Address1>200 Repair Rd</Address1>
|
||||
<City>Mechanicsburg</City>
|
||||
<StateProvince>PA</StateProvince>
|
||||
<PostalCode>17055</PostalCode>
|
||||
<Country>USA</Country>
|
||||
</Address>
|
||||
</Communications>
|
||||
</OrgInfo>
|
||||
<ContactInfo>
|
||||
<Communications>
|
||||
<CommQualifier>WP</CommQualifier>
|
||||
<CommPhone>5559876543</CommPhone>
|
||||
</Communications>
|
||||
<Communications>
|
||||
<CommQualifier>FX</CommQualifier>
|
||||
<CommPhone>5559876544</CommPhone>
|
||||
</Communications>
|
||||
</ContactInfo>
|
||||
</Party>
|
||||
</RepairFacility>
|
||||
|
||||
<!-- Adjuster -->
|
||||
<Adjuster>
|
||||
<Party>
|
||||
<PersonInfo>
|
||||
<PersonName>
|
||||
<FirstName>Alice</FirstName>
|
||||
<LastName>Johnson</LastName>
|
||||
</PersonName>
|
||||
</PersonInfo>
|
||||
</Party>
|
||||
</Adjuster>
|
||||
|
||||
<!-- Supplier -->
|
||||
<Supplier>
|
||||
<Party>
|
||||
<OrgInfo>
|
||||
<CompanyName>PartsRUs</CompanyName>
|
||||
</OrgInfo>
|
||||
</Party>
|
||||
</Supplier>
|
||||
|
||||
<!-- Sender -->
|
||||
<Sender>
|
||||
<Party>
|
||||
<OrgInfo>
|
||||
<CompanyName>XmlSender</CompanyName>
|
||||
</OrgInfo>
|
||||
</Party>
|
||||
</Sender>
|
||||
|
||||
<!-- Other Admin Party -->
|
||||
<OtherParty>
|
||||
<Party>
|
||||
<OrgInfo>
|
||||
<CompanyName>ThirdPartyAdmin</CompanyName>
|
||||
</OrgInfo>
|
||||
</Party>
|
||||
<AdminType>TPA</AdminType>
|
||||
</OtherParty>
|
||||
</AdminInfo>
|
||||
|
||||
<!-- (Optional) Rates -->
|
||||
<ProfileInfo>
|
||||
<RateInfo>
|
||||
<RateType>LABOR</RateType>
|
||||
<Rate>100.0</Rate>
|
||||
<RateTierInfo>
|
||||
<TierNum>1</TierNum>
|
||||
<Percentage>50.0</Percentage>
|
||||
</RateTierInfo>
|
||||
</RateInfo>
|
||||
</ProfileInfo>
|
||||
|
||||
<!-- Vehicle details -->
|
||||
<VehicleInfo>
|
||||
<VINInfo>
|
||||
<VINNum>1HGCM82633A004352</VINNum>
|
||||
</VINInfo>
|
||||
<License>
|
||||
<LicensePlateNum>ABC1234</LicensePlateNum>
|
||||
<LicensePlateStateProvince>CA</LicensePlateStateProvince>
|
||||
</License>
|
||||
<VehicleDesc>
|
||||
<ModelYear>2020</ModelYear>
|
||||
<MakeDesc>Honda</MakeDesc>
|
||||
<ModelName>Accord</ModelName>
|
||||
<BodyStyle>Sedan</BodyStyle>
|
||||
<EngineDesc>2.0L</EngineDesc>
|
||||
<ProductionDate>2019-10-10</ProductionDate>
|
||||
<SubModelDesc>Sport</SubModelDesc>
|
||||
<FuelType>Gasoline</FuelType>
|
||||
</VehicleDesc>
|
||||
<Paint>
|
||||
<Exterior>
|
||||
<ColorName>Blue</ColorName>
|
||||
</Exterior>
|
||||
</Paint>
|
||||
<Condition>
|
||||
<DrivableInd>Y</DrivableInd>
|
||||
</Condition>
|
||||
</VehicleInfo>
|
||||
|
||||
<!-- Damage line with non-OEM part -->
|
||||
<DamageLineInfo>
|
||||
<LineNum>1</LineNum>
|
||||
<UniqueSequenceNum>1001</UniqueSequenceNum>
|
||||
<ParentLineNum>0</ParentLineNum>
|
||||
<ManualLineInd>0</ManualLineInd>
|
||||
<AutomatedEntry>1</AutomatedEntry>
|
||||
<DescJudgmentInd>0</DescJudgmentInd>
|
||||
<LineStatusCode>Draft</LineStatusCode>
|
||||
<LineDesc>Front Bumper</LineDesc>
|
||||
<PartInfo>
|
||||
<PartType>PAA</PartType>
|
||||
<Quantity>1</Quantity>
|
||||
<PartPrice>200.00</PartPrice>
|
||||
<OEMPartNum>OEM123</OEMPartNum>
|
||||
<NonOEM>
|
||||
<NonOEMPartNum>NONOEM123</NonOEMPartNum>
|
||||
<NonOEMPartPrice>180.00</NonOEMPartPrice>
|
||||
<SupplierRefNum>VEND1</SupplierRefNum>
|
||||
<PartSelectedInd>1</PartSelectedInd>
|
||||
</NonOEM>
|
||||
<TaxableInd>1</TaxableInd>
|
||||
<AfterMarketUsage>OV</AfterMarketUsage>
|
||||
<CertificationType>C</CertificationType>
|
||||
<PriceJudgmentInd>0</PriceJudgmentInd>
|
||||
<GlassPartInd>0</GlassPartInd>
|
||||
<PriceInclInd>0</PriceInclInd>
|
||||
<OrderByApplicationInd>false</OrderByApplicationInd>
|
||||
</PartInfo>
|
||||
<LaborInfo>
|
||||
<LaborType>LAB</LaborType>
|
||||
<LaborOperation>OP1</LaborOperation>
|
||||
<LaborHours>2.5</LaborHours>
|
||||
<LaborAmt>250.00</LaborAmt>
|
||||
</LaborInfo>
|
||||
<LineMemo>Replace bumper</LineMemo>
|
||||
</DamageLineInfo>
|
||||
|
||||
<!-- Damage line with glass part -->
|
||||
<DamageLineInfo>
|
||||
<LineNum>2</LineNum>
|
||||
<UniqueSequenceNum>1002</UniqueSequenceNum>
|
||||
<ParentLineNum>0</ParentLineNum>
|
||||
<ManualLineInd>0</ManualLineInd>
|
||||
<AutomatedEntry>0</AutomatedEntry>
|
||||
<DescJudgmentInd>0</DescJudgmentInd>
|
||||
<LineStatusCode>Draft</LineStatusCode>
|
||||
<LineDesc>Windshield</LineDesc>
|
||||
<PartInfo>
|
||||
<PartType>PAG</PartType>
|
||||
<Quantity>1</Quantity>
|
||||
<PartPrice>572.06</PartPrice>
|
||||
<OEMPartNum>5610104082</OEMPartNum>
|
||||
<NonOEM>
|
||||
<NonOEMPartNum>5610104082</NonOEMPartNum>
|
||||
<NonOEMPartPrice>572.06</NonOEMPartPrice>
|
||||
<SupplierRefNum>VEND2</SupplierRefNum>
|
||||
<PartSelectedInd>1</PartSelectedInd>
|
||||
</NonOEM>
|
||||
<TaxableInd>1</TaxableInd>
|
||||
<AfterMarketUsage>NU</AfterMarketUsage>
|
||||
<GlassPartInd>1</GlassPartInd>
|
||||
<PriceJudgmentInd>0</PriceJudgmentInd>
|
||||
<PriceInclInd>0</PriceInclInd>
|
||||
<OrderByApplicationInd>false</OrderByApplicationInd>
|
||||
</PartInfo>
|
||||
<LaborInfo>
|
||||
<LaborType>LAB</LaborType>
|
||||
<LaborOperation>OP11</LaborOperation>
|
||||
<LaborHours>3.7</LaborHours>
|
||||
<LaborAmt>370.00</LaborAmt>
|
||||
</LaborInfo>
|
||||
<LineMemo>Replace windshield</LineMemo>
|
||||
</DamageLineInfo>
|
||||
|
||||
<!-- Damage line with sublet info -->
|
||||
<DamageLineInfo>
|
||||
<LineNum>3</LineNum>
|
||||
<UniqueSequenceNum>1003</UniqueSequenceNum>
|
||||
<ParentLineNum>0</ParentLineNum>
|
||||
<ManualLineInd>0</ManualLineInd>
|
||||
<AutomatedEntry>1</AutomatedEntry>
|
||||
<DescJudgmentInd>0</DescJudgmentInd>
|
||||
<LineStatusCode>Draft</LineStatusCode>
|
||||
<LineDesc>Sublet Upholstery Repair</LineDesc>
|
||||
<SubletInfo>
|
||||
<SubletVendorName>UpholsteryCo</SubletVendorName>
|
||||
<SubletAmount>200.00</SubletAmount>
|
||||
<SubletLaborHours>2.0</SubletLaborHours>
|
||||
</SubletInfo>
|
||||
<LineMemo>Stitching match required</LineMemo>
|
||||
</DamageLineInfo>
|
||||
|
||||
<!-- Damage line with labor-only work -->
|
||||
<DamageLineInfo>
|
||||
<LineNum>4</LineNum>
|
||||
<UniqueSequenceNum>1004</UniqueSequenceNum>
|
||||
<ParentLineNum>0</ParentLineNum>
|
||||
<ManualLineInd>0</ManualLineInd>
|
||||
<AutomatedEntry>1</AutomatedEntry>
|
||||
<DescJudgmentInd>0</DescJudgmentInd>
|
||||
<LineStatusCode>Draft</LineStatusCode>
|
||||
<LineDesc>Dent Repair Door</LineDesc>
|
||||
<LaborInfo>
|
||||
<LaborType>LAD</LaborType>
|
||||
<LaborOperation>OP3</LaborOperation>
|
||||
<LaborHours>1.5</LaborHours>
|
||||
<LaborAmt>150.00</LaborAmt>
|
||||
</LaborInfo>
|
||||
<LineMemo>Requires touch-up</LineMemo>
|
||||
</DamageLineInfo>
|
||||
</VehicleDamageEstimateAddRq>
|
||||
@@ -1,5 +1,6 @@
|
||||
const express = require("express");
|
||||
const router = express.Router();
|
||||
const bodyParser = require("body-parser"); // Add body-parser dependency
|
||||
|
||||
// Pull secrets from env
|
||||
const { VSSTA_INTEGRATION_SECRET, PARTS_MANAGEMENT_INTEGRATION_SECRET } = process.env;
|
||||
@@ -20,12 +21,15 @@ if (typeof PARTS_MANAGEMENT_INTEGRATION_SECRET === "string" && PARTS_MANAGEMENT_
|
||||
const partsManagementIntegrationMiddleware = require("../middleware/partsManagementIntegrationMiddleware");
|
||||
const partsManagementVehicleDamageEstimateAddRq = require("../integrations/partsManagement/partsManagementVehicleDamageEstimateAddRq");
|
||||
|
||||
router.post("/parts-management/provision", partsManagementIntegrationMiddleware, partsManagementProvisioning);
|
||||
// Add XML parsing middleware for the VehicleDamageEstimateAddRq route
|
||||
router.post(
|
||||
"/parts-management/VehicleDamageEstimateAddRq",
|
||||
bodyParser.raw({ type: "application/xml", limit: "10mb" }), // Parse XML body
|
||||
partsManagementIntegrationMiddleware,
|
||||
partsManagementVehicleDamageEstimateAddRq
|
||||
);
|
||||
|
||||
router.post("/parts-management/provision", partsManagementIntegrationMiddleware, partsManagementProvisioning);
|
||||
} else {
|
||||
console.warn("PARTS_MANAGEMENT_INTEGRATION_SECRET is not set — skipping /parts-management/provision route");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user