Skip to content

Commit

Permalink
Add abs period to returns on two-part tariff review page (#1161)
Browse files Browse the repository at this point in the history
https://eaflood.atlassian.net/browse/WATER-4550

While testing the two-part tariff review pages, the business identified difficulties looking up the abstraction period for the matching returns. They requested a change where the abstraction period for all returns is displayed underneath the return's description. This PR is making that change.
  • Loading branch information
Beckyrose200 authored Jul 4, 2024
1 parent a443153 commit b7aa822
Show file tree
Hide file tree
Showing 14 changed files with 175 additions and 21 deletions.
8 changes: 8 additions & 0 deletions app/models/review-return.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ class ReviewReturnModel extends BaseModel {
to: 'reviewLicences.id'
}
},
returnLog: {
relation: Model.BelongsToOneRelation,
modelClass: 'return-log.model',
join: {
from: 'reviewReturns.returnId',
to: 'returnLogs.id'
}
},
reviewChargeElements: {
relation: Model.ManyToManyRelation,
modelClass: 'review-charge-element.model',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

const DetermineAbstractionPeriodService = require('../../../services/bill-runs/determine-abstraction-periods.service.js')
const { formatLongDate } = require('../../base.presenter.js')
const { formatAbstractionPeriod, formatLongDate } = require('../../base.presenter.js')

/**
* Prepares and processes bill run and review charge element and returns data for presentation
Expand Down Expand Up @@ -49,6 +49,12 @@ function _financialYear (financialYearEnding) {
return `${startYear} to ${endYear}`
}

function _prepareAbsPeriod (returnLog) {
const { periodStartDay, periodStartMonth, periodEndDay, periodEndMonth } = returnLog

return formatAbstractionPeriod(periodStartDay, periodStartMonth, periodEndDay, periodEndMonth)
}

function _matchedReturns (reviewReturns) {
const matchedReturns = []

Expand All @@ -64,7 +70,8 @@ function _matchedReturns (reviewReturns) {
returnStatus: _returnStatus(returnLog),
returnTotal,
issues: returnLog.issues?.length > 0 ? returnLog.issues.split(', ') : [''],
returnLink
returnLink,
absPeriod: _prepareAbsPeriod(returnLog.returnLog)
})
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
const Big = require('big.js')

const DetermineAbstractionPeriodService = require('../../../services/bill-runs/determine-abstraction-periods.service.js')
const { formatLongDate } = require('../../base.presenter.js')
const { formatAbstractionPeriod, formatLongDate } = require('../../base.presenter.js')

/**
* Formats the review licence data ready for presenting in the review licence page
Expand Down Expand Up @@ -166,7 +166,8 @@ function _matchedReturns (returnLogs) {
purpose: returnLog.purposes[0].tertiary.description,
returnTotal: _returnTotal(returnLog),
issues: returnLog.issues.length > 0 ? returnLog.issues.split(', ') : [''],
returnLink: _returnLink(returnLog)
returnLink: _returnLink(returnLog),
absPeriod: _prepareAbsPeriod(returnLog.returnLog)
}
)
}
Expand All @@ -175,6 +176,12 @@ function _matchedReturns (returnLogs) {
return matchedReturns
}

function _prepareAbsPeriod (returnLog) {
const { periodStartDay, periodStartMonth, periodEndDay, periodEndMonth } = returnLog

return formatAbstractionPeriod(periodStartDay, periodStartMonth, periodEndDay, periodEndMonth)
}

function _prepareChargeData (licence, billRun) {
const chargeData = []

Expand Down Expand Up @@ -303,7 +310,8 @@ function _unmatchedReturns (returnLogs) {
purpose: returnLog.purposes[0].tertiary.description,
returnTotal: `${returnLog.allocated} / ${returnLog.quantity} ML`,
issues: returnLog.issues.length > 0 ? returnLog.issues.split(', ') : [''],
returnLink: _returnLink(returnLog)
returnLink: _returnLink(returnLog),
absPeriod: _prepareAbsPeriod(returnLog.returnLog)
}
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* @module FetchMatchDetailsService
*/

const { ref } = require('objection')

const BillRunModel = require('../../../models/bill-run.model.js')
const ReviewChargeElementModel = require('../../../models/review-charge-element.model.js')

Expand Down Expand Up @@ -36,6 +38,14 @@ async function _fetchReviewChargeElement (reviewChargeElementId) {
return ReviewChargeElementModel.query()
.findById(reviewChargeElementId)
.withGraphFetched('reviewReturns')
.withGraphFetched('reviewReturns.returnLog')
.modifyGraph('reviewReturns.returnLog', (builder) => {
builder.select([
ref('metadata:nald.periodStartDay').castInt().as('periodStartDay'),
ref('metadata:nald.periodStartMonth').castInt().as('periodStartMonth'),
ref('metadata:nald.periodEndDay').castInt().as('periodEndDay'),
ref('metadata:nald.periodEndMonth').castInt().as('periodEndMonth')])
})
.withGraphFetched('chargeElement')
.modifyGraph('chargeElement', (builder) => {
builder.select([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* @module FetchReviewLicenceResultsService
*/

const { ref } = require('objection')

const BillRunModel = require('../../../models/bill-run.model.js')
const FetchBillingAccountService = require('../../fetch-billing-account.service.js')
const ReviewLicenceModel = require('../../../models/review-licence.model.js')
Expand All @@ -20,6 +22,7 @@ const ReviewLicenceModel = require('../../../models/review-licence.model.js')
async function go (billRunId, licenceId) {
const billRun = await _fetchBillRun(billRunId)
const licence = await _fetchReviewLicence(licenceId, billRunId)

await _fetchBillingAccountDetails(licence[0].reviewChargeVersions)

return { billRun, licence }
Expand Down Expand Up @@ -72,6 +75,14 @@ async function _fetchReviewLicence (licenceId, billRunId) {
.modifyGraph('reviewReturns', (builder) => {
builder.orderBy('reviewReturns.startDate', 'asc')
})
.withGraphFetched('reviewReturns.returnLog')
.modifyGraph('reviewReturns.returnLog', (builder) => {
builder.select([
ref('metadata:nald.periodStartDay').castInt().as('periodStartDay'),
ref('metadata:nald.periodStartMonth').castInt().as('periodStartMonth'),
ref('metadata:nald.periodEndDay').castInt().as('periodEndDay'),
ref('metadata:nald.periodEndMonth').castInt().as('periodEndMonth')])
})
.withGraphFetched('reviewChargeVersions')
.modifyGraph('reviewChargeVersions', (builder) => {
builder
Expand Down
3 changes: 2 additions & 1 deletion app/views/bill-runs/match-details.njk
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@
{% set action %}
<a class="govuk-link" href="{{return.returnLink}}">{{ return.reference }}<span class="govuk-visually-hidden"></a>
<div>{{ return.dates }}</div>
<div>{{return.absPeriod}}</div>
{% endset %}

{% set returnSummary %}
Expand Down Expand Up @@ -204,7 +205,7 @@
firstCellIsHeader: false,
head: [
{
text: 'Return reference and dates'
text: 'Return reference and periods'
},
{
text: 'Purpose and description'
Expand Down
6 changes: 4 additions & 2 deletions app/views/bill-runs/review-licence.njk
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@
{% set action %}
<a class="govuk-link" href="{{return.returnLink}}">{{ return.reference }}<span class="govuk-visually-hidden"></a>
<div>{{return.dates}}</div>
<div>{{return.absPeriod}}</div>
{% endset %}

{% set returnSummary %}
Expand Down Expand Up @@ -231,7 +232,7 @@
firstCellIsHeader: false,
head: [
{
text: 'Return reference and dates'
text: 'Return reference and periods'
},
{
text: 'Purpose and description'
Expand All @@ -258,6 +259,7 @@
{% set action %}
<a class="govuk-link" href="{{return.returnLink}}">{{ return.reference }}<span class="govuk-visually-hidden"></a>
<div>{{return.dates}}</div>
<div>{{return.absPeriod}}</div>
{% endset %}

{% set returnSummary %}
Expand Down Expand Up @@ -311,7 +313,7 @@
firstCellIsHeader: false,
head: [
{
text: 'Return reference and dates'
text: 'Return reference and periods'
},
{
text: 'Purpose and description'
Expand Down
35 changes: 35 additions & 0 deletions test/models/review-return.model.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const { expect } = Code

// Test helpers
const DatabaseSupport = require('../support/database.js')
const ReturnLogHelper = require('../support/helpers/return-log.helper.js')
const ReturnLogModel = require('../../app/models/return-log.model.js')
const ReviewChargeElementHelper = require('../support/helpers/review-charge-element.helper.js')
const ReviewChargeElementModel = require('../../app/models/review-charge-element.model.js')
const ReviewLicenceHelper = require('../support/helpers/review-licence.helper.js')
Expand Down Expand Up @@ -47,6 +49,7 @@ describe('Review Return model', () => {
testReviewLicence = await ReviewLicenceHelper.add()

const { id: reviewLicenceId } = testReviewLicence

testRecord = await ReviewReturnHelper.add({ reviewLicenceId })
})

Expand All @@ -70,6 +73,37 @@ describe('Review Return model', () => {
})
})

describe('when linking to return log', () => {
let testReturnLog

beforeEach(async () => {
testReturnLog = await ReturnLogHelper.add()

const { id: returnId } = testReturnLog

testRecord = await ReviewReturnHelper.add({ returnId })
})

it('can successfully run a related query', async () => {
const query = await ReviewReturnModel.query()
.innerJoinRelated('returnLog')

expect(query).to.exist()
})

it('can eager load the return log', async () => {
const result = await ReviewReturnModel.query()
.findById(testRecord.id)
.withGraphFetched('returnLog')

expect(result).to.be.instanceOf(ReviewReturnModel)
expect(result.id).to.equal(testRecord.id)

expect(result.returnLog).to.be.an.instanceOf(ReturnLogModel)
expect(result.returnLog).to.equal(testReturnLog)
})
})

describe('when linking to review charge elements', () => {
let testReviewChargeElements

Expand All @@ -80,6 +114,7 @@ describe('Review Return model', () => {
testReviewChargeElements = []
for (let i = 0; i < 2; i++) {
const testReviewChargeElement = await ReviewChargeElementHelper.add()

testReviewChargeElements.push(testReviewChargeElement)

await ReviewChargeElementReturnHelper.add({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ describe('Match Details presenter', () => {
returnStatus: 'completed',
returnTotal: '0 ML / 0 ML',
issues: [''],
returnLink: '/returns/return?id=v1:1:01/57/14/1646:15584914:2022-04-01:2023-03-31'
returnLink: '/returns/return?id=v1:1:01/57/14/1646:15584914:2022-04-01:2023-03-31',
absPeriod: '1 April to 31 March'
}
]
})
Expand Down Expand Up @@ -93,7 +94,13 @@ function _reviewChargeElementData () {
endDate: new Date('2022-05-06'),
issues: null,
createdAt: new Date('2024-04-02'),
updatedAt: new Date('2024-04-02')
updatedAt: new Date('2024-04-02'),
returnLog: {
periodEndDay: 31,
periodEndMonth: 3,
periodStartDay: 1,
periodStartMonth: 4
}
}
],
chargeElement: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ describe('Review Licence presenter', () => {
purpose: 'Site description',
returnTotal: '0 ML / 0 ML',
issues: [''],
returnLink: '/returns/return?id=v1:1:01/60/28/3437:17061181:2022-04-01:2023-03-31'
returnLink: '/returns/return?id=v1:1:01/60/28/3437:17061181:2022-04-01:2023-03-31',
absPeriod: '1 April to 31 March'
}
],
unmatchedReturns: [
Expand All @@ -57,7 +58,8 @@ describe('Review Licence presenter', () => {
returnId: 'v2:1:01/60/28/3437:17061181:2022-04-01:2023-03-31',
returnLink: '/returns/return?id=v2:1:01/60/28/3437:17061181:2022-04-01:2023-03-31',
returnStatus: 'completed',
returnTotal: '0 / 0 ML'
returnTotal: '0 / 0 ML',
absPeriod: '1 April to 31 March'
}
],
chargeData: [
Expand Down Expand Up @@ -286,7 +288,13 @@ function _licenceData () {
chargeDatesOverlap: false,
issues: '',
status: 'ready'
}]
}],
returnLog: {
periodStartDay: 1,
periodStartMonth: 4,
periodEndDay: 31,
periodEndMonth: 3
}
},
{
id: '4864f643-5c16-5ca9-8512-f63e1d4e58be',
Expand All @@ -310,7 +318,13 @@ function _licenceData () {
startDate: new Date(' 2022-04-01'),
endDate: new Date('2022-05-06'),
issues: '',
reviewChargeElements: []
reviewChargeElements: [],
returnLog: {
periodStartDay: 1,
periodStartMonth: 4,
periodEndDay: 31,
periodEndMonth: 3
}
}],
reviewChargeVersions: [{
id: '3de5634a-da26-4241-87e9-7248a4b83a69',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const BillRunHelper = require('../../../support/helpers/bill-run.helper.js')
const ChargeElementHelper = require('../../../support/helpers/charge-element.helper.js')
const ChargeReferenceHelper = require('../../../support/helpers/charge-reference.helper.js')
const DatabaseSupport = require('../../../support/database.js')
const ReturnLogHelper = require('../../../support/helpers/return-log.helper.js')
const ReviewChargeElementHelper = require('../../../support/helpers/review-charge-element.helper.js')
const ReviewChargeElementReturnHelper = require('../../../support/helpers/review-charge-element-return.helper.js')
const ReviewChargeReferenceHelper = require('../../../support/helpers/review-charge-reference.helper.js')
Expand Down Expand Up @@ -44,6 +45,7 @@ describe('Fetch Match Details service', () => {
let chargeReference
let reviewChargeVersion
let reviewChargeReference
let returnLog

beforeEach(async () => {
reviewChargeVersion = await ReviewChargeVersionHelper.add()
Expand All @@ -62,7 +64,17 @@ describe('Fetch Match Details service', () => {
let reviewReturn

beforeEach(async () => {
reviewReturn = await ReviewReturnHelper.add()
const metadata = {
nald: {
periodEndDay: 30,
periodEndMonth: 9,
periodStartDay: 1,
periodStartMonth: 4
}
}

returnLog = await ReturnLogHelper.add({ metadata })
reviewReturn = await ReviewReturnHelper.add({ returnId: returnLog.id })

await ReviewChargeElementReturnHelper.add({
reviewChargeElementId: reviewChargeElement.id,
Expand Down Expand Up @@ -114,7 +126,13 @@ describe('Fetch Match Details service', () => {
endDate: reviewReturn.endDate,
issues: reviewReturn.issues,
createdAt: reviewReturn.createdAt,
updatedAt: reviewReturn.updatedAt
updatedAt: reviewReturn.updatedAt,
returnLog: {
periodEndDay: returnLog.metadata.nald.periodEndDay,
periodEndMonth: returnLog.metadata.nald.periodEndMonth,
periodStartDay: returnLog.metadata.nald.periodStartDay,
periodStartMonth: returnLog.metadata.nald.periodStartMonth
}
}
],
chargeElement: {
Expand Down
Loading

0 comments on commit b7aa822

Please sign in to comment.