@@ -9,152 +9,152 @@ const moment = require("moment-timezone");
|
||||
const logger = require('../../utils/logger');
|
||||
|
||||
require("dotenv").config({
|
||||
path: path.resolve(
|
||||
process.cwd(),
|
||||
`.env.${process.env.NODE_ENV || "development"}`
|
||||
),
|
||||
path: path.resolve(
|
||||
process.cwd(),
|
||||
`.env.${process.env.NODE_ENV || "development"}`
|
||||
),
|
||||
});
|
||||
|
||||
exports.default = async (req, res) => {
|
||||
const { bills: billsToQuery } = req.body;
|
||||
const {bills: billsToQuery} = req.body;
|
||||
|
||||
const BearerToken = req.BearerToken;
|
||||
const client = req.userGraphQLClient;
|
||||
const BearerToken = req.BearerToken;
|
||||
const client = req.userGraphQLClient;
|
||||
|
||||
try {
|
||||
logger.log(
|
||||
"qbxml-payable-create",
|
||||
"DEBUG",
|
||||
req.user.email,
|
||||
req.body.billsToQuery
|
||||
);
|
||||
try {
|
||||
logger.log(
|
||||
"qbxml-payable-create",
|
||||
"DEBUG",
|
||||
req.user.email,
|
||||
req.body.billsToQuery
|
||||
);
|
||||
|
||||
const result = await client
|
||||
.setHeaders({ Authorization: BearerToken })
|
||||
.request(queries.QUERY_BILLS_FOR_PAYABLES_EXPORT, {
|
||||
bills: billsToQuery,
|
||||
});
|
||||
const { bills, bodyshops } = result;
|
||||
const bodyshop = bodyshops[0];
|
||||
const result = await client
|
||||
.setHeaders({Authorization: BearerToken})
|
||||
.request(queries.QUERY_BILLS_FOR_PAYABLES_EXPORT, {
|
||||
bills: billsToQuery,
|
||||
});
|
||||
const {bills, bodyshops} = result;
|
||||
const bodyshop = bodyshops[0];
|
||||
|
||||
const QbXmlToExecute = [];
|
||||
bills.map((i) => {
|
||||
QbXmlToExecute.push({
|
||||
id: i.id,
|
||||
okStatusCodes: ["0"],
|
||||
qbxml: generateBill(i, bodyshop),
|
||||
});
|
||||
});
|
||||
const QbXmlToExecute = [];
|
||||
bills.map((i) => {
|
||||
QbXmlToExecute.push({
|
||||
id: i.id,
|
||||
okStatusCodes: ["0"],
|
||||
qbxml: generateBill(i, bodyshop),
|
||||
});
|
||||
});
|
||||
|
||||
//For each invoice.
|
||||
res.status(200).json(QbXmlToExecute);
|
||||
} catch (error) {
|
||||
logger.log(
|
||||
"qbxml-payable-error",
|
||||
"ERROR",
|
||||
req.user.email,
|
||||
req.body.billsToQuery,
|
||||
{ error: error.message, stack: error.stack }
|
||||
);
|
||||
res.status(400).send(JSON.stringify(error));
|
||||
}
|
||||
//For each invoice.
|
||||
res.status(200).json(QbXmlToExecute);
|
||||
} catch (error) {
|
||||
logger.log(
|
||||
"qbxml-payable-error",
|
||||
"ERROR",
|
||||
req.user.email,
|
||||
req.body.billsToQuery,
|
||||
{error: error.message, stack: error.stack}
|
||||
);
|
||||
res.status(400).send(JSON.stringify(error));
|
||||
}
|
||||
};
|
||||
|
||||
const generateBill = (bill, bodyshop) => {
|
||||
const billQbxmlObj = {
|
||||
QBXML: {
|
||||
QBXMLMsgsRq: {
|
||||
"@onError": "continueOnError",
|
||||
[`${bill.is_credit_memo ? "VendorCreditAddRq" : "BillAddRq"}`]: {
|
||||
[`${bill.is_credit_memo ? "VendorCreditAdd" : "BillAdd"}`]: {
|
||||
VendorRef: {
|
||||
FullName: bill.vendor.name,
|
||||
const billQbxmlObj = {
|
||||
QBXML: {
|
||||
QBXMLMsgsRq: {
|
||||
"@onError": "continueOnError",
|
||||
[`${bill.is_credit_memo ? "VendorCreditAddRq" : "BillAddRq"}`]: {
|
||||
[`${bill.is_credit_memo ? "VendorCreditAdd" : "BillAdd"}`]: {
|
||||
VendorRef: {
|
||||
FullName: bill.vendor.name,
|
||||
},
|
||||
TxnDate: moment(bill.date)
|
||||
//.tz(bill.job.bodyshop.timezone)
|
||||
.format("YYYY-MM-DD"),
|
||||
...(!bill.is_credit_memo &&
|
||||
bill.vendor.due_date && {
|
||||
DueDate: moment(bill.date)
|
||||
// .tz(bill.job.bodyshop.timezone)
|
||||
.add(bill.vendor.due_date, "days")
|
||||
.format("YYYY-MM-DD"),
|
||||
}),
|
||||
RefNumber: bill.invoice_number,
|
||||
Memo: `RO ${bill.job.ro_number || ""}`,
|
||||
ExpenseLineAdd: bill.billlines.map((il) =>
|
||||
generateBillLine(
|
||||
il,
|
||||
bodyshop.md_responsibility_centers,
|
||||
bill.job.class
|
||||
)
|
||||
),
|
||||
},
|
||||
},
|
||||
},
|
||||
TxnDate: moment(bill.date)
|
||||
//.tz(bill.job.bodyshop.timezone)
|
||||
.format("YYYY-MM-DD"),
|
||||
...(!bill.is_credit_memo &&
|
||||
bill.vendor.due_date && {
|
||||
DueDate: moment(bill.date)
|
||||
// .tz(bill.job.bodyshop.timezone)
|
||||
.add(bill.vendor.due_date, "days")
|
||||
.format("YYYY-MM-DD"),
|
||||
}),
|
||||
RefNumber: bill.invoice_number,
|
||||
Memo: `RO ${bill.job.ro_number || ""}`,
|
||||
ExpenseLineAdd: bill.billlines.map((il) =>
|
||||
generateBillLine(
|
||||
il,
|
||||
bodyshop.md_responsibility_centers,
|
||||
bill.job.class
|
||||
)
|
||||
),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
var billQbxml_partial = builder
|
||||
.create(billQbxmlObj, {
|
||||
version: "1.30",
|
||||
encoding: "UTF-8",
|
||||
headless: true,
|
||||
})
|
||||
.end({ pretty: true });
|
||||
var billQbxml_partial = builder
|
||||
.create(billQbxmlObj, {
|
||||
version: "1.30",
|
||||
encoding: "UTF-8",
|
||||
headless: true,
|
||||
})
|
||||
.end({pretty: true});
|
||||
|
||||
const billQbxml_Full = QbXmlUtils.addQbxmlHeader(billQbxml_partial);
|
||||
const billQbxml_Full = QbXmlUtils.addQbxmlHeader(billQbxml_partial);
|
||||
|
||||
return billQbxml_Full;
|
||||
return billQbxml_Full;
|
||||
};
|
||||
|
||||
const generateBillLine = (billLine, responsibilityCenters, jobClass) => {
|
||||
return {
|
||||
AccountRef: {
|
||||
FullName: responsibilityCenters.costs.find(
|
||||
(c) => c.name === billLine.cost_center
|
||||
).accountname,
|
||||
},
|
||||
Amount: Dinero({
|
||||
amount: Math.round(billLine.actual_cost * 100),
|
||||
})
|
||||
.multiply(billLine.quantity || 1)
|
||||
.toFormat(DineroQbFormat),
|
||||
...(jobClass ? { ClassRef: { FullName: jobClass } } : {}),
|
||||
...(process.env.COUNTRY !== "USA"
|
||||
? {
|
||||
SalesTaxCodeRef: {
|
||||
FullName: findTaxCode(
|
||||
billLine,
|
||||
responsibilityCenters.sales_tax_codes
|
||||
),
|
||||
},
|
||||
}
|
||||
: {}),
|
||||
};
|
||||
return {
|
||||
AccountRef: {
|
||||
FullName: responsibilityCenters.costs.find(
|
||||
(c) => c.name === billLine.cost_center
|
||||
).accountname,
|
||||
},
|
||||
Amount: Dinero({
|
||||
amount: Math.round(billLine.actual_cost * 100),
|
||||
})
|
||||
.multiply(billLine.quantity || 1)
|
||||
.toFormat(DineroQbFormat),
|
||||
...(jobClass ? {ClassRef: {FullName: jobClass}} : {}),
|
||||
...(process.env.COUNTRY !== "USA"
|
||||
? {
|
||||
SalesTaxCodeRef: {
|
||||
FullName: findTaxCode(
|
||||
billLine,
|
||||
responsibilityCenters.sales_tax_codes
|
||||
),
|
||||
},
|
||||
}
|
||||
: {}),
|
||||
};
|
||||
};
|
||||
|
||||
const findTaxCode = (billLine, taxcode) => {
|
||||
const {
|
||||
applicable_taxes: { local, state, federal },
|
||||
} =
|
||||
billLine.applicable_taxes === null
|
||||
? {
|
||||
...billLine,
|
||||
applicable_taxes: { local: false, state: false, federal: false },
|
||||
}
|
||||
: billLine;
|
||||
const t = taxcode.filter(
|
||||
(t) =>
|
||||
!!t.local === !!local &&
|
||||
!!t.state === !!state &&
|
||||
!!t.federal === !!federal
|
||||
);
|
||||
if (t.length === 1) {
|
||||
return t[0].code;
|
||||
} else if (t.length > 1) {
|
||||
return "Multiple Tax Codes Match";
|
||||
} else {
|
||||
return "No Tax Code Matches";
|
||||
}
|
||||
const {
|
||||
applicable_taxes: {local, state, federal},
|
||||
} =
|
||||
billLine.applicable_taxes === null
|
||||
? {
|
||||
...billLine,
|
||||
applicable_taxes: {local: false, state: false, federal: false},
|
||||
}
|
||||
: billLine;
|
||||
const t = taxcode.filter(
|
||||
(t) =>
|
||||
!!t.local === !!local &&
|
||||
!!t.state === !!state &&
|
||||
!!t.federal === !!federal
|
||||
);
|
||||
if (t.length === 1) {
|
||||
return t[0].code;
|
||||
} else if (t.length > 1) {
|
||||
return "Multiple Tax Codes Match";
|
||||
} else {
|
||||
return "No Tax Code Matches";
|
||||
}
|
||||
};
|
||||
|
||||
@@ -9,202 +9,202 @@ const QbxmlReceivables = require("./qbxml-receivables");
|
||||
const logger = require('../../utils/logger');
|
||||
|
||||
require("dotenv").config({
|
||||
path: path.resolve(
|
||||
process.cwd(),
|
||||
`.env.${process.env.NODE_ENV || "development"}`
|
||||
),
|
||||
path: path.resolve(
|
||||
process.cwd(),
|
||||
`.env.${process.env.NODE_ENV || "development"}`
|
||||
),
|
||||
});
|
||||
|
||||
const { generateJobTier, generateOwnerTier, generateSourceTier } = QbXmlUtils;
|
||||
const {generateJobTier, generateOwnerTier, generateSourceTier} = QbXmlUtils;
|
||||
|
||||
exports.default = async (req, res) => {
|
||||
const { payments: paymentsToQuery } = req.body;
|
||||
const {payments: paymentsToQuery} = req.body;
|
||||
|
||||
const BearerToken = req.BearerToken;
|
||||
const client = req.userGraphQLClient;
|
||||
const BearerToken = req.BearerToken;
|
||||
const client = req.userGraphQLClient;
|
||||
|
||||
try {
|
||||
logger.log(
|
||||
"qbxml-payments-create",
|
||||
"DEBUG",
|
||||
req.user.email,
|
||||
req.body.paymentsToQuery,
|
||||
null
|
||||
);
|
||||
try {
|
||||
logger.log(
|
||||
"qbxml-payments-create",
|
||||
"DEBUG",
|
||||
req.user.email,
|
||||
req.body.paymentsToQuery,
|
||||
null
|
||||
);
|
||||
|
||||
const result = await client
|
||||
.setHeaders({ Authorization: BearerToken })
|
||||
.request(queries.QUERY_PAYMENTS_FOR_EXPORT, {
|
||||
payments: paymentsToQuery,
|
||||
});
|
||||
const { payments, bodyshops } = result;
|
||||
const bodyshop = bodyshops[0];
|
||||
const isThreeTier = bodyshop.accountingconfig.tiers === 3;
|
||||
const twoTierPref = bodyshop.accountingconfig.twotierpref;
|
||||
const result = await client
|
||||
.setHeaders({Authorization: BearerToken})
|
||||
.request(queries.QUERY_PAYMENTS_FOR_EXPORT, {
|
||||
payments: paymentsToQuery,
|
||||
});
|
||||
const {payments, bodyshops} = result;
|
||||
const bodyshop = bodyshops[0];
|
||||
const isThreeTier = bodyshop.accountingconfig.tiers === 3;
|
||||
const twoTierPref = bodyshop.accountingconfig.twotierpref;
|
||||
|
||||
const QbXmlToExecute = [];
|
||||
payments.map((i) => {
|
||||
if (isThreeTier) {
|
||||
QbXmlToExecute.push({
|
||||
id: i.id,
|
||||
okStatusCodes: ["0", "3100"],
|
||||
qbxml: QbxmlReceivables.generateSourceCustomerQbxml(i.job, bodyshop), // Create the source customer.
|
||||
const QbXmlToExecute = [];
|
||||
payments.map((i) => {
|
||||
if (isThreeTier) {
|
||||
QbXmlToExecute.push({
|
||||
id: i.id,
|
||||
okStatusCodes: ["0", "3100"],
|
||||
qbxml: QbxmlReceivables.generateSourceCustomerQbxml(i.job, bodyshop), // Create the source customer.
|
||||
});
|
||||
}
|
||||
|
||||
QbXmlToExecute.push({
|
||||
id: i.id,
|
||||
okStatusCodes: ["0", "3100"],
|
||||
qbxml: QbxmlReceivables.generateJobQbxml(
|
||||
i.job,
|
||||
bodyshop,
|
||||
isThreeTier,
|
||||
2,
|
||||
twoTierPref
|
||||
),
|
||||
});
|
||||
|
||||
QbXmlToExecute.push({
|
||||
id: i.id,
|
||||
okStatusCodes: ["0", "3100"],
|
||||
qbxml: QbxmlReceivables.generateJobQbxml(
|
||||
i.job,
|
||||
bodyshop,
|
||||
isThreeTier,
|
||||
3,
|
||||
twoTierPref
|
||||
),
|
||||
});
|
||||
|
||||
QbXmlToExecute.push({
|
||||
id: i.id,
|
||||
okStatusCodes: ["0"],
|
||||
qbxml: generatePayment(i, isThreeTier, twoTierPref, bodyshop),
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
QbXmlToExecute.push({
|
||||
id: i.id,
|
||||
okStatusCodes: ["0", "3100"],
|
||||
qbxml: QbxmlReceivables.generateJobQbxml(
|
||||
i.job,
|
||||
bodyshop,
|
||||
isThreeTier,
|
||||
2,
|
||||
twoTierPref
|
||||
),
|
||||
});
|
||||
|
||||
QbXmlToExecute.push({
|
||||
id: i.id,
|
||||
okStatusCodes: ["0", "3100"],
|
||||
qbxml: QbxmlReceivables.generateJobQbxml(
|
||||
i.job,
|
||||
bodyshop,
|
||||
isThreeTier,
|
||||
3,
|
||||
twoTierPref
|
||||
),
|
||||
});
|
||||
|
||||
QbXmlToExecute.push({
|
||||
id: i.id,
|
||||
okStatusCodes: ["0"],
|
||||
qbxml: generatePayment(i, isThreeTier, twoTierPref, bodyshop),
|
||||
});
|
||||
});
|
||||
|
||||
res.status(200).json(QbXmlToExecute);
|
||||
} catch (error) {
|
||||
logger.log(
|
||||
"qbxml-payments-error",
|
||||
"error",
|
||||
req.user.email,
|
||||
req.body.paymentsToQuery,
|
||||
{ error: error.message, stack: error.stack }
|
||||
);
|
||||
res.status(400).send(JSON.stringify(error));
|
||||
}
|
||||
res.status(200).json(QbXmlToExecute);
|
||||
} catch (error) {
|
||||
logger.log(
|
||||
"qbxml-payments-error",
|
||||
"error",
|
||||
req.user.email,
|
||||
req.body.paymentsToQuery,
|
||||
{error: error.message, stack: error.stack}
|
||||
);
|
||||
res.status(400).send(JSON.stringify(error));
|
||||
}
|
||||
};
|
||||
|
||||
const generatePayment = (payment, isThreeTier, twoTierPref, bodyshop) => {
|
||||
let paymentQbxmlObj;
|
||||
if (payment.amount > 0) {
|
||||
paymentQbxmlObj = {
|
||||
QBXML: {
|
||||
QBXMLMsgsRq: {
|
||||
"@onError": "continueOnError",
|
||||
ReceivePaymentAddRq: {
|
||||
ReceivePaymentAdd: {
|
||||
CustomerRef: {
|
||||
FullName: (payment.job.bodyshop.accountingconfig.tiers === 3
|
||||
? `${generateSourceTier(payment.job)}:${generateOwnerTier(
|
||||
payment.job,
|
||||
isThreeTier,
|
||||
twoTierPref
|
||||
)}:${generateJobTier(payment.job)}`
|
||||
: `${generateOwnerTier(
|
||||
payment.job,
|
||||
isThreeTier,
|
||||
twoTierPref
|
||||
)}:${generateJobTier(payment.job)}`
|
||||
).trim(),
|
||||
},
|
||||
ARAccountRef: {
|
||||
FullName:
|
||||
payment.job.bodyshop.md_responsibility_centers.ar.accountname,
|
||||
},
|
||||
TxnDate: moment(payment.date)
|
||||
// .tz(bodyshop.timezone)
|
||||
.format("YYYY-MM-DD"), //Trim String
|
||||
RefNumber: payment.paymentnum || payment.transactionid,
|
||||
TotalAmount: Dinero({
|
||||
amount: Math.round(payment.amount * 100),
|
||||
}).toFormat(DineroQbFormat),
|
||||
PaymentMethodRef: {
|
||||
FullName: payment.type,
|
||||
},
|
||||
Memo: `RO ${payment.job.ro_number || ""} OWNER ${
|
||||
payment.job.ownr_fn || ""
|
||||
} ${payment.job.ownr_ln || ""} ${payment.job.ownr_co_nm || ""} ${
|
||||
payment.stripeid || ""
|
||||
} ${payment.payer ? ` PAID BY ${payment.payer}` : ""}`,
|
||||
IsAutoApply: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
} else {
|
||||
paymentQbxmlObj = {
|
||||
QBXML: {
|
||||
QBXMLMsgsRq: {
|
||||
"@onError": "continueOnError",
|
||||
CreditMemoAddRq: {
|
||||
CreditMemoAdd: {
|
||||
CustomerRef: {
|
||||
FullName: (payment.job.bodyshop.accountingconfig.tiers === 3
|
||||
? `${generateSourceTier(payment.job)}:${generateOwnerTier(
|
||||
payment.job,
|
||||
isThreeTier,
|
||||
twoTierPref
|
||||
)}:${generateJobTier(payment.job)}`
|
||||
: `${generateOwnerTier(
|
||||
payment.job,
|
||||
isThreeTier,
|
||||
twoTierPref
|
||||
)}:${generateJobTier(payment.job)}`
|
||||
).trim(),
|
||||
},
|
||||
ARAccountRef: {
|
||||
FullName:
|
||||
payment.job.bodyshop.md_responsibility_centers.ar.accountname,
|
||||
},
|
||||
TxnDate: moment(payment.date)
|
||||
//.tz(bodyshop.timezone)
|
||||
.format("YYYY-MM-DD"), //Trim String
|
||||
RefNumber:
|
||||
payment.paymentnum || payment.stripeid || payment.transactionid,
|
||||
|
||||
CreditMemoLineAdd: [
|
||||
{
|
||||
ItemRef: {
|
||||
FullName:
|
||||
payment.job.bodyshop.md_responsibility_centers.refund
|
||||
.accountitem,
|
||||
},
|
||||
Desc: payment.memo,
|
||||
Amount: Dinero({
|
||||
amount: Math.round(payment.amount * 100 * -1),
|
||||
}).toFormat(DineroQbFormat),
|
||||
SalesTaxCodeRef: { FullName: "E" },
|
||||
let paymentQbxmlObj;
|
||||
if (payment.amount > 0) {
|
||||
paymentQbxmlObj = {
|
||||
QBXML: {
|
||||
QBXMLMsgsRq: {
|
||||
"@onError": "continueOnError",
|
||||
ReceivePaymentAddRq: {
|
||||
ReceivePaymentAdd: {
|
||||
CustomerRef: {
|
||||
FullName: (payment.job.bodyshop.accountingconfig.tiers === 3
|
||||
? `${generateSourceTier(payment.job)}:${generateOwnerTier(
|
||||
payment.job,
|
||||
isThreeTier,
|
||||
twoTierPref
|
||||
)}:${generateJobTier(payment.job)}`
|
||||
: `${generateOwnerTier(
|
||||
payment.job,
|
||||
isThreeTier,
|
||||
twoTierPref
|
||||
)}:${generateJobTier(payment.job)}`
|
||||
).trim(),
|
||||
},
|
||||
ARAccountRef: {
|
||||
FullName:
|
||||
payment.job.bodyshop.md_responsibility_centers.ar.accountname,
|
||||
},
|
||||
TxnDate: moment(payment.date)
|
||||
// .tz(bodyshop.timezone)
|
||||
.format("YYYY-MM-DD"), //Trim String
|
||||
RefNumber: payment.paymentnum || payment.transactionid,
|
||||
TotalAmount: Dinero({
|
||||
amount: Math.round(payment.amount * 100),
|
||||
}).toFormat(DineroQbFormat),
|
||||
PaymentMethodRef: {
|
||||
FullName: payment.type,
|
||||
},
|
||||
Memo: `RO ${payment.job.ro_number || ""} OWNER ${
|
||||
payment.job.ownr_fn || ""
|
||||
} ${payment.job.ownr_ln || ""} ${payment.job.ownr_co_nm || ""} ${
|
||||
payment.stripeid || ""
|
||||
} ${payment.payer ? ` PAID BY ${payment.payer}` : ""}`,
|
||||
IsAutoApply: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
};
|
||||
} else {
|
||||
paymentQbxmlObj = {
|
||||
QBXML: {
|
||||
QBXMLMsgsRq: {
|
||||
"@onError": "continueOnError",
|
||||
CreditMemoAddRq: {
|
||||
CreditMemoAdd: {
|
||||
CustomerRef: {
|
||||
FullName: (payment.job.bodyshop.accountingconfig.tiers === 3
|
||||
? `${generateSourceTier(payment.job)}:${generateOwnerTier(
|
||||
payment.job,
|
||||
isThreeTier,
|
||||
twoTierPref
|
||||
)}:${generateJobTier(payment.job)}`
|
||||
: `${generateOwnerTier(
|
||||
payment.job,
|
||||
isThreeTier,
|
||||
twoTierPref
|
||||
)}:${generateJobTier(payment.job)}`
|
||||
).trim(),
|
||||
},
|
||||
ARAccountRef: {
|
||||
FullName:
|
||||
payment.job.bodyshop.md_responsibility_centers.ar.accountname,
|
||||
},
|
||||
TxnDate: moment(payment.date)
|
||||
//.tz(bodyshop.timezone)
|
||||
.format("YYYY-MM-DD"), //Trim String
|
||||
RefNumber:
|
||||
payment.paymentnum || payment.stripeid || payment.transactionid,
|
||||
|
||||
var paymentQbxmlPartial = builder
|
||||
.create(paymentQbxmlObj, {
|
||||
version: "1.30",
|
||||
encoding: "UTF-8",
|
||||
headless: true,
|
||||
})
|
||||
.end({ pretty: true });
|
||||
CreditMemoLineAdd: [
|
||||
{
|
||||
ItemRef: {
|
||||
FullName:
|
||||
payment.job.bodyshop.md_responsibility_centers.refund
|
||||
.accountitem,
|
||||
},
|
||||
Desc: payment.memo,
|
||||
Amount: Dinero({
|
||||
amount: Math.round(payment.amount * 100 * -1),
|
||||
}).toFormat(DineroQbFormat),
|
||||
SalesTaxCodeRef: {FullName: "E"},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
const paymentQbxmlFull = QbXmlUtils.addQbxmlHeader(paymentQbxmlPartial);
|
||||
var paymentQbxmlPartial = builder
|
||||
.create(paymentQbxmlObj, {
|
||||
version: "1.30",
|
||||
encoding: "UTF-8",
|
||||
headless: true,
|
||||
})
|
||||
.end({pretty: true});
|
||||
|
||||
return paymentQbxmlFull;
|
||||
const paymentQbxmlFull = QbXmlUtils.addQbxmlHeader(paymentQbxmlPartial);
|
||||
|
||||
return paymentQbxmlFull;
|
||||
};
|
||||
|
||||
@@ -9,304 +9,304 @@ const CreateInvoiceLines = require("../qb-receivables-lines").default;
|
||||
const logger = require('../../utils/logger');
|
||||
|
||||
require("dotenv").config({
|
||||
path: path.resolve(
|
||||
process.cwd(),
|
||||
`.env.${process.env.NODE_ENV || "development"}`
|
||||
),
|
||||
path: path.resolve(
|
||||
process.cwd(),
|
||||
`.env.${process.env.NODE_ENV || "development"}`
|
||||
),
|
||||
});
|
||||
|
||||
Dinero.globalRoundingMode = "HALF_EVEN";
|
||||
const { generateJobTier, generateOwnerTier, generateSourceTier } = QbXmlUtils;
|
||||
const {generateJobTier, generateOwnerTier, generateSourceTier} = QbXmlUtils;
|
||||
|
||||
exports.default = async (req, res) => {
|
||||
const { jobIds } = req.body;
|
||||
const {jobIds} = req.body;
|
||||
|
||||
const BearerToken = req.BearerToken;
|
||||
const client = req.userGraphQLClient;
|
||||
const BearerToken = req.BearerToken;
|
||||
const client = req.userGraphQLClient;
|
||||
|
||||
try {
|
||||
logger.log(
|
||||
"qbxml-receivables-create",
|
||||
"DEBUG",
|
||||
req.user.email,
|
||||
req.body.jobIds,
|
||||
null
|
||||
);
|
||||
try {
|
||||
logger.log(
|
||||
"qbxml-receivables-create",
|
||||
"DEBUG",
|
||||
req.user.email,
|
||||
req.body.jobIds,
|
||||
null
|
||||
);
|
||||
|
||||
const result = await client
|
||||
.setHeaders({ Authorization: BearerToken })
|
||||
.request(queries.QUERY_JOBS_FOR_RECEIVABLES_EXPORT, { ids: jobIds });
|
||||
const { jobs, bodyshops } = result;
|
||||
const QbXmlToExecute = [];
|
||||
const result = await client
|
||||
.setHeaders({Authorization: BearerToken})
|
||||
.request(queries.QUERY_JOBS_FOR_RECEIVABLES_EXPORT, {ids: jobIds});
|
||||
const {jobs, bodyshops} = result;
|
||||
const QbXmlToExecute = [];
|
||||
|
||||
const bodyshop = bodyshops[0];
|
||||
const bodyshop = bodyshops[0];
|
||||
|
||||
jobs.map((jobs_by_pk) => {
|
||||
//Is this a two tier, or 3 tier setup?
|
||||
const isThreeTier = bodyshop.accountingconfig.tiers === 3;
|
||||
const twoTierPref = bodyshop.accountingconfig.twotierpref;
|
||||
jobs.map((jobs_by_pk) => {
|
||||
//Is this a two tier, or 3 tier setup?
|
||||
const isThreeTier = bodyshop.accountingconfig.tiers === 3;
|
||||
const twoTierPref = bodyshop.accountingconfig.twotierpref;
|
||||
|
||||
//This is the Insurance Company tier IF 3 tier is selected.
|
||||
if (isThreeTier) {
|
||||
QbXmlToExecute.push({
|
||||
id: jobs_by_pk.id,
|
||||
okStatusCodes: ["0", "3100"],
|
||||
qbxml: generateSourceCustomerQbxml(jobs_by_pk, bodyshop), // Create the source customer.
|
||||
//This is the Insurance Company tier IF 3 tier is selected.
|
||||
if (isThreeTier) {
|
||||
QbXmlToExecute.push({
|
||||
id: jobs_by_pk.id,
|
||||
okStatusCodes: ["0", "3100"],
|
||||
qbxml: generateSourceCustomerQbxml(jobs_by_pk, bodyshop), // Create the source customer.
|
||||
});
|
||||
}
|
||||
|
||||
//If 3 tier, this should be the customer.
|
||||
//If 2 tier, this should be based on the pref.
|
||||
QbXmlToExecute.push({
|
||||
id: jobs_by_pk.id,
|
||||
okStatusCodes: ["0", "3100"],
|
||||
qbxml: generateJobQbxml(
|
||||
jobs_by_pk,
|
||||
bodyshop,
|
||||
isThreeTier,
|
||||
2,
|
||||
twoTierPref
|
||||
),
|
||||
});
|
||||
|
||||
//This is always going to be the job.
|
||||
QbXmlToExecute.push({
|
||||
id: jobs_by_pk.id,
|
||||
okStatusCodes: ["0", "3100"],
|
||||
qbxml: generateJobQbxml(
|
||||
jobs_by_pk,
|
||||
bodyshop,
|
||||
isThreeTier,
|
||||
3,
|
||||
twoTierPref
|
||||
),
|
||||
});
|
||||
|
||||
if (!req.body.custDataOnly) {
|
||||
//Generate the actual invoice.
|
||||
QbXmlToExecute.push({
|
||||
id: jobs_by_pk.id,
|
||||
okStatusCodes: ["0"],
|
||||
qbxml: generateInvoiceQbxml(
|
||||
jobs_by_pk,
|
||||
bodyshop,
|
||||
isThreeTier,
|
||||
twoTierPref
|
||||
),
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//If 3 tier, this should be the customer.
|
||||
//If 2 tier, this should be based on the pref.
|
||||
QbXmlToExecute.push({
|
||||
id: jobs_by_pk.id,
|
||||
okStatusCodes: ["0", "3100"],
|
||||
qbxml: generateJobQbxml(
|
||||
jobs_by_pk,
|
||||
bodyshop,
|
||||
isThreeTier,
|
||||
2,
|
||||
twoTierPref
|
||||
),
|
||||
});
|
||||
|
||||
//This is always going to be the job.
|
||||
QbXmlToExecute.push({
|
||||
id: jobs_by_pk.id,
|
||||
okStatusCodes: ["0", "3100"],
|
||||
qbxml: generateJobQbxml(
|
||||
jobs_by_pk,
|
||||
bodyshop,
|
||||
isThreeTier,
|
||||
3,
|
||||
twoTierPref
|
||||
),
|
||||
});
|
||||
|
||||
if (!req.body.custDataOnly) {
|
||||
//Generate the actual invoice.
|
||||
QbXmlToExecute.push({
|
||||
id: jobs_by_pk.id,
|
||||
okStatusCodes: ["0"],
|
||||
qbxml: generateInvoiceQbxml(
|
||||
jobs_by_pk,
|
||||
bodyshop,
|
||||
isThreeTier,
|
||||
twoTierPref
|
||||
),
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
res.status(200).json(QbXmlToExecute);
|
||||
} catch (error) {
|
||||
logger.log(
|
||||
"qbxml-receivables-error",
|
||||
"error",
|
||||
req.user.email,
|
||||
req.body.jobIds,
|
||||
{ error: error.message, stack: error.stack }
|
||||
);
|
||||
res.status(400).send(JSON.stringify(error));
|
||||
}
|
||||
res.status(200).json(QbXmlToExecute);
|
||||
} catch (error) {
|
||||
logger.log(
|
||||
"qbxml-receivables-error",
|
||||
"error",
|
||||
req.user.email,
|
||||
req.body.jobIds,
|
||||
{error: error.message, stack: error.stack}
|
||||
);
|
||||
res.status(400).send(JSON.stringify(error));
|
||||
}
|
||||
};
|
||||
|
||||
const generateSourceCustomerQbxml = (jobs_by_pk, bodyshop) => {
|
||||
const customerQbxmlObj = {
|
||||
QBXML: {
|
||||
QBXMLMsgsRq: {
|
||||
"@onError": "continueOnError",
|
||||
CustomerAddRq: {
|
||||
CustomerAdd: {
|
||||
Name: jobs_by_pk.ins_co_nm.trim(),
|
||||
// BillAddress: {
|
||||
// Addr1: jobs_by_pk.ownr_addr1,
|
||||
// Addr2: jobs_by_pk.ownr_addr2,
|
||||
// City: jobs_by_pk.ownr_city,
|
||||
// State: jobs_by_pk.ownr_st,
|
||||
// PostalCode: jobs_by_pk.ownr_zip,
|
||||
// },
|
||||
},
|
||||
const customerQbxmlObj = {
|
||||
QBXML: {
|
||||
QBXMLMsgsRq: {
|
||||
"@onError": "continueOnError",
|
||||
CustomerAddRq: {
|
||||
CustomerAdd: {
|
||||
Name: jobs_by_pk.ins_co_nm.trim(),
|
||||
// BillAddress: {
|
||||
// Addr1: jobs_by_pk.ownr_addr1,
|
||||
// Addr2: jobs_by_pk.ownr_addr2,
|
||||
// City: jobs_by_pk.ownr_city,
|
||||
// State: jobs_by_pk.ownr_st,
|
||||
// PostalCode: jobs_by_pk.ownr_zip,
|
||||
// },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
var customerQbxml_partial = builder
|
||||
.create(customerQbxmlObj, {
|
||||
version: "1.30",
|
||||
encoding: "UTF-8",
|
||||
headless: true,
|
||||
})
|
||||
.end({ pretty: true });
|
||||
var customerQbxml_partial = builder
|
||||
.create(customerQbxmlObj, {
|
||||
version: "1.30",
|
||||
encoding: "UTF-8",
|
||||
headless: true,
|
||||
})
|
||||
.end({pretty: true});
|
||||
|
||||
const customerQbxml_Full = QbXmlUtils.addQbxmlHeader(customerQbxml_partial);
|
||||
const customerQbxml_Full = QbXmlUtils.addQbxmlHeader(customerQbxml_partial);
|
||||
|
||||
return customerQbxml_Full;
|
||||
return customerQbxml_Full;
|
||||
};
|
||||
exports.generateSourceCustomerQbxml = generateSourceCustomerQbxml;
|
||||
const generateJobQbxml = (
|
||||
jobs_by_pk,
|
||||
bodyshop,
|
||||
isThreeTier,
|
||||
tierLevel,
|
||||
twoTierPref
|
||||
jobs_by_pk,
|
||||
bodyshop,
|
||||
isThreeTier,
|
||||
tierLevel,
|
||||
twoTierPref
|
||||
) => {
|
||||
let Name;
|
||||
let ParentRefName;
|
||||
let Name;
|
||||
let ParentRefName;
|
||||
|
||||
if (tierLevel === 2) {
|
||||
Name = generateOwnerTier(jobs_by_pk, isThreeTier, twoTierPref);
|
||||
ParentRefName = isThreeTier ? generateSourceTier(jobs_by_pk) : null;
|
||||
} else if (tierLevel === 3) {
|
||||
Name = generateJobTier(jobs_by_pk);
|
||||
ParentRefName = isThreeTier
|
||||
? `${generateSourceTier(jobs_by_pk)}:${generateOwnerTier(jobs_by_pk)}`
|
||||
: generateOwnerTier(jobs_by_pk, isThreeTier, twoTierPref);
|
||||
}
|
||||
if (tierLevel === 2) {
|
||||
Name = generateOwnerTier(jobs_by_pk, isThreeTier, twoTierPref);
|
||||
ParentRefName = isThreeTier ? generateSourceTier(jobs_by_pk) : null;
|
||||
} else if (tierLevel === 3) {
|
||||
Name = generateJobTier(jobs_by_pk);
|
||||
ParentRefName = isThreeTier
|
||||
? `${generateSourceTier(jobs_by_pk)}:${generateOwnerTier(jobs_by_pk)}`
|
||||
: generateOwnerTier(jobs_by_pk, isThreeTier, twoTierPref);
|
||||
}
|
||||
|
||||
const jobQbxmlObj = {
|
||||
QBXML: {
|
||||
QBXMLMsgsRq: {
|
||||
"@onError": "continueOnError",
|
||||
const jobQbxmlObj = {
|
||||
QBXML: {
|
||||
QBXMLMsgsRq: {
|
||||
"@onError": "continueOnError",
|
||||
|
||||
CustomerAddRq: {
|
||||
CustomerAdd: {
|
||||
Name: Name,
|
||||
ParentRef: ParentRefName
|
||||
? {
|
||||
FullName: ParentRefName,
|
||||
}
|
||||
: null,
|
||||
...(tierLevel === 3
|
||||
? {
|
||||
BillAddress: {
|
||||
Addr1: jobs_by_pk.ownr_addr1,
|
||||
Addr2: jobs_by_pk.ownr_addr2,
|
||||
City: jobs_by_pk.ownr_city,
|
||||
State: jobs_by_pk.ownr_st,
|
||||
PostalCode: jobs_by_pk.ownr_zip,
|
||||
},
|
||||
ShipAddress: {
|
||||
Addr1: jobs_by_pk.ownr_addr1,
|
||||
Addr2: jobs_by_pk.ownr_addr2,
|
||||
City: jobs_by_pk.ownr_city,
|
||||
State: jobs_by_pk.ownr_st,
|
||||
PostalCode: jobs_by_pk.ownr_zip,
|
||||
},
|
||||
Email: jobs_by_pk.ownr_ea,
|
||||
}
|
||||
: {}),
|
||||
},
|
||||
CustomerAddRq: {
|
||||
CustomerAdd: {
|
||||
Name: Name,
|
||||
ParentRef: ParentRefName
|
||||
? {
|
||||
FullName: ParentRefName,
|
||||
}
|
||||
: null,
|
||||
...(tierLevel === 3
|
||||
? {
|
||||
BillAddress: {
|
||||
Addr1: jobs_by_pk.ownr_addr1,
|
||||
Addr2: jobs_by_pk.ownr_addr2,
|
||||
City: jobs_by_pk.ownr_city,
|
||||
State: jobs_by_pk.ownr_st,
|
||||
PostalCode: jobs_by_pk.ownr_zip,
|
||||
},
|
||||
ShipAddress: {
|
||||
Addr1: jobs_by_pk.ownr_addr1,
|
||||
Addr2: jobs_by_pk.ownr_addr2,
|
||||
City: jobs_by_pk.ownr_city,
|
||||
State: jobs_by_pk.ownr_st,
|
||||
PostalCode: jobs_by_pk.ownr_zip,
|
||||
},
|
||||
Email: jobs_by_pk.ownr_ea,
|
||||
}
|
||||
: {}),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
var jobQbxml_partial = builder
|
||||
.create(jobQbxmlObj, {
|
||||
version: "1.30",
|
||||
encoding: "UTF-8",
|
||||
headless: true,
|
||||
})
|
||||
.end({ pretty: true });
|
||||
var jobQbxml_partial = builder
|
||||
.create(jobQbxmlObj, {
|
||||
version: "1.30",
|
||||
encoding: "UTF-8",
|
||||
headless: true,
|
||||
})
|
||||
.end({pretty: true});
|
||||
|
||||
const jobQbxml_Full = QbXmlUtils.addQbxmlHeader(jobQbxml_partial);
|
||||
const jobQbxml_Full = QbXmlUtils.addQbxmlHeader(jobQbxml_partial);
|
||||
|
||||
return jobQbxml_Full;
|
||||
return jobQbxml_Full;
|
||||
};
|
||||
|
||||
exports.generateJobQbxml = generateJobQbxml;
|
||||
const generateInvoiceQbxml = (
|
||||
jobs_by_pk,
|
||||
bodyshop,
|
||||
isThreeTier,
|
||||
twoTierPref
|
||||
jobs_by_pk,
|
||||
bodyshop,
|
||||
isThreeTier,
|
||||
twoTierPref
|
||||
) => {
|
||||
//Build the Invoice XML file.
|
||||
//Build the Invoice XML file.
|
||||
|
||||
const InvoiceLineAdd = CreateInvoiceLines({ bodyshop, jobs_by_pk });
|
||||
const InvoiceLineAdd = CreateInvoiceLines({bodyshop, jobs_by_pk});
|
||||
|
||||
const invoiceQbxmlObj = {
|
||||
QBXML: {
|
||||
QBXMLMsgsRq: {
|
||||
"@onError": "stopOnError",
|
||||
InvoiceAddRq: {
|
||||
InvoiceAdd: {
|
||||
CustomerRef: {
|
||||
FullName: (bodyshop.accountingconfig.tiers === 3
|
||||
? `${generateSourceTier(jobs_by_pk)}:${generateOwnerTier(
|
||||
jobs_by_pk
|
||||
)}:${generateJobTier(jobs_by_pk)}`
|
||||
: `${generateOwnerTier(
|
||||
jobs_by_pk,
|
||||
isThreeTier,
|
||||
twoTierPref
|
||||
)}:${generateJobTier(jobs_by_pk)}`
|
||||
).trim(),
|
||||
},
|
||||
...(jobs_by_pk.class
|
||||
? { ClassRef: { FullName: jobs_by_pk.class } }
|
||||
: {}),
|
||||
const invoiceQbxmlObj = {
|
||||
QBXML: {
|
||||
QBXMLMsgsRq: {
|
||||
"@onError": "stopOnError",
|
||||
InvoiceAddRq: {
|
||||
InvoiceAdd: {
|
||||
CustomerRef: {
|
||||
FullName: (bodyshop.accountingconfig.tiers === 3
|
||||
? `${generateSourceTier(jobs_by_pk)}:${generateOwnerTier(
|
||||
jobs_by_pk
|
||||
)}:${generateJobTier(jobs_by_pk)}`
|
||||
: `${generateOwnerTier(
|
||||
jobs_by_pk,
|
||||
isThreeTier,
|
||||
twoTierPref
|
||||
)}:${generateJobTier(jobs_by_pk)}`
|
||||
).trim(),
|
||||
},
|
||||
...(jobs_by_pk.class
|
||||
? {ClassRef: {FullName: jobs_by_pk.class}}
|
||||
: {}),
|
||||
|
||||
ARAccountRef: {
|
||||
FullName: bodyshop.md_responsibility_centers.ar.accountname,
|
||||
},
|
||||
TxnDate: moment(jobs_by_pk.date_invoiced)
|
||||
.tz(bodyshop.timezone)
|
||||
.format("YYYY-MM-DD"),
|
||||
RefNumber: jobs_by_pk.ro_number,
|
||||
BillAddress: {
|
||||
Addr1: jobs_by_pk.ownr_co_nm
|
||||
? 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,
|
||||
State: jobs_by_pk.ownr_st,
|
||||
PostalCode: jobs_by_pk.ownr_zip,
|
||||
},
|
||||
ShipAddress: {
|
||||
Addr1: jobs_by_pk.ownr_co_nm
|
||||
? 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,
|
||||
State: jobs_by_pk.ownr_st,
|
||||
PostalCode: jobs_by_pk.ownr_zip,
|
||||
},
|
||||
PONumber: jobs_by_pk.clm_no,
|
||||
ItemSalesTaxRef: {
|
||||
FullName:
|
||||
bodyshop.md_responsibility_centers.taxes.invoiceexemptcode,
|
||||
},
|
||||
IsToBePrinted: bodyshop.accountingconfig.printlater,
|
||||
...(jobs_by_pk.ownr_ea
|
||||
? { IsToBeEmailed: bodyshop.accountingconfig.emaillater }
|
||||
: {}),
|
||||
ARAccountRef: {
|
||||
FullName: bodyshop.md_responsibility_centers.ar.accountname,
|
||||
},
|
||||
TxnDate: moment(jobs_by_pk.date_invoiced)
|
||||
.tz(bodyshop.timezone)
|
||||
.format("YYYY-MM-DD"),
|
||||
RefNumber: jobs_by_pk.ro_number,
|
||||
BillAddress: {
|
||||
Addr1: jobs_by_pk.ownr_co_nm
|
||||
? 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,
|
||||
State: jobs_by_pk.ownr_st,
|
||||
PostalCode: jobs_by_pk.ownr_zip,
|
||||
},
|
||||
ShipAddress: {
|
||||
Addr1: jobs_by_pk.ownr_co_nm
|
||||
? 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,
|
||||
State: jobs_by_pk.ownr_st,
|
||||
PostalCode: jobs_by_pk.ownr_zip,
|
||||
},
|
||||
PONumber: jobs_by_pk.clm_no,
|
||||
ItemSalesTaxRef: {
|
||||
FullName:
|
||||
bodyshop.md_responsibility_centers.taxes.invoiceexemptcode,
|
||||
},
|
||||
IsToBePrinted: bodyshop.accountingconfig.printlater,
|
||||
...(jobs_by_pk.ownr_ea
|
||||
? {IsToBeEmailed: bodyshop.accountingconfig.emaillater}
|
||||
: {}),
|
||||
|
||||
InvoiceLineAdd: InvoiceLineAdd,
|
||||
},
|
||||
InvoiceLineAdd: InvoiceLineAdd,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
var invoiceQbxml_partial = builder
|
||||
.create(invoiceQbxmlObj, {
|
||||
version: "1.30",
|
||||
encoding: "UTF-8",
|
||||
headless: true,
|
||||
})
|
||||
.end({ pretty: true });
|
||||
var invoiceQbxml_partial = builder
|
||||
.create(invoiceQbxmlObj, {
|
||||
version: "1.30",
|
||||
encoding: "UTF-8",
|
||||
headless: true,
|
||||
})
|
||||
.end({pretty: true});
|
||||
|
||||
const invoiceQbxml_Full = QbXmlUtils.addQbxmlHeader(invoiceQbxml_partial);
|
||||
const invoiceQbxml_Full = QbXmlUtils.addQbxmlHeader(invoiceQbxml_partial);
|
||||
|
||||
return invoiceQbxml_Full;
|
||||
return invoiceQbxml_Full;
|
||||
};
|
||||
|
||||
// const generateInvoiceLine = (job, allocation, responsibilityCenters) => {
|
||||
|
||||
@@ -1,50 +1,50 @@
|
||||
exports.addQbxmlHeader = addQbxmlHeader = (xml) => {
|
||||
return `<?xml version="1.0" encoding="utf-8"?>
|
||||
return `<?xml version="1.0" encoding="utf-8"?>
|
||||
<?qbxml version="13.0"?>
|
||||
${xml}
|
||||
`;
|
||||
};
|
||||
|
||||
exports.generateSourceTier = (jobs_by_pk) => {
|
||||
return jobs_by_pk.ins_co_nm && jobs_by_pk.ins_co_nm.trim().replace(":", " ");
|
||||
return jobs_by_pk.ins_co_nm && jobs_by_pk.ins_co_nm.trim().replace(":", " ");
|
||||
};
|
||||
|
||||
exports.generateJobTier = (jobs_by_pk) => {
|
||||
return jobs_by_pk.ro_number && jobs_by_pk.ro_number.trim().replace(":", " ");
|
||||
return jobs_by_pk.ro_number && jobs_by_pk.ro_number.trim().replace(":", " ");
|
||||
};
|
||||
|
||||
exports.generateOwnerTier = (jobs_by_pk, isThreeTier, twotierpref) => {
|
||||
if (isThreeTier) {
|
||||
//It's always gonna be the owner now. Same as 2 tier by name
|
||||
return (
|
||||
jobs_by_pk.ownr_co_nm
|
||||
? `${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)
|
||||
.trim()} #${jobs_by_pk.owner.accountingid || ""}`
|
||||
)
|
||||
.trim()
|
||||
.replace(":", " ");
|
||||
} else {
|
||||
//What's the 2 tier pref?
|
||||
if (twotierpref === "source") {
|
||||
return this.generateSourceTier(jobs_by_pk);
|
||||
//It should be the insurance co.
|
||||
if (isThreeTier) {
|
||||
//It's always gonna be the owner now. Same as 2 tier by name
|
||||
return (
|
||||
jobs_by_pk.ownr_co_nm
|
||||
? `${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)
|
||||
.trim()} #${jobs_by_pk.owner.accountingid || ""}`
|
||||
)
|
||||
.trim()
|
||||
.replace(":", " ");
|
||||
} else {
|
||||
//Same as 3 tier
|
||||
return (
|
||||
jobs_by_pk.ownr_co_nm
|
||||
? `${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)
|
||||
.trim()} #${jobs_by_pk.owner.accountingid || ""}`
|
||||
)
|
||||
.trim()
|
||||
.replace(":", " ");
|
||||
//What's the 2 tier pref?
|
||||
if (twotierpref === "source") {
|
||||
return this.generateSourceTier(jobs_by_pk);
|
||||
//It should be the insurance co.
|
||||
} else {
|
||||
//Same as 3 tier
|
||||
return (
|
||||
jobs_by_pk.ownr_co_nm
|
||||
? `${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)
|
||||
.trim()} #${jobs_by_pk.owner.accountingid || ""}`
|
||||
)
|
||||
.trim()
|
||||
.replace(":", " ");
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
{
|
||||
"id": "12345",
|
||||
"okStatusCodes": ["0", "31400"],
|
||||
"okStatusCodes": [
|
||||
"0",
|
||||
"31400"
|
||||
],
|
||||
"qbxml": "the qbxml string"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user