Skip to content

Commit

Permalink
Merge branch 'main' into WATER-4386-returns-required-journey-check-yo…
Browse files Browse the repository at this point in the history
…ur-requirements-page-with-requirements-summary-cards
  • Loading branch information
jonathangoulding authored May 29, 2024
2 parents 18867cc + a7ff364 commit b91e884
Show file tree
Hide file tree
Showing 35 changed files with 2,122 additions and 133 deletions.
33 changes: 33 additions & 0 deletions app/controllers/bill-runs.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
const Boom = require('@hapi/boom')

const AmendAdjustmentFactorService = require('../services/bill-runs/two-part-tariff/amend-adjustment-factor.service.js')
const AmendAuthorisedVolumeService = require('../services/bill-runs/two-part-tariff/amend-authorised-volume.service.js')
const AmendBillableReturnsService = require('../services/bill-runs/two-part-tariff/amend-billable-returns.service.js')
const CancelBillRunService = require('../services/bill-runs/cancel-bill-run.service.js')
const ChargeReferenceDetailsService = require('../services/bill-runs/two-part-tariff/charge-reference-details.service.js')
Expand All @@ -20,6 +21,7 @@ const ReviewLicenceService = require('../services/bill-runs/two-part-tariff/revi
const SendBillRunService = require('../services/bill-runs/send-bill-run.service.js')
const StartBillRunProcessService = require('../services/bill-runs/start-bill-run-process.service.js')
const SubmitAmendedAdjustmentFactorService = require('../services/bill-runs/two-part-tariff/submit-amended-adjustment-factor.service.js')
const SubmitAmendedAuthorisedVolumeService = require('../services/bill-runs/two-part-tariff/submit-amended-authorised-volume.service.js')
const SubmitAmendedBillableReturnsService = require('..//services/bill-runs/two-part-tariff/submit-amended-billable-returns.service.js')
const SubmitCancelBillRunService = require('../services/bill-runs/submit-cancel-bill-run.service.js')
const SubmitRemoveBillRunLicenceService = require('../services/bill-runs/two-part-tariff/submit-remove-bill-run-licence.service.js')
Expand All @@ -40,6 +42,18 @@ async function amendAdjustmentFactor (request, h) {
})
}

async function amendAuthorisedVolume (request, h) {
const { id: billRunId, licenceId, reviewChargeReferenceId } = request.params

const pageData = await AmendAuthorisedVolumeService.go(billRunId, licenceId, reviewChargeReferenceId)

return h.view('bill-runs/amend-authorised-volume.njk', {
pageTitle: 'Set the authorised volume',
activeNavBar: 'bill-runs',
...pageData
})
}

async function amendBillableReturns (request, h) {
const { id: billRunId, licenceId, reviewChargeElementId } = request.params

Expand Down Expand Up @@ -180,6 +194,23 @@ async function submitAmendedAdjustmentFactor (request, h) {
return h.redirect(`/system/bill-runs/${billRunId}/review/${licenceId}/charge-reference-details/${reviewChargeReferenceId}`)
}

async function submitAmendedAuthorisedVolume (request, h) {
const { id: billRunId, licenceId, reviewChargeReferenceId } = request.params
const pageData = await SubmitAmendedAuthorisedVolumeService.go(
billRunId,
licenceId,
reviewChargeReferenceId,
request.payload,
request.yar
)

if (pageData.error) {
return h.view('bill-runs/amend-authorised-volume.njk', pageData)
}

return h.redirect(`/system/bill-runs/${billRunId}/review/${licenceId}/charge-reference-details/${reviewChargeReferenceId}`)
}

async function submitAmendedBillableReturns (request, h) {
const { id: billRunId, licenceId, reviewChargeElementId } = request.params

Expand Down Expand Up @@ -268,6 +299,7 @@ async function view (request, h) {

module.exports = {
amendAdjustmentFactor,
amendAuthorisedVolume,
amendBillableReturns,
cancel,
chargeReferenceDetails,
Expand All @@ -279,6 +311,7 @@ module.exports = {
reviewLicence,
send,
submitAmendedAdjustmentFactor,
submitAmendedAuthorisedVolume,
submitAmendedBillableReturns,
submitCancel,
submitReview,
Expand Down
8 changes: 8 additions & 0 deletions app/controllers/data.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* @module DataController
*/

const LoadService = require('../services/data/load/load.service.js')
const SeedService = require('../services/data/seed/seed.service.js')
const SubmitDeduplicateService = require('../services/data/deduplicate/submit-deduplicate.service.js')
const TearDownService = require('../services/data/tear-down/tear-down.service.js')
Expand All @@ -16,6 +17,12 @@ async function deduplicate (_request, h) {
})
}

async function load (request, h) {
const result = await LoadService.go(request.payload)

return h.response(result).code(200)
}

async function seed (_request, h) {
await SeedService.go()

Expand Down Expand Up @@ -44,6 +51,7 @@ async function tearDown (_request, h) {

module.exports = {
deduplicate,
load,
seed,
submitDeduplicate,
tearDown
Expand Down
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
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function go (billRun, reviewChargeReference, licenceId) {
reference: reviewChargeReference.chargeReference.chargeCategory.reference,
description: reviewChargeReference.chargeReference.chargeCategory.shortDescription,
totalBillableReturns: _totalBillableReturns(reviewChargeReference.reviewChargeElements),
authorisedVolume: reviewChargeReference.chargeReference.volume,
authorisedVolume: reviewChargeReference.amendedAuthorisedVolume,
adjustments,
additionalCharges: _additionalCharges(reviewChargeReference.chargeReference)
},
Expand Down
3 changes: 1 addition & 2 deletions app/presenters/licences/set-up.presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
const { formatLongDate } = require('../base.presenter.js')

const roles = {
billing: 'billing',
workflowEditor: 'charge_version_workflow_editor',
workflowReviewer: 'charge_version_workflow_reviewer'
}
Expand Down Expand Up @@ -81,7 +80,7 @@ function _endsSixYearsAgo (endDate) {
const sixYearsFromYesterday = new Date(yesterday.getTime())
sixYearsFromYesterday.setFullYear(yesterday.getFullYear() - sixYears)

return endDate < sixYearsFromYesterday
return endDate.date < sixYearsFromYesterday
}

function _status (status) {
Expand Down
26 changes: 26 additions & 0 deletions app/routes/bill-runs.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,32 @@ const routes = [
description: 'Review a charge reference from a two-part tariff licence'
}
},
{
method: 'GET',
path: '/bill-runs/{id}/review/{licenceId}/charge-reference-details/{reviewChargeReferenceId}/amend-authorised-volume',
handler: BillRunsController.amendAuthorisedVolume,
options: {
auth: {
access: {
scope: ['billing']
}
},
description: 'Amend a charge references authorised volume from a two-part tariff licence'
}
},
{
method: 'POST',
path: '/bill-runs/{id}/review/{licenceId}/charge-reference-details/{reviewChargeReferenceId}/amend-authorised-volume',
handler: BillRunsController.submitAmendedAuthorisedVolume,
options: {
auth: {
access: {
scope: ['billing']
}
},
description: 'Submit the amended charge references authorised volume from a two-part tariff licence'
}
},
{
method: 'GET',
path: '/bill-runs/{id}/review/{licenceId}/charge-reference-details/{reviewChargeReferenceId}/amend-adjustment-factor',
Expand Down
13 changes: 13 additions & 0 deletions app/routes/data.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@ const routes = [
description: 'Submit licence to be de-duped'
}
},
{
method: 'POST',
path: '/data/load',
handler: DataController.load,
options: {
app: {
excludeFromProd: true,
plainOutput: true
},
auth: false,
description: 'Used to load test data in the database'
}
},
{
method: 'POST',
path: '/data/seed',
Expand Down
2 changes: 1 addition & 1 deletion app/routes/licence.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const routes = [
options: {
auth: {
access: {
scope: ['billing']
scope: ['view_charge_versions']
}
},
description: 'View a licence set up page'
Expand Down
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
}
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
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ async function _fetchBillRun (billRunId) {
.findById(billRunId)
.select(
'id',
'fromFinancialYearEnding',
'toFinancialYearEnding')
}

Expand Down
Loading

0 comments on commit b91e884

Please sign in to comment.