-
Notifications
You must be signed in to change notification settings - Fork 105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor Human Resources and Payroll Management #7943
Open
jniles
wants to merge
46
commits into
master
Choose a base branch
from
refactor-payroll-management
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cd1a9d8
to
a10945c
Compare
818ac29
to
9b635c8
Compare
This commit comments the commitmentByEmployee.js file as a work in progress towards the major payroll refactor.
Adds detailed comments to the commitment.js file, as well as refactoring the code in the following ways: 1. Uses async/await in place of promises for better control flow. 2. Use switch/case for explicit control flow. 2. Delete unused variables, consolidate other variables.
Adds comments to the dataCommitment function.
Adds debug comments for the multiple payroll configuration files. Also unwraps the function signature for setMultiConfiguration to no longer take mysterious parameters.
Refactors the payroll settings controller to include additional comments, debug() calls and reduce code complexity.
Refactors and renames the API for payroll account configurations from /account_config to /payroll/account_config to prevent confusion. Updates comments to ensure correctness and usefulness. Also migrates the API to using async/await.
Adds documentation comments.
This commit adds the appropriate eslint skips to allow longer line comments.
Adds comments, debug() calls, and refactors code to reduce side effects. For example, many totally functions are consolidated into reduce() functions.
Work-in-progress towards #7791. Adds description keys to the commitmentByEmployee() function.
Moves rubric filtering and summing functions into a new common.js file to help with legibility.
Tightens up the commitment.js file by removing the need for external cost center code and using `const` to ensure that the arrays are not reassigned.
Refactors the commitment controller to more cleanly trace the payroll process.
Removes the assignCostCenter function that was previously in the cost center module. There is no need for it to be there, since it only deals with array processing (though the array is a cost center). Instead, it is replaced with an anonymous function inline.
Adds unit tests for the common.js modules.
Moves the cost center assignment function to `payroll/common.js` since it is shared between the groupedCommitment and commitment files. Also adds tests for all the common.js functions.
Reduces the complexity of exchange rate lookups across all commitment functions by converting the exchange rates into an exchange rate map with O(1) lookup time. Reduces lookups from O(n^2) to O(n) lookups.server
Finalizes the clean up work on payroll to provide a base for continued improvement.
Reworks the commitment function signatures to reduce the size of the function signatures. Still a work in progress.
This commit simplifies the function call signature by removing extra parameters that are instead attached to the configuration object passed into the subsequent commitment() calls.
Simplifies the commitmentByEmployee() function to make external calls to newly implemented functions: 1. calculateEmployeeBenefits 2. calculateEmployeeWithholdings 3. calculateEmployeePayrollTaxes 4. calculateEmployeePension Each function filters the rubrics for their specific rubric type and accumulates the values by employee. The descriptions have now also been improved to record the rubric label, employee information, and payment period information to the voucher descriptive text. Closes #7791.
Migrates the code that configures an employee for payment to async/await to reduce verbosity and better control variable scope.
Replaces the function call with the object spread.
Cleans up a few comments and inconsistent variable names noticed during the review period.
Replaces the `date_embauche` with `hiring_date` for better English consistency. Closes #7821.
Enhances the `bhCurrencyInput` with a `horizontal` property that will allow the currency to render correctly when on a form-horizontal form.
Replaces var with let/const in currency service and passes ESLint.
Moves the rubrics for payroll lower in the "Optional Information" section for better consistency. It also cleans up the controller's eslint issues.
Corrects the spelling of "Human Resources" throughout the application.
Unifies the rubric configuration modal to configure both the label and checkboxes for applied rubrics at the same time for a more streamlined configuration.
Migrates the rubric configuration server controllers to use the `payroll/` prefix in routes. It also removes the `/setting` suffix from the routes, opting instead to have an API similar to the cash payments or invoices API where the items are provided as an array in the main payment configuration object. The next step will be to unify the client UI to allow simultaneous configuration for the payroll rubrics.
Uses a unified interface for the rubric configuration service.
Fixes a race condition that caused buggy behavior in the Tax IPR Config Modal controller. Now, the submit button is disabled until all the data is available to use.
Does not crash when the rubric items are empty.
Block modal submission when required fields are not filled in and ensure that `unset` tests work to allow creating a modal with empty rubric fields.
Converts the server side code to async/await, removes duplicate FunctionService.
Adds a column to the "function registry" to show the number of employees with that function assigned.
Removes an unused, untranslated chart-modal.html. No idea where it came from.
Implements the same style of batch creates used on the account modal for creating functions.
Removes technical debt by removing duplicate code.
Fixes lint errors in employee modules.
Addresses a number of cosmetic requests discussed in #6097. Notably, the English syntax for "nontaxable" and "payslip" have been addressed. Additionally, the currency exchange rate is not rendered on the payslip if the currency is the enterprise currency. However, there is a bug with the currency rendering on the payslip generator that does not allow the currency to be properly rendered. This will be addressed in a future PR.
edc1702
to
7111960
Compare
Runs `eslint --fix` on the services associated with human resources and payroll.
ede1f3b
to
509302f
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR is ready for testing and merge, once #7979 lands.
It's main contribution is a much better logical flow to the payroll code on the server, and address some of the UI complaints multiple_payroll module. Because little was changed in the data model (SQL) or the core of the UI, the tests were not needed to be extensively updated.
The old PR description is found below to denote the journey we've been on in this PR.
Previous PR Description:
This PR reworks the underlying Human Resources and Payroll Management code and procedures to allow for better code readability, maintainability, efficiency and testing. It is part of an effort to rewrite the payment processes to support multiple payroll systems in a unified way (#7752).
All updates and changes are being made a feature branch
refactor-payroll-management
. This is the PR pulls that branch intomaster
. It will be marked as a draft, and should not be merged until it is marked as needing review.General Approach
The general approach for this refactor is to:
async
/await
,Promise
, etc) and removing unused code paths.debug()
calls to complex tasks to document code behavior.isBenefitRubric()
)payroll/
prefix where there might be confusion (e.g.account_config/
->payroll/account_config/
)Some notable changes:
Issues Tackled
The following issues are tacked in part or in whole:
commitmentByEmployee()
function so far).Payroll Concepts and Definitions (as expressed by BHIMA)
For a review of the DRC Human Resources definitions, see #7969. Below, we discuss how these concepts are expressed in BHIMA.
There are four basic types of payroll modifications: benefits, payroll taxes, withholdings, and pension allowances.
is_discount === 0
.is_employee !== 1
,is_discount === 1
,is_linked_pension_fund === 0
.is_discount === 1
andis_employee === 1
.is_employee !== 0
,is_discount === 1
, andis_linked_pension_fund ===1
.Note: we should probably rename "withholdings" to "deductions".
Notable and/or Breaking Changes
/account_config/
to/payroll/account_config/
since it is used to configure accounts used in the payroll modules.DEBUG
to includepayroll:*
spews out much more informative information about the transaction process.common.js
function and is shared across all commitment types. It also has some rudimentary tests.commitmentByEmployee()
now calls out to relevantcalculate*()
functions for taxes, withholdings, pension and benefits. This should make the code somewhat more legible.Testing
We don't have very many payroll tests. In particular, I'm not sure we have tests for all the different types of
commitment
functions listed in the enterprise settings. Which means that, should this get merged, we cannot be 100% this code will not break something in production.Ideally, I'm hoping to continue to hack on payroll over the holidays until we get something that is easy to reason about, maintain, and trace if a regression or a bug occurs. However, we probably shouldn't do a release and/or upgrade until we have better test coverage or assurance that the payroll code isn't going to break in mysterious ways at one of the production sites.
Future Work
This PR addresses only about a quarter of the needed payroll refactor. In many ways, it addresses the low-hanging fruit of function signatures and variable hoisting. More in depth refactor is needed in the following areas:
payroll/multiplePayroll/common.js
, document them, and test them.multiplePayrollIndice
associated with multiple indexes.payrollSettings
and associated files.commitFunction#dataCommit()
function to have a simpler function signature.On thing I noticed while working on this refactor: there are several places where we loop through employees and compute rubric values that are nearly identical. For example, each
commitment
function (commitment.js
,groupedCommitment.js
,commitmentByEmployee.js
) loops through the employees, but generates slightly different transactions with the results. With the current code structure, this is fine. However, there is likely a way to make some sort of intermediate representation of the data that is common between all three that we can then reuse for all three.As an example, one can imagine some sort of pseudocode like this:
An advantage of this style is that we could then write unit tests for the
loopThroughEmployeesAndComputeRubrics()
function and ensure that we are correctly expressing the rubrics as transactions. It would make it faster and easier to write a variety of tests for different scenarios (e.g. multiple pension withholdings, increases of greater than 100%, etc).Payroll Order of Operations
I spoke to Nancy Allan, who guided me through the basic payroll order of operations. They are:
It should be noted that pension and taxes on pension are separate calculations.
Unanswered Questions: