Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

View licence bills Fixes #998

Merged
merged 5 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions app/presenters/licences/view-licence-bills.presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
})
}
Expand Down
13 changes: 8 additions & 5 deletions app/services/licences/fetch-licence-bills.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions app/views/licences/tabs/bills.njk
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
</td>
<td class="govuk-table__cell govuk-table__cell--numeric">
{{ bill.total }}
{% if bill.credit %}
<div>Credit</div>
{% endif %}
</td>
</tr>
{% endfor %}
Expand Down
63 changes: 62 additions & 1 deletion test/presenters/licences/view-licence-bills-presenter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}]
Expand All @@ -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
}]
}
3 changes: 3 additions & 0 deletions test/services/licences/fetch-licence-bills.service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}]
)
Expand Down
Loading