Skip to content
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

Fix error calculating auth. and billable days #156

Merged
merged 34 commits into from
Mar 8, 2023

Conversation

Cruikshanks
Copy link
Member

@Cruikshanks Cruikshanks commented Mar 7, 2023

https://eaflood.atlassian.net/browse/WATER-3906

In the first round of testing, we came across a scenario where our FormatSrocTransactionLineService service calculated the authorisedDays and billableDays as null.

After some investigation we realised

  • we had 2 ways to calculate billable days
  • both had a fundamental flaw

AbstractionBillingPeriodService would take a billing period and a charge purpose and return 1 or 2 abstraction periods with the billable days calculated. But it didn't take into account any overlap between the abstraction periods it determined. It also didn't account for any overlap across all the charge purposes a charge element has.

FormatSrocTransactionLineService was doing its own logic for determining the abstraction period. It was also looking across the charge purposes and dealing with any overlap. But when determining the abstraction period it hadn't accounted for something like 01-JAN to 30-JUN. A period like that needs to be factored in twice, especially when determining the authorised days. This is because if, for example, the billing period is 01-APR-2023 to 31-MAR-2023 it overlaps the first few months and the last few months.

We realised we need to combine the logic of AbstractionBillingPeriodService with FormatSrocTransactionLineService use of ConsolidateDateRangesService.

So, this change adds CalculateAuthorisedAndBillableDaysService, which completely replaces AbstractionBillingPeriodService and the logic in FormatSrocTransactionLineService.

This is the most complex bit of the whole process (that we've encountered) and we're hopeful we now have it nailed. This change also adds lots of documentation to try and help our future selves! 😀

https://eaflood.atlassian.net/browse/WATER-3906

In the first round of testing we came across a scenario where our `FormatSrocTransactionLineService` service calculated the `authorisedDays` and `billableDays` as `null`.

This change fixes the issue.
@Cruikshanks Cruikshanks added the bug Something isn't working label Mar 7, 2023
@Cruikshanks Cruikshanks self-assigned this Mar 7, 2023
Cruikshanks and others added 27 commits March 7, 2023 14:44
Plus avoids confusion with the actual billableDays value.
Again, trying to move away from the use of `billable` to something more generic.
Previously we were adding properties to our abstraction period objects to be used in subsequent methods.

It's not red line, but it is something you try and avoid. With this refactoring we avoid mutating the abstraction periods and act on the results of the methods directly.
We think we don't need these elements any more. So, we are commenting them out before we start running it through our unit tests to confirm if that is the case.
These will be rewritten to use our ace scenarios!
Our function for calculating abstraction periods didn't work when the reference period started and ended the same year. We have amended the logic so that instead of checking the start and end day/month and creating dates accordingly, we simply create a start and end date using the reference period's start year, and fix the end date's year if needed. Doing this means we also need to create an additional abstraction period to consider but we will look at refactoring to only do this if necessary
As per our team style, we split the one-line filter onto two lines
Our tests were breaking due to changes we'd made -- we now pass in the billing period instead of the financial year, so we simply change what we pass in our tests to get them working again
@Cruikshanks Cruikshanks marked this pull request as ready for review March 8, 2023 17:02
@Cruikshanks Cruikshanks requested review from StuAA78 and Jozzey March 8, 2023 17:02
Jozzey
Jozzey previously approved these changes Mar 8, 2023
Copy link
Contributor

@Jozzey Jozzey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏼 Just one typo

Co-authored-by: Jason Claxton <[email protected]>
@Cruikshanks Cruikshanks merged commit c927273 into main Mar 8, 2023
@Cruikshanks Cruikshanks deleted the fix-error--calculating-billable-days branch March 8, 2023 23:18
Cruikshanks added a commit that referenced this pull request Mar 9, 2023
https://eaflood.atlassian.net/browse/WATER-3906

Having implemented our [Fix error calculating auth. and billable days](#156) we clocked that we were calculating charge periods, option flags, and the authorised and billable days multiple times, when they do not change between iterations of the charge elements in a charge version.

We only want to be executing our services when needed as it reduces complexity and the chance of an error occurring. It also means we get a slight performance bump.

So, this change refactors how the `ProcessBillingBatchService` and the `FormatSrocTransactionLineService` interact together to create the transaction lines for a billing batch.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants