Merged in feature/IO-3498-QBO-Auth-Token (pull request #2843)
IO-3498 QBO Fix for Returned Data from oauthClient Approved-by: Dave Richer
This commit is contained in:
@@ -57,14 +57,3 @@ exports.refresh = async (oauthClient, req) => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.setNewRefreshToken = async (email, apiResponse) => {
|
|
||||||
// Deprecated - tokens are now auto-updated in the oauthClient and the token isn't pushed back from QBO API calls anymore
|
|
||||||
|
|
||||||
// logger.log("qbo-token-updated", "DEBUG", email, null, {apiResponse: apiResponse});
|
|
||||||
|
|
||||||
// await client.request(queries.SET_QBO_AUTH, {
|
|
||||||
// email,
|
|
||||||
// qbo_auth: { ...apiResponse.token, createdAt: Date.now() }
|
|
||||||
// });
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ const Dinero = require("dinero.js");
|
|||||||
const DineroQbFormat = require("../accounting-constants").DineroQbFormat;
|
const DineroQbFormat = require("../accounting-constants").DineroQbFormat;
|
||||||
const apiGqlClient = require("../../graphql-client/graphql-client").client;
|
const apiGqlClient = require("../../graphql-client/graphql-client").client;
|
||||||
const queries = require("../../graphql-client/queries");
|
const queries = require("../../graphql-client/queries");
|
||||||
const { refresh: refreshOauthToken, setNewRefreshToken } = require("./qbo-callback");
|
const { refresh: refreshOauthToken } = require("./qbo-callback");
|
||||||
const OAuthClient = require("intuit-oauth");
|
const OAuthClient = require("intuit-oauth");
|
||||||
const moment = require("moment-timezone");
|
const moment = require("moment-timezone");
|
||||||
const findTaxCode = require("../qb-receivables-lines").findTaxCode;
|
const findTaxCode = require("../qb-receivables-lines").findTaxCode;
|
||||||
@@ -87,17 +87,17 @@ exports.default = async (req, res) => {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.log("qbo-paybles-create-error", "ERROR", req.user.email, null, {
|
logger.log("qbo-paybles-create-error", "ERROR", req.user.email, null, {
|
||||||
error:
|
error:
|
||||||
(error?.authResponse && error.authResponse.body) ||
|
error?.authResponse?.body ||
|
||||||
error.response?.data?.Fault?.Error.map((e) => e.Detail).join(", ") ||
|
error?.response?.data?.Fault?.Error.map((e) => e.Detail).join(", ") ||
|
||||||
error?.message
|
error?.message
|
||||||
});
|
});
|
||||||
ret.push({
|
ret.push({
|
||||||
billid: bill.id,
|
billid: bill.id,
|
||||||
success: false,
|
success: false,
|
||||||
errorMessage:
|
errorMessage:
|
||||||
(error && error.authResponse && error.authResponse.body) ||
|
error?.authResponse?.body ||
|
||||||
error.response?.data?.Fault?.Error.map((e) => e.Detail).join(", ") ||
|
error?.response?.data?.Fault?.Error.map((e) => e.Detail).join(", ") ||
|
||||||
(error && error.message)
|
error?.message
|
||||||
});
|
});
|
||||||
|
|
||||||
//Add the export log error.
|
//Add the export log error.
|
||||||
@@ -108,9 +108,7 @@ exports.default = async (req, res) => {
|
|||||||
bodyshopid: bodyshop.id,
|
bodyshopid: bodyshop.id,
|
||||||
billid: bill.id,
|
billid: bill.id,
|
||||||
successful: false,
|
successful: false,
|
||||||
message: JSON.stringify([
|
message: JSON.stringify([error?.authResponse?.body || error?.message]),
|
||||||
(error && error.authResponse && error.authResponse.body) || (error && error.message)
|
|
||||||
]),
|
|
||||||
useremail: req.user.email
|
useremail: req.user.email
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -152,8 +150,8 @@ async function QueryVendorRecord(oauthClient, qbo_realmId, req, bill) {
|
|||||||
bodyshopid: bill.job.shopid,
|
bodyshopid: bill.job.shopid,
|
||||||
email: req.user.email
|
email: req.user.email
|
||||||
});
|
});
|
||||||
setNewRefreshToken(req.user.email, result);
|
|
||||||
return result.json?.QueryResponse?.Vendor[0];
|
return result.json?.QueryResponse?.Vendor?.[0];
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.log("qbo-payables-error", "DEBUG", req.user.email, bill.id, {
|
logger.log("qbo-payables-error", "DEBUG", req.user.email, bill.id, {
|
||||||
method: "QueryVendorRecord",
|
method: "QueryVendorRecord",
|
||||||
@@ -186,11 +184,11 @@ async function InsertVendorRecord(oauthClient, qbo_realmId, req, bill) {
|
|||||||
bodyshopid: bill.job.shopid,
|
bodyshopid: bill.job.shopid,
|
||||||
email: req.user.email
|
email: req.user.email
|
||||||
});
|
});
|
||||||
setNewRefreshToken(req.user.email, result);
|
|
||||||
if (result.status >= 400) {
|
if (result.status >= 400) {
|
||||||
throw new Error(JSON.stringify(result.json.Fault));
|
throw new Error(JSON.stringify(result.json.Fault));
|
||||||
}
|
}
|
||||||
if (result.status === 200) return result?.json;
|
if (result.status === 200) return result?.json.Vendor;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.log("qbo-payables-error", "DEBUG", req.user.email, bill.id, {
|
logger.log("qbo-payables-error", "DEBUG", req.user.email, bill.id, {
|
||||||
method: "InsertVendorRecord",
|
method: "InsertVendorRecord",
|
||||||
@@ -248,12 +246,7 @@ async function InsertBill(oauthClient, qbo_realmId, req, bill, vendor, bodyshop)
|
|||||||
}
|
}
|
||||||
//QB USA with GST
|
//QB USA with GST
|
||||||
//This was required for the No. 1 Collision Group.
|
//This was required for the No. 1 Collision Group.
|
||||||
if (
|
if (bodyshop.accountingconfig?.qbo && bodyshop.accountingconfig?.qbo_usa && bodyshop.region_config.includes("CA_")) {
|
||||||
bodyshop.accountingconfig &&
|
|
||||||
bodyshop.accountingconfig.qbo &&
|
|
||||||
bodyshop.accountingconfig.qbo_usa &&
|
|
||||||
bodyshop.region_config.includes("CA_")
|
|
||||||
) {
|
|
||||||
lines.push({
|
lines.push({
|
||||||
DetailType: "AccountBasedExpenseLineDetail",
|
DetailType: "AccountBasedExpenseLineDetail",
|
||||||
|
|
||||||
@@ -276,7 +269,8 @@ async function InsertBill(oauthClient, qbo_realmId, req, bill, vendor, bodyshop)
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const billQbo = {
|
let billQbo, VendorCredit;
|
||||||
|
const billObject = {
|
||||||
VendorRef: {
|
VendorRef: {
|
||||||
value: vendor.Id
|
value: vendor.Id
|
||||||
},
|
},
|
||||||
@@ -298,22 +292,30 @@ async function InsertBill(oauthClient, qbo_realmId, req, bill, vendor, bodyshop)
|
|||||||
DocNumber: bill.invoice_number,
|
DocNumber: bill.invoice_number,
|
||||||
//...(bill.job.class ? { ClassRef: { Id: classes[bill.job.class] } } : {}),
|
//...(bill.job.class ? { ClassRef: { Id: classes[bill.job.class] } } : {}),
|
||||||
...(!(
|
...(!(
|
||||||
bodyshop.accountingconfig &&
|
bodyshop.accountingconfig?.qbo &&
|
||||||
bodyshop.accountingconfig.qbo &&
|
bodyshop.accountingconfig?.qbo_usa &&
|
||||||
bodyshop.accountingconfig.qbo_usa &&
|
|
||||||
bodyshop.region_config.includes("CA_")
|
bodyshop.region_config.includes("CA_")
|
||||||
)
|
)
|
||||||
? { GlobalTaxCalculation: "TaxExcluded" }
|
? { GlobalTaxCalculation: "TaxExcluded" }
|
||||||
: {}),
|
: {}),
|
||||||
...(bodyshop.accountingconfig.qbo_departmentid &&
|
...(bodyshop.accountingconfig.qbo_departmentid?.trim() !== "" && {
|
||||||
bodyshop.accountingconfig.qbo_departmentid.trim() !== "" && {
|
DepartmentRef: { value: bodyshop.accountingconfig.qbo_departmentid }
|
||||||
DepartmentRef: { value: bodyshop.accountingconfig.qbo_departmentid }
|
}),
|
||||||
}),
|
|
||||||
PrivateNote: `RO ${bill.job.ro_number || ""}`,
|
PrivateNote: `RO ${bill.job.ro_number || ""}`,
|
||||||
Line: lines
|
Line: lines
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (bill.is_credit_memo) {
|
||||||
|
VendorCredit = billObject;
|
||||||
|
} else {
|
||||||
|
billQbo = billObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
const logKey = bill.is_credit_memo ? "VendorCredit" : "billQbo";
|
||||||
|
const logValue = bill.is_credit_memo ? VendorCredit : billQbo;
|
||||||
|
|
||||||
logger.log("qbo-payable-objectlog", "DEBUG", req.user.email, bill.id, {
|
logger.log("qbo-payable-objectlog", "DEBUG", req.user.email, bill.id, {
|
||||||
billQbo
|
[logKey]: logValue
|
||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
const result = await oauthClient.makeApiCall({
|
const result = await oauthClient.makeApiCall({
|
||||||
@@ -322,7 +324,7 @@ async function InsertBill(oauthClient, qbo_realmId, req, bill, vendor, bodyshop)
|
|||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json"
|
"Content-Type": "application/json"
|
||||||
},
|
},
|
||||||
body: JSON.stringify(billQbo)
|
body: JSON.stringify(bill.is_credit_memo ? VendorCredit : billQbo)
|
||||||
});
|
});
|
||||||
logger.LogIntegrationCall({
|
logger.LogIntegrationCall({
|
||||||
platform: "QBO",
|
platform: "QBO",
|
||||||
@@ -333,7 +335,7 @@ async function InsertBill(oauthClient, qbo_realmId, req, bill, vendor, bodyshop)
|
|||||||
bodyshopid: bill.job.shopid,
|
bodyshopid: bill.job.shopid,
|
||||||
email: req.user.email
|
email: req.user.email
|
||||||
});
|
});
|
||||||
setNewRefreshToken(req.user.email, result);
|
|
||||||
if (result.status >= 400) {
|
if (result.status >= 400) {
|
||||||
throw new Error(JSON.stringify(result.json.Fault));
|
throw new Error(JSON.stringify(result.json.Fault));
|
||||||
}
|
}
|
||||||
@@ -418,7 +420,7 @@ async function QueryMetaData(oauthClient, qbo_realmId, req, bodyshopid) {
|
|||||||
bodyshopid,
|
bodyshopid,
|
||||||
email: req.user.email
|
email: req.user.email
|
||||||
});
|
});
|
||||||
setNewRefreshToken(req.user.email, accounts);
|
|
||||||
const taxCodes = await oauthClient.makeApiCall({
|
const taxCodes = await oauthClient.makeApiCall({
|
||||||
url: urlBuilder(qbo_realmId, "query", `select * From TaxCode`),
|
url: urlBuilder(qbo_realmId, "query", `select * From TaxCode`),
|
||||||
method: "POST",
|
method: "POST",
|
||||||
@@ -449,31 +451,14 @@ async function QueryMetaData(oauthClient, qbo_realmId, req, bodyshopid) {
|
|||||||
bodyshopid,
|
bodyshopid,
|
||||||
email: req.user.email
|
email: req.user.email
|
||||||
});
|
});
|
||||||
const taxCodeMapping = {};
|
|
||||||
|
|
||||||
taxCodes.json &&
|
const taxCodeMapping = Object.fromEntries((taxCodes.json?.QueryResponse?.TaxCode || []).map((t) => [t.Name, t.Id]));
|
||||||
taxCodes.json.QueryResponse &&
|
|
||||||
taxCodes.json.QueryResponse.TaxCode &&
|
|
||||||
taxCodes.json.QueryResponse.TaxCode.forEach((t) => {
|
|
||||||
taxCodeMapping[t.Name] = t.Id;
|
|
||||||
});
|
|
||||||
|
|
||||||
const accountMapping = {};
|
const accountMapping = Object.fromEntries(
|
||||||
|
(accounts.json?.QueryResponse?.Account || []).map((t) => [t.FullyQualifiedName, t.Id])
|
||||||
|
);
|
||||||
|
|
||||||
accounts.json &&
|
const classMapping = Object.fromEntries((classes.json?.QueryResponse?.Class || []).map((c) => [c.Name, c.Id]));
|
||||||
accounts.json.QueryResponse &&
|
|
||||||
accounts.json.QueryResponse.Account &&
|
|
||||||
accounts.json.QueryResponse.Account.forEach((t) => {
|
|
||||||
accountMapping[t.FullyQualifiedName] = t.Id;
|
|
||||||
});
|
|
||||||
|
|
||||||
const classMapping = {};
|
|
||||||
classes.json &&
|
|
||||||
classes.json.QueryResponse &&
|
|
||||||
classes.json.QueryResponse.Class &&
|
|
||||||
classes.json.QueryResponse.Class.forEach((t) => {
|
|
||||||
classMapping[t.Name] = t.Id;
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
accounts: accountMapping,
|
accounts: accountMapping,
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ const Dinero = require("dinero.js");
|
|||||||
|
|
||||||
const apiGqlClient = require("../../graphql-client/graphql-client").client;
|
const apiGqlClient = require("../../graphql-client/graphql-client").client;
|
||||||
const queries = require("../../graphql-client/queries");
|
const queries = require("../../graphql-client/queries");
|
||||||
const { refresh: refreshOauthToken, setNewRefreshToken } = require("./qbo-callback");
|
const { refresh: refreshOauthToken } = require("./qbo-callback");
|
||||||
const OAuthClient = require("intuit-oauth");
|
const OAuthClient = require("intuit-oauth");
|
||||||
const moment = require("moment-timezone");
|
const moment = require("moment-timezone");
|
||||||
const {
|
const {
|
||||||
@@ -145,7 +145,7 @@ exports.default = async (req, res) => {
|
|||||||
ret.push({ paymentid: payment.id, success: true });
|
ret.push({ paymentid: payment.id, success: true });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.log("qbo-payment-create-error", "ERROR", req.user.email, null, {
|
logger.log("qbo-payment-create-error", "ERROR", req.user.email, null, {
|
||||||
error: (error && error.authResponse && error.authResponse.body) || (error && error.message)
|
error: error?.authResponse?.body || error?.message
|
||||||
});
|
});
|
||||||
//Add the export log error.
|
//Add the export log error.
|
||||||
if (elgen) {
|
if (elgen) {
|
||||||
@@ -155,9 +155,7 @@ exports.default = async (req, res) => {
|
|||||||
bodyshopid: bodyshop.id,
|
bodyshopid: bodyshop.id,
|
||||||
paymentid: payment.id,
|
paymentid: payment.id,
|
||||||
successful: false,
|
successful: false,
|
||||||
message: JSON.stringify([
|
message: JSON.stringify([error?.authResponse?.body || error?.message]),
|
||||||
(error && error.authResponse && error.authResponse.body) || (error && error.message)
|
|
||||||
]),
|
|
||||||
useremail: req.user.email
|
useremail: req.user.email
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -167,7 +165,7 @@ exports.default = async (req, res) => {
|
|||||||
ret.push({
|
ret.push({
|
||||||
paymentid: payment.id,
|
paymentid: payment.id,
|
||||||
success: false,
|
success: false,
|
||||||
errorMessage: (error && error.authResponse && error.authResponse.body) || (error && error.message)
|
errorMessage: error?.authResponse?.body || error?.message
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -201,9 +199,7 @@ async function InsertPayment(oauthClient, qbo_realmId, req, payment, parentRef)
|
|||||||
CustomerRef: {
|
CustomerRef: {
|
||||||
value: parentRef.Id
|
value: parentRef.Id
|
||||||
},
|
},
|
||||||
TxnDate: moment(payment.date) //.tz(bodyshop.timezone)
|
TxnDate: moment(payment.date).format("YYYY-MM-DD"),
|
||||||
.format("YYYY-MM-DD"),
|
|
||||||
//DueDate: bill.due_date && moment(bill.due_date).format("YYYY-MM-DD"),
|
|
||||||
DocNumber: payment.paymentnum,
|
DocNumber: payment.paymentnum,
|
||||||
TotalAmt: Dinero({
|
TotalAmt: Dinero({
|
||||||
amount: Math.round(payment.amount * 100)
|
amount: Math.round(payment.amount * 100)
|
||||||
@@ -211,19 +207,13 @@ async function InsertPayment(oauthClient, qbo_realmId, req, payment, parentRef)
|
|||||||
PaymentMethodRef: {
|
PaymentMethodRef: {
|
||||||
value: paymentMethods[payment.type]
|
value: paymentMethods[payment.type]
|
||||||
},
|
},
|
||||||
PrivateNote: payment.memo
|
PrivateNote: payment.memo?.substring(0, 4000)?.trim() ?? "",
|
||||||
? payment.memo.length > 4000
|
|
||||||
? payment.memo.substring(0, 4000).trim()
|
|
||||||
: payment.memo.trim()
|
|
||||||
: "",
|
|
||||||
PaymentRefNum: payment.transactionid,
|
PaymentRefNum: payment.transactionid,
|
||||||
...(invoices && invoices.length === 1 && invoices[0]
|
...(invoices?.length === 1 && invoices[0]
|
||||||
? {
|
? {
|
||||||
Line: [
|
Line: [
|
||||||
{
|
{
|
||||||
Amount: Dinero({
|
Amount: Dinero({ amount: Math.round(payment.amount * 100) }).toFormat(DineroQbFormat),
|
||||||
amount: Math.round(payment.amount * 100)
|
|
||||||
}).toFormat(DineroQbFormat),
|
|
||||||
LinkedTxn: [
|
LinkedTxn: [
|
||||||
{
|
{
|
||||||
TxnId: invoices[0].Id,
|
TxnId: invoices[0].Id,
|
||||||
@@ -256,11 +246,11 @@ async function InsertPayment(oauthClient, qbo_realmId, req, payment, parentRef)
|
|||||||
bodyshopid: payment.job.shopid,
|
bodyshopid: payment.job.shopid,
|
||||||
email: req.user.email
|
email: req.user.email
|
||||||
});
|
});
|
||||||
setNewRefreshToken(req.user.email, result);
|
|
||||||
if (result.status >= 400) {
|
if (result.status >= 400) {
|
||||||
throw new Error(JSON.stringify(result.json.Fault));
|
throw new Error(JSON.stringify(result.json.Fault));
|
||||||
}
|
}
|
||||||
if (result.status === 200) return result?.json;
|
if (result.status === 200) return result?.json.Customer;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.log("qbo-payables-error", "DEBUG", req.user.email, payment.id, {
|
logger.log("qbo-payables-error", "DEBUG", req.user.email, payment.id, {
|
||||||
method: "InsertPayment",
|
method: "InsertPayment",
|
||||||
@@ -273,11 +263,7 @@ async function InsertPayment(oauthClient, qbo_realmId, req, payment, parentRef)
|
|||||||
|
|
||||||
async function QueryMetaData(oauthClient, qbo_realmId, req, ro_number, isCreditMemo, parentTierRef, bodyshopid) {
|
async function QueryMetaData(oauthClient, qbo_realmId, req, ro_number, isCreditMemo, parentTierRef, bodyshopid) {
|
||||||
const invoice = await oauthClient.makeApiCall({
|
const invoice = await oauthClient.makeApiCall({
|
||||||
url: urlBuilder(
|
url: urlBuilder(qbo_realmId, "query", `select * From Invoice where DocNumber like '${ro_number}%'`),
|
||||||
qbo_realmId,
|
|
||||||
"query",
|
|
||||||
`select * From Invoice where DocNumber like '${ro_number}%'`
|
|
||||||
),
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json"
|
"Content-Type": "application/json"
|
||||||
@@ -292,11 +278,7 @@ async function QueryMetaData(oauthClient, qbo_realmId, req, ro_number, isCreditM
|
|||||||
email: req.user.email
|
email: req.user.email
|
||||||
});
|
});
|
||||||
const paymentMethods = await oauthClient.makeApiCall({
|
const paymentMethods = await oauthClient.makeApiCall({
|
||||||
url: urlBuilder(
|
url: urlBuilder(qbo_realmId, "query", `select * From PaymentMethod`),
|
||||||
qbo_realmId,
|
|
||||||
"query",
|
|
||||||
`select * From PaymentMethod`
|
|
||||||
),
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json"
|
"Content-Type": "application/json"
|
||||||
@@ -310,7 +292,6 @@ async function QueryMetaData(oauthClient, qbo_realmId, req, ro_number, isCreditM
|
|||||||
bodyshopid,
|
bodyshopid,
|
||||||
email: req.user.email
|
email: req.user.email
|
||||||
});
|
});
|
||||||
setNewRefreshToken(req.user.email, paymentMethods);
|
|
||||||
|
|
||||||
// const classes = await oauthClient.makeApiCall({
|
// const classes = await oauthClient.makeApiCall({
|
||||||
// url: urlBuilder(qbo_realmId, "query", `select * From Class`),
|
// url: urlBuilder(qbo_realmId, "query", `select * From Class`),
|
||||||
@@ -320,14 +301,9 @@ async function QueryMetaData(oauthClient, qbo_realmId, req, ro_number, isCreditM
|
|||||||
// },
|
// },
|
||||||
// });
|
// });
|
||||||
|
|
||||||
const paymentMethodMapping = {};
|
const paymentMethodMapping = Object.fromEntries(
|
||||||
|
(paymentMethods.json?.QueryResponse?.PaymentMethod || []).map((t) => [t.Name, t.Id])
|
||||||
paymentMethods.json &&
|
);
|
||||||
paymentMethods.json.QueryResponse &&
|
|
||||||
paymentMethods.json.QueryResponse.PaymentMethod &&
|
|
||||||
paymentMethods.json.QueryResponse.PaymentMethod.forEach((t) => {
|
|
||||||
paymentMethodMapping[t.Name] = t.Id;
|
|
||||||
});
|
|
||||||
|
|
||||||
// const accountMapping = {};
|
// const accountMapping = {};
|
||||||
|
|
||||||
@@ -347,11 +323,7 @@ async function QueryMetaData(oauthClient, qbo_realmId, req, ro_number, isCreditM
|
|||||||
|
|
||||||
if (isCreditMemo) {
|
if (isCreditMemo) {
|
||||||
const taxCodes = await oauthClient.makeApiCall({
|
const taxCodes = await oauthClient.makeApiCall({
|
||||||
url: urlBuilder(
|
url: urlBuilder(qbo_realmId, "query", `select * From TaxCode`),
|
||||||
qbo_realmId,
|
|
||||||
"query",
|
|
||||||
`select * From TaxCode`
|
|
||||||
),
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json"
|
"Content-Type": "application/json"
|
||||||
@@ -366,11 +338,7 @@ async function QueryMetaData(oauthClient, qbo_realmId, req, ro_number, isCreditM
|
|||||||
email: req.user.email
|
email: req.user.email
|
||||||
});
|
});
|
||||||
const items = await oauthClient.makeApiCall({
|
const items = await oauthClient.makeApiCall({
|
||||||
url: urlBuilder(
|
url: urlBuilder(qbo_realmId, "query", `select * From Item`),
|
||||||
qbo_realmId,
|
|
||||||
"query",
|
|
||||||
`select * From Item`
|
|
||||||
),
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json"
|
"Content-Type": "application/json"
|
||||||
@@ -384,24 +352,11 @@ async function QueryMetaData(oauthClient, qbo_realmId, req, ro_number, isCreditM
|
|||||||
bodyshopid,
|
bodyshopid,
|
||||||
email: req.user.email
|
email: req.user.email
|
||||||
});
|
});
|
||||||
setNewRefreshToken(req.user.email, items);
|
|
||||||
|
|
||||||
const itemMapping = {};
|
const taxCodeMapping = Object.fromEntries((taxCodes.json?.QueryResponse?.TaxCode || []).map((t) => [t.Name, t.Id]));
|
||||||
|
|
||||||
items.json &&
|
const itemMapping = Object.fromEntries((items.json?.QueryResponse?.Item || []).map((item) => [item.Name, item.Id]));
|
||||||
items.json.QueryResponse &&
|
|
||||||
items.json.QueryResponse.Item &&
|
|
||||||
items.json.QueryResponse.Item.forEach((t) => {
|
|
||||||
itemMapping[t.Name] = t.Id;
|
|
||||||
});
|
|
||||||
const taxCodeMapping = {};
|
|
||||||
|
|
||||||
taxCodes.json &&
|
|
||||||
taxCodes.json.QueryResponse &&
|
|
||||||
taxCodes.json.QueryResponse.TaxCode &&
|
|
||||||
taxCodes.json.QueryResponse.TaxCode.forEach((t) => {
|
|
||||||
taxCodeMapping[t.Name] = t.Id;
|
|
||||||
});
|
|
||||||
ret = {
|
ret = {
|
||||||
...ret,
|
...ret,
|
||||||
items: itemMapping,
|
items: itemMapping,
|
||||||
@@ -413,12 +368,10 @@ async function QueryMetaData(oauthClient, qbo_realmId, req, ro_number, isCreditM
|
|||||||
...ret,
|
...ret,
|
||||||
paymentMethods: paymentMethodMapping,
|
paymentMethods: paymentMethodMapping,
|
||||||
invoices:
|
invoices:
|
||||||
invoice.json &&
|
invoice.json?.QueryResponse?.Invoice &&
|
||||||
invoice.json.QueryResponse &&
|
|
||||||
invoice.json.QueryResponse.Invoice &&
|
|
||||||
(parentTierRef
|
(parentTierRef
|
||||||
? [invoice.json.QueryResponse.Invoice.find((x) => x.CustomerRef.value === parentTierRef.Id)]
|
? [invoice.json?.QueryResponse?.Invoice.find((x) => x.CustomerRef?.value === parentTierRef?.Id)]
|
||||||
: [invoice.json.QueryResponse.Invoice[0]])
|
: [invoice.json?.QueryResponse?.Invoice?.[0]])
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -433,7 +386,7 @@ async function InsertCreditMemo(oauthClient, qbo_realmId, req, payment, parentRe
|
|||||||
payment.job.shopid
|
payment.job.shopid
|
||||||
);
|
);
|
||||||
|
|
||||||
if (invoices && invoices.length !== 1) {
|
if (invoices?.length !== 1) {
|
||||||
throw new Error(`More than 1 invoice with DocNumber ${payment.ro_number} found.`);
|
throw new Error(`More than 1 invoice with DocNumber ${payment.ro_number} found.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -441,11 +394,9 @@ async function InsertCreditMemo(oauthClient, qbo_realmId, req, payment, parentRe
|
|||||||
CustomerRef: {
|
CustomerRef: {
|
||||||
value: parentRef.Id
|
value: parentRef.Id
|
||||||
},
|
},
|
||||||
TxnDate: moment(payment.date)
|
TxnDate: moment(payment.date).format("YYYY-MM-DD"),
|
||||||
//.tz(bodyshop.timezone)
|
|
||||||
.format("YYYY-MM-DD"),
|
|
||||||
DocNumber: payment.paymentnum,
|
DocNumber: payment.paymentnum,
|
||||||
...(invoices && invoices[0] ? { InvoiceRef: { value: invoices[0].Id } } : {}),
|
...(invoices?.[0] ? { InvoiceRef: { value: invoices[0].Id } } : {}),
|
||||||
PaymentRefNum: payment.transactionid,
|
PaymentRefNum: payment.transactionid,
|
||||||
Line: [
|
Line: [
|
||||||
{
|
{
|
||||||
@@ -494,7 +445,7 @@ async function InsertCreditMemo(oauthClient, qbo_realmId, req, payment, parentRe
|
|||||||
bodyshopid: req.user.bodyshopid,
|
bodyshopid: req.user.bodyshopid,
|
||||||
email: req.user.email
|
email: req.user.email
|
||||||
});
|
});
|
||||||
setNewRefreshToken(req.user.email, result);
|
|
||||||
if (result.status >= 400) {
|
if (result.status >= 400) {
|
||||||
throw new Error(JSON.stringify(result.json.Fault));
|
throw new Error(JSON.stringify(result.json.Fault));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ const StandardizeName = require("./qbo").StandardizeName;
|
|||||||
const logger = require("../../utils/logger");
|
const logger = require("../../utils/logger");
|
||||||
const apiGqlClient = require("../../graphql-client/graphql-client").client;
|
const apiGqlClient = require("../../graphql-client/graphql-client").client;
|
||||||
const queries = require("../../graphql-client/queries");
|
const queries = require("../../graphql-client/queries");
|
||||||
const { refresh: refreshOauthToken, setNewRefreshToken } = require("./qbo-callback");
|
const { refresh: refreshOauthToken } = require("./qbo-callback");
|
||||||
const OAuthClient = require("intuit-oauth");
|
const OAuthClient = require("intuit-oauth");
|
||||||
const CreateInvoiceLines = require("../qb-receivables-lines").default;
|
const CreateInvoiceLines = require("../qb-receivables-lines").default;
|
||||||
const moment = require("moment-timezone");
|
const moment = require("moment-timezone");
|
||||||
@@ -103,7 +103,7 @@ exports.default = async (req, res) => {
|
|||||||
if (!req.body.custDataOnly) {
|
if (!req.body.custDataOnly) {
|
||||||
await InsertInvoice(oauthClient, qbo_realmId, req, job, bodyshop, jobTier);
|
await InsertInvoice(oauthClient, qbo_realmId, req, job, bodyshop, jobTier);
|
||||||
|
|
||||||
if (job.qb_multiple_payers && job.qb_multiple_payers.length > 0) {
|
if (job.qb_multiple_payers?.length > 0) {
|
||||||
for (const [index, payer] of job.qb_multiple_payers.entries()) {
|
for (const [index, payer] of job.qb_multiple_payers.entries()) {
|
||||||
//do the thing.
|
//do the thing.
|
||||||
|
|
||||||
@@ -150,23 +150,21 @@ exports.default = async (req, res) => {
|
|||||||
|
|
||||||
// //No error. Mark the job exported & insert export log.
|
// //No error. Mark the job exported & insert export log.
|
||||||
if (elgen) {
|
if (elgen) {
|
||||||
await client
|
await client.setHeaders({ Authorization: BearerToken }).request(queries.QBO_MARK_JOB_EXPORTED, {
|
||||||
.setHeaders({ Authorization: BearerToken })
|
jobId: job.id,
|
||||||
.request(queries.QBO_MARK_JOB_EXPORTED, {
|
job: {
|
||||||
jobId: job.id,
|
status: bodyshop.md_ro_statuses.default_exported || "Exported*",
|
||||||
job: {
|
date_exported: moment().tz(bodyshop.timezone)
|
||||||
status: bodyshop.md_ro_statuses.default_exported || "Exported*",
|
},
|
||||||
date_exported: moment().tz(bodyshop.timezone)
|
logs: [
|
||||||
},
|
{
|
||||||
logs: [
|
bodyshopid: bodyshop.id,
|
||||||
{
|
jobid: job.id,
|
||||||
bodyshopid: bodyshop.id,
|
successful: true,
|
||||||
jobid: job.id,
|
useremail: req.user.email
|
||||||
successful: true,
|
}
|
||||||
useremail: req.user.email
|
]
|
||||||
}
|
});
|
||||||
]
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ret.push({ jobid: job.id, success: true });
|
ret.push({ jobid: job.id, success: true });
|
||||||
@@ -193,9 +191,7 @@ exports.default = async (req, res) => {
|
|||||||
bodyshopid: bodyshop.id,
|
bodyshopid: bodyshop.id,
|
||||||
jobid: job.id,
|
jobid: job.id,
|
||||||
successful: false,
|
successful: false,
|
||||||
message: JSON.stringify([
|
message: JSON.stringify([error?.authResponse?.body || error?.message]),
|
||||||
(error && error.authResponse && error.authResponse.body) || (error && error.message)
|
|
||||||
]),
|
|
||||||
useremail: req.user.email
|
useremail: req.user.email
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -232,18 +228,13 @@ async function QueryInsuranceCo(oauthClient, qbo_realmId, req, job) {
|
|||||||
platform: "QBO",
|
platform: "QBO",
|
||||||
method: "POST",
|
method: "POST",
|
||||||
name: "QueryCustomer",
|
name: "QueryCustomer",
|
||||||
status: result.response?.status,
|
status: result.status,
|
||||||
bodyshopid: job.shopid,
|
bodyshopid: job.shopid,
|
||||||
jobid: job.id,
|
jobid: job.id,
|
||||||
email: req.user.email
|
email: req.user.email
|
||||||
});
|
});
|
||||||
setNewRefreshToken(req.user.email, result);
|
|
||||||
return (
|
return result.json?.QueryResponse?.Customer?.[0];
|
||||||
result.json &&
|
|
||||||
result.json.QueryResponse &&
|
|
||||||
result.json.QueryResponse.Customer &&
|
|
||||||
result.json.QueryResponse.Customer[0]
|
|
||||||
);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.log("qbo-receivables-error", "DEBUG", req.user.email, job.id, {
|
logger.log("qbo-receivables-error", "DEBUG", req.user.email, job.id, {
|
||||||
error,
|
error,
|
||||||
@@ -287,13 +278,13 @@ async function InsertInsuranceCo(oauthClient, qbo_realmId, req, job, bodyshop) {
|
|||||||
platform: "QBO",
|
platform: "QBO",
|
||||||
method: "POST",
|
method: "POST",
|
||||||
name: "InsertCustomer",
|
name: "InsertCustomer",
|
||||||
status: result.response.status,
|
status: result.status,
|
||||||
bodyshopid: job.shopid,
|
bodyshopid: job.shopid,
|
||||||
jobid: job.id,
|
jobid: job.id,
|
||||||
email: req.user.email
|
email: req.user.email
|
||||||
});
|
});
|
||||||
setNewRefreshToken(req.user.email, result);
|
|
||||||
return result && result.json.Customer;
|
return result.json?.Customer;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.log("qbo-receivables-error", "DEBUG", req.user.email, job.id, {
|
logger.log("qbo-receivables-error", "DEBUG", req.user.email, job.id, {
|
||||||
error,
|
error,
|
||||||
@@ -322,18 +313,13 @@ async function QueryOwner(oauthClient, qbo_realmId, req, job, parentTierRef) {
|
|||||||
platform: "QBO",
|
platform: "QBO",
|
||||||
method: "POST",
|
method: "POST",
|
||||||
name: "QueryCustomer",
|
name: "QueryCustomer",
|
||||||
status: result.response?.status,
|
status: result.status,
|
||||||
bodyshopid: job.shopid,
|
bodyshopid: job.shopid,
|
||||||
jobid: job.id,
|
jobid: job.id,
|
||||||
email: req.user.email
|
email: req.user.email
|
||||||
});
|
});
|
||||||
setNewRefreshToken(req.user.email, result);
|
|
||||||
return (
|
return result.json?.QueryResponse?.Customer?.find((x) => x.ParentRef?.value === parentTierRef?.Id);
|
||||||
result.json &&
|
|
||||||
result.json.QueryResponse &&
|
|
||||||
result.json.QueryResponse.Customer &&
|
|
||||||
result.json.QueryResponse.Customer.find((x) => x.ParentRef?.value === parentTierRef?.Id)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.QueryOwner = QueryOwner;
|
exports.QueryOwner = QueryOwner;
|
||||||
@@ -373,13 +359,13 @@ async function InsertOwner(oauthClient, qbo_realmId, req, job, isThreeTier, pare
|
|||||||
platform: "QBO",
|
platform: "QBO",
|
||||||
method: "POST",
|
method: "POST",
|
||||||
name: "InsertCustomer",
|
name: "InsertCustomer",
|
||||||
status: result.response?.status,
|
status: result.status,
|
||||||
bodyshopid: job.shopid,
|
bodyshopid: job.shopid,
|
||||||
jobid: job.id,
|
jobid: job.id,
|
||||||
email: req.user.email
|
email: req.user.email
|
||||||
});
|
});
|
||||||
setNewRefreshToken(req.user.email, result);
|
|
||||||
return result && result.json.Customer;
|
return result.json?.Customer;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.log("qbo-receivables-error", "DEBUG", req.user.email, job.id, {
|
logger.log("qbo-receivables-error", "DEBUG", req.user.email, job.id, {
|
||||||
error,
|
error,
|
||||||
@@ -407,20 +393,14 @@ async function QueryJob(oauthClient, qbo_realmId, req, job, parentTierRef) {
|
|||||||
platform: "QBO",
|
platform: "QBO",
|
||||||
method: "POST",
|
method: "POST",
|
||||||
name: "QueryCustomer",
|
name: "QueryCustomer",
|
||||||
status: result.response?.status,
|
status: result.status,
|
||||||
bodyshopid: job.shopid,
|
bodyshopid: job.shopid,
|
||||||
jobid: job.id,
|
jobid: job.id,
|
||||||
email: req.user.email
|
email: req.user.email
|
||||||
});
|
});
|
||||||
setNewRefreshToken(req.user.email, result);
|
|
||||||
return (
|
const customers = result.json?.QueryResponse?.Customer;
|
||||||
result.json &&
|
return customers && (parentTierRef ? customers.find((x) => x.ParentRef.value === parentTierRef.Id) : customers[0]);
|
||||||
result.json.QueryResponse &&
|
|
||||||
result.json.QueryResponse.Customer &&
|
|
||||||
(parentTierRef
|
|
||||||
? result.json.QueryResponse.Customer.find((x) => x.ParentRef.value === parentTierRef.Id)
|
|
||||||
: result.json.QueryResponse.Customer[0])
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.QueryJob = QueryJob;
|
exports.QueryJob = QueryJob;
|
||||||
@@ -460,11 +440,11 @@ async function InsertJob(oauthClient, qbo_realmId, req, job, parentTierRef) {
|
|||||||
jobid: job.id,
|
jobid: job.id,
|
||||||
email: req.user.email
|
email: req.user.email
|
||||||
});
|
});
|
||||||
setNewRefreshToken(req.user.email, result);
|
|
||||||
if (result.status >= 400) {
|
if (result.status >= 400) {
|
||||||
throw new Error(JSON.stringify(result.json.Fault));
|
throw new Error(JSON.stringify(result.json.Fault));
|
||||||
}
|
}
|
||||||
if (result.status === 200) return result?.json;
|
if (result.status === 200) return result?.json.Customer;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.log("qbo-receivables-error", "DEBUG", req.user.email, job.id, {
|
logger.log("qbo-receivables-error", "DEBUG", req.user.email, job.id, {
|
||||||
method: "InsertOwner",
|
method: "InsertOwner",
|
||||||
@@ -479,13 +459,7 @@ exports.InsertJob = InsertJob;
|
|||||||
|
|
||||||
async function QueryMetaData(oauthClient, qbo_realmId, req, bodyshopid, jobid) {
|
async function QueryMetaData(oauthClient, qbo_realmId, req, bodyshopid, jobid) {
|
||||||
const items = await oauthClient.makeApiCall({
|
const items = await oauthClient.makeApiCall({
|
||||||
url: urlBuilder(
|
url: urlBuilder(qbo_realmId, "query", `select * From Item where active = true maxresults 1000`),
|
||||||
qbo_realmId,
|
|
||||||
"query",
|
|
||||||
`select *
|
|
||||||
From Item
|
|
||||||
where active = true maxresults 1000`
|
|
||||||
),
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json"
|
"Content-Type": "application/json"
|
||||||
@@ -500,15 +474,9 @@ async function QueryMetaData(oauthClient, qbo_realmId, req, bodyshopid, jobid) {
|
|||||||
jobid: jobid,
|
jobid: jobid,
|
||||||
email: req.user.email
|
email: req.user.email
|
||||||
});
|
});
|
||||||
setNewRefreshToken(req.user.email, items);
|
|
||||||
const taxCodes = await oauthClient.makeApiCall({
|
const taxCodes = await oauthClient.makeApiCall({
|
||||||
url: urlBuilder(
|
url: urlBuilder(qbo_realmId, "query", `select * From TaxCode where active = true`),
|
||||||
qbo_realmId,
|
|
||||||
"query",
|
|
||||||
`select *
|
|
||||||
From TaxCode
|
|
||||||
where active = true`
|
|
||||||
),
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json"
|
"Content-Type": "application/json"
|
||||||
@@ -524,12 +492,7 @@ async function QueryMetaData(oauthClient, qbo_realmId, req, bodyshopid, jobid) {
|
|||||||
email: req.user.email
|
email: req.user.email
|
||||||
});
|
});
|
||||||
const classes = await oauthClient.makeApiCall({
|
const classes = await oauthClient.makeApiCall({
|
||||||
url: urlBuilder(
|
url: urlBuilder(qbo_realmId, "query", `select * From Class`),
|
||||||
qbo_realmId,
|
|
||||||
"query",
|
|
||||||
`select *
|
|
||||||
From Class`
|
|
||||||
),
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json"
|
"Content-Type": "application/json"
|
||||||
@@ -544,31 +507,12 @@ async function QueryMetaData(oauthClient, qbo_realmId, req, bodyshopid, jobid) {
|
|||||||
jobid: jobid,
|
jobid: jobid,
|
||||||
email: req.user.email
|
email: req.user.email
|
||||||
});
|
});
|
||||||
const taxCodeMapping = {};
|
|
||||||
|
|
||||||
taxCodes.json &&
|
const taxCodeMapping = Object.fromEntries((taxCodes.json?.QueryResponse?.TaxCode || []).map((t) => [t.Name, t.Id]));
|
||||||
taxCodes.json.QueryResponse &&
|
|
||||||
taxCodes.json.QueryResponse.TaxCode &&
|
|
||||||
taxCodes.json.QueryResponse.TaxCode.forEach((t) => {
|
|
||||||
taxCodeMapping[t.Name] = t.Id;
|
|
||||||
});
|
|
||||||
|
|
||||||
const itemMapping = {};
|
const itemMapping = Object.fromEntries((items.json?.QueryResponse?.Item || []).map((item) => [item.Name, item.Id]));
|
||||||
|
|
||||||
items.json &&
|
const classMapping = Object.fromEntries((classes.json?.QueryResponse?.Class || []).map((c) => [c.Name, c.Id]));
|
||||||
items.json.QueryResponse &&
|
|
||||||
items.json.QueryResponse.Item &&
|
|
||||||
items.json.QueryResponse.Item.forEach((t) => {
|
|
||||||
itemMapping[t.Name] = t.Id;
|
|
||||||
});
|
|
||||||
|
|
||||||
const classMapping = {};
|
|
||||||
classes.json &&
|
|
||||||
classes.json.QueryResponse &&
|
|
||||||
classes.json.QueryResponse.Class &&
|
|
||||||
classes.json.QueryResponse.Class.forEach((t) => {
|
|
||||||
classMapping[t.Name] = t.Id;
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
items: itemMapping,
|
items: itemMapping,
|
||||||
@@ -601,12 +545,11 @@ async function InsertInvoice(oauthClient, qbo_realmId, req, job, bodyshop, paren
|
|||||||
} ${job.v_vin || ""} ${job.plate_no || ""} `.trim()
|
} ${job.v_vin || ""} ${job.plate_no || ""} `.trim()
|
||||||
},
|
},
|
||||||
CustomerRef: {
|
CustomerRef: {
|
||||||
value: parentTierRef.Id
|
value: parentTierRef?.Id
|
||||||
},
|
},
|
||||||
...(bodyshop.accountingconfig.qbo_departmentid &&
|
...(bodyshop.accountingconfig.qbo_departmentid?.trim() !== "" && {
|
||||||
bodyshop.accountingconfig.qbo_departmentid.trim() !== "" && {
|
DepartmentRef: { value: bodyshop.accountingconfig.qbo_departmentid }
|
||||||
DepartmentRef: { value: bodyshop.accountingconfig.qbo_departmentid }
|
}),
|
||||||
}),
|
|
||||||
CustomField: [
|
CustomField: [
|
||||||
...(bodyshop.accountingconfig.ReceivableCustomField1
|
...(bodyshop.accountingconfig.ReceivableCustomField1
|
||||||
? [
|
? [
|
||||||
@@ -636,9 +579,8 @@ async function InsertInvoice(oauthClient, qbo_realmId, req, job, bodyshop, paren
|
|||||||
]
|
]
|
||||||
: [])
|
: [])
|
||||||
],
|
],
|
||||||
...(bodyshop.accountingconfig &&
|
...(bodyshop.accountingconfig?.qbo &&
|
||||||
bodyshop.accountingconfig.qbo &&
|
bodyshop.accountingconfig?.qbo_usa && {
|
||||||
bodyshop.accountingconfig.qbo_usa && {
|
|
||||||
TxnTaxDetail: {
|
TxnTaxDetail: {
|
||||||
TxnTaxCodeRef: {
|
TxnTaxCodeRef: {
|
||||||
value: taxCodes[bodyshop.md_responsibility_centers.taxes.state.accountitem]
|
value: taxCodes[bodyshop.md_responsibility_centers.taxes.state.accountitem]
|
||||||
@@ -679,7 +621,7 @@ async function InsertInvoice(oauthClient, qbo_realmId, req, job, bodyshop, paren
|
|||||||
jobid: job.id,
|
jobid: job.id,
|
||||||
email: req.user.email
|
email: req.user.email
|
||||||
});
|
});
|
||||||
setNewRefreshToken(req.user.email, result);
|
|
||||||
if (result.status >= 400) {
|
if (result.status >= 400) {
|
||||||
throw new Error(JSON.stringify(result.json.Fault));
|
throw new Error(JSON.stringify(result.json.Fault));
|
||||||
}
|
}
|
||||||
@@ -732,10 +674,9 @@ async function InsertInvoiceMultiPayerInvoice(
|
|||||||
CustomerRef: {
|
CustomerRef: {
|
||||||
value: parentTierRef.Id
|
value: parentTierRef.Id
|
||||||
},
|
},
|
||||||
...(bodyshop.accountingconfig.qbo_departmentid &&
|
...(bodyshop.accountingconfig.qbo_departmentid?.trim() !== "" && {
|
||||||
bodyshop.accountingconfig.qbo_departmentid.trim() !== "" && {
|
DepartmentRef: { value: bodyshop.accountingconfig.qbo_departmentid }
|
||||||
DepartmentRef: { value: bodyshop.accountingconfig.qbo_departmentid }
|
}),
|
||||||
}),
|
|
||||||
CustomField: [
|
CustomField: [
|
||||||
...(bodyshop.accountingconfig.ReceivableCustomField1
|
...(bodyshop.accountingconfig.ReceivableCustomField1
|
||||||
? [
|
? [
|
||||||
@@ -765,9 +706,8 @@ async function InsertInvoiceMultiPayerInvoice(
|
|||||||
]
|
]
|
||||||
: [])
|
: [])
|
||||||
],
|
],
|
||||||
...(bodyshop.accountingconfig &&
|
...(bodyshop.accountingconfig?.qbo &&
|
||||||
bodyshop.accountingconfig.qbo &&
|
bodyshop.accountingconfig?.qbo_usa &&
|
||||||
bodyshop.accountingconfig.qbo_usa &&
|
|
||||||
bodyshop.region_config.includes("CA_") && {
|
bodyshop.region_config.includes("CA_") && {
|
||||||
TxnTaxDetail: {
|
TxnTaxDetail: {
|
||||||
TxnTaxCodeRef: {
|
TxnTaxCodeRef: {
|
||||||
@@ -809,7 +749,7 @@ async function InsertInvoiceMultiPayerInvoice(
|
|||||||
jobid: job.id,
|
jobid: job.id,
|
||||||
email: req.user.email
|
email: req.user.email
|
||||||
});
|
});
|
||||||
setNewRefreshToken(req.user.email, result);
|
|
||||||
if (result.status >= 400) {
|
if (result.status >= 400) {
|
||||||
throw new Error(JSON.stringify(result.json.Fault));
|
throw new Error(JSON.stringify(result.json.Fault));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user