* @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'),
$cs = CRM_Core_DAO::executeQuery($query, $params);
$count = 0;
- $amount = $average = array();
+ $amount = $average = $cancelAmount = array();
while ($cs->fetch()) {
if ($cs->amount > 0) {
$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);
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);
<th class="contriTotalLeft">{ts}Total Soft Credits{/ts} - {$softCreditTotals.amount|crmMoney:$softCreditTotals.currency}</th>
<th class="right" width="10px"> </th>
<th class="right contriTotalRight"> {ts}Avg Soft Credits{/ts} - {$softCreditTotals.avg|crmMoney:$softCreditTotals.currency}</th>
+
+ {if $softCreditTotals.cancelAmount}
+ <th class="right contriTotalRight"> {ts}Total Cancelled Soft Credits{/ts} - {$softCreditTotals.cancelAmount|crmMoney:$softCreditTotals.currency}</th>
+ {/if}
+
</tr>
</table>
<p></p>