-
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.
https://eaflood.atlassian.net/browse/WATER-4387 We need to add this to support our work to improve how bill runs are cancelled. Basically, replace the crummy legacy one! Rather than invest time in updating the existing cancel bill run page to point to what will be our new cancel endpoint we instead are investing in rebuilding it. There are already changes we'll need to make to support work on [cancelling a two-part tariff bill run](https://eaflood.atlassian.net/browse/WATER-4189) so we may as well focus our efforts on building a replacement page. This change adds the route, controller, presenter, service and view for a new cancel bill run page.
- Loading branch information
1 parent
37ba3ea
commit 8d01d36
Showing
8 changed files
with
481 additions
and
1 deletion.
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,81 @@ | ||
'use strict' | ||
|
||
/** | ||
* Formats the bill run data ready for presenting in the cancel bill run confirmation page | ||
* @module CancelBillRunPresenter | ||
*/ | ||
|
||
const { capitalize, formatLongDate } = require('../base.presenter.js') | ||
|
||
/** | ||
* Prepares and processes bill run data for presentation | ||
* | ||
* @param {module:BillRunModel} billRun - an instance of `BillRunModel` | ||
* | ||
* @returns {Object} - the prepared bill run data to be passed to the cancel bill run confirmation page | ||
*/ | ||
function go (billRun) { | ||
const { | ||
batchType, | ||
billRunNumber, | ||
createdAt, | ||
id, | ||
region, | ||
scheme, | ||
status, | ||
summer, | ||
toFinancialYearEnding | ||
} = billRun | ||
|
||
return { | ||
backLink: _backLink(id, status), | ||
billRunId: id, | ||
billRunNumber, | ||
billRunStatus: status, | ||
billRunType: _billRunType(batchType, summer, scheme), | ||
chargeScheme: _chargeScheme(scheme), | ||
dateCreated: formatLongDate(createdAt), | ||
financialYear: _financialYear(toFinancialYearEnding), | ||
region: capitalize(region.displayName) | ||
} | ||
} | ||
|
||
function _backLink (id, status) { | ||
if (status === 'review') { | ||
return `/system/bill-runs/${id}/review` | ||
} | ||
|
||
return `/system/bill-runs/${id}` | ||
} | ||
|
||
function _billRunType (batchType, summer, scheme) { | ||
if (batchType !== 'two_part_tariff') { | ||
return capitalize(batchType) | ||
} | ||
|
||
if (scheme === 'sroc') { | ||
return 'Two-part tariff' | ||
} | ||
|
||
if (summer) { | ||
return 'Two-part tariff summer' | ||
} | ||
|
||
return 'Two-part tariff winter and all year' | ||
} | ||
|
||
function _chargeScheme (scheme) { | ||
if (scheme === 'sroc') { | ||
return 'Current' | ||
} | ||
|
||
return 'Old' | ||
} | ||
|
||
function _financialYear (financialYearEnding) { | ||
return `${financialYearEnding - 1} to ${financialYearEnding}` | ||
} | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
'use strict' | ||
|
||
/** | ||
* Orchestrates fetching and presenting the data needed for the cancel bill run confirmation page | ||
* @module CancelBillRunService | ||
*/ | ||
|
||
const BillRunModel = require('../../models/bill-run.model.js') | ||
const CancelBillRunPresenter = require('../../presenters/bill-runs/cancel-bill-run.presenter.js') | ||
|
||
/** | ||
* Orchestrates fetching and presenting the data needed for the cancel bill run confirmation page | ||
* | ||
* @param {string} id - The UUID of the bill run to cancel | ||
* | ||
* @returns {Promise<Object}> an object representing the `pageData` needed by the cancel bill run template. It contains | ||
* details of the bill run. | ||
*/ | ||
async function go (id) { | ||
const billRun = await _fetchBillRun(id) | ||
|
||
const pageData = CancelBillRunPresenter.go(billRun) | ||
|
||
return pageData | ||
} | ||
|
||
async function _fetchBillRun (id) { | ||
return BillRunModel.query() | ||
.findById(id) | ||
.select([ | ||
'id', | ||
'batchType', | ||
'billRunNumber', | ||
'createdAt', | ||
'scheme', | ||
'status', | ||
'summer', | ||
'toFinancialYearEnding' | ||
]) | ||
.withGraphFetched('region') | ||
.modifyGraph('region', (builder) => { | ||
builder.select([ | ||
'id', | ||
'displayName' | ||
]) | ||
}) | ||
} | ||
|
||
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,84 @@ | ||
{% extends 'layout.njk' %} | ||
{% from "govuk/components/back-link/macro.njk" import govukBackLink %} | ||
{% from "govuk/components/button/macro.njk" import govukButton %} | ||
{% from "govuk/components/details/macro.njk" import govukDetails %} | ||
{% from "govuk/components/summary-list/macro.njk" import govukSummaryList %} | ||
{% from "govuk/components/table/macro.njk" import govukTable %} | ||
|
||
{% from "macros/badge.njk" import badge %} | ||
|
||
{% block breadcrumbs %} | ||
{# Back link #} | ||
{{ | ||
govukBackLink({ | ||
text: 'Back', | ||
href: backLink | ||
}) | ||
}} | ||
{% endblock %} | ||
|
||
{% block content %} | ||
{# Main heading #} | ||
<div class="govuk-body"> | ||
<h1 class="govuk-heading-xl govuk-!-margin-bottom-3"> | ||
<span class="govuk-caption-l">Bill run {{ billRunNumber }}</span>{{ pageTitle }} | ||
</h1> | ||
</div> | ||
|
||
<div class="govuk-grid-row govuk-!-margin-bottom-0"> | ||
<div class="govuk-grid-column-full"> | ||
|
||
{# Status badge #} | ||
{% if billRunStatus === 'ready' %} | ||
{% set badgeType = 'info' %} | ||
{% elif billRunStatus === 'sent' %} | ||
{% set badgeType = 'success' %} | ||
{% endif %} | ||
<p class="govuk-body"> | ||
{{ badge(billRunStatus, badgeType) }} | ||
</p> | ||
|
||
{# Bill run meta-data #} | ||
{# | ||
GOV.UK summary lists only allow us to assign attributes at the top level and not to each row. This means we | ||
can't assign our data-test attribute using the component. Our solution is to use the html option for each row | ||
instead of text and wrap each value in a <span>. That way we can manually assign our data-test attribute to the | ||
span. | ||
#} | ||
{{ | ||
govukSummaryList({ | ||
classes: 'govuk-summary-list--no-border', | ||
attributes: { | ||
'data-test': 'meta-data' | ||
}, | ||
rows: [ | ||
{ | ||
key: { text: "Date created", classes: "meta-data__label" }, | ||
value: { html: '<span data-test="meta-data-created">' + dateCreated + '</span>', classes: "meta-data__value" } | ||
}, | ||
{ | ||
key: { text: "Region", classes: "meta-data__label" }, | ||
value: { html: '<span data-test="meta-data-region">' + region + '</span>', classes: "meta-data__value" } | ||
}, | ||
{ | ||
key: { text: "Bill run type", classes: "meta-data__label" }, | ||
value: { html: '<span data-test="meta-data-type">' + billRunType + '</span>', classes: "meta-data__value" } | ||
}, | ||
{ | ||
key: { text: "Charge scheme", classes: "meta-data__label" }, | ||
value: { html: '<span data-test="meta-data-scheme">' + chargeScheme + '</span>', classes: "meta-data__value" } | ||
}, | ||
{ | ||
key: { text: "Financial year", classes: "meta-data__label" }, | ||
value: { html: '<span data-test="meta-data-year">' + financialYear + '</span>', classes: "meta-data__value" } | ||
} | ||
] | ||
}) | ||
}} | ||
|
||
<form method="post"> | ||
{{ govukButton({ text: "Cancel bill run" }) }} | ||
</form> | ||
</div> | ||
</div> | ||
{% endblock %} |
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.