-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add logic 2 determine billable abstraction periods #81
Conversation
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.
It's not calculating the billable days or limiting the results to periods to be considered. But it is implementing the logic we outlined in https://eaflood.atlassian.net/browse/WATER-3834 to give us the raw data we'll need.
There was a problem hiding this 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 😁
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] | ||
} |
There was a problem hiding this comment.
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!)
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.