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 including unnecessary supp. billing trans. #210

Merged
merged 4 commits into from
May 4, 2023

Conversation

Cruikshanks
Copy link
Member

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

Recent testing found an issue following the change we made in Inc. changes to agreements & charges in supp bill. Although the final result was correct, we were always creating invoices with transaction lines for scenarios we should have been returning an EMPTY bill run.

The reason was our changed logic to compare calculated transaction lines to previous ones. It was always returning 'false' i.e. the lines were always different when they should be matching and cancelling each other out.

The problem was an unexpected way the previous team was handling Section 130 agreements. Whether a charge version has one or not is held in the linked charge_elements table in the adjustments field, for example

{"s126": null, "s127": true, "s130": false, "charge": null, "winter": false, "aggregate": null}

We generate our calculated transaction lines using this source data so hold section130Agreement as a boolean. What we found when we looked at the billing_transactions table is that this is a varchar, not a boolean. It looks like the initial build of PRESROC billing stored values other than 'true' or 'false'. But that then changed to 'true' and 'false' and these are the only values used for SROC.

This means we weren't aware FetchPreviousBillingTransactionsService was returning previous transactions with section130Agreement held as a string. So, when we came to compare it was causing it to always determine the transactions were different.

So, this change fixes the issue by using Knex raw to cast the value in our query to a boolean to match what we get and use in FetchChargeVersionsService. Doing at there will be the most performant and means it matches our expectations of what type section130Agreement will be.

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

Recent testing found an issue following the change we made in [Inc. changes to agreements & charges in supp bill](#207). Although the final result was correct, we were always create invoices with transaction lines for scenarios we should have been returning an `EMPTY` bill run.

The reason was our changed logic to compare calculated transaction lines to previous ones. It was always returning 'false' i.e. the lines were always different when they should be matching and cancelling each other out.

The problem was an unexpected way the previous team was handling Section 130 agreements. Whether a charge version has one or not is held in the linked `charge_elements` table in the adjustments field, for example

```json
{"s126": null, "s127": true, "s130": false, "charge": null, "winter": false, "aggregate": null}
```

We generate our calculated transaction lines using this source data so hold `section130Agreement` as a boolean. What we found when we looked at the `billing_transactions` table is that this is a varchar not a boolean. It looks like the initial build of PRESROC billing stored values other than 'true' or 'false'. But that then changed to 'true' and 'false' and these are the only values used for SROC.

This means we weren't aware `FetchPreviousBillingTransactionsService` was return previous transactions with `section130Agreement` held as a string. So, when we came to compare it was causing it to always determine the transactions were different.

So, this change fixes the issue by using [Knex raw](https://knexjs.org/guide/raw.html) to cast the value in our query to a boolean to match what we get and use in `FetchChargeVersionsService`. Doing at there will be the most performant and means it matches our expectations of what type `section130Agreement` will be.
@Cruikshanks Cruikshanks added the bug Something isn't working label May 4, 2023
@Cruikshanks Cruikshanks self-assigned this May 4, 2023
@Cruikshanks Cruikshanks marked this pull request as ready for review May 4, 2023 11:58
Copy link
Contributor

@StuAA78 StuAA78 left a comment

Choose a reason for hiding this comment

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

Looks good, just a small suggested comment tweak!

Co-authored-by: Stuart Adair <[email protected]>
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.

@Cruikshanks Cruikshanks requested a review from StuAA78 May 4, 2023 14:29
@Cruikshanks Cruikshanks merged commit 5500c24 into main May 4, 2023
@Cruikshanks Cruikshanks deleted the fix-calculate-unchanged-transactions branch May 4, 2023 16:28
Cruikshanks added a commit that referenced this pull request May 16, 2023
https://eaflood.atlassian.net/browse/WATER-4010

We found another scenario where the bill run was always adding a credit and debit for a charge version on each bill run.

The scenario was a new charge version is added which applies an abatement agreement (section 126 factor). The bill run gets run and sent.

Another minor change is then made. No new debit and credit is needed. But when the engine grabs the previous debit, flips it to a credit and compares it against the calculated line it finds they don't match.

This results in a debit and credit for the same amount appearing each time when they should be cancelled out and not appear at all.

We tracked the problem down to the `charge_element` holding all the values as strings inside a JSONB field (`adjustments`). But when they get persisted to the `billing_transactions` table they are properly stored as a number.

This is the same issue as [Fix including unnecessary supp. billing trans.](#210) only in reverse. Thanks legacy code!

This change ensures when it comes to the comparison of `section126Factor` both previous and calculated and looking at the same data type.
Cruikshanks added a commit that referenced this pull request May 16, 2023
https://eaflood.atlassian.net/browse/WATER-4010

We found another scenario where the bill run always added credit and debit for the charge version on each bill run.

The scenario was a new charge version was added which applied an abatement agreement (section 126 factor). The bill run gets run and sent.

Another minor change is then made. No new debit and credit are needed. But when the engine grabs the previous debit, flips it to credit and compares it against the calculated line it finds they don't match.

This results in a debit and credit for the same amount appearing each time when they should be cancelled out and not appear at all.

We tracked the problem down to the `charge_element` holding all the values as strings inside a JSONB field (`adjustments`). But when they get persisted to the `billing_transactions` table they are properly stored as a number.

This is the same issue as [Fix including unnecessary supp. billing trans.](#210) only in reverse. Thanks, legacy code!

This change ensures when it comes to the comparison of `section126Factor` both previous and calculated and looking at the same data type.
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