diff --git a/app/presenters/licences/view-licence-bills.presenter.js b/app/presenters/licences/view-licence-bills.presenter.js index a770fa9dda..c983fad75d 100644 --- a/app/presenters/licences/view-licence-bills.presenter.js +++ b/app/presenters/licences/view-licence-bills.presenter.js @@ -19,17 +19,40 @@ 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: bill.billRun.batchType, + runType: _formatBatchType(bill.billRun.batchType), financialYear: bill.financialYearEnding, total: formatMoney(bill.netAmount), accountId: bill.billingAccountId, - id: bill.id + id: bill.id, + 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 4fb99d027a..1564df56ec 100644 --- a/app/services/licences/fetch-licence-bills.service.js +++ b/app/services/licences/fetch-licence-bills.service.js @@ -25,13 +25,16 @@ 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.createdAt', + 'bills.credit', + 'bills.deminimis', + 'bills.financialYearEnding', + 'bills.id', + 'bills.invoiceNumber', + 'bills.legacyId', + '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 a28fdcee12..0d8e38945c 100644 --- a/app/views/licences/tabs/bills.njk +++ b/app/views/licences/tabs/bills.njk @@ -38,6 +38,9 @@ {{ bill.total }} + {% 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 8ab40905b6..cf0ed41820 100644 --- a/test/presenters/licences/view-licence-bills-presenter.test.js +++ b/test/presenters/licences/view-licence-bills-presenter.test.js @@ -21,9 +21,11 @@ describe('View Licence Bills presenter', () => { account: 'acc123', accountId: 'bicc1233', billNumber: 'inv123', + credit: false, dateCreated: '1 January 2020', financialYear: '2021', id: 'id123', + legacyId: null, runType: 'annual', total: '£1,234,567.89' }] @@ -38,18 +40,77 @@ 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') + }) + + 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') + }) + }) }) }) +function _bill () { + return { + accountNumber: 'acc123', + billRun: { batchType: 'annual' }, + billingAccountId: 'bicc1233', + createdAt: new Date('2020-01-01'), + credit: false, + deminimis: false, + financialYearEnding: '2021', + id: 'id123', + invoiceNumber: 'inv123', + legacyId: null, + netAmount: 123456789 + } +} + function _bills () { + return [_bill()] +} + +function _billsTwoPartTariff () { return [{ accountNumber: 'acc123', - billRun: { batchType: 'annual' }, + billRun: { batchType: 'two_part_tariff' }, billingAccountId: 'bicc1233', createdAt: new Date('2020-01-01'), + credit: false, + deminimis: false, financialYearEnding: '2021', id: 'id123', invoiceNumber: 'inv123', + legacyId: 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 7e173c013f..bd3a495a41 100644 --- a/test/services/licences/fetch-licence-bills.service.test.js +++ b/test/services/licences/fetch-licence-bills.service.test.js @@ -62,9 +62,12 @@ describe('Fetch licence bills service', () => { billRun: null, billingAccountId, createdAt: createdDate, + credit: null, + deminimis: false, financialYearEnding: 2023, id: billId, invoiceNumber: '123', + legacyId: null, netAmount: 12345 }] )