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

Fix bill run type in view licence bills tab #1159

Merged
merged 11 commits into from
Jul 3, 2024
56 changes: 32 additions & 24 deletions app/presenters/licences/view-licence-bills.presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @module ViewLicenceBillsPresenter
*/

const { formatLongDate, formatMoney } = require('../base.presenter')
const { formatBillRunType, formatLongDate, formatMoney } = require('../base.presenter.js')

/**
* Formats data for the `/licences/{id}/bills` view licence bill page
Expand All @@ -14,47 +14,55 @@ const { formatLongDate, formatMoney } = require('../base.presenter')
*/
function go (bills) {
return {
activeTab: 'bills',
bills: _formatBillsToTableRow(bills)
bills: _bills(bills)
}
}

function _formatBatchType (batchType) {
return batchType.replace(/_/g, ' ')
function _bills (bills) {
return bills.map((bill) => {
const {
accountNumber,
billingAccountId,
billRun,
createdAt,
credit,
financialYearEnding,
id: billId,
netAmount
} = bill

return {
accountNumber,
billingAccountId,
billId,
billNumber: _formatBillNumber(bill),
billRunType: formatBillRunType(billRun.batchType, billRun.scheme, billRun.summer),
credit,
dateCreated: formatLongDate(createdAt),
financialYearEnding,
total: formatMoney(netAmount)
}
})
}

function _formatBillNumberLabel (bill) {
function _formatBillNumber (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: _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,
legacyId: bill.legacyId,
credit: bill.credit
}
})
return ''
}

module.exports = {
Expand Down
7 changes: 6 additions & 1 deletion app/services/licences/fetch-licence-bills.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ async function _fetch (licenceId, page) {
.where('billRuns.status', 'sent')
.withGraphFetched('billRun')
.modifyGraph('billRun', (builder) => {
builder.select(['batchType'])
builder.select([
'id',
'batchType',
'scheme',
'summer'
])
})
.orderBy([
{ column: 'createdAt', order: 'desc' }
Expand Down
15 changes: 8 additions & 7 deletions app/services/licences/view-licence-bills.service.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
'use strict'

/**
* Orchestrates fetching and presenting the data needed for the licence summary page
* Orchestrates fetching and presenting the data needed for the view licence bills tab
* @module ViewLicenceBillsService
*/

const FetchLicenceBillsService = require('./fetch-licence-bills.service')
const ViewLicenceBillsPresenter = require('../../presenters/licences/view-licence-bills.presenter')
const ViewLicenceService = require('./view-licence.service')
const PaginatorPresenter = require('../../presenters/paginator.presenter')
const FetchLicenceBillsService = require('./fetch-licence-bills.service.js')
const PaginatorPresenter = require('../../presenters/paginator.presenter.js')
const ViewLicenceBillsPresenter = require('../../presenters/licences/view-licence-bills.presenter.js')
const ViewLicenceService = require('./view-licence.service.js')

/**
* Orchestrates fetching and presenting the data needed for the licence summary page
* Orchestrates fetching and presenting the data needed for the view licence bills tab
*
* @param {string} licenceId - The UUID of the licence
*
* @returns {Promise<Object>} an object representing the `pageData` needed by the licence summary template.
* @returns {Promise<Object>} an object representing the `pageData` needed by the licence bills template.
*/
async function go (licenceId, auth, page) {
const commonData = await ViewLicenceService.go(licenceId, auth)
Expand All @@ -26,6 +26,7 @@ async function go (licenceId, auth, page) {
const pagination = PaginatorPresenter.go(billsData.pagination.total, Number(page), `/system/licences/${licenceId}/bills`)

return {
activeTab: 'bills',
...commonData,
...pageData,
pagination
Expand Down
8 changes: 4 additions & 4 deletions app/views/licences/tabs/bills.njk
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,23 @@

{% set row = [
{
html: '<a href="/system/bills/' + bill.id + '">' + bill.billNumber + '</a>',
html: '<a href="/system/bills/' + bill.billId + '">' + bill.billNumber + '</a>',
attributes: { 'data-test': 'bill-number-' + rowIndex }
},
{
text: bill.dateCreated,
attributes: { 'data-test': 'bill-created-' + rowIndex }
},
{
html: '<a href="/billing-accounts/' + bill.accountId + '">' + bill.account + '</a>',
html: '<a href="/billing-accounts/' + bill.billingAccountId + '">' + bill.accountNumber + '</a>',
attributes: { 'data-test': 'bill-account-' + rowIndex }
},
{
text: bill.runType,
text: bill.billRunType,
attributes: { 'data-test': 'bill-type-' + rowIndex }
},
{
text: bill.financialYear,
text: bill.financialYearEnding,
attributes: { 'data-test': 'bill-year-' + rowIndex },
format: 'numeric'
},
Expand Down
116 changes: 0 additions & 116 deletions test/presenters/licences/view-licence-bills-presenter.test.js

This file was deleted.

Loading
Loading