IO-256 Export payments with no matching invoice & export cust data.

This commit is contained in:
Patrick Fic
2021-10-14 15:07:31 -07:00
parent 1d210a9e52
commit 161d476ab3
4 changed files with 2588 additions and 55 deletions

View File

@@ -21,47 +21,61 @@ export function JobsDetailHeaderActionexportCustomerData({
const handleExportCustData = async (e) => { const handleExportCustData = async (e) => {
logImEXEvent("job_export_cust_data"); logImEXEvent("job_export_cust_data");
let QbXmlResponse;
try {
QbXmlResponse = await axios.post(
"/accounting/qbxml/receivables",
{ jobIds: [job.id], custDataOnly: true },
{
headers: {
Authorization: `Bearer ${await auth.currentUser.getIdToken()}`,
},
}
);
console.log("handle -> XML", QbXmlResponse);
} catch (error) {
console.log("Error getting QBXML from Server.", error);
notification["error"]({
message: t("jobs.errors.exporting", {
error: "Unable to retrieve QBXML. " + JSON.stringify(error.message),
}),
});
return;
}
let PartnerResponse; let PartnerResponse;
try { if (bodyshop.accountingconfig && bodyshop.accountingconfig.qbo) {
PartnerResponse = await axios.post( PartnerResponse = await axios.post(
"http://localhost:1337/qb/", `/qbo/receivables`,
QbXmlResponse.data,
{ {
headers: { jobIds: [job.id],
Authorization: `Bearer ${await auth.currentUser.getIdToken()}`, custDataOnly: true,
}, },
} { withCredentials: true }
); );
} catch (error) { } else {
console.log("Error connecting to quickbooks or partner.", error); //Default is QBD
notification["error"]({
message: t("jobs.errors.exporting-partner"),
});
return; let QbXmlResponse;
try {
QbXmlResponse = await axios.post(
"/accounting/qbxml/receivables",
{ jobIds: [job.id], custDataOnly: true },
{
headers: {
Authorization: `Bearer ${await auth.currentUser.getIdToken()}`,
},
}
);
console.log("handle -> XML", QbXmlResponse);
} catch (error) {
console.log("Error getting QBXML from Server.", error);
notification["error"]({
message: t("jobs.errors.exporting", {
error: "Unable to retrieve QBXML. " + JSON.stringify(error.message),
}),
});
return;
}
//let PartnerResponse;
try {
PartnerResponse = await axios.post(
"http://localhost:1337/qb/",
QbXmlResponse.data,
{
headers: {
Authorization: `Bearer ${await auth.currentUser.getIdToken()}`,
},
}
);
} catch (error) {
console.log("Error connecting to quickbooks or partner.", error);
notification["error"]({
message: t("jobs.errors.exporting-partner"),
});
return;
}
} }
//Check to see if any of them failed. If they didn't don't execute the update. //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 failedTransactions = PartnerResponse.data.filter((r) => !r.success);

File diff suppressed because it is too large Load Diff

View File

@@ -75,7 +75,7 @@ exports.default = async (req, res) => {
//Replace this with a for-each loop to check every single Job that's included in the list. //Replace this with a for-each loop to check every single Job that's included in the list.
let insCoCustomerTier, ownerCustomerTier, jobTier; let insCoCustomerTier, ownerCustomerTier, jobTier;
if (isThreeTier || twoTierPref === "source") { if (isThreeTier || (!isThreeTier && twoTierPref === "source")) {
//Insert the insurance company tier. //Insert the insurance company tier.
//Query for top level customer, the insurance company name. //Query for top level customer, the insurance company name.
insCoCustomerTier = await QueryInsuranceCo( insCoCustomerTier = await QueryInsuranceCo(
@@ -94,7 +94,7 @@ exports.default = async (req, res) => {
} }
} }
if (isThreeTier || twoTierPref === "name") { if (isThreeTier || (!isThreeTier && twoTierPref === "name")) {
//Insert the name/owner and account for whether the source should be the ins co in 3 tier.. //Insert the name/owner and account for whether the source should be the ins co in 3 tier..
ownerCustomerTier = await QueryOwner(oauthClient, req, payment.job); ownerCustomerTier = await QueryOwner(oauthClient, req, payment.job);
//Query for the owner itself. //Query for the owner itself.
@@ -119,8 +119,7 @@ exports.default = async (req, res) => {
oauthClient, oauthClient,
req, req,
payment.job, payment.job,
isThreeTier, ownerCustomerTier || insCoCustomerTier
ownerCustomerTier
); );
} }
@@ -158,7 +157,7 @@ async function InsertPayment(oauthClient, req, payment, parentRef) {
payment.job.ro_number payment.job.ro_number
); );
if (invoices.length !== 1) { if (invoices && invoices.length !== 1) {
throw new Error( throw new Error(
`More than 1 invoice with DocNumber ${payment.ro_number} found.` `More than 1 invoice with DocNumber ${payment.ro_number} found.`
); );
@@ -177,19 +176,23 @@ async function InsertPayment(oauthClient, req, payment, parentRef) {
PaymentMethodRef: { PaymentMethodRef: {
value: paymentMethods[payment.type], value: paymentMethods[payment.type],
}, },
Line: [ ...(invoices && invoices.length === 1
{ ? {
Amount: Dinero({ Line: [
amount: Math.round(payment.amount * 100), {
}).toFormat(DineroQbFormat), Amount: Dinero({
LinkedTxn: [ amount: Math.round(payment.amount * 100),
{ }).toFormat(DineroQbFormat),
TxnId: invoices[0].Id, LinkedTxn: [
TxnType: "Invoice", {
}, TxnId: invoices[0].Id,
], TxnType: "Invoice",
}, },
], ],
},
],
}
: {}),
}; };
logger.log("qbo-payments-objectlog", "DEBUG", req.user.email, payment.id, { logger.log("qbo-payments-objectlog", "DEBUG", req.user.email, payment.id, {
paymentQbo, paymentQbo,

View File

@@ -111,7 +111,9 @@ exports.default = async (req, res) => {
); );
} }
await InsertInvoice(oauthClient, req, job, bodyshop, jobTier); if (!req.body.custDataOnly) {
await InsertInvoice(oauthClient, req, job, bodyshop, jobTier);
}
ret.push({ jobid: job.id, success: true }); ret.push({ jobid: job.id, success: true });
} catch (error) { } catch (error) {
ret.push({ ret.push({