IO-223 WIP ARMS

This commit is contained in:
Patrick Fic
2021-11-29 10:46:59 -08:00
parent 8c40d541c4
commit 673654a9b7

View File

@@ -2,7 +2,7 @@ const path = require("path");
const queries = require("../graphql-client/queries");
const Dinero = require("dinero.js");
const moment = require("moment");
var builder = require("xmlbuilder2");
const _ = require("lodash");
const logger = require("../utils/logger");
require("dotenv").config({
@@ -11,6 +11,12 @@ require("dotenv").config({
`.env.${process.env.NODE_ENV || "development"}`
),
});
const soap = require("soap");
const entegralEndpoint =
process.env.NODE_ENV === "production"
? "https://ws.entegral.com/RepairOrderFolderService/RepairOrderFolderService.asmx?op=RepairOrderFolderAddRq"
: "https://ws.entegral.com/RepairOrderFolderService/RepairOrderFolderService.asmx?op=RepairOrderFolderAddRq";
const client = require("../graphql-client/graphql-client").client;
const uuid = require("uuid").v4;
@@ -43,7 +49,7 @@ exports.default = async (req, res) => {
DocumentVerNum: GetSupplementNumber(job.joblines), //TODO Get Supplement Number
DocumentStatus: GetDocumentstatus(job, bodyshop),
CreateDateTime: moment().format(),
// TransmitDateTime: "2009-03-11T11:58:31.0404914-07:00", Omitted from ARMS docs
TransmitDateTime: moment().format(), // Omitted from ARMS docs
},
EventInfo: {
AssignmentEvent: {
@@ -51,7 +57,7 @@ exports.default = async (req, res) => {
job.asgn_date && moment(job.asgn_date).format(),
},
EstimateEvent: {
UploadDateTime: "2009-03-02T17:00:00.0000000-08:00", //TODO Figure out what this actually is. 'Date Estimate was uploaded'
UploadDateTime: moment().format(),
},
RepairEvent: {
ArrivalDateTime:
@@ -266,10 +272,12 @@ exports.default = async (req, res) => {
job.loss_date && moment(job.loss_date).format(),
LossDescCode: "Collision",
PrimaryPOI: {
POICode: job.area_of_damage.impact1,
POICode:
job.area_of_damage && job.area_of_damage.impact1,
},
SecondaryPOI: {
POICode: job.area_of_damage.impact2,
POICode:
job.area_of_damage && job.area_of_damage.impact2,
},
},
TotalLossInd: job.tlos_ind,
@@ -443,7 +451,7 @@ exports.default = async (req, res) => {
TotalTypeDesc: "Body Labor",
TotalHours: job.job_totals.rates.lab.hours,
TotalAmt: Dinero(job.job_totals.rates.lab.total).toFormat(
0.0
"0.0"
),
},
{
@@ -451,7 +459,7 @@ exports.default = async (req, res) => {
TotalTypeDesc: "Frame Labor",
TotalHours: job.job_totals.rates.laf.hours,
TotalAmt: Dinero(job.job_totals.rates.laf.total).toFormat(
0.0
"0.0"
),
},
{
@@ -459,7 +467,7 @@ exports.default = async (req, res) => {
TotalTypeDesc: "Mechanical Labor",
TotalHours: job.job_totals.rates.lam.hours,
TotalAmt: Dinero(job.job_totals.rates.lam.total).toFormat(
0.0
"0.0"
),
},
{
@@ -467,7 +475,7 @@ exports.default = async (req, res) => {
TotalTypeDesc: "Refinish Labor",
TotalHours: job.job_totals.rates.lar.hours,
TotalAmt: Dinero(job.job_totals.rates.lar.total).toFormat(
0.0
"0.0"
),
},
],
@@ -541,14 +549,14 @@ exports.default = async (req, res) => {
TotalType: "MAPA",
TotalTypeDesc: "Paint Materials",
TotalAmt: Dinero(job.job_totals.rates.mapa.total).toFormat(
0.0
"0.0"
),
},
{
TotalType: "MASH",
TotalTypeDesc: "Shop Materials",
TotalAmt: Dinero(job.job_totals.rates.mash.total).toFormat(
0.0
"0.0"
),
},
// {
@@ -569,7 +577,7 @@ exports.default = async (req, res) => {
TotalType: "OTTW",
TotalTypeDesc: "Towing",
TotalAmt: Dinero(job.job_totals.additional.towing).toFormat(
0.0
"0.0"
),
},
{
@@ -586,7 +594,7 @@ exports.default = async (req, res) => {
TotalSubType: "T2",
TotalTypeDesc: "Net Total",
TotalAmt: Dinero(job.job_totals.totals.subtotal).toFormat(
0.0
"0.0"
),
},
{
@@ -594,7 +602,7 @@ exports.default = async (req, res) => {
TotalSubType: "F7",
TotalTypeDesc: "Sales Tax",
TotalAmt: Dinero(job.job_totals.totals.state_tax).toFormat(
0.0
"0.0"
),
},
{
@@ -722,15 +730,15 @@ exports.default = async (req, res) => {
// },
ProductionStatus: {
ProductionStage: {
ProductionStageCode: 4,
ProductionStageDateTime: "2009-03-11T11:58:32.1898319-07:00",
ProductionStageStatusComment:
"Going to be painted this afternoon",
ProductionStageCode: GetProductionStageCode(job),
ProductionStageDateTime: moment().format(),
// ProductionStageStatusComment:
// "Going to be painted this afternoon",
},
RepairStatus: {
RepairStatusCode: 2,
RepairStatusDateTime: "2009-03-11T11:58:32.1898319-07:00",
RepairStatusMemo: "Waiting on back ordered parts",
RepairStatusCode: GetRepairStatusCode(job),
RepairStatusDateTime: moment().format(),
// RepairStatusMemo: "Waiting on back ordered parts",
},
},
// RepairOrderNotes: {
@@ -771,6 +779,37 @@ exports.default = async (req, res) => {
logger.log("arms-end-shop-extract", "DEBUG", "api", bodyshop.id, {
shopname: bodyshop.shopname,
});
console.log(new Buffer.from(
`${process.env.ENTEGRAL_USER}:${process.env.ENTEGRAL_PASSWORD}`
).toString("base64"))
try {
const entegralSoapClient = await soap.createClientAsync(
entegralEndpoint,
{
wsdl_headers: {
Authorization: `Basic ${new Buffer.from(
`${process.env.ENTEGRAL_USER}:${process.env.ENTEGRAL_PASSWORD}`
).toString("base64")}`,
},
}
);
} catch (error) {
console.log(error);
}
// const soapResponseVehicleInsertUpdate =
// await entegralSoapClient.RepairOrderFolderAddRq ({
// arg0: CDK_CREDENTIALS,
// arg1: { id: JobData.bodyshop.cdk_dealerid },
// arg2: {
// fileType: "VEHICLES",
// vehiclesVehicleId: DMSVid.vehiclesVehId,
// },
// });
// const [result, rawResponse, , rawRequest] = soapResponseVehicleInsertUpdate;
res.json(ret);
} catch (error) {
//Error at the shop level.
@@ -793,7 +832,7 @@ exports.default = async (req, res) => {
}
}
res.sendStatus(200);
// res.sendStatus(200);
} catch (error) {
res.status(200).json(error);
}
@@ -815,3 +854,10 @@ function GetDocumentstatus(job, bodyshop) {
return "0";
}
}
function GetRepairStatusCode(job) {
return "25";
}
function GetProductionStageCode(job) {
return "33";
}