From 821c4f61b32cd25334d9bb69abee589eebfc883e Mon Sep 17 00:00:00 2001 From: Alan Cruikshanks Date: Tue, 18 Apr 2023 14:30:38 +0100 Subject: [PATCH] Implement possible fix Though have confirmed manually locally via a number of scenarios this does the trick. --- .../fetch-charge-versions.service.js | 5 +++-- .../process-billing-batch.service.js | 8 +++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/app/services/supplementary-billing/fetch-charge-versions.service.js b/app/services/supplementary-billing/fetch-charge-versions.service.js index 0d547238bf..e9db8fe61e 100644 --- a/app/services/supplementary-billing/fetch-charge-versions.service.js +++ b/app/services/supplementary-billing/fetch-charge-versions.service.js @@ -34,13 +34,14 @@ async function _fetch (regionId, billingPeriod) { 'scheme', 'chargeVersions.startDate', 'chargeVersions.endDate', - 'invoiceAccountId' + 'invoiceAccountId', + 'status' ]) .innerJoinRelated('licence') .where('scheme', 'sroc') .where('includeInSrocSupplementaryBilling', true) .where('regionId', regionId) - .where('chargeVersions.status', 'current') + // .where('chargeVersions.status', 'current') .where('chargeVersions.startDate', '>=', billingPeriod.startDate) .where('chargeVersions.startDate', '<=', billingPeriod.endDate) .whereNotExists( diff --git a/app/services/supplementary-billing/process-billing-batch.service.js b/app/services/supplementary-billing/process-billing-batch.service.js index 625cd629b0..5c5618408c 100644 --- a/app/services/supplementary-billing/process-billing-batch.service.js +++ b/app/services/supplementary-billing/process-billing-batch.service.js @@ -73,12 +73,14 @@ async function go (billingBatch, billingPeriod) { currentBillingData.billingInvoice = billingInvoice currentBillingData.billingInvoiceLicence = billingInvoiceLicence - const calculatedTransactions = _generateCalculatedTransactions(billingPeriod, chargeVersion, billingBatchId, billingInvoiceLicence) - currentBillingData.calculatedTransactions.push(...calculatedTransactions) + if (chargeVersion.status === 'current') { + const calculatedTransactions = _generateCalculatedTransactions(billingPeriod, chargeVersion, billingBatchId, billingInvoiceLicence) + currentBillingData.calculatedTransactions.push(...calculatedTransactions) + } } await _finaliseCurrentInvoiceLicence(currentBillingData, billingPeriod, billingBatch) - await _processReplacedChargeVersions(currentBillingData, billingBatch, billingPeriod) + // await _processReplacedChargeVersions(currentBillingData, billingBatch, billingPeriod) await _finaliseBillingBatch(billingBatch, chargeVersions, currentBillingData.isEmpty)