Merge branch 'master' into feature/intellipay
This commit is contained in:
@@ -123,8 +123,14 @@ async function PbsCalculateAllocationsAp(socket, billids) {
|
||||
|
||||
if (!billHash[cc.name]) {
|
||||
billHash[cc.name] = {
|
||||
Account: cc.dms_acctnumber,
|
||||
ControlNumber: bill.vendor.dmsid,
|
||||
Account:
|
||||
bodyshop.pbs_configuration.appostingaccount === "wip"
|
||||
? cc.dms_wip_acctnumber
|
||||
: cc.dms_acctnumber,
|
||||
ControlNumber:
|
||||
bodyshop.pbs_configuration.apcontrol === "ro"
|
||||
? bill.job.ro_number
|
||||
: bill.vendor.dmsid,
|
||||
Amount: Dinero(),
|
||||
// Comment: "String",
|
||||
AdditionalInfo: bill.vendor.name,
|
||||
@@ -164,7 +170,7 @@ async function PbsCalculateAllocationsAp(socket, billids) {
|
||||
|
||||
let APAmount = Dinero();
|
||||
Object.keys(billHash).map((key) => {
|
||||
if (billHash[key].Amount.getAmount() > 0) {
|
||||
if (billHash[key].Amount.getAmount() > 0 || billHash[key].Amount.getAmount() < 0) {
|
||||
transactionObject.Posting.Lines.push({
|
||||
...billHash[key],
|
||||
Amount: billHash[key].Amount.toFormat("0.00"),
|
||||
|
||||
@@ -249,10 +249,10 @@ async function QueryCustomersFromDms(socket) {
|
||||
SerialNumber: socket.JobData.bodyshop.pbs_serialnumber,
|
||||
//ContactId: "00000000000000000000000000000000",
|
||||
// ContactCode: socket.JobData.owner.accountingid,
|
||||
FirstName: socket.JobData.ownr_co_nm
|
||||
FirstName: socket.JobData.ownr_fn,
|
||||
LastName: socket.JobData.ownr_co_nm
|
||||
? socket.JobData.ownr_co_nm
|
||||
: socket.JobData.ownr_fn,
|
||||
LastName: socket.JobData.ownr_ln,
|
||||
: socket.JobData.ownr_ln,
|
||||
PhoneNumber: socket.JobData.ownr_ph1,
|
||||
EmailAddress: socket.JobData.ownr_ea,
|
||||
// ModifiedSince: "0001-01-01T00:00:00.0000000Z",
|
||||
|
||||
@@ -133,7 +133,13 @@ const generateBillLine = (billLine, responsibilityCenters, jobClass) => {
|
||||
const findTaxCode = (billLine, taxcode) => {
|
||||
const {
|
||||
applicable_taxes: { local, state, federal },
|
||||
} = billLine;
|
||||
} =
|
||||
billLine.applicable_taxes === null
|
||||
? {
|
||||
...billLine,
|
||||
applicable_taxes: { local: false, state: false, federal: false },
|
||||
}
|
||||
: billLine;
|
||||
const t = taxcode.filter(
|
||||
(t) =>
|
||||
!!t.local === !!local &&
|
||||
|
||||
@@ -262,10 +262,10 @@ const generateInvoiceQbxml = (
|
||||
RefNumber: jobs_by_pk.ro_number,
|
||||
BillAddress: {
|
||||
Addr1: jobs_by_pk.ownr_co_nm
|
||||
? jobs_by_pk.ownr_co_nm.substring(0, 30)
|
||||
: `${`${jobs_by_pk.ownr_ln || ""} ${
|
||||
jobs_by_pk.ownr_fn || ""
|
||||
}`.substring(0, 30)}`,
|
||||
? jobs_by_pk.ownr_co_nm.substring(0, 30).trim()
|
||||
: `${`${jobs_by_pk.ownr_ln || ""} ${jobs_by_pk.ownr_fn || ""}`
|
||||
.substring(0, 30)
|
||||
.trim()}`,
|
||||
Addr2: jobs_by_pk.ownr_addr1,
|
||||
Addr3: jobs_by_pk.ownr_addr2,
|
||||
City: jobs_by_pk.ownr_city,
|
||||
@@ -274,10 +274,10 @@ const generateInvoiceQbxml = (
|
||||
},
|
||||
ShipAddress: {
|
||||
Addr1: jobs_by_pk.ownr_co_nm
|
||||
? jobs_by_pk.ownr_co_nm.substring(0, 30)
|
||||
: `${`${jobs_by_pk.ownr_ln || ""} ${
|
||||
jobs_by_pk.ownr_fn || ""
|
||||
}`.substring(0, 30)}`,
|
||||
? jobs_by_pk.ownr_co_nm.substring(0, 30).trim()
|
||||
: `${`${jobs_by_pk.ownr_ln || ""} ${jobs_by_pk.ownr_fn || ""}`
|
||||
.substring(0, 30)
|
||||
.trim()}`,
|
||||
Addr2: jobs_by_pk.ownr_addr1,
|
||||
Addr3: jobs_by_pk.ownr_addr2,
|
||||
City: jobs_by_pk.ownr_city,
|
||||
|
||||
@@ -21,9 +21,9 @@ exports.generateOwnerTier = (jobs_by_pk, isThreeTier, twotierpref) => {
|
||||
? `${jobs_by_pk.ownr_co_nm.substring(0, 30)} #${
|
||||
jobs_by_pk.owner.accountingid || ""
|
||||
}`
|
||||
: `${`${jobs_by_pk.ownr_ln || ""} ${
|
||||
jobs_by_pk.ownr_fn || ""
|
||||
}`.substring(0, 30)} #${jobs_by_pk.owner.accountingid || ""}`
|
||||
: `${`${jobs_by_pk.ownr_ln || ""} ${jobs_by_pk.ownr_fn || ""}`
|
||||
.substring(0, 30)
|
||||
.trim()} #${jobs_by_pk.owner.accountingid || ""}`
|
||||
)
|
||||
.trim()
|
||||
.replace(":", " ");
|
||||
@@ -39,9 +39,9 @@ exports.generateOwnerTier = (jobs_by_pk, isThreeTier, twotierpref) => {
|
||||
? `${jobs_by_pk.ownr_co_nm.substring(0, 30)} #${
|
||||
jobs_by_pk.owner.accountingid || ""
|
||||
}`
|
||||
: `${`${jobs_by_pk.ownr_ln || ""} ${
|
||||
jobs_by_pk.ownr_fn || ""
|
||||
}`.substring(0, 30)} #${jobs_by_pk.owner.accountingid || ""}`
|
||||
: `${`${jobs_by_pk.ownr_ln || ""} ${jobs_by_pk.ownr_fn || ""}`
|
||||
.substring(0, 30)
|
||||
.trim()} #${jobs_by_pk.owner.accountingid || ""}`
|
||||
)
|
||||
.trim()
|
||||
.replace(":", " ");
|
||||
|
||||
@@ -224,6 +224,7 @@ async function CdkSelectedCustomer(socket, selectedCustomerId) {
|
||||
} finally {
|
||||
//Ensure we always insert logEvents
|
||||
//GQL to insert logevents.
|
||||
|
||||
CdkBase.createLogEvent(
|
||||
socket,
|
||||
"DEBUG",
|
||||
@@ -431,7 +432,7 @@ async function QueryDmsCustomerById(socket, JobData, CustomerId) {
|
||||
|
||||
async function QueryDmsCustomerByName(socket, JobData) {
|
||||
const ownerName = (
|
||||
JobData.ownr_co_nm && JobData.ownr_co_nm !== ""
|
||||
JobData.ownr_co_nm && JobData.ownr_co_nm.trim() !== ""
|
||||
? JobData.ownr_co_nm
|
||||
: `${JobData.ownr_ln},${JobData.ownr_fn}`
|
||||
).replace(replaceSpecialRegex, "");
|
||||
@@ -641,7 +642,8 @@ async function InsertDmsCustomer(socket, newCustomerNumber) {
|
||||
.toUpperCase(),
|
||||
middleName: null,
|
||||
nameType:
|
||||
socket.JobData.ownr_co_nm && socket.JobData.ownr_co_nm
|
||||
socket.JobData.ownr_co_nm &&
|
||||
String(socket.JobData.ownr_co_nm).trim() !== ""
|
||||
? "Business"
|
||||
: "Person",
|
||||
suffix: null,
|
||||
@@ -715,19 +717,33 @@ async function InsertDmsVehicle(socket) {
|
||||
dealer: {
|
||||
dealerNumber: socket.JobData.bodyshop.cdk_dealerid,
|
||||
...(socket.txEnvelope.inservicedate && {
|
||||
inServiceDate: moment(socket.txEnvelope.inservicedate)
|
||||
//.tz(socket.JobData.bodyshop.timezone)
|
||||
.startOf("day")
|
||||
.toISOString(),
|
||||
inServiceDate:
|
||||
socket.txEnvelope.dms_unsold === true
|
||||
? ""
|
||||
: moment(socket.txEnvelope.inservicedate)
|
||||
//.tz(socket.JobData.bodyshop.timezone)
|
||||
.startOf("day")
|
||||
.toISOString(),
|
||||
}),
|
||||
vehicleId: socket.DMSVid.vehiclesVehId,
|
||||
},
|
||||
manufacturer: {},
|
||||
vehicle: {
|
||||
deliveryDate: moment()
|
||||
// .tz(socket.JobData.bodyshop.timezone)
|
||||
.format("YYYYMMDD"),
|
||||
licensePlateNo: socket.JobData.plate_no,
|
||||
deliveryDate:
|
||||
socket.txEnvelope.dms_unsold === true
|
||||
? ""
|
||||
: moment()
|
||||
// .tz(socket.JobData.bodyshop.timezone)
|
||||
.format("YYYYMMDD"),
|
||||
licensePlateNo:
|
||||
socket.JobData.plate_no === null
|
||||
? null
|
||||
: String(socket.JobData.plate_no).replace(/([^\w]|_)/g, "")
|
||||
.length === 0
|
||||
? null
|
||||
: String(socket.JobData.plate_no)
|
||||
.replace(/([^\w]|_)/g, "")
|
||||
.toUpperCase(),
|
||||
make: socket.txEnvelope.dms_make,
|
||||
modelAbrev: socket.txEnvelope.dms_model,
|
||||
modelYear: socket.JobData.v_model_yr,
|
||||
@@ -850,19 +866,25 @@ async function UpdateDmsVehicle(socket) {
|
||||
...socket.DMSVeh.dealer,
|
||||
...((socket.txEnvelope.inservicedate ||
|
||||
socket.DMSVeh.dealer.inServiceDate) && {
|
||||
inServiceDate: moment(
|
||||
socket.DMSVeh.dealer.inServiceDate ||
|
||||
socket.txEnvelope.inservicedate
|
||||
)
|
||||
// .tz(socket.JobData.bodyshop.timezone)
|
||||
.toISOString(),
|
||||
inServiceDate:
|
||||
socket.txEnvelope.dms_unsold === true
|
||||
? ""
|
||||
: moment(
|
||||
socket.DMSVeh.dealer.inServiceDate ||
|
||||
socket.txEnvelope.inservicedate
|
||||
)
|
||||
// .tz(socket.JobData.bodyshop.timezone)
|
||||
.toISOString(),
|
||||
}),
|
||||
},
|
||||
vehicle: {
|
||||
...socket.DMSVeh.vehicle,
|
||||
deliveryDate: moment(socket.DMSVeh.vehicle.deliveryDate)
|
||||
//.tz(socket.JobData.bodyshop.timezone)
|
||||
.toISOString(),
|
||||
deliveryDate:
|
||||
socket.txEnvelope.dms_unsold === true
|
||||
? ""
|
||||
: moment(socket.DMSVeh.vehicle.deliveryDate)
|
||||
//.tz(socket.JobData.bodyshop.timezone)
|
||||
.toISOString(),
|
||||
},
|
||||
owners: ids,
|
||||
},
|
||||
@@ -1092,7 +1114,13 @@ async function GenerateTransWips(socket) {
|
||||
if (alloc.sale.getAmount() > 0 && !alloc.tax) {
|
||||
const item = {
|
||||
acct: alloc.profitCenter.dms_acctnumber,
|
||||
cntl: socket.JobData.ro_number,
|
||||
cntl:
|
||||
alloc.profitCenter.dms_control_override &&
|
||||
alloc.profitCenter.dms_control_override !== null &&
|
||||
alloc.profitCenter.dms_control_override !== undefined &&
|
||||
alloc.profitCenter.dms_control_override?.trim() !== ""
|
||||
? alloc.profitCenter.dms_control_override
|
||||
: socket.JobData.ro_number,
|
||||
cntl2: null,
|
||||
credtMemoNo: null,
|
||||
postAmt: alloc.sale.multiply(-1).getAmount(),
|
||||
@@ -1109,7 +1137,13 @@ async function GenerateTransWips(socket) {
|
||||
if (alloc.cost.getAmount() > 0 && !alloc.tax) {
|
||||
const item = {
|
||||
acct: alloc.costCenter.dms_acctnumber,
|
||||
cntl: socket.JobData.ro_number,
|
||||
cntl:
|
||||
alloc.costCenter.dms_control_override &&
|
||||
alloc.costCenter.dms_control_override !== null &&
|
||||
alloc.costCenter.dms_control_override !== undefined &&
|
||||
alloc.costCenter.dms_control_override?.trim() !== ""
|
||||
? alloc.costCenter.dms_control_override
|
||||
: socket.JobData.ro_number,
|
||||
cntl2: null,
|
||||
credtMemoNo: null,
|
||||
postAmt: alloc.cost.getAmount(),
|
||||
@@ -1123,7 +1157,13 @@ async function GenerateTransWips(socket) {
|
||||
|
||||
const itemWip = {
|
||||
acct: alloc.costCenter.dms_wip_acctnumber,
|
||||
cntl: socket.JobData.ro_number,
|
||||
cntl:
|
||||
alloc.costCenter.dms_control_override &&
|
||||
alloc.costCenter.dms_control_override !== null &&
|
||||
alloc.costCenter.dms_control_override !== undefined &&
|
||||
alloc.costCenter.dms_control_override?.trim() !== ""
|
||||
? alloc.costCenter.dms_control_override
|
||||
: socket.JobData.ro_number,
|
||||
cntl2: null,
|
||||
credtMemoNo: null,
|
||||
postAmt: alloc.cost.multiply(-1).getAmount(),
|
||||
@@ -1158,7 +1198,13 @@ async function GenerateTransWips(socket) {
|
||||
if (alloc.sale.getAmount() > 0) {
|
||||
const item2 = {
|
||||
acct: alloc.profitCenter.dms_acctnumber,
|
||||
cntl: socket.JobData.ro_number,
|
||||
cntl:
|
||||
alloc.profitCenter.dms_control_override &&
|
||||
alloc.profitCenter.dms_control_override !== null &&
|
||||
alloc.profitCenter.dms_control_override !== undefined &&
|
||||
alloc.profitCenter.dms_control_override?.trim() !== ""
|
||||
? alloc.profitCenter.dms_control_override
|
||||
: socket.JobData.ro_number,
|
||||
cntl2: null,
|
||||
credtMemoNo: null,
|
||||
postAmt: alloc.sale.multiply(-1).getAmount(),
|
||||
@@ -1189,6 +1235,7 @@ async function GenerateTransWips(socket) {
|
||||
|
||||
wips.push(item);
|
||||
});
|
||||
socket.transWips = wips;
|
||||
return wips;
|
||||
}
|
||||
|
||||
@@ -1364,6 +1411,7 @@ async function MarkJobExported(socket, jobid) {
|
||||
jobid: jobid,
|
||||
successful: true,
|
||||
useremail: socket.user.email,
|
||||
metadata: socket.transWips,
|
||||
},
|
||||
bill: {
|
||||
exported: true,
|
||||
|
||||
@@ -42,14 +42,16 @@ function pollFunc(fn, timeout, interval) {
|
||||
pollFunc(getEntegralShopData, 0, 5 * 60 * 1000); //Set the metadata to refresh every 5 minutes.
|
||||
|
||||
async function getEntegralShopData() {
|
||||
await storage.init({ logging: true });
|
||||
const { bodyshops } = await client.request(queries.GET_ENTEGRAL_SHOPS);
|
||||
logger.log("set-entegral-shops-local-storage", "DEBUG", "API", null, null);
|
||||
await storage.setItem("entegralShops", bodyshops);
|
||||
return true; //Continue execution.
|
||||
// await storage.init({ logging: true });
|
||||
// const { bodyshops } = await client.request(queries.GET_ENTEGRAL_SHOPS);
|
||||
// logger.log("set-entegral-shops-local-storage", "DEBUG", "API", null, null);
|
||||
// await storage.setItem("entegralShops", bodyshops);
|
||||
// return true; //Continue execution.
|
||||
}
|
||||
|
||||
exports.default = async (req, res) => {
|
||||
res.sendStatus(401);
|
||||
return;
|
||||
//Query for the List of Bodyshop Clients.
|
||||
const job = req.body.event.data.new;
|
||||
logger.log("arms-job-update", "DEBUG", "api", job.id, null);
|
||||
|
||||
@@ -40,6 +40,10 @@ exports.default = async (req, res) => {
|
||||
|
||||
const specificShopIds = req.body.bodyshopIds; // ['uuid]
|
||||
const { start, end, skipUpload } = req.body; //YYYY-MM-DD
|
||||
if (req.headers["x-imex-auth"] !== process.env.AUTOHOUSE_AUTH_TOKEN) {
|
||||
res.sendStatus(401);
|
||||
return;
|
||||
}
|
||||
const allxmlsToUpload = [];
|
||||
const allErrors = [];
|
||||
try {
|
||||
@@ -261,20 +265,20 @@ const CreateRepairOrderTag = (job, errorCallback) => {
|
||||
}${job.est_ct_fn ? job.est_ct_fn : ""}`,
|
||||
},
|
||||
CustomerInformation: {
|
||||
FirstName: job.ownr_fn || "",
|
||||
LastName: job.ownr_ln || "",
|
||||
Street: job.ownr_addr1 || "",
|
||||
City: job.ownr_city || "",
|
||||
State: job.ownr_st || "",
|
||||
FirstName: "",
|
||||
LastName: "",
|
||||
Street: "",
|
||||
City: "",
|
||||
State: "",
|
||||
Zip: (job.ownr_zip && job.ownr_zip.substring(0, 3)) || "",
|
||||
Phone1: job.ownr_ph1 || "",
|
||||
Phone1: "",
|
||||
Phone2: null,
|
||||
Phone2Extension: null,
|
||||
Phone3: null,
|
||||
Phone3Extension: null,
|
||||
FileComments: null,
|
||||
Source: null,
|
||||
Email: job.ownr_ea || "",
|
||||
Email: "",
|
||||
RetWhsl: null,
|
||||
Cat: null,
|
||||
InsuredorClaimantFlag: null,
|
||||
@@ -758,7 +762,12 @@ const CreateCosts = (job) => {
|
||||
}, {});
|
||||
|
||||
//If the hourly rates for job costing are set, add them in.
|
||||
if (job.bodyshop.jc_hourly_rates && job.bodyshop.jc_hourly_rates.mapa) {
|
||||
if (
|
||||
job.bodyshop.jc_hourly_rates &&
|
||||
(job.bodyshop.jc_hourly_rates.mapa ||
|
||||
typeof job.bodyshop.jc_hourly_rates.mapa === "number" ||
|
||||
isNaN(job.bodyshop.jc_hourly_rates.mapa) === false)
|
||||
) {
|
||||
if (
|
||||
!billTotalsByCostCenters[
|
||||
job.bodyshop.md_responsibility_centers.defaults.costs.MAPA
|
||||
@@ -767,18 +776,45 @@ const CreateCosts = (job) => {
|
||||
billTotalsByCostCenters[
|
||||
job.bodyshop.md_responsibility_centers.defaults.costs.MAPA
|
||||
] = Dinero();
|
||||
billTotalsByCostCenters[
|
||||
job.bodyshop.md_responsibility_centers.defaults.costs.MAPA
|
||||
] = billTotalsByCostCenters[
|
||||
job.bodyshop.md_responsibility_centers.defaults.costs.MAPA
|
||||
].add(
|
||||
Dinero({
|
||||
amount:
|
||||
(job.bodyshop.jc_hourly_rates &&
|
||||
job.bodyshop.jc_hourly_rates.mapa * 100) ||
|
||||
0,
|
||||
}).multiply(job.job_totals.rates.mapa.hours)
|
||||
);
|
||||
if (job.bodyshop.use_paint_scale_data === true) {
|
||||
if (job.mixdata.length > 0) {
|
||||
billTotalsByCostCenters[
|
||||
job.bodyshop.md_responsibility_centers.defaults.costs.MAPA
|
||||
] = Dinero({
|
||||
amount: Math.round(
|
||||
((job.mixdata[0] && job.mixdata[0].totalliquidcost) || 0) * 100
|
||||
),
|
||||
});
|
||||
} else {
|
||||
billTotalsByCostCenters[
|
||||
job.bodyshop.md_responsibility_centers.defaults.costs.MAPA
|
||||
] = billTotalsByCostCenters[
|
||||
job.bodyshop.md_responsibility_centers.defaults.costs.MAPA
|
||||
].add(
|
||||
Dinero({
|
||||
amount: Math.round(
|
||||
(job.bodyshop.jc_hourly_rates &&
|
||||
job.bodyshop.jc_hourly_rates.mapa * 100) ||
|
||||
0
|
||||
),
|
||||
}).multiply(job.job_totals.rates.mapa.hours)
|
||||
);
|
||||
}
|
||||
} else {
|
||||
billTotalsByCostCenters[
|
||||
job.bodyshop.md_responsibility_centers.defaults.costs.MAPA
|
||||
] = billTotalsByCostCenters[
|
||||
job.bodyshop.md_responsibility_centers.defaults.costs.MAPA
|
||||
].add(
|
||||
Dinero({
|
||||
amount: Math.round(
|
||||
(job.bodyshop.jc_hourly_rates &&
|
||||
job.bodyshop.jc_hourly_rates.mapa * 100) ||
|
||||
0
|
||||
),
|
||||
}).multiply(job.job_totals.rates.mapa.hours)
|
||||
);
|
||||
}
|
||||
}
|
||||
if (job.bodyshop.jc_hourly_rates && job.bodyshop.jc_hourly_rates.mash) {
|
||||
if (
|
||||
@@ -795,10 +831,11 @@ const CreateCosts = (job) => {
|
||||
job.bodyshop.md_responsibility_centers.defaults.costs.MASH
|
||||
].add(
|
||||
Dinero({
|
||||
amount:
|
||||
amount: Math.round(
|
||||
(job.bodyshop.jc_hourly_rates &&
|
||||
job.bodyshop.jc_hourly_rates.mash * 100) ||
|
||||
0,
|
||||
0
|
||||
),
|
||||
}).multiply(job.job_totals.rates.mash.hours)
|
||||
);
|
||||
}
|
||||
@@ -814,7 +851,11 @@ const CreateCosts = (job) => {
|
||||
].add(
|
||||
Dinero({
|
||||
amount: Math.round((ticket_val.rate || 0) * 100),
|
||||
}).multiply(ticket_val.actualhrs || ticket_val.productivehrs || 0)
|
||||
}).multiply(
|
||||
(ticket_val.flat_rate
|
||||
? ticket_val.productivehrs
|
||||
: ticket_val.actualhrs) || 0
|
||||
)
|
||||
);
|
||||
|
||||
return ticket_acc;
|
||||
|
||||
@@ -28,7 +28,7 @@ exports.sendServerEmail = async function ({ subject, text }) {
|
||||
transporter.sendMail(
|
||||
{
|
||||
from: `ImEX Online API - ${process.env.NODE_ENV} <noreply@imex.online>`,
|
||||
to: ["patrick@snapt.ca"],
|
||||
to: ["patrick@imexsystems.ca", "support@thinkimex.com"],
|
||||
subject: subject,
|
||||
text: text,
|
||||
ses: {
|
||||
|
||||
@@ -658,7 +658,6 @@ exports.QUERY_EMPLOYEE_PIN = `query QUERY_EMPLOYEE_PIN($shopId: uuid!, $employee
|
||||
|
||||
exports.AUTOHOUSE_QUERY = `query AUTOHOUSE_EXPORT($start: timestamptz, $bodyshopid: uuid!, $end: timestamptz) {
|
||||
bodyshops_by_pk(id: $bodyshopid){
|
||||
|
||||
id
|
||||
shopname
|
||||
address1
|
||||
@@ -674,6 +673,7 @@ exports.AUTOHOUSE_QUERY = `query AUTOHOUSE_EXPORT($start: timestamptz, $bodyshop
|
||||
jc_hourly_rates
|
||||
cdk_dealerid
|
||||
pbs_serialnumber
|
||||
use_paint_scale_data
|
||||
timezone
|
||||
}
|
||||
jobs(where: {_and: [{converted: {_eq: true}}, {updated_at: {_gt: $start}}, {updated_at: {_lte: $end}}, {shopid: {_eq: $bodyshopid}}]}) {
|
||||
@@ -808,6 +808,7 @@ exports.AUTOHOUSE_QUERY = `query AUTOHOUSE_EXPORT($start: timestamptz, $bodyshop
|
||||
cost_center
|
||||
actualhrs
|
||||
productivehrs
|
||||
flat_rate
|
||||
}
|
||||
area_of_damage
|
||||
employee_prep_rel {
|
||||
@@ -828,6 +829,10 @@ exports.AUTOHOUSE_QUERY = `query AUTOHOUSE_EXPORT($start: timestamptz, $bodyshop
|
||||
employee_number
|
||||
id
|
||||
}
|
||||
mixdata(limit: 1, order_by: {updated_at: desc}) {
|
||||
jobid
|
||||
totalliquidcost
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
@@ -938,7 +943,7 @@ exports.UPDATE_JOB = `
|
||||
}
|
||||
`;
|
||||
|
||||
exports.GET_JOB_BY_PK = ` query GET_JOB_BY_PK($id: uuid!) {
|
||||
exports.GET_JOB_BY_PK = `query GET_JOB_BY_PK($id: uuid!) {
|
||||
jobs_by_pk(id: $id) {
|
||||
updated_at
|
||||
alt_transport
|
||||
@@ -1220,12 +1225,17 @@ exports.QUERY_JOB_COSTING_DETAILS = ` query QUERY_JOB_COSTING_DETAILS($id: uuid!
|
||||
flat_rate
|
||||
ciecacode
|
||||
}
|
||||
mixdata(limit: 1, order_by: {updated_at: desc}) {
|
||||
jobid
|
||||
totalliquidcost
|
||||
}
|
||||
bodyshop{
|
||||
id
|
||||
md_responsibility_centers
|
||||
jc_hourly_rates
|
||||
cdk_dealerid
|
||||
pbs_serialnumber
|
||||
use_paint_scale_data
|
||||
}
|
||||
}
|
||||
}`;
|
||||
@@ -1328,12 +1338,17 @@ exports.QUERY_JOB_COSTING_DETAILS_MULTI = ` query QUERY_JOB_COSTING_DETAILS_MULT
|
||||
flat_rate
|
||||
ciecacode
|
||||
}
|
||||
mixdata(limit: 1, order_by: {updated_at: desc}) {
|
||||
jobid
|
||||
totalliquidcost
|
||||
}
|
||||
bodyshop {
|
||||
id
|
||||
md_responsibility_centers
|
||||
jc_hourly_rates
|
||||
cdk_dealerid
|
||||
pbs_serialnumber
|
||||
pbs_serialnumber
|
||||
use_paint_scale_data
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1715,6 +1730,7 @@ query GET_PBS_AP_ALLOCATIONS($billids: [uuid!]) {
|
||||
md_responsibility_centers
|
||||
timezone
|
||||
pbs_serialnumber
|
||||
pbs_configuration
|
||||
id
|
||||
}
|
||||
bills(where: {id: {_in: $billids}, exported:{_eq: false}}) {
|
||||
@@ -1751,3 +1767,35 @@ query GET_PBS_AP_ALLOCATIONS($billids: [uuid!]) {
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
exports.QUERY_PARTS_SCAN = `query QUERY_PARTS_SCAN ($id: uuid!) {
|
||||
jobs_by_pk(id: $id) {
|
||||
bodyshop {
|
||||
id
|
||||
md_parts_scan
|
||||
}
|
||||
joblines(where: {removed: {_eq: false}}) {
|
||||
id
|
||||
line_desc
|
||||
critical
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
exports.UPDATE_PARTS_CRITICAL = `mutation UPDATE_PARTS_CRITICAL ($IdsToMarkCritical:[uuid!]!, $jobid: uuid!){
|
||||
critical: update_joblines(where:{id:{_in:$IdsToMarkCritical}}, _set:{critical: true}){
|
||||
affected_rows
|
||||
}
|
||||
notcritical: update_joblines(where:{id:{_nin:$IdsToMarkCritical}, jobid: {_eq: $jobid}}, _set:{critical: false}){
|
||||
affected_rows
|
||||
}
|
||||
}`;
|
||||
|
||||
exports.ACTIVE_SHOP_BY_USER = `query ACTIVE_SHOP_BY_USER($user: String) {
|
||||
associations(where: {active: {_eq: true}, useremail: {_eq: $user}}) {
|
||||
id
|
||||
shopid
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
@@ -612,7 +612,12 @@ function GenerateCostingData(job) {
|
||||
|
||||
//If the hourly rates for job costing are set, add them in.
|
||||
|
||||
if (job.bodyshop.jc_hourly_rates && job.bodyshop.jc_hourly_rates.mapa) {
|
||||
if (
|
||||
job.bodyshop.jc_hourly_rates &&
|
||||
(job.bodyshop.jc_hourly_rates.mapa ||
|
||||
typeof job.bodyshop.jc_hourly_rates.mapa === "number" ||
|
||||
isNaN(job.bodyshop.jc_hourly_rates.mapa) === false)
|
||||
) {
|
||||
if (
|
||||
!billTotalsByCostCenters.additionalCosts[
|
||||
job.bodyshop.md_responsibility_centers.defaults.costs.MAPA
|
||||
@@ -621,18 +626,45 @@ function GenerateCostingData(job) {
|
||||
billTotalsByCostCenters.additionalCosts[
|
||||
job.bodyshop.md_responsibility_centers.defaults.costs.MAPA
|
||||
] = Dinero();
|
||||
billTotalsByCostCenters.additionalCosts[
|
||||
job.bodyshop.md_responsibility_centers.defaults.costs.MAPA
|
||||
] = billTotalsByCostCenters.additionalCosts[
|
||||
job.bodyshop.md_responsibility_centers.defaults.costs.MAPA
|
||||
].add(
|
||||
Dinero({
|
||||
amount:
|
||||
(job.bodyshop.jc_hourly_rates &&
|
||||
job.bodyshop.jc_hourly_rates.mapa * 100) ||
|
||||
0,
|
||||
}).multiply(materialsHours.mapaHrs)
|
||||
);
|
||||
if (job.bodyshop.use_paint_scale_data === true) {
|
||||
if (job.mixdata.length > 0) {
|
||||
billTotalsByCostCenters.additionalCosts[
|
||||
job.bodyshop.md_responsibility_centers.defaults.costs.MAPA
|
||||
] = Dinero({
|
||||
amount: Math.round(
|
||||
((job.mixdata[0] && job.mixdata[0].totalliquidcost) || 0) * 100
|
||||
),
|
||||
});
|
||||
} else {
|
||||
billTotalsByCostCenters.additionalCosts[
|
||||
job.bodyshop.md_responsibility_centers.defaults.costs.MAPA
|
||||
] = billTotalsByCostCenters.additionalCosts[
|
||||
job.bodyshop.md_responsibility_centers.defaults.costs.MAPA
|
||||
].add(
|
||||
Dinero({
|
||||
amount: Math.round(
|
||||
(job.bodyshop.jc_hourly_rates &&
|
||||
job.bodyshop.jc_hourly_rates.mapa * 100) ||
|
||||
0
|
||||
),
|
||||
}).multiply(materialsHours.mapaHrs)
|
||||
);
|
||||
}
|
||||
} else {
|
||||
billTotalsByCostCenters.additionalCosts[
|
||||
job.bodyshop.md_responsibility_centers.defaults.costs.MAPA
|
||||
] = billTotalsByCostCenters.additionalCosts[
|
||||
job.bodyshop.md_responsibility_centers.defaults.costs.MAPA
|
||||
].add(
|
||||
Dinero({
|
||||
amount: Math.round(
|
||||
(job.bodyshop.jc_hourly_rates &&
|
||||
job.bodyshop.jc_hourly_rates.mapa * 100) ||
|
||||
0
|
||||
),
|
||||
}).multiply(materialsHours.mapaHrs)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (job.bodyshop.jc_hourly_rates && job.bodyshop.jc_hourly_rates.mash) {
|
||||
@@ -650,10 +682,11 @@ function GenerateCostingData(job) {
|
||||
job.bodyshop.md_responsibility_centers.defaults.costs.MASH
|
||||
].add(
|
||||
Dinero({
|
||||
amount:
|
||||
amount: Math.round(
|
||||
(job.bodyshop.jc_hourly_rates &&
|
||||
job.bodyshop.jc_hourly_rates.mash * 100) ||
|
||||
0,
|
||||
0
|
||||
),
|
||||
}).multiply(materialsHours.mashHrs)
|
||||
);
|
||||
}
|
||||
@@ -810,7 +843,9 @@ function GenerateCostingData(job) {
|
||||
//Push adjustments to bottom line.
|
||||
if (job.adjustment_bottom_line) {
|
||||
//Add to totals.
|
||||
const Adjustment = Dinero({ amount: job.adjustment_bottom_line * 100 }); //Need to invert, since this is being assigned as a cost.
|
||||
const Adjustment = Dinero({
|
||||
amount: Math.round(job.adjustment_bottom_line * 100),
|
||||
}); //Need to invert, since this is being assigned as a cost.
|
||||
summaryData.totalLaborSales = summaryData.totalLaborSales.add(Adjustment);
|
||||
summaryData.totalSales = summaryData.totalSales.add(Adjustment);
|
||||
//Add to lines.
|
||||
|
||||
@@ -17,10 +17,11 @@ require("dotenv").config({
|
||||
});
|
||||
async function StatusTransition(req, res) {
|
||||
if (req.headers["event-secret"] !== process.env.EVENT_SECRET) {
|
||||
res.status(403).send("Unauthorized");
|
||||
res.status(401).send("Unauthorized");
|
||||
return;
|
||||
}
|
||||
|
||||
res.sendStatus(200);
|
||||
return;
|
||||
const {
|
||||
id: jobid,
|
||||
status: value,
|
||||
@@ -78,7 +79,7 @@ async function StatusTransition(req, res) {
|
||||
|
||||
res.sendStatus(200); //.json(ret);
|
||||
} catch (error) {
|
||||
logger.log("job-costing-error", "ERROR", req.user.email, jobid, {
|
||||
logger.log("job-status-transition-error", "ERROR", req.user?.email, jobid, {
|
||||
message: error.message,
|
||||
stack: error.stack,
|
||||
});
|
||||
|
||||
323
server/opensearch/os-handler.js
Normal file
323
server/opensearch/os-handler.js
Normal file
@@ -0,0 +1,323 @@
|
||||
const Dinero = require("dinero.js");
|
||||
const queries = require("../graphql-client/queries");
|
||||
//const client = require("../graphql-client/graphql-client").client;
|
||||
const _ = require("lodash");
|
||||
const GraphQLClient = require("graphql-request").GraphQLClient;
|
||||
const logger = require("../utils/logger");
|
||||
|
||||
const path = require("path");
|
||||
const client = require("../graphql-client/graphql-client").client;
|
||||
require("dotenv").config({
|
||||
path: path.resolve(
|
||||
process.cwd(),
|
||||
`.env.${process.env.NODE_ENV || "development"}`
|
||||
),
|
||||
});
|
||||
const { Client, Connection } = require("@opensearch-project/opensearch");
|
||||
const { defaultProvider } = require("@aws-sdk/credential-provider-node");
|
||||
const aws4 = require("aws4");
|
||||
const { gql } = require("graphql-request");
|
||||
|
||||
var host = process.env.OPEN_SEARCH_HOST;
|
||||
const createAwsConnector = (credentials, region) => {
|
||||
class AmazonConnection extends Connection {
|
||||
buildRequestObject(params) {
|
||||
const request = super.buildRequestObject(params);
|
||||
request.service = "es";
|
||||
request.region = region;
|
||||
request.headers = request.headers || {};
|
||||
request.headers["host"] = request.hostname;
|
||||
|
||||
return aws4.sign(request, credentials);
|
||||
}
|
||||
}
|
||||
return {
|
||||
Connection: AmazonConnection,
|
||||
};
|
||||
};
|
||||
|
||||
const getClient = async () => {
|
||||
const credentials = await defaultProvider()();
|
||||
return new Client({
|
||||
...createAwsConnector(credentials, "ca-central-1"),
|
||||
node: host,
|
||||
});
|
||||
};
|
||||
|
||||
async function OpenSearchUpdateHandler(req, res) {
|
||||
if (req.headers["event-secret"] !== process.env.EVENT_SECRET) {
|
||||
res.status(401).send("Unauthorized");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
var osClient = await getClient();
|
||||
// const osClient = new Client({
|
||||
// node: `https://imex:<password>@search-imexonline-search-ixp2stfvwp6qocjsowzjzyreoy.ca-central-1.es.amazonaws.com/`,
|
||||
// });
|
||||
|
||||
if (req.body.event.op === "DELETE") {
|
||||
let response;
|
||||
response = await osClient.delete({
|
||||
id: req.body.event.data.old.id,
|
||||
index: req.body.table.name,
|
||||
});
|
||||
res.status(200).json(response.body);
|
||||
} else {
|
||||
let document;
|
||||
|
||||
switch (req.body.table.name) {
|
||||
case "jobs":
|
||||
document = _.pick(req.body.event.data.new, [
|
||||
"id",
|
||||
"bodyshopid",
|
||||
"clm_no",
|
||||
"clm_total",
|
||||
"comment",
|
||||
"ins_co_nm",
|
||||
"owner_owing",
|
||||
"ownr_co_nm",
|
||||
"ownr_fn",
|
||||
"ownr_ln",
|
||||
"ownr_ph1",
|
||||
"ownr_ph2",
|
||||
"plate_no",
|
||||
"ro_number",
|
||||
"status",
|
||||
"v_model_yr",
|
||||
"v_make_desc",
|
||||
"v_model_desc",
|
||||
"v_vin",
|
||||
]);
|
||||
document.bodyshopid = req.body.event.data.new.shopid;
|
||||
break;
|
||||
case "vehicles":
|
||||
document = _.pick(req.body.event.data.new, [
|
||||
"id",
|
||||
"v_model_yr",
|
||||
"v_model_desc",
|
||||
"v_make_desc",
|
||||
"v_color",
|
||||
"v_vin",
|
||||
"plate_no",
|
||||
]);
|
||||
document.bodyshopid = req.body.event.data.new.shopid;
|
||||
break;
|
||||
case "owners":
|
||||
document = _.pick(req.body.event.data.new, [
|
||||
"id",
|
||||
"ownr_fn",
|
||||
"ownr_ln",
|
||||
"ownr_co_nm",
|
||||
"ownr_ph1",
|
||||
"ownr_ph2",
|
||||
]);
|
||||
document.bodyshopid = req.body.event.data.new.shopid;
|
||||
break;
|
||||
case "bills":
|
||||
const bill = await client.request(
|
||||
`query ADMIN_GET_BILL_BY_ID($billId: uuid!) {
|
||||
bills_by_pk(id: $billId) {
|
||||
id
|
||||
job {
|
||||
id
|
||||
ro_number
|
||||
shopid
|
||||
}
|
||||
vendor {
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
{ billId: req.body.event.data.new.id }
|
||||
);
|
||||
document = {
|
||||
..._.pick(req.body.event.data.new, [
|
||||
"id",
|
||||
"date",
|
||||
"exported",
|
||||
"exported_at",
|
||||
"invoice_number",
|
||||
"is_credit_memo",
|
||||
"total",
|
||||
]),
|
||||
...bill.bills_by_pk,
|
||||
bodyshopid: bill.bills_by_pk.job.shopid,
|
||||
};
|
||||
break;
|
||||
case "payments":
|
||||
//Query to get the job and RO number
|
||||
const payment = await client.request(
|
||||
`query ADMIN_GET_PAYMENT_BY_ID($paymentId: uuid!) {
|
||||
payments_by_pk(id: $paymentId) {
|
||||
id
|
||||
job {
|
||||
id
|
||||
ro_number
|
||||
shopid
|
||||
ownerid
|
||||
ownr_co_nm
|
||||
ownr_fn
|
||||
ownr_ln
|
||||
owner {
|
||||
id
|
||||
ownr_co_nm
|
||||
ownr_fn
|
||||
ownr_ln
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
{ paymentId: req.body.event.data.new.id }
|
||||
);
|
||||
document = {
|
||||
..._.pick(req.body.event.data.new, [
|
||||
"id",
|
||||
"amount",
|
||||
"created_at",
|
||||
"date",
|
||||
"exportedat",
|
||||
"memo",
|
||||
"payer",
|
||||
"paymentnum",
|
||||
"transactionid",
|
||||
"type",
|
||||
]),
|
||||
...payment.payments_by_pk,
|
||||
bodyshopid: payment.payments_by_pk.job.shopid,
|
||||
};
|
||||
break;
|
||||
}
|
||||
const payload = {
|
||||
id: req.body.event.data.new.id,
|
||||
index: req.body.table.name,
|
||||
body: document,
|
||||
};
|
||||
|
||||
let response;
|
||||
response = await osClient.index(payload);
|
||||
console.log(response.body);
|
||||
res.status(200).json(response.body);
|
||||
}
|
||||
} catch (error) {
|
||||
res.status(400).json(JSON.stringify(error));
|
||||
} finally {
|
||||
}
|
||||
}
|
||||
|
||||
async function OpensearchSearchHandler(req, res) {
|
||||
try {
|
||||
const { search, bodyshopid, index } = req.body;
|
||||
if (!req.user) {
|
||||
res.sendStatus(401);
|
||||
return;
|
||||
}
|
||||
logger.log("os-search", "DEBUG", req.user.email, null, {
|
||||
search,
|
||||
});
|
||||
|
||||
const BearerToken = req.headers.authorization;
|
||||
const client = new GraphQLClient(process.env.GRAPHQL_ENDPOINT, {
|
||||
headers: {
|
||||
Authorization: BearerToken,
|
||||
},
|
||||
});
|
||||
|
||||
const assocs = await client
|
||||
.setHeaders({ Authorization: BearerToken })
|
||||
.request(queries.ACTIVE_SHOP_BY_USER, {
|
||||
user: req.user.email,
|
||||
});
|
||||
|
||||
if (assocs.length === 0) {
|
||||
res.sendStatus(401);
|
||||
}
|
||||
|
||||
var osClient = await getClient();
|
||||
|
||||
const { body } = await osClient.search({
|
||||
...(index ? { index } : {}),
|
||||
body: {
|
||||
size: 100,
|
||||
query: {
|
||||
bool: {
|
||||
must: [
|
||||
{
|
||||
match: {
|
||||
bodyshopid: assocs.associations[0].shopid,
|
||||
},
|
||||
},
|
||||
{
|
||||
bool: {
|
||||
should: [
|
||||
{
|
||||
multi_match: {
|
||||
query: search,
|
||||
type: "cross_fields",
|
||||
fields: ["*ownr_fn", "*ownr_ln"],
|
||||
},
|
||||
},
|
||||
{
|
||||
multi_match: {
|
||||
query: search,
|
||||
type: "most_fields",
|
||||
fields: [
|
||||
"*v_model_yr",
|
||||
"*v_make_desc^2",
|
||||
"*v_model_desc^3",
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
query_string: {
|
||||
query: `*${search}*`,
|
||||
|
||||
fields: [
|
||||
"*ro_number^20",
|
||||
"*clm_no^14",
|
||||
"*v_vin^12",
|
||||
"*plate_no^12",
|
||||
"*ownr_ln^10",
|
||||
"transactionid^10",
|
||||
"paymentnum^10",
|
||||
"invoice_number^10",
|
||||
"*ownr_fn^8",
|
||||
"*ownr_co_nm^8",
|
||||
"*ownr_ph1^8",
|
||||
"*ownr_ph2^8",
|
||||
"*",
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
minimum_should_match: 1,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
sort: [
|
||||
{
|
||||
_score: {
|
||||
order: "desc",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
res.json(body);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
logger.log("os-search-error", "ERROR", req.user.email, null, {
|
||||
error: JSON.stringify(error),
|
||||
});
|
||||
res.status(400).json(error);
|
||||
} finally {
|
||||
}
|
||||
}
|
||||
|
||||
exports.handler = OpenSearchUpdateHandler;
|
||||
exports.search = OpensearchSearchHandler;
|
||||
58
server/parts-scan/parts-scan.js
Normal file
58
server/parts-scan/parts-scan.js
Normal file
@@ -0,0 +1,58 @@
|
||||
const Dinero = require("dinero.js");
|
||||
const queries = require("../graphql-client/queries");
|
||||
const { job } = require("../scheduling/scheduling-job");
|
||||
const GraphQLClient = require("graphql-request").GraphQLClient;
|
||||
const logger = require("../utils/logger");
|
||||
const _ = require("lodash");
|
||||
// Dinero.defaultCurrency = "USD";
|
||||
// Dinero.globalLocale = "en-CA";
|
||||
|
||||
exports.partsScan = async function (req, res) {
|
||||
const BearerToken = req.headers.authorization;
|
||||
const { jobid } = req.body;
|
||||
logger.log("job-parts-scan", "DEBUG", req.user?.email, jobid, null);
|
||||
const client = new GraphQLClient(process.env.GRAPHQL_ENDPOINT, {
|
||||
headers: {
|
||||
Authorization: BearerToken,
|
||||
},
|
||||
});
|
||||
|
||||
try {
|
||||
//Query all jobline data using the user's authorization.
|
||||
const data = await client
|
||||
.setHeaders({ Authorization: BearerToken })
|
||||
.request(queries.QUERY_PARTS_SCAN, {
|
||||
id: jobid,
|
||||
});
|
||||
|
||||
//Create RegExps once for better performance.
|
||||
const IdsToMarkCritical = [];
|
||||
const RegExpressions = data.jobs_by_pk.bodyshop.md_parts_scan.map(
|
||||
(r) => new RegExp(r.expression, r.flags)
|
||||
);
|
||||
|
||||
//Check each line against each regex rule.
|
||||
data.jobs_by_pk.joblines.forEach((jobline) => {
|
||||
RegExpressions.forEach((rExp) => {
|
||||
if (jobline.line_desc.match(rExp)) {
|
||||
IdsToMarkCritical.push(jobline);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
const result = await client
|
||||
.setHeaders({ Authorization: BearerToken })
|
||||
.request(queries.UPDATE_PARTS_CRITICAL, {
|
||||
IdsToMarkCritical: _.uniqBy(IdsToMarkCritical, "id").map((i) => i.id),
|
||||
jobid: jobid,
|
||||
});
|
||||
|
||||
res.status(200).json(result);
|
||||
} catch (error) {
|
||||
logger.log("job-parts-scan-error", "ERROR", req.user.email, jobid, {
|
||||
jobid,
|
||||
error,
|
||||
});
|
||||
res.status(400).json(JSON.stringify(error));
|
||||
}
|
||||
};
|
||||
@@ -1,3 +1,12 @@
|
||||
exports.servertime = (req, res) => {
|
||||
res.status(200).send(new Date());
|
||||
};
|
||||
|
||||
exports.jsrAuth = async (req, res) => {
|
||||
res.send(
|
||||
"Basic " +
|
||||
Buffer.from(
|
||||
`${process.env.JSR_USER}:${process.env.JSR_PASSWORD}`
|
||||
).toString("base64")
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user