From f2f50411bb9ab9720bfad71997f3fb62e44804c3 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Mon, 20 Dec 2021 14:15:14 +1300 Subject: [PATCH] [REF] Simplify getContributionStatuses The effect of the altered calls to getContributionStatus is to get a small set of options returned. In the cases of participant & membership forms this is pending or completed. For the ufGroup option it seems cancelled & failed are also data entry options (this method should still cope if they don't exist). The existing function is really confusing - but all that confusion is designed for one form - back office contribution form - and augmented by overloading by other functions. This splits it out. Could sites be using 'weird and wonderful other statuses'? Our system really is set up around supporting specific statuses and doing financial entries for those so I think maybe we are right to not try to pander to any that could exist --- CRM/Contribute/BAO/Contribution/Utils.php | 35 ++++++++++++++++++----- CRM/Core/BAO/UFGroup.php | 2 +- CRM/Event/Form/Participant.php | 2 +- CRM/Member/Form/Membership.php | 2 +- CRM/Member/Form/MembershipRenewal.php | 2 +- 5 files changed, 32 insertions(+), 11 deletions(-) diff --git a/CRM/Contribute/BAO/Contribution/Utils.php b/CRM/Contribute/BAO/Contribution/Utils.php index 59db370f4a..d00a4a23c1 100644 --- a/CRM/Contribute/BAO/Contribution/Utils.php +++ b/CRM/Contribute/BAO/Contribution/Utils.php @@ -236,13 +236,6 @@ LIMIT 1 'Overdue', 'Partially paid', ]); - - if ($usedFor && $usedFor !== 'contribution') { - $statusNamesToUnset = array_merge($statusNamesToUnset, [ - 'Cancelled', - 'Failed', - ]); - } } else { switch ($name) { @@ -301,6 +294,34 @@ LIMIT 1 return $statuses; } + /** + * Get the options for pending and completed as an array with labels as values. + * + * @return array + */ + public static function getPendingAndCompleteStatuses(): array { + $statusIDS = [ + CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Pending'), + CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Completed'), + ]; + return array_intersect_key(CRM_Contribute_BAO_Contribution::buildOptions('contribution_status_id'), array_flip($statusIDS)); + } + + /** + * Get the options for pending and completed as an array with labels as values. + * + * @return array + */ + public static function getPendingCompleteFailedAndCancelledStatuses(): array { + $statusIDS = [ + CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Pending'), + CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Completed'), + CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Failed'), + CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Cancelled'), + ]; + return array_intersect_key(CRM_Contribute_BAO_Contribution::buildOptions('contribution_status_id'), array_flip($statusIDS)); + } + /** * CRM-8254 / CRM-6907 - override default currency if applicable * these lines exist to support a non-default currency on the form but are probably diff --git a/CRM/Core/BAO/UFGroup.php b/CRM/Core/BAO/UFGroup.php index 3b7df791c6..ad9c7d1a01 100644 --- a/CRM/Core/BAO/UFGroup.php +++ b/CRM/Core/BAO/UFGroup.php @@ -2093,7 +2093,7 @@ AND ( entity_id IS NULL OR entity_id <= 0 ) ); } elseif ($fieldName === 'contribution_status_id') { - $contributionStatuses = CRM_Contribute_BAO_Contribution_Utils::getContributionStatuses(); + $contributionStatuses = CRM_Contribute_BAO_Contribution_Utils::getPendingCompleteFailedAndCancelledStatuses(); $form->add('select', $name, $title, $contributionStatuses, $required, ['placeholder' => TRUE] diff --git a/CRM/Event/Form/Participant.php b/CRM/Event/Form/Participant.php index 204304aaf0..4d694d102e 100644 --- a/CRM/Event/Form/Participant.php +++ b/CRM/Event/Form/Participant.php @@ -1733,7 +1733,7 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment } $form->add('select', 'contribution_status_id', - ts('Payment Status'), CRM_Contribute_BAO_Contribution_Utils::getContributionStatuses('participant') + ts('Payment Status'), CRM_Contribute_BAO_Contribution_Utils::getPendingAndCompleteStatuses('participant') ); $form->add('text', 'check_number', ts('Check Number'), diff --git a/CRM/Member/Form/Membership.php b/CRM/Member/Form/Membership.php index 683f186395..8654b6aa83 100644 --- a/CRM/Member/Form/Membership.php +++ b/CRM/Member/Form/Membership.php @@ -598,7 +598,7 @@ DESC limit 1"); ); $this->add('select', 'contribution_status_id', - ts('Payment Status'), CRM_Contribute_BAO_Contribution_Utils::getContributionStatuses('membership') + ts('Payment Status'), CRM_Contribute_BAO_Contribution_Utils::getPendingAndCompleteStatuses() ); $this->add('text', 'check_number', ts('Check Number'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Contribution', 'check_number') diff --git a/CRM/Member/Form/MembershipRenewal.php b/CRM/Member/Form/MembershipRenewal.php index ff06bbf866..2bd26231ae 100644 --- a/CRM/Member/Form/MembershipRenewal.php +++ b/CRM/Member/Form/MembershipRenewal.php @@ -359,7 +359,7 @@ class CRM_Member_Form_MembershipRenewal extends CRM_Member_Form { ); $this->add('select', 'contribution_status_id', ts('Payment Status'), - CRM_Contribute_BAO_Contribution_Utils::getContributionStatuses('membership') + CRM_Contribute_BAO_Contribution_Utils::getPendingAndCompleteStatuses('membership') ); $this->add('text', 'check_number', ts('Check Number'), -- 2.25.1