-
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 new view bill run presenter (#541)
https://eaflood.atlassian.net/browse/WATER-4223 This presenter has been added to format the bill run data used in a new bill run page that will replace the existing one in the legacy service. The page displays top-level details about the bill run (date created type, region etc) and then a summary for each bill linked to the bill run. This presenter handles the top-level information returned by `FetchBillRunService`.
- Loading branch information
1 parent
cb726d6
commit 30a225f
Showing
2 changed files
with
441 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
'use strict' | ||
|
||
/** | ||
* Formats bill run data ready for presenting in the view bill run page | ||
* @module ViewBillRunPresenter | ||
*/ | ||
|
||
const { | ||
capitalize, | ||
formatLongDate, | ||
formatMoney | ||
} = require('../base.presenter.js') | ||
|
||
function go (billRun) { | ||
const { | ||
batchType, | ||
billingBatchId, | ||
billRunNumber, | ||
createdAt, | ||
creditNoteCount, | ||
creditNoteValue, | ||
invoiceCount, | ||
invoiceValue, | ||
isSummer, | ||
netTotal, | ||
region, | ||
scheme, | ||
status, | ||
transactionFileReference, | ||
toFinancialYearEnding | ||
} = billRun | ||
|
||
const billRunType = _billRunType(batchType, isSummer, scheme) | ||
const regionName = capitalize(region.displayName) | ||
|
||
return { | ||
billsCount: _billsCount(creditNoteCount, invoiceCount, billRunType), | ||
billRunId: billingBatchId, | ||
billRunNumber, | ||
billRunStatus: status, | ||
billRunTotal: _billRunTotal(netTotal), | ||
billRunType, | ||
chargeScheme: _chargeScheme(scheme), | ||
creditsCount: _creditsCount(creditNoteCount), | ||
creditsTotal: formatMoney(creditNoteValue), | ||
dateCreated: formatLongDate(createdAt), | ||
debitsCount: _debitsCount(invoiceCount), | ||
debitsTotal: formatMoney(invoiceValue), | ||
displayCreditDebitTotals: _displayCreditDebitTotals(billRun), | ||
financialYear: _financialYear(toFinancialYearEnding), | ||
pageTitle: _pageTitle(regionName, billRunType), | ||
region: regionName, | ||
transactionFile: transactionFileReference | ||
} | ||
} | ||
|
||
function _billsCount (creditsCount, debitsCount, billRunType) { | ||
const total = creditsCount + debitsCount | ||
|
||
if (total === 1) { | ||
return `1 ${billRunType} bill` | ||
} | ||
|
||
return `${total} ${billRunType} bills` | ||
} | ||
|
||
function _billRunTotal (valueInPence) { | ||
const valueAsMoney = formatMoney(valueInPence) | ||
|
||
if (valueInPence < 0) { | ||
return `${valueAsMoney} credit` | ||
} | ||
|
||
return valueAsMoney | ||
} | ||
|
||
function _billRunType (batchType, isSummer, scheme) { | ||
if (batchType !== 'two_part_tariff') { | ||
return capitalize(batchType) | ||
} | ||
|
||
if (scheme === 'sroc') { | ||
return 'Two-part tariff' | ||
} | ||
|
||
if (isSummer) { | ||
return 'Two-part tariff summer' | ||
} | ||
|
||
return 'Two-part tariff winter and all year' | ||
} | ||
|
||
function _chargeScheme (scheme) { | ||
if (scheme === 'sroc') { | ||
return 'Current' | ||
} | ||
|
||
return 'Old' | ||
} | ||
|
||
function _creditsCount (count) { | ||
if (count === 1) { | ||
return '1 credit note' | ||
} | ||
|
||
return `${count} credit notes` | ||
} | ||
|
||
function _debitsCount (count) { | ||
if (count === 1) { | ||
return '1 invoice' | ||
} | ||
|
||
return `${count} invoices` | ||
} | ||
|
||
function _displayCreditDebitTotals (billRun) { | ||
const { batchType } = billRun | ||
|
||
return batchType === 'supplementary' | ||
} | ||
|
||
function _financialYear (financialYearEnding) { | ||
return `${financialYearEnding - 1} to ${financialYearEnding}` | ||
} | ||
|
||
function _pageTitle (regionName, billRunType) { | ||
const lowercaseBillRunType = billRunType.toLowerCase() | ||
|
||
return `${regionName} ${lowercaseBillRunType}` | ||
} | ||
|
||
module.exports = { | ||
go | ||
} |
Oops, something went wrong.