-
-
Notifications
You must be signed in to change notification settings - Fork 814
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
[REF] Consolidate code in processMembership #17611
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -740,7 +740,6 @@ protected function sendReceipt($membership) { | |
* @param int $membershipID | ||
* @param $pending | ||
* @param int $contributionRecurID | ||
* @param $membershipSource | ||
* @param $isPayLater | ||
* | ||
* @return CRM_Member_BAO_Membership | ||
|
@@ -749,7 +748,6 @@ protected function sendReceipt($membership) { | |
*/ | ||
public function processMembership($contactID, $membershipTypeID, $is_test, $changeToday, $customFieldsFormatted, $numRenewTerms, $membershipID, $pending, $contributionRecurID, $isPayLater) { | ||
$allStatus = CRM_Member_PseudoConstant::membershipStatus(); | ||
$format = '%Y%m%d'; | ||
$membershipTypeDetails = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($membershipTypeID); | ||
$ids = []; | ||
|
||
|
@@ -787,54 +785,30 @@ public function processMembership($contactID, $membershipTypeID, $is_test, $chan | |
// Check and fix the membership if it is STALE | ||
CRM_Member_BAO_Membership::fixMembershipStatusBeforeRenew($currentMembership, $changeToday); | ||
|
||
// Now Renew the membership | ||
if (!$currentMembership['is_current_member']) { | ||
// membership is not CURRENT | ||
|
||
// CRM-7297 Membership Upsell - calculate dates based on new membership type | ||
$dates = CRM_Member_BAO_MembershipType::getRenewalDatesForMembershipType($currentMembership['id'], | ||
$changeToday, | ||
$membershipTypeID, | ||
$numRenewTerms | ||
); | ||
$isMembershipCurrent = $currentMembership['is_current_member']; | ||
|
||
foreach (['start_date', 'end_date'] as $dateType) { | ||
$currentMembership[$dateType] = $dates[$dateType] ?? NULL; | ||
} | ||
$currentMembership['is_test'] = $is_test; | ||
$memParams = $currentMembership; | ||
$memParams['membership_type_id'] = $membershipTypeID; | ||
} | ||
else { | ||
// CRM-7297 Membership Upsell - calculate dates based on new membership type | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All of these have been moved outside the if below as they are the same in both places |
||
$dates = CRM_Member_BAO_MembershipType::getRenewalDatesForMembershipType($currentMembership['id'], | ||
$changeToday, | ||
$membershipTypeID, | ||
$numRenewTerms | ||
); | ||
$memParams = [ | ||
'membership_type_id' => $membershipTypeID, | ||
'end_date' => $dates['end_date'] ?? NULL, | ||
'join_date' => $currentMembership['join_date'], | ||
'start_date' => $isMembershipCurrent ? $currentMembership['start_date'] : ($dates['start_date'] ?? NULL), | ||
'id' => $currentMembership['id'], | ||
'is_test' => $is_test, | ||
// Since we are renewing, make status override false. | ||
'is_override' => FALSE, | ||
'modified_id' => $contactID, | ||
'log_start_date' => $dates['log_start_date'], | ||
]; | ||
|
||
// Now Renew the membership | ||
if ($isMembershipCurrent) { | ||
// CURRENT Membership | ||
$membership = new CRM_Member_DAO_Membership(); | ||
$membership->id = $currentMembership['id']; | ||
$membership->find(TRUE); | ||
// CRM-7297 Membership Upsell - calculate dates based on new membership type | ||
$dates = CRM_Member_BAO_MembershipType::getRenewalDatesForMembershipType($membership->id, | ||
$changeToday, | ||
$membershipTypeID, | ||
$numRenewTerms | ||
); | ||
|
||
// Insert renewed dates for CURRENT membership | ||
$memParams = []; | ||
$memParams['join_date'] = $membership->join_date; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. gone - tests show unneeded |
||
$memParams['start_date'] = $membership->start_date; | ||
$memParams['end_date'] = $dates['end_date'] ?? NULL; | ||
$memParams['membership_type_id'] = $membershipTypeID; | ||
|
||
//set the log start date. | ||
$memParams['log_start_date'] = CRM_Utils_Date::customFormat($dates['log_start_date'], $format); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. gone - tests show unneeded |
||
|
||
if (empty($membership->source)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. gone - tests show unneeded |
||
$memParams['source'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', | ||
$currentMembership['id'], | ||
'source' | ||
); | ||
} | ||
|
||
if (!empty($currentMembership['id'])) { | ||
$ids['membership'] = $currentMembership['id']; | ||
} | ||
|
@@ -847,12 +821,6 @@ public function processMembership($contactID, $membershipTypeID, $is_test, $chan | |
$memParams['contribution_recur_id'] = $contributionRecurID; | ||
} | ||
|
||
//since we are renewing, | ||
//make status override false. | ||
$memParams['is_override'] = FALSE; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. moved up |
||
|
||
$params['modified_id'] = $contactID; | ||
|
||
$memParams['custom'] = $customFieldsFormatted; | ||
// @todo stop passing $ids (membership and userId may be set by this point) | ||
$membership = CRM_Member_BAO_Membership::create($memParams, $ids); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gone - tests show unneeded