diff --git a/app/services/supplementary-billing/fetch-charge-versions.service.js b/app/services/supplementary-billing/fetch-charge-versions.service.js index 1ef8a61567..b1043aef61 100644 --- a/app/services/supplementary-billing/fetch-charge-versions.service.js +++ b/app/services/supplementary-billing/fetch-charge-versions.service.js @@ -47,6 +47,7 @@ async function _fetch (regionId, billingPeriod) { ChargeVersionWorkflow.query() .select(1) .whereColumn('chargeVersions.licenceId', 'chargeVersionWorkflows.licenceId') + .whereNull('chargeVersionWorkflows.dateDeleted') ) .orderBy([ { column: 'chargeVersions.invoiceAccountId' }, diff --git a/test/services/supplementary-billing/fetch-charge-versions.service.test.js b/test/services/supplementary-billing/fetch-charge-versions.service.test.js index e65af9a185..70d312455e 100644 --- a/test/services/supplementary-billing/fetch-charge-versions.service.test.js +++ b/test/services/supplementary-billing/fetch-charge-versions.service.test.js @@ -41,6 +41,7 @@ describe('Fetch Charge Versions service', () => { let chargeElement let chargePurpose let changeReason + let licence beforeEach(async () => { billingPeriod = { @@ -48,12 +49,13 @@ describe('Fetch Charge Versions service', () => { endDate: new Date('2023-03-31') } - const { licenceId } = await LicenceHelper.add({ + licence = await LicenceHelper.add({ regionId, isWaterUndertaker: true, includeInSrocSupplementaryBilling: true, includeInSupplementaryBilling: 'yes' }) + const { licenceId } = licence changeReason = await ChangeReasonHelper.add({ triggersMinimumCharge: true }) // This creates a 'current' SROC charge version @@ -87,6 +89,20 @@ describe('Fetch Charge Versions service', () => { }) }) + describe('including those linked to soft-deleted workflow records', () => { + beforeEach(async () => { + await ChargeVersionWorkflowHelper.add({ licenceId: licence.licenceId, dateDeleted: new Date('2022-04-01') }) + }) + + it('returns the SROC charge versions that are applicable', async () => { + const result = await FetchChargeVersionsService.go(regionId, billingPeriod) + + expect(result).to.have.length(2) + expect(result[0].chargeVersionId).to.equal(testRecords[0].chargeVersionId) + expect(result[1].chargeVersionId).to.equal(testRecords[1].chargeVersionId) + }) + }) + it("returns both 'current' and 'superseded' SROC charge versions that are applicable", async () => { const result = await FetchChargeVersionsService.go(regionId, billingPeriod)