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

Update Extend.php #66

Open
wants to merge 1 commit into
base: new_master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions api/v3/Membership/Extend.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,10 @@ function civicrm_api3_membership_extend($params) {
civicrm_membership.end_date AS end_date,
civicrm_membership_type.minimum_fee AS minimum_fee,
civicrm_membership_type.duration_unit AS p_unit,
civicrm_membership_type.duration_interval AS p_interval
civicrm_membership_type.duration_interval AS p_interval,
civicrm_membership_type.period_type AS p_type,
civicrm_membership_type.fixed_period_start_day AS p_start_day,
civicrm_membership_type.fixed_period_rollover_day AS p_rollover_day
FROM civicrm_membership
LEFT JOIN civicrm_membership_type ON civicrm_membership_type.id = civicrm_membership.membership_type_id ";
if (empty($params['membership_ids'])) {
Expand Down Expand Up @@ -135,7 +138,10 @@ function civicrm_api3_membership_extend($params) {
'p_unit' => $membership_query->p_unit,
'p_interval' => $membership_query->p_interval,
'end_date' => $membership_query->end_date,
'start_date' => $membership_query->start_date);
'start_date' => $membership_query->start_date,
'p_type' => $membership_query->p_type,
'p_start_day' => $membership_query->p_start_day,
'p_rollover_day' => $membership_query->p_rollover_day);
}
$membership_query->free();
$stats['memberships_checked'] = count($memberships);
Expand All @@ -146,6 +152,9 @@ function civicrm_api3_membership_extend($params) {
$expected_payment_amount = (float) $membership['minimum_fee'];
$payment_unit = $membership['p_unit'];
$payment_interval = (int) $membership['p_interval'];
$payment_type = $membership['p_type'];
$payment_start_day = $membership['p_start_day'];
$payment_rollover_day = $membership['p_rollover_day'];

if (!empty($params['custom_fee']) || !empty($params['custom_interval'])) {
// custom field/value override
Expand Down Expand Up @@ -201,6 +210,21 @@ function civicrm_api3_membership_extend($params) {

// 4. find the starting time
$date = strtotime($membership['start_date']);
// the next lines implement support for membership period type "fixed"
// TODO: This currently works only for membership periods of type "year" and starting Jan-01 with duration 1 year.
// TODO: Should be enhanced for other duration unit / duration interval and differing fixed period start days.
if ($payment_type=="fixed"){
// sanitize the content of these fields (they might have no leading zero and are only 3 characters long)
$payment_start_day=str_pad($payment_start_day, 4, "0", STR_PAD_LEFT);
$payment_rollover_day=str_pad($payment_rollover_day, 4, "0", STR_PAD_LEFT);
// Check if rollover date was reached when the membership started:
// In this case, no additional payment is needed in the following membership period (year),
// and we add 1 year to the membership start date:
$rollover = strtotime("$date-substr($payment_rollover_day, 0, 2)-substr($payment_rollover_day, 2, 2)");
if ($rollover < $date) {$date = strtotime("+1 year", $date);}
// Move $date back to the start of the payment period
$date = strtotime("$date-substr($payment_start_day, 0, 2)-substr($payment_start_day, 2, 2)");
}
if ($horizon) {
while ($date < $horizon) {
$date = strtotime("+$payment_interval $payment_unit", $date);
Expand Down