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

@@ -1,4 +1,4 @@
<babeledit_project version="1.2" be_version="2.7.1"> <babeledit_project be_version="2.7.1" version="1.2">
<!-- <!--
BabelEdit project file BabelEdit project file
@@ -23689,6 +23689,27 @@
<folder_node> <folder_node>
<name>successes</name> <name>successes</name>
<children> <children>
<concept_node>
<name>exported</name>
<definition_loaded>false</definition_loaded>
<description></description>
<comment></comment>
<default_text></default_text>
<translations>
<translation>
<language>en-US</language>
<approved>false</approved>
</translation>
<translation>
<language>es-MX</language>
<approved>false</approved>
</translation>
<translation>
<language>fr-CA</language>
<approved>false</approved>
</translation>
</translations>
</concept_node>
<concept_node> <concept_node>
<name>payment</name> <name>payment</name>
<definition_loaded>false</definition_loaded> <definition_loaded>false</definition_loaded>

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,6 +1,7 @@
import { useMutation } from "@apollo/react-hooks"; import { useMutation } from "@apollo/react-hooks";
import { Button, notification } from "antd"; import { Button, notification } from "antd";
import axios from "axios"; import axios from "axios";
import _ from "lodash";
import React, { useState } from "react"; import React, { useState } from "react";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { connect } from "react-redux"; import { connect } from "react-redux";
@@ -67,44 +68,47 @@ export function PaymentsExportAllButton({
return; return;
} }
console.log("handleQbxml -> PartnerResponse", PartnerResponse); const groupedData = _.groupBy(PartnerResponse.data, "id");
const failedTransactions = PartnerResponse.data.filter((r) => !r.success); const proms = [];
const successfulTransactions = PartnerResponse.data.filter( Object.keys(groupedData).forEach((key) => {
(r) => r.success proms.push(
); (async () => {
if (failedTransactions.length > 0) { const failedTransactions = groupedData[key].filter((r) => !r.success);
//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),
}),
});
}
}
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 (!!completedCallback) completedCallback([]);
if (!!loadingCallback) loadingCallback(false); if (!!loadingCallback) loadingCallback(false);
setLoading(false); setLoading(false);

View File

@@ -1439,6 +1439,7 @@
"totalpayments": "Total Payments" "totalpayments": "Total Payments"
}, },
"successes": { "successes": {
"exported": "Payment exported successfully.",
"payment": "Payment created successfully. ", "payment": "Payment created successfully. ",
"stripe": "Credit card transaction charged successfully." "stripe": "Credit card transaction charged successfully."
} }

View File

@@ -1439,6 +1439,7 @@
"totalpayments": "" "totalpayments": ""
}, },
"successes": { "successes": {
"exported": "",
"payment": "", "payment": "",
"stripe": "" "stripe": ""
} }

View File

@@ -1439,6 +1439,7 @@
"totalpayments": "" "totalpayments": ""
}, },
"successes": { "successes": {
"exported": "",
"payment": "", "payment": "",
"stripe": "" "stripe": ""
} }

View File

