Skip to content

Commit

Permalink
Merge branch 'main' into jest
Browse files Browse the repository at this point in the history
  • Loading branch information
MJ B authored Oct 6, 2023
2 parents 6e3415f + 8cd3399 commit 931f99f
Show file tree
Hide file tree
Showing 3 changed files with 694 additions and 691 deletions.
9 changes: 6 additions & 3 deletions app/services/check/allocate-returns-volumes.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,21 @@ function go (chargeReference) {
returnVolumeInMegalitres = returnData.volumes.total / 1000
// Loop through each charge element
chargeReference.chargeElements.forEach((chargeElement) => {
if (!chargeElement.allocatedReturnVolume) {
chargeElement.allocatedReturnVolume = 0
}
// Check the chargeElement is not already fully allocated
if (chargeElement.billableAnnualQuantity < chargeElement.authorisedAnnualQuantity) {
if (chargeElement.allocatedReturnVolume < chargeElement.authorisedAnnualQuantity) {
// Check if the return's purpose and abstraction period match the charge element
if (_matchReturnToElement(returnData.metadata, chargeElement)) {
// Calculate how much is left to allocated to the ChargeElement from the return
let volumeLeftToAllocate = chargeElement.authorisedAnnualQuantity - chargeElement.billableAnnualQuantity
let volumeLeftToAllocate = chargeElement.authorisedAnnualQuantity - chargeElement.allocatedReturnVolume
// Check for the case that the return does not cover the full allocation
if (returnVolumeInMegalitres < volumeLeftToAllocate) {
volumeLeftToAllocate = returnVolumeInMegalitres
}

chargeElement.billableAnnualQuantity += volumeLeftToAllocate
chargeElement.allocatedReturnVolume += volumeLeftToAllocate
returnVolumeInMegalitres -= volumeLeftToAllocate
}
}
Expand Down
4 changes: 2 additions & 2 deletions app/services/check/friendly-response.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ function _formatFriendlyChargeReferences (friendlyChargeReferences, chargeRefere
function _formatFriendlyChargeElements (friendlyChargeElements, chargeElements) {
chargeElements.forEach((chargeElement) => {
const {
allocatedReturnVolume,
authorisedAnnualQuantity,
billableAnnualQuantity,
chargePurposeId,
description,
isSection127AgreementEnabled,
Expand All @@ -126,7 +126,7 @@ function _formatFriendlyChargeElements (friendlyChargeElements, chargeElements)
description,
abstractionPeriod: formatAbstractionPeriod(startDay, startMonth, endDay, endMonth),
authorisedAnnualQuantity,
billableAnnualQuantity,
allocatedReturnVolume,
timeLimit: _formatTimeLimit(timeLimitedStartDate, timeLimitedEndDate),
loss
}
Expand Down
Loading

0 comments on commit 931f99f

Please sign in to comment.