compucorp / uk.co.compucorp.membershipextras

Membership Extras for CiviCRM
Other
5 stars 8 forks source link

MAE-751: Consolidate logic for calculating membership instalment dates #435

Closed olayiwola-compucorp closed 2 years ago

olayiwola-compucorp commented 2 years ago

Overview

The instalment dates listed on the new membership screen can sometimes not match the contribution instalment dates after creation, this difference is noticeable when using a day above 28. In this PR we use the same logic used in calculating contribution dates to calculate the instalment dates for the new membership screen.

Before

The instalment dates on the new membership screen.

Screenshot 2022-06-15 at 09 04 37

The new membership screen uses the inbuilt PHP DateTime function to add months to date, and this function behaves in some certain way as we've seen in the screen above, 2022-01-29 + 1month = 2022-03-01 and subsequent months use the day from the previous calculation.

The actual instalment dates after creation.

date

Whereas when creating the contributions, the instalment dates are calculated using the custom function getSameDayNextMonth https://github.com/compucorp/uk.co.compucorp.membershipextras/blob/326e69ed0468cb4f2b40ad6adc0b6630257e84d3/CRM/MembershipExtras/Service/InstalmentReceiveDateCalculator.php#L102 to add months to date, this function helps handle the scenario mentioned above such that 2022-01-29 + 1month = 2022-02-28 and subsequent dates makes use of the day from the first calculation.

After

New membership screen using the function getSameDayNextMonth to calculate instalment dates

Screenshot 2022-06-15 at 09 31 48 Screenshot 2022-06-15 at 09 32 02 Screenshot 2022-06-15 at 09 32 13