Refactored communication with partner app to use custom objects + error handling BOD-83 BOD-138 BOD-139

This commit is contained in:
Patrick Fic
2020-06-02 17:46:51 -07:00
parent 6060def9f4
commit 59f21b95b1
12 changed files with 176 additions and 55 deletions

View File

@@ -11536,6 +11536,27 @@
</translation>
</translations>
</concept_node>
<concept_node>
<name>viewallocations</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>
</children>
</folder_node>
<folder_node>
@@ -11892,6 +11913,27 @@
</translation>
</translations>
</concept_node>
<concept_node>
<name>accounting-payables</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>accounting-receivables</name>
<definition_loaded>false</definition_loaded>

View File

@@ -1,4 +1,4 @@
import { Input, Table } from "antd";
import { Input, Table, Button } from "antd";
import React, { useState } from "react";
import { useTranslation } from "react-i18next";
import { Link } from "react-router-dom";
@@ -123,13 +123,14 @@ export default function AccountingReceivablesTableComponent({ loading, jobs }) {
sorter: (a, b) => a.clm_total - b.clm_total,
render: (text, record) => (
<div>
<div style={{ display: "flex" }}>
<JobExportButton
jobId={record.id}
disabled={!!record.date_exported}
/>
{JSON.stringify(record.date_exported)}
<Link to={`/manage/jobs/${record.id}/close`}>
<Button>{t("jobs.labels.viewallocations")}</Button>
</Link>
</div>
),
},

View File

