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) => {
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;
try {
if (bodyshop.accountingconfig && bodyshop.accountingconfig.qbo) {
PartnerResponse = await axios.post(
"http://localhost:1337/qb/",
QbXmlResponse.data,
`/qbo/receivables`,
{
headers: {
Authorization: `Bearer ${await auth.currentUser.getIdToken()}`,
},
}
jobIds: [job.id],
custDataOnly: true,
},
{ withCredentials: true }
);
} catch (error) {
console.log("Error connecting to quickbooks or partner.", error);
notification["error"]({
message: t("jobs.errors.exporting-partner"),
});
} else {
//Default is QBD
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.
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.
let insCoCustomerTier, ownerCustomerTier, jobTier;
if (isThreeTier || twoTierPref === "source") {
if (isThreeTier || (!isThreeTier && twoTierPref === "source")) {
//Insert the insurance company tier.
//Query for top level customer, the insurance company name.
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..
ownerCustomerTier = await QueryOwner(oauthClient, req, payment.job);
//Query for the owner itself.
@@ -119,8 +119,7 @@ exports.default = async (req, res) => {
oauthClient,
req,
payment.job,
isThreeTier,
ownerCustomerTier
ownerCustomerTier || insCoCustomerTier
);
}
@@ -158,7 +157,7 @@ async function InsertPayment(oauthClient, req, payment, parentRef) {
payment.job.ro_number
);
if (invoices.length !== 1) {
if (invoices && invoices.length !== 1) {
throw new Error(
`More than 1 invoice with DocNumber ${payment.ro_number} found.`
);
@@ -177,19 +176,23 @@ async function InsertPayment(oauthClient, req, payment, parentRef) {
PaymentMethodRef: {
value: paymentMethods[payment.type],
},
Line: [
{
Amount: Dinero({
amount: Math.round(payment.amount * 100),
}).toFormat(DineroQbFormat),
LinkedTxn: [
{
TxnId: invoices[0].Id,
TxnType: "Invoice",
},
],
},
],
...(invoices && invoices.length === 1
? {
Line: [
{
Amount: Dinero({
amount: Math.round(payment.amount * 100),
}).toFormat(DineroQbFormat),
LinkedTxn: [
{
TxnId: invoices[0].Id,
TxnType: "Invoice",
},
],
},
],
}
: {}),
};
logger.log("qbo-payments-objectlog", "DEBUG", req.user.email, payment.id, {
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 });
} catch (error) {
ret.push({