Merge branch 'master-AIO' into feature/IO-3356-pbs-ro-posting
This commit is contained in:
@@ -1,7 +1,3 @@
|
||||
const path = require("path");
|
||||
require("dotenv").config({
|
||||
path: path.resolve(process.cwd(), `.env.${process.env.NODE_ENV || "development"}`)
|
||||
});
|
||||
const GraphQLClient = require("graphql-request").GraphQLClient;
|
||||
|
||||
const queries = require("../../graphql-client/queries");
|
||||
|
||||
@@ -1,8 +1,3 @@
|
||||
const path = require("path");
|
||||
require("dotenv").config({
|
||||
path: path.resolve(process.cwd(), `.env.${process.env.NODE_ENV || "development"}`)
|
||||
});
|
||||
|
||||
const IMEX_PBS_USER = process.env.IMEX_PBS_USER,
|
||||
IMEX_PBS_PASSWORD = process.env.IMEX_PBS_PASSWORD;
|
||||
const PBS_CREDENTIALS = {
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
const path = require("path");
|
||||
require("dotenv").config({
|
||||
path: path.resolve(process.cwd(), `.env.${process.env.NODE_ENV || "development"}`)
|
||||
});
|
||||
const GraphQLClient = require("graphql-request").GraphQLClient;
|
||||
const AxiosLib = require("axios").default;
|
||||
const queries = require("../../graphql-client/queries");
|
||||
@@ -116,6 +112,7 @@ exports.PbsSelectedCustomer = async function PbsSelectedCustomer(socket, selecte
|
||||
await InsertFailedExportLog(socket, error);
|
||||
}
|
||||
};
|
||||
|
||||
// Was Successful
|
||||
async function CheckForErrors(socket, response) {
|
||||
if (response.WasSuccessful === undefined || response.WasSuccessful === true) {
|
||||
@@ -142,7 +139,7 @@ async function QueryVehicleFromDms(socket) {
|
||||
try {
|
||||
if (!socket.JobData.v_vin) return null;
|
||||
|
||||
const { data: VehicleGetResponse, request } = await axios.post(
|
||||
const { data: VehicleGetResponse } = await axios.post(
|
||||
PBS_ENDPOINTS.VehicleGet,
|
||||
{
|
||||
SerialNumber: socket.JobData.bodyshop.pbs_serialnumber,
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
const path = require("path");
|
||||
require("dotenv").config({
|
||||
path: path.resolve(process.cwd(), `.env.${process.env.NODE_ENV || "development"}`)
|
||||
});
|
||||
const OAuthClient = require("intuit-oauth");
|
||||
const logger = require("../../utils/logger");
|
||||
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
const path = require("path");
|
||||
require("dotenv").config({
|
||||
path: path.resolve(process.cwd(), `.env.${process.env.NODE_ENV || "development"}`)
|
||||
});
|
||||
const logger = require("../../utils/logger");
|
||||
const OAuthClient = require("intuit-oauth");
|
||||
const client = require("../../graphql-client/graphql-client").client;
|
||||
@@ -13,7 +9,7 @@ const oauthClient = new OAuthClient({
|
||||
clientId: process.env.QBO_CLIENT_ID,
|
||||
clientSecret: process.env.QBO_SECRET,
|
||||
environment: process.env.NODE_ENV === "production" ? "production" : "sandbox",
|
||||
redirectUri: process.env.QBO_REDIRECT_URI,
|
||||
redirectUri: process.env.QBO_REDIRECT_URI
|
||||
});
|
||||
|
||||
const url = InstanceEndpoints();
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
const urlBuilder = require("./qbo").urlBuilder;
|
||||
const StandardizeName = require("./qbo").StandardizeName;
|
||||
const path = require("path");
|
||||
require("dotenv").config({
|
||||
path: path.resolve(process.cwd(), `.env.${process.env.NODE_ENV || "development"}`)
|
||||
});
|
||||
|
||||
const logger = require("../../utils/logger");
|
||||
const Dinero = require("dinero.js");
|
||||
const DineroQbFormat = require("../accounting-constants").DineroQbFormat;
|
||||
@@ -19,7 +16,7 @@ exports.default = async (req, res) => {
|
||||
clientId: process.env.QBO_CLIENT_ID,
|
||||
clientSecret: process.env.QBO_SECRET,
|
||||
environment: process.env.NODE_ENV === "production" ? "production" : "sandbox",
|
||||
redirectUri: process.env.QBO_REDIRECT_URI,
|
||||
redirectUri: process.env.QBO_REDIRECT_URI
|
||||
});
|
||||
|
||||
try {
|
||||
@@ -65,36 +62,34 @@ exports.default = async (req, res) => {
|
||||
vendorRecord = await InsertVendorRecord(oauthClient, qbo_realmId, req, bill);
|
||||
}
|
||||
|
||||
const insertResults = await InsertBill(oauthClient, qbo_realmId, req, bill, vendorRecord, bodyshop);
|
||||
await InsertBill(oauthClient, qbo_realmId, req, bill, vendorRecord, bodyshop);
|
||||
|
||||
// //No error. Mark the job exported & insert export log.
|
||||
if (elgen) {
|
||||
const result = await client
|
||||
.setHeaders({ Authorization: BearerToken })
|
||||
.request(queries.QBO_MARK_BILL_EXPORTED, {
|
||||
billId: bill.id,
|
||||
bill: {
|
||||
exported: true,
|
||||
exported_at: moment().tz(bodyshop.timezone)
|
||||
},
|
||||
logs: [
|
||||
{
|
||||
bodyshopid: bodyshop.id,
|
||||
billid: bill.id,
|
||||
successful: true,
|
||||
useremail: req.user.email
|
||||
}
|
||||
]
|
||||
});
|
||||
await client.setHeaders({ Authorization: BearerToken }).request(queries.QBO_MARK_BILL_EXPORTED, {
|
||||
billId: bill.id,
|
||||
bill: {
|
||||
exported: true,
|
||||
exported_at: moment().tz(bodyshop.timezone)
|
||||
},
|
||||
logs: [
|
||||
{
|
||||
bodyshopid: bodyshop.id,
|
||||
billid: bill.id,
|
||||
successful: true,
|
||||
useremail: req.user.email
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
ret.push({ billid: bill.id, success: true });
|
||||
} catch (error) {
|
||||
logger.log("qbo-paybles-create-error", "ERROR", req.user.email, null, {
|
||||
error:
|
||||
(error && error.authResponse && error.authResponse.body) ||
|
||||
(error?.authResponse && error.authResponse.body) ||
|
||||
error.response?.data?.Fault?.Error.map((e) => e.Detail).join(", ") ||
|
||||
(error && error.message)
|
||||
error?.message
|
||||
});
|
||||
ret.push({
|
||||
billid: bill.id,
|
||||
@@ -107,7 +102,7 @@ exports.default = async (req, res) => {
|
||||
|
||||
//Add the export log error.
|
||||
if (elgen) {
|
||||
const result = await client.setHeaders({ Authorization: BearerToken }).request(queries.INSERT_EXPORT_LOG, {
|
||||
await client.setHeaders({ Authorization: BearerToken }).request(queries.INSERT_EXPORT_LOG, {
|
||||
logs: [
|
||||
{
|
||||
bodyshopid: bodyshop.id,
|
||||
@@ -141,7 +136,9 @@ async function QueryVendorRecord(oauthClient, qbo_realmId, req, bill) {
|
||||
url: urlBuilder(
|
||||
qbo_realmId,
|
||||
"query",
|
||||
`select * From vendor where DisplayName = '${StandardizeName(bill.vendor.name)}'`
|
||||
`select *
|
||||
From vendor
|
||||
where DisplayName = '${StandardizeName(bill.vendor.name)}'`
|
||||
),
|
||||
method: "POST",
|
||||
headers: {
|
||||
@@ -156,7 +153,7 @@ async function QueryVendorRecord(oauthClient, qbo_realmId, req, bill) {
|
||||
status: result.response?.status,
|
||||
bodyshopid: bill.job.shopid,
|
||||
email: req.user.email
|
||||
})
|
||||
});
|
||||
setNewRefreshToken(req.user.email, result);
|
||||
return (
|
||||
result.json &&
|
||||
@@ -194,7 +191,7 @@ async function InsertVendorRecord(oauthClient, qbo_realmId, req, bill) {
|
||||
status: result.response?.status,
|
||||
bodyshopid: bill.job.shopid,
|
||||
email: req.user.email
|
||||
})
|
||||
});
|
||||
setNewRefreshToken(req.user.email, result);
|
||||
return result && result.json && result.json.Vendor;
|
||||
} catch (error) {
|
||||
@@ -263,11 +260,11 @@ async function InsertBill(oauthClient, qbo_realmId, req, bill, vendor, bodyshop)
|
||||
.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")
|
||||
}),
|
||||
DueDate: moment(bill.date)
|
||||
//.tz(bill.job.bodyshop.timezone)
|
||||
.add(bill.vendor.due_date, "days")
|
||||
.format("YYYY-MM-DD")
|
||||
}),
|
||||
DocNumber: bill.invoice_number,
|
||||
//...(bill.job.class ? { ClassRef: { Id: classes[bill.job.class] } } : {}),
|
||||
...(!(
|
||||
@@ -280,8 +277,8 @@ async function InsertBill(oauthClient, qbo_realmId, req, bill, vendor, bodyshop)
|
||||
: {}),
|
||||
...(bodyshop.accountingconfig.qbo_departmentid &&
|
||||
bodyshop.accountingconfig.qbo_departmentid.trim() !== "" && {
|
||||
DepartmentRef: { value: bodyshop.accountingconfig.qbo_departmentid }
|
||||
}),
|
||||
DepartmentRef: { value: bodyshop.accountingconfig.qbo_departmentid }
|
||||
}),
|
||||
PrivateNote: `RO ${bill.job.ro_number || ""}`,
|
||||
Line: lines
|
||||
};
|
||||
@@ -305,7 +302,7 @@ async function InsertBill(oauthClient, qbo_realmId, req, bill, vendor, bodyshop)
|
||||
status: result.response?.status,
|
||||
bodyshopid: bill.job.shopid,
|
||||
email: req.user.email
|
||||
})
|
||||
});
|
||||
setNewRefreshToken(req.user.email, result);
|
||||
return result && result.json && result.json.Bill;
|
||||
} catch (error) {
|
||||
@@ -353,8 +350,8 @@ const generateBillLine = (
|
||||
accountingconfig.qbo && accountingconfig.qbo_usa && region_config.includes("CA_")
|
||||
? {}
|
||||
: {
|
||||
value: taxCodes[findTaxCode(billLine.applicable_taxes, ioSalesTaxCodes)]
|
||||
},
|
||||
value: taxCodes[findTaxCode(billLine.applicable_taxes, ioSalesTaxCodes)]
|
||||
},
|
||||
AccountRef: {
|
||||
value: accounts[account.accountname]
|
||||
}
|
||||
@@ -373,7 +370,9 @@ async function QueryMetaData(oauthClient, qbo_realmId, req, bodyshopid) {
|
||||
url: urlBuilder(
|
||||
qbo_realmId,
|
||||
"query",
|
||||
`select * From Account where AccountType in ('Cost of Goods Sold', 'Other Current Liability')`
|
||||
`select *
|
||||
From Account
|
||||
where AccountType in ('Cost of Goods Sold', 'Other Current Liability')`
|
||||
),
|
||||
method: "POST",
|
||||
headers: {
|
||||
@@ -387,10 +386,15 @@ async function QueryMetaData(oauthClient, qbo_realmId, req, bodyshopid) {
|
||||
status: accounts.response?.status,
|
||||
bodyshopid,
|
||||
email: req.user.email
|
||||
})
|
||||
});
|
||||
setNewRefreshToken(req.user.email, accounts);
|
||||
const taxCodes = await oauthClient.makeApiCall({
|
||||
url: urlBuilder(qbo_realmId, "query", `select * From TaxCode`),
|
||||
url: urlBuilder(
|
||||
qbo_realmId,
|
||||
"query",
|
||||
`select *
|
||||
From TaxCode`
|
||||
),
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
@@ -403,9 +407,14 @@ async function QueryMetaData(oauthClient, qbo_realmId, req, bodyshopid) {
|
||||
status: taxCodes.status,
|
||||
bodyshopid,
|
||||
email: req.user.email
|
||||
})
|
||||
});
|
||||
const classes = await oauthClient.makeApiCall({
|
||||
url: urlBuilder(qbo_realmId, "query", `select * From Class`),
|
||||
url: urlBuilder(
|
||||
qbo_realmId,
|
||||
"query",
|
||||
`select *
|
||||
From Class`
|
||||
),
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
@@ -418,7 +427,7 @@ async function QueryMetaData(oauthClient, qbo_realmId, req, bodyshopid) {
|
||||
status: classes.status,
|
||||
bodyshopid,
|
||||
email: req.user.email
|
||||
})
|
||||
});
|
||||
const taxCodeMapping = {};
|
||||
|
||||
taxCodes.json &&
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
const path = require("path");
|
||||
require("dotenv").config({
|
||||
path: path.resolve(process.cwd(), `.env.${process.env.NODE_ENV || "development"}`)
|
||||
});
|
||||
const logger = require("../../utils/logger");
|
||||
const Dinero = require("dinero.js");
|
||||
|
||||
@@ -274,7 +270,13 @@ async function InsertPayment(oauthClient, qbo_realmId, req, payment, parentRef)
|
||||
|
||||
async function QueryMetaData(oauthClient, qbo_realmId, req, ro_number, isCreditMemo, parentTierRef, bodyshopid) {
|
||||
const invoice = await oauthClient.makeApiCall({
|
||||
url: urlBuilder(qbo_realmId, "query", `select * From Invoice where DocNumber like '${ro_number}%'`),
|
||||
url: urlBuilder(
|
||||
qbo_realmId,
|
||||
"query",
|
||||
`select *
|
||||
From Invoice
|
||||
where DocNumber like '${ro_number}%'`
|
||||
),
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
@@ -290,7 +292,12 @@ async function QueryMetaData(oauthClient, qbo_realmId, req, ro_number, isCreditM
|
||||
email: req.user.email
|
||||
});
|
||||
const paymentMethods = await oauthClient.makeApiCall({
|
||||
url: urlBuilder(qbo_realmId, "query", `select * From PaymentMethod`),
|
||||
url: urlBuilder(
|
||||
qbo_realmId,
|
||||
"query",
|
||||
`select *
|
||||
From PaymentMethod`
|
||||
),
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
@@ -341,7 +348,12 @@ async function QueryMetaData(oauthClient, qbo_realmId, req, ro_number, isCreditM
|
||||
|
||||
if (isCreditMemo) {
|
||||
const taxCodes = await oauthClient.makeApiCall({
|
||||
url: urlBuilder(qbo_realmId, "query", `select * From TaxCode`),
|
||||
url: urlBuilder(
|
||||
qbo_realmId,
|
||||
"query",
|
||||
`select *
|
||||
From TaxCode`
|
||||
),
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
@@ -357,7 +369,12 @@ async function QueryMetaData(oauthClient, qbo_realmId, req, ro_number, isCreditM
|
||||
email: req.user.email
|
||||
});
|
||||
const items = await oauthClient.makeApiCall({
|
||||
url: urlBuilder(qbo_realmId, "query", `select * From Item`),
|
||||
url: urlBuilder(
|
||||
qbo_realmId,
|
||||
"query",
|
||||
`select *
|
||||
From Item`
|
||||
),
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
const urlBuilder = require("./qbo").urlBuilder;
|
||||
const StandardizeName = require("./qbo").StandardizeName;
|
||||
|
||||
const path = require("path");
|
||||
require("dotenv").config({
|
||||
path: path.resolve(process.cwd(), `.env.${process.env.NODE_ENV || "development"}`)
|
||||
});
|
||||
const logger = require("../../utils/logger");
|
||||
const apiGqlClient = require("../../graphql-client/graphql-client").client;
|
||||
const queries = require("../../graphql-client/queries");
|
||||
@@ -12,7 +8,6 @@ const { refresh: refreshOauthToken, setNewRefreshToken } = require("./qbo-callba
|
||||
const OAuthClient = require("intuit-oauth");
|
||||
const CreateInvoiceLines = require("../qb-receivables-lines").default;
|
||||
const moment = require("moment-timezone");
|
||||
const GraphQLClient = require("graphql-request").GraphQLClient;
|
||||
const { generateOwnerTier } = require("../qbxml/qbxml-utils");
|
||||
const { createMultiQbPayerLines } = require("../qb-receivables-lines");
|
||||
|
||||
@@ -21,7 +16,7 @@ exports.default = async (req, res) => {
|
||||
clientId: process.env.QBO_CLIENT_ID,
|
||||
clientSecret: process.env.QBO_SECRET,
|
||||
environment: process.env.NODE_ENV === "production" ? "production" : "sandbox",
|
||||
redirectUri: process.env.QBO_REDIRECT_URI,
|
||||
redirectUri: process.env.QBO_REDIRECT_URI
|
||||
});
|
||||
|
||||
try {
|
||||
@@ -226,7 +221,10 @@ async function QueryInsuranceCo(oauthClient, qbo_realmId, req, job) {
|
||||
url: urlBuilder(
|
||||
qbo_realmId,
|
||||
"query",
|
||||
`select * From Customer where DisplayName = '${StandardizeName(job.ins_co_nm.trim())}' and Active = true`
|
||||
`select *
|
||||
From Customer
|
||||
where DisplayName = '${StandardizeName(job.ins_co_nm.trim())}'
|
||||
and Active = true`
|
||||
),
|
||||
method: "POST",
|
||||
headers: {
|
||||
@@ -241,7 +239,7 @@ async function QueryInsuranceCo(oauthClient, qbo_realmId, req, job) {
|
||||
bodyshopid: job.shopid,
|
||||
jobid: job.id,
|
||||
email: req.user.email
|
||||
})
|
||||
});
|
||||
setNewRefreshToken(req.user.email, result);
|
||||
return (
|
||||
result.json &&
|
||||
@@ -296,7 +294,7 @@ async function InsertInsuranceCo(oauthClient, qbo_realmId, req, job, bodyshop) {
|
||||
bodyshopid: job.shopid,
|
||||
jobid: job.id,
|
||||
email: req.user.email
|
||||
})
|
||||
});
|
||||
setNewRefreshToken(req.user.email, result);
|
||||
return result && result.json.Customer;
|
||||
} catch (error) {
|
||||
@@ -316,7 +314,10 @@ async function QueryOwner(oauthClient, qbo_realmId, req, job, isThreeTier, paren
|
||||
url: urlBuilder(
|
||||
qbo_realmId,
|
||||
"query",
|
||||
`select * From Customer where DisplayName = '${StandardizeName(ownerName)}' and Active = true`
|
||||
`select *
|
||||
From Customer
|
||||
where DisplayName = '${StandardizeName(ownerName)}'
|
||||
and Active = true`
|
||||
),
|
||||
method: "POST",
|
||||
headers: {
|
||||
@@ -331,7 +332,7 @@ async function QueryOwner(oauthClient, qbo_realmId, req, job, isThreeTier, paren
|
||||
bodyshopid: job.shopid,
|
||||
jobid: job.id,
|
||||
email: req.user.email
|
||||
})
|
||||
});
|
||||
setNewRefreshToken(req.user.email, result);
|
||||
return (
|
||||
result.json &&
|
||||
@@ -358,11 +359,11 @@ async function InsertOwner(oauthClient, qbo_realmId, req, job, isThreeTier, pare
|
||||
...(job.ownr_ea ? { PrimaryEmailAddr: { Address: job.ownr_ea.trim() } } : {}),
|
||||
...(isThreeTier
|
||||
? {
|
||||
Job: true,
|
||||
ParentRef: {
|
||||
value: parentTierRef.Id
|
||||
Job: true,
|
||||
ParentRef: {
|
||||
value: parentTierRef.Id
|
||||
}
|
||||
}
|
||||
}
|
||||
: {})
|
||||
};
|
||||
try {
|
||||
@@ -382,7 +383,7 @@ async function InsertOwner(oauthClient, qbo_realmId, req, job, isThreeTier, pare
|
||||
bodyshopid: job.shopid,
|
||||
jobid: job.id,
|
||||
email: req.user.email
|
||||
})
|
||||
});
|
||||
setNewRefreshToken(req.user.email, result);
|
||||
return result && result.json.Customer;
|
||||
} catch (error) {
|
||||
@@ -401,7 +402,10 @@ async function QueryJob(oauthClient, qbo_realmId, req, job, parentTierRef) {
|
||||
url: urlBuilder(
|
||||
qbo_realmId,
|
||||
"query",
|
||||
`select * From Customer where DisplayName = '${job.ro_number}' and Active = true`
|
||||
`select *
|
||||
From Customer
|
||||
where DisplayName = '${job.ro_number}'
|
||||
and Active = true`
|
||||
),
|
||||
method: "POST",
|
||||
headers: {
|
||||
@@ -416,7 +420,7 @@ async function QueryJob(oauthClient, qbo_realmId, req, job, parentTierRef) {
|
||||
bodyshopid: job.shopid,
|
||||
jobid: job.id,
|
||||
email: req.user.email
|
||||
})
|
||||
});
|
||||
setNewRefreshToken(req.user.email, result);
|
||||
return (
|
||||
result.json &&
|
||||
@@ -464,7 +468,7 @@ async function InsertJob(oauthClient, qbo_realmId, req, job, parentTierRef) {
|
||||
bodyshopid: job.shopid,
|
||||
jobid: job.id,
|
||||
email: req.user.email
|
||||
})
|
||||
});
|
||||
setNewRefreshToken(req.user.email, result);
|
||||
return result && result.json.Customer;
|
||||
} catch (error) {
|
||||
@@ -480,7 +484,13 @@ exports.InsertJob = InsertJob;
|
||||
|
||||
async function QueryMetaData(oauthClient, qbo_realmId, req, bodyshopid, jobid) {
|
||||
const items = await oauthClient.makeApiCall({
|
||||
url: urlBuilder(qbo_realmId, "query", `select * From Item where active=true maxresults 1000`),
|
||||
url: urlBuilder(
|
||||
qbo_realmId,
|
||||
"query",
|
||||
`select *
|
||||
From Item
|
||||
where active = true maxresults 1000`
|
||||
),
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
@@ -494,10 +504,16 @@ async function QueryMetaData(oauthClient, qbo_realmId, req, bodyshopid, jobid) {
|
||||
bodyshopid,
|
||||
jobid: jobid,
|
||||
email: req.user.email
|
||||
})
|
||||
});
|
||||
setNewRefreshToken(req.user.email, items);
|
||||
const taxCodes = await oauthClient.makeApiCall({
|
||||
url: urlBuilder(qbo_realmId, "query", `select * From TaxCode where active=true`),
|
||||
url: urlBuilder(
|
||||
qbo_realmId,
|
||||
"query",
|
||||
`select *
|
||||
From TaxCode
|
||||
where active = true`
|
||||
),
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
@@ -511,9 +527,14 @@ async function QueryMetaData(oauthClient, qbo_realmId, req, bodyshopid, jobid) {
|
||||
bodyshopid,
|
||||
jobid: jobid,
|
||||
email: req.user.email
|
||||
})
|
||||
});
|
||||
const classes = await oauthClient.makeApiCall({
|
||||
url: urlBuilder(qbo_realmId, "query", `select * From Class`),
|
||||
url: urlBuilder(
|
||||
qbo_realmId,
|
||||
"query",
|
||||
`select *
|
||||
From Class`
|
||||
),
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
@@ -527,7 +548,7 @@ async function QueryMetaData(oauthClient, qbo_realmId, req, bodyshopid, jobid) {
|
||||
bodyshopid,
|
||||
jobid: jobid,
|
||||
email: req.user.email
|
||||
})
|
||||
});
|
||||
const taxCodeMapping = {};
|
||||
|
||||
taxCodes.json &&
|
||||
@@ -578,55 +599,57 @@ async function InsertInvoice(oauthClient, qbo_realmId, req, job, bodyshop, paren
|
||||
DocNumber: job.ro_number,
|
||||
...(job.class ? { ClassRef: { value: classes[job.class] } } : {}),
|
||||
CustomerMemo: {
|
||||
value: `${job.clm_no ? `Claim No: ${job.clm_no}` : ``}${job.po_number ? `PO No: ${job.po_number}` : ``
|
||||
} Vehicle:${job.v_model_yr || ""} ${job.v_make_desc || ""} ${job.v_model_desc || ""
|
||||
} ${job.v_vin || ""} ${job.plate_no || ""} `.trim()
|
||||
value: `${job.clm_no ? `Claim No: ${job.clm_no}` : ``}${
|
||||
job.po_number ? `PO No: ${job.po_number}` : ``
|
||||
} Vehicle:${job.v_model_yr || ""} ${job.v_make_desc || ""} ${
|
||||
job.v_model_desc || ""
|
||||
} ${job.v_vin || ""} ${job.plate_no || ""} `.trim()
|
||||
},
|
||||
CustomerRef: {
|
||||
value: parentTierRef.Id
|
||||
},
|
||||
...(bodyshop.accountingconfig.qbo_departmentid &&
|
||||
bodyshop.accountingconfig.qbo_departmentid.trim() !== "" && {
|
||||
DepartmentRef: { value: bodyshop.accountingconfig.qbo_departmentid }
|
||||
}),
|
||||
DepartmentRef: { value: bodyshop.accountingconfig.qbo_departmentid }
|
||||
}),
|
||||
CustomField: [
|
||||
...(bodyshop.accountingconfig.ReceivableCustomField1
|
||||
? [
|
||||
{
|
||||
DefinitionId: "1",
|
||||
StringValue: job[bodyshop.accountingconfig.ReceivableCustomField1],
|
||||
Type: "StringType"
|
||||
}
|
||||
]
|
||||
{
|
||||
DefinitionId: "1",
|
||||
StringValue: job[bodyshop.accountingconfig.ReceivableCustomField1],
|
||||
Type: "StringType"
|
||||
}
|
||||
]
|
||||
: []),
|
||||
...(bodyshop.accountingconfig.ReceivableCustomField2
|
||||
? [
|
||||
{
|
||||
DefinitionId: "2",
|
||||
StringValue: job[bodyshop.accountingconfig.ReceivableCustomField2],
|
||||
Type: "StringType"
|
||||
}
|
||||
]
|
||||
{
|
||||
DefinitionId: "2",
|
||||
StringValue: job[bodyshop.accountingconfig.ReceivableCustomField2],
|
||||
Type: "StringType"
|
||||
}
|
||||
]
|
||||
: []),
|
||||
...(bodyshop.accountingconfig.ReceivableCustomField3
|
||||
? [
|
||||
{
|
||||
DefinitionId: "3",
|
||||
StringValue: job[bodyshop.accountingconfig.ReceivableCustomField3],
|
||||
Type: "StringType"
|
||||
}
|
||||
]
|
||||
{
|
||||
DefinitionId: "3",
|
||||
StringValue: job[bodyshop.accountingconfig.ReceivableCustomField3],
|
||||
Type: "StringType"
|
||||
}
|
||||
]
|
||||
: [])
|
||||
],
|
||||
...(bodyshop.accountingconfig &&
|
||||
bodyshop.accountingconfig.qbo &&
|
||||
bodyshop.accountingconfig.qbo_usa && {
|
||||
TxnTaxDetail: {
|
||||
TxnTaxCodeRef: {
|
||||
value: taxCodes[bodyshop.md_responsibility_centers.taxes.state.accountitem]
|
||||
TxnTaxDetail: {
|
||||
TxnTaxCodeRef: {
|
||||
value: taxCodes[bodyshop.md_responsibility_centers.taxes.state.accountitem]
|
||||
}
|
||||
}
|
||||
}
|
||||
}),
|
||||
}),
|
||||
|
||||
...(bodyshop.accountingconfig.printlater ? { PrintStatus: "NeedToPrint" } : {}),
|
||||
...(bodyshop.accountingconfig.emaillater && job.ownr_ea ? { EmailStatus: "NeedToSend" } : {}),
|
||||
@@ -660,7 +683,7 @@ async function InsertInvoice(oauthClient, qbo_realmId, req, job, bodyshop, paren
|
||||
bodyshopid: job.shopid,
|
||||
jobid: job.id,
|
||||
email: req.user.email
|
||||
})
|
||||
});
|
||||
setNewRefreshToken(req.user.email, result);
|
||||
return result && result.json && result.json.Invoice;
|
||||
} catch (error) {
|
||||
@@ -702,56 +725,58 @@ async function InsertInvoiceMultiPayerInvoice(
|
||||
DocNumber: job.ro_number + suffix,
|
||||
...(job.class ? { ClassRef: { value: classes[job.class] } } : {}),
|
||||
CustomerMemo: {
|
||||
value: `${job.clm_no ? `Claim No: ${job.clm_no}` : ``}${job.po_number ? `PO No: ${job.po_number}` : ``
|
||||
} Vehicle:${job.v_model_yr || ""} ${job.v_make_desc || ""} ${job.v_model_desc || ""
|
||||
} ${job.v_vin || ""} ${job.plate_no || ""} `.trim()
|
||||
value: `${job.clm_no ? `Claim No: ${job.clm_no}` : ``}${
|
||||
job.po_number ? `PO No: ${job.po_number}` : ``
|
||||
} Vehicle:${job.v_model_yr || ""} ${job.v_make_desc || ""} ${
|
||||
job.v_model_desc || ""
|
||||
} ${job.v_vin || ""} ${job.plate_no || ""} `.trim()
|
||||
},
|
||||
CustomerRef: {
|
||||
value: parentTierRef.Id
|
||||
},
|
||||
...(bodyshop.accountingconfig.qbo_departmentid &&
|
||||
bodyshop.accountingconfig.qbo_departmentid.trim() !== "" && {
|
||||
DepartmentRef: { value: bodyshop.accountingconfig.qbo_departmentid }
|
||||
}),
|
||||
DepartmentRef: { value: bodyshop.accountingconfig.qbo_departmentid }
|
||||
}),
|
||||
CustomField: [
|
||||
...(bodyshop.accountingconfig.ReceivableCustomField1
|
||||
? [
|
||||
{
|
||||
DefinitionId: "1",
|
||||
StringValue: job[bodyshop.accountingconfig.ReceivableCustomField1],
|
||||
Type: "StringType"
|
||||
}
|
||||
]
|
||||
{
|
||||
DefinitionId: "1",
|
||||
StringValue: job[bodyshop.accountingconfig.ReceivableCustomField1],
|
||||
Type: "StringType"
|
||||
}
|
||||
]
|
||||
: []),
|
||||
...(bodyshop.accountingconfig.ReceivableCustomField2
|
||||
? [
|
||||
{
|
||||
DefinitionId: "2",
|
||||
StringValue: job[bodyshop.accountingconfig.ReceivableCustomField2],
|
||||
Type: "StringType"
|
||||
}
|
||||
]
|
||||
{
|
||||
DefinitionId: "2",
|
||||
StringValue: job[bodyshop.accountingconfig.ReceivableCustomField2],
|
||||
Type: "StringType"
|
||||
}
|
||||
]
|
||||
: []),
|
||||
...(bodyshop.accountingconfig.ReceivableCustomField3
|
||||
? [
|
||||
{
|
||||
DefinitionId: "3",
|
||||
StringValue: job[bodyshop.accountingconfig.ReceivableCustomField3],
|
||||
Type: "StringType"
|
||||
}
|
||||
]
|
||||
{
|
||||
DefinitionId: "3",
|
||||
StringValue: job[bodyshop.accountingconfig.ReceivableCustomField3],
|
||||
Type: "StringType"
|
||||
}
|
||||
]
|
||||
: [])
|
||||
],
|
||||
...(bodyshop.accountingconfig &&
|
||||
bodyshop.accountingconfig.qbo &&
|
||||
bodyshop.accountingconfig.qbo_usa &&
|
||||
bodyshop.region_config.includes("CA_") && {
|
||||
TxnTaxDetail: {
|
||||
TxnTaxCodeRef: {
|
||||
value: taxCodes[bodyshop.md_responsibility_centers.taxes.state.accountitem]
|
||||
TxnTaxDetail: {
|
||||
TxnTaxCodeRef: {
|
||||
value: taxCodes[bodyshop.md_responsibility_centers.taxes.state.accountitem]
|
||||
}
|
||||
}
|
||||
}
|
||||
}),
|
||||
}),
|
||||
|
||||
...(bodyshop.accountingconfig.printlater ? { PrintStatus: "NeedToPrint" } : {}),
|
||||
...(bodyshop.accountingconfig.emaillater && job.ownr_ea ? { EmailStatus: "NeedToSend" } : {}),
|
||||
@@ -785,7 +810,7 @@ async function InsertInvoiceMultiPayerInvoice(
|
||||
bodyshopid: job.shopid,
|
||||
jobid: job.id,
|
||||
email: req.user.email
|
||||
})
|
||||
});
|
||||
setNewRefreshToken(req.user.email, result);
|
||||
return result && result.json && result.json.Invoice;
|
||||
} catch (error) {
|
||||
|
||||
@@ -1,8 +1,3 @@
|
||||
const path = require("path");
|
||||
require("dotenv").config({
|
||||
path: path.resolve(process.cwd(), `.env.${process.env.NODE_ENV || "development"}`)
|
||||
});
|
||||
|
||||
function urlBuilder(realmId, object, query = null) {
|
||||
return `https://${
|
||||
process.env.NODE_ENV === "production" ? "" : "sandbox-"
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
const GraphQLClient = require("graphql-request").GraphQLClient;
|
||||
const path = require("path");
|
||||
const DineroQbFormat = require("../accounting-constants").DineroQbFormat;
|
||||
const queries = require("../../graphql-client/queries");
|
||||
const Dinero = require("dinero.js");
|
||||
@@ -9,10 +7,6 @@ const moment = require("moment-timezone");
|
||||
const logger = require("../../utils/logger");
|
||||
const InstanceManager = require("../../utils/instanceMgr").default;
|
||||
|
||||
require("dotenv").config({
|
||||
path: path.resolve(process.cwd(), `.env.${process.env.NODE_ENV || "development"}`)
|
||||
});
|
||||
|
||||
exports.default = async (req, res) => {
|
||||
const { bills: billsToQuery } = req.body;
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
const path = require("path");
|
||||
const DineroQbFormat = require("../accounting-constants").DineroQbFormat;
|
||||
const queries = require("../../graphql-client/queries");
|
||||
const Dinero = require("dinero.js");
|
||||
@@ -8,10 +7,6 @@ const QbXmlUtils = require("./qbxml-utils");
|
||||
const QbxmlReceivables = require("./qbxml-receivables");
|
||||
const logger = require("../../utils/logger");
|
||||
|
||||
require("dotenv").config({
|
||||
path: path.resolve(process.cwd(), `.env.${process.env.NODE_ENV || "development"}`)
|
||||
});
|
||||
|
||||
const { generateJobTier, generateOwnerTier, generateSourceTier } = QbXmlUtils;
|
||||
|
||||
exports.default = async (req, res) => {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
const path = require("path");
|
||||
const DineroQbFormat = require("../accounting-constants").DineroQbFormat;
|
||||
const queries = require("../../graphql-client/queries");
|
||||
const Dinero = require("dinero.js");
|
||||
@@ -9,10 +8,6 @@ const CreateInvoiceLines = require("../qb-receivables-lines").default;
|
||||
const logger = require("../../utils/logger");
|
||||
const InstanceManager = require("../../utils/instanceMgr").default;
|
||||
|
||||
require("dotenv").config({
|
||||
path: path.resolve(process.cwd(), `.env.${process.env.NODE_ENV || "development"}`)
|
||||
});
|
||||
|
||||
Dinero.globalRoundingMode = "HALF_EVEN";
|
||||
const { generateJobTier, generateOwnerTier, generateSourceTier } = QbXmlUtils;
|
||||
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
exports.addQbxmlHeader = addQbxmlHeader = (xml) => {
|
||||
const addQbxmlHeader = (xml) => {
|
||||
return `<?xml version="1.0" encoding="utf-8"?>
|
||||
<?qbxml version="13.0"?>
|
||||
${xml}
|
||||
`;
|
||||
};
|
||||
|
||||
exports.addQbxmlHeader = addQbxmlHeader;
|
||||
|
||||
exports.generateSourceTier = (jobs_by_pk) => {
|
||||
return jobs_by_pk.ins_co_nm && jobs_by_pk.ins_co_nm.trim().replace(":", " ");
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user