Skip to content

Commit

Permalink
Amend bill count in bill run view for zero value (#602)
Browse files Browse the repository at this point in the history
https://eaflood.atlassian.net/browse/WATER-4223

In testing of the new bill run view we've built a scenario was found where the count of bills we show didn't match with the number of bills on the page.

For example, the bill run had 6 credit notes and 4 invoices so we displayed "10 Supplementary bills" as the caption. But when you counted the bills listed there were 11.

We double-checked what the legacy UI was doing with this bill run and found it also displayed 6 credits and 4 invoices. But its caption was "11 supplementary bills".

Neither looks right!

After digging in we found the extra bill is a 'zero value' bill (where the credit and debit lines have value but they cancel each other out). These don't get sent to SSCL so are not included in the credit note and invoice count.

After consultation with users, they don't want these to be included in the credit note or invoice count as this will mess up their reconciliation process. But they would like the total count to be correct. The agreed solution is that when a bill run contains zero-value bills we should extend the caption, for example, "10 Supplementary bills and 1 zero value bill".

This change implements that solution.
  • Loading branch information
Cruikshanks authored Dec 16, 2023
1 parent f45f182 commit fbae6f7
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 31 deletions.
26 changes: 22 additions & 4 deletions app/presenters/bill-runs/view-bill-run.presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const {
formatMoney
} = require('../base.presenter.js')

function go (billRun) {
function go (billRun, billSummaries) {
const {
batchType,
billRunNumber,
Expand All @@ -34,7 +34,7 @@ function go (billRun) {
const regionName = capitalize(region.displayName)

return {
billsCount: _billsCount(creditNoteCount, invoiceCount, billRunType),
billsCount: _billsCount(creditNoteCount, invoiceCount, billRunType, billSummaries),
billRunId: id,
billRunNumber,
billRunStatus: status,
Expand All @@ -54,14 +54,32 @@ function go (billRun) {
}
}

function _billsCount (creditsCount, debitsCount, billRunType) {
function _billsCount (creditsCount, debitsCount, billRunType, billSummaries) {
const total = creditsCount + debitsCount

// NOTE: A bill run wouldn't exist if there was just a single zero value bill on it. So, we can safely assume if the
// total is 1 it's not for a zero value bill and we can immediately return.
if (total === 1) {
return `1 ${billRunType} bill`
}

return `${total} ${billRunType} bills`
const numberOfZeroValueBills = billSummaries.reduce((count, billSummary) => {
if (billSummary.netAmount === 0) {
count += 1
}

return count
}, 0)

if (numberOfZeroValueBills === 0) {
return `${total} ${billRunType} bills`
}

if (numberOfZeroValueBills === 1) {
return `${total} ${billRunType} bills and 1 zero value bill`
}

return `${total} ${billRunType} bills and ${numberOfZeroValueBills} zero value bills`
}

function _billRunTotal (valueInPence) {
Expand Down
2 changes: 1 addition & 1 deletion app/services/bill-runs/view-bill-run.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const FetchBillRunService = require('./fetch-bill-run.service.js')
async function go (id) {
const result = await FetchBillRunService.go(id)

const billRun = ViewBillRunPresenter.go(result.billRun)
const billRun = ViewBillRunPresenter.go(result.billRun, result.billSummaries)
const billGroups = ViewBillSummariesPresenter.go(result.billSummaries)

return {
Expand Down
109 changes: 83 additions & 26 deletions test/presenters/bill-runs/view-bill-run.presenter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ const ViewBillRunPresenter = require('../../../app/presenters/bill-runs/view-bil

describe('View Bill Run presenter', () => {
let billRun
let billSummaries

describe('when provided with a populated bill run', () => {
beforeEach(() => {
billRun = _testBillRun()
billSummaries = _testBillSummaries()
})

it('correctly presents the data', () => {
const result = ViewBillRunPresenter.go(billRun)
const result = ViewBillRunPresenter.go(billRun, billSummaries)

expect(result).to.equal({
billsCount: '8 Supplementary bills',
Expand All @@ -43,38 +45,66 @@ describe('View Bill Run presenter', () => {
})

describe("the 'billsCount' property", () => {
// NOTE: We have no tests for zero value bills in this scenario because a bill run won't exist if it just contains
// a single zero value bill. So, if there is only one bill it must be a credit or an invoice
describe('when the sum of the invoice and credit count is 1', () => {
beforeEach(() => {
billRun.creditNoteCount = 0
billRun.invoiceCount = 1
})

it('returns to sum plus the bill run type as singular (1 Supplementary bill)', () => {
const result = ViewBillRunPresenter.go(billRun)
it('returns 1 plus the bill run type as singular (1 Supplementary bill)', () => {
const result = ViewBillRunPresenter.go(billRun, billSummaries)

expect(result.billsCount).to.equal('1 Supplementary bill')
})
})

describe('when the sum of the invoice and credit count is more than 1', () => {
beforeEach(() => {
billRun.batchType = 'annual'
billRun.creditNoteCount = 5
billRun.invoiceCount = 7
})

it('returns to sum plus the bill run type pluralised (12 Annual bills)', () => {
const result = ViewBillRunPresenter.go(billRun)
describe('and there are no zero value bills', () => {
it('returns the sum plus the bill run type pluralised (12 Supplementary bills)', () => {
const result = ViewBillRunPresenter.go(billRun, billSummaries)

expect(result.billsCount).to.equal('12 Supplementary bills')
})
})

describe('and there is 1 zero value bill', () => {
beforeEach(() => {
billSummaries[0].netAmount = 0
})

it('returns the sum plus the bill run type pluralised and zero value as singular (12 Supplementary bills and 1 zero value bill)', () => {
const result = ViewBillRunPresenter.go(billRun, billSummaries)

expect(result.billsCount).to.equal('12 Annual bills')
expect(result.billsCount).to.equal('12 Supplementary bills and 1 zero value bill')
})
})

describe('and there are multiple zero value bills', () => {
beforeEach(() => {
billSummaries[0].netAmount = 0
billSummaries[1].netAmount = 0
})

it('returns the sum plus the bill run type and zero value pluralised (12 Supplementary bills and 2 zero value bills)', () => {
const result = ViewBillRunPresenter.go(billRun, billSummaries)

expect(result.billsCount).to.equal('12 Supplementary bills and 2 zero value bills')
})
})
})
})

describe("the 'billRunTotal' property", () => {
describe('when the net total is greater than 0', () => {
it('returns the value converted to pounds, formatted as money and showing as a debit (£707.00)', () => {
const result = ViewBillRunPresenter.go(billRun)
const result = ViewBillRunPresenter.go(billRun, billSummaries)

expect(result.billRunTotal).to.equal('£707.00')
})
Expand All @@ -86,7 +116,7 @@ describe('View Bill Run presenter', () => {
})

it('returns the value converted to pounds, formatted as money and showing as a debit (£0.00)', () => {
const result = ViewBillRunPresenter.go(billRun)
const result = ViewBillRunPresenter.go(billRun, billSummaries)

expect(result.billRunTotal).to.equal('£0.00')
})
Expand All @@ -98,7 +128,7 @@ describe('View Bill Run presenter', () => {
})

it('returns the value converted to pounds, formatted as money and showing as a credit (£707.00 credit)', () => {
const result = ViewBillRunPresenter.go(billRun)
const result = ViewBillRunPresenter.go(billRun, billSummaries)

expect(result.billRunTotal).to.equal('£707.00 credit')
})
Expand All @@ -112,15 +142,15 @@ describe('View Bill Run presenter', () => {
})

it('returns Annual', () => {
const result = ViewBillRunPresenter.go(billRun)
const result = ViewBillRunPresenter.go(billRun, billSummaries)

expect(result.billRunType).to.equal('Annual')
})
})

describe('when the bill run is supplementary', () => {
it('returns Supplementary', () => {
const result = ViewBillRunPresenter.go(billRun)
const result = ViewBillRunPresenter.go(billRun, billSummaries)

expect(result.billRunType).to.equal('Supplementary')
})
Expand All @@ -133,7 +163,7 @@ describe('View Bill Run presenter', () => {

describe('and the scheme is sroc', () => {
it('returns Supplementary', () => {
const result = ViewBillRunPresenter.go(billRun)
const result = ViewBillRunPresenter.go(billRun, billSummaries)

expect(result.billRunType).to.equal('Two-part tariff')
})
Expand All @@ -146,7 +176,7 @@ describe('View Bill Run presenter', () => {

describe('and it is not summer only', () => {
it('returns Supplementary', () => {
const result = ViewBillRunPresenter.go(billRun)
const result = ViewBillRunPresenter.go(billRun, billSummaries)

expect(result.billRunType).to.equal('Two-part tariff winter and all year')
})
Expand All @@ -158,7 +188,7 @@ describe('View Bill Run presenter', () => {
})

it('returns Supplementary', () => {
const result = ViewBillRunPresenter.go(billRun)
const result = ViewBillRunPresenter.go(billRun, billSummaries)

expect(result.billRunType).to.equal('Two-part tariff summer')
})
Expand All @@ -170,7 +200,7 @@ describe('View Bill Run presenter', () => {
describe("the 'chargeScheme' property", () => {
describe('when the bill run is sroc', () => {
it('returns Current', () => {
const result = ViewBillRunPresenter.go(billRun)
const result = ViewBillRunPresenter.go(billRun, billSummaries)

expect(result.chargeScheme).to.equal('Current')
})
Expand All @@ -182,7 +212,7 @@ describe('View Bill Run presenter', () => {
})

it('returns Old', () => {
const result = ViewBillRunPresenter.go(billRun)
const result = ViewBillRunPresenter.go(billRun, billSummaries)

expect(result.chargeScheme).to.equal('Old')
})
Expand All @@ -196,15 +226,15 @@ describe('View Bill Run presenter', () => {
})

it('returns the count singular (1 credit note)', () => {
const result = ViewBillRunPresenter.go(billRun)
const result = ViewBillRunPresenter.go(billRun, billSummaries)

expect(result.creditsCount).to.equal('1 credit note')
})
})

describe('when there are multiple credit notes', () => {
it('returns the count pluralised (2 credit notes)', () => {
const result = ViewBillRunPresenter.go(billRun)
const result = ViewBillRunPresenter.go(billRun, billSummaries)

expect(result.creditsCount).to.equal('2 credit notes')
})
Expand All @@ -218,15 +248,15 @@ describe('View Bill Run presenter', () => {
})

it('returns the count singular (1 invoice)', () => {
const result = ViewBillRunPresenter.go(billRun)
const result = ViewBillRunPresenter.go(billRun, billSummaries)

expect(result.debitsCount).to.equal('1 invoice')
})
})

describe('when there are multiple invoices', () => {
it('returns the count pluralised (6 invoices)', () => {
const result = ViewBillRunPresenter.go(billRun)
const result = ViewBillRunPresenter.go(billRun, billSummaries)

expect(result.debitsCount).to.equal('6 invoices')
})
Expand All @@ -240,15 +270,15 @@ describe('View Bill Run presenter', () => {
})

it('returns false', () => {
const result = ViewBillRunPresenter.go(billRun)
const result = ViewBillRunPresenter.go(billRun, billSummaries)

expect(result.displayCreditDebitTotals).to.be.false()
})
})

describe('when the bill run is supplementary', () => {
it('returns true', () => {
const result = ViewBillRunPresenter.go(billRun)
const result = ViewBillRunPresenter.go(billRun, billSummaries)

expect(result.displayCreditDebitTotals).to.be.true()
})
Expand All @@ -257,23 +287,23 @@ describe('View Bill Run presenter', () => {

describe("the 'financialYear' property", () => {
it('returns the to and from financial year (2023 to 2024)', () => {
const result = ViewBillRunPresenter.go(billRun)
const result = ViewBillRunPresenter.go(billRun, billSummaries)

expect(result.financialYear).to.equal('2023 to 2024')
})
})

describe("the 'pageTitle' property", () => {
it('returns the region name and bill run type (Wales supplementary)', () => {
const result = ViewBillRunPresenter.go(billRun)
const result = ViewBillRunPresenter.go(billRun, billSummaries)

expect(result.pageTitle).to.equal('Wales supplementary')
})
})

describe("the 'region' property", () => {
it("returns the bill run's region display name capitalized (Wales)", () => {
const result = ViewBillRunPresenter.go(billRun)
const result = ViewBillRunPresenter.go(billRun, billSummaries)

expect(result.region).to.equal('Wales')
})
Expand Down Expand Up @@ -304,3 +334,30 @@ function _testBillRun () {
}
}
}

function _testBillSummaries () {
return [
{
id: '7c8a248c-b71e-463c-bea8-bc5e0a5d95e2',
billingAccountId: 'e8bd9fe1-47eb-42f2-a507-786bccd35aee',
accountNumber: 'E11101999A',
netAmount: -9700,
financialYearEnding: 2023,
companyName: 'H M Scotty & Daughter',
agentName: 'Geordie Leforge',
allLicences: '17/53/001/G/782',
waterCompany: false
},
{
id: '64924759-8142-4a08-9d1e-1e902cd9d316',
billingAccountId: 'ee3f5562-26ad-4d58-9b59-5c388a13d7d0',
accountNumber: 'E22288888A',
netAmount: 21317800,
financialYearEnding: 2023,
companyName: 'Acme Water Services Ltd',
agentName: null,
allLicences: '17/53/001/A/101,17/53/002/B/205,17/53/002/C/308',
waterCompany: true
}
]
}

0 comments on commit fbae6f7

Please sign in to comment.