Skip to content

Commit df02d20

Browse files
authored
Inc. changes to agreements & charges in supp bill (#207)
https://eaflood.atlassian.net/browse/WATER-3989 When a new charge version is added to a licence, users can change agreements and charges linked to the licence via the charge version. So, for example, when the SROC charge version is first applied the licence does **not** have a two-part tariff agreement (2PT). But later in the year, one is added. To do this the business will add a new charge version and apply the 2PT agreement. Though the number of billable days calculated won't change, the charge that the [charging-module-api](https://gothub.com/DEFRA/sroc-charging-module-api) returns will. So, we need to credit the previous transaction and calculate a new debit. At the moment, our engine does not look at changes to agreements and charges. So, it will compare the billable days, see no change and cancel both the previous and calculated transaction lines before we get a value from the charging module. This change updates the logic for comparing previous transactions to those we've calculated to include agreements and charges. If there has been a change, the lines won't match and get cancelled so will then progress to the next step; sending them to the charging module to calculate their charge value.
1 parent c3be9d4 commit df02d20

File tree

2 files changed

+439
-103
lines changed

2 files changed

+439
-103
lines changed

app/services/supplementary-billing/process-billing-transactions.service.js

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,55 @@ async function go (calculatedTransactions, billingInvoice, billingInvoiceLicence
3939
}
4040

4141
/**
42+
* Compares a calculated transaction to the transactions from previous bill runs
43+
*
4244
* Takes a single calculated debit transaction and checks to see if the provided array of reversed (credit) transactions
43-
* contains a transaction that will cancel it out, returning `true` or `false` to indicate if it does or doesn't. Since
44-
* the calculated debit transactions have not yet been sent to the Charging Module, we look at `chargeType`,
45-
* `chargeCategoryCode` and `billableDays` as any given combination of these will always result in the same value coming
46-
* back from the Charging Module.
45+
* contains a transaction that will cancel it out, returning `true` or `false` to indicate if it does or doesn't.
46+
*
47+
* We compare those properties which determine the charge value calculated by the charging module. If the calculated
48+
* transaction's properties matches one in reversedTransactions we return true. This will tell the calling method
49+
* to not include the calculated transaction in the bill run. We also remove the matched transaction from
50+
* reversedTransactions.
51+
*
52+
* The key properties are charge type, category code, and billable days. But we also need to compare agreements and
53+
* additional charges because if those have changed, we'll need to credit the previous transaction and calculate the
54+
* new debit value. Because what we are checking does not match up to what you see in the UI we have this reference
55+
*
56+
* - Abatement agreement - section126Factor
57+
* - Two-part tariff agreement - section127Agreement
58+
* - Canal and River Trust agreement - section130Agreement
59+
* - Aggregate - aggregateFactor
60+
* - Charge Adjustment - adjustmentFactor
61+
* - Winter discount - isWinterOnly
62+
*
63+
* - Additional charges - isSupportedSource
64+
* - Additional charges - supportedSourceName
65+
* - Additional charges - isWaterCompanyCharge
4766
*
4867
* NOTE: This function will mutate the provided array of reversed transactions if one of the transactions in it will
4968
* cancel the calculated transaction; in this case, we remove the reversed transaction from the array as it can only
5069
* cancel one calculated transaction.
5170
*/
5271
function _cancelCalculatedTransaction (calculatedTransaction, reversedTransactions) {
72+
// When we put together this matching logic our instincts were to try and do something 'better' than this long,
73+
// chained && statement. But whatever we came up with was
74+
// - more complex
75+
// - less performant
76+
// We found this easy to see what properties are being compared. Plus the moment something doesn't match we bail. So,
77+
// much as it feels 'wrong', we are sticking with it!
5378
const result = reversedTransactions.findIndex((reversedTransaction) => {
5479
return reversedTransaction.chargeType === calculatedTransaction.chargeType &&
5580
reversedTransaction.chargeCategoryCode === calculatedTransaction.chargeCategoryCode &&
56-
reversedTransaction.billableDays === calculatedTransaction.billableDays
81+
reversedTransaction.billableDays === calculatedTransaction.billableDays &&
82+
reversedTransaction.section126Factor === calculatedTransaction.section126Factor &&
83+
reversedTransaction.section127Agreement === calculatedTransaction.section127Agreement &&
84+
reversedTransaction.section130Agreement === calculatedTransaction.section130Agreement &&
85+
reversedTransaction.aggregateFactor === calculatedTransaction.aggregateFactor &&
86+
reversedTransaction.adjustmentFactor === calculatedTransaction.adjustmentFactor &&
87+
reversedTransaction.isWinterOnly === calculatedTransaction.isWinterOnly &&
88+
reversedTransaction.isSupportedSource === calculatedTransaction.isSupportedSource &&
89+
reversedTransaction.supportedSourceName === calculatedTransaction.supportedSourceName &&
90+
reversedTransaction.isWaterCompanyCharge === calculatedTransaction.isWaterCompanyCharge
5791
})
5892

5993
if (result === -1) {

0 commit comments

Comments
 (0)