WIP Exporting Fixes

This commit is contained in:
Patrick Fic
2021-02-16 17:09:01 -08:00
parent 930d9fe7dc
commit 9533e7c4e0
13 changed files with 174 additions and 126 deletions

View File

@@ -152,7 +152,7 @@ export default function AccountingPayablesTableComponent({ loading, bills }) {
return (
<div className="imex-table-header">
<PayableExportAll
billIds={selectedBills}
billids={selectedBills}
disabled={transInProgress || selectedBills.length === 0}
loadingCallback={setTransInProgress}
completedCallback={setSelectedBills}

View File

@@ -1,6 +1,7 @@
import { useMutation } from "@apollo/react-hooks";
import { Button, notification } from "antd";
import axios from "axios";
import _ from "lodash";
import React, { useState } from "react";
import { useTranslation } from "react-i18next";
import { connect } from "react-redux";
@@ -71,45 +72,50 @@ export function JobsExportAllButton({
}
console.log("PartnerResponse", PartnerResponse);
const groupedData = _.groupBy(PartnerResponse.data, "id");
const proms = [];
//Check to see if any of them failed. If they didn't don't execute the update.
const failedTransactions = PartnerResponse.data.filter((r) => !r.success);
const successfulTransactions = PartnerResponse.data.filter(
(r) => r.success
);
if (failedTransactions.length > 0) {
//Uh oh. At least one was no good.
failedTransactions.map((ft) =>
notification["error"]({
message: t("jobs.errors.exporting", {
error: ft.errorMessage || "",
}),
})
);
}
if (successfulTransactions.length > 0) {
const jobUpdateResponse = await updateJob({
variables: {
jobIds: successfulTransactions.map((st) => st.id),
job: {
status: bodyshop.md_ro_statuses.default_exported || "Exported*",
date_exported: new Date(),
},
},
Object.keys(groupedData).forEach((key) => {
proms.push(async () => {
//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"]({
message: t("jobs.errors.exporting", {
error: ft.errorMessage || "",
}),
})
);
} else {
const jobUpdateResponse = await updateJob({
variables: {
jobIds: [key],
job: {
status: bodyshop.md_ro_statuses.default_exported || "Exported*",
date_exported: new Date(),
},
},
});
if (!!!jobUpdateResponse.errors) {
notification["success"]({
message: t("jobs.successes.exported"),
});
} else {
notification["error"]({
message: t("jobs.errors.exporting", {
error: JSON.stringify(jobUpdateResponse.error),
}),
});
}
}
});
});
await Promise.all(proms);
if (!!!jobUpdateResponse.errors) {
notification["success"]({
message: t("jobs.successes.exported"),
});
} else {
notification["error"]({
message: t("jobs.errors.exporting", {
error: JSON.stringify(jobUpdateResponse.error),
}),
});
}
}
if (!!completedCallback) completedCallback([]);
if (!!loadingCallback) loadingCallback(false);
setLoading(false);

View File

@@ -5,10 +5,9 @@ import React, { useState } from "react";
import { useTranslation } from "react-i18next";
import { connect } from "react-redux";
import { createStructuredSelector } from "reselect";
import { auth } from "../../firebase/firebase.utils";
import { auth, logImEXEvent } from "../../firebase/firebase.utils";
import { UPDATE_PAYMENTS } from "../../graphql/payments.queries";
import { selectBodyshop } from "../../redux/user/user.selectors";
import { logImEXEvent } from "../../firebase/firebase.utils";
const mapStateToProps = createStructuredSelector({
bodyshop: selectBodyshop,
@@ -74,9 +73,7 @@ export function PaymentExportButton({
console.log("handleQbxml -> PartnerResponse", PartnerResponse);
const failedTransactions = PartnerResponse.data.filter((r) => !r.success);
const successfulTransactions = PartnerResponse.data.filter(
(r) => r.success
);
if (failedTransactions.length > 0) {
//Uh oh. At least one was no good.
failedTransactions.map((ft) =>
@@ -86,11 +83,10 @@ export function PaymentExportButton({
}),
})
);
}
if (successfulTransactions.length > 0) {
} else {
const paymentUpdateResponse = await updatePayment({
variables: {
paymentIdList: successfulTransactions.map((st) => st.id),
paymentIdList: [paymentId],
payment: {
exportedat: new Date(),
},
@@ -98,11 +94,11 @@ export function PaymentExportButton({
});
if (!!!paymentUpdateResponse.errors) {
notification["success"]({
message: t("jobs.successes.exported"),
message: t("payments.successes.exported"),
});
} else {
notification["error"]({
message: t("jobs.errors.exporting", {
message: t("payments.errors.exporting", {
error: JSON.stringify(paymentUpdateResponse.error),
}),
});
@@ -118,7 +114,8 @@ export function PaymentExportButton({
onClick={handleQbxml}
loading={loading}
disabled={disabled}
type='dashed'>
type="dashed"
>
{t("jobs.actions.export")}
</Button>
);

View File

@@ -108,10 +108,14 @@ export function PaymentFormComponent({
>
<Select disabled={disabled}>
<Select.Option value="Visa">Visa</Select.Option>
<Select.Option value="Mastercard">Mastercard</Select.Option>
<Select.Option value="AMEX">AMEX</Select.Option>
<Select.Option value="Master Card">Mastercard</Select.Option>
<Select.Option value="American Express">
American Express
</Select.Option>
<Select.Option value="Discover">Discover</Select.Option>
<Select.Option value="Cash">Cash</Select.Option>
<Select.Option value="Cheque">Cheque</Select.Option>
<Select.Option value="Interac Debit">Interac Debit</Select.Option>
<Select.Option value="EFT">EFT</Select.Option>
</Select>
</Form.Item>

View File

@@ -1,6 +1,7 @@
import { useMutation } from "@apollo/react-hooks";
import { Button, notification } from "antd";
import axios from "axios";
import _ from "lodash";
import React, { useState } from "react";
import { useTranslation } from "react-i18next";
import { connect } from "react-redux";
@@ -67,44 +68,47 @@ export function PaymentsExportAllButton({
return;
}
console.log("handleQbxml -> PartnerResponse", PartnerResponse);
const failedTransactions = PartnerResponse.data.filter((r) => !r.success);
const successfulTransactions = PartnerResponse.data.filter(
(r) => r.success
);
if (failedTransactions.length > 0) {
//Uh oh. At least one was no good.
failedTransactions.map((ft) =>
notification["error"]({
message: t("payments.errors.exporting", {
error: ft.errorMessage || "",
}),
})
);
}
if (successfulTransactions.length > 0) {
const paymentUpdateResponse = await updatePayments({
variables: {
paymentIdList: successfulTransactions.map((st) => st.id),
payment: {
//exported: true,
exportedat: new Date(),
},
},
});
if (!!!paymentUpdateResponse.errors) {
notification["success"]({
message: t("jobs.successes.exported"),
});
} else {
notification["error"]({
message: t("jobs.errors.exporting", {
error: JSON.stringify(paymentUpdateResponse.error),
}),
});
}
}
const groupedData = _.groupBy(PartnerResponse.data, "id");
const proms = [];
Object.keys(groupedData).forEach((key) => {
proms.push(
(async () => {
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"]({
message: t("payments.errors.exporting", {
error: ft.errorMessage || "",
}),
})
);
} else {
const paymentUpdateResponse = await updatePayments({
variables: {
paymentIdList: [key],
payment: {
exportedat: new Date(),
},
},
});
if (!!!paymentUpdateResponse.errors) {
notification["success"]({
message: t("payments.successes.exported"),
});
} else {
notification["error"]({
message: t("payments.errors.exporting", {
error: JSON.stringify(paymentUpdateResponse.error),
}),
});
}
}
})()
);
});
await Promise.all(proms);
if (!!completedCallback) completedCallback([]);
if (!!loadingCallback) loadingCallback(false);
setLoading(false);