Skip to content

Commit

Permalink
Show credits/debits in view bill for tpt supp. (#1766)
Browse files Browse the repository at this point in the history
https://eaflood.atlassian.net/browse/WATER-4201

> Part of the work to support two-part tariff supplementary bill runs

Spotted whilst adding support for `two_part_supplementary` bill runs. Our view bill page only displays credit and debit totals if the bill run type is 'supplementary'. With us adding two-part tariff supplementary bill runs, we also need it to display them for this bill type.

Because a couple of presenters need this, and we've managed to reduce inconsistencies by ensuring our presenters are using the billing helpers we've created, this change moves the logic to a helper.

But rather than add it to our `BasePresenter`, which is getting a little overloaded, we instead create a new `BillingPresenter`, and move our existing 'billing' helpers to it.

_Then_ we add the helper to this new presenter!

Finaly, we ensure the helper says 'yes' to displaying credits for two-part tariff supplementary! 😁
  • Loading branch information
Cruikshanks authored Mar 1, 2025
1 parent 189506e commit e4a3a4f
Show file tree
Hide file tree
Showing 23 changed files with 322 additions and 366 deletions.
67 changes: 0 additions & 67 deletions app/presenters/base.presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,6 @@ function formatQuantity(units, quantity) {
return formatNumber(convertedQuantity)
}

/**
* Generates the page title for a bill run, for example, 'Anglian supplementary'
*
* Typically the page title when viewing a bill run is the region name followed by the bill run type. We determine the
* bill run type using the bill run's batch type, scheme and in the case of two-part tariff PRESROC bill runs, whether
* it is summer only or not.
*
* @param {string} regionName - Name of the region the bill run is for
* @param {string} batchType - The type of bill run; annual, supplementary or two_part_tariff
* @param {string} scheme - Whether the bill run is PRESROC (alcs) or SROC (sroc)
* @param {boolean} summer - Applies to PRESROC two-part tariff bill runs. Whether the bill run is for summer only
*
* @returns The bill run title to use in bill run pages
*/
function generateBillRunTitle(regionName, batchType, scheme, summer) {
const billRunType = formatBillRunType(batchType, scheme, summer)

return `${titleCase(regionName)} ${billRunType.toLowerCase()}`
}

/**
* Formats an abstraction day and month into its string variant, for example, 1 and 4 becomes '1 April'
*
Expand Down Expand Up @@ -100,35 +80,6 @@ function formatAbstractionPeriod(startDay, startMonth, endDay, endMonth) {
return `${startDate} to ${endDate}`
}

/**
* Formats how the bill run type for display in views
*
* @param {string} batchType - The type of bill run; annual, supplementary, two_part_tariff or two_part_supplementary
* @param {string} scheme - Whether the bill run is PRESROC (alcs) or SROC (sroc)
* @param {boolean} summer - Applies to PRESROC two-part tariff bill runs. Whether the bill run is for summer only
*
* @returns {string} The bill run type formatted for display
*/
function formatBillRunType(batchType, scheme, summer) {
if (!['two_part_tariff', 'two_part_supplementary'].includes(batchType)) {
return titleCase(batchType)
}

if (batchType === 'two_part_supplementary') {
return 'Two-part tariff supplementary'
}

if (scheme === 'sroc') {
return 'Two-part tariff'
}

if (summer) {
return 'Two-part tariff summer'
}

return 'Two-part tariff winter and all year'
}

/**
* Converts a date into the format required by the Charging Module, eg 25/03/2021 becomes 25-MAR-2021
*
Expand All @@ -151,21 +102,6 @@ function formatChargingModuleDate(date) {
return `${day}-${month}-${year}`
}

/**
* Formats a bill run's scheme (alcs or sroc) for display in a view (Old or Current)
*
* @param {string} scheme - The bill run scheme to format
*
* @returns {string} The scheme formatted for display
*/
function formatChargeScheme(scheme) {
if (scheme === 'sroc') {
return 'Current'
}

return 'Old'
}

/**
* Formats the financial year ending of a bill run for display in a view
*
Expand Down Expand Up @@ -326,12 +262,9 @@ function titleCase(value) {

module.exports = {
convertPenceToPounds,
generateBillRunTitle,
formatAbstractionDate,
formatAbstractionPeriod,
formatBillRunType,
formatChargingModuleDate,
formatChargeScheme,
formatFinancialYear,
formatLongDate,
formatLongDateTime,
Expand Down
10 changes: 2 additions & 8 deletions app/presenters/bill-licences/remove-bill-licence.presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,8 @@
* @module RemoveBillLicencePresenter
*/

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

/**
* Formats data for the confirm remove a bill licence page
Expand Down
11 changes: 2 additions & 9 deletions app/presenters/bill-licences/view-bill-licence.presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

const { formatMoney } = require('../base.presenter.js')
const { displayCreditDebitTotals } = require('../billing.presenter.js')
const ViewCompensationChargeTransactionPresenter = require('./view-compensation-charge-transaction.presenter.js')
const ViewMinimumChargeTransactionPresenter = require('./view-minimum-charge-transaction.presenter.js')
const ViewStandardChargeTransactionPresenter = require('./view-standard-charge-transaction.presenter.js')
Expand All @@ -22,16 +23,14 @@ const ViewStandardChargeTransactionPresenter = require('./view-standard-charge-t
function go(billLicence) {
const { id: billLicenceId, bill, licenceId, licenceRef, transactions } = billLicence

const displayCreditDebitTotals = _displayCreditDebitTotals(bill.billRun)

const { creditTotal, debitTotal, total } = _totals(transactions)

return {
accountNumber: bill.accountNumber,
billId: bill.id,
creditTotal,
debitTotal,
displayCreditDebitTotals,
displayCreditDebitTotals: displayCreditDebitTotals(bill.billRun.batchType),
licenceId,
licenceRef,
removeLicenceLink: _removeLicenceLink(bill.billRun, billLicenceId),
Expand All @@ -43,12 +42,6 @@ function go(billLicence) {
}
}

function _displayCreditDebitTotals(billRun) {
const { batchType } = billRun

return batchType === 'supplementary'
}

function _removeLicenceLink(billRun, billLicenceId) {
const { status } = billRun

Expand Down
10 changes: 2 additions & 8 deletions app/presenters/bill-runs/empty-bill-run-presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,8 @@
* @module EmptyBillRunPresenter
*/

const {
generateBillRunTitle,
formatBillRunType,
formatChargeScheme,
formatFinancialYear,
formatLongDate,
titleCase
} = require('../base.presenter.js')
const { formatFinancialYear, formatLongDate, titleCase } = require('../base.presenter.js')
const { formatBillRunType, formatChargeScheme, generateBillRunTitle } = require('../billing.presenter.js')

/**
* Prepares and processes bill run data for presentation
Expand Down
10 changes: 2 additions & 8 deletions app/presenters/bill-runs/errored-bill-run-presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,8 @@
* @module ErroredBillRunPresenter
*/

const {
generateBillRunTitle,
formatBillRunType,
formatChargeScheme,
formatFinancialYear,
formatLongDate,
titleCase
} = require('../base.presenter.js')
const { formatFinancialYear, formatLongDate, titleCase } = require('../base.presenter.js')
const { formatBillRunType, formatChargeScheme, generateBillRunTitle } = require('../billing.presenter.js')

/**
* Prepares and processes bill run data for presentation
Expand Down
3 changes: 2 additions & 1 deletion app/presenters/bill-runs/index-bill-runs.presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
* @module IndexBillRunsPresenter
*/

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

/**
* Formats the summary data for each bill run for use in the /bill-runs page
Expand Down
10 changes: 2 additions & 8 deletions app/presenters/bill-runs/review/review-bill-run.presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,8 @@
* @module ReviewBillRunPresenter
*/

const {
formatBillRunType,
formatChargeScheme,
formatFinancialYear,
formatLongDate,
generateBillRunTitle,
titleCase
} = require('../../base.presenter.js')
const { formatFinancialYear, formatLongDate, titleCase } = require('../../base.presenter.js')
const { formatBillRunType, formatChargeScheme, generateBillRunTitle } = require('../../billing.presenter.js')

/**
* Prepares and processes bill run, licence and filter data for presentation
Expand Down
8 changes: 2 additions & 6 deletions app/presenters/bill-runs/review/review-licence.presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,8 @@
* @module ReviewLicencePresenter
*/

const {
formatAbstractionPeriod,
formatFinancialYear,
formatLongDate,
generateBillRunTitle
} = require('../../base.presenter.js')
const { formatAbstractionPeriod, formatFinancialYear, formatLongDate } = require('../../base.presenter.js')
const { generateBillRunTitle } = require('../../billing.presenter.js')
const {
calculateTotalBillableReturns,
determineReturnLink,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* @module AllowBillRunPresenter
*/

const { formatBillRunType, formatChargeScheme } = require('../../../base.presenter.js')
const { checkPageBackLink } = require('./base-check.presenter.js')
const { formatBillRunType, formatChargeScheme } = require('../../../billing.presenter.js')
const { engineTriggers } = require('../../../../lib/static-lookups.lib.js')

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
* @module BlockedBillRunPresenter
*/

const { formatBillRunType, formatChargeScheme, formatLongDate } = require('../../../base.presenter.js')
const { formatLongDate } = require('../../../base.presenter.js')
const { checkPageBackLink } = require('./base-check.presenter.js')
const { formatBillRunType, formatChargeScheme } = require('../../../billing.presenter.js')

const LAST_PRESROC_YEAR = 2022

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @module NoAnnualBillRunPresenter
*/

const { formatBillRunType, formatChargeScheme } = require('../../../base.presenter.js')
const { formatBillRunType, formatChargeScheme } = require('../../../billing.presenter.js')
const { checkPageBackLink } = require('./base-check.presenter.js')

/**
Expand Down
18 changes: 5 additions & 13 deletions app/presenters/bill-runs/view-bill-run.presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@
* @module ViewBillRunPresenter
*/

const { formatFinancialYear, formatLongDate, formatMoney, titleCase } = require('../base.presenter.js')
const {
generateBillRunTitle,
formatBillRunType,
formatChargeScheme,
formatFinancialYear,
formatLongDate,
formatMoney,
titleCase
} = require('../base.presenter.js')
displayCreditDebitTotals,
generateBillRunTitle
} = require('../billing.presenter.js')

/**
* Formats bill run data ready for presenting in the view bill run page
Expand Down Expand Up @@ -57,7 +55,7 @@ function go(billRun, billSummaries) {
dateCreated: formatLongDate(createdAt),
debitsCount: _debitsCount(invoiceCount),
debitsTotal: formatMoney(invoiceValue),
displayCreditDebitTotals: _displayCreditDebitTotals(billRun),
displayCreditDebitTotals: displayCreditDebitTotals(billRun.batchType),
financialYear: formatFinancialYear(toFinancialYearEnding),
pageTitle: generateBillRunTitle(region.displayName, batchType, scheme, summer),
region: titleCase(region.displayName),
Expand Down Expand Up @@ -119,12 +117,6 @@ function _debitsCount(count) {
return `${count} invoices`
}

function _displayCreditDebitTotals(billRun) {
const { batchType } = billRun

return batchType === 'supplementary'
}

module.exports = {
go
}
9 changes: 2 additions & 7 deletions app/presenters/bill-runs/view-cancel-bill-run.presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,8 @@
* @module ViewCancelBillRunPresenter
*/

const {
formatBillRunType,
formatChargeScheme,
formatFinancialYear,
formatLongDate,
titleCase
} = require('../base.presenter.js')
const { formatFinancialYear, formatLongDate, titleCase } = require('../base.presenter.js')
const { formatBillRunType, formatChargeScheme } = require('../billing.presenter.js')

/**
* Prepares and processes bill run data for presentation
Expand Down
9 changes: 2 additions & 7 deletions app/presenters/bill-runs/view-send-bill-run.presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,8 @@
* @module ViewSendBillRunPresenter
*/

const {
formatBillRunType,
formatChargeScheme,
formatFinancialYear,
formatLongDate,
titleCase
} = require('../base.presenter.js')
const { formatFinancialYear, formatLongDate, titleCase } = require('../base.presenter.js')
const { formatBillRunType, formatChargeScheme } = require('../billing.presenter.js')

/**
* Prepares and processes bill run data for presentation
Expand Down
Loading

0 comments on commit e4a3a4f

Please sign in to comment.