Frontend
Masters
Formula Master

Formula Master

Navigation Path

Company → Masters → Formula Master


1. Formula List Page

URL

/masters/formula-master

Page Description

  • Displays a list of all formulas configured in the system
  • Allows admins to manage calculation formulas used across payroll and statutory modules
  • Displays associated salary heads for reference
  • Provides actions to add, edit, and delete formulas

List Table Columns

Column NameDescription
S NoSerial number
DescriptionFormula description
FormulaCalculation formula
LimitMaximum applicable limit
ActionsEdit and Delete options

Row Actions

ActionDescription
EditOpens Edit Formula page with pre-filled data
DeleteOpens delete confirmation alert

2. Add Formula Page

Triggered From

Formula List Page → Add Formula button

Page Description

  • Allows admins to create a new calculation formula
  • Formula can reference predefined heads from the Head List

Add Formula – Fields

Field NameTypeMandatoryDescription
DescriptionText InputYesEnter formula description
FormulaText InputYesEnter calculation formula
LimitNumber InputNoDefine maximum limit for the formula

Actions

ActionBehavior
SaveValidates and saves the formula
ResetClears all entered values
CancelReturns to Formula List page

Validation Rules

  • Description is mandatory
  • Formula is mandatory
  • Formula syntax must be valid
  • Duplicate formula descriptions are not allowed

3. Head List Reference Table

Description

  • Displays available heads that can be used while defining formulas
  • Used as a reference for building formula expressions

Head List Table Columns

Column NameDescription
H IDHead identifier
DescriptionHead description
TypeHead type (Earning / Deduction)

4. Edit Formula Page

Triggered From

Formula List Page → Edit icon

Page Description

  • Allows updating existing formula details
  • All fields are pre-filled with saved data

Editable Fields

Field NameEditable
DescriptionYes
FormulaYes
LimitYes

Actions

ActionBehavior
UpdateSaves changes
CancelDiscards changes and navigates back

5. Delete Formula Confirmation Alert

Triggered From

Formula List Page → Delete icon

Alert Content

  • Confirmation message before deletion

Actions:

  • Confirm / Yes → Deletes the formula
  • Cancel → Closes the alert without action

Delete Behavior

  • Formula is removed permanently after confirmation
  • Deletion may be restricted if the formula is already in use


Field Definitions, Usage, and Calculation Logic

This section provides a technical analysis of the Formula Master's data structure and its role as the payroll calculation engine.

1. Field Definitions

Field NameData TypeDescriptionExample Value
formulaDescriptionStringUser-facing name of the formula.HRA @ 50% of Basic
formulaStringThe mathematical expression (Regex Validated).("BASIC" * 50) / 100
limitNumberMaximum allowable value for the result.15000
companyIdObjectIdReference to the parent Company.60a8b...

2. Field Usage & System Impact

CategoryValidation / RuleSystem Behavior
SyntaxallowedPatternRegex: /^[\d\s+\-*\/()"]+$/. Only numbers, operators, and double quotes are allowed.
Variables"HEAD_NAME"Strings in double quotes are anchors for other salary head values.
CappinglimitIf the calculated value exceeds this number, the system truncates it to the limit.

3. Business & Calculation Logic

The Formula Master is the "Logic Hub" for the payroll module:

A. Formula Validation Engine

The backend enforces strict schema-level validation to prevent code injection via formulas. The validate hook in the model ensures that no alphabetical characters outside of double-quoted head references are saved.

B. Execution Flow (Runtime)

When the payroll engine processes a salary slip:

  1. Head Retrieval: It fetches the list of all earnings and deductions for the employee.
  2. Anchor Replacement: It replaces tokens like "BASIC" or "DA" in the formula string with their evaluated numeric values.
  3. Math Evaluation: The resulting string (e.g., (15000 * 50) / 100) is safe-evaluated to derive the component value.
  4. Limit Check: If a limit is defined (e.g., PF limit of 1800), the engine applies Math.min(calculatedValue, limit).

C. Relational Dependencies

Formulas are multi-tenant. A formula created by Company A is not visible to Company B. If a salary head is deleted, any formulas referencing that head name (in quotes) will fail during payroll execution, necessitating a manual update to the formula master.


The Formula Master module interacts with the following API endpoints:

Base URL

export const FORMULAMASTER_URL = '/api/salaryFormulaMaster'

Endpoints

EndpointMethodDescriptionParameters/Body
${FORMULAMASTER_URL}POSTCreate a new formulaBody: data
${FORMULAMASTER_URL}GETGet all formulasQuery: page, limit
${FORMULAMASTER_URL}/:formulaIdGETGet formula by IDPath: formulaId
${FORMULAMASTER_URL}/:formulaIdPATCHUpdate an existing formulaPath: formulaId, Body: body
${FORMULAMASTER_URL}/delete/:formulaIdPATCHDelete a formulaPath: formulaId

RTK Query Hooks

The following hooks are available for frontend integration:

  • useCreateFormulaMutation
  • useGetAllFormulasQuery
  • useGetFormulaByIdQuery
  • useUpdateFormulaMutation
  • useDeleteFormulaMutation

End of Documentation