@@ -61,7 +61,8 @@ const generateBill = (bill) => {
FullName: bill.vendor.name, FullName: bill.vendor.name,
}, },
TxnDate: moment(bill.date).format("YYYY-MM-DD"), TxnDate: moment(bill.date).format("YYYY-MM-DD"),
DueDate: moment(bill.due_date).format("YYYY-MM-DD"), DueDate:
bill.due_date && moment(bill.due_date).format("YYYY-MM-DD"),
RefNumber: bill.bill_number, RefNumber: bill.bill_number,
Memo: `RO ${bill.job.ro_number || ""} OWNER ${ Memo: `RO ${bill.job.ro_number || ""} OWNER ${
bill.job.ownr_fn || "" bill.job.ownr_fn || ""

View File

@@ -6,6 +6,7 @@ const Dinero = require("dinero.js");
var builder = require("xmlbuilder"); var builder = require("xmlbuilder");
const moment = require("moment"); const moment = require("moment");
const QbXmlUtils = require("./qbxml-utils"); const QbXmlUtils = require("./qbxml-utils");
const QbxmlReceivables = require("./qbxml-receivables");
require("dotenv").config({ require("dotenv").config({
path: path.resolve( path: path.resolve(
process.cwd(), process.cwd(),
@@ -31,42 +32,49 @@ exports.default = async (req, res) => {
.request(queries.QUERY_PAYMENTS_FOR_EXPORT, { .request(queries.QUERY_PAYMENTS_FOR_EXPORT, {
payments: paymentsToQuery, payments: paymentsToQuery,
}); });
const { payments } = result; const { payments, bodyshops } = result;
const bodyshop = bodyshops[0];
const isThreeTier = bodyshop.accountingconfig.tiers === 3;
const twoTierPref = bodyshop.accountingconfig.twotierpref;
if (isThreeTier) {
QbXmlToExecute.push({
id: jobs_by_pk.id,
okStatusCodes: ["0", "3100"],
qbxml: generateSourceCustomerQbxml(jobs_by_pk, bodyshop), // Create the source customer.
});
}
QbXmlToExecute.push({
id: jobs_by_pk.id,
okStatusCodes: ["0", "3100"],
qbxml: generateJobQbxml(
jobs_by_pk,
bodyshop,
isThreeTier,
2,
twoTierPref
),
});
QbXmlToExecute.push({
id: jobs_by_pk.id,
okStatusCodes: ["0", "3100"],
qbxml: generateJobQbxml(
jobs_by_pk,
bodyshop,
isThreeTier,
3,
twoTierPref
),
});
const QbXmlToExecute = []; const QbXmlToExecute = [];
payments.map((i) => { payments.map((i) => {
if (isThreeTier) {
QbXmlToExecute.push({
id: i.id,
okStatusCodes: ["0", "3100"],
qbxml: QbxmlReceivables.generateSourceCustomerQbxml(i.job, bodyshop), // Create the source customer.
});
}
QbXmlToExecute.push({
id: i.id,
okStatusCodes: ["0", "3100"],
qbxml: QbxmlReceivables.generateJobQbxml(
i.job,
bodyshop,
isThreeTier,
2,
twoTierPref
),
});
QbXmlToExecute.push({
id: i.id,
okStatusCodes: ["0", "3100"],
qbxml: QbxmlReceivables.generateJobQbxml(
i.job,
bodyshop,
isThreeTier,
3,
twoTierPref
),
});
QbXmlToExecute.push({ QbXmlToExecute.push({
id: i.id, id: i.id,
okStatusCodes: ["0"], okStatusCodes: ["0"],

View File

@@ -29,8 +29,7 @@ exports.default = async (req, res) => {
const result = await client const result = await client
.setHeaders({ Authorization: BearerToken }) .setHeaders({ Authorization: BearerToken })
.request(queries.QUERY_JOBS_FOR_RECEIVABLES_EXPORT, { ids: jobIds }); .request(queries.QUERY_JOBS_FOR_RECEIVABLES_EXPORT, { ids: jobIds });
const { jobs } = result; const { jobs, bodyshops } = result;
const { bodyshops } = result;
const QbXmlToExecute = []; const QbXmlToExecute = [];
const bodyshop = bodyshops[0]; const bodyshop = bodyshops[0];
@@ -119,7 +118,7 @@ const generateSourceCustomerQbxml = (jobs_by_pk, bodyshop) => {
return customerQbxml_Full; return customerQbxml_Full;
}; };
exports.generateSourceCustomerQbxml = generateSourceCustomerQbxml;
const generateJobQbxml = ( const generateJobQbxml = (
jobs_by_pk, jobs_by_pk,
bodyshop, bodyshop,
@@ -170,7 +169,7 @@ const generateJobQbxml = (
console.log("jobQbxml_Full", jobQbxml_Full); console.log("jobQbxml_Full", jobQbxml_Full);
return jobQbxml_Full; return jobQbxml_Full;
}; };
exports.generateJobQbxml = generateJobQbxml;
const generateInvoiceQbxml = (jobs_by_pk, bodyshop) => { const generateInvoiceQbxml = (jobs_by_pk, bodyshop) => {
//Build the Invoice XML file. //Build the Invoice XML file.
const InvoiceLineAdd = []; const InvoiceLineAdd = [];

View File

@@ -146,7 +146,12 @@ query QUERY_BILLS_FOR_PAYABLES_EXPORT($bills: [uuid!]!) {
`; `;
exports.QUERY_PAYMENTS_FOR_EXPORT = ` exports.QUERY_PAYMENTS_FOR_EXPORT = `
query QUERY_PAYMENTS_FOR_EXPORT($payments: [uuid!]!) { query QUERY_PAYMENTS_FOR_EXPORT($payments: [uuid!]!)
{ bodyshops(where: {associations: {active: {_eq: true}}}) {
id
md_responsibility_centers
accountingconfig
}
payments(where: {id: {_in: $payments}}) { payments(where: {id: {_in: $payments}}) {
id id
created_at created_at