Salary Planning with a Hierarchy

Overview


Salary planning is the process of forecasting salary expense based on manipulating the salary and bonus data for an organizations exmployees. Most organizations have hierarchies within the organization, i.e. divisions and managers within those divisions. For planning at the top levels, it is useful to be able to roll up any forecast to the division or manager level.

Management Hierarchy


Fo many analyses, you need to aggregate or group data along a management hierarchy. That is, you may want to compute the sum of salaries of individuals that report up thourhg a given manager.


let hierarchyRecord = {
  employeeId:2,
  managerId:1				
};
					

Using Tree Data Structure


The best way to analyze tree like data is to read the data into a tree data structure. The tree api provides a simple way to group data into a tree.

The tree api makes it easy to treansform data from a flat array such as the following into a tree.


let hierarchy = [
  { employeeId:1, managerId:6	},
  { employeeId:2, managerId:6	},
  { employeeId:3, managerId:6	},
  { employeeId:4, managerId:7	},
  { employeeId:5, managerId:7	},
  { employeeId:6 },
  { employeeId:7 },
];
					


Notice that objects have an id and a parentid. If those properties are present, you can create a tree by calling the following


let te = await import('/lib/tree/v1.0.0/tree-map.mjs');
let tree = te.fromTable(hierarchy.map(p=>{
  return {
    id:p.employeeId,
    parentid:p.managerId
  }
}));
					


Next, the following code calculates the payroll for all the employees who report up to the employee with id = 6.


let records2 = records.filter(p=>tree[p.id].ancestors[6] !== undefined)
let ranges = cd.biMonthlyRanges('2020-01', '2021-12');
let payments = py.forecast(ranges, records2);
					
Try it!

Contents