<?php
/*
+--------------------------------------------------------------------+
- | CiviCRM version 4.3 |
+ | CiviCRM version 4.4 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2013 |
+--------------------------------------------------------------------+
'no_display' => TRUE,
'required' => TRUE,
),
+ 'contact_type' =>
+ array(
+ 'title' => ts('Contact Type'),
+ ),
+ 'contact_sub_type' =>
+ array(
+ 'title' => ts('Contact SubType'),
+ ),
),
'grouping' => 'contact-fields',
'group_bys' =>
'options' => CRM_Contribute_PseudoConstant::financialType(),
'type' => CRM_Utils_Type::T_INT,
),
+ 'contribution_page_id' =>
+ array('title' => ts('Contribution Page'),
+ 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
+ 'options' => CRM_Contribute_PseudoConstant::contributionPage(),
+ 'type' => CRM_Utils_Type::T_INT,
+ ),
'total_amount' =>
array('title' => ts('Contribution Amount'),
),
'amount' =>
array('title' => ts('Soft Credit Amount'),
),
+ 'soft_credit_type_id' =>
+ array('title' => 'Soft Credit Type',
+ 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
+ 'options' => CRM_Core_OptionGroup::values('soft_credit_type'),
+ 'default' => NULL,
+ 'type' => CRM_Utils_Type::T_STRING,
+ ),
'soft_sum' =>
array('title' => ts('Soft Credit Aggregate'),
'type' => CRM_Report_Form::OP_INT,
function from() {
$softCreditJoin = "LEFT";
- if (CRM_Utils_Array::value('soft_amount', $this->_params['fields']) &&
+ if (CRM_Utils_Array::value('soft_amount', $this->_params['fields']) &&
!CRM_Utils_Array::value('total_amount', $this->_params['fields'])) {
// if its only soft credit stats, use inner join
$softCreditJoin = "INNER";
}
}
+ function storeWhereHavingClauseArray(){
+ parent::storeWhereHavingClauseArray();
+ if (!CRM_Utils_Array::value('soft_amount', $this->_params['fields']) && !empty($this->_havingClauses)){
+ foreach ($this->_havingClauses as $key => $havingClause) {
+ if (stristr($havingClause, 'soft_soft')){
+ unset($this->_havingClauses[$key]);
+ }
+ }
+ }
+ }
+
function statistics(&$rows) {
$statistics = parent::statistics($rows);
$softCredit = CRM_Utils_Array::value('soft_amount', $this->_params['fields']);
$onlySoftCredit = $softCredit && !CRM_Utils_Array::value('total_amount', $this->_params['fields']);
+ $totalAmount = $average = $softTotalAmount = $softAverage = array();
- $select = "SELECT
+ $select = "SELECT
COUNT({$this->_aliases['civicrm_contribution']}.total_amount ) as civicrm_contribution_total_amount_count,
SUM({$this->_aliases['civicrm_contribution']}.total_amount ) as civicrm_contribution_total_amount_sum,
ROUND(AVG({$this->_aliases['civicrm_contribution']}.total_amount), 2) as civicrm_contribution_total_amount_avg,
{$this->_aliases['civicrm_contribution']}.currency as currency";
if ($softCredit) {
- $select .= ",
+ $select .= ",
COUNT({$this->_aliases['civicrm_contribution_soft']}.amount ) as civicrm_contribution_soft_soft_amount_count,
SUM({$this->_aliases['civicrm_contribution_soft']}.amount ) as civicrm_contribution_soft_soft_amount_sum,
ROUND(AVG({$this->_aliases['civicrm_contribution_soft']}.amount), 2) as civicrm_contribution_soft_soft_amount_avg";
}
$group = "\nGROUP BY {$this->_aliases['civicrm_contribution']}.currency";
$sql = "{$select} {$this->_from} {$this->_where} {$group} {$this->_having}";
-
+
$dao = CRM_Core_DAO::executeQuery($sql);
$totalAmount = $average = $softTotalAmount = $softAverage = array();
$count = $softCount = 0;
while ($dao->fetch()) {
- $totalAmount[] = CRM_Utils_Money::format($dao->civicrm_contribution_total_amount_sum, $dao->currency)."(".$dao->civicrm_contribution_total_amount_count.")";
+ $totalAmount[] = CRM_Utils_Money::format($dao->civicrm_contribution_total_amount_sum, $dao->currency)." (".$dao->civicrm_contribution_total_amount_count.")";
$average[] = CRM_Utils_Money::format($dao->civicrm_contribution_total_amount_avg, $dao->currency);
$count += $dao->civicrm_contribution_total_amount_count;
-
+
if ($softCredit) {
- $softTotalAmount[] = CRM_Utils_Money::format($dao->civicrm_contribution_soft_soft_amount_sum, $dao->currency)."(".$dao->civicrm_contribution_soft_soft_amount_count.")";
+ $softTotalAmount[] = CRM_Utils_Money::format($dao->civicrm_contribution_soft_soft_amount_sum, $dao->currency)." (".$dao->civicrm_contribution_soft_soft_amount_count.")";
$softAverage[] = CRM_Utils_Money::format($dao->civicrm_contribution_soft_soft_amount_avg, $dao->currency);
$softCount += $dao->civicrm_contribution_soft_soft_amount_count;
}
}
-
+
if (!$onlySoftCredit) {
$statistics['counts']['amount'] = array(
'title' => ts('Total Amount'),
function buildChart(&$rows) {
$graphRows = array();
- $count = 0;
if (CRM_Utils_Array::value('charts', $this->_params)) {
- foreach ($rows as $key => $row) {
- if ($row['civicrm_contribution_receive_date_subtotal']) {
- $graphRows['receive_date'][] = $row['civicrm_contribution_receive_date_start'];
- $graphRows[$this->_interval][] = $row['civicrm_contribution_receive_date_interval'];
- $graphRows['value'][] = $row['civicrm_contribution_total_amount_sum'];
- $count++;
+ if (CRM_Utils_Array::value('receive_date', $this->_params['group_bys'])) {
+
+ $contrib = !empty($this->_params['fields']['total_amount']) ? TRUE : FALSE;
+ $softContrib = !empty($this->_params['fields']['soft_amount']) ? TRUE : FALSE;
+
+ foreach ($rows as $key => $row) {
+ if ($row['civicrm_contribution_receive_date_subtotal']) {
+ $graphRows['receive_date'][] = $row['civicrm_contribution_receive_date_start'];
+ $graphRows[$this->_interval][] = $row['civicrm_contribution_receive_date_interval'];
+ if ($softContrib && $contrib) {
+ // both contri & soft contri stats are present
+ $graphRows['multiValue'][0][] = $row['civicrm_contribution_total_amount_sum'];
+ $graphRows['multiValue'][1][] = $row['civicrm_contribution_soft_soft_amount_sum'];
+ } else if ($softContrib) {
+ // only soft contributions
+ $graphRows['multiValue'][0][] = $row['civicrm_contribution_soft_soft_amount_sum'];
+ } else {
+ // only contributions
+ $graphRows['multiValue'][0][] = $row['civicrm_contribution_total_amount_sum'];
+ }
+ }
}
- }
- if (CRM_Utils_Array::value('receive_date', $this->_params['group_bys'])) {
+ if ($softContrib && $contrib) {
+ $graphRows['barKeys'][0] = ts('Contributions');
+ $graphRows['barKeys'][1] = ts('Soft Credits');
+ $graphRows['legend'] = ts('Contributions and Soft Credits');
+ } else if ($softContrib) {
+ $graphRows['legend'] = ts('Soft Credits');
+ }
// build the chart.
$config = CRM_Core_Config::Singleton();