WIP Exporting Fixes
This commit is contained in:
@@ -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
|
||||
@@ -23689,6 +23689,27 @@
|
||||
<folder_node>
|
||||
<name>successes</name>
|
||||
<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>
|
||||
<name>payment</name>
|
||||
<definition_loaded>false</definition_loaded>
|
||||
|
||||
@@ -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}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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>
|
||||
);
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -1439,6 +1439,7 @@
|
||||
"totalpayments": "Total Payments"
|
||||
},
|
||||
"successes": {
|
||||
"exported": "Payment exported successfully.",
|
||||
"payment": "Payment created successfully. ",
|
||||
"stripe": "Credit card transaction charged successfully."
|
||||
}
|
||||
|
||||
@@ -1439,6 +1439,7 @@
|
||||
"totalpayments": ""
|
||||
},
|
||||
"successes": {
|
||||
"exported": "",
|
||||
"payment": "",
|
||||
"stripe": ""
|
||||
}
|
||||
|
||||
@@ -1439,6 +1439,7 @@
|
||||
"totalpayments": ""
|
||||
},
|
||||
"successes": {
|
||||
"exported": "",
|
||||
"payment": "",
|
||||
"stripe": ""
|
||||
}
|
||||
|
||||
@@ -61,7 +61,8 @@ const generateBill = (bill) => {
|
||||
FullName: bill.vendor.name,
|
||||
},
|
||||
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,
|
||||
Memo: `RO ${bill.job.ro_number || ""} OWNER ${
|
||||
bill.job.ownr_fn || ""
|
||||
|
||||
@@ -6,6 +6,7 @@ const Dinero = require("dinero.js");
|
||||
var builder = require("xmlbuilder");
|
||||
const moment = require("moment");
|
||||
const QbXmlUtils = require("./qbxml-utils");
|
||||
const QbxmlReceivables = require("./qbxml-receivables");
|
||||
require("dotenv").config({
|
||||
path: path.resolve(
|
||||
process.cwd(),
|
||||
@@ -31,42 +32,49 @@ exports.default = async (req, res) => {
|
||||
.request(queries.QUERY_PAYMENTS_FOR_EXPORT, {
|
||||
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 = [];
|
||||
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({
|
||||
id: i.id,
|
||||
okStatusCodes: ["0"],
|
||||
|
||||
@@ -29,8 +29,7 @@ exports.default = async (req, res) => {
|
||||
const result = await client
|
||||
.setHeaders({ Authorization: BearerToken })
|
||||
.request(queries.QUERY_JOBS_FOR_RECEIVABLES_EXPORT, { ids: jobIds });
|
||||
const { jobs } = result;
|
||||
const { bodyshops } = result;
|
||||
const { jobs, bodyshops } = result;
|
||||
const QbXmlToExecute = [];
|
||||
|
||||
const bodyshop = bodyshops[0];
|
||||
@@ -119,7 +118,7 @@ const generateSourceCustomerQbxml = (jobs_by_pk, bodyshop) => {
|
||||
|
||||
return customerQbxml_Full;
|
||||
};
|
||||
|
||||
exports.generateSourceCustomerQbxml = generateSourceCustomerQbxml;
|
||||
const generateJobQbxml = (
|
||||
jobs_by_pk,
|
||||
bodyshop,
|
||||
@@ -170,7 +169,7 @@ const generateJobQbxml = (
|
||||
console.log("jobQbxml_Full", jobQbxml_Full);
|
||||
return jobQbxml_Full;
|
||||
};
|
||||
|
||||
exports.generateJobQbxml = generateJobQbxml;
|
||||
const generateInvoiceQbxml = (jobs_by_pk, bodyshop) => {
|
||||
//Build the Invoice XML file.
|
||||
const InvoiceLineAdd = [];
|
||||
|
||||
@@ -146,7 +146,12 @@ query QUERY_BILLS_FOR_PAYABLES_EXPORT($bills: [uuid!]!) {
|
||||
`;
|
||||
|
||||
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}}) {
|
||||
id
|
||||
created_at
|
||||
|
||||
Reference in New Issue
Block a user