-
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.
Remove Licence from bill 2PT bill run during review (#927)
https://eaflood.atlassian.net/browse/WATER-4216 On the licence review page add a button for “remove from bill run”. When clicked you should be presented with a confirmation page with a confirm button, when this is clicked the licence should be removed from the current bill run. Once the licence is removed the user should be returned to the bill run review page with a banner confirming the licence has been removed. When removed the licence will be flagged for two-part tariff supplementary billing.
- Loading branch information
Showing
20 changed files
with
848 additions
and
15 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
35 changes: 35 additions & 0 deletions
35
app/presenters/bill-runs/two-part-tariff/remove-bill-run-licence.presenter.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,35 @@ | ||
'use strict' | ||
|
||
/** | ||
* Formats the data ready for presenting in the remove bill run licence confirmation page | ||
* @module RemoveBillRunLicencePresenter | ||
*/ | ||
|
||
const { formatFinancialYear, formatLongDate } = require('../../base.presenter.js') | ||
|
||
/** | ||
* Formats the data ready for presenting in the remove bill run licence confirmation page | ||
* | ||
* @param {module:BillRunModel} billRun - an instance of `BillRunModel` | ||
* @param {string} licenceId - UUID of the licence to remove from the bill run | ||
* @param {string} licenceRef - the licence reference of the licence to remove from the bill run | ||
* | ||
* @returns {Object} - the prepared data to be passed to the remove licence template | ||
*/ | ||
function go (billRun, licenceId, licenceRef) { | ||
const { billRunNumber, createdAt, region, status, toFinancialYearEnding } = billRun | ||
|
||
return { | ||
pageTitle: `You're about to remove ${licenceRef} from the bill run`, | ||
backLink: `../review/${licenceId}`, | ||
billRunNumber, | ||
billRunStatus: status, | ||
dateCreated: formatLongDate(createdAt), | ||
financialYear: formatFinancialYear(toFinancialYearEnding), | ||
region | ||
} | ||
} | ||
|
||
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
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
53 changes: 53 additions & 0 deletions
53
app/services/bill-runs/two-part-tariff/remove-bill-run-licence.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,53 @@ | ||
'use strict' | ||
|
||
/** | ||
* Orchestrates fetching and presenting the data needed for the remove bill run licence confirmation page | ||
* @module RemoveBillRunLicenceService | ||
*/ | ||
|
||
const BillRunModel = require('../../../models/bill-run.model.js') | ||
const LicenceModel = require('../../../models/licence.model.js') | ||
const RemoveBillRunLicencePresenter = require('../../../presenters/bill-runs/two-part-tariff/remove-bill-run-licence.presenter.js') | ||
|
||
/** | ||
* Orchestrates fetching and presenting the data needed for the remove bill run licence confirmation page | ||
* | ||
* @param {string} billRunId - The UUID of the bill run that the licence is in | ||
* @param {string} licenceId - UUID of the licence to remove from the bill run | ||
* | ||
* @returns {Promise<Object}> an object representing the `pageData` needed by the remove licence template. It contains | ||
* details of the bill run & the licence reference. | ||
*/ | ||
async function go (billRunId, licenceId) { | ||
const billRun = await _fetchBillRun(billRunId) | ||
const licenceRef = await _fetchLicenceRef(licenceId) | ||
|
||
const pageData = RemoveBillRunLicencePresenter.go(billRun, licenceId, licenceRef) | ||
|
||
return pageData | ||
} | ||
|
||
async function _fetchBillRun (billRunId) { | ||
return BillRunModel.query() | ||
.findById(billRunId) | ||
.select( | ||
'billRuns.billRunNumber', | ||
'billRuns.createdAt', | ||
'billRuns.status', | ||
'billRuns.toFinancialYearEnding', | ||
'region.displayName as region' | ||
) | ||
.innerJoinRelated('region') | ||
} | ||
|
||
async function _fetchLicenceRef (licenceId) { | ||
const licence = await LicenceModel.query() | ||
.findById(licenceId) | ||
.select('licenceRef') | ||
|
||
return licence.licenceRef | ||
} | ||
|
||
module.exports = { | ||
go | ||
} |
86 changes: 86 additions & 0 deletions
86
app/services/bill-runs/two-part-tariff/remove-review-data.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,86 @@ | ||
'use strict' | ||
|
||
/** | ||
* Deletes all of the persisted data relating to the bill and licence from the review tables. | ||
* @module RemoveReviewDataService | ||
*/ | ||
|
||
const { db } = require('../../../../db/db.js') | ||
|
||
/** | ||
* Deletes all of the persisted data relating to the bill and licence from the review tables | ||
* | ||
* @param {string} billRunId - The UUID of the bill run that the licence is in | ||
* @param {string} licenceId - UUID of the licence to remove from the review tables | ||
*/ | ||
async function go (billRunId, licenceId) { | ||
await _removeChargeElementReturns(billRunId, licenceId) | ||
await _removeReturns(billRunId, licenceId) | ||
await _removeChargeElements(billRunId, licenceId) | ||
await _removeChargeReferences(billRunId, licenceId) | ||
await _removeChargeVersions(billRunId, licenceId) | ||
await _removeLicence(billRunId, licenceId) | ||
} | ||
|
||
async function _removeChargeElements (billRunId, licenceId) { | ||
return db | ||
.del() | ||
.from('reviewChargeElements AS rce') | ||
.innerJoin('reviewChargeReferences AS rcr', 'rce.reviewChargeReferenceId', 'rcr.id') | ||
.innerJoin('reviewChargeVersions AS rcv', 'rcr.reviewChargeVersionId', 'rcv.id') | ||
.innerJoin('reviewLicences AS rl', 'rcv.reviewLicenceId', 'rl.id') | ||
.where('rl.billRunId', billRunId) | ||
.andWhere('rl.licenceId', licenceId) | ||
} | ||
|
||
async function _removeChargeElementReturns (billRunId, licenceId) { | ||
return db | ||
.del() | ||
.from('reviewChargeElementsReturns AS rcer') | ||
.innerJoin('reviewChargeElements AS rce', 'rcer.reviewChargeElementId', 'rce.id') | ||
.innerJoin('reviewChargeReferences AS rcr', 'rce.reviewChargeReferenceId', 'rcr.id') | ||
.innerJoin('reviewChargeVersions AS rcv', 'rcr.reviewChargeVersionId', 'rcv.id') | ||
.innerJoin('reviewLicences AS rl', 'rcv.reviewLicenceId', 'rl.id') | ||
.where('rl.billRunId', billRunId) | ||
.andWhere('rl.licenceId', licenceId) | ||
} | ||
|
||
async function _removeChargeReferences (billRunId, licenceId) { | ||
return db | ||
.del() | ||
.from('reviewChargeReferences AS rcr') | ||
.innerJoin('reviewChargeVersions AS rcv', 'rcr.reviewChargeVersionId', 'rcv.id') | ||
.innerJoin('reviewLicences AS rl', 'rcv.reviewLicenceId', 'rl.id') | ||
.where('rl.billRunId', billRunId) | ||
.andWhere('rl.licenceId', licenceId) | ||
} | ||
|
||
async function _removeChargeVersions (billRunId, licenceId) { | ||
return db | ||
.del() | ||
.from('reviewChargeVersions AS rcv') | ||
.innerJoin('reviewLicences AS rl', 'rcv.reviewLicenceId', 'rl.id') | ||
.where('rl.billRunId', billRunId) | ||
.andWhere('rl.licenceId', licenceId) | ||
} | ||
|
||
async function _removeLicence (billRunId, licenceId) { | ||
return db | ||
.del() | ||
.from('reviewLicences') | ||
.where('billRunId', billRunId) | ||
.andWhere('licenceId', licenceId) | ||
} | ||
|
||
async function _removeReturns (billRunId, licenceId) { | ||
return db | ||
.del() | ||
.from('reviewReturns AS rr') | ||
.innerJoin('reviewLicences AS rl', 'rr.reviewLicenceId', 'rl.id') | ||
.where('rl.billRunId', billRunId) | ||
.andWhere('rl.licenceId', licenceId) | ||
} | ||
|
||
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
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.