IO-2054 Add Payments Export
This commit is contained in:
@@ -73,11 +73,19 @@ exports.default = async (req, res) => {
|
||||
|
||||
for (const payment of payments) {
|
||||
try {
|
||||
const isThreeTier = bodyshop.accountingconfig.tiers === 3;
|
||||
const twoTierPref = bodyshop.accountingconfig.twotierpref;
|
||||
let isThreeTier = bodyshop.accountingconfig.tiers === 3;
|
||||
let twoTierPref = bodyshop.accountingconfig.twotierpref;
|
||||
|
||||
//Replace this with a for-each loop to check every single Job that's included in the list.
|
||||
|
||||
//QB Multi AR - If it is in this scenario, overwrite whatever defaults are set since multi AR
|
||||
//will always go Source => RO
|
||||
if (payment.payer !== "Customer") {
|
||||
payment.job.ins_co_nm = payment.payer;
|
||||
twoTierPref = "source";
|
||||
isThreeTier = false;
|
||||
}
|
||||
|
||||
let insCoCustomerTier, ownerCustomerTier, jobTier;
|
||||
if (isThreeTier || (!isThreeTier && twoTierPref === "source")) {
|
||||
//Insert the insurance company tier.
|
||||
@@ -106,7 +114,9 @@ exports.default = async (req, res) => {
|
||||
oauthClient,
|
||||
qbo_realmId,
|
||||
req,
|
||||
payment.job
|
||||
payment.job,
|
||||
isThreeTier,
|
||||
insCoCustomerTier
|
||||
);
|
||||
//Query for the owner itself.
|
||||
if (!ownerCustomerTier) {
|
||||
@@ -122,7 +132,17 @@ exports.default = async (req, res) => {
|
||||
}
|
||||
|
||||
//Query for the Job or Create it.
|
||||
jobTier = await QueryJob(oauthClient, qbo_realmId, req, payment.job);
|
||||
jobTier = await QueryJob(
|
||||
oauthClient,
|
||||
qbo_realmId,
|
||||
req,
|
||||
payment.job,
|
||||
isThreeTier
|
||||
? ownerCustomerTier
|
||||
: twoTierPref === "source"
|
||||
? insCoCustomerTier
|
||||
: ownerCustomerTier
|
||||
);
|
||||
|
||||
// Need to validate that the job tier is associated to the right individual?
|
||||
|
||||
@@ -237,7 +257,8 @@ async function InsertPayment(
|
||||
qbo_realmId,
|
||||
req,
|
||||
payment.job.ro_number,
|
||||
false
|
||||
false,
|
||||
parentRef
|
||||
);
|
||||
|
||||
if (invoices && invoices.length !== 1) {
|
||||
@@ -260,7 +281,7 @@ async function InsertPayment(
|
||||
PaymentMethodRef: {
|
||||
value: paymentMethods[payment.type],
|
||||
},
|
||||
...(invoices && invoices.length === 1
|
||||
...(invoices && invoices.length === 1 && invoices[0]
|
||||
? {
|
||||
Line: [
|
||||
{
|
||||
@@ -305,13 +326,14 @@ async function QueryMetaData(
|
||||
qbo_realmId,
|
||||
req,
|
||||
ro_number,
|
||||
isCreditMemo
|
||||
isCreditMemo,
|
||||
parentTierRef
|
||||
) {
|
||||
const invoice = await oauthClient.makeApiCall({
|
||||
url: urlBuilder(
|
||||
qbo_realmId,
|
||||
"query",
|
||||
`select * From Invoice where DocNumber = '${ro_number}'`
|
||||
`select * From Invoice where DocNumber like '${ro_number}%'`
|
||||
),
|
||||
method: "POST",
|
||||
headers: {
|
||||
@@ -407,7 +429,13 @@ async function QueryMetaData(
|
||||
invoices:
|
||||
invoice.json &&
|
||||
invoice.json.QueryResponse &&
|
||||
invoice.json.QueryResponse.Invoice,
|
||||
(parentTierRef
|
||||
? [
|
||||
invoice.json.QueryResponse.Invoice.find(
|
||||
(x) => x.CustomerRef.value === parentTierRef.Id
|
||||
),
|
||||
]
|
||||
: [invoice.json.QueryResponse.Invoice[0]]),
|
||||
};
|
||||
}
|
||||
async function InsertCreditMemo(
|
||||
@@ -423,7 +451,8 @@ async function InsertCreditMemo(
|
||||
qbo_realmId,
|
||||
req,
|
||||
payment.job.ro_number,
|
||||
true
|
||||
true,
|
||||
parentRef
|
||||
);
|
||||
|
||||
if (invoices && invoices.length !== 1) {
|
||||
|
||||
Reference in New Issue
Block a user