Refactored communication with partner app to use custom objects + error handling BOD-83 BOD-138 BOD-139
This commit is contained in:
@@ -11536,6 +11536,27 @@
|
|||||||
</translation>
|
</translation>
|
||||||
</translations>
|
</translations>
|
||||||
</concept_node>
|
</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>
|
</children>
|
||||||
</folder_node>
|
</folder_node>
|
||||||
<folder_node>
|
<folder_node>
|
||||||
@@ -11892,6 +11913,27 @@
|
|||||||
</translation>
|
</translation>
|
||||||
</translations>
|
</translations>
|
||||||
</concept_node>
|
</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>
|
<concept_node>
|
||||||
<name>accounting-receivables</name>
|
<name>accounting-receivables</name>
|
||||||
<definition_loaded>false</definition_loaded>
|
<definition_loaded>false</definition_loaded>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Input, Table } from "antd";
|
import { Input, Table, Button } from "antd";
|
||||||
import React, { useState } from "react";
|
import React, { useState } from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { Link } from "react-router-dom";
|
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,
|
sorter: (a, b) => a.clm_total - b.clm_total,
|
||||||
|
|
||||||
render: (text, record) => (
|
render: (text, record) => (
|
||||||
<div>
|
<div style={{ display: "flex" }}>
|
||||||
<JobExportButton
|
<JobExportButton
|
||||||
jobId={record.id}
|
jobId={record.id}
|
||||||
disabled={!!record.date_exported}
|
disabled={!!record.date_exported}
|
||||||
/>
|
/>
|
||||||
|
<Link to={`/manage/jobs/${record.id}/close`}>
|
||||||
{JSON.stringify(record.date_exported)}
|
<Button>{t("jobs.labels.viewallocations")}</Button>
|
||||||
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -229,6 +229,11 @@ function Header({
|
|||||||
{t("menus.header.accounting-receivables")}
|
{t("menus.header.accounting-receivables")}
|
||||||
</Link>
|
</Link>
|
||||||
</Menu.Item>
|
</Menu.Item>
|
||||||
|
<Menu.Item key="payables">
|
||||||
|
<Link to="/manage/accounting/payables">
|
||||||
|
{t("menus.header.accounting-payables")}
|
||||||
|
</Link>
|
||||||
|
</Menu.Item>
|
||||||
</Menu.SubMenu>
|
</Menu.SubMenu>
|
||||||
|
|
||||||
<Menu.SubMenu title={t("menus.header.shop")}>
|
<Menu.SubMenu title={t("menus.header.shop")}>
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ 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 } 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";
|
import { selectBodyshop } from "../../redux/user/user.selectors";
|
||||||
const mapStateToProps = createStructuredSelector({
|
const mapStateToProps = createStructuredSelector({
|
||||||
bodyshop: selectBodyshop,
|
bodyshop: selectBodyshop,
|
||||||
@@ -19,7 +19,7 @@ export function InvoiceExportButton({
|
|||||||
loadingCallback,
|
loadingCallback,
|
||||||
}) {
|
}) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [updateInvoice] = useMutation(UPDATE_INVOICE);
|
const [updateInvoice] = useMutation(UPDATE_INVOICES);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
||||||
const handleQbxml = async () => {
|
const handleQbxml = async () => {
|
||||||
@@ -51,6 +51,7 @@ export function InvoiceExportButton({
|
|||||||
}
|
}
|
||||||
|
|
||||||
let PartnerResponse;
|
let PartnerResponse;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
PartnerResponse = await axios.post(
|
PartnerResponse = await axios.post(
|
||||||
"http://e9c5a8ed9079.ngrok.io/qb/",
|
"http://e9c5a8ed9079.ngrok.io/qb/",
|
||||||
@@ -66,26 +67,42 @@ export function InvoiceExportButton({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const invoiceUpdateResponse = await updateInvoice({
|
console.log("handleQbxml -> PartnerResponse", PartnerResponse);
|
||||||
variables: {
|
const failedTransactions = PartnerResponse.data.filter((r) => !r.success);
|
||||||
invoiceId: invoiceId,
|
const successfulTransactions = PartnerResponse.data.filter(
|
||||||
invoice: {
|
(r) => r.success
|
||||||
exported: true,
|
);
|
||||||
exported_at: new Date(),
|
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);
|
if (!!loadingCallback) loadingCallback(false);
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ export function JobsCloseExportButton({ bodyshop, jobId, disabled }) {
|
|||||||
let PartnerResponse;
|
let PartnerResponse;
|
||||||
try {
|
try {
|
||||||
PartnerResponse = await axios.post(
|
PartnerResponse = await axios.post(
|
||||||
"http://localhost:1337/qb/",
|
"http://e9c5a8ed9079.ngrok.io/qb/",
|
||||||
QbXmlResponse.data,
|
QbXmlResponse.data,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
@@ -62,26 +62,40 @@ export function JobsCloseExportButton({ bodyshop, jobId, disabled }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
console.log("PartnerResponse", PartnerResponse);
|
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) {
|
//Check to see if any of them failed. If they didn't don't execute the update.
|
||||||
notification["success"]({
|
const failedTransactions = PartnerResponse.data.filter((r) => !r.success);
|
||||||
message: t("jobs.successes.exported"),
|
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 {
|
} else {
|
||||||
notification["error"]({
|
const jobUpdateResponse = await updateJob({
|
||||||
message: t("jobs.errors.exporting", {
|
variables: {
|
||||||
error: JSON.stringify(jobUpdateResponse.error),
|
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);
|
setLoading(false);
|
||||||
|
|||||||
@@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|||||||
@@ -706,7 +706,8 @@
|
|||||||
"suspense": "Suspense",
|
"suspense": "Suspense",
|
||||||
"total_repairs": "Total Repairs",
|
"total_repairs": "Total Repairs",
|
||||||
"totals": "Totals",
|
"totals": "Totals",
|
||||||
"vehicle_info": "Vehicle"
|
"vehicle_info": "Vehicle",
|
||||||
|
"viewallocations": "View Allocations"
|
||||||
},
|
},
|
||||||
"successes": {
|
"successes": {
|
||||||
"addedtoproduction": "Job added to production board.",
|
"addedtoproduction": "Job added to production board.",
|
||||||
@@ -731,6 +732,7 @@
|
|||||||
},
|
},
|
||||||
"header": {
|
"header": {
|
||||||
"accounting": "Accounting",
|
"accounting": "Accounting",
|
||||||
|
"accounting-payables": "Payables",
|
||||||
"accounting-receivables": "Receivables",
|
"accounting-receivables": "Receivables",
|
||||||
"activejobs": "Active Jobs",
|
"activejobs": "Active Jobs",
|
||||||
"alljobs": "All Jobs",
|
"alljobs": "All Jobs",
|
||||||
|
|||||||
@@ -706,7 +706,8 @@
|
|||||||
"suspense": "",
|
"suspense": "",
|
||||||
"total_repairs": "",
|
"total_repairs": "",
|
||||||
"totals": "",
|
"totals": "",
|
||||||
"vehicle_info": "Vehículo"
|
"vehicle_info": "Vehículo",
|
||||||
|
"viewallocations": ""
|
||||||
},
|
},
|
||||||
"successes": {
|
"successes": {
|
||||||
"addedtoproduction": "",
|
"addedtoproduction": "",
|
||||||
@@ -731,6 +732,7 @@
|
|||||||
},
|
},
|
||||||
"header": {
|
"header": {
|
||||||
"accounting": "",
|
"accounting": "",
|
||||||
|
"accounting-payables": "",
|
||||||
"accounting-receivables": "",
|
"accounting-receivables": "",
|
||||||
"activejobs": "Empleos activos",
|
"activejobs": "Empleos activos",
|
||||||
"alljobs": "",
|
"alljobs": "",
|
||||||
|
|||||||
@@ -706,7 +706,8 @@
|
|||||||
"suspense": "",
|
"suspense": "",
|
||||||
"total_repairs": "",
|
"total_repairs": "",
|
||||||
"totals": "",
|
"totals": "",
|
||||||
"vehicle_info": "Véhicule"
|
"vehicle_info": "Véhicule",
|
||||||
|
"viewallocations": ""
|
||||||
},
|
},
|
||||||
"successes": {
|
"successes": {
|
||||||
"addedtoproduction": "",
|
"addedtoproduction": "",
|
||||||
@@ -731,6 +732,7 @@
|
|||||||
},
|
},
|
||||||
"header": {
|
"header": {
|
||||||
"accounting": "",
|
"accounting": "",
|
||||||
|
"accounting-payables": "",
|
||||||
"accounting-receivables": "",
|
"accounting-receivables": "",
|
||||||
"activejobs": "Emplois actifs",
|
"activejobs": "Emplois actifs",
|
||||||
"alljobs": "",
|
"alljobs": "",
|
||||||
|
|||||||
@@ -32,7 +32,11 @@ exports.default = async (req, res) => {
|
|||||||
|
|
||||||
const QbXmlToExecute = [];
|
const QbXmlToExecute = [];
|
||||||
invoices.map((i) => {
|
invoices.map((i) => {
|
||||||
QbXmlToExecute.push(generateBill(i));
|
QbXmlToExecute.push({
|
||||||
|
id: i.id,
|
||||||
|
okStatusCodes: ["0"],
|
||||||
|
qbxml: generateBill(i),
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
//For each invoice.
|
//For each invoice.
|
||||||
|
|||||||
@@ -33,14 +33,30 @@ exports.default = async (req, res) => {
|
|||||||
//Is this a two tier, or 3 tier setup?
|
//Is this a two tier, or 3 tier setup?
|
||||||
const isThreeTier = bodyshop.accountingconfig.tiers === 3;
|
const isThreeTier = bodyshop.accountingconfig.tiers === 3;
|
||||||
if (isThreeTier) {
|
if (isThreeTier) {
|
||||||
QbXmlToExecute.push(
|
QbXmlToExecute.push({
|
||||||
generateSourceCustomerQbxml(jobs_by_pk, bodyshop) // Create the source customer.
|
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.
|
//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);
|
res.status(200).json(QbXmlToExecute);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -196,7 +212,6 @@ const generateInvoiceQbxml = (jobs_by_pk, bodyshop) => {
|
|||||||
FullName: bodyshop.md_responsibility_centers.taxes.federal.accountitem,
|
FullName: bodyshop.md_responsibility_centers.taxes.federal.accountitem,
|
||||||
},
|
},
|
||||||
Desc: bodyshop.md_responsibility_centers.taxes.federal.accountdesc,
|
Desc: bodyshop.md_responsibility_centers.taxes.federal.accountdesc,
|
||||||
//Quantity: 1,
|
|
||||||
Amount: federal_tax.toFormat(DineroQbFormat),
|
Amount: federal_tax.toFormat(DineroQbFormat),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -207,7 +222,6 @@ const generateInvoiceQbxml = (jobs_by_pk, bodyshop) => {
|
|||||||
FullName: bodyshop.md_responsibility_centers.taxes.state.accountitem,
|
FullName: bodyshop.md_responsibility_centers.taxes.state.accountitem,
|
||||||
},
|
},
|
||||||
Desc: bodyshop.md_responsibility_centers.taxes.state.accountdesc,
|
Desc: bodyshop.md_responsibility_centers.taxes.state.accountdesc,
|
||||||
//Quantity: 1,
|
|
||||||
Amount: state_tax.toFormat(DineroQbFormat),
|
Amount: state_tax.toFormat(DineroQbFormat),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -218,7 +232,6 @@ const generateInvoiceQbxml = (jobs_by_pk, bodyshop) => {
|
|||||||
FullName: bodyshop.md_responsibility_centers.taxes.local.accountitem,
|
FullName: bodyshop.md_responsibility_centers.taxes.local.accountitem,
|
||||||
},
|
},
|
||||||
Desc: bodyshop.md_responsibility_centers.taxes.local.accountdesc,
|
Desc: bodyshop.md_responsibility_centers.taxes.local.accountdesc,
|
||||||
//Quantity: 1,
|
|
||||||
Amount: local_tax.toFormat(DineroQbFormat),
|
Amount: local_tax.toFormat(DineroQbFormat),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
5
server/accounting/qbxml/qbxmlObject.json
Normal file
5
server/accounting/qbxml/qbxmlObject.json
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"id": "12345",
|
||||||
|
"okStatusCodes": ["0", "31400"],
|
||||||
|
"qbxml": "the qbxml string"
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user