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

Add new single licence bill templates #514

Merged
merged 5 commits into from
Nov 10, 2023
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
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
Loading