-
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.
Merge branch 'main' into WATER-4386-returns-required-journey-check-yo…
…ur-requirements-page-with-requirements-summary-cards
- Loading branch information
Showing
35 changed files
with
2,122 additions
and
133 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
58 changes: 58 additions & 0 deletions
58
app/presenters/bill-runs/two-part-tariff/amend-authorised-volume.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,58 @@ | ||
'use strict' | ||
|
||
/** | ||
* Formats the two part tariff review data ready for presenting in the amend authorised volume page | ||
* @module AmendAuthorisedVolumePresenter | ||
*/ | ||
|
||
const { formatLongDate, formatFinancialYear } = require('../../base.presenter.js') | ||
|
||
/** | ||
* Prepares and processes bill run and review charge reference data for presenting | ||
* | ||
* @param {module:BillRunModel} billRun - the data from the bill run | ||
* @param {module:ReviewChargeReference} reviewChargeReference - the data from the review charge reference | ||
* @param {String} licenceId - the UUID of the licence being reviewed | ||
* | ||
* @returns {Object} the prepared bill run and charge reference data to be passed to the amend authorised volume page | ||
*/ | ||
function go (billRun, reviewChargeReference, licenceId) { | ||
return { | ||
billRunId: billRun.id, | ||
licenceId, | ||
financialYear: formatFinancialYear(billRun.toFinancialYearEnding), | ||
chargePeriod: _prepareDate( | ||
reviewChargeReference.reviewChargeVersion.chargePeriodStartDate, | ||
reviewChargeReference.reviewChargeVersion.chargePeriodEndDate | ||
), | ||
chargeReference: { | ||
id: reviewChargeReference.id, | ||
description: reviewChargeReference.chargeReference.chargeCategory.shortDescription, | ||
authorisedVolume: reviewChargeReference.amendedAuthorisedVolume, | ||
totalBillableReturns: _totalBillableReturns(reviewChargeReference.reviewChargeElements) | ||
}, | ||
chargeCategory: { | ||
minVolume: reviewChargeReference.chargeReference.chargeCategory.minVolume, | ||
maxVolume: reviewChargeReference.chargeReference.chargeCategory.maxVolume | ||
} | ||
} | ||
} | ||
|
||
function _prepareDate (startDate, endDate) { | ||
const preparedStartDate = formatLongDate(startDate) | ||
const preparedEndDate = formatLongDate(endDate) | ||
|
||
return `${preparedStartDate} to ${preparedEndDate}` | ||
} | ||
|
||
function _totalBillableReturns (reviewChargeElements) { | ||
return reviewChargeElements.reduce((total, reviewChargeElement) => { | ||
total += reviewChargeElement.amendedAllocated | ||
|
||
return total | ||
}, 0) | ||
} | ||
|
||
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
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
30 changes: 30 additions & 0 deletions
30
app/services/bill-runs/two-part-tariff/amend-authorised-volume.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,30 @@ | ||
'use strict' | ||
|
||
/** | ||
* Orchestrates fetching and presenting the data needed for the amend authorised volume page | ||
* @module AmendAuthorisedVolumeService | ||
*/ | ||
|
||
const AmendAuthorisedVolumePresenter = require('../../../presenters/bill-runs/two-part-tariff/amend-authorised-volume.presenter.js') | ||
const FetchAuthorisedVolumeService = require('./fetch-authorised-volume.service.js') | ||
|
||
/** | ||
* Orchestrates fetching and presenting the data needed for the amend authorised volume page | ||
* | ||
* @param {String} billRunId - The UUID for the bill run | ||
* @param {String} licenceId - The UUID of the licence that is being reviewed | ||
* @param {String} reviewChargeReferenceId - The UUID of the review charge reference being viewed | ||
* | ||
* @returns {Promise<Object>} the 'pageData' needed to view the amend authorised volume page | ||
*/ | ||
async function go (billRunId, licenceId, reviewChargeReferenceId) { | ||
const { billRun, reviewChargeReference } = await FetchAuthorisedVolumeService.go(billRunId, reviewChargeReferenceId) | ||
|
||
const pageData = AmendAuthorisedVolumePresenter.go(billRun, reviewChargeReference, licenceId) | ||
|
||
return pageData | ||
} | ||
|
||
module.exports = { | ||
go | ||
} |
70 changes: 70 additions & 0 deletions
70
app/services/bill-runs/two-part-tariff/fetch-authorised-volume.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,70 @@ | ||
'use strict' | ||
|
||
/** | ||
* Fetches the individual charge reference details when the authorised volume is being amended for a two-part tariff | ||
* bill run | ||
* @module FetchAuthorisedVolumeService | ||
*/ | ||
|
||
const BillRunModel = require('../../../models/bill-run.model.js') | ||
const ReviewChargeReferenceModel = require('../../../models/review-charge-reference.model.js') | ||
|
||
/** | ||
* Fetches the charge reference details for an individual licence | ||
* | ||
* @param {String} billRunId - UUID of the bill run | ||
* @param {String} reviewChargeReferenceId - The UUID of the review charge reference being viewed | ||
* | ||
* @returns {Promise<Object>} An object containing the bill run and review charge reference instances | ||
*/ | ||
async function go (billRunId, reviewChargeReferenceId) { | ||
const billRun = await _fetchBillRun(billRunId) | ||
const reviewChargeReference = await _fetchReviewChargeReference(reviewChargeReferenceId) | ||
|
||
return { billRun, reviewChargeReference } | ||
} | ||
|
||
async function _fetchBillRun (billRunId) { | ||
return BillRunModel.query() | ||
.findById(billRunId) | ||
.select( | ||
'id', | ||
'toFinancialYearEnding') | ||
} | ||
|
||
async function _fetchReviewChargeReference (reviewChargeReferenceId) { | ||
return ReviewChargeReferenceModel.query() | ||
.findById(reviewChargeReferenceId) | ||
.select('id', 'amendedAuthorisedVolume') | ||
.withGraphFetched('chargeReference') | ||
.modifyGraph('chargeReference', (builder) => { | ||
builder.select([ | ||
'chargeCategoryId' | ||
]) | ||
}) | ||
.withGraphFetched('chargeReference.chargeCategory') | ||
.modifyGraph('chargeReference.chargeCategory', (builder) => { | ||
builder.select([ | ||
'shortDescription', | ||
'minVolume', | ||
'maxVolume' | ||
]) | ||
}) | ||
.withGraphFetched('reviewChargeVersion') | ||
.modifyGraph('reviewChargeVersion', (builder) => { | ||
builder.select([ | ||
'chargePeriodStartDate', | ||
'chargePeriodEndDate' | ||
]) | ||
}) | ||
.withGraphFetched('reviewChargeElements') | ||
.modifyGraph('reviewChargeElements', (builder) => { | ||
builder.select([ | ||
'amendedAllocated' | ||
]) | ||
}) | ||
} | ||
|
||
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
Oops, something went wrong.