IO-256 Export payments with no matching invoice & export cust data.
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user