From 971cdafbbee5f754df95aef2e9e2492ec3964d78 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 4 Mar 2016 17:08:15 +0000 Subject: [PATCH] Display total cancelled soft credits in summary --- CRM/Contribute/BAO/ContributionSoft.php | 24 +++++++++++++++---- CRM/Contribute/Page/Tab.php | 3 ++- .../CRM/Contribute/Page/ContributionSoft.tpl | 5 ++++ 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/CRM/Contribute/BAO/ContributionSoft.php b/CRM/Contribute/BAO/ContributionSoft.php index aecf78541a..0d6e85ee5a 100644 --- a/CRM/Contribute/BAO/ContributionSoft.php +++ b/CRM/Contribute/BAO/ContributionSoft.php @@ -243,12 +243,15 @@ class CRM_Contribute_BAO_ContributionSoft extends CRM_Contribute_DAO_Contributio * @return array */ public static function getSoftContributionTotals($contact_id, $isTest = 0) { - $query = ' + + $whereClause = "AND cc.cancel_date IS NULL"; + + $query = " SELECT SUM(amount) as amount, AVG(total_amount) as average, cc.currency FROM civicrm_contribution_soft ccs LEFT JOIN civicrm_contribution cc ON ccs.contribution_id = cc.id - WHERE cc.is_test = %2 AND ccs.contact_id = %1 - GROUP BY currency'; + WHERE cc.is_test = %2 AND ccs.contact_id = %1 {$whereClause} + GROUP BY currency"; $params = array( 1 => array($contact_id, 'Integer'), @@ -258,7 +261,7 @@ class CRM_Contribute_BAO_ContributionSoft extends CRM_Contribute_DAO_Contributio $cs = CRM_Core_DAO::executeQuery($query, $params); $count = 0; - $amount = $average = array(); + $amount = $average = $cancelAmount = array(); while ($cs->fetch()) { if ($cs->amount > 0) { @@ -268,12 +271,23 @@ class CRM_Contribute_BAO_ContributionSoft extends CRM_Contribute_DAO_Contributio $currency[] = $cs->currency; } } - + + //to get cancel amount + $cancelAmountWhereClause = "AND cc.cancel_date IS NOT NULL"; + $query = str_replace($whereClause, $cancelAmountWhereClause, $query); + $cancelAmountSQL = CRM_Core_DAO::executeQuery($query, $params); + while ($cancelAmountSQL->fetch()) { + if ($cancelAmountSQL->amount > 0) { + $cancelAmount[] = $cancelAmountSQL->amount; + } + } + if ($count > 0) { return array( implode(', ', $amount), implode(', ', $average), implode(', ', $currency), + implode(', ', $cancelAmount), ); } return array(0, 0); diff --git a/CRM/Contribute/Page/Tab.php b/CRM/Contribute/Page/Tab.php index b284ed0118..e7ee1f2cfd 100644 --- a/CRM/Contribute/Page/Tab.php +++ b/CRM/Contribute/Page/Tab.php @@ -180,7 +180,8 @@ class CRM_Contribute_Page_Tab extends CRM_Core_Page { list($softCreditTotals['amount'], $softCreditTotals['avg'], - $softCreditTotals['currency'] + $softCreditTotals['currency'], + $softCreditTotals['cancelAmount'] //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 05af80f83d..3723de3d70 100644 --- a/templates/CRM/Contribute/Page/ContributionSoft.tpl +++ b/templates/CRM/Contribute/Page/ContributionSoft.tpl @@ -31,6 +31,11 @@ {ts}Total Soft Credits{/ts} - {$softCreditTotals.amount|crmMoney:$softCreditTotals.currency}     {ts}Avg Soft Credits{/ts} - {$softCreditTotals.avg|crmMoney:$softCreditTotals.currency} + + {if $softCreditTotals.cancelAmount} +   {ts}Total Cancelled Soft Credits{/ts} - {$softCreditTotals.cancelAmount|crmMoney:$softCreditTotals.currency} + {/if} +

-- 2.25.1