Resolved calculations for profile markups and discounts.

This commit is contained in:
Patrick Fic
2023-10-06 07:57:26 -07:00
parent 4bd139f93b
commit ef146032df
5 changed files with 328 additions and 377 deletions

View File

@@ -25,58 +25,37 @@ exports.default = async function (socket, jobid) {
const { bodyshop } = job;
const taxAllocations = {
// local: {
// center: bodyshop.md_responsibility_centers.taxes.local.name,
// sale: Dinero(job.job_totals.totals.local_tax),
// cost: Dinero(),
// profitCenter: bodyshop.md_responsibility_centers.taxes.local,
// costCenter: bodyshop.md_responsibility_centers.taxes.local,
// },
// state: {
// center: bodyshop.md_responsibility_centers.taxes.state.name,
// sale: Dinero(job.job_totals.totals.state_tax),
// cost: Dinero(),
// profitCenter: bodyshop.md_responsibility_centers.taxes.state,
// costCenter: bodyshop.md_responsibility_centers.taxes.state,
// },
// federal: {
// center: bodyshop.md_responsibility_centers.taxes.federal.name,
// sale: Dinero(job.job_totals.totals.federal_tax),
// cost: Dinero(),
// profitCenter: bodyshop.md_responsibility_centers.taxes.federal,
// costCenter: bodyshop.md_responsibility_centers.taxes.federal,
// },
tax_ty1: {
center: bodyshop.md_responsibility_centers.taxes[`tax_ty1`].name,
sale: Dinero(job_totals.totals.us_sales_tax_breakdown[`ty1Tax`]),
sale: Dinero(job.job_totals.totals.us_sales_tax_breakdown[`ty1Tax`]),
cost: Dinero(),
profitCenter: bodyshop.md_responsibility_centers.taxes[`tax_ty1`],
costCenter: bodyshop.md_responsibility_centers.taxes[`tax_ty1`],
},
tax_ty2: {
center: bodyshop.md_responsibility_centers.taxes[`tax_ty2`].name,
sale: Dinero(job_totals.totals.us_sales_tax_breakdown[`ty2Tax`]),
sale: Dinero(job.job_totals.totals.us_sales_tax_breakdown[`ty2Tax`]),
cost: Dinero(),
profitCenter: bodyshop.md_responsibility_centers.taxes[`tax_ty2`],
costCenter: bodyshop.md_responsibility_centers.taxes[`tax_ty2`],
},
tax_ty3: {
center: bodyshop.md_responsibility_centers.taxes[`tax_ty3`].name,
sale: Dinero(job_totals.totals.us_sales_tax_breakdown[`ty3Tax`]),
sale: Dinero(job.job_totals.totals.us_sales_tax_breakdown[`ty3Tax`]),
cost: Dinero(),
profitCenter: bodyshop.md_responsibility_centers.taxes[`tax_ty3`],
costCenter: bodyshop.md_responsibility_centers.taxes[`tax_ty3`],
},
tax_ty4: {
center: bodyshop.md_responsibility_centers.taxes[`tax_ty4`].name,
sale: Dinero(job_totals.totals.us_sales_tax_breakdown[`ty4Tax`]),
sale: Dinero(job.job_totals.totals.us_sales_tax_breakdown[`ty4Tax`]),
cost: Dinero(),
profitCenter: bodyshop.md_responsibility_centers.taxes[`tax_ty4`],
costCenter: bodyshop.md_responsibility_centers.taxes[`tax_ty4`],
},
tax_ty5: {
center: bodyshop.md_responsibility_centers.taxes[`tax_ty5`].name,
sale: Dinero(job_totals.totals.us_sales_tax_breakdown[`ty5Tax`]),
sale: Dinero(job.job_totals.totals.us_sales_tax_breakdown[`ty5Tax`]),
cost: Dinero(),
profitCenter: bodyshop.md_responsibility_centers.taxes[`tax_ty5`],
costCenter: bodyshop.md_responsibility_centers.taxes[`tax_ty5`],
@@ -363,6 +342,30 @@ exports.default = async function (socket, jobid) {
}
}
//profile level adjustments
Object.keys(job.job_totals.parts.adjustments).forEach((key) => {
const accountName = selectedDmsAllocationConfig.profits[key];
const otherAccount = bodyshop.md_responsibility_centers.profits.find(
(c) => c.name === accountName
);
if (otherAccount) {
if (!profitCenterHash[accountName])
profitCenterHash[accountName] = Dinero();
profitCenterHash[accountName] = profitCenterHash[accountName].add(
Dinero(job.job_totals.parts.adjustments[key])
);
} else {
CdkBase.createLogEvent(
socket,
"ERROR",
`Error encountered in CdkCalculateAllocations. Unable to find adjustment account. ${error}`
);
}
});
const jobAllocations = _.union(
Object.keys(profitCenterHash),
Object.keys(costCenterHash)