diff --git a/server/cdk/cdk-calculate-allocations.js b/server/cdk/cdk-calculate-allocations.js index cd75dc6ec..5f8605232 100644 --- a/server/cdk/cdk-calculate-allocations.js +++ b/server/cdk/cdk-calculate-allocations.js @@ -224,11 +224,34 @@ exports.default = async function (socket, jobid) { 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 (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 b2fd4e23e..8e70ca959 100644 --- a/server/graphql-client/queries.js +++ b/server/graphql-client/queries.js @@ -1793,6 +1793,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 @@ -1900,6 +1901,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 + } } }`;