-
-
Notifications
You must be signed in to change notification settings - Fork 825
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CRM-38: Show Recurring Contributions on Membership Modal View
Currently, when viewing a membership from contact's detailed view (on memberships tab), it is hard to tell if a membership has any recurring contributions associated to it, even though you can see all payments done for the membership. Added a recurring contributions section below the contributions table currently being shown, by loading recurring contributions using ajax call to load list of recurring contributions. Added recurring contributionslist to membership edit view using ajax call.
- Loading branch information
1 parent
421e9a1
commit 6e3ba0b
Showing
7 changed files
with
271 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
<?php | ||
|
||
/** | ||
* Shows list of recurring contributions related to membership. | ||
*/ | ||
class CRM_Member_Page_RecurringContributions extends CRM_Core_Page { | ||
|
||
/** | ||
* ID of the membership for which we need to see related recurring contributions. | ||
* | ||
* @var int | ||
*/ | ||
private $membershipID = NULL; | ||
|
||
/** | ||
* ID of the contact owner of the membership. | ||
* | ||
* @var int | ||
*/ | ||
public $contactID = NULL; | ||
|
||
/** | ||
* Builds list of recurring contributions associated to membership. | ||
* | ||
* @return null | ||
*/ | ||
public function run() { | ||
$this->membershipID = CRM_Utils_Request::retrieve('membershipID', 'Positive', $this); | ||
$this->contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE); | ||
|
||
$this->loadRecurringContributions(); | ||
|
||
return parent::run(); | ||
} | ||
|
||
/** | ||
* Loads recurring contributions and assigns them to the form, to be used on | ||
* the template. | ||
*/ | ||
private function loadRecurringContributions() { | ||
$recurringContributions = $this->getRecurContributions($this->membershipID); | ||
|
||
if (!empty($recurringContributions)) { | ||
$this->assign('recurRows', $recurringContributions); | ||
$this->assign('recur', TRUE); | ||
} | ||
} | ||
|
||
/** | ||
* Obtains list of recurring contributions associated to a membership. | ||
* | ||
* @param int $membershipID | ||
* | ||
* @return array | ||
*/ | ||
private function getRecurContributions($membershipID) { | ||
$result = civicrm_api3('MembershipPayment', 'get', array( | ||
'sequential' => 1, | ||
'contribution_id.contribution_recur_id.id' => ['IS NOT NULL' => TRUE], | ||
'options' => ['limit' => 0], | ||
'return' => array( | ||
'contribution_id.contribution_recur_id.id', | ||
'contribution_id.contribution_recur_id.contact_id', | ||
'contribution_id.contribution_recur_id.start_date', | ||
'contribution_id.contribution_recur_id.end_date', | ||
'contribution_id.contribution_recur_id.next_sched_contribution_date', | ||
'contribution_id.contribution_recur_id.amount', | ||
'contribution_id.contribution_recur_id.currency', | ||
'contribution_id.contribution_recur_id.frequency_unit', | ||
'contribution_id.contribution_recur_id.frequency_interval', | ||
'contribution_id.contribution_recur_id.installments', | ||
'contribution_id.contribution_recur_id.contribution_status_id', | ||
'contribution_id.contribution_recur_id.is_test', | ||
'contribution_id.contribution_recur_id.payment_processor_id', | ||
), | ||
'membership_id' => $membershipID, | ||
)); | ||
$recurringContributions = array(); | ||
$contributionStatuses = CRM_Contribute_PseudoConstant::contributionStatus(); | ||
|
||
foreach ($result['values'] as $payment) { | ||
$recurringContributionID = $payment['contribution_id.contribution_recur_id.id']; | ||
$alreadyProcessed = isset($recurringContributions[$recurringContributionID]); | ||
|
||
if ($alreadyProcessed) { | ||
continue; | ||
} | ||
|
||
foreach ($payment as $field => $value) { | ||
$key = strtr($field, array('contribution_id.contribution_recur_id.' => '')); | ||
$recurringContributions[$recurringContributionID][$key] = $value; | ||
} | ||
|
||
$contactID = $recurringContributions[$recurringContributionID]['contact_id']; | ||
$contributionStatusID = $recurringContributions[$recurringContributionID]['contribution_status_id']; | ||
|
||
$recurringContributions[$recurringContributionID]['id'] = $recurringContributionID; | ||
$recurringContributions[$recurringContributionID]['contactId'] = $contactID; | ||
$recurringContributions[$recurringContributionID]['contribution_status'] = CRM_Utils_Array::value($contributionStatusID, $contributionStatuses); | ||
|
||
$this->setActionsForRecurringContribution($recurringContributionID, $recurringContributions[$recurringContributionID]); | ||
} | ||
return $recurringContributions; | ||
} | ||
|
||
/** | ||
* Calculates and assigns the actions available for given recurring | ||
* contribution. | ||
* | ||
* @param int $recurID | ||
* @param array $recurringContribution | ||
*/ | ||
private function setActionsForRecurringContribution($recurID, &$recurringContribution) { | ||
$action = array_sum(array_keys($this->recurLinks($recurID))); | ||
// no action allowed if it's not active | ||
$recurringContribution['is_active'] = ($recurringContribution['contribution_status_id'] != 3); | ||
if ($recurringContribution['is_active']) { | ||
$details = CRM_Contribute_BAO_ContributionRecur::getSubscriptionDetails($recurringContribution['id'], 'recur'); | ||
$hideUpdate = $details->membership_id & $details->auto_renew; | ||
if ($hideUpdate || empty($details->processor_id)) { | ||
$action -= CRM_Core_Action::UPDATE; | ||
} | ||
$recurringContribution['action'] = CRM_Core_Action::formLink( | ||
$this->recurLinks($recurID), | ||
$action, | ||
array( | ||
'cid' => $this->contactID, | ||
'crid' => $recurID, | ||
'cxt' => 'contribution', | ||
), | ||
ts('more'), | ||
FALSE, | ||
'contribution.selector.recurring', | ||
'Contribution', | ||
$recurID | ||
); | ||
} | ||
} | ||
|
||
/** | ||
* This method returns the links that are given for recur search row. | ||
* currently the links added for each row are: | ||
* - View | ||
* - Edit | ||
* - Cancel | ||
* | ||
* @param bool $id | ||
* | ||
* @return array | ||
*/ | ||
private function recurLinks($id) { | ||
return CRM_Contribute_Page_Tab::recurLinks($id, 'contribution'); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{if $recur} | ||
<div class="solid-border-top"> | ||
<br /><label>{ts 1=$displayName}Recurring Contributions{/ts}</label> | ||
</div> | ||
{include file="CRM/Contribute/Page/ContributionRecur.tpl" action=16} | ||
{/if} |