From d9c8c3c8c860fb7340560fb560bca5b1ce1dad54 Mon Sep 17 00:00:00 2001 From: Patrick Figel Date: Tue, 26 Feb 2019 21:06:13 +0100 Subject: [PATCH] dev/core#756 - CRM/Contribute - Fix multi-currency soft credit summary This fixes an exception caused by multiple currencies being passed to CRM_Utils_Money::format. It also resolves some inconsistencies in how the summary table is rendered for soft credits. --- CRM/Contribute/BAO/ContributionSoft.php | 16 ++++---- CRM/Contribute/Page/Tab.php | 7 ++-- .../CRM/Contribute/Page/ContributionSoft.tpl | 11 +----- .../Page/ContributionSoftTotals.tpl | 37 +++++++++++++++++++ .../Contribute/Page/ContributionTotals.tpl | 6 +-- 5 files changed, 51 insertions(+), 26 deletions(-) create mode 100644 templates/CRM/Contribute/Page/ContributionSoftTotals.tpl diff --git a/CRM/Contribute/BAO/ContributionSoft.php b/CRM/Contribute/BAO/ContributionSoft.php index 1e711bd63bd8..1f6671cb3dbb 100644 --- a/CRM/Contribute/BAO/ContributionSoft.php +++ b/CRM/Contribute/BAO/ContributionSoft.php @@ -253,15 +253,14 @@ public static function getSoftContributionTotals($contact_id, $isTest = 0) { $cs = CRM_Core_DAO::executeQuery($query, $params); - $count = 0; + $count = $countCancelled = 0; $amount = $average = $cancelAmount = array(); while ($cs->fetch()) { if ($cs->amount > 0) { $count++; - $amount[] = $cs->amount; - $average[] = $cs->average; - $currency[] = $cs->currency; + $amount[] = CRM_Utils_Money::format($cs->amount, $cs->currency); + $average[] = CRM_Utils_Money::format($cs->average, $cs->currency); } } @@ -271,16 +270,17 @@ public static function getSoftContributionTotals($contact_id, $isTest = 0) { $cancelAmountSQL = CRM_Core_DAO::executeQuery($query, $params); while ($cancelAmountSQL->fetch()) { if ($cancelAmountSQL->amount > 0) { - $count++; - $cancelAmount[] = $cancelAmountSQL->amount; + $countCancelled++; + $cancelAmount[] = CRM_Utils_Money::format($cancelAmountSQL->amount, $cancelAmountSQL->currency); } } - if ($count > 0) { + if ($count > 0 || $countCancelled > 0) { return array( + $count, + $countCancelled, implode(', ', $amount), implode(', ', $average), - implode(', ', $currency), implode(', ', $cancelAmount), ); } diff --git a/CRM/Contribute/Page/Tab.php b/CRM/Contribute/Page/Tab.php index f921e552f9cb..ed5200a85243 100644 --- a/CRM/Contribute/Page/Tab.php +++ b/CRM/Contribute/Page/Tab.php @@ -153,10 +153,11 @@ public function browse() { if (!empty($softCreditList)) { $softCreditTotals = array(); - list($softCreditTotals['amount'], + list($softCreditTotals['count'], + $softCreditTotals['cancel']['count'], + $softCreditTotals['amount'], $softCreditTotals['avg'], - $softCreditTotals['currency'], - $softCreditTotals['cancelAmount'] // to get cancel amount + $softCreditTotals['cancel']['amount'] // to get cancel amount ) = CRM_Contribute_BAO_ContributionSoft::getSoftContributionTotals($this->_contactId, $isTest); $this->assign('softCredit', TRUE); diff --git a/templates/CRM/Contribute/Page/ContributionSoft.tpl b/templates/CRM/Contribute/Page/ContributionSoft.tpl index 5f7bc4943131..f8fa253111f7 100644 --- a/templates/CRM/Contribute/Page/ContributionSoft.tpl +++ b/templates/CRM/Contribute/Page/ContributionSoft.tpl @@ -27,16 +27,7 @@ {strip} {if $context neq 'membership'} - - {if $softCreditTotals.amount} - - - - {/if} - {if $softCreditTotals.cancelAmount} - - {/if} - + {include file="CRM/Contribute/Page/ContributionSoftTotals.tpl"}
{ts}Total Soft Credits{/ts} – {$softCreditTotals.amount|crmMoney:$softCreditTotals.currency}     {ts}Avg Soft Credits{/ts} – {$softCreditTotals.avg|crmMoney:$softCreditTotals.currency}   {ts}Total Cancelled Soft Credits{/ts} – {$softCreditTotals.cancelAmount|crmMoney:$softCreditTotals.currency}

{/if} diff --git a/templates/CRM/Contribute/Page/ContributionSoftTotals.tpl b/templates/CRM/Contribute/Page/ContributionSoftTotals.tpl new file mode 100644 index 000000000000..73a7460903c3 --- /dev/null +++ b/templates/CRM/Contribute/Page/ContributionSoftTotals.tpl @@ -0,0 +1,37 @@ +{* + +--------------------------------------------------------------------+ + | CiviCRM version 5 | + +--------------------------------------------------------------------+ + | Copyright CiviCRM LLC (c) 2004-2019 | + +--------------------------------------------------------------------+ + | This file is a part of CiviCRM. | + | | + | CiviCRM is free software; you can copy, modify, and distribute it | + | under the terms of the GNU Affero General Public License | + | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | + | | + | CiviCRM is distributed in the hope that it will be useful, but | + | WITHOUT ANY WARRANTY; without even the implied warranty of | + | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | + | See the GNU Affero General Public License for more details. | + | | + | You should have received a copy of the GNU Affero General Public | + | License and the CiviCRM Licensing Exception along | + | with this program; if not, contact CiviCRM LLC | + | at info[AT]civicrm[DOT]org. If you have questions about the | + | GNU Affero General Public License or the licensing of CiviCRM, | + | see the CiviCRM license FAQ at http://civicrm.org/licensing | + +--------------------------------------------------------------------+ +*} +{* Display soft credit totals for a contact or search result-set *} + + + {if $softCreditTotals.amount} + {ts}Total Soft Credit Amount{/ts} – {$softCreditTotals.amount} +   {ts}# Completed Soft Credits{/ts} – {$softCreditTotals.count} +   {ts}Avg Soft Credit Amount{/ts} – {$softCreditTotals.avg} + {/if} + {if $softCreditTotals.cancel.amount} +   {ts}Cancelled/Refunded{/ts} – {$softCreditTotals.cancel.amount} + {/if} + diff --git a/templates/CRM/Contribute/Page/ContributionTotals.tpl b/templates/CRM/Contribute/Page/ContributionTotals.tpl index e995ee4e0f05..d5735b74f095 100644 --- a/templates/CRM/Contribute/Page/ContributionTotals.tpl +++ b/templates/CRM/Contribute/Page/ContributionTotals.tpl @@ -61,11 +61,7 @@ {/if} {if $contributionSummary.soft_credit.count} - - {ts}Total Soft Credit Amount{/ts} – {$contributionSummary.soft_credit.amount} -   {ts}# Completed Soft Credits{/ts} – {$contributionSummary.soft_credit.count} -   {ts}Avg Soft Credit Amount{/ts} – {$contributionSummary.soft_credit.avg} - + {include file="CRM/Contribute/Page/ContributionSoftTotals.tpl" softCreditTotals=$contributionSummary.soft_credit} {/if} {/if}