top of page

Group total

Introduction

I want to show for example, the hour of a product service or the total of a category’s product in each group. How to manage it?



Custom field you will need

In the quote line groups



In the quote line





Custom Script



//   Initialize the number of hours
export   function onInit(lines) {
lines.forEach(function   (line) {
if   (line.record) {
line.record["BundleHours__c"]   = 0;
}
});
return   Promise.resolve();
}

//   Calculate the number of hours in the bundle using the child variables tasks   time, quantity
export   function onBeforeCalculate(quoteModel, quoteLineModels) {
calculateBundleHours(quoteLineModels);
return   Promise.resolve();
}

//   Exported function to be called before calculation in Salesforce CPQ
export   function onAfterCalculate(quoteModel, quoteLineModels, _conn) {
applyGroupTotalValue(quoteLineModels,   quoteModel);
return   Promise.resolve();
}

//   Helper function to get the total time for tasks and perform the calculation
function   getTotalFromTasks(time, qty) {
return   (time / 60) * qty;
}

function   calculateBundleHours(quoteLines) {
quoteLines.forEach(function   (line) {
var   parent = line.parentItem;
if   (parent && parent.record) {
var   parentTotalHours = parent.record["BundleHours__c"] || 0;
var   childTime = line.record.Time__c || 0;
var   childQuantity = line.record.SBQQ__Quantity__c || 1;
var   childTotalTime = getTotalFromTasks(childTime, childQuantity);

parentTotalHours   += childTotalTime;
parent.record["BundleHours__c"]   = parentTotalHours;
}
});
}

function   applyGroupTotalValue(_lines, quoteModel) {
for   (const group of quoteModel.groups) {
if   (group.lineItems.length > 0) {
var   totalHours = 0;
var   totalSupply = 0;
var   totalHT = 0;

for   (const line of group.lineItems) {
const   lineRecord = line.record;
const   netTotal = lineRecord.SBQQ__NetTotal__c;

if   (lineRecord.Categorie__c === "Categorie1") {
totalHours   += getTotalFromTasks(lineRecord.Time__c, lineRecord.SBQQ__Quantity__c);
}
if   (lineRecord.Categorie__c === "Categorie2") {
totalSupply   += netTotal;
}
totalHT   += netTotal;
}

const   groupRecord = group.record;
groupRecord["TotalGroupHour__c"]   = totalHours;
groupRecord["TotalCategorieGroup__c"]   = totalSupply;
groupRecord["TotalHTGroup__c"]   = totalHT;
}
}
}



Time for upgrade

You can do a twin field between quote line and product for time and category. The product should logically a specific category and have a specific time for a task (example: make a bed is a task and you need 5 minutes).


Result


4 views0 comments

Recent Posts

See All

留言

評等為 0(最高為 5 顆星)。
暫無評等

新增評等
bottom of page