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

Add logic 2 determine billable abstraction periods #81

Merged
merged 7 commits into from
Jan 19, 2023

Conversation

Cruikshanks
Copy link
Member

https://eaflood.atlassian.net/browse/WATER-3834

In Implement abstraction period query using Objection we amended the query used in test/services/supplementary-billing/fetch-charge-versions.service.test.js to include abstraction period information for each charge version candidate.

We're aiming to get to a 'billable days' value but the next step is determining for each abstraction period whether it is relevant to the current billing period, and if so, how much of it.

This change implements a service which can be used to answer both those questions.

https://eaflood.atlassian.net/browse/WATER-3834

In [Implement abstraction period query using Objection](#66) we amended the query used in `test/services/supplementary-billing/fetch-charge-versions.service.test.js` to include abstraction period information for each charge version candidate.

We're aiming to get to a 'billable days' value but the next step is determining for each abstraction period, is it relevant to the current billing period, and if so, how much of it.

This change implements a service which can be used to answer both those questions.
@Cruikshanks Cruikshanks added the enhancement New feature or request label Jan 10, 2023
@Cruikshanks Cruikshanks self-assigned this Jan 10, 2023
@Jozzey Jozzey marked this pull request as ready for review January 19, 2023 16:44
@Jozzey Jozzey merged commit e3e16c5 into main Jan 19, 2023
@Jozzey Jozzey deleted the add-logic-to-determine-billable-abstraction-periods branch January 19, 2023 16:58
Copy link
Member Author

@Cruikshanks Cruikshanks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to add some documentation and my feelings on my first attempt at solving the problem!

But once I've done that this is all good to go 😁

Comment on lines +18 to +51
function _abstractionPeriods (billingPeriod, chargePurpose) {
const billingPeriodStartYear = billingPeriod.startDate.getFullYear()
const billingPeriodEndYear = billingPeriod.endDate.getFullYear()
const {
abstractionPeriodStartDay: startDay,
abstractionPeriodStartMonth: startMonth,
abstractionPeriodEndDay: endDay,
abstractionPeriodEndMonth: endMonth
} = chargePurpose
const firstPeriod = {}

if (endMonth === startMonth) {
if (endDay >= startDay) {
firstPeriod.startDate = new Date(billingPeriodEndYear, startMonth - 1, startDay)
firstPeriod.endDate = new Date(billingPeriodEndYear, endMonth - 1, endDay)
} else {
firstPeriod.startDate = new Date(billingPeriodStartYear, startMonth - 1, startDay)
firstPeriod.endDate = new Date(billingPeriodEndYear, endMonth - 1, endDay)
}
} else if (endMonth >= startMonth) {
firstPeriod.startDate = new Date(billingPeriodEndYear, startMonth - 1, startDay)
firstPeriod.endDate = new Date(billingPeriodEndYear, endMonth - 1, endDay)
} else {
firstPeriod.startDate = new Date(billingPeriodStartYear, startMonth - 1, startDay)
firstPeriod.endDate = new Date(billingPeriodEndYear, endMonth - 1, endDay)
}

const previousPeriod = {
startDate: _subtractOneYear(firstPeriod.startDate),
endDate: _subtractOneYear(firstPeriod.endDate)
}

return [previousPeriod, firstPeriod]
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I look at this function and go 🤮 . But I have a stinkin' cold and it's the end of the day, so don't know how I'd go about improving it.

But I definitely need to add some documentation to give some context as to what on earth it is trying to achieve.

Let me at least do that and then we're all good IMHO (though any suggestions for improvement I'm open to!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants