Merge branch 'release/2021-10-22' into test
This commit is contained in:
@@ -210,7 +210,7 @@ export function ScheduleEventComponent({
|
|||||||
job: event.job,
|
job: event.job,
|
||||||
previousEvent: event.id,
|
previousEvent: event.id,
|
||||||
color: event.color,
|
color: event.color,
|
||||||
alt_transport: event.alt_transport,
|
alt_transport: event.job && event.job.alt_transport,
|
||||||
note: event.note,
|
note: event.note,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import {
|
|||||||
import { logImEXEvent } from "../../firebase/firebase.utils";
|
import { logImEXEvent } from "../../firebase/firebase.utils";
|
||||||
import { INSERT_EXPORT_LOG } from "../../graphql/accounting.queries";
|
import { INSERT_EXPORT_LOG } from "../../graphql/accounting.queries";
|
||||||
import { useHistory } from "react-router-dom";
|
import { useHistory } from "react-router-dom";
|
||||||
import { useCookies } from "react-cookie";
|
|
||||||
|
|
||||||
const mapStateToProps = createStructuredSelector({
|
const mapStateToProps = createStructuredSelector({
|
||||||
bodyshop: selectBodyshop,
|
bodyshop: selectBodyshop,
|
||||||
@@ -33,7 +33,6 @@ export function JobsCloseExportButton({
|
|||||||
const [updateJob] = useMutation(UPDATE_JOB);
|
const [updateJob] = useMutation(UPDATE_JOB);
|
||||||
const [insertExportLog] = useMutation(INSERT_EXPORT_LOG);
|
const [insertExportLog] = useMutation(INSERT_EXPORT_LOG);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [cookies] = useCookies();
|
|
||||||
|
|
||||||
const handleQbxml = async () => {
|
const handleQbxml = async () => {
|
||||||
//Check if it's a CDK setup.
|
//Check if it's a CDK setup.
|
||||||
@@ -182,16 +181,7 @@ export function JobsCloseExportButton({
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Button
|
<Button onClick={handleQbxml} loading={loading} disabled={disabled}>
|
||||||
onClick={handleQbxml}
|
|
||||||
loading={loading}
|
|
||||||
disabled={
|
|
||||||
disabled ||
|
|
||||||
(bodyshop.accountingconfig &&
|
|
||||||
bodyshop.accountingconfig.qbo &&
|
|
||||||
!cookies.qbo_realmId)
|
|
||||||
}
|
|
||||||
>
|
|
||||||
{t("jobs.actions.export")}
|
{t("jobs.actions.export")}
|
||||||
</Button>
|
</Button>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -11,9 +11,8 @@ import { INSERT_EXPORT_LOG } from "../../graphql/accounting.queries";
|
|||||||
import { UPDATE_JOBS } from "../../graphql/jobs.queries";
|
import { UPDATE_JOBS } from "../../graphql/jobs.queries";
|
||||||
import {
|
import {
|
||||||
selectBodyshop,
|
selectBodyshop,
|
||||||
selectCurrentUser,
|
selectCurrentUser
|
||||||
} from "../../redux/user/user.selectors";
|
} from "../../redux/user/user.selectors";
|
||||||
import { useCookies } from "react-cookie";
|
|
||||||
|
|
||||||
const mapStateToProps = createStructuredSelector({
|
const mapStateToProps = createStructuredSelector({
|
||||||
bodyshop: selectBodyshop,
|
bodyshop: selectBodyshop,
|
||||||
@@ -31,7 +30,7 @@ export function JobsExportAllButton({
|
|||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [updateJob] = useMutation(UPDATE_JOBS);
|
const [updateJob] = useMutation(UPDATE_JOBS);
|
||||||
const [insertExportLog] = useMutation(INSERT_EXPORT_LOG);
|
const [insertExportLog] = useMutation(INSERT_EXPORT_LOG);
|
||||||
const [cookies] = useCookies();
|
|
||||||
|
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const handleQbxml = async () => {
|
const handleQbxml = async () => {
|
||||||
@@ -175,16 +174,7 @@ export function JobsExportAllButton({
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Button
|
<Button onClick={handleQbxml} loading={loading} disabled={disabled}>
|
||||||
onClick={handleQbxml}
|
|
||||||
loading={loading}
|
|
||||||
disabled={
|
|
||||||
disabled ||
|
|
||||||
(bodyshop.accountingconfig &&
|
|
||||||
bodyshop.accountingconfig.qbo &&
|
|
||||||
!cookies.qbo_realmId)
|
|
||||||
}
|
|
||||||
>
|
|
||||||
{t("jobs.actions.export")}
|
{t("jobs.actions.export")}
|
||||||
</Button>
|
</Button>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import {
|
|||||||
import { logImEXEvent } from "../../firebase/firebase.utils";
|
import { logImEXEvent } from "../../firebase/firebase.utils";
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
import { INSERT_EXPORT_LOG } from "../../graphql/accounting.queries";
|
import { INSERT_EXPORT_LOG } from "../../graphql/accounting.queries";
|
||||||
import { useCookies } from "react-cookie";
|
|
||||||
|
|
||||||
const mapStateToProps = createStructuredSelector({
|
const mapStateToProps = createStructuredSelector({
|
||||||
bodyshop: selectBodyshop,
|
bodyshop: selectBodyshop,
|
||||||
@@ -33,7 +33,7 @@ export function PayableExportAll({
|
|||||||
const [updateBill] = useMutation(UPDATE_BILLS);
|
const [updateBill] = useMutation(UPDATE_BILLS);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [insertExportLog] = useMutation(INSERT_EXPORT_LOG);
|
const [insertExportLog] = useMutation(INSERT_EXPORT_LOG);
|
||||||
const [cookies] = useCookies();
|
|
||||||
|
|
||||||
const handleQbxml = async () => {
|
const handleQbxml = async () => {
|
||||||
logImEXEvent("accounting_payables_export_all");
|
logImEXEvent("accounting_payables_export_all");
|
||||||
@@ -174,16 +174,7 @@ export function PayableExportAll({
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Button
|
<Button onClick={handleQbxml} loading={loading} disabled={disabled}>
|
||||||
onClick={handleQbxml}
|
|
||||||
loading={loading}
|
|
||||||
disabled={
|
|
||||||
disabled ||
|
|
||||||
(bodyshop.accountingconfig &&
|
|
||||||
bodyshop.accountingconfig.qbo &&
|
|
||||||
!cookies.qbo_realmId)
|
|
||||||
}
|
|
||||||
>
|
|
||||||
{t("jobs.actions.exportselected")}
|
{t("jobs.actions.exportselected")}
|
||||||
</Button>
|
</Button>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import {
|
|||||||
} from "../../redux/user/user.selectors";
|
} from "../../redux/user/user.selectors";
|
||||||
import { logImEXEvent } from "../../firebase/firebase.utils";
|
import { logImEXEvent } from "../../firebase/firebase.utils";
|
||||||
import { INSERT_EXPORT_LOG } from "../../graphql/accounting.queries";
|
import { INSERT_EXPORT_LOG } from "../../graphql/accounting.queries";
|
||||||
import { useCookies } from "react-cookie";
|
|
||||||
|
|
||||||
const mapStateToProps = createStructuredSelector({
|
const mapStateToProps = createStructuredSelector({
|
||||||
bodyshop: selectBodyshop,
|
bodyshop: selectBodyshop,
|
||||||
@@ -32,7 +32,7 @@ export function PayableExportButton({
|
|||||||
const [updateBill] = useMutation(UPDATE_BILLS);
|
const [updateBill] = useMutation(UPDATE_BILLS);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [insertExportLog] = useMutation(INSERT_EXPORT_LOG);
|
const [insertExportLog] = useMutation(INSERT_EXPORT_LOG);
|
||||||
const [cookies] = useCookies();
|
|
||||||
|
|
||||||
const handleQbxml = async () => {
|
const handleQbxml = async () => {
|
||||||
logImEXEvent("accounting_export_payable");
|
logImEXEvent("accounting_export_payable");
|
||||||
@@ -176,16 +176,7 @@ export function PayableExportButton({
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Button
|
<Button onClick={handleQbxml} loading={loading} disabled={disabled}>
|
||||||
onClick={handleQbxml}
|
|
||||||
loading={loading}
|
|
||||||
disabled={
|
|
||||||
disabled ||
|
|
||||||
(bodyshop.accountingconfig &&
|
|
||||||
bodyshop.accountingconfig.qbo &&
|
|
||||||
!cookies.qbo_realmId)
|
|
||||||
}
|
|
||||||
>
|
|
||||||
{t("jobs.actions.export")}
|
{t("jobs.actions.export")}
|
||||||
</Button>
|
</Button>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import { createStructuredSelector } from "reselect";
|
|||||||
import { auth, logImEXEvent } from "../../firebase/firebase.utils";
|
import { auth, logImEXEvent } from "../../firebase/firebase.utils";
|
||||||
import { INSERT_EXPORT_LOG } from "../../graphql/accounting.queries";
|
import { INSERT_EXPORT_LOG } from "../../graphql/accounting.queries";
|
||||||
import { UPDATE_PAYMENTS } from "../../graphql/payments.queries";
|
import { UPDATE_PAYMENTS } from "../../graphql/payments.queries";
|
||||||
import { useCookies } from "react-cookie";
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
selectBodyshop,
|
selectBodyshop,
|
||||||
@@ -32,7 +32,7 @@ export function PaymentExportButton({
|
|||||||
const [updatePayment] = useMutation(UPDATE_PAYMENTS);
|
const [updatePayment] = useMutation(UPDATE_PAYMENTS);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [insertExportLog] = useMutation(INSERT_EXPORT_LOG);
|
const [insertExportLog] = useMutation(INSERT_EXPORT_LOG);
|
||||||
const [cookies] = useCookies();
|
|
||||||
|
|
||||||
const handleQbxml = async () => {
|
const handleQbxml = async () => {
|
||||||
logImEXEvent("accounting_payment_export");
|
logImEXEvent("accounting_payment_export");
|
||||||
@@ -177,16 +177,7 @@ export function PaymentExportButton({
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Button
|
<Button onClick={handleQbxml} loading={loading} disabled={disabled}>
|
||||||
onClick={handleQbxml}
|
|
||||||
loading={loading}
|
|
||||||
disabled={
|
|
||||||
disabled ||
|
|
||||||
(bodyshop.accountingconfig &&
|
|
||||||
bodyshop.accountingconfig.qbo &&
|
|
||||||
!cookies.qbo_realmId)
|
|
||||||
}
|
|
||||||
>
|
|
||||||
{t("jobs.actions.export")}
|
{t("jobs.actions.export")}
|
||||||
</Button>
|
</Button>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import { connect } from "react-redux";
|
|||||||
import { createStructuredSelector } from "reselect";
|
import { createStructuredSelector } from "reselect";
|
||||||
import { INSERT_EXPORT_LOG } from "../../graphql/accounting.queries";
|
import { INSERT_EXPORT_LOG } from "../../graphql/accounting.queries";
|
||||||
import { UPDATE_PAYMENTS } from "../../graphql/payments.queries";
|
import { UPDATE_PAYMENTS } from "../../graphql/payments.queries";
|
||||||
import { useCookies } from "react-cookie";
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
selectBodyshop,
|
selectBodyshop,
|
||||||
@@ -31,7 +31,7 @@ export function PaymentsExportAllButton({
|
|||||||
const [updatePayments] = useMutation(UPDATE_PAYMENTS);
|
const [updatePayments] = useMutation(UPDATE_PAYMENTS);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [insertExportLog] = useMutation(INSERT_EXPORT_LOG);
|
const [insertExportLog] = useMutation(INSERT_EXPORT_LOG);
|
||||||
const [cookies] = useCookies();
|
|
||||||
|
|
||||||
const handleQbxml = async () => {
|
const handleQbxml = async () => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
@@ -158,16 +158,7 @@ export function PaymentsExportAllButton({
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Button
|
<Button onClick={handleQbxml} loading={loading} disabled={disabled}>
|
||||||
onClick={handleQbxml}
|
|
||||||
loading={loading}
|
|
||||||
disabled={
|
|
||||||
disabled ||
|
|
||||||
(bodyshop.accountingconfig &&
|
|
||||||
bodyshop.accountingconfig.qbo &&
|
|
||||||
!cookies.qbo_realmId)
|
|
||||||
}
|
|
||||||
>
|
|
||||||
{t("jobs.actions.exportselected")}
|
{t("jobs.actions.exportselected")}
|
||||||
</Button>
|
</Button>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Space, Tag } from "antd";
|
import { Space } from "antd";
|
||||||
import Axios from "axios";
|
import Axios from "axios";
|
||||||
import queryString from "query-string";
|
import queryString from "query-string";
|
||||||
import React, { useEffect } from "react";
|
import React, { useEffect } from "react";
|
||||||
@@ -9,7 +9,7 @@ import QboSignIn from "../../assets/qbo/C2QB_green_btn_med_default.svg";
|
|||||||
export default function QboAuthorizeComponent() {
|
export default function QboAuthorizeComponent() {
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
const [cookies, setCookie] = useCookies(["access_token", "refresh_token"]);
|
const [, setCookie] = useCookies(["access_token", "refresh_token"]);
|
||||||
|
|
||||||
const handleQbSignIn = async () => {
|
const handleQbSignIn = async () => {
|
||||||
const result = await Axios.post("/qbo/authorize");
|
const result = await Axios.post("/qbo/authorize");
|
||||||
@@ -24,20 +24,20 @@ export default function QboAuthorizeComponent() {
|
|||||||
const hasBeenCalledBack = code && realmId && state;
|
const hasBeenCalledBack = code && realmId && state;
|
||||||
|
|
||||||
if (hasBeenCalledBack) {
|
if (hasBeenCalledBack) {
|
||||||
setCookie("qbo_code", code, { path: "/" });
|
// setCookie("qbo_code", code, { path: "/" });
|
||||||
setCookie("qbo_state", state, { path: "/" });
|
// setCookie("qbo_state", state, { path: "/" });
|
||||||
|
|
||||||
let expires = new Date();
|
// let expires = new Date();
|
||||||
expires.setTime(expires.getTime() + 8726400 * 1000);
|
// expires.setTime(expires.getTime() + 8726400 * 1000);
|
||||||
|
|
||||||
setCookie("qbo_realmId", realmId, {
|
// setCookie("qbo_realmId", realmId, {
|
||||||
path: "/",
|
// path: "/",
|
||||||
expires,
|
// expires,
|
||||||
|
|
||||||
...(process.env.NODE_ENV !== "development"
|
// ...(process.env.NODE_ENV !== "development"
|
||||||
? { domain: `.${window.location.host}` }
|
// ? { domain: `.${window.location.host}` }
|
||||||
: {}),
|
// : {}),
|
||||||
});
|
// });
|
||||||
|
|
||||||
history.push({ pathname: `/manage/accounting/receivables` });
|
history.push({ pathname: `/manage/accounting/receivables` });
|
||||||
}
|
}
|
||||||
@@ -52,9 +52,7 @@ export default function QboAuthorizeComponent() {
|
|||||||
src={QboSignIn}
|
src={QboSignIn}
|
||||||
style={{ cursor: "pointer" }}
|
style={{ cursor: "pointer" }}
|
||||||
/>
|
/>
|
||||||
{!cookies.qbo_realmId && (
|
|
||||||
<Tag color="red">No QuickBooks company has been connected.</Tag>
|
|
||||||
)}
|
|
||||||
{error && JSON.parse(decodeURIComponent(error)).error_description}
|
{error && JSON.parse(decodeURIComponent(error)).error_description}
|
||||||
</Space>
|
</Space>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -203,6 +203,7 @@
|
|||||||
- authlevel
|
- authlevel
|
||||||
- default_prod_list_view
|
- default_prod_list_view
|
||||||
- id
|
- id
|
||||||
|
- qbo_realmId
|
||||||
- shopid
|
- shopid
|
||||||
- useremail
|
- useremail
|
||||||
filter:
|
filter:
|
||||||
@@ -216,6 +217,7 @@
|
|||||||
- active
|
- active
|
||||||
- authlevel
|
- authlevel
|
||||||
- default_prod_list_view
|
- default_prod_list_view
|
||||||
|
- qbo_realmId
|
||||||
filter:
|
filter:
|
||||||
bodyshop:
|
bodyshop:
|
||||||
associations:
|
associations:
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
-- Could not auto-generate a down migration.
|
||||||
|
-- Please write an appropriate down migration for the SQL below:
|
||||||
|
-- alter table "public"."associations" add column "qbo_realmId" text
|
||||||
|
-- null;
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
alter table "public"."associations" add column "qbo_realmId" text
|
||||||
|
null;
|
||||||
File diff suppressed because one or more lines are too long
@@ -38,7 +38,9 @@ exports.default = function ({
|
|||||||
|
|
||||||
if (
|
if (
|
||||||
(jobline.prt_dsmk_p && jobline.prt_dsmk_p !== 0) ||
|
(jobline.prt_dsmk_p && jobline.prt_dsmk_p !== 0) ||
|
||||||
jobline.prt_dsmk_m !== 0
|
((jobline.db_ref === "900511" || jobline.db_ref === "900510") &&
|
||||||
|
jobline.prt_dsmk_m &&
|
||||||
|
jobline.prt_dsmk_m !== 0)
|
||||||
) {
|
) {
|
||||||
// console.log("Have a part discount", jobline);
|
// console.log("Have a part discount", jobline);
|
||||||
DineroAmount = DineroAmount.add(
|
DineroAmount = DineroAmount.add(
|
||||||
|
|||||||
@@ -44,9 +44,10 @@ exports.default = async (req, res) => {
|
|||||||
)}`
|
)}`
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
await client.request(queries.SET_QBO_AUTH, {
|
await client.request(queries.SET_QBO_AUTH_WITH_REALM, {
|
||||||
email: params.state,
|
email: params.state,
|
||||||
qbo_auth: { ...authResponse.json, createdAt: Date.now() },
|
qbo_auth: { ...authResponse.json, createdAt: Date.now() },
|
||||||
|
qbo_realmId: params.realmId,
|
||||||
});
|
});
|
||||||
logger.log(
|
logger.log(
|
||||||
"qbo-callback-create-token-success",
|
"qbo-callback-create-token-success",
|
||||||
|
|||||||
@@ -34,10 +34,14 @@ exports.default = async (req, res) => {
|
|||||||
const response = await apiGqlClient.request(queries.GET_QBO_AUTH, {
|
const response = await apiGqlClient.request(queries.GET_QBO_AUTH, {
|
||||||
email: req.user.email,
|
email: req.user.email,
|
||||||
});
|
});
|
||||||
|
const { qbo_realmId } = response.associations[0];
|
||||||
|
|
||||||
oauthClient.setToken(response.associations[0].qbo_auth);
|
oauthClient.setToken(response.associations[0].qbo_auth);
|
||||||
|
if (!qbo_realmId) {
|
||||||
await refreshOauthToken(oauthClient, req);
|
res.status(401).json({ error: "No company associated." });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await refreshOauthToken(oauthClient, qbo_realmId, req);
|
||||||
|
|
||||||
const BearerToken = req.headers.authorization;
|
const BearerToken = req.headers.authorization;
|
||||||
const { bills: billsToQuery } = req.body;
|
const { bills: billsToQuery } = req.body;
|
||||||
@@ -60,14 +64,26 @@ exports.default = async (req, res) => {
|
|||||||
for (const bill of bills) {
|
for (const bill of bills) {
|
||||||
try {
|
try {
|
||||||
let vendorRecord;
|
let vendorRecord;
|
||||||
vendorRecord = await QueryVendorRecord(oauthClient, req, bill);
|
vendorRecord = await QueryVendorRecord(
|
||||||
|
oauthClient,
|
||||||
|
qbo_realmId,
|
||||||
|
qbo_realmId,
|
||||||
|
req,
|
||||||
|
bill
|
||||||
|
);
|
||||||
|
|
||||||
if (!vendorRecord) {
|
if (!vendorRecord) {
|
||||||
vendorRecord = await InsertVendorRecord(oauthClient, req, bill);
|
vendorRecord = await InsertVendorRecord(
|
||||||
|
oauthClient,
|
||||||
|
qbo_realmId,
|
||||||
|
req,
|
||||||
|
bill
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const insertResults = await InsertBill(
|
const insertResults = await InsertBill(
|
||||||
oauthClient,
|
oauthClient,
|
||||||
|
qbo_realmId,
|
||||||
req,
|
req,
|
||||||
bill,
|
bill,
|
||||||
vendorRecord
|
vendorRecord
|
||||||
@@ -93,11 +109,11 @@ exports.default = async (req, res) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
async function QueryVendorRecord(oauthClient, req, bill) {
|
async function QueryVendorRecord(oauthClient, qbo_realmId, req, bill) {
|
||||||
try {
|
try {
|
||||||
const result = await oauthClient.makeApiCall({
|
const result = await oauthClient.makeApiCall({
|
||||||
url: urlBuilder(
|
url: urlBuilder(
|
||||||
req.cookies.qbo_realmId,
|
qbo_realmId,
|
||||||
"query",
|
"query",
|
||||||
`select * From vendor where DisplayName = '${bill.vendor.name}'`
|
`select * From vendor where DisplayName = '${bill.vendor.name}'`
|
||||||
),
|
),
|
||||||
@@ -123,13 +139,13 @@ async function QueryVendorRecord(oauthClient, req, bill) {
|
|||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async function InsertVendorRecord(oauthClient, req, bill) {
|
async function InsertVendorRecord(oauthClient, qbo_realmId, req, bill) {
|
||||||
const Vendor = {
|
const Vendor = {
|
||||||
DisplayName: bill.vendor.name,
|
DisplayName: bill.vendor.name,
|
||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
const result = await oauthClient.makeApiCall({
|
const result = await oauthClient.makeApiCall({
|
||||||
url: urlBuilder(req.cookies.qbo_realmId, "vendor"),
|
url: urlBuilder(qbo_realmId, "vendor"),
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@@ -149,8 +165,12 @@ async function InsertVendorRecord(oauthClient, req, bill) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function InsertBill(oauthClient, req, bill, vendor) {
|
async function InsertBill(oauthClient, qbo_realmId, req, bill, vendor) {
|
||||||
const { accounts, taxCodes, classes } = await QueryMetaData(oauthClient, req);
|
const { accounts, taxCodes, classes } = await QueryMetaData(
|
||||||
|
oauthClient,
|
||||||
|
qbo_realmId,
|
||||||
|
req
|
||||||
|
);
|
||||||
|
|
||||||
const billQbo = {
|
const billQbo = {
|
||||||
VendorRef: {
|
VendorRef: {
|
||||||
@@ -182,7 +202,7 @@ async function InsertBill(oauthClient, req, bill, vendor) {
|
|||||||
try {
|
try {
|
||||||
const result = await oauthClient.makeApiCall({
|
const result = await oauthClient.makeApiCall({
|
||||||
url: urlBuilder(
|
url: urlBuilder(
|
||||||
req.cookies.qbo_realmId,
|
qbo_realmId,
|
||||||
bill.is_credit_memo ? "vendorcredit" : "bill"
|
bill.is_credit_memo ? "vendorcredit" : "bill"
|
||||||
),
|
),
|
||||||
method: "POST",
|
method: "POST",
|
||||||
@@ -248,10 +268,10 @@ const generateBillLine = (
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
async function QueryMetaData(oauthClient, req) {
|
async function QueryMetaData(oauthClient, qbo_realmId, req) {
|
||||||
const accounts = await oauthClient.makeApiCall({
|
const accounts = await oauthClient.makeApiCall({
|
||||||
url: urlBuilder(
|
url: urlBuilder(
|
||||||
req.cookies.qbo_realmId,
|
qbo_realmId,
|
||||||
"query",
|
"query",
|
||||||
`select * From Account where AccountType = 'Cost of Goods Sold'`
|
`select * From Account where AccountType = 'Cost of Goods Sold'`
|
||||||
),
|
),
|
||||||
@@ -262,7 +282,7 @@ async function QueryMetaData(oauthClient, req) {
|
|||||||
});
|
});
|
||||||
setNewRefreshToken(req.user.email, accounts);
|
setNewRefreshToken(req.user.email, accounts);
|
||||||
const taxCodes = await oauthClient.makeApiCall({
|
const taxCodes = await oauthClient.makeApiCall({
|
||||||
url: urlBuilder(req.cookies.qbo_realmId, "query", `select * From TaxCode`),
|
url: urlBuilder(qbo_realmId, "query", `select * From TaxCode`),
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@@ -270,7 +290,7 @@ async function QueryMetaData(oauthClient, req) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const classes = await oauthClient.makeApiCall({
|
const classes = await oauthClient.makeApiCall({
|
||||||
url: urlBuilder(req.cookies.qbo_realmId, "query", `select * From Class`),
|
url: urlBuilder(qbo_realmId, "query", `select * From Class`),
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
|||||||
@@ -42,10 +42,13 @@ exports.default = async (req, res) => {
|
|||||||
const response = await apiGqlClient.request(queries.GET_QBO_AUTH, {
|
const response = await apiGqlClient.request(queries.GET_QBO_AUTH, {
|
||||||
email: req.user.email,
|
email: req.user.email,
|
||||||
});
|
});
|
||||||
|
const { qbo_realmId } = response.associations[0];
|
||||||
oauthClient.setToken(response.associations[0].qbo_auth);
|
oauthClient.setToken(response.associations[0].qbo_auth);
|
||||||
|
if (!qbo_realmId) {
|
||||||
await refreshOauthToken(oauthClient, req);
|
res.status(401).json({ error: "No company associated." });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await refreshOauthToken(oauthClient, qbo_realmId, req);
|
||||||
|
|
||||||
const BearerToken = req.headers.authorization;
|
const BearerToken = req.headers.authorization;
|
||||||
const { payments: paymentsToQuery } = req.body;
|
const { payments: paymentsToQuery } = req.body;
|
||||||
@@ -80,6 +83,7 @@ exports.default = async (req, res) => {
|
|||||||
//Query for top level customer, the insurance company name.
|
//Query for top level customer, the insurance company name.
|
||||||
insCoCustomerTier = await QueryInsuranceCo(
|
insCoCustomerTier = await QueryInsuranceCo(
|
||||||
oauthClient,
|
oauthClient,
|
||||||
|
qbo_realmId,
|
||||||
req,
|
req,
|
||||||
payment.job
|
payment.job
|
||||||
);
|
);
|
||||||
@@ -87,6 +91,7 @@ exports.default = async (req, res) => {
|
|||||||
//Creating the Insurance Customer.
|
//Creating the Insurance Customer.
|
||||||
insCoCustomerTier = await InsertInsuranceCo(
|
insCoCustomerTier = await InsertInsuranceCo(
|
||||||
oauthClient,
|
oauthClient,
|
||||||
|
qbo_realmId,
|
||||||
req,
|
req,
|
||||||
payment.job,
|
payment.job,
|
||||||
bodyshop
|
bodyshop
|
||||||
@@ -96,11 +101,17 @@ exports.default = async (req, res) => {
|
|||||||
|
|
||||||
if (isThreeTier || (!isThreeTier && twoTierPref === "name")) {
|
if (isThreeTier || (!isThreeTier && twoTierPref === "name")) {
|
||||||
//Insert the name/owner and account for whether the source should be the ins co in 3 tier..
|
//Insert the name/owner and account for whether the source should be the ins co in 3 tier..
|
||||||
ownerCustomerTier = await QueryOwner(oauthClient, req, payment.job);
|
ownerCustomerTier = await QueryOwner(
|
||||||
|
oauthClient,
|
||||||
|
qbo_realmId,
|
||||||
|
req,
|
||||||
|
payment.job
|
||||||
|
);
|
||||||
//Query for the owner itself.
|
//Query for the owner itself.
|
||||||
if (!ownerCustomerTier) {
|
if (!ownerCustomerTier) {
|
||||||
ownerCustomerTier = await InsertOwner(
|
ownerCustomerTier = await InsertOwner(
|
||||||
oauthClient,
|
oauthClient,
|
||||||
|
qbo_realmId,
|
||||||
req,
|
req,
|
||||||
payment.job,
|
payment.job,
|
||||||
isThreeTier,
|
isThreeTier,
|
||||||
@@ -110,20 +121,21 @@ exports.default = async (req, res) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Query for the Job or Create it.
|
//Query for the Job or Create it.
|
||||||
jobTier = await QueryJob(oauthClient, req, payment.job);
|
jobTier = await QueryJob(oauthClient, qbo_realmId, req, payment.job);
|
||||||
|
|
||||||
// Need to validate that the job tier is associated to the right individual?
|
// Need to validate that the job tier is associated to the right individual?
|
||||||
|
|
||||||
if (!jobTier) {
|
if (!jobTier) {
|
||||||
jobTier = await InsertJob(
|
jobTier = await InsertJob(
|
||||||
oauthClient,
|
oauthClient,
|
||||||
|
qbo_realmId,
|
||||||
req,
|
req,
|
||||||
payment.job,
|
payment.job,
|
||||||
ownerCustomerTier || insCoCustomerTier
|
ownerCustomerTier || insCoCustomerTier
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
await InsertPayment(oauthClient, req, payment, jobTier);
|
await InsertPayment(oauthClient, qbo_realmId, req, payment, jobTier);
|
||||||
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, {
|
logger.log("qbo-payment-create-error", "ERROR", req.user.email, {
|
||||||
@@ -150,9 +162,16 @@ exports.default = async (req, res) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
async function InsertPayment(oauthClient, req, payment, parentRef) {
|
async function InsertPayment(
|
||||||
|
oauthClient,
|
||||||
|
qbo_realmId,
|
||||||
|
req,
|
||||||
|
payment,
|
||||||
|
parentRef
|
||||||
|
) {
|
||||||
const { paymentMethods, invoices } = await QueryMetaData(
|
const { paymentMethods, invoices } = await QueryMetaData(
|
||||||
oauthClient,
|
oauthClient,
|
||||||
|
qbo_realmId,
|
||||||
req,
|
req,
|
||||||
payment.job.ro_number
|
payment.job.ro_number
|
||||||
);
|
);
|
||||||
@@ -199,7 +218,7 @@ async function InsertPayment(oauthClient, req, payment, parentRef) {
|
|||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
const result = await oauthClient.makeApiCall({
|
const result = await oauthClient.makeApiCall({
|
||||||
url: urlBuilder(req.cookies.qbo_realmId, "payment"),
|
url: urlBuilder(qbo_realmId, "payment"),
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@@ -216,10 +235,10 @@ async function InsertPayment(oauthClient, req, payment, parentRef) {
|
|||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async function QueryMetaData(oauthClient, req, ro_number) {
|
async function QueryMetaData(oauthClient, qbo_realmId, req, ro_number) {
|
||||||
const invoice = await oauthClient.makeApiCall({
|
const invoice = await oauthClient.makeApiCall({
|
||||||
url: urlBuilder(
|
url: urlBuilder(
|
||||||
req.cookies.qbo_realmId,
|
qbo_realmId,
|
||||||
"query",
|
"query",
|
||||||
`select * From Invoice where DocNumber = '${ro_number}'`
|
`select * From Invoice where DocNumber = '${ro_number}'`
|
||||||
),
|
),
|
||||||
@@ -230,11 +249,7 @@ async function QueryMetaData(oauthClient, req, ro_number) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const paymentMethods = await oauthClient.makeApiCall({
|
const paymentMethods = await oauthClient.makeApiCall({
|
||||||
url: urlBuilder(
|
url: urlBuilder(qbo_realmId, "query", `select * From PaymentMethod`),
|
||||||
req.cookies.qbo_realmId,
|
|
||||||
"query",
|
|
||||||
`select * From PaymentMethod`
|
|
||||||
),
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@@ -243,7 +258,7 @@ async function QueryMetaData(oauthClient, req, ro_number) {
|
|||||||
setNewRefreshToken(req.user.email, paymentMethods);
|
setNewRefreshToken(req.user.email, paymentMethods);
|
||||||
|
|
||||||
// const classes = await oauthClient.makeApiCall({
|
// const classes = await oauthClient.makeApiCall({
|
||||||
// url: urlBuilder(req.cookies.qbo_realmId, "query", `select * From Class`),
|
// url: urlBuilder(qbo_realmId, "query", `select * From Class`),
|
||||||
// method: "POST",
|
// method: "POST",
|
||||||
// headers: {
|
// headers: {
|
||||||
// "Content-Type": "application/json",
|
// "Content-Type": "application/json",
|
||||||
|
|||||||
@@ -34,7 +34,11 @@ exports.default = async (req, res) => {
|
|||||||
const response = await apiGqlClient.request(queries.GET_QBO_AUTH, {
|
const response = await apiGqlClient.request(queries.GET_QBO_AUTH, {
|
||||||
email: req.user.email,
|
email: req.user.email,
|
||||||
});
|
});
|
||||||
|
const { qbo_realmId } = response.associations[0];
|
||||||
|
if (!qbo_realmId) {
|
||||||
|
res.status(401).json({ error: "No company associated." });
|
||||||
|
return;
|
||||||
|
}
|
||||||
oauthClient.setToken(response.associations[0].qbo_auth);
|
oauthClient.setToken(response.associations[0].qbo_auth);
|
||||||
|
|
||||||
await refreshOauthToken(oauthClient, req);
|
await refreshOauthToken(oauthClient, req);
|
||||||
@@ -69,11 +73,17 @@ exports.default = async (req, res) => {
|
|||||||
if (isThreeTier || (!isThreeTier && twoTierPref === "source")) {
|
if (isThreeTier || (!isThreeTier && twoTierPref === "source")) {
|
||||||
//Insert the insurance company tier.
|
//Insert the insurance company tier.
|
||||||
//Query for top level customer, the insurance company name.
|
//Query for top level customer, the insurance company name.
|
||||||
insCoCustomerTier = await QueryInsuranceCo(oauthClient, req, job);
|
insCoCustomerTier = await QueryInsuranceCo(
|
||||||
|
oauthClient,
|
||||||
|
qbo_realmId,
|
||||||
|
req,
|
||||||
|
job
|
||||||
|
);
|
||||||
if (!insCoCustomerTier) {
|
if (!insCoCustomerTier) {
|
||||||
//Creating the Insurance Customer.
|
//Creating the Insurance Customer.
|
||||||
insCoCustomerTier = await InsertInsuranceCo(
|
insCoCustomerTier = await InsertInsuranceCo(
|
||||||
oauthClient,
|
oauthClient,
|
||||||
|
qbo_realmId,
|
||||||
req,
|
req,
|
||||||
job,
|
job,
|
||||||
bodyshop
|
bodyshop
|
||||||
@@ -83,11 +93,17 @@ exports.default = async (req, res) => {
|
|||||||
|
|
||||||
if (isThreeTier || (!isThreeTier && twoTierPref === "name")) {
|
if (isThreeTier || (!isThreeTier && twoTierPref === "name")) {
|
||||||
//Insert the name/owner and account for whether the source should be the ins co in 3 tier..
|
//Insert the name/owner and account for whether the source should be the ins co in 3 tier..
|
||||||
ownerCustomerTier = await QueryOwner(oauthClient, req, job);
|
ownerCustomerTier = await QueryOwner(
|
||||||
|
oauthClient,
|
||||||
|
qbo_realmId,
|
||||||
|
req,
|
||||||
|
job
|
||||||
|
);
|
||||||
//Query for the owner itself.
|
//Query for the owner itself.
|
||||||
if (!ownerCustomerTier) {
|
if (!ownerCustomerTier) {
|
||||||
ownerCustomerTier = await InsertOwner(
|
ownerCustomerTier = await InsertOwner(
|
||||||
oauthClient,
|
oauthClient,
|
||||||
|
qbo_realmId,
|
||||||
req,
|
req,
|
||||||
job,
|
job,
|
||||||
isThreeTier,
|
isThreeTier,
|
||||||
@@ -97,13 +113,14 @@ exports.default = async (req, res) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Query for the Job or Create it.
|
//Query for the Job or Create it.
|
||||||
jobTier = await QueryJob(oauthClient, req, job);
|
jobTier = await QueryJob(oauthClient, qbo_realmId, req, job);
|
||||||
|
|
||||||
// Need to validate that the job tier is associated to the right individual?
|
// Need to validate that the job tier is associated to the right individual?
|
||||||
|
|
||||||
if (!jobTier) {
|
if (!jobTier) {
|
||||||
jobTier = await InsertJob(
|
jobTier = await InsertJob(
|
||||||
oauthClient,
|
oauthClient,
|
||||||
|
qbo_realmId,
|
||||||
req,
|
req,
|
||||||
job,
|
job,
|
||||||
|
|
||||||
@@ -112,7 +129,14 @@ exports.default = async (req, res) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!req.body.custDataOnly) {
|
if (!req.body.custDataOnly) {
|
||||||
await InsertInvoice(oauthClient, req, job, bodyshop, jobTier);
|
await InsertInvoice(
|
||||||
|
oauthClient,
|
||||||
|
qbo_realmId,
|
||||||
|
req,
|
||||||
|
job,
|
||||||
|
bodyshop,
|
||||||
|
jobTier
|
||||||
|
);
|
||||||
}
|
}
|
||||||
ret.push({ jobid: job.id, success: true });
|
ret.push({ jobid: job.id, success: true });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -136,11 +160,11 @@ exports.default = async (req, res) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
async function QueryInsuranceCo(oauthClient, req, job) {
|
async function QueryInsuranceCo(oauthClient, qbo_realmId, req, job) {
|
||||||
try {
|
try {
|
||||||
const result = await oauthClient.makeApiCall({
|
const result = await oauthClient.makeApiCall({
|
||||||
url: urlBuilder(
|
url: urlBuilder(
|
||||||
req.cookies.qbo_realmId,
|
qbo_realmId,
|
||||||
"query",
|
"query",
|
||||||
`select * From Customer where DisplayName = '${job.ins_co_nm}'`
|
`select * From Customer where DisplayName = '${job.ins_co_nm}'`
|
||||||
),
|
),
|
||||||
@@ -165,7 +189,7 @@ async function QueryInsuranceCo(oauthClient, req, job) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
exports.QueryInsuranceCo = QueryInsuranceCo;
|
exports.QueryInsuranceCo = QueryInsuranceCo;
|
||||||
async function InsertInsuranceCo(oauthClient, req, job, bodyshop) {
|
async function InsertInsuranceCo(oauthClient, qbo_realmId, req, job, bodyshop) {
|
||||||
const insCo = bodyshop.md_ins_cos.find((i) => i.name === job.ins_co_nm);
|
const insCo = bodyshop.md_ins_cos.find((i) => i.name === job.ins_co_nm);
|
||||||
|
|
||||||
const Customer = {
|
const Customer = {
|
||||||
@@ -180,7 +204,7 @@ async function InsertInsuranceCo(oauthClient, req, job, bodyshop) {
|
|||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
const result = await oauthClient.makeApiCall({
|
const result = await oauthClient.makeApiCall({
|
||||||
url: urlBuilder(req.cookies.qbo_realmId, "customer"),
|
url: urlBuilder(qbo_realmId, "customer"),
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@@ -198,11 +222,11 @@ async function InsertInsuranceCo(oauthClient, req, job, bodyshop) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
exports.InsertInsuranceCo = InsertInsuranceCo;
|
exports.InsertInsuranceCo = InsertInsuranceCo;
|
||||||
async function QueryOwner(oauthClient, req, job) {
|
async function QueryOwner(oauthClient, qbo_realmId, req, job) {
|
||||||
const ownerName = generateOwnerTier(job, true, null);
|
const ownerName = generateOwnerTier(job, true, null);
|
||||||
const result = await oauthClient.makeApiCall({
|
const result = await oauthClient.makeApiCall({
|
||||||
url: urlBuilder(
|
url: urlBuilder(
|
||||||
req.cookies.qbo_realmId,
|
qbo_realmId,
|
||||||
"query",
|
"query",
|
||||||
`select * From Customer where DisplayName = '${ownerName}'`
|
`select * From Customer where DisplayName = '${ownerName}'`
|
||||||
),
|
),
|
||||||
@@ -220,7 +244,14 @@ async function QueryOwner(oauthClient, req, job) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
exports.QueryOwner = QueryOwner;
|
exports.QueryOwner = QueryOwner;
|
||||||
async function InsertOwner(oauthClient, req, job, isThreeTier, parentTierRef) {
|
async function InsertOwner(
|
||||||
|
oauthClient,
|
||||||
|
qbo_realmId,
|
||||||
|
req,
|
||||||
|
job,
|
||||||
|
isThreeTier,
|
||||||
|
parentTierRef
|
||||||
|
) {
|
||||||
const ownerName = generateOwnerTier(job, true, null);
|
const ownerName = generateOwnerTier(job, true, null);
|
||||||
const Customer = {
|
const Customer = {
|
||||||
DisplayName: ownerName,
|
DisplayName: ownerName,
|
||||||
@@ -242,7 +273,7 @@ async function InsertOwner(oauthClient, req, job, isThreeTier, parentTierRef) {
|
|||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
const result = await oauthClient.makeApiCall({
|
const result = await oauthClient.makeApiCall({
|
||||||
url: urlBuilder(req.cookies.qbo_realmId, "customer"),
|
url: urlBuilder(qbo_realmId, "customer"),
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@@ -260,10 +291,10 @@ async function InsertOwner(oauthClient, req, job, isThreeTier, parentTierRef) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
exports.InsertOwner = InsertOwner;
|
exports.InsertOwner = InsertOwner;
|
||||||
async function QueryJob(oauthClient, req, job) {
|
async function QueryJob(oauthClient, qbo_realmId, req, job) {
|
||||||
const result = await oauthClient.makeApiCall({
|
const result = await oauthClient.makeApiCall({
|
||||||
url: urlBuilder(
|
url: urlBuilder(
|
||||||
req.cookies.qbo_realmId,
|
qbo_realmId,
|
||||||
"query",
|
"query",
|
||||||
`select * From Customer where DisplayName = '${job.ro_number}'`
|
`select * From Customer where DisplayName = '${job.ro_number}'`
|
||||||
),
|
),
|
||||||
@@ -281,7 +312,7 @@ async function QueryJob(oauthClient, req, job) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
exports.QueryJob = QueryJob;
|
exports.QueryJob = QueryJob;
|
||||||
async function InsertJob(oauthClient, req, job, parentTierRef) {
|
async function InsertJob(oauthClient, qbo_realmId, req, job, parentTierRef) {
|
||||||
const Customer = {
|
const Customer = {
|
||||||
DisplayName: job.ro_number,
|
DisplayName: job.ro_number,
|
||||||
BillAddr: {
|
BillAddr: {
|
||||||
@@ -299,7 +330,7 @@ async function InsertJob(oauthClient, req, job, parentTierRef) {
|
|||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
const result = await oauthClient.makeApiCall({
|
const result = await oauthClient.makeApiCall({
|
||||||
url: urlBuilder(req.cookies.qbo_realmId, "customer"),
|
url: urlBuilder(qbo_realmId, "customer"),
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@@ -317,9 +348,9 @@ async function InsertJob(oauthClient, req, job, parentTierRef) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
exports.InsertJob = InsertJob;
|
exports.InsertJob = InsertJob;
|
||||||
async function QueryMetaData(oauthClient, req) {
|
async function QueryMetaData(oauthClient, qbo_realmId, req) {
|
||||||
const items = await oauthClient.makeApiCall({
|
const items = await oauthClient.makeApiCall({
|
||||||
url: urlBuilder(req.cookies.qbo_realmId, "query", `select * From Item`),
|
url: urlBuilder(qbo_realmId, "query", `select * From Item`),
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@@ -327,7 +358,7 @@ async function QueryMetaData(oauthClient, req) {
|
|||||||
});
|
});
|
||||||
setNewRefreshToken(req.user.email, items);
|
setNewRefreshToken(req.user.email, items);
|
||||||
const taxCodes = await oauthClient.makeApiCall({
|
const taxCodes = await oauthClient.makeApiCall({
|
||||||
url: urlBuilder(req.cookies.qbo_realmId, "query", `select * From TaxCode`),
|
url: urlBuilder(qbo_realmId, "query", `select * From TaxCode`),
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@@ -335,7 +366,7 @@ async function QueryMetaData(oauthClient, req) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const classes = await oauthClient.makeApiCall({
|
const classes = await oauthClient.makeApiCall({
|
||||||
url: urlBuilder(req.cookies.qbo_realmId, "query", `select * From Class`),
|
url: urlBuilder(qbo_realmId, "query", `select * From Class`),
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@@ -375,8 +406,19 @@ async function QueryMetaData(oauthClient, req) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async function InsertInvoice(oauthClient, req, job, bodyshop, parentTierRef) {
|
async function InsertInvoice(
|
||||||
const { items, taxCodes, classes } = await QueryMetaData(oauthClient, req);
|
oauthClient,
|
||||||
|
qbo_realmId,
|
||||||
|
req,
|
||||||
|
job,
|
||||||
|
bodyshop,
|
||||||
|
parentTierRef
|
||||||
|
) {
|
||||||
|
const { items, taxCodes, classes } = await QueryMetaData(
|
||||||
|
oauthClient,
|
||||||
|
qbo_realmId,
|
||||||
|
req
|
||||||
|
);
|
||||||
const InvoiceLineAdd = CreateInvoiceLines({
|
const InvoiceLineAdd = CreateInvoiceLines({
|
||||||
bodyshop,
|
bodyshop,
|
||||||
jobs_by_pk: job,
|
jobs_by_pk: job,
|
||||||
@@ -407,7 +449,7 @@ async function InsertInvoice(oauthClient, req, job, bodyshop, parentTierRef) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const result = await oauthClient.makeApiCall({
|
const result = await oauthClient.makeApiCall({
|
||||||
url: urlBuilder(req.cookies.qbo_realmId, "invoice"),
|
url: urlBuilder(qbo_realmId, "invoice"),
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
|
||||||
headers: {
|
headers: {
|
||||||
|
|||||||
@@ -70,7 +70,12 @@ exports.default = async function (socket, jobid) {
|
|||||||
amount: Math.round(val.act_price * 100),
|
amount: Math.round(val.act_price * 100),
|
||||||
}).multiply(val.part_qty || 1);
|
}).multiply(val.part_qty || 1);
|
||||||
|
|
||||||
if ((val.prt_dsmk_p && val.prt_dsmk_p !== 0) || val.prt_dsmk_m !== 0) {
|
if (
|
||||||
|
(val.prt_dsmk_p && val.prt_dsmk_p !== 0) ||
|
||||||
|
((val.db_ref === "900511" || val.db_ref === "900510") &&
|
||||||
|
val.prt_dsmk_m &&
|
||||||
|
val.prt_dsmk_m !== 0)
|
||||||
|
) {
|
||||||
// console.log("Have a part discount", val);
|
// console.log("Have a part discount", val);
|
||||||
DineroAmount = DineroAmount.add(
|
DineroAmount = DineroAmount.add(
|
||||||
val.prt_dsmk_m && val.prt_dsmk_m !== 0
|
val.prt_dsmk_m && val.prt_dsmk_m !== 0
|
||||||
|
|||||||
@@ -1194,9 +1194,17 @@ exports.GET_QBO_AUTH = `query GET_QBO_AUTH($email: String!) {
|
|||||||
associations(where: {_and: {active: {_eq: true}, useremail: {_eq: $email}}}){
|
associations(where: {_and: {active: {_eq: true}, useremail: {_eq: $email}}}){
|
||||||
id
|
id
|
||||||
qbo_auth
|
qbo_auth
|
||||||
|
qbo_realmId
|
||||||
}
|
}
|
||||||
}`;
|
}`;
|
||||||
|
|
||||||
|
exports.SET_QBO_AUTH_WITH_REALM = `mutation SET_QBO_AUTH($email: String!, $qbo_auth: jsonb!, $qbo_realmId: String) {
|
||||||
|
update_associations(_set: {qbo_auth: $qbo_auth, qbo_realmId: $qbo_realmId}, where: {_and: {active: {_eq: true}, useremail: {_eq: $email}}}){
|
||||||
|
affected_rows
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
exports.SET_QBO_AUTH = `mutation SET_QBO_AUTH($email: String!, $qbo_auth: jsonb!) {
|
exports.SET_QBO_AUTH = `mutation SET_QBO_AUTH($email: String!, $qbo_auth: jsonb!) {
|
||||||
update_associations(_set: {qbo_auth: $qbo_auth}, where: {_and: {active: {_eq: true}, useremail: {_eq: $email}}}){
|
update_associations(_set: {qbo_auth: $qbo_auth}, where: {_and: {active: {_eq: true}, useremail: {_eq: $email}}}){
|
||||||
affected_rows
|
affected_rows
|
||||||
|
|||||||
@@ -270,7 +270,10 @@ function CalculatePartsTotals(jobLines) {
|
|||||||
})
|
})
|
||||||
.multiply(value.part_qty || 0)
|
.multiply(value.part_qty || 0)
|
||||||
.add(
|
.add(
|
||||||
value.prt_dsmk_m && value.prt_dsmk_m !== 0
|
(value.db_ref === "900511" ||
|
||||||
|
value.db_ref === "900510") &&
|
||||||
|
value.prt_dsmk_m &&
|
||||||
|
value.prt_dsmk_m !== 0
|
||||||
? Dinero({ amount: Math.round(value.prt_dsmk_m * 100) })
|
? Dinero({ amount: Math.round(value.prt_dsmk_m * 100) })
|
||||||
: Dinero({
|
: Dinero({
|
||||||
amount: Math.round(value.act_price * 100),
|
amount: Math.round(value.act_price * 100),
|
||||||
@@ -295,7 +298,9 @@ function CalculatePartsTotals(jobLines) {
|
|||||||
parts: {
|
parts: {
|
||||||
...acc.parts,
|
...acc.parts,
|
||||||
prt_dsmk_total: acc.parts.prt_dsmk_total.add(
|
prt_dsmk_total: acc.parts.prt_dsmk_total.add(
|
||||||
value.prt_dsmk_m && value.prt_dsmk_m !== 0
|
(value.db_ref === "900511" || value.db_ref === "900510") &&
|
||||||
|
value.prt_dsmk_m &&
|
||||||
|
value.prt_dsmk_m !== 0
|
||||||
? Dinero({ amount: Math.round(value.prt_dsmk_m * 100) })
|
? Dinero({ amount: Math.round(value.prt_dsmk_m * 100) })
|
||||||
: Dinero({
|
: Dinero({
|
||||||
amount: Math.round(value.act_price * 100),
|
amount: Math.round(value.act_price * 100),
|
||||||
@@ -339,7 +344,9 @@ function CalculatePartsTotals(jobLines) {
|
|||||||
}).multiply(value.part_qty || 0)
|
}).multiply(value.part_qty || 0)
|
||||||
)
|
)
|
||||||
.add(
|
.add(
|
||||||
value.prt_dsmk_m && value.prt_dsmk_m !== 0
|
(value.db_ref === "900511" || value.db_ref === "900510") &&
|
||||||
|
value.prt_dsmk_m &&
|
||||||
|
value.prt_dsmk_m !== 0
|
||||||
? Dinero({ amount: Math.round(value.prt_dsmk_m * 100) })
|
? Dinero({ amount: Math.round(value.prt_dsmk_m * 100) })
|
||||||
: Dinero({
|
: Dinero({
|
||||||
amount: Math.round(value.act_price * 100),
|
amount: Math.round(value.act_price * 100),
|
||||||
|
|||||||
Reference in New Issue
Block a user