@@ -229,6 +229,11 @@ function Header({
{t("menus.header.accounting-receivables")}
</Link>
</Menu.Item>
<Menu.Item key="payables">
<Link to="/manage/accounting/payables">
{t("menus.header.accounting-payables")}
</Link>
</Menu.Item>
</Menu.SubMenu>
<Menu.SubMenu title={t("menus.header.shop")}>

View File

@@ -6,7 +6,7 @@ import { useTranslation } from "react-i18next";
import { connect } from "react-redux";
import { createStructuredSelector } from "reselect";
import { auth } from "../../firebase/firebase.utils";
import { UPDATE_INVOICE } from "../../graphql/invoices.queries";
import { UPDATE_INVOICES } from "../../graphql/invoices.queries";
import { selectBodyshop } from "../../redux/user/user.selectors";
const mapStateToProps = createStructuredSelector({
bodyshop: selectBodyshop,
@@ -19,7 +19,7 @@ export function InvoiceExportButton({
loadingCallback,
}) {
const { t } = useTranslation();
const [updateInvoice] = useMutation(UPDATE_INVOICE);
const [updateInvoice] = useMutation(UPDATE_INVOICES);
const [loading, setLoading] = useState(false);
const handleQbxml = async () => {
@@ -51,6 +51,7 @@ export function InvoiceExportButton({
}
let PartnerResponse;
try {
PartnerResponse = await axios.post(
"http://e9c5a8ed9079.ngrok.io/qb/",
@@ -66,26 +67,42 @@ export function InvoiceExportButton({
return;
}
const invoiceUpdateResponse = await updateInvoice({
variables: {
invoiceId: invoiceId,
invoice: {
exported: true,
exported_at: new Date(),
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("invoices.errors.exporting", {
error: ft.errorMessage || "",
}),
})
);
}
if (successfulTransactions.length > 0) {
const invoiceUpdateResponse = await updateInvoice({
variables: {
invoiceIdList: successfulTransactions.map((st) => st.id),
invoice: {
exported: true,
exported_at: new Date(),
},
},
},
});
if (!!!invoiceUpdateResponse.errors) {
notification["success"]({
message: t("jobs.successes.exported"),
});
} else {
notification["error"]({
message: t("jobs.errors.exporting", {
error: JSON.stringify(invoiceUpdateResponse.error),
}),
});
if (!!!invoiceUpdateResponse.errors) {
notification["success"]({
message: t("jobs.successes.exported"),
});
} else {
notification["error"]({
message: t("jobs.errors.exporting", {
error: JSON.stringify(invoiceUpdateResponse.error),
}),
});
}
}
if (!!loadingCallback) loadingCallback(false);

View File

@@ -44,7 +44,7 @@ export function JobsCloseExportButton({ bodyshop, jobId, disabled }) {
let PartnerResponse;
try {
PartnerResponse = await axios.post(
"http://localhost:1337/qb/",
"http://e9c5a8ed9079.ngrok.io/qb/",
QbXmlResponse.data,
{
headers: {
@@ -62,26 +62,40 @@ export function JobsCloseExportButton({ bodyshop, jobId, disabled }) {
}
console.log("PartnerResponse", PartnerResponse);
const jobUpdateResponse = await updateJob({
variables: {
jobId: jobId,
job: {
status: bodyshop.md_ro_statuses.default_exported || "Exported*",
date_exported: new Date(),
},
},
});
if (!!!jobUpdateResponse.errors) {
notification["success"]({
message: t("jobs.successes.exported"),
});
//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);
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 {
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["success"]({
message: t("jobs.successes.exported"),
});
} else {
notification["error"]({
message: t("jobs.errors.exporting", {
error: JSON.stringify(jobUpdateResponse.error),
}),
});
}
}
setLoading(false);

View File

@@ -135,3 +135,17 @@ export const UPDATE_INVOICE = gql`
}
}
`;
export const UPDATE_INVOICES = gql`
mutation UPDATE_INVOICES(
$invoiceIdList: [uuid!]!
$invoice: invoices_set_input!
) {
update_invoices(where: { id: { _in: $invoiceIdList } }, _set: $invoice) {
returning {
id
exported
exported_at
}
}
}
`;

View File

@@ -706,7 +706,8 @@
"suspense": "Suspense",
"total_repairs": "Total Repairs",
"totals": "Totals",
"vehicle_info": "Vehicle"
"vehicle_info": "Vehicle",
"viewallocations": "View Allocations"
},
"successes": {
"addedtoproduction": "Job added to production board.",
@@ -731,6 +732,7 @@
},
"header": {
"accounting": "Accounting",
"accounting-payables": "Payables",
"accounting-receivables": "Receivables",
"activejobs": "Active Jobs",
"alljobs": "All Jobs",

View File

@@ -706,7 +706,8 @@
"suspense": "",
"total_repairs": "",
"totals": "",
"vehicle_info": "Vehículo"
"vehicle_info": "Vehículo",
"viewallocations": ""
},
"successes": {
"addedtoproduction": "",
@@ -731,6 +732,7 @@
},
"header": {
"accounting": "",
"accounting-payables": "",
"accounting-receivables": "",
"activejobs": "Empleos activos",
"alljobs": "",

View File

@@ -706,7 +706,8 @@
"suspense": "",
"total_repairs": "",
"totals": "",
"vehicle_info": "Véhicule"
"vehicle_info": "Véhicule",
"viewallocations": ""
},
"successes": {
"addedtoproduction": "",
@@ -731,6 +732,7 @@
},
"header": {
"accounting": "",
"accounting-payables": "",
"accounting-receivables": "",
"activejobs": "Emplois actifs",
"alljobs": "",

View File

@@ -32,7 +32,11 @@ exports.default = async (req, res) => {
const QbXmlToExecute = [];
invoices.map((i) => {
QbXmlToExecute.push(generateBill(i));
QbXmlToExecute.push({
id: i.id,
okStatusCodes: ["0"],
qbxml: generateBill(i),
});
});
//For each invoice.

View File

@@ -33,14 +33,30 @@ exports.default = async (req, res) => {
//Is this a two tier, or 3 tier setup?
const isThreeTier = bodyshop.accountingconfig.tiers === 3;
if (isThreeTier) {
QbXmlToExecute.push(
generateSourceCustomerQbxml(jobs_by_pk, bodyshop) // Create the source customer.
);
QbXmlToExecute.push({
id: jobId,
okStatusCodes: ["0", "3100"],
qbxml: generateSourceCustomerQbxml(jobs_by_pk, bodyshop), // Create the source customer.
});
}
QbXmlToExecute.push(generateJobQbxml(jobs_by_pk, bodyshop, isThreeTier, 2));
QbXmlToExecute.push(generateJobQbxml(jobs_by_pk, bodyshop, isThreeTier, 3));
QbXmlToExecute.push({
id: jobId,
okStatusCodes: ["0", "3100"],
qbxml: generateJobQbxml(jobs_by_pk, bodyshop, isThreeTier, 2),
});
QbXmlToExecute.push({
id: jobId,
okStatusCodes: ["0", "3100"],
qbxml: generateJobQbxml(jobs_by_pk, bodyshop, isThreeTier, 3),
});
//Generate the actual invoice.
QbXmlToExecute.push(generateInvoiceQbxml(jobs_by_pk, bodyshop));
QbXmlToExecute.push({
id: jobId,
okStatusCodes: ["0"],
qbxml: generateInvoiceQbxml(jobs_by_pk, bodyshop),
});
res.status(200).json(QbXmlToExecute);
} catch (error) {
@@ -196,7 +212,6 @@ const generateInvoiceQbxml = (jobs_by_pk, bodyshop) => {
FullName: bodyshop.md_responsibility_centers.taxes.federal.accountitem,
},
Desc: bodyshop.md_responsibility_centers.taxes.federal.accountdesc,
//Quantity: 1,
Amount: federal_tax.toFormat(DineroQbFormat),
});
}
@@ -207,7 +222,6 @@ const generateInvoiceQbxml = (jobs_by_pk, bodyshop) => {
FullName: bodyshop.md_responsibility_centers.taxes.state.accountitem,
},
Desc: bodyshop.md_responsibility_centers.taxes.state.accountdesc,
//Quantity: 1,
Amount: state_tax.toFormat(DineroQbFormat),
});
}
@@ -218,7 +232,6 @@ const generateInvoiceQbxml = (jobs_by_pk, bodyshop) => {
FullName: bodyshop.md_responsibility_centers.taxes.local.accountitem,
},
Desc: bodyshop.md_responsibility_centers.taxes.local.accountdesc,
//Quantity: 1,
Amount: local_tax.toFormat(DineroQbFormat),
});
}

View File

@@ -0,0 +1,5 @@
{
"id": "12345",
"okStatusCodes": ["0", "31400"],
"qbxml": "the qbxml string"
}