-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add View Licence Bills page https://eaflood.atlassian.net/browse/WATER-4316 The existing service handling view licence is slow because it loads all the data for the tabs in one render. Work has been done previously to refactor the summary page to load only the summary information. This change will introduce a bills controller, service and presenter to handle the view licence bills page. This will share the same view as the summary page and load the same 'common data' established in [previous work](#957).
- Loading branch information
1 parent
9360788
commit 346a95c
Showing
15 changed files
with
481 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
'use strict' | ||
|
||
/** | ||
* Formats data for the `/licences/{id}/bills` view licence bill page | ||
* @module ViewLicenceBillsPresenter | ||
*/ | ||
|
||
const { formatLongDate, formatMoney } = require('../base.presenter') | ||
|
||
/** | ||
* Formats data for the `/licences/{id}/bills` view licence bill page | ||
* | ||
* @returns {Object} The data formatted for the view template | ||
*/ | ||
function go (bills) { | ||
return { | ||
activeTab: 'bills', | ||
bills: _formatBillsToTableRow(bills) | ||
} | ||
} | ||
|
||
function _formatBillsToTableRow (bills) { | ||
return bills.map((bill) => { | ||
return { | ||
billNumber: bill.invoiceNumber, | ||
dateCreated: formatLongDate(new Date(bill.createdAt)), | ||
account: bill.accountNumber, | ||
runType: bill.billRun.batchType, | ||
financialYear: bill.financialYearEnding, | ||
total: formatMoney(bill.netAmount), | ||
accountId: bill.billingAccountId, | ||
id: bill.id | ||
} | ||
}) | ||
} | ||
|
||
module.exports = { | ||
go | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
'use strict' | ||
|
||
/** | ||
* Fetches all return logs for a licence which is needed for the view '/licences/{id}/bills` page | ||
* @module FetchLicenceBillsService | ||
*/ | ||
|
||
const BillModel = require('../../models/bill.model') | ||
|
||
const DatabaseConfig = require('../../../config/database.config') | ||
|
||
/** | ||
* Fetches all bills for a licence which is needed for the view '/licences/{id}/bills` page | ||
* | ||
* @param {string} licenceId - The UUID for the licence to fetch | ||
* | ||
* @returns {Promise<Object>} the data needed to populate the view licence page's bills tab | ||
*/ | ||
async function go (licenceId, page) { | ||
const { results, total } = await _fetch(licenceId, page) | ||
|
||
return { bills: results, pagination: { total } } | ||
} | ||
|
||
async function _fetch (licenceId, page) { | ||
return BillModel.query() | ||
.select([ | ||
'bills.id', | ||
'bills.invoiceNumber', | ||
'bills.accountNumber', | ||
'bills.financialYearEnding', | ||
'bills.netAmount', | ||
'bills.billingAccountId', | ||
'bills.createdAt' | ||
]) | ||
.innerJoinRelated('billLicences') | ||
.where('billLicences.licence_id', licenceId) | ||
.withGraphFetched('billRun') | ||
.modifyGraph('billRun', (builder) => { | ||
builder.select(['batchType']) | ||
}) | ||
.orderBy([ | ||
{ column: 'createdAt', order: 'desc' } | ||
]) | ||
.page(page - 1, DatabaseConfig.defaultPageSize) | ||
} | ||
|
||
module.exports = { | ||
go | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
'use strict' | ||
|
||
/** | ||
* Orchestrates fetching and presenting the data needed for the licence summary page | ||
* @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') | ||
|
||
/** | ||
* Orchestrates fetching and presenting the data needed for the licence summary page | ||
* | ||
* @param {string} licenceId - The UUID of the licence | ||
* | ||
* @returns {Promise<Object>} an object representing the `pageData` needed by the licence summary template. | ||
*/ | ||
async function go (licenceId, auth, page) { | ||
const commonData = await ViewLicenceService.go(licenceId, auth) | ||
|
||
const billsData = await FetchLicenceBillsService.go(licenceId, page) | ||
const pageData = ViewLicenceBillsPresenter.go(billsData.bills) | ||
|
||
const pagination = PaginatorPresenter.go(billsData.pagination.total, Number(page), `/system/licences/${licenceId}/bills`) | ||
|
||
return { | ||
...commonData, | ||
...pageData, | ||
pagination | ||
} | ||
} | ||
|
||
module.exports = { | ||
go | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
{% from "govuk/components/pagination/macro.njk" import govukPagination %} | ||
|
||
<table class="govuk-table"> | ||
<h2 class="govuk-heading-l">Bills</h2> | ||
{% if bills %} | ||
<table class="govuk-table"> | ||
<thead class="govuk-table__head"> | ||
<tr class="govuk-table__row"> | ||
<th class="govuk-table__header" scope="col">Bill number</th> | ||
<th class="govuk-table__header" scope="col">Date created</th> | ||
<th class="govuk-table__header" scope="col">Billing account</th> | ||
<th class="govuk-table__header" scope="col">Bill run type</th> | ||
<th class="govuk-table__header govuk-table__header--numeric" scope="col">Financial year</th> | ||
<th class="govuk-table__header govuk-table__header--numeric" scope="col">Bill total</th> | ||
</tr> | ||
</thead> | ||
<tbody class="govuk-table__body"> | ||
{% for bill in bills %} | ||
<tr class="govuk-table__row"> | ||
<td class="govuk-table__cell" scope="row"> | ||
<a href="/system/bills/{{ bill.id }}"> | ||
{{ bill.billNumber }} | ||
</a> | ||
</td> | ||
<td class="govuk-table__cell"> | ||
{{ bill.dateCreated }} | ||
</td> | ||
<td class="govuk-table__cell"> | ||
<a href="/billing-accounts/{{ bill.accountId }}"> | ||
{{ bill.account }} | ||
</a> | ||
</td> | ||
<td class="govuk-table__cell"> | ||
{{ bill.runType | title }} | ||
</td> | ||
<td class="govuk-table__cell govuk-table__cell--numeric"> | ||
{{ bill.financialYear }} | ||
</td> | ||
<td class="govuk-table__cell govuk-table__cell--numeric"> | ||
{{ bill.total }} | ||
</td> | ||
</tr> | ||
{% endfor %} | ||
</tbody> | ||
</table> | ||
{% else %} | ||
<p>No bills sent for this licence.</p> | ||
{% endif %} | ||
</table> | ||
|
||
{% if bills and pagination.numberOfPages > 1 %} | ||
{{ govukPagination(pagination.component) }} | ||
{% endif %} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.