diff --git a/app/services/licences/supplementary/determine-return-log-years.service.js b/app/services/licences/supplementary/determine-return-log-years.service.js index a646068679..649ec0abf9 100644 --- a/app/services/licences/supplementary/determine-return-log-years.service.js +++ b/app/services/licences/supplementary/determine-return-log-years.service.js @@ -8,6 +8,7 @@ const { ref } = require('objection') const ReturnLogModel = require('../../../models/return-log.model.js') +const LicenceModel = require('../../../models/licence.model.js') const SROC_START_DATE = new Date('2022-04-01') @@ -34,7 +35,14 @@ async function go (returnLogId) { flagForBilling: false } + if (startDate < SROC_START_DATE) { + // As the returns start date is before the SROC start date, we need to flag the return for pre sroc billing + await _flagLicenceForPreSrocSupplementary(licence.id) + } + if (endDate < SROC_START_DATE) { + // If the end date of the return is before the start of SROC then we do not need to flag the licence for sroc + // supplementary billing return result } @@ -63,6 +71,12 @@ async function _fetchReturnLog (returnLogId) { }) } +async function _flagLicenceForPreSrocSupplementary (licenceId) { + return LicenceModel.query() + .patch({ includeInPresrocBilling: 'yes' }) + .where('id', licenceId) +} + module.exports = { go } diff --git a/test/services/licences/supplementary/determine-return-log-years.service.test.js b/test/services/licences/supplementary/determine-return-log-years.service.test.js index 9ec11a7ef9..54e25232cd 100644 --- a/test/services/licences/supplementary/determine-return-log-years.service.test.js +++ b/test/services/licences/supplementary/determine-return-log-years.service.test.js @@ -9,6 +9,7 @@ const { expect } = Code // Test helpers const LicenceHelper = require('../../../support/helpers/licence.helper.js') +const LicenceModel = require('../../../../app/models/licence.model.js') const ReturnLogHelper = require('../../../support/helpers/return-log.helper.js') // Thing under test @@ -44,6 +45,14 @@ describe('Determine Return Log Years Service', () => { expect(result.flagForBilling).to.equal(false) expect(result.twoPartTariff).to.equal(false) }) + + it('does not flag the licence for pre sroc supplementary billing', async () => { + await DetermineReturnLogYearsService.go(returnLog.id) + + const result = await LicenceModel.query().select(['includeInPresrocBilling']).where('id', licence.id) + + expect(result[0].includeInPresrocBilling).to.equal('no') + }) }) describe('and two-part tariff is true', () => { @@ -77,6 +86,14 @@ describe('Determine Return Log Years Service', () => { expect(result.flagForBilling).to.equal(false) expect(result.twoPartTariff).to.equal(true) }) + + it('flags the licence for pre sroc supplementary billing', async () => { + await DetermineReturnLogYearsService.go(returnLog.id) + + const result = await LicenceModel.query().select(['includeInPresrocBilling']).where('id', licence.id) + + expect(result[0].includeInPresrocBilling).to.equal('yes') + }) }) describe('and the end date is after the SROC billing start date', () => { @@ -95,6 +112,14 @@ describe('Determine Return Log Years Service', () => { expect(result.flagForBilling).to.equal(true) expect(result.twoPartTariff).to.equal(true) }) + + it('flags the licence for pre sroc supplementary billing', async () => { + await DetermineReturnLogYearsService.go(returnLog.id) + + const result = await LicenceModel.query().select(['includeInPresrocBilling']).where('id', licence.id) + + expect(result[0].includeInPresrocBilling).to.equal('yes') + }) }) }) })