-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move reusable supplementary billing services (#1760)
https://eaflood.atlassian.net/browse/WATER-4201 As we write this description, the long outstanding annual SROC two-part tariff bill runs are being 'sent' in production. The final part of two-part tariff is to add support for supplementary billing; when changes are made to a licence or the returns previously submitted and billed, we need to generate supplementary two-part tariff bill runs. We've already made several changes to support it, off the back of a [spike](#1412). That spike has shown us there are existing billing services, especially in supplementary billing, that we can reuse for two-part supplementary. This change moves them to make their reuse more transparent, while tweaking a few things to allow reuse.
- Loading branch information
1 parent
6f11e96
commit 7967091
Showing
14 changed files
with
267 additions
and
226 deletions.
There are no files selected for viewing
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
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
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
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
51 changes: 51 additions & 0 deletions
51
app/services/bill-runs/reverse-supplementary-transactions.service.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
'use strict' | ||
|
||
/** | ||
* Takes previously billed transactions and returns reversed and cleansed versions of them for supplementary billing | ||
* @module ReverseSupplementaryTransactionsService | ||
*/ | ||
|
||
const { generateUUID } = require('../../lib/general.lib.js') | ||
|
||
/** | ||
* Takes previously billed transactions and returns reversed and cleansed versions of them for supplementary billing | ||
* | ||
* In supplementary we need to "reverse" transactions. We start by identifying previous debit transactions that have not | ||
* been cancelled out by a previous credit transaction. | ||
* | ||
* We then "reverse" these previous debits as credits and compare them to the transactions generated as part of the | ||
* bill run currently in progress. | ||
* | ||
* If the "reversed" transaction matches the generated transaction, we know including both will just result in £0. | ||
* If like the legacy service we included them, it could lead to a zero value bill which our users hate! So, we drop\ | ||
* both from the bill run. | ||
* | ||
* Those reversed and generated transactions that don't match, are what gets included and eventually billed. | ||
* | ||
* This service takes the previous debit transactions and a bill licence ID, and returns a copy of them, but with | ||
* | ||
* - `credit` set to `true` | ||
* - `status` set to `candidate` | ||
* - `billLicenceId` set to the supplied ID | ||
* - `id` set to a new UUID | ||
* | ||
* @param {module:TransactionModel[]} transactions - The transactions to be reversed | ||
* @param {string} billLicenceId - The bill licence UUID these transactions are to be added to | ||
* | ||
* @returns {object[]} The "reversed" transactions | ||
*/ | ||
function go(transactions, billLicenceId) { | ||
return transactions.map((transaction) => { | ||
return { | ||
...transaction, | ||
id: generateUUID(), | ||
billLicenceId, | ||
credit: true, | ||
status: 'candidate' | ||
} | ||
}) | ||
} | ||
|
||
module.exports = { | ||
go | ||
} |
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
47 changes: 0 additions & 47 deletions
47
app/services/bill-runs/supplementary/reverse-transactions.service.js
This file was deleted.
Oops, something went wrong.
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
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
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
Oops, something went wrong.