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,6 +21,19 @@ export function JobsDetailHeaderActionexportCustomerData({
const handleExportCustData = async (e) => { const handleExportCustData = async (e) => {
logImEXEvent("job_export_cust_data"); logImEXEvent("job_export_cust_data");
let PartnerResponse;
if (bodyshop.accountingconfig && bodyshop.accountingconfig.qbo) {
PartnerResponse = await axios.post(
`/qbo/receivables`,
{
jobIds: [job.id],
custDataOnly: true,
},
{ withCredentials: true }
);
} else {
//Default is QBD
let QbXmlResponse; let QbXmlResponse;
try { try {
QbXmlResponse = await axios.post( QbXmlResponse = await axios.post(
@@ -44,7 +57,7 @@ export function JobsDetailHeaderActionexportCustomerData({
return; return;
} }
let PartnerResponse; //let PartnerResponse;
try { try {
PartnerResponse = await axios.post( PartnerResponse = await axios.post(
"http://localhost:1337/qb/", "http://localhost:1337/qb/",
@@ -63,6 +76,7 @@ export function JobsDetailHeaderActionexportCustomerData({
return; 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);
if (failedTransactions.length > 0) { if (failedTransactions.length > 0) {

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,6 +176,8 @@ async function InsertPayment(oauthClient, req, payment, parentRef) {
PaymentMethodRef: { PaymentMethodRef: {
value: paymentMethods[payment.type], value: paymentMethods[payment.type],
}, },
...(invoices && invoices.length === 1
? {
Line: [ Line: [
{ {
Amount: Dinero({ Amount: Dinero({
@@ -190,6 +191,8 @@ async function InsertPayment(oauthClient, req, payment, parentRef) {
], ],
}, },
], ],
}
: {}),
}; };
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) => {
); );
} }
if (!req.body.custDataOnly) {
await InsertInvoice(oauthClient, req, job, bodyshop, jobTier); 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({