From c6a41a55d1044ea86cf2b17774584eeac6c355ea Mon Sep 17 00:00:00 2001 From: Carlos Capote Date: Tue, 11 Oct 2016 18:40:59 +0100 Subject: [PATCH] CRM-19418 Fixes showing cancelled contribution box on 4.6 --- CRM/Contribute/BAO/Contribution.php | 15 +++++++++++ CRM/Contribute/Form/Contribution.php | 9 +++++++ .../CRM/Contribute/Form/Contribution.tpl | 25 +++++++++++-------- 3 files changed, 39 insertions(+), 10 deletions(-) diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index 8fa4a144ba..9d66b15bc5 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -3183,6 +3183,21 @@ WHERE contribution_id = %1 "; } } + + /** + * Is this contribution status a reversal. + * + * If so we would expect to record a negative value in the financial_trxn table. + * + * @param int $status_id + * + * @return bool + */ + public static function isContributionStatusNegative($status_id) { + $reversalStatuses = array('Cancelled', 'Chargeback', 'Refunded'); + return in_array(CRM_Contribute_PseudoConstant::contributionStatus($status_id, 'name'), $reversalStatuses); + } + /** * Check status validation on update of a contribution. * diff --git a/CRM/Contribute/Form/Contribution.php b/CRM/Contribute/Form/Contribution.php index 000f247fa2..8c9a3b5cb5 100644 --- a/CRM/Contribute/Form/Contribution.php +++ b/CRM/Contribute/Form/Contribution.php @@ -707,6 +707,15 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP } } + // define the status IDs that show the cancellation info, see CRM-17589 + $cancelInfo_show_ids = array(); + foreach (array_keys($statusName) as $status_id) { + if (CRM_Contribute_BAO_Contribution::isContributionStatusNegative($status_id)) { + $cancelInfo_show_ids[] = "'$status_id'"; + } + } + $this->assign('cancelInfo_show_ids', implode(',', $cancelInfo_show_ids)); + if ($this->_id) { $contributionStatus = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $this->_id, 'contribution_status_id'); $name = CRM_Utils_Array::value($contributionStatus, $statusName); diff --git a/templates/CRM/Contribute/Form/Contribution.tpl b/templates/CRM/Contribute/Form/Contribution.tpl index c889d54d42..ee73d68f26 100644 --- a/templates/CRM/Contribute/Form/Contribution.tpl +++ b/templates/CRM/Contribute/Form/Contribution.tpl @@ -467,6 +467,11 @@ } } + function status() { + cj("#cancel_date").val(''); + cj("#cancel_reason").val(''); + } + {/literal} @@ -500,16 +505,16 @@ } ); - function showHideCancelInfo(obj) { - if (obj.find(":selected").text() == 'Refunded' || obj.find(":selected").text() == 'Cancelled') { - $('#cancelInfo').show( ); - $('#total_amount').attr('readonly', true); - } - else { - $("#cancel_date").val(''); - $("#cancel_reason").val(''); - $('#cancelInfo').hide( ); - $("#total_amount").removeAttr('readonly'); + function showHideCancelInfo(obj) { + var cancelInfo_show_ids = [{/literal}{$cancelInfo_show_ids}{literal}]; + if (cancelInfo_show_ids.indexOf(obj.val()) > -1) { + $('#cancelInfo').show( ); + $('#total_amount').attr('readonly', true); + } + else { + status(); + $('#cancelInfo').hide( ); + $("#total_amount").removeAttr('readonly'); } } }); -- 2.25.1