IO-710 Export Log page & insert actions on export

This commit is contained in:
Patrick Fic
2021-04-21 14:31:40 -07:00
parent 6d9576b9a4
commit 09e1ab7f83
38 changed files with 653 additions and 180 deletions

View File

@@ -6,7 +6,7 @@ import { logImEXEvent } from "../../firebase/firebase.utils";
import CurrencyFormatter from "../../utils/CurrencyFormatter";
import { alphaSort } from "../../utils/sorters";
import JobExportButton from "../jobs-close-export-button/jobs-close-export-button.component";
import { JobsExportAllButton } from "../jobs-export-all-button/jobs-export-all-button.component";
import JobsExportAllButton from "../jobs-export-all-button/jobs-export-all-button.component";
export default function AccountingReceivablesTableComponent({ loading, jobs }) {
const { t } = useTranslation();

View File

@@ -7,15 +7,24 @@ import { connect } from "react-redux";
import { createStructuredSelector } from "reselect";
import { auth } from "../../firebase/firebase.utils";
import { UPDATE_JOB } from "../../graphql/jobs.queries";
import { selectBodyshop } from "../../redux/user/user.selectors";
import {
selectBodyshop,
selectCurrentUser,
} from "../../redux/user/user.selectors";
import { logImEXEvent } from "../../firebase/firebase.utils";
import { INSERT_EXPORT_LOG } from "../../graphql/accounting.queries";
const mapStateToProps = createStructuredSelector({
bodyshop: selectBodyshop,
currentUser: selectCurrentUser,
});
export function JobsCloseExportButton({ bodyshop, jobId, disabled }) {
export function JobsCloseExportButton({
bodyshop,
currentUser,
jobId,
disabled,
}) {
const { t } = useTranslation();
const [updateJob] = useMutation(UPDATE_JOB);
const [insertExportLog] = useMutation(INSERT_EXPORT_LOG);
@@ -77,35 +86,39 @@ export function JobsCloseExportButton({ bodyshop, jobId, disabled }) {
failedTransactions.forEach((ft) => {
//insert failed export log
notification.open({
key: "failedexports",
// key: "failedexports",
type: "error",
message: t("jobs.errors.exporting", {
error: ft.errorMessage || "",
}),
});
//Call is not awaited as it is not critical to finish before proceeding.
insertExportLog({
variables: {
logs: [
{
bodyshopid: bodyshop.id,
jobid: jobId,
success: false,
message: JSON.stringify(ft.errorMessage),
},
],
},
});
});
} else {
//Insert success export log.
insertExportLog({
await insertExportLog({
variables: {
logs: [
{
bodyshopid: bodyshop.id,
jobid: jobId,
success: true,
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,
},
],
},
@@ -123,7 +136,7 @@ export function JobsCloseExportButton({ bodyshop, jobId, disabled }) {
if (!jobUpdateResponse.errors) {
notification.open({
type: "error",
type: "success",
key: "jobsuccessexport",
message: t("jobs.successes.exported"),
});

View File

@@ -7,15 +7,21 @@ import { useTranslation } from "react-i18next";
import { connect } from "react-redux";
import { createStructuredSelector } from "reselect";
import { auth, logImEXEvent } from "../../firebase/firebase.utils";
import { INSERT_EXPORT_LOG } from "../../graphql/accounting.queries";
import { UPDATE_JOBS } from "../../graphql/jobs.queries";
import { selectBodyshop } from "../../redux/user/user.selectors";
import {
selectBodyshop,
selectCurrentUser,
} from "../../redux/user/user.selectors";
const mapStateToProps = createStructuredSelector({
bodyshop: selectBodyshop,
currentUser: selectCurrentUser,
});
export function JobsExportAllButton({
bodyshop,
currentUser,
jobIds,
disabled,
loadingCallback,
@@ -23,6 +29,8 @@ export function JobsExportAllButton({
}) {
const { t } = useTranslation();
const [updateJob] = useMutation(UPDATE_JOBS);
const [insertExportLog] = useMutation(INSERT_EXPORT_LOG);
const [loading, setLoading] = useState(false);
const handleQbxml = async () => {
logImEXEvent("jobs_export_all");
@@ -73,35 +81,67 @@ export function JobsExportAllButton({
console.log("PartnerResponse", PartnerResponse);
const groupedData = _.groupBy(PartnerResponse.data, "id");
const proms = [];
Object.keys(groupedData).forEach((key) => {
proms.push(async () => {
await Promise.all(
Object.keys(groupedData).map(async (key) => {
//Check to see if any of them failed. If they didn't don't execute the update.
const failedTransactions = groupedData[key].filter((r) => !r.success);
if (failedTransactions.length > 0) {
//Uh oh. At least one was no good.
failedTransactions.map((ft) =>
notification["error"]({
failedTransactions.forEach((ft) => {
notification.open({
// key: "failedexports",
type: "error",
message: t("jobs.errors.exporting", {
error: ft.errorMessage || "",
}),
})
);
});
//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],
job: {
fields: {
status: bodyshop.md_ro_statuses.default_exported || "Exported*",
date_exported: new Date(),
},
},
});
if (!!!jobUpdateResponse.errors) {
notification["success"]({
if (!jobUpdateResponse.errors) {
notification.open({
type: "success",
key: "jobsuccessexport",
message: t("jobs.successes.exported"),
});
} else {
@@ -112,9 +152,8 @@ export function JobsExportAllButton({
});
}
}
});
});
await Promise.all(proms);
})
);
if (!!completedCallback) completedCallback([]);
if (!!loadingCallback) loadingCallback(false);

View File

@@ -7,16 +7,22 @@ import { connect } from "react-redux";
import { createStructuredSelector } from "reselect";
import { auth } from "../../firebase/firebase.utils";
import { UPDATE_BILLS } from "../../graphql/bills.queries";
import { selectBodyshop } from "../../redux/user/user.selectors";
import {
selectBodyshop,
selectCurrentUser,
} from "../../redux/user/user.selectors";
import { logImEXEvent } from "../../firebase/firebase.utils";
import _ from "lodash";
import { INSERT_EXPORT_LOG } from "../../graphql/accounting.queries";
const mapStateToProps = createStructuredSelector({
bodyshop: selectBodyshop,
currentUser: selectCurrentUser,
});
export function PayableExportAll({
bodyshop,
currentUser,
billids,
disabled,
loadingCallback,
@@ -25,6 +31,7 @@ export function PayableExportAll({
const { t } = useTranslation();
const [updateBill] = useMutation(UPDATE_BILLS);
const [loading, setLoading] = useState(false);
const [insertExportLog] = useMutation(INSERT_EXPORT_LOG);
const handleQbxml = async () => {
logImEXEvent("accounting_payables_export_all");
@@ -89,7 +96,36 @@ 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],
@@ -100,7 +136,9 @@ export function PayableExportAll({
},
});
if (!!!billUpdateResponse.errors) {
notification["success"]({
notification.open({
type: "success",
key: "billsuccessexport",
message: t("bills.successes.exported"),
});
} else {

View File

@@ -7,15 +7,21 @@ import { connect } from "react-redux";
import { createStructuredSelector } from "reselect";
import { auth } from "../../firebase/firebase.utils";
import { UPDATE_BILLS } from "../../graphql/bills.queries";
import { selectBodyshop } from "../../redux/user/user.selectors";
import {
selectBodyshop,
selectCurrentUser,
} from "../../redux/user/user.selectors";
import { logImEXEvent } from "../../firebase/firebase.utils";
import { INSERT_EXPORT_LOG } from "../../graphql/accounting.queries";
const mapStateToProps = createStructuredSelector({
bodyshop: selectBodyshop,
currentUser: selectCurrentUser,
});
export function PayableExportButton({
bodyshop,
currentUser,
billId,
disabled,
loadingCallback,
@@ -23,6 +29,7 @@ export function PayableExportButton({
const { t } = useTranslation();
const [updateBill] = useMutation(UPDATE_BILLS);
const [loading, setLoading] = useState(false);
const [insertExportLog] = useMutation(INSERT_EXPORT_LOG);
const handleQbxml = async () => {
logImEXEvent("accounting_export_payable");
@@ -84,8 +91,35 @@ 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.id),
@@ -96,7 +130,9 @@ export function PayableExportButton({
},
});
if (!!!billUpdateResponse.errors) {
notification["success"]({
notification.open({
type: "success",
key: "billsuccessexport",
message: t("bills.successes.exported"),
});
} else {

View File

@@ -6,15 +6,21 @@ import { useTranslation } from "react-i18next";
import { connect } from "react-redux";
import { createStructuredSelector } from "reselect";
import { auth, logImEXEvent } from "../../firebase/firebase.utils";
import { INSERT_EXPORT_LOG } from "../../graphql/accounting.queries";
import { UPDATE_PAYMENTS } from "../../graphql/payments.queries";
import { selectBodyshop } from "../../redux/user/user.selectors";
import {
selectBodyshop,
selectCurrentUser,
} from "../../redux/user/user.selectors";
const mapStateToProps = createStructuredSelector({
bodyshop: selectBodyshop,
currentUser: selectCurrentUser,
});
export function PaymentExportButton({
bodyshop,
currentUser,
paymentId,
disabled,
loadingCallback,
@@ -22,6 +28,7 @@ export function PaymentExportButton({
const { t } = useTranslation();
const [updatePayment] = useMutation(UPDATE_PAYMENTS);
const [loading, setLoading] = useState(false);
const [insertExportLog] = useMutation(INSERT_EXPORT_LOG);
const handleQbxml = async () => {
logImEXEvent("accounting_payment_export");
@@ -83,7 +90,36 @@ 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: [paymentId],
@@ -93,7 +129,9 @@ export function PaymentExportButton({
},
});
if (!!!paymentUpdateResponse.errors) {
notification["success"]({
notification.open({
type: "success",
key: "paymentsuccessexport",
message: t("payments.successes.exported"),
});
} else {

View File

@@ -7,14 +7,20 @@ import { useTranslation } from "react-i18next";
import { connect } from "react-redux";
import { createStructuredSelector } from "reselect";
import { auth } from "../../firebase/firebase.utils";
import { INSERT_EXPORT_LOG } from "../../graphql/accounting.queries";
import { UPDATE_PAYMENTS } from "../../graphql/payments.queries";
import { selectBodyshop } from "../../redux/user/user.selectors";
import {
selectBodyshop,
selectCurrentUser,
} from "../../redux/user/user.selectors";
const mapStateToProps = createStructuredSelector({
bodyshop: selectBodyshop,
currentUser: selectCurrentUser,
});
export function PaymentsExportAllButton({
bodyshop,
currentUser,
paymentIds,
disabled,
loadingCallback,
@@ -23,6 +29,7 @@ export function PaymentsExportAllButton({
const { t } = useTranslation();
const [updatePayments] = useMutation(UPDATE_PAYMENTS);
const [loading, setLoading] = useState(false);
const [insertExportLog] = useMutation(INSERT_EXPORT_LOG);
const handleQbxml = async () => {
setLoading(true);
@@ -84,7 +91,34 @@ 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],
@@ -94,7 +128,9 @@ export function PaymentsExportAllButton({
},
});
if (!!!paymentUpdateResponse.errors) {
notification["success"]({
notification.open({
type: "success",
key: "paymentsuccessexport",
message: t("payments.successes.exported"),
});
} else {