Skip to content

Commit

Permalink
Merge pull request #13711 from greenpeace-cee/fix-multi-currency-soft…
Browse files Browse the repository at this point in the history
…-credit

dev/core#756 - CRM/Contribute - Fix multi-currency soft credit summary
  • Loading branch information
eileenmcnaughton authored Feb 28, 2019
2 parents 9df02bf + d9c8c3c commit c2db3ab
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 26 deletions.
16 changes: 8 additions & 8 deletions CRM/Contribute/BAO/ContributionSoft.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand All @@ -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),
);
}
Expand Down
7 changes: 4 additions & 3 deletions CRM/Contribute/Page/Tab.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 1 addition & 10 deletions templates/CRM/Contribute/Page/ContributionSoft.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,7 @@
{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}
Expand Down
37 changes: 37 additions & 0 deletions templates/CRM/Contribute/Page/ContributionSoftTotals.tpl
Original file line number Diff line number Diff line change
@@ -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>
6 changes: 1 addition & 5 deletions templates/CRM/Contribute/Page/ContributionTotals.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,7 @@
{/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}

Expand Down

0 comments on commit c2db3ab

Please sign in to comment.