Skip to content

Commit

Permalink
BASWSPRT-249: Set membership's status properly when recording the pay…
Browse files Browse the repository at this point in the history
…ment

PR: civicrm#20095
  • Loading branch information
ahed-compucorp committed Jul 16, 2021
1 parent 6b83b70 commit f58e729
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions CRM/Contribute/BAO/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -4811,11 +4811,8 @@ public static function updateMembershipBasedOnCompletionOfContribution($contribu
'membership_activity_status' => 'Completed',
];

$currentMembership = CRM_Member_BAO_Membership::getContactMembership($membershipParams['contact_id'],
$membershipParams['membership_type_id'],
$membershipParams['is_test'],
$membershipParams['id']
);
$currentMembership = [];
CRM_Member_BAO_Membership::retrieve($membershipParams, $currentMembership);

// CRM-8141 update the membership type with the value recorded in log when membership created/renewed
// this picks up membership type changes during renewals
Expand All @@ -4833,7 +4830,8 @@ public static function updateMembershipBasedOnCompletionOfContribution($contribu
$membershipParams['membership_type_id'] = $dao->membership_type_id;
}
}
if (empty($membership['end_date']) || (int) $membership['status_id'] !== CRM_Core_PseudoConstant::getKey('CRM_Member_BAO_Membership', 'status_id', 'Pending')) {
$pendingMembershipStatusID = CRM_Core_PseudoConstant::getKey('CRM_Member_BAO_Membership', 'status_id', 'Pending');
if (empty($membership['end_date']) || (int) $membership['status_id'] !== $pendingMembershipStatusID) {
// Passing num_terms to the api triggers date calculations, but for pending memberships these may be already calculated.
// sigh - they should be consistent but removing the end date check causes test failures & maybe UI too?
// The api assumes num_terms is a special sauce for 'is_renewal' so we need to not pass it when updating a pending to completed.
Expand All @@ -4851,7 +4849,16 @@ public static function updateMembershipBasedOnCompletionOfContribution($contribu
'start_date',
'end_date',
], NULL);
if ($currentMembership) {
if ($currentMembership && (int) $currentMembership['status_id'] === $pendingMembershipStatusID) {
$currentMembership['join_date'] = $currentMembership['join_date'] ?? NULL;
$currentMembership['start_date'] = $currentMembership['start_date'] ?? NULL;
$currentMembership['end_date'] = $currentMembership['end_date'] ?? NULL;

$dates = CRM_Member_BAO_MembershipType::getDatesForMembershipType($membershipParams['membership_type_id'],
$currentMembership['join_date'], $currentMembership['start_date'], $currentMembership['end_date']
);
}
else {
/*
* Fixed FOR CRM-4433
* In BAO/Membership.php(renewMembership function), we skip the extend membership date and status
Expand Down

0 comments on commit f58e729

Please sign in to comment.