-
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.
Mark for supplementary billing service and unit tests
- Loading branch information
1 parent
e0536b5
commit d4190ce
Showing
2 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
app/presenters/licences/supplementary/mark-for-supplementary-billing.presenter.js
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,54 @@ | ||
'use strict' | ||
|
||
/** | ||
* Formats the two part tariff review data ready for presenting in the amend adjustment factor page | ||
* @module MarkForSupplementaryBillingPresenter | ||
*/ | ||
|
||
const { formatFinancialYear } = require('../../base.presenter.js') | ||
|
||
function go (licence) { | ||
return { | ||
licenceId: licence.id, | ||
licenceRef: licence.licenceRef, | ||
financialYears: _yearsToDisplay() | ||
} | ||
} | ||
|
||
function _yearsToDisplay () { | ||
const currentDate = new Date() | ||
const currentYear = currentDate.getFullYear() | ||
const currentMonth = currentDate.getMonth() | ||
const years = [] | ||
let preSrocYears = false | ||
|
||
// Determine the financial year we are in | ||
const financialYearEnd = (currentMonth >= 3) ? currentYear + 1 : currentYear | ||
|
||
for (let i = 0; i < 6; i++) { | ||
const year = financialYearEnd - i | ||
|
||
if (year > 2022) { | ||
years.push({ | ||
text: `${formatFinancialYear(year)}`, | ||
value: year | ||
}) | ||
} else if (!preSrocYears) { | ||
years.push({ | ||
text: 'Before 2022', | ||
value: 'preSroc', | ||
hint: { | ||
text: 'Old charge scheme' | ||
} | ||
}) | ||
|
||
preSrocYears = true | ||
} | ||
} | ||
|
||
return years | ||
} | ||
|
||
module.exports = { | ||
go | ||
} |
38 changes: 38 additions & 0 deletions
38
app/services/licences/supplementary/mark-for-supplementary-billing.service.js
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,38 @@ | ||
'use strict' | ||
|
||
/** | ||
* Orchestrates flagging a licence for supplementary billing | ||
* @module MarkForSupplementaryBillingService | ||
*/ | ||
|
||
const LicenceModel = require('../../../../app/models/licence.model.js') | ||
const MarkForSupplementaryBillingPresenter = require('../../../presenters/licences/supplementary/mark-for-supplementary-billing.presenter.js') | ||
|
||
/** | ||
* Orchestrates fetching and presenting the data needed for the licence mark for supplementary billing page | ||
* | ||
* @param {string} licenceId - the UUID of the licence being flagged for supplementary billing | ||
* | ||
* @returns {Promise<object>} an object representing the `pageData` needed by the mark for supplementary billing page. | ||
* It contains details of the last 6 years from todays date and the licence details. | ||
*/ | ||
async function go (licenceId) { | ||
const licenceData = await _fetchLicenceData(licenceId) | ||
|
||
const pageData = MarkForSupplementaryBillingPresenter.go(licenceData) | ||
|
||
return pageData | ||
} | ||
|
||
async function _fetchLicenceData (licenceId) { | ||
return LicenceModel.query() | ||
.findById(licenceId) | ||
.select([ | ||
'id', | ||
'licenceRef' | ||
]) | ||
} | ||
|
||
module.exports = { | ||
go | ||
} |