Skip to content

Commit

Permalink
Add new single licence bill templates (#514)
Browse files Browse the repository at this point in the history
https://eaflood.atlassian.net/browse/WATER-4132

In WATER-4155 and WATER-4156 we built 2 new pages for displaying a bill. WATER-4155 covered a new bill page that displayed details about the bill, the bill run it is in, and its billing account. It then listed all licences connected to the bill.

Each licence if selected would take you to a new bill-licence page (WATER-4156 ) which displays the transactions for that licence in detail. This fixed the issue (WATER-4070 ) with the legacy code being unable to display licences with large (100s) numbers of licences.

But what if a bill has just 1 licence? In this case, the team agreed that showing a table for 1 licence and requiring a user to click through for the details was superfluous.

So, WATER-4132 is about building a page for that scenario; a bill with just 1 licence. In this change, we add the new templates needed to do this along with changes to the controller and ViewBillService to determine which template to show.
  • Loading branch information
Cruikshanks authored Nov 10, 2023
1 parent 921b6ea commit 1fef820
Show file tree
Hide file tree
Showing 7 changed files with 1,144 additions and 195 deletions.
16 changes: 15 additions & 1 deletion app/controllers/bills.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,27 @@ async function view (request, h) {

const pageData = await ViewBillService.go(id)

return h.view('bills/view.njk', {
const view = _determineView(pageData)

return h.view(view, {
pageTitle: `Bill for ${pageData.accountName}`,
activeNavBar: 'bill-runs',
...pageData
})
}

function _determineView (pageData) {
if (pageData.billLicences) {
return 'bills/view-multi-licence.njk'
}

if (pageData.scheme === 'sroc') {
return 'bills/view-single-licence-sroc.njk'
}

return 'bills/view-single-licence-presroc.njk'
}

module.exports = {
view
}
33 changes: 29 additions & 4 deletions app/services/bills/view-bill.service.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
'use strict'

/**
* Orchestrates fetching and presenting the data needed for the view bill page
* Orchestrates fetching and presenting the data needed for one of the view bill templates
* @module ViewBillService
*/

const BillPresenter = require('../../presenters/bills/bill.presenter.js')
const FetchBillService = require('./fetch-bill-service.js')
const FetchBillingAccountService = require('./fetch-billing-account.service.js')
const FetchBillLicence = require('../bill-licences/fetch-bill-licence.service.js')
const FetchBillService = require('./fetch-bill-service.js')
const LicenceSummariesPresenter = require('../../presenters/bills/licence-summaries.presenter.js')
const ViewBillLicencePresenter = require('../../presenters/bill-licences/view-bill-licence.presenter.js')

/**
* Orchestrates fetching and presenting the data needed for the view bill page
* Orchestrates fetching and presenting the data needed for one of the view bill templates
*
* When viewing a bill we are required to return a different template depending on whether the bill is linked to one
* or multiple licences.
*
* All templates depend on the same bill and billing account data. We show the same thing at the top of the page. But
* if the bill has multiple licences we show a table that summarises them so depend on `LicenceSummariesPresenter`.
*
* Else when there is just 1 licence we show all the transactions details instead (saving the user an extra click!).
* For this we need to fetch the bill licence and use `ViewBillLicencePresenter` to generate the data.
*
* @param {string} id The UUID for the bill to view
*
Expand All @@ -22,8 +33,22 @@ async function go (id) {
const { bill, licenceSummaries } = await FetchBillService.go(id)
const billingAccount = await FetchBillingAccountService.go(bill.invoiceAccountId)

// Irrespective of of how many licences are linked to the bill, the templates always need formatted bill and billing
// account data
const billAndBillingAccountData = BillPresenter.go(bill, billingAccount)
const additionalData = LicenceSummariesPresenter.go(licenceSummaries)

let additionalData = {}

// If we have multiple licences we need to provide formatted licence summary data for the multi licence bill template
if (licenceSummaries.length > 1) {
additionalData = LicenceSummariesPresenter.go(licenceSummaries)
} else {
// Else we need to provide we need to provide bill licence data for the single licence bill templates
// (ViewBillLicencePresenter handles both PRESROC and SROC)
const billLicence = await FetchBillLicence.go(licenceSummaries[0].billingInvoiceLicenceId)

additionalData = ViewBillLicencePresenter.go(billLicence)
}

return {
...billAndBillingAccountData,
Expand Down
File renamed without changes.
Loading

0 comments on commit 1fef820

Please sign in to comment.