CRM-14951: no of terms should be calculated on contribution id rather than entity...
authorCiviCRM <info@civicrm.org>
Wed, 16 Jul 2014 04:27:52 +0000 (09:57 +0530)
committerCiviCRM <info@civicrm.org>
Wed, 16 Jul 2014 04:27:52 +0000 (09:57 +0530)
CRM/Contribute/BAO/Contribution.php
CRM/Core/Payment/BaseIPN.php

index f2baaea93900b838268348eba35af6898860bd45..7e9f3721590c798cdd8a9bbe22d1a0be7e4daa65 100644 (file)
@@ -256,7 +256,7 @@ class CRM_Contribute_BAO_Contribution extends CRM_Contribute_DAO_Contribution {
     $numTerms = CRM_Core_DAO::singleValueQuery("
       SELECT membership_num_terms FROM civicrm_line_item li
       LEFT JOIN civicrm_price_field_value v ON li.price_field_value_id = v.id
-      WHERE entity_id = %1 AND entity_table = 'civicrm_contribution' AND membership_type_id = %2",
+      WHERE contribution_id = %1 AND membership_type_id = %2",
       array(1 => array($this->id, 'Integer') , 2 => array($membershipTypeID, 'Integer'))
     );
     // default of 1 is precautionary
index f41531ea6e02beb4324dd2f6b4a529a9ef70925b..3de497e6666db4dfeb03be36de7b3633c1d377d5 100644 (file)
@@ -401,6 +401,7 @@ LIMIT 1;";
             // else fall back to using current membership type
             $dao->free();
 
+            $num_terms = $contribution->getNumTermsByContributionAndMembershipType($membership->membership_type_id);
             if ($currentMembership) {
               /*
                * Fixed FOR CRM-4433
@@ -409,7 +410,6 @@ LIMIT 1;";
                */
               CRM_Member_BAO_Membership::fixMembershipStatusBeforeRenew($currentMembership, $changeToday);
 
-              $num_terms = $contribution->getNumTermsByContributionAndMembershipType($membership->membership_type_id);
               // @todo - we should pass membership_type_id instead of null here but not
               // adding as not sure of testing
               $dates = CRM_Member_BAO_MembershipType::getRenewalDatesForMembershipType($membership->id,
@@ -419,7 +419,7 @@ LIMIT 1;";
               $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, $num_terms);
             }
 
             //get the status for membership.