IO-1125 Add Mapa & Mash for jobs that don't have it.

This commit is contained in:
Patrick Fic
2021-05-18 11:17:28 -07:00
parent 7ee740f7ce
commit 7731833898
9 changed files with 6642 additions and 6564 deletions

View File

@@ -177,7 +177,7 @@ const generateJobQbxml = (
.end({ pretty: true });
const jobQbxml_Full = QbXmlUtils.addQbxmlHeader(jobQbxml_partial);
console.log("jobQbxml_Full", jobQbxml_Full);
return jobQbxml_Full;
};
@@ -192,10 +192,23 @@ const generateInvoiceQbxml = (
const InvoiceLineAdd = [];
const responsibilityCenters = bodyshop.md_responsibility_centers;
const invoiceLineHash = {};
const invoiceLineHash = {}; //The hash of cost and profit centers based on the center name.
//Determine if there are MAPA and MASH lines already on the estimate.
//If there are, don't do anything extra (mitchell estimate)
//Otherwise, calculate them and add them to the default MAPA and MASH centers.
let hasMapaLine = false;
let hasMashLine = false;
//Create the invoice lines mapping.
jobs_by_pk.joblines.map((jobline) => {
//Parts Lines
if (jobline.db_ref === "936008") { //If either of these DB REFs change, they also need to change in job-totals calculations.
hasMapaLine = true;
}
if (jobline.db_ref === "936007") {
hasMashLine = true;
}
if (jobline.profitcenter_part && jobline.act_price) {
const DineroAmount = Dinero({
@@ -216,18 +229,15 @@ const generateInvoiceQbxml = (
Desc: account.accountdesc,
Quantity: 1, //jobline.part_qty,
Amount: DineroAmount, //.toFormat(DineroQbFormat),
//Amount: DineroAmount.toFormat(DineroQbFormat),
SalesTaxCodeRef: {
FullName: "E",
},
};
} else {
invoiceLineHash[account.name].Amount = invoiceLineHash[
account.name
].Amount.add(DineroAmount);
invoiceLineHash[account.name].Amount =
invoiceLineHash[account.name].Amount.add(DineroAmount);
}
}
// Labor Lines
if (
jobline.profitcenter_labor &&
@@ -260,14 +270,64 @@ const generateInvoiceQbxml = (
},
};
} else {
invoiceLineHash[account.name].Amount = invoiceLineHash[
account.name
].Amount.add(DineroAmount);
invoiceLineHash[account.name].Amount =
invoiceLineHash[account.name].Amount.add(DineroAmount);
}
}
});
// console.log("Done creating hash", JSON.stringify(invoiceLineHash));
if (!hasMapaLine) {
console.log("Adding MAPA Line Manually.");
const mapaAccountName = responsibilityCenters.defaults.profits.MAPA;
const mapaAccount = responsibilityCenters.profits.find(
(c) => c.name === mapaAccountName
);
if (mapaAccount) {
InvoiceLineAdd.push({
ItemRef: { FullName: mapaAccount.accountitem },
Desc: mapaAccount.accountdesc,
Quantity: 1,
Amount: Dinero(jobs_by_pk.job_totals.rates.mapa.total).toFormat(
DineroQbFormat
),
SalesTaxCodeRef: {
FullName: "E",
},
});
} else {
console.log("NO MAPA ACCOUNT FOUND!!");
}
}
if (!hasMashLine) {
console.log("Adding MASH Line Manually.");
const mashAccountName = responsibilityCenters.defaults.profits.MASH;
const mashAccount = responsibilityCenters.profits.find(
(c) => c.name === mashAccountName
);
if (mashAccount) {
InvoiceLineAdd.push({
ItemRef: { FullName: mashAccount.accountitem },
Desc: mashAccount.accountdesc,
Quantity: 1,
Amount: Dinero(jobs_by_pk.job_totals.rates.mash.total).toFormat(
DineroQbFormat
),
SalesTaxCodeRef: {
FullName: "E",
},
});
} else {
console.log("NO MASH ACCOUNT FOUND!!");
}
}
//Convert the hash to an array.
Object.keys(invoiceLineHash).forEach((key) => {
InvoiceLineAdd.push({
@@ -370,7 +430,6 @@ const generateInvoiceQbxml = (
},
};
console.log(JSON.stringify(invoiceQbxmlObj, null, 2));
var invoiceQbxml_partial = builder
.create(invoiceQbxmlObj, {
version: "1.30",
@@ -380,7 +439,6 @@ const generateInvoiceQbxml = (
.end({ pretty: true });
const invoiceQbxml_Full = QbXmlUtils.addQbxmlHeader(invoiceQbxml_partial);
console.log("invoiceQbxml_Full", invoiceQbxml_Full);
return invoiceQbxml_Full;
};

View File

@@ -100,6 +100,7 @@ query QUERY_JOBS_FOR_RECEIVABLES_EXPORT($ids: [uuid!]!) {
op_code_desc
profitcenter_labor
profitcenter_part
db_ref
}
}
bodyshops(where: {associations: {active: {_eq: true}}}) {

View File

@@ -165,7 +165,7 @@ function CalculateRatesTotals(ratesList) {
if (item.mod_lbr_ty === "LAR") {
ret.mapa.hours = ret.mapa.hours + item.mod_lb_hrs;
} else {
ret.mash.hours = ret.mash.hours + item.mod_lb_hrs;
ret.mash.hours = ret.mash.hours + item.mod_lb_hrs; //Apparently there may be an exclusion for glass hours in BC.
}
}
});