diff --git a/client/src/components/accounting-payables-table/accounting-payables-table.component.jsx b/client/src/components/accounting-payables-table/accounting-payables-table.component.jsx
index ed3a7b24c..71939895e 100644
--- a/client/src/components/accounting-payables-table/accounting-payables-table.component.jsx
+++ b/client/src/components/accounting-payables-table/accounting-payables-table.component.jsx
@@ -28,7 +28,7 @@ export default connect(
mapDispatchToProps
)(AccountingPayablesTableComponent);
-export function AccountingPayablesTableComponent({ bodyshop, loading, bills }) {
+export function AccountingPayablesTableComponent({ bodyshop, loading, bills, refetch }) {
const { t } = useTranslation();
const [selectedBills, setSelectedBills] = useState([]);
const [transInProgress, setTransInProgress] = useState(false);
@@ -149,6 +149,7 @@ export function AccountingPayablesTableComponent({ bodyshop, loading, bills }) {
disabled={transInProgress || !!record.exported}
loadingCallback={setTransInProgress}
setSelectedBills={setSelectedBills}
+ refetch={refetch}
/>
),
@@ -181,6 +182,7 @@ export function AccountingPayablesTableComponent({ bodyshop, loading, bills }) {
disabled={transInProgress || selectedBills.length === 0}
loadingCallback={setTransInProgress}
completedCallback={setSelectedBills}
+ refetch={refetch}
/>
{bodyshop.accountingconfig && bodyshop.accountingconfig.qbo && (
diff --git a/client/src/components/accounting-payments-table/accounting-payments-table.component.jsx b/client/src/components/accounting-payments-table/accounting-payments-table.component.jsx
index 3a8c0c6b4..05e5277dd 100644
--- a/client/src/components/accounting-payments-table/accounting-payments-table.component.jsx
+++ b/client/src/components/accounting-payments-table/accounting-payments-table.component.jsx
@@ -32,6 +32,7 @@ export function AccountingPayablesTableComponent({
bodyshop,
loading,
payments,
+ refetch,
}) {
const { t } = useTranslation();
const [selectedPayments, setSelectedPayments] = useState([]);
@@ -147,6 +148,7 @@ export function AccountingPayablesTableComponent({
disabled={transInProgress || !!record.exportedat}
loadingCallback={setTransInProgress}
setSelectedPayments={setSelectedPayments}
+ refetch={refetch}
/>
),
},
@@ -187,6 +189,7 @@ export function AccountingPayablesTableComponent({
disabled={transInProgress || selectedPayments.length === 0}
loadingCallback={setTransInProgress}
completedCallback={setSelectedPayments}
+ refetch={refetch}
/>
{bodyshop.accountingconfig && bodyshop.accountingconfig.qbo && (
diff --git a/client/src/components/accounting-receivables-table/accounting-receivables-table.component.jsx b/client/src/components/accounting-receivables-table/accounting-receivables-table.component.jsx
index d954448d4..082d42da2 100644
--- a/client/src/components/accounting-receivables-table/accounting-receivables-table.component.jsx
+++ b/client/src/components/accounting-receivables-table/accounting-receivables-table.component.jsx
@@ -31,6 +31,7 @@ export function AccountingReceivablesTableComponent({
bodyshop,
loading,
jobs,
+ refetch,
}) {
const { t } = useTranslation();
const [selectedJobs, setSelectedJobs] = useState([]);
@@ -155,6 +156,7 @@ export function AccountingReceivablesTableComponent({
jobId={record.id}
disabled={!!record.date_exported}
setSelectedJobs={setSelectedJobs}
+ refetch={refetch}
/>
@@ -205,6 +207,7 @@ export function AccountingReceivablesTableComponent({
disabled={transInProgress || selectedJobs.length === 0}
loadingCallback={setTransInProgress}
completedCallback={setSelectedJobs}
+ refetch={refetch}
/>
)}
{bodyshop.accountingconfig && bodyshop.accountingconfig.qbo && (
diff --git a/client/src/components/jobs-close-export-button/jobs-close-export-button.component.jsx b/client/src/components/jobs-close-export-button/jobs-close-export-button.component.jsx
index 8d783557e..f5a59c8c0 100644
--- a/client/src/components/jobs-close-export-button/jobs-close-export-button.component.jsx
+++ b/client/src/components/jobs-close-export-button/jobs-close-export-button.component.jsx
@@ -15,7 +15,6 @@ import { logImEXEvent } from "../../firebase/firebase.utils";
import { INSERT_EXPORT_LOG } from "../../graphql/accounting.queries";
import { useHistory } from "react-router-dom";
-
const mapStateToProps = createStructuredSelector({
bodyshop: selectBodyshop,
currentUser: selectCurrentUser,
@@ -27,6 +26,7 @@ export function JobsCloseExportButton({
jobId,
disabled,
setSelectedJobs,
+ refetch,
}) {
const history = useHistory();
const { t } = useTranslation();
@@ -46,13 +46,9 @@ export function JobsCloseExportButton({
//Check if it's a QBO Setup.
let PartnerResponse;
if (bodyshop.accountingconfig && bodyshop.accountingconfig.qbo) {
- PartnerResponse = await axios.post(
- `/qbo/receivables`,
- {
- jobIds: [jobId],
- },
-
- );
+ PartnerResponse = await axios.post(`/qbo/receivables`, {
+ jobIds: [jobId],
+ });
} else {
//Default is QBD
@@ -117,58 +113,64 @@ export function JobsCloseExportButton({
});
});
- await insertExportLog({
- variables: {
- logs: [
- {
- bodyshopid: bodyshop.id,
- jobid: jobId,
- successful: false,
- message: JSON.stringify(
- failedTransactions.map((ft) => ft.errorMessage)
- ),
- useremail: currentUser.email,
- },
- ],
- },
- });
+ if (!(bodyshop.accountingconfig && bodyshop.accountingconfig.qbo)) {
+ //QBO Logs are handled server side.
+ await insertExportLog({
+ variables: {
+ logs: [
+ {
+ bodyshopid: bodyshop.id,
+ jobid: jobId,
+ successful: false,
+ message: JSON.stringify(
+ failedTransactions.map((ft) => ft.errorMessage)
+ ),
+ useremail: currentUser.email,
+ },
+ ],
+ },
+ });
+ }
} else {
//Insert success export log.
- await insertExportLog({
- variables: {
- logs: [
- {
- bodyshopid: bodyshop.id,
- jobid: jobId,
- successful: true,
- useremail: currentUser.email,
- },
- ],
- },
- });
-
- const jobUpdateResponse = await updateJob({
- variables: {
- jobId: jobId,
- job: {
- status: bodyshop.md_ro_statuses.default_exported || "Exported*",
- date_exported: new Date(),
+ if (!(bodyshop.accountingconfig && bodyshop.accountingconfig.qbo)) {
+ //QBO Logs are handled server side.
+ await insertExportLog({
+ variables: {
+ logs: [
+ {
+ bodyshopid: bodyshop.id,
+ jobid: jobId,
+ successful: true,
+ useremail: currentUser.email,
+ },
+ ],
},
- },
- });
+ });
- if (!jobUpdateResponse.errors) {
- notification.open({
- type: "success",
- key: "jobsuccessexport",
- message: t("jobs.successes.exported"),
- });
- } else {
- notification["error"]({
- message: t("jobs.errors.exporting", {
- error: JSON.stringify(jobUpdateResponse.error),
- }),
+ const jobUpdateResponse = await updateJob({
+ variables: {
+ jobId: jobId,
+ job: {
+ status: bodyshop.md_ro_statuses.default_exported || "Exported*",
+ date_exported: new Date(),
+ },
+ },
});
+
+ if (!jobUpdateResponse.errors) {
+ notification.open({
+ type: "success",
+ key: "jobsuccessexport",
+ message: t("jobs.successes.exported"),
+ });
+ } else {
+ notification["error"]({
+ message: t("jobs.errors.exporting", {
+ error: JSON.stringify(jobUpdateResponse.error),
+ }),
+ });
+ }
}
if (setSelectedJobs) {
setSelectedJobs((selectedJobs) => {
@@ -176,7 +178,7 @@ export function JobsCloseExportButton({
});
}
}
-
+ if (bodyshop.accountingconfig && bodyshop.accountingconfig.qbo) refetch();
setLoading(false);
};
diff --git a/client/src/components/jobs-export-all-button/jobs-export-all-button.component.jsx b/client/src/components/jobs-export-all-button/jobs-export-all-button.component.jsx
index 80aa92f7f..a1c19a020 100644
--- a/client/src/components/jobs-export-all-button/jobs-export-all-button.component.jsx
+++ b/client/src/components/jobs-export-all-button/jobs-export-all-button.component.jsx
@@ -26,6 +26,7 @@ export function JobsExportAllButton({
disabled,
loadingCallback,
completedCallback,
+ refetch,
}) {
const { t } = useTranslation();
const [updateJob] = useMutation(UPDATE_JOBS);
@@ -83,6 +84,7 @@ export function JobsExportAllButton({
return;
}
}
+
console.log("PartnerResponse", PartnerResponse);
const groupedData = _.groupBy(
PartnerResponse.data,
@@ -106,61 +108,70 @@ export function JobsExportAllButton({
});
//Call is not awaited as it is not critical to finish before proceeding.
});
- await insertExportLog({
- variables: {
- logs: [
- {
- bodyshopid: bodyshop.id,
- jobid: key,
- successful: false,
- message: JSON.stringify(
- failedTransactions.map((ft) => ft.errorMessage)
- ),
- useremail: currentUser.email,
- },
- ],
- },
- });
- } else {
- await insertExportLog({
- variables: {
- logs: [
- {
- bodyshopid: bodyshop.id,
- jobid: key,
- successful: true,
- useremail: currentUser.email,
- },
- ],
- },
- });
- const jobUpdateResponse = await updateJob({
- variables: {
- jobIds: [key],
- fields: {
- status: bodyshop.md_ro_statuses.default_exported || "Exported*",
- date_exported: new Date(),
+ if (!(bodyshop.accountingconfig && bodyshop.accountingconfig.qbo)) {
+ //QBO Logs are handled server side.
+ await insertExportLog({
+ variables: {
+ logs: [
+ {
+ bodyshopid: bodyshop.id,
+ jobid: key,
+ successful: false,
+ message: JSON.stringify(
+ failedTransactions.map((ft) => ft.errorMessage)
+ ),
+ useremail: currentUser.email,
+ },
+ ],
},
- },
- });
+ });
+ }
+ } else {
+ if (!(bodyshop.accountingconfig && bodyshop.accountingconfig.qbo)) {
+ //QBO Logs are handled server side.
+ await insertExportLog({
+ variables: {
+ logs: [
+ {
+ bodyshopid: bodyshop.id,
+ jobid: key,
+ successful: true,
+ useremail: currentUser.email,
+ },
+ ],
+ },
+ });
- if (!jobUpdateResponse.errors) {
- notification.open({
- type: "success",
- key: "jobsuccessexport",
- message: t("jobs.successes.exported"),
- });
- } else {
- notification["error"]({
- message: t("jobs.errors.exporting", {
- error: JSON.stringify(jobUpdateResponse.error),
- }),
+ const jobUpdateResponse = await updateJob({
+ variables: {
+ jobIds: [key],
+ fields: {
+ status:
+ bodyshop.md_ro_statuses.default_exported || "Exported*",
+ date_exported: new Date(),
+ },
+ },
});
+
+ if (!jobUpdateResponse.errors) {
+ notification.open({
+ type: "success",
+ key: "jobsuccessexport",
+ message: t("jobs.successes.exported"),
+ });
+ } else {
+ notification["error"]({
+ message: t("jobs.errors.exporting", {
+ error: JSON.stringify(jobUpdateResponse.error),
+ }),
+ });
+ }
}
}
})
);
+ if (bodyshop.accountingconfig && bodyshop.accountingconfig.qbo) refetch();
if (!!completedCallback) completedCallback([]);
if (!!loadingCallback) loadingCallback(false);
diff --git a/client/src/components/payable-export-all-button/payable-export-all-button.component.jsx b/client/src/components/payable-export-all-button/payable-export-all-button.component.jsx
index 0cfe607df..e6b7253e1 100644
--- a/client/src/components/payable-export-all-button/payable-export-all-button.component.jsx
+++ b/client/src/components/payable-export-all-button/payable-export-all-button.component.jsx
@@ -27,6 +27,7 @@ export function PayableExportAll({
disabled,
loadingCallback,
completedCallback,
+ refetch,
}) {
const { t } = useTranslation();
const [updateBill] = useMutation(UPDATE_BILLS);
@@ -104,57 +105,62 @@ export function PayableExportAll({
}),
})
);
-
- await insertExportLog({
- variables: {
- logs: [
- {
- bodyshopid: bodyshop.id,
- billid: key,
- successful: false,
- message: JSON.stringify(
- failedTransactions.map((ft) => ft.errorMessage)
- ),
- useremail: currentUser.email,
- },
- ],
- },
- });
- } else {
- await insertExportLog({
- variables: {
- logs: [
- {
- bodyshopid: bodyshop.id,
- billid: key,
- successful: true,
- useremail: currentUser.email,
- },
- ],
- },
- });
-
- const billUpdateResponse = await updateBill({
- variables: {
- billIdList: [key],
- bill: {
- exported: true,
- exported_at: new Date(),
+ if (!(bodyshop.accountingconfig && bodyshop.accountingconfig.qbo)) {
+ //QBO Logs are handled server side.
+ await insertExportLog({
+ variables: {
+ logs: [
+ {
+ bodyshopid: bodyshop.id,
+ billid: key,
+ successful: false,
+ message: JSON.stringify(
+ failedTransactions.map((ft) => ft.errorMessage)
+ ),
+ useremail: currentUser.email,
+ },
+ ],
},
- },
- });
- if (!!!billUpdateResponse.errors) {
- notification.open({
- type: "success",
- key: "billsuccessexport",
- message: t("bills.successes.exported"),
});
- } else {
- notification["error"]({
- message: t("bills.errors.exporting", {
- error: JSON.stringify(billUpdateResponse.error),
- }),
+ }
+ } else {
+ if (!(bodyshop.accountingconfig && bodyshop.accountingconfig.qbo)) {
+ //QBO Logs are handled server side.
+ await insertExportLog({
+ variables: {
+ logs: [
+ {
+ bodyshopid: bodyshop.id,
+ billid: key,
+ successful: true,
+ useremail: currentUser.email,
+ },
+ ],
+ },
});
+
+ const billUpdateResponse = await updateBill({
+ variables: {
+ billIdList: [key],
+ bill: {
+ exported: true,
+ exported_at: new Date(),
+ },
+ },
+ });
+ if (!!!billUpdateResponse.errors) {
+ notification.open({
+ type: "success",
+ key: "billsuccessexport",
+ message: t("bills.successes.exported"),
+ });
+ } else {
+ notification["error"]({
+ message: t("bills.errors.exporting", {
+ error: JSON.stringify(billUpdateResponse.error),
+ }),
+ });
+ }
}
}
})()
@@ -164,6 +170,8 @@ export function PayableExportAll({
await Promise.all(proms);
if (!!completedCallback) completedCallback([]);
if (!!loadingCallback) loadingCallback(false);
+ if (bodyshop.accountingconfig && bodyshop.accountingconfig.qbo) refetch();
+
setLoading(false);
};
diff --git a/client/src/components/payable-export-button/payable-export-button.component.jsx b/client/src/components/payable-export-button/payable-export-button.component.jsx
index 17a2acedb..a92c3dbd7 100644
--- a/client/src/components/payable-export-button/payable-export-button.component.jsx
+++ b/client/src/components/payable-export-button/payable-export-button.component.jsx
@@ -26,6 +26,7 @@ export function PayableExportButton({
disabled,
loadingCallback,
setSelectedBills,
+ refetch,
}) {
const { t } = useTranslation();
const [updateBill] = useMutation(UPDATE_BILLS);
@@ -100,64 +101,72 @@ export function PayableExportButton({
}),
})
);
- await insertExportLog({
- variables: {
- logs: [
- {
- bodyshopid: bodyshop.id,
- billid: billId,
- successful: false,
- message: JSON.stringify(
- failedTransactions.map((ft) => ft.errorMessage)
- ),
- useremail: currentUser.email,
- },
- ],
- },
- });
- }
- if (successfulTransactions.length > 0) {
- await insertExportLog({
- variables: {
- logs: [
- {
- bodyshopid: bodyshop.id,
- billid: billId,
- successful: true,
- useremail: currentUser.email,
- },
- ],
- },
- });
- const billUpdateResponse = await updateBill({
- variables: {
- billIdList: successfulTransactions.map(
- (st) =>
- st[
- bodyshop.accountingconfig && bodyshop.accountingconfig.qbo
- ? "billid"
- : "id"
- ]
- ),
- bill: {
- exported: true,
- exported_at: new Date(),
+ if (!(bodyshop.accountingconfig && bodyshop.accountingconfig.qbo)) {
+ //QBO Logs are handled server side.
+ await insertExportLog({
+ variables: {
+ logs: [
+ {
+ bodyshopid: bodyshop.id,
+ billid: billId,
+ successful: false,
+ message: JSON.stringify(
+ failedTransactions.map((ft) => ft.errorMessage)
+ ),
+ useremail: currentUser.email,
+ },
+ ],
},
- },
- });
- if (!!!billUpdateResponse.errors) {
- notification.open({
- type: "success",
- key: "billsuccessexport",
- message: t("bills.successes.exported"),
- });
- } else {
- notification["error"]({
- message: t("bills.errors.exporting", {
- error: JSON.stringify(billUpdateResponse.error),
- }),
});
}
+ }
+ if (successfulTransactions.length > 0) {
+ if (!(bodyshop.accountingconfig && bodyshop.accountingconfig.qbo)) {
+ //QBO Logs are handled server side.
+ await insertExportLog({
+ variables: {
+ logs: [
+ {
+ bodyshopid: bodyshop.id,
+ billid: billId,
+ successful: true,
+ useremail: currentUser.email,
+ },
+ ],
+ },
+ });
+ const billUpdateResponse = await updateBill({
+ variables: {
+ billIdList: successfulTransactions.map(
+ (st) =>
+ st[
+ bodyshop.accountingconfig && bodyshop.accountingconfig.qbo
+ ? "billid"
+ : "id"
+ ]
+ ),
+ bill: {
+ exported: true,
+ exported_at: new Date(),
+ },
+ },
+ });
+ if (!!!billUpdateResponse.errors) {
+ notification.open({
+ type: "success",
+ key: "billsuccessexport",
+ message: t("bills.successes.exported"),
+ });
+ } else {
+ notification["error"]({
+ message: t("bills.errors.exporting", {
+ error: JSON.stringify(billUpdateResponse.error),
+ }),
+ });
+ }
+ }
+ if (bodyshop.accountingconfig && bodyshop.accountingconfig.qbo) refetch();
+
if (setSelectedBills) {
setSelectedBills((selectedBills) => {
return selectedBills.filter((i) => i !== billId);
diff --git a/client/src/components/payment-export-button/payment-export-button.component.jsx b/client/src/components/payment-export-button/payment-export-button.component.jsx
index 0d50032c4..0dd2b3c51 100644
--- a/client/src/components/payment-export-button/payment-export-button.component.jsx
+++ b/client/src/components/payment-export-button/payment-export-button.component.jsx
@@ -26,6 +26,7 @@ export function PaymentExportButton({
disabled,
loadingCallback,
setSelectedPayments,
+ refetch,
}) {
const { t } = useTranslation();
const [updatePayment] = useMutation(UPDATE_PAYMENTS);
@@ -100,63 +101,68 @@ export function PaymentExportButton({
}),
})
);
-
- await insertExportLog({
- variables: {
- logs: [
- {
- bodyshopid: bodyshop.id,
- paymentid: paymentId,
- successful: false,
- message: JSON.stringify(
- failedTransactions.map((ft) => ft.errorMessage)
- ),
- useremail: currentUser.email,
- },
- ],
- },
- });
- } else {
- await insertExportLog({
- variables: {
- logs: [
- {
- bodyshopid: bodyshop.id,
- paymentid: paymentId,
- successful: true,
- useremail: currentUser.email,
- },
- ],
- },
- });
-
- const paymentUpdateResponse = await updatePayment({
- variables: {
- paymentIdList: successfulTransactions.map(
- (st) =>
- st[
- bodyshop.accountingconfig && bodyshop.accountingconfig.qbo
- ? "paymentid"
- : "id"
- ]
- ),
- payment: {
- exportedat: new Date(),
+ if (!(bodyshop.accountingconfig && bodyshop.accountingconfig.qbo)) {
+ //QBO Logs are handled server side.
+ await insertExportLog({
+ variables: {
+ logs: [
+ {
+ bodyshopid: bodyshop.id,
+ paymentid: paymentId,
+ successful: false,
+ message: JSON.stringify(
+ failedTransactions.map((ft) => ft.errorMessage)
+ ),
+ useremail: currentUser.email,
+ },
+ ],
},
- },
- });
- if (!!!paymentUpdateResponse.errors) {
- notification.open({
- type: "success",
- key: "paymentsuccessexport",
- message: t("payments.successes.exported"),
});
- } else {
- notification["error"]({
- message: t("payments.errors.exporting", {
- error: JSON.stringify(paymentUpdateResponse.error),
- }),
+ }
+ } else {
+ if (!(bodyshop.accountingconfig && bodyshop.accountingconfig.qbo)) {
+ //QBO Logs are handled server side.
+ await insertExportLog({
+ variables: {
+ logs: [
+ {
+ bodyshopid: bodyshop.id,
+ paymentid: paymentId,
+ successful: true,
+ useremail: currentUser.email,
+ },
+ ],
+ },
});
+
+ const paymentUpdateResponse = await updatePayment({
+ variables: {
+ paymentIdList: successfulTransactions.map(
+ (st) =>
+ st[
+ bodyshop.accountingconfig && bodyshop.accountingconfig.qbo
+ ? "paymentid"
+ : "id"
+ ]
+ ),
+ payment: {
+ exportedat: new Date(),
+ },
+ },
+ });
+ if (!!!paymentUpdateResponse.errors) {
+ notification.open({
+ type: "success",
+ key: "paymentsuccessexport",
+ message: t("payments.successes.exported"),
+ });
+ } else {
+ notification["error"]({
+ message: t("payments.errors.exporting", {
+ error: JSON.stringify(paymentUpdateResponse.error),
+ }),
+ });
+ }
}
if (setSelectedPayments) {
@@ -165,7 +171,7 @@ export function PaymentExportButton({
});
}
}
-
+ if (bodyshop.accountingconfig && bodyshop.accountingconfig.qbo) refetch();
if (!!loadingCallback) loadingCallback(false);
setLoading(false);
};
diff --git a/client/src/components/payments-export-all-button/payments-export-all-button.component.jsx b/client/src/components/payments-export-all-button/payments-export-all-button.component.jsx
index b24536210..7533ac9ec 100644
--- a/client/src/components/payments-export-all-button/payments-export-all-button.component.jsx
+++ b/client/src/components/payments-export-all-button/payments-export-all-button.component.jsx
@@ -25,6 +25,7 @@ export function PaymentsExportAllButton({
disabled,
loadingCallback,
completedCallback,
+ refetch
}) {
const { t } = useTranslation();
const [updatePayments] = useMutation(UPDATE_PAYMENTS);
@@ -92,54 +93,61 @@ export function PaymentsExportAllButton({
}),
})
);
- await insertExportLog({
- variables: {
- logs: [
- {
- bodyshopid: bodyshop.id,
- paymentid: key,
- successful: false,
- message: JSON.stringify(
- failedTransactions.map((ft) => ft.errorMessage)
- ),
- useremail: currentUser.email,
- },
- ],
- },
- });
- } else {
- await insertExportLog({
- variables: {
- logs: [
- {
- bodyshopid: bodyshop.id,
- paymentid: key,
- successful: true,
- useremail: currentUser.email,
- },
- ],
- },
- });
- const paymentUpdateResponse = await updatePayments({
- variables: {
- paymentIdList: [key],
- payment: {
- exportedat: new Date(),
+ if (!(bodyshop.accountingconfig && bodyshop.accountingconfig.qbo)) {
+ //QBO Logs are handled server side.
+ await insertExportLog({
+ variables: {
+ logs: [
+ {
+ bodyshopid: bodyshop.id,
+ paymentid: key,
+ successful: false,
+ message: JSON.stringify(
+ failedTransactions.map((ft) => ft.errorMessage)
+ ),
+ useremail: currentUser.email,
+ },
+ ],
},
- },
- });
- if (!!!paymentUpdateResponse.errors) {
- notification.open({
- type: "success",
- key: "paymentsuccessexport",
- message: t("payments.successes.exported"),
});
- } else {
- notification["error"]({
- message: t("payments.errors.exporting", {
- error: JSON.stringify(paymentUpdateResponse.error),
- }),
+ }
+ } else {
+ if (!(bodyshop.accountingconfig && bodyshop.accountingconfig.qbo)) {
+ //QBO Logs are handled server side.
+
+ await insertExportLog({
+ variables: {
+ logs: [
+ {
+ bodyshopid: bodyshop.id,
+ paymentid: key,
+ successful: true,
+ useremail: currentUser.email,
+ },
+ ],
+ },
});
+ const paymentUpdateResponse = await updatePayments({
+ variables: {
+ paymentIdList: [key],
+ payment: {
+ exportedat: new Date(),
+ },
+ },
+ });
+ if (!!!paymentUpdateResponse.errors) {
+ notification.open({
+ type: "success",
+ key: "paymentsuccessexport",
+ message: t("payments.successes.exported"),
+ });
+ } else {
+ notification["error"]({
+ message: t("payments.errors.exporting", {
+ error: JSON.stringify(paymentUpdateResponse.error),
+ }),
+ });
+ }
}
}
})()
@@ -148,6 +156,7 @@ export function PaymentsExportAllButton({
await Promise.all(proms);
if (!!completedCallback) completedCallback([]);
if (!!loadingCallback) loadingCallback(false);
+ if (bodyshop.accountingconfig && bodyshop.accountingconfig.qbo) refetch();
setLoading(false);
};
diff --git a/client/src/pages/accounting-payables/accounting-payables.container.jsx b/client/src/pages/accounting-payables/accounting-payables.container.jsx
index b9e2a1a1e..b9e92d875 100644
--- a/client/src/pages/accounting-payables/accounting-payables.container.jsx
+++ b/client/src/pages/accounting-payables/accounting-payables.container.jsx
@@ -45,7 +45,7 @@ export function AccountingPayablesContainer({
checkPartnerStatus(bodyshop, true);
}, [t, setBreadcrumbs, setSelectedHeader, bodyshop]);
- const { loading, error, data } = useQuery(QUERY_BILLS_FOR_EXPORT, {
+ const { loading, error, data, refetch } = useQuery(QUERY_BILLS_FOR_EXPORT, {
fetchPolicy: "network-only",
nextFetchPolicy: "network-only",
});
@@ -73,6 +73,7 @@ export function AccountingPayablesContainer({
diff --git a/client/src/pages/accounting-payments/accounting-payments.container.jsx b/client/src/pages/accounting-payments/accounting-payments.container.jsx
index dadecdd5a..e74194e06 100644
--- a/client/src/pages/accounting-payments/accounting-payments.container.jsx
+++ b/client/src/pages/accounting-payments/accounting-payments.container.jsx
@@ -44,10 +44,13 @@ export function AccountingPaymentsContainer({
checkPartnerStatus(bodyshop, true);
}, [t, setBreadcrumbs, setSelectedHeader, bodyshop]);
- const { loading, error, data } = useQuery(QUERY_PAYMENTS_FOR_EXPORT, {
- fetchPolicy: "network-only",
- nextFetchPolicy: "network-only",
- });
+ const { loading, error, data, refetch } = useQuery(
+ QUERY_PAYMENTS_FOR_EXPORT,
+ {
+ fetchPolicy: "network-only",
+ nextFetchPolicy: "network-only",
+ }
+ );
if (error) return ;
const noPath =
@@ -70,6 +73,7 @@ export function AccountingPaymentsContainer({
diff --git a/client/src/pages/accounting-receivables/accounting-receivables.container.jsx b/client/src/pages/accounting-receivables/accounting-receivables.container.jsx
index 8fec8fce7..485800a00 100644
--- a/client/src/pages/accounting-receivables/accounting-receivables.container.jsx
+++ b/client/src/pages/accounting-receivables/accounting-receivables.container.jsx
@@ -44,7 +44,7 @@ export function AccountingReceivablesContainer({
checkPartnerStatus(bodyshop, true);
}, [t, setBreadcrumbs, setSelectedHeader, bodyshop]);
- const { loading, error, data } = useQuery(QUERY_JOBS_FOR_EXPORT, {
+ const { loading, error, data, refetch } = useQuery(QUERY_JOBS_FOR_EXPORT, {
variables: {
invoicedStatus: bodyshop.md_ro_statuses.default_invoiced || "Invoiced*",
},
@@ -75,6 +75,7 @@ export function AccountingReceivablesContainer({
diff --git a/server/accounting/qbo/qbo-callback.js b/server/accounting/qbo/qbo-callback.js
index b65d98978..422d1a19f 100644
--- a/server/accounting/qbo/qbo-callback.js
+++ b/server/accounting/qbo/qbo-callback.js
@@ -71,7 +71,7 @@ exports.default = async (req, res) => {
exports.refresh = async (oauthClient, req) => {
try {
- logger.log("qbo-token-refresh", "DEBUG", req.user.email, null, null);
+ // logger.log("qbo-token-refresh", "DEBUG", req.user.email, null, null);
const authResponse = await oauthClient.refresh();
await client.request(queries.SET_QBO_AUTH, {
email: req.user.email,
@@ -85,7 +85,7 @@ exports.refresh = async (oauthClient, req) => {
};
exports.setNewRefreshToken = async (email, apiResponse) => {
- logger.log("qbo-token-updated", "DEBUG", email, null, null);
+ //logger.log("qbo-token-updated", "DEBUG", email, null, null);
await client.request(queries.SET_QBO_AUTH, {
email,
diff --git a/server/accounting/qbo/qbo-payables.js b/server/accounting/qbo/qbo-payables.js
index e2eb6be82..6b3bb6000 100644
--- a/server/accounting/qbo/qbo-payables.js
+++ b/server/accounting/qbo/qbo-payables.js
@@ -59,8 +59,9 @@ exports.default = async (req, res) => {
bills: billsToQuery,
});
- const { bills } = result;
+ const { bills, bodyshops } = result;
const ret = [];
+ const bodyshop = bodyshops[0];
for (const bill of bills) {
try {
@@ -86,9 +87,29 @@ exports.default = async (req, res) => {
qbo_realmId,
req,
bill,
- vendorRecord
+ vendorRecord,
+ bodyshop
);
+ // //No error. Mark the job exported & insert export log.
+ 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,
+ },
+ ],
+ });
+
ret.push({ billid: bill.id, success: true });
} catch (error) {
ret.push({
@@ -98,6 +119,24 @@ exports.default = async (req, res) => {
(error && error.authResponse && error.authResponse.body) ||
(error && error.message),
});
+
+ //Add the export log error.
+ const result = await client
+ .setHeaders({ Authorization: BearerToken })
+ .request(queries.INSERT_EXPORT_LOG, {
+ logs: [
+ {
+ bodyshopid: bodyshop.id,
+ billid: bill.id,
+ successful: false,
+ message: JSON.stringify([
+ (error && error.authResponse && error.authResponse.body) ||
+ (error && error.message),
+ ]),
+ useremail: req.user.email,
+ },
+ ],
+ });
}
}
@@ -167,7 +206,7 @@ async function InsertVendorRecord(oauthClient, qbo_realmId, req, bill) {
}
}
-async function InsertBill(oauthClient, qbo_realmId, req, bill, vendor) {
+async function InsertBill(oauthClient, qbo_realmId, req, bill, vendor, bodyshop) {
const { accounts, taxCodes, classes } = await QueryMetaData(
oauthClient,
qbo_realmId,
@@ -179,20 +218,20 @@ async function InsertBill(oauthClient, qbo_realmId, req, bill, vendor) {
il,
accounts,
bill.job.class,
- bill.job.bodyshop.md_responsibility_centers.sales_tax_codes,
+ bodyshop.md_responsibility_centers.sales_tax_codes,
classes,
taxCodes,
- bill.job.bodyshop.md_responsibility_centers.costs
+ bodyshop.md_responsibility_centers.costs
)
);
//QB USA with GST
//This was required for the No. 1 Collision Group.
if (
- bill.job.bodyshop.accountingconfig &&
- bill.job.bodyshop.accountingconfig.qbo &&
- bill.job.bodyshop.accountingconfig.qbo_usa &&
- bill.job.bodyshop.region_config.includes("CA_")
+ bodyshop.accountingconfig &&
+ bodyshop.accountingconfig.qbo &&
+ bodyshop.accountingconfig.qbo_usa &&
+ bodyshop.region_config.includes("CA_")
) {
lines.push({
DetailType: "AccountBasedExpenseLineDetail",
@@ -204,7 +243,7 @@ async function InsertBill(oauthClient, qbo_realmId, req, bill, vendor) {
AccountRef: {
value:
accounts[
- bill.job.bodyshop.md_responsibility_centers.taxes.federal
+ bodyshop.md_responsibility_centers.taxes.federal
.accountdesc
],
},
@@ -239,6 +278,14 @@ async function InsertBill(oauthClient, qbo_realmId, req, bill, vendor) {
}),
DocNumber: bill.invoice_number,
//...(bill.job.class ? { ClassRef: { Id: classes[bill.job.class] } } : {}),
+ ...(!(
+ bodyshop.accountingconfig &&
+ bodyshop.accountingconfig.qbo &&
+ bodyshop.accountingconfig.qbo_usa &&
+ bodyshop.region_config.includes("CA_")
+ )
+ ? { GlobalTaxCalculation: "TaxExcluded" }
+ : {}),
PrivateNote: `RO ${bill.job.ro_number || ""}`,
Line: lines,
diff --git a/server/accounting/qbo/qbo-payments.js b/server/accounting/qbo/qbo-payments.js
index f943b57f3..6dd44e07b 100644
--- a/server/accounting/qbo/qbo-payments.js
+++ b/server/accounting/qbo/qbo-payments.js
@@ -155,6 +155,25 @@ exports.default = async (req, res) => {
bodyshop
);
}
+
+ // //No error. Mark the payment exported & insert export log.
+ const result = await client
+ .setHeaders({ Authorization: BearerToken })
+ .request(queries.QBO_MARK_PAYMENT_EXPORTED, {
+ paymentId: payment.id,
+ payment: {
+ exportedat: moment().tz(bodyshop.timezone),
+ },
+ logs: [
+ {
+ bodyshopid: bodyshop.id,
+ paymentid: payment.id,
+ successful: true,
+ useremail: req.user.email,
+ },
+ ],
+ });
+
ret.push({ paymentid: payment.id, success: true });
} catch (error) {
logger.log("qbo-payment-create-error", "ERROR", req.user.email, {
@@ -162,7 +181,24 @@ exports.default = async (req, res) => {
(error && error.authResponse && error.authResponse.body) ||
(error && error.message),
});
-
+ //Add the export log error.
+ const result = await client
+ .setHeaders({ Authorization: BearerToken })
+ .request(queries.INSERT_EXPORT_LOG, {
+ logs: [
+ {
+ bodyshopid: bodyshop.id,
+ paymentid: payment.id,
+ successful: false,
+ message: JSON.stringify([
+ (error && error.authResponse && error.authResponse.body) ||
+ (error && error.message),
+ ]),
+ useremail: req.user.email,
+ },
+ ],
+ });
+
ret.push({
paymentid: payment.id,
success: false,
diff --git a/server/accounting/qbo/qbo-receivables.js b/server/accounting/qbo/qbo-receivables.js
index ca581b9d2..93276b426 100644
--- a/server/accounting/qbo/qbo-receivables.js
+++ b/server/accounting/qbo/qbo-receivables.js
@@ -139,6 +139,25 @@ exports.default = async (req, res) => {
bodyshop,
jobTier
);
+
+ // //No error. Mark the job exported & insert export log.
+ const result = await client
+ .setHeaders({ Authorization: BearerToken })
+ .request(queries.QBO_MARK_JOB_EXPORTED, {
+ jobId: job.id,
+ job: {
+ status: bodyshop.md_ro_statuses.default_exported || "Exported*",
+ date_exported: moment().tz(bodyshop.timezone),
+ },
+ logs: [
+ {
+ bodyshopid: bodyshop.id,
+ jobid: job.id,
+ successful: true,
+ useremail: req.user.email,
+ },
+ ],
+ });
}
ret.push({ jobid: job.id, success: true });
} catch (error) {
@@ -149,6 +168,23 @@ exports.default = async (req, res) => {
(error && error.authResponse && error.authResponse.body) ||
(error && error.message),
});
+ //Add the export log error.
+ const result = await client
+ .setHeaders({ Authorization: BearerToken })
+ .request(queries.INSERT_EXPORT_LOG, {
+ logs: [
+ {
+ bodyshopid: bodyshop.id,
+ jobid: job.id,
+ successful: false,
+ message: JSON.stringify([
+ (error && error.authResponse && error.authResponse.body) ||
+ (error && error.message),
+ ]),
+ useremail: req.user.email,
+ },
+ ],
+ });
}
}
diff --git a/server/accounting/qbxml/qbxml-payables.js b/server/accounting/qbxml/qbxml-payables.js
index 28e7ba2cd..99e4d37ba 100644
--- a/server/accounting/qbxml/qbxml-payables.js
+++ b/server/accounting/qbxml/qbxml-payables.js
@@ -37,14 +37,15 @@ exports.default = async (req, res) => {
.request(queries.QUERY_BILLS_FOR_PAYABLES_EXPORT, {
bills: billsToQuery,
});
- const { bills } = result;
+ const { bills, bodyshops } = result;
+ const bodyshop = bodyshops[0];
const QbXmlToExecute = [];
bills.map((i) => {
QbXmlToExecute.push({
id: i.id,
okStatusCodes: ["0"],
- qbxml: generateBill(i),
+ qbxml: generateBill(i, bodyshop),
});
});
@@ -62,7 +63,7 @@ exports.default = async (req, res) => {
}
};
-const generateBill = (bill) => {
+const generateBill = (bill, bodyshop) => {
const billQbxmlObj = {
QBXML: {
QBXMLMsgsRq: {
@@ -87,7 +88,7 @@ const generateBill = (bill) => {
ExpenseLineAdd: bill.billlines.map((il) =>
generateBillLine(
il,
- bill.job.bodyshop.md_responsibility_centers,
+ bodyshop.md_responsibility_centers,
bill.job.class
)
),
diff --git a/server/graphql-client/queries.js b/server/graphql-client/queries.js
index 9ff253e93..972651008 100644
--- a/server/graphql-client/queries.js
+++ b/server/graphql-client/queries.js
@@ -217,6 +217,7 @@ query QUERY_JOBS_FOR_RECEIVABLES_EXPORT($ids: [uuid!]!) {
accountingconfig
md_ins_cos
timezone
+ md_ro_statuses
}
}
`;
@@ -408,6 +409,13 @@ query QUERY_JOBS_FOR_PBS_EXPORT($id: uuid!) {
exports.QUERY_BILLS_FOR_PAYABLES_EXPORT = `
query QUERY_BILLS_FOR_PAYABLES_EXPORT($bills: [uuid!]!) {
+ bodyshops(where: {associations: {active: {_eq: true}}}) {
+ id
+ md_responsibility_centers
+ timezone
+ region_config
+ accountingconfig
+ }
bills(where: {id: {_in: $bills}}) {
id
date
@@ -424,12 +432,6 @@ query QUERY_BILLS_FOR_PAYABLES_EXPORT($bills: [uuid!]!) {
ownr_ln
ownr_co_nm
class
- bodyshop{
- md_responsibility_centers
- timezone
- region_config
- accountingconfig
- }
}
billlines{
id
@@ -1482,6 +1484,7 @@ mutation MARK_JOB_EXPORTED($jobId: uuid!, $job: jobs_set_input!, $log: exportlog
}
}
`;
+
exports.INSERT_EXPORT_LOG = `
mutation INSERT_EXPORT_LOG($log: exportlog_insert_input!) {
insert_exportlog_one(object: $log) {
@@ -1534,4 +1537,52 @@ exports.QUERY_JOB_ID_MIXDATA = `query QUERY_JOB_ID_MIXDATA($roNumbers: [String!]
}
}
-`;
\ No newline at end of file
+`;
+
+exports.QBO_MARK_JOB_EXPORTED = `
+mutation QBO_MARK_JOB_EXPORTED($jobId: uuid!, $job: jobs_set_input!, $logs: [exportlog_insert_input!]!) {
+ insert_exportlog(objects: $logs) {
+ affected_rows
+ }
+ update_jobs(where: {id: {_eq: $jobId}}, _set: $job) {
+ returning {
+ id
+
+ }
+ }
+}
+
+`;
+exports.QBO_MARK_BILL_EXPORTED = `
+mutation QBO_MARK_BILL_EXPORTED($billId: uuid!, $bill: bills_set_input!, $logs: [exportlog_insert_input!]!) {
+ insert_exportlog(objects: $logs) {
+ affected_rows
+ }
+ update_bills(where: { id: { _eq: $billId } }, _set: $bill) {
+ returning {
+ id
+ }
+ }
+}
+
+`;
+
+exports.QBO_MARK_PAYMENT_EXPORTED = `
+mutation QBO_MARK_PAYMENT_EXPORTED($paymentId: uuid!, $payment: payments_set_input!, $logs: [exportlog_insert_input!]!) {
+ insert_exportlog(objects: $logs) {
+ affected_rows
+ }
+ update_payments(where: {id: {_eq: $paymentId}}, _set: $payment) {
+ returning {
+ id
+ }
+ }
+}`;
+
+exports.INSERT_EXPORT_LOG = `
+ mutation INSERT_EXPORT_LOG($logs: [exportlog_insert_input!]!) {
+ insert_exportlog(objects: $logs) {
+ affected_rows
+ }
+ }
+`;