diff --git a/server/cdk/cdk-calculate-allocations.js b/server/cdk/cdk-calculate-allocations.js index 600db20b4..b557f322d 100644 --- a/server/cdk/cdk-calculate-allocations.js +++ b/server/cdk/cdk-calculate-allocations.js @@ -236,10 +236,36 @@ exports.default = async function (socket, jobid) { const mapaAccountName = selectedDmsAllocationConfig.costs.MAPA; const mapaAccount = bodyshop.md_responsibility_centers.costs.find((c) => c.name === mapaAccountName); if (mapaAccount) { - if (!costCenterHash[mapaAccountName]) costCenterHash[mapaAccountName] = Dinero(); - costCenterHash[mapaAccountName] = costCenterHash[mapaAccountName].add( - Dinero(job.job_totals.rates.mapa.total).percentage(bodyshop?.cdk_configuration?.sendmaterialscosting) - ); + if (!costCenterHash[mapaAccountName]) + costCenterHash[mapaAccountName] = Dinero(); + if (job.bodyshop.use_paint_scale_data === true) { + if (job.mixdata.length > 0) { + costCenterHash[mapaAccountName] = costCenterHash[ + mapaAccountName + ].add( + Dinero({ + amount: Math.round( + ((job.mixdata[0] && job.mixdata[0].totalliquidcost) || 0) * + 100 + ), + }) + ); + } else { + costCenterHash[mapaAccountName] = costCenterHash[ + mapaAccountName + ].add( + Dinero(job.job_totals.rates.mapa.total).percentage( + bodyshop?.cdk_configuration?.sendmaterialscosting + ) + ); + } + } else { + costCenterHash[mapaAccountName] = costCenterHash[mapaAccountName].add( + Dinero(job.job_totals.rates.mapa.total).percentage( + bodyshop?.cdk_configuration?.sendmaterialscosting + ) + ); + } } else { //console.log("NO MAPA ACCOUNT FOUND!!"); } diff --git a/server/graphql-client/queries.js b/server/graphql-client/queries.js index cd61b3575..d26db1405 100644 --- a/server/graphql-client/queries.js +++ b/server/graphql-client/queries.js @@ -1790,6 +1790,7 @@ exports.GET_CDK_ALLOCATIONS = `query QUERY_JOB_CLOSE_DETAILS($id: uuid!) { md_responsibility_centers cdk_configuration pbs_configuration + use_paint_scale_data } ro_number dms_allocation @@ -1897,6 +1898,10 @@ exports.GET_CDK_ALLOCATIONS = `query QUERY_JOB_CLOSE_DETAILS($id: uuid!) { line_ref unq_seq } + mixdata(limit: 1, order_by: {updated_at: desc}) { + jobid + totalliquidcost + } } }`;