Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change where the allocated Return volume is held #445

Merged
merged 2 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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