From ca31ce481b524904306018bc5d1177fb9c53a1d3 Mon Sep 17 00:00:00 2001 From: jonathangoulding Date: Thu, 9 May 2024 09:14:08 +0100 Subject: [PATCH 1/4] View licence bills Handle two part tariff string --- .../licences/view-licence-bills.presenter.js | 6 +++++- .../view-licence-bills-presenter.test.js | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/app/presenters/licences/view-licence-bills.presenter.js b/app/presenters/licences/view-licence-bills.presenter.js index a770fa9dda..dfec01aee5 100644 --- a/app/presenters/licences/view-licence-bills.presenter.js +++ b/app/presenters/licences/view-licence-bills.presenter.js @@ -25,7 +25,7 @@ function _formatBillsToTableRow (bills) { billNumber: bill.invoiceNumber, dateCreated: formatLongDate(new Date(bill.createdAt)), account: bill.accountNumber, - runType: bill.billRun.batchType, + runType: _formatBatchType(bill.billRun.batchType), financialYear: bill.financialYearEnding, total: formatMoney(bill.netAmount), accountId: bill.billingAccountId, @@ -34,6 +34,10 @@ function _formatBillsToTableRow (bills) { }) } +function _formatBatchType (batchType) { + return batchType.replace(/_/g, ' ') +} + module.exports = { go } diff --git a/test/presenters/licences/view-licence-bills-presenter.test.js b/test/presenters/licences/view-licence-bills-presenter.test.js index 8ab40905b6..1d305c3c0b 100644 --- a/test/presenters/licences/view-licence-bills-presenter.test.js +++ b/test/presenters/licences/view-licence-bills-presenter.test.js @@ -38,6 +38,11 @@ describe('View Licence Bills presenter', () => { const result = ViewLicenceBillsPresenter.go(_bills()) expect(result.bills[0].total).to.equal('£1,234,567.89') }) + + it('correctly formats the two part tariff batch type', () => { + const result = ViewLicenceBillsPresenter.go(_billsTwoPartTariff()) + expect(result.bills[0].runType).to.equal('two part tariff') + }) }) }) @@ -53,3 +58,16 @@ function _bills () { netAmount: 123456789 }] } + +function _billsTwoPartTariff () { + return [{ + accountNumber: 'acc123', + billRun: { batchType: 'two_part_tariff' }, + billingAccountId: 'bicc1233', + createdAt: new Date('2020-01-01'), + financialYearEnding: '2021', + id: 'id123', + invoiceNumber: 'inv123', + netAmount: 123456789 + }] +} From e3f3c8f41b10f447d2c0c57b6b9b45bdff4580b7 Mon Sep 17 00:00:00 2001 From: jonathangoulding Date: Fri, 10 May 2024 10:53:05 +0100 Subject: [PATCH 2/4] feat: add rebilling logic to the bill number --- .../licences/view-licence-bills.presenter.js | 45 ++++++++- .../licences/fetch-licence-bills.service.js | 6 +- app/views/licences/tabs/bills.njk | 40 ++++++++ .../view-licence-bills-presenter.test.js | 91 +++++++++++++++++-- .../fetch-licence-bills.service.test.js | 6 +- 5 files changed, 176 insertions(+), 12 deletions(-) diff --git a/app/presenters/licences/view-licence-bills.presenter.js b/app/presenters/licences/view-licence-bills.presenter.js index dfec01aee5..7c4ca9069c 100644 --- a/app/presenters/licences/view-licence-bills.presenter.js +++ b/app/presenters/licences/view-licence-bills.presenter.js @@ -19,23 +19,60 @@ function go (bills) { } } +function _formatBatchType (batchType) { + return batchType.replace(/_/g, ' ') +} + +function _formatBillNumberLabel (bill) { + if (bill.invoiceNumber) { + return bill.invoiceNumber + } + if (bill.deminimis) { + return 'De minimis bill' + } + if (bill.legacyId) { + return 'NALD revised bill' + } + if (bill.netAmount === 0) { + return 'Zero value bill' + } + + return null +} + function _formatBillsToTableRow (bills) { return bills.map((bill) => { return { - billNumber: bill.invoiceNumber, + billNumber: _formatBillNumberLabel(bill), dateCreated: formatLongDate(new Date(bill.createdAt)), account: bill.accountNumber, runType: _formatBatchType(bill.billRun.batchType), financialYear: bill.financialYearEnding, total: formatMoney(bill.netAmount), accountId: bill.billingAccountId, - id: bill.id + id: bill.id, + rebilling: _formatRebillingInformation(bill), + legacyId: bill.legacyId } }) } -function _formatBatchType (batchType) { - return batchType.replace(/_/g, ' ') +function _formatRebillingInformation (bill) { + return { + flaggedForRebilling: bill.flaggedForRebilling, + rebillingState: _formatRebillingState(bill.rebillingState) + } +} + +function _formatRebillingState (rebillingState) { + if (rebillingState === 'rebill') { + return 'Reissued' + } + + if (rebillingState === 'reversal') { + return 'Reversed' + } + return null } module.exports = { diff --git a/app/services/licences/fetch-licence-bills.service.js b/app/services/licences/fetch-licence-bills.service.js index 4fb99d027a..3b25200c02 100644 --- a/app/services/licences/fetch-licence-bills.service.js +++ b/app/services/licences/fetch-licence-bills.service.js @@ -31,7 +31,11 @@ async function _fetch (licenceId, page) { 'bills.financialYearEnding', 'bills.netAmount', 'bills.billingAccountId', - 'bills.createdAt' + 'bills.createdAt', + 'bills.flaggedForRebilling', + 'bills.rebillingState', + 'bills.legacyId', + 'bills.deminimis' ]) .innerJoinRelated('billLicences') .where('billLicences.licence_id', licenceId) diff --git a/app/views/licences/tabs/bills.njk b/app/views/licences/tabs/bills.njk index a28fdcee12..3535bb002c 100644 --- a/app/views/licences/tabs/bills.njk +++ b/app/views/licences/tabs/bills.njk @@ -21,6 +21,12 @@ {{ bill.billNumber }} + {% if bill.rebilling.flaggedForRebilling != true and bill.rebilling.rebillingState %} +

{{ bill.rebilling.rebillingState | title }}

+ {% endif %} + {% if bill.rebilling.flaggedForRebilling %} +

Marked for reissue

+ {% endif %} {{ bill.dateCreated }} @@ -28,6 +34,16 @@ {{ bill.account }} + + + {# missing +{% if invoice.invoiceAccount %} + + {{ invoice.invoiceAccount.accountNumber }} + + {% else %} + {{ invoice.accountNumber }} + {% endif %} #} @@ -38,6 +54,30 @@ {{ bill.total }} + + {# missing +{% if invoice.isCredit %} +
Credit
+ {% endif %} #} + + {# {% macro amountCell(invoice) %} + + {{ chargeOrDash(invoice.netTotal) }} + {% if invoice.isCredit %} +
Credit
+ {% endif %} + +{% endmacro %} #} + + {# + {% macro chargeOrDash (value, isSigned = false) %} + {% if value | defaultTo(false) !== false %} + {{ value | charge(isSigned) }} + {% else %} + -Loading + {% endif %} + {% endmacro %} + #} {% endfor %} diff --git a/test/presenters/licences/view-licence-bills-presenter.test.js b/test/presenters/licences/view-licence-bills-presenter.test.js index 1d305c3c0b..dec684dd64 100644 --- a/test/presenters/licences/view-licence-bills-presenter.test.js +++ b/test/presenters/licences/view-licence-bills-presenter.test.js @@ -25,7 +25,13 @@ describe('View Licence Bills presenter', () => { financialYear: '2021', id: 'id123', runType: 'annual', - total: '£1,234,567.89' + total: '£1,234,567.89', + legacyId: null, + rebilling: { + flaggedForRebilling: false, + rebillingState: null + } + }] }) }) @@ -43,11 +49,72 @@ describe('View Licence Bills presenter', () => { const result = ViewLicenceBillsPresenter.go(_billsTwoPartTariff()) expect(result.bills[0].runType).to.equal('two part tariff') }) + + describe('billNumber', () => { + it('correctly formats the \'billNumber\' to the invoice number', () => { + const result = ViewLicenceBillsPresenter.go(_bills()) + expect(result.bills[0].billNumber).to.equal('inv123') + }) + + it('correctly formats the \'billNumber\' to \'De minimis bill\'', () => { + const bill = _bill() + bill.invoiceNumber = null + bill.deminimis = true + const result = ViewLicenceBillsPresenter.go([bill]) + expect(result.bills[0].billNumber).to.equal('De minimis bill') + }) + + it('correctly formats the \'billNumber\' to \'NALD revised bill\'', () => { + const bill = _bill() + bill.invoiceNumber = null + bill.legacyId = 'lgcy' + const result = ViewLicenceBillsPresenter.go([bill]) + expect(result.bills[0].billNumber).to.equal('NALD revised bill') + }) + + it('correctly formats the \'billNumber\' to \'Zero value bill\'', () => { + const bill = _bill() + bill.invoiceNumber = null + bill.netAmount = 0 + const result = ViewLicenceBillsPresenter.go([bill]) + expect(result.bills[0].billNumber).to.equal('Zero value bill') + }) + }) + describe('rebilling', () => { + it('returns flaggedForRebilling false', () => { + const bill = _bill() + const result = ViewLicenceBillsPresenter.go([bill]) + expect(result.bills[0].rebilling.flaggedForRebilling).to.be.false() + }) + it('returns flaggedForRebilling true', () => { + const bill = _bill() + bill.flaggedForRebilling = true + const result = ViewLicenceBillsPresenter.go([bill]) + expect(result.bills[0].rebilling.flaggedForRebilling).to.be.true() + }) + it('formats the rebillingState to \'rebill\'', () => { + const bill = _bill() + bill.rebillingState = 'rebill' + const result = ViewLicenceBillsPresenter.go([bill]) + expect(result.bills[0].rebilling.rebillingState).to.equal('Reissued') + }) + it('formats the rebillingState to \'reversal\'', () => { + const bill = _bill() + bill.rebillingState = 'reversal' + const result = ViewLicenceBillsPresenter.go([bill]) + expect(result.bills[0].rebilling.rebillingState).to.equal('Reversed') + }) + it('formats the rebillingState to \'null\'', () => { + const bill = _bill() + const result = ViewLicenceBillsPresenter.go([bill]) + expect(result.bills[0].rebilling.rebillingState).to.be.null() + }) + }) }) }) -function _bills () { - return [{ +function _bill () { + return { accountNumber: 'acc123', billRun: { batchType: 'annual' }, billingAccountId: 'bicc1233', @@ -55,8 +122,16 @@ function _bills () { financialYearEnding: '2021', id: 'id123', invoiceNumber: 'inv123', - netAmount: 123456789 - }] + netAmount: 123456789, + legacyId: null, + deminimis: false, + flaggedForRebilling: false, + rebillingState: null + } +} + +function _bills () { + return [_bill()] } function _billsTwoPartTariff () { @@ -68,6 +143,10 @@ function _billsTwoPartTariff () { financialYearEnding: '2021', id: 'id123', invoiceNumber: 'inv123', - netAmount: 123456789 + netAmount: 123456789, + legacyId: null, + deminimis: false, + flaggedForRebilling: false, + rebillingState: null }] } diff --git a/test/services/licences/fetch-licence-bills.service.test.js b/test/services/licences/fetch-licence-bills.service.test.js index 7e173c013f..dc86711ce3 100644 --- a/test/services/licences/fetch-licence-bills.service.test.js +++ b/test/services/licences/fetch-licence-bills.service.test.js @@ -62,10 +62,14 @@ describe('Fetch licence bills service', () => { billRun: null, billingAccountId, createdAt: createdDate, + deminimis: false, financialYearEnding: 2023, + flaggedForRebilling: false, id: billId, invoiceNumber: '123', - netAmount: 12345 + legacyId: null, + netAmount: 12345, + rebillingState: null }] ) }) From 632df1a9679fc2751917e212fe69bb4a0760c3a2 Mon Sep 17 00:00:00 2001 From: jonathangoulding Date: Fri, 10 May 2024 11:22:29 +0100 Subject: [PATCH 3/4] feat: credit note --- .../licences/view-licence-bills.presenter.js | 3 +- .../licences/fetch-licence-bills.service.js | 13 +++---- app/views/licences/tabs/bills.njk | 36 ++----------------- .../view-licence-bills-presenter.test.js | 22 ++++++------ .../fetch-licence-bills.service.test.js | 1 + 5 files changed, 25 insertions(+), 50 deletions(-) diff --git a/app/presenters/licences/view-licence-bills.presenter.js b/app/presenters/licences/view-licence-bills.presenter.js index 7c4ca9069c..586b3ca94b 100644 --- a/app/presenters/licences/view-licence-bills.presenter.js +++ b/app/presenters/licences/view-licence-bills.presenter.js @@ -52,7 +52,8 @@ function _formatBillsToTableRow (bills) { accountId: bill.billingAccountId, id: bill.id, rebilling: _formatRebillingInformation(bill), - legacyId: bill.legacyId + legacyId: bill.legacyId, + credit: bill.credit } }) } diff --git a/app/services/licences/fetch-licence-bills.service.js b/app/services/licences/fetch-licence-bills.service.js index 3b25200c02..9f0946f835 100644 --- a/app/services/licences/fetch-licence-bills.service.js +++ b/app/services/licences/fetch-licence-bills.service.js @@ -25,17 +25,18 @@ async function go (licenceId, page) { async function _fetch (licenceId, page) { return BillModel.query() .select([ - 'bills.id', - 'bills.invoiceNumber', 'bills.accountNumber', - 'bills.financialYearEnding', - 'bills.netAmount', 'bills.billingAccountId', 'bills.createdAt', + 'bills.credit', + 'bills.deminimis', + 'bills.financialYearEnding', 'bills.flaggedForRebilling', - 'bills.rebillingState', + 'bills.id', + 'bills.invoiceNumber', 'bills.legacyId', - 'bills.deminimis' + 'bills.netAmount', + 'bills.rebillingState' ]) .innerJoinRelated('billLicences') .where('billLicences.licence_id', licenceId) diff --git a/app/views/licences/tabs/bills.njk b/app/views/licences/tabs/bills.njk index 3535bb002c..203c73fe3b 100644 --- a/app/views/licences/tabs/bills.njk +++ b/app/views/licences/tabs/bills.njk @@ -34,16 +34,6 @@ {{ bill.account }} - - - {# missing -{% if invoice.invoiceAccount %} - - {{ invoice.invoiceAccount.accountNumber }} - - {% else %} - {{ invoice.accountNumber }} - {% endif %} #} @@ -54,30 +44,10 @@ {{ bill.total }} + {% if bill.credit %} +
Credit
+ {% endif %} - {# missing -{% if invoice.isCredit %} -
Credit
- {% endif %} #} - - {# {% macro amountCell(invoice) %} - - {{ chargeOrDash(invoice.netTotal) }} - {% if invoice.isCredit %} -
Credit
- {% endif %} - -{% endmacro %} #} - - {# - {% macro chargeOrDash (value, isSigned = false) %} - {% if value | defaultTo(false) !== false %} - {{ value | charge(isSigned) }} - {% else %} - -Loading - {% endif %} - {% endmacro %} - #} {% endfor %} diff --git a/test/presenters/licences/view-licence-bills-presenter.test.js b/test/presenters/licences/view-licence-bills-presenter.test.js index dec684dd64..b9db8ce7da 100644 --- a/test/presenters/licences/view-licence-bills-presenter.test.js +++ b/test/presenters/licences/view-licence-bills-presenter.test.js @@ -21,17 +21,17 @@ describe('View Licence Bills presenter', () => { account: 'acc123', accountId: 'bicc1233', billNumber: 'inv123', + credit: false, dateCreated: '1 January 2020', financialYear: '2021', id: 'id123', - runType: 'annual', - total: '£1,234,567.89', legacyId: null, rebilling: { flaggedForRebilling: false, rebillingState: null - } - + }, + runType: 'annual', + total: '£1,234,567.89' }] }) }) @@ -119,13 +119,14 @@ function _bill () { billRun: { batchType: 'annual' }, billingAccountId: 'bicc1233', createdAt: new Date('2020-01-01'), + credit: false, + deminimis: false, financialYearEnding: '2021', + flaggedForRebilling: false, id: 'id123', invoiceNumber: 'inv123', - netAmount: 123456789, legacyId: null, - deminimis: false, - flaggedForRebilling: false, + netAmount: 123456789, rebillingState: null } } @@ -140,13 +141,14 @@ function _billsTwoPartTariff () { billRun: { batchType: 'two_part_tariff' }, billingAccountId: 'bicc1233', createdAt: new Date('2020-01-01'), + credit: false, + deminimis: false, financialYearEnding: '2021', + flaggedForRebilling: false, id: 'id123', invoiceNumber: 'inv123', - netAmount: 123456789, legacyId: null, - deminimis: false, - flaggedForRebilling: false, + netAmount: 123456789, rebillingState: null }] } diff --git a/test/services/licences/fetch-licence-bills.service.test.js b/test/services/licences/fetch-licence-bills.service.test.js index dc86711ce3..f0194fd6f8 100644 --- a/test/services/licences/fetch-licence-bills.service.test.js +++ b/test/services/licences/fetch-licence-bills.service.test.js @@ -62,6 +62,7 @@ describe('Fetch licence bills service', () => { billRun: null, billingAccountId, createdAt: createdDate, + credit: null, deminimis: false, financialYearEnding: 2023, flaggedForRebilling: false, From bf214294389b5ff543dd4357d85a625f7c92d9b2 Mon Sep 17 00:00:00 2001 From: jonathangoulding Date: Fri, 10 May 2024 16:07:26 +0100 Subject: [PATCH 4/4] chore: remove rebilling logic --- .../licences/view-licence-bills.presenter.js | 19 --------- .../licences/fetch-licence-bills.service.js | 4 +- app/views/licences/tabs/bills.njk | 7 ---- .../view-licence-bills-presenter.test.js | 42 +------------------ .../fetch-licence-bills.service.test.js | 4 +- 5 files changed, 4 insertions(+), 72 deletions(-) diff --git a/app/presenters/licences/view-licence-bills.presenter.js b/app/presenters/licences/view-licence-bills.presenter.js index 586b3ca94b..c983fad75d 100644 --- a/app/presenters/licences/view-licence-bills.presenter.js +++ b/app/presenters/licences/view-licence-bills.presenter.js @@ -51,31 +51,12 @@ function _formatBillsToTableRow (bills) { total: formatMoney(bill.netAmount), accountId: bill.billingAccountId, id: bill.id, - rebilling: _formatRebillingInformation(bill), legacyId: bill.legacyId, credit: bill.credit } }) } -function _formatRebillingInformation (bill) { - return { - flaggedForRebilling: bill.flaggedForRebilling, - rebillingState: _formatRebillingState(bill.rebillingState) - } -} - -function _formatRebillingState (rebillingState) { - if (rebillingState === 'rebill') { - return 'Reissued' - } - - if (rebillingState === 'reversal') { - return 'Reversed' - } - return null -} - module.exports = { go } diff --git a/app/services/licences/fetch-licence-bills.service.js b/app/services/licences/fetch-licence-bills.service.js index 9f0946f835..1564df56ec 100644 --- a/app/services/licences/fetch-licence-bills.service.js +++ b/app/services/licences/fetch-licence-bills.service.js @@ -31,12 +31,10 @@ async function _fetch (licenceId, page) { 'bills.credit', 'bills.deminimis', 'bills.financialYearEnding', - 'bills.flaggedForRebilling', 'bills.id', 'bills.invoiceNumber', 'bills.legacyId', - 'bills.netAmount', - 'bills.rebillingState' + 'bills.netAmount' ]) .innerJoinRelated('billLicences') .where('billLicences.licence_id', licenceId) diff --git a/app/views/licences/tabs/bills.njk b/app/views/licences/tabs/bills.njk index 203c73fe3b..0d8e38945c 100644 --- a/app/views/licences/tabs/bills.njk +++ b/app/views/licences/tabs/bills.njk @@ -21,12 +21,6 @@ {{ bill.billNumber }} - {% if bill.rebilling.flaggedForRebilling != true and bill.rebilling.rebillingState %} -

{{ bill.rebilling.rebillingState | title }}

- {% endif %} - {% if bill.rebilling.flaggedForRebilling %} -

Marked for reissue

- {% endif %} {{ bill.dateCreated }} @@ -47,7 +41,6 @@ {% if bill.credit %}
Credit
{% endif %} - {% endfor %} diff --git a/test/presenters/licences/view-licence-bills-presenter.test.js b/test/presenters/licences/view-licence-bills-presenter.test.js index b9db8ce7da..cf0ed41820 100644 --- a/test/presenters/licences/view-licence-bills-presenter.test.js +++ b/test/presenters/licences/view-licence-bills-presenter.test.js @@ -26,10 +26,6 @@ describe('View Licence Bills presenter', () => { financialYear: '2021', id: 'id123', legacyId: null, - rebilling: { - flaggedForRebilling: false, - rebillingState: null - }, runType: 'annual', total: '£1,234,567.89' }] @@ -80,36 +76,6 @@ describe('View Licence Bills presenter', () => { expect(result.bills[0].billNumber).to.equal('Zero value bill') }) }) - describe('rebilling', () => { - it('returns flaggedForRebilling false', () => { - const bill = _bill() - const result = ViewLicenceBillsPresenter.go([bill]) - expect(result.bills[0].rebilling.flaggedForRebilling).to.be.false() - }) - it('returns flaggedForRebilling true', () => { - const bill = _bill() - bill.flaggedForRebilling = true - const result = ViewLicenceBillsPresenter.go([bill]) - expect(result.bills[0].rebilling.flaggedForRebilling).to.be.true() - }) - it('formats the rebillingState to \'rebill\'', () => { - const bill = _bill() - bill.rebillingState = 'rebill' - const result = ViewLicenceBillsPresenter.go([bill]) - expect(result.bills[0].rebilling.rebillingState).to.equal('Reissued') - }) - it('formats the rebillingState to \'reversal\'', () => { - const bill = _bill() - bill.rebillingState = 'reversal' - const result = ViewLicenceBillsPresenter.go([bill]) - expect(result.bills[0].rebilling.rebillingState).to.equal('Reversed') - }) - it('formats the rebillingState to \'null\'', () => { - const bill = _bill() - const result = ViewLicenceBillsPresenter.go([bill]) - expect(result.bills[0].rebilling.rebillingState).to.be.null() - }) - }) }) }) @@ -122,12 +88,10 @@ function _bill () { credit: false, deminimis: false, financialYearEnding: '2021', - flaggedForRebilling: false, id: 'id123', invoiceNumber: 'inv123', legacyId: null, - netAmount: 123456789, - rebillingState: null + netAmount: 123456789 } } @@ -144,11 +108,9 @@ function _billsTwoPartTariff () { credit: false, deminimis: false, financialYearEnding: '2021', - flaggedForRebilling: false, id: 'id123', invoiceNumber: 'inv123', legacyId: null, - netAmount: 123456789, - rebillingState: null + netAmount: 123456789 }] } diff --git a/test/services/licences/fetch-licence-bills.service.test.js b/test/services/licences/fetch-licence-bills.service.test.js index f0194fd6f8..bd3a495a41 100644 --- a/test/services/licences/fetch-licence-bills.service.test.js +++ b/test/services/licences/fetch-licence-bills.service.test.js @@ -65,12 +65,10 @@ describe('Fetch licence bills service', () => { credit: null, deminimis: false, financialYearEnding: 2023, - flaggedForRebilling: false, id: billId, invoiceNumber: '123', legacyId: null, - netAmount: 12345, - rebillingState: null + netAmount: 12345 }] ) })