dev/core#756 - CRM/Contribute - Fix multi-currency soft credit summary
authorPatrick Figel <pfigel@greenpeace.org>
Tue, 26 Feb 2019 20:06:13 +0000 (21:06 +0100)
committerPatrick Figel <pfigel@greenpeace.org>
Wed, 27 Feb 2019 20:38:20 +0000 (21:38 +0100)
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
CRM/Contribute/Page/Tab.php
templates/CRM/Contribute/Page/ContributionSoft.tpl
templates/CRM/Contribute/Page/ContributionSoftTotals.tpl [new file with mode: 0644]
templates/CRM/Contribute/Page/ContributionTotals.tpl

index 1e711bd63bd8d9683b043b83927983bfc8a86831..1f6671cb3dbb98ce806cc6cc49735b8dd279495e 100644 (file)
@@ -253,15 +253,14 @@ class CRM_Contribute_BAO_ContributionSoft extends CRM_Contribute_DAO_Contributio
 
     $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 @@ class CRM_Contribute_BAO_ContributionSoft extends CRM_Contribute_DAO_Contributio
     $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(',&nbsp;', $amount),
         implode(',&nbsp;', $average),
-        implode(',&nbsp;', $currency),
         implode(',&nbsp;', $cancelAmount),
       );
     }
index f921e552f9cb17f50deaa993c53750d5d68c6431..ed5200a852430d02ab4894118bff084e5cf86208 100644 (file)
@@ -153,10 +153,11 @@ class CRM_Contribute_Page_Tab extends CRM_Core_Page {
     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);
index 5f7bc49431318ae452c2de4aab70b0b9475cae73..f8fa253111f7d71292e9dd30213a97f5f3dc6248 100644 (file)
 {strip}
 {if $context neq 'membership'}
     <table class="form-layout-compressed">
-        <tr>
-          {if $softCreditTotals.amount}
-            <th class="contriTotalLeft">{ts}Total Soft Credits{/ts} &ndash; {$softCreditTotals.amount|crmMoney:$softCreditTotals.currency}</th>
-            <th class="right" width="10px"> &nbsp; </th>
-            <th class="right contriTotalRight"> &nbsp; {ts}Avg Soft Credits{/ts} &ndash; {$softCreditTotals.avg|crmMoney:$softCreditTotals.currency}</th>
-          {/if}
-          {if $softCreditTotals.cancelAmount}
-            <th class="right contriTotalRight"> &nbsp; {ts}Total Cancelled Soft Credits{/ts} &ndash; {$softCreditTotals.cancelAmount|crmMoney:$softCreditTotals.currency}</th>
-          {/if}
-        </tr>
+        {include file="CRM/Contribute/Page/ContributionSoftTotals.tpl"}
     </table>
     <p></p>
 {/if}
diff --git a/templates/CRM/Contribute/Page/ContributionSoftTotals.tpl b/templates/CRM/Contribute/Page/ContributionSoftTotals.tpl
new file mode 100644 (file)
index 0000000..73a7460
--- /dev/null
@@ -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 *}
+
+<tr>
+  {if $softCreditTotals.amount}
+    <th class="contriTotalLeft right">{ts}Total Soft Credit Amount{/ts} &ndash; {$softCreditTotals.amount}</th>
+    <th class="right"> &nbsp; {ts}# Completed Soft Credits{/ts} &ndash; {$softCreditTotals.count}</th>
+    <th class="right contriTotalRight"> &nbsp; {ts}Avg Soft Credit Amount{/ts} &ndash; {$softCreditTotals.avg}</th>
+  {/if}
+  {if $softCreditTotals.cancel.amount}
+    <th class="disabled right contriTotalRight"> &nbsp; {ts}Cancelled/Refunded{/ts} &ndash; {$softCreditTotals.cancel.amount}</th>
+  {/if}
+</tr>
index e995ee4e0f058c6074e69ddfc2ec2fdba2016033..d5735b74f0951dc40fc6342bed3594b20643ee32 100644 (file)
           {/if}
       </tr>
       {if $contributionSummary.soft_credit.count}
-      <tr>
-        <th class="contriTotalLeft right">{ts}Total Soft Credit Amount{/ts} &ndash; {$contributionSummary.soft_credit.amount}</th>
-        <th class="right"> &nbsp; {ts}# Completed Soft Credits{/ts} &ndash; {$contributionSummary.soft_credit.count}</th>
-        <th class="right contriTotalRight"> &nbsp; {ts}Avg Soft Credit Amount{/ts} &ndash; {$contributionSummary.soft_credit.avg}</th>
-      </tr>
+        {include file="CRM/Contribute/Page/ContributionSoftTotals.tpl" softCreditTotals=$contributionSummary.soft_credit}
       {/if}
     {/if}