compucorp / uk.co.compucorp.membershipextras

Membership Extras for CiviCRM
Other
5 stars 8 forks source link

MAE-591: Use 'next scheduled contribution date' instead of membership end date for autorenewal #393

Closed omarabuhussein closed 3 years ago

omarabuhussein commented 3 years ago

Overview

Some of the current criteria we have for autorenewal are:

And if any of these conditions apply, then we proceed with the autorenewal.

Here I change this to use the payment plan "next scheduled contribution date" as a condition for auto-renewal, so if this field value is less or equal today date (with days to renew in advance setting in mind) then we renew the payment plan, otherwise we don't.

And as part of this, we now set the new first installment receive date to equal the "next scheduled contribution date" instead of using the new membership "start date", where the rest of the installments follow the first installment date same as before.

This simplify the autorenewal by removing the dependency on the related membership dates, and allows for better flexibility in controlling when the renewal should happen and controlling the new installment dates.

Hence that this does not mean we removed other autorenewal conditions, such as that you still need to have active renewal subscription line items for the renewal to happen, and that the payment plan should not be cancelled ..etc

As part of this PR, I also did the following:

1- Created an upgrader to update the "next scheduled contribution date" for all existing offline payment plans to equal the minimum membership end date attached to it, which should ensure that the renewals should happen next time at their correct dates. 2- I changed the autorenewal job to use the "recurring contribution status" option group instead of "contribution status" option group, it is just happened that the Values for the option values in each option group are almost similar such as for the "Cancelled" status were both equal 3. Also the refunded status does not exist for recurring contributions, so I removed it from the query that get the recurring contributions to renew and just kept the part where it check for non cancelled recurring contributions.