Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev/core#756 - CRM/Contribute - Fix multi-currency soft credit summary #13711

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
pfigel marked this conversation as resolved.
Show resolved Hide resolved
) = 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