Successful 2tier and 3 tier export of invoices. BOD-83 BOD-131
This commit is contained in:
@@ -31,17 +31,16 @@ exports.default = async (req, res) => {
|
||||
|
||||
//Is this a two tier, or 3 tier setup?
|
||||
const isThreeTier = bodyshop.accountingconfig.tiers === 3;
|
||||
|
||||
QbXmlToExecute.push(
|
||||
generateCustomerQbxml(jobs_by_pk, bodyshop, isThreeTier)
|
||||
);
|
||||
|
||||
if (isThreeTier) {
|
||||
QbXmlToExecute.push(generateJobQbxml(jobs_by_pk, bodyshop, 2));
|
||||
QbXmlToExecute.push(generateJobQbxml(jobs_by_pk, bodyshop, 3));
|
||||
QbXmlToExecute.push(
|
||||
generateSourceCustomerQbxml(jobs_by_pk, bodyshop) // Create the source customer.
|
||||
);
|
||||
}
|
||||
QbXmlToExecute.push(generateJobQbxml(jobs_by_pk, bodyshop, isThreeTier, 2));
|
||||
QbXmlToExecute.push(generateJobQbxml(jobs_by_pk, bodyshop, isThreeTier, 3));
|
||||
//Generate the actual invoice.
|
||||
QbXmlToExecute.push(generateInvoiceQbxml(jobs_by_pk, bodyshop));
|
||||
|
||||
console.log(QbXmlToExecute);
|
||||
res.status(200).json(QbXmlToExecute);
|
||||
} catch (error) {
|
||||
console.log("error", error);
|
||||
@@ -49,31 +48,21 @@ exports.default = async (req, res) => {
|
||||
}
|
||||
};
|
||||
|
||||
const generateCustomerQbxml = (jobs_by_pk, bodyshop, isThreeTier) => {
|
||||
const generateSourceCustomerQbxml = (jobs_by_pk, bodyshop) => {
|
||||
const customerQbxmlObj = {
|
||||
QBXML: {
|
||||
QBXMLMsgsRq: {
|
||||
"@onError": "continueOnError",
|
||||
CustomerAddRq: {
|
||||
CustomerAdd: {
|
||||
Name: isThreeTier
|
||||
? jobs_by_pk.ins_co_nm
|
||||
: jobs_by_pk.ownr_co_nm
|
||||
? `${jobs_by_pk.ownr_co_nm} - ${jobs_by_pk.ownr_ln || ""} ${
|
||||
jobs_by_pk.ownr_fn || ""
|
||||
} #${jobs_by_pk.owner.accountingid || ""}`
|
||||
: `${jobs_by_pk.ownr_ln || ""} ${jobs_by_pk.ownr_fn || ""} #${
|
||||
jobs_by_pk.owner.accountingid || ""
|
||||
}`,
|
||||
BillAddress: isThreeTier
|
||||
? null
|
||||
: {
|
||||
Addr1: jobs_by_pk.ownr_addr1,
|
||||
Addr2: jobs_by_pk.ownr_addr2,
|
||||
City: jobs_by_pk.ownr_city,
|
||||
State: jobs_by_pk.ownr_st,
|
||||
PostalCode: jobs_by_pk.ownrzip,
|
||||
},
|
||||
Name: jobs_by_pk.ins_co_nm,
|
||||
BillAddress: {
|
||||
Addr1: jobs_by_pk.ownr_addr1,
|
||||
Addr2: jobs_by_pk.ownr_addr2,
|
||||
City: jobs_by_pk.ownr_city,
|
||||
State: jobs_by_pk.ownr_st,
|
||||
PostalCode: jobs_by_pk.ownrzip,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -93,15 +82,35 @@ const generateCustomerQbxml = (jobs_by_pk, bodyshop, isThreeTier) => {
|
||||
return customerQbxml_Full;
|
||||
};
|
||||
|
||||
const generateJobQbxml = (jobs_by_pk, bodyshop, isThreeTier, tierLevel) => {
|
||||
const tier1Name = jobs_by_pk.ownr_co_nm;
|
||||
const tier2Name = jobs_by_pk.ownr_co_nm
|
||||
const generateSourceTier = (jobs_by_pk) => {
|
||||
return jobs_by_pk.ins_co_nm;
|
||||
};
|
||||
const generateJobTier = (jobs_by_pk) => {
|
||||
return jobs_by_pk.ro_number;
|
||||
};
|
||||
const generateOwnerTier = (jobs_by_pk) => {
|
||||
return jobs_by_pk.ownr_co_nm
|
||||
? `${jobs_by_pk.ownr_co_nm} - ${jobs_by_pk.ownr_ln || ""} ${
|
||||
jobs_by_pk.ownr_fn || ""
|
||||
} #${jobs_by_pk.owner.accountingid || ""}`
|
||||
: `${jobs_by_pk.ownr_ln || ""} ${jobs_by_pk.ownr_fn || ""} #${
|
||||
jobs_by_pk.owner.accountingid || ""
|
||||
}`;
|
||||
};
|
||||
|
||||
const generateJobQbxml = (jobs_by_pk, bodyshop, isThreeTier, tierLevel) => {
|
||||
let Name;
|
||||
let ParentRefName;
|
||||
|
||||
if (tierLevel === 2) {
|
||||
Name = generateOwnerTier(jobs_by_pk);
|
||||
ParentRefName = isThreeTier ? generateSourceTier(jobs_by_pk) : null;
|
||||
} else if (tierLevel === 3) {
|
||||
Name = generateJobTier(jobs_by_pk);
|
||||
ParentRefName = isThreeTier
|
||||
? `${jobs_by_pk.ins_co_nm}:${generateOwnerTier(jobs_by_pk)}`
|
||||
: generateOwnerTier(jobs_by_pk);
|
||||
}
|
||||
|
||||
const jobQbxmlObj = {
|
||||
QBXML: {
|
||||
@@ -109,10 +118,12 @@ const generateJobQbxml = (jobs_by_pk, bodyshop, isThreeTier, tierLevel) => {
|
||||
"@onError": "continueOnError",
|
||||
CustomerAddRq: {
|
||||
CustomerAdd: {
|
||||
Name: tierLevel === 2 ? null : null,
|
||||
ParentRef: {
|
||||
FullName: tierLevel === 2 ? null : null,
|
||||
},
|
||||
Name: Name,
|
||||
ParentRef: ParentRefName
|
||||
? {
|
||||
FullName: ParentRefName,
|
||||
}
|
||||
: null,
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -128,6 +139,7 @@ const generateJobQbxml = (jobs_by_pk, bodyshop, isThreeTier, tierLevel) => {
|
||||
.end({ pretty: true });
|
||||
|
||||
const jobQbxml_Full = addQbxmlHeader(jobQbxml_partial);
|
||||
console.log("jobQbxml_Full", jobQbxml_Full);
|
||||
return jobQbxml_Full;
|
||||
};
|
||||
|
||||
@@ -170,6 +182,46 @@ const generateInvoiceQbxml = (jobs_by_pk, bodyshop) => {
|
||||
);
|
||||
});
|
||||
|
||||
//Add tax lines
|
||||
const job_totals = JSON.parse(jobs_by_pk.job_totals);
|
||||
|
||||
const federal_tax = Dinero(job_totals.totals.federal_tax);
|
||||
const state_tax = Dinero(job_totals.totals.state_tax);
|
||||
const local_tax = Dinero(job_totals.totals.local_tax);
|
||||
|
||||
if (federal_tax.getAmount() > 0) {
|
||||
InvoiceLineAdd.push({
|
||||
ItemRef: {
|
||||
FullName: bodyshop.md_responsibility_centers.taxes.federal.accountitem,
|
||||
},
|
||||
Desc: bodyshop.md_responsibility_centers.taxes.federal.accountdesc,
|
||||
//Quantity: 1,
|
||||
Amount: federal_tax.toFormat(DineroQbFormat),
|
||||
});
|
||||
}
|
||||
|
||||
if (state_tax.getAmount() > 0) {
|
||||
InvoiceLineAdd.push({
|
||||
ItemRef: {
|
||||
FullName: bodyshop.md_responsibility_centers.taxes.state.accountitem,
|
||||
},
|
||||
Desc: bodyshop.md_responsibility_centers.taxes.state.accountdesc,
|
||||
//Quantity: 1,
|
||||
Amount: state_tax.toFormat(DineroQbFormat),
|
||||
});
|
||||
}
|
||||
|
||||
if (local_tax.getAmount() > 0) {
|
||||
InvoiceLineAdd.push({
|
||||
ItemRef: {
|
||||
FullName: bodyshop.md_responsibility_centers.taxes.local.accountitem,
|
||||
},
|
||||
Desc: bodyshop.md_responsibility_centers.taxes.local.accountdesc,
|
||||
//Quantity: 1,
|
||||
Amount: local_tax.toFormat(DineroQbFormat),
|
||||
});
|
||||
}
|
||||
|
||||
const invoiceQbxmlObj = {
|
||||
QBXML: {
|
||||
QBXMLMsgsRq: {
|
||||
@@ -177,13 +229,14 @@ const generateInvoiceQbxml = (jobs_by_pk, bodyshop) => {
|
||||
InvoiceAddRq: {
|
||||
InvoiceAdd: {
|
||||
CustomerRef: {
|
||||
//This can equal the Customer or the Customer Job.
|
||||
FullName:
|
||||
bodyshop.accountingconfig.tiers === 3
|
||||
? "3tier"
|
||||
: bodyshop.accountingconfig.twotierpref === "name"
|
||||
? "2tiername"
|
||||
: "2tiersource",
|
||||
? `${generateSourceTier(jobs_by_pk)}:${generateOwnerTier(
|
||||
jobs_by_pk
|
||||
)}:${generateJobTier(jobs_by_pk)}`
|
||||
: `${generateOwnerTier(jobs_by_pk)}:${generateJobTier(
|
||||
jobs_by_pk
|
||||
)}`,
|
||||
},
|
||||
TxnDate: new Date(),
|
||||
RefNumber: jobs_by_pk.ro_number,
|
||||
@@ -234,7 +287,7 @@ const generateInvoiceLine = (job, allocation, responsibilityCenters) => {
|
||||
//Rate: 100,
|
||||
Amount: DineroAmount.toFormat(DineroQbFormat),
|
||||
SalesTaxCodeRef: {
|
||||
FullName: "Z",
|
||||
FullName: "E",
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
@@ -48,6 +48,7 @@ query QUERY_JOBS_FOR_RECEIVABLES_EXPORT($id: uuid!) {
|
||||
date_invoiced
|
||||
ro_number
|
||||
clm_total
|
||||
clm_no
|
||||
invoice_allocation
|
||||
ownerid
|
||||
ownr_ln
|
||||
|
||||
Reference in New Issue
Block a user