compucorp / uk.co.compucorp.membershipextras

Membership Extras for CiviCRM
Other
5 stars 8 forks source link

ESEB-115: Fix pro-rata calculation during leap years #514

Closed omarabuhussein closed 9 months ago

omarabuhussein commented 10 months ago

Before

If you have a fixed membership with:

image

And you are trying to create a fixed membership with payment plan in non leap year (such as 2023), but with future dates that fall within a leap year (such as 2024-01-01 to 2024-12-31), then the membership form will keep not allow you to set the end date to "2024-12-31", and instead will keep changing the end date into "2023-12-31" which is the fixed period rollover day during the current year (instead of the using the future year that you are trying to create the membership in), This will also result in showing wrong pro-rata membership fees:

https://github.com/compucorp/uk.co.compucorp.membershipextras/assets/6275540/4b77faef-ffca-461e-a4c6-a8a72bd6539f

After

The membership end date is no longer being set based on current year, and instead it is now more aligned with the selected membership dates, and because of that the membership fees are now calculated correctly:

https://github.com/compucorp/uk.co.compucorp.membershipextras/assets/6275540/1798f7d8-9d43-48d4-a179-d4c4be03ac02

I also found out that other scenarios around leap years that were not handled correctly before but they now do, such as:

In addition to that, I found that the "skip pro-rata" setting was not always utilized correctly, given it was always relying on the "Current Year" to check if the membership pro-rata should be skipped or not, instead of relying on the input start membership and end dates, so cases where the membership starts during one year (such as 2024) and ends in another (e.g 2025), or the membership is created in the future (e.g we are in 2024 and trying to create a membership that starts and ends in 2025).