From 9c09f5b790309fa7924aaf3298e214e459f958f1 Mon Sep 17 00:00:00 2001 From: Andrew Hunt Date: Tue, 2 Apr 2013 15:16:47 -0400 Subject: [PATCH] check number of terms when updating member payment status --- CRM/Contribute/BAO/Contribution.php | 23 ++++++++++++++++------- CRM/Price/BAO/LineItem.php | 2 ++ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index d6087b9c39..f14ae8ff5e 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -1681,17 +1681,26 @@ LEFT JOIN civicrm_contribution contribution ON ( componentPayment.contribution_ // else fall back to using current membership type $dao->free(); + // Figure out number of terms + $numterms = 1; + $lineitems = CRM_Price_BAO_LineItem::getLineItems($contributionId, 'contribution'); + foreach ($lineitems as $lineitem) { + if ($membership->membership_type_id == CRM_Utils_Array::value('membership_type_id', $lineitem)) { + $numterms = CRM_Utils_Array::value('membership_num_terms', $lineitem); + + // in case membership_num_terms comes through as null or zero + $numterms = $numterms >= 1 ? $numterms : 1; + break; + } + } + if ($currentMembership) { - CRM_Member_BAO_Membership::fixMembershipStatusBeforeRenew($currentMembership, - $changeToday = NULL - ); - $dates = CRM_Member_BAO_MembershipType::getRenewalDatesForMembershipType($membership->id, - $changeToday = NULL - ); + CRM_Member_BAO_Membership::fixMembershipStatusBeforeRenew($currentMembership, NULL); + $dates = CRM_Member_BAO_MembershipType::getRenewalDatesForMembershipType($membership->id, NULL, NULL, $numterms); $dates['join_date'] = CRM_Utils_Date::customFormat($currentMembership['join_date'], $format); } else { - $dates = CRM_Member_BAO_MembershipType::getDatesForMembershipType($membership->membership_type_id); + $dates = CRM_Member_BAO_MembershipType::getDatesForMembershipType($membership->membership_type_id, null, null, null, $numterms); } //get the status for membership. diff --git a/CRM/Price/BAO/LineItem.php b/CRM/Price/BAO/LineItem.php index 89723470f1..2c3de75543 100644 --- a/CRM/Price/BAO/LineItem.php +++ b/CRM/Price/BAO/LineItem.php @@ -112,6 +112,7 @@ class CRM_Price_BAO_LineItem extends CRM_Price_DAO_LineItem { pf.label as field_title, pf.html_type, pfv.membership_type_id, + pfv.membership_num_terms, li.price_field_id, li.participant_count, li.price_field_value_id, @@ -158,6 +159,7 @@ class CRM_Price_BAO_LineItem extends CRM_Price_DAO_LineItem { 'description' => $dao->description, 'entity_id' => $entityId, 'membership_type_id' => $dao->membership_type_id, + 'membership_num_terms' => $dao->membership_num_terms, ); } return $lineItems; -- 2.25.1