3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2015
33 class CRM_Report_Form_Contribute_Summary
extends CRM_Report_Form
{
34 protected $_addressField = FALSE;
36 protected $_charts = array(
38 'barChart' => 'Bar Chart',
39 'pieChart' => 'Pie Chart',
41 protected $_customGroupExtends = array('Contribution');
42 protected $_customGroupGroupBy = TRUE;
44 public $_drilldownReport = array('contribute/detail' => 'Link to Detail Report');
49 public function __construct() {
51 // Check if CiviCampaign is a) enabled and b) has active campaigns
52 $config = CRM_Core_Config
::singleton();
53 $campaignEnabled = in_array("CiviCampaign", $config->enableComponents
);
54 if ($campaignEnabled) {
55 $getCampaigns = CRM_Campaign_BAO_Campaign
::getPermissionedCampaigns(NULL, NULL, TRUE, FALSE, TRUE);
56 $this->activeCampaigns
= $getCampaigns['campaigns'];
57 asort($this->activeCampaigns
);
60 $this->_columns
= array(
61 'civicrm_contact' => array(
62 'dao' => 'CRM_Contact_DAO_Contact',
63 'fields' => array_merge(
64 $this->getBasicContactFields(),
67 'title' => ts('Contact Name'),
72 'grouping' => 'contact-fields',
74 'id' => array('title' => ts('Contact ID')),
76 'title' => ts('Contact Name'),
80 'civicrm_email' => array(
81 'dao' => 'CRM_Core_DAO_Email',
84 'title' => ts('Email'),
88 'grouping' => 'contact-fields',
90 'civicrm_phone' => array(
91 'dao' => 'CRM_Core_DAO_Phone',
94 'title' => ts('Phone'),
98 'grouping' => 'contact-fields',
100 'civicrm_financial_type' => array(
101 'dao' => 'CRM_Financial_DAO_FinancialType',
102 'fields' => array('financial_type' => NULL),
103 'grouping' => 'contri-fields',
104 'group_bys' => array(
105 'financial_type' => array('title' => ts('Financial Type')),
108 'civicrm_contribution' => array(
109 'dao' => 'CRM_Contribute_DAO_Contribution',
110 //'bao' => 'CRM_Contribute_BAO_Contribution',
112 'contribution_status_id' => array(
113 'title' => ts('Contribution Status'),
115 'contribution_source' => array('title' => ts('Source')),
118 'no_display' => TRUE,
120 'total_amount' => array(
121 'title' => ts('Contribution Amount Stats'),
123 'statistics' => array(
124 'count' => ts('Contributions'),
125 'sum' => ts('Contribution Aggregate'),
126 'avg' => ts('Contribution Avg'),
130 'grouping' => 'contri-fields',
132 'receive_date' => array('operatorType' => CRM_Report_Form
::OP_DATE
),
133 'contribution_status_id' => array(
134 'title' => ts('Contribution Status'),
135 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
136 'options' => CRM_Contribute_PseudoConstant
::contributionStatus(),
137 'default' => array(1),
138 'type' => CRM_Utils_Type
::T_INT
,
141 'title' => 'Currency',
142 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
143 'options' => CRM_Core_OptionGroup
::values('currencies_enabled'),
145 'type' => CRM_Utils_Type
::T_STRING
,
147 'financial_type_id' => array(
148 'title' => ts('Financial Type'),
149 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
150 'options' => CRM_Contribute_PseudoConstant
::financialType(),
151 'type' => CRM_Utils_Type
::T_INT
,
153 'contribution_page_id' => array(
154 'title' => ts('Contribution Page'),
155 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
156 'options' => CRM_Contribute_PseudoConstant
::contributionPage(),
157 'type' => CRM_Utils_Type
::T_INT
,
159 'total_amount' => array(
160 'title' => ts('Contribution Amount'),
162 'total_sum' => array(
163 'title' => ts('Contribution Aggregate'),
164 'type' => CRM_Report_Form
::OP_INT
,
165 'dbAlias' => 'civicrm_contribution_total_amount_sum',
168 'total_count' => array(
169 'title' => ts('Contribution Count'),
170 'type' => CRM_Report_Form
::OP_INT
,
171 'dbAlias' => 'civicrm_contribution_total_amount_count',
174 'total_avg' => array(
175 'title' => ts('Contribution Avg'),
176 'type' => CRM_Report_Form
::OP_INT
,
177 'dbAlias' => 'civicrm_contribution_total_amount_avg',
181 'group_bys' => array(
182 'receive_date' => array(
187 'contribution_source' => NULL,
188 'contribution_status_id' => array(
189 'title' => ts('Contribution Status'),
190 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
191 'options' => CRM_Contribute_PseudoConstant
::contributionStatus(),
192 'default' => array(1),
193 'type' => CRM_Utils_Type
::T_INT
,
197 'civicrm_contribution_soft' => array(
198 'dao' => 'CRM_Contribute_DAO_ContributionSoft',
200 'soft_amount' => array(
201 'title' => ts('Soft Credit Amount Stats'),
203 'statistics' => array(
204 'count' => ts('Soft Credits'),
205 'sum' => ts('Soft Credit Aggregate'),
206 'avg' => ts('Soft Credit Avg'),
210 'grouping' => 'contri-fields',
213 'title' => ts('Soft Credit Amount'),
215 'soft_credit_type_id' => array(
216 'title' => 'Soft Credit Type',
217 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
218 'options' => CRM_Core_OptionGroup
::values('soft_credit_type'),
220 'type' => CRM_Utils_Type
::T_STRING
,
223 'title' => ts('Soft Credit Aggregate'),
224 'type' => CRM_Report_Form
::OP_INT
,
225 'dbAlias' => 'civicrm_contribution_soft_soft_amount_sum',
228 'soft_count' => array(
229 'title' => ts('Soft Credits Count'),
230 'type' => CRM_Report_Form
::OP_INT
,
231 'dbAlias' => 'civicrm_contribution_soft_soft_amount_count',
235 'title' => ts('Soft Credit Avg'),
236 'type' => CRM_Report_Form
::OP_INT
,
237 'dbAlias' => 'civicrm_contribution_soft_soft_amount_avg',
242 ) +
$this->addAddressFields();
244 // If we have a campaign, build out the relevant elements
245 if ($campaignEnabled && !empty($this->activeCampaigns
)) {
246 $this->_columns
['civicrm_contribution']['fields']['campaign_id'] = array(
247 'title' => 'Campaign',
248 'default' => 'false',
250 $this->_columns
['civicrm_contribution']['filters']['campaign_id'] = array(
251 'title' => ts('Campaign'),
252 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
253 'options' => $this->activeCampaigns
,
255 $this->_columns
['civicrm_contribution']['group_bys']['campaign_id'] = array('title' => ts('Campaign'));
258 $this->_tagFilter
= TRUE;
259 $this->_groupFilter
= TRUE;
260 $this->_currencyColumn
= 'civicrm_contribution_currency';
261 parent
::__construct();
267 public function select() {
269 $this->_columnHeaders
= array();
270 foreach ($this->_columns
as $tableName => $table) {
271 if (array_key_exists('group_bys', $table)) {
272 foreach ($table['group_bys'] as $fieldName => $field) {
273 if ($tableName == 'civicrm_address') {
274 $this->_addressField
= TRUE;
276 if (!empty($this->_params
['group_bys'][$fieldName])) {
277 switch (CRM_Utils_Array
::value($fieldName, $this->_params
['group_bys_freq'])) {
279 $select[] = "DATE_SUB({$field['dbAlias']}, INTERVAL WEEKDAY({$field['dbAlias']}) DAY) AS {$tableName}_{$fieldName}_start";
280 $select[] = "YEARWEEK({$field['dbAlias']}) AS {$tableName}_{$fieldName}_subtotal";
281 $select[] = "WEEKOFYEAR({$field['dbAlias']}) AS {$tableName}_{$fieldName}_interval";
282 $field['title'] = 'Week';
286 $select[] = "MAKEDATE(YEAR({$field['dbAlias']}), 1) AS {$tableName}_{$fieldName}_start";
287 $select[] = "YEAR({$field['dbAlias']}) AS {$tableName}_{$fieldName}_subtotal";
288 $select[] = "YEAR({$field['dbAlias']}) AS {$tableName}_{$fieldName}_interval";
289 $field['title'] = 'Year';
293 $select[] = "DATE_SUB({$field['dbAlias']}, INTERVAL (DAYOFMONTH({$field['dbAlias']})-1) DAY) as {$tableName}_{$fieldName}_start";
294 $select[] = "MONTH({$field['dbAlias']}) AS {$tableName}_{$fieldName}_subtotal";
295 $select[] = "MONTHNAME({$field['dbAlias']}) AS {$tableName}_{$fieldName}_interval";
296 $field['title'] = 'Month';
300 $select[] = "STR_TO_DATE(CONCAT( 3 * QUARTER( {$field['dbAlias']} ) -2 , '/', '1', '/', YEAR( {$field['dbAlias']} ) ), '%m/%d/%Y') AS {$tableName}_{$fieldName}_start";
301 $select[] = "QUARTER({$field['dbAlias']}) AS {$tableName}_{$fieldName}_subtotal";
302 $select[] = "QUARTER({$field['dbAlias']}) AS {$tableName}_{$fieldName}_interval";
303 $field['title'] = 'Quarter';
306 if (!empty($this->_params
['group_bys_freq'][$fieldName])) {
307 $this->_interval
= $field['title'];
308 $this->_columnHeaders
["{$tableName}_{$fieldName}_start"]['title'] = $field['title'] . ' Beginning';
309 $this->_columnHeaders
["{$tableName}_{$fieldName}_start"]['type'] = $field['type'];
310 $this->_columnHeaders
["{$tableName}_{$fieldName}_start"]['group_by'] = $this->_params
['group_bys_freq'][$fieldName];
312 // just to make sure these values are transfered to rows.
313 // since we need that for calculation purpose,
314 // e.g making subtotals look nicer or graphs
315 $this->_columnHeaders
["{$tableName}_{$fieldName}_interval"] = array('no_display' => TRUE);
316 $this->_columnHeaders
["{$tableName}_{$fieldName}_subtotal"] = array('no_display' => TRUE);
322 if (array_key_exists('fields', $table)) {
323 foreach ($table['fields'] as $fieldName => $field) {
324 if ($tableName == 'civicrm_address') {
325 $this->_addressField
= TRUE;
327 if (!empty($field['required']) ||
328 !empty($this->_params
['fields'][$fieldName])
330 // only include statistics columns if set
331 if (!empty($field['statistics'])) {
332 foreach ($field['statistics'] as $stat => $label) {
333 $this->_columnHeaders
["{$tableName}_{$fieldName}_{$stat}"]['title'] = $label;
334 $this->_columnHeaders
["{$tableName}_{$fieldName}_{$stat}"]['type'] = $field['type'];
335 $this->_statFields
[] = "{$tableName}_{$fieldName}_{$stat}";
336 switch (strtolower($stat)) {
338 $select[] = "SUM({$field['dbAlias']}) as {$tableName}_{$fieldName}_{$stat}";
342 $select[] = "COUNT({$field['dbAlias']}) as {$tableName}_{$fieldName}_{$stat}";
343 $this->_columnHeaders
["{$tableName}_{$fieldName}_{$stat}"]['type'] = CRM_Utils_Type
::T_INT
;
347 $select[] = "ROUND(AVG({$field['dbAlias']}),2) as {$tableName}_{$fieldName}_{$stat}";
353 $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}";
354 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array
::value('type', $field);
355 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['title'] = CRM_Utils_Array
::value('title', $field);
362 $this->_select
= "SELECT " . implode(', ', $select) . " ";
368 * @param array $fields
369 * @param array $files
370 * @param CRM_Report_Form_Contribute_Summary $self
374 public static function formRule($fields, $files, $self) {
375 // Check for searching combination of display columns and
377 $ignoreFields = array('total_amount', 'sort_name');
378 $errors = $self->customDataFormRule($fields, $ignoreFields);
380 if (empty($fields['fields']['total_amount'])) {
386 if (!empty($fields[$val])) {
387 $errors[$val] = ts("Please select the Amount Statistics");
398 * @param string $entity
400 public function from($entity = NULL) {
401 $softCreditJoinType = "LEFT";
402 if (!empty($this->_params
['fields']['soft_amount']) &&
403 empty($this->_params
['fields']['total_amount'])
405 // if its only soft credit stats, use inner join
406 $softCreditJoinType = "INNER";
409 $softCreditJoin = "{$softCreditJoinType} JOIN civicrm_contribution_soft {$this->_aliases['civicrm_contribution_soft']}
410 ON {$this->_aliases['civicrm_contribution_soft']}.contribution_id = {$this->_aliases['civicrm_contribution']}.id";
411 if ($entity == 'contribution' ||
empty($this->_params
['fields']['soft_amount'])) {
412 $softCreditJoin .= " AND {$this->_aliases['civicrm_contribution_soft']}.id = (SELECT MIN(id) FROM civicrm_contribution_soft cs WHERE cs.contribution_id = {$this->_aliases['civicrm_contribution']}.id) ";
416 FROM civicrm_contact {$this->_aliases['civicrm_contact']} {$this->_aclFrom}
417 INNER JOIN civicrm_contribution {$this->_aliases['civicrm_contribution']}
418 ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_contribution']}.contact_id AND
419 {$this->_aliases['civicrm_contribution']}.is_test = 0
421 LEFT JOIN civicrm_financial_type {$this->_aliases['civicrm_financial_type']}
422 ON {$this->_aliases['civicrm_contribution']}.financial_type_id ={$this->_aliases['civicrm_financial_type']}.id
423 LEFT JOIN civicrm_email {$this->_aliases['civicrm_email']}
424 ON ({$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_email']}.contact_id AND
425 {$this->_aliases['civicrm_email']}.is_primary = 1)
427 LEFT JOIN civicrm_phone {$this->_aliases['civicrm_phone']}
428 ON ({$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_phone']}.contact_id AND
429 {$this->_aliases['civicrm_phone']}.is_primary = 1)";
431 if ($this->_addressField
) {
433 LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']}
434 ON {$this->_aliases['civicrm_contact']}.id =
435 {$this->_aliases['civicrm_address']}.contact_id AND
436 {$this->_aliases['civicrm_address']}.is_primary = 1\n";
441 * Set group by clause.
443 public function groupBy() {
444 $this->_groupBy
= "";
446 if (!empty($this->_params
['group_bys']) &&
447 is_array($this->_params
['group_bys'])
449 foreach ($this->_columns
as $tableName => $table) {
450 if (array_key_exists('group_bys', $table)) {
451 foreach ($table['group_bys'] as $fieldName => $field) {
452 if (!empty($this->_params
['group_bys'][$fieldName])) {
453 if (!empty($field['chart'])) {
454 $this->assign('chartSupported', TRUE);
457 if (!empty($table['group_bys'][$fieldName]['frequency']) &&
458 !empty($this->_params
['group_bys_freq'][$fieldName])
461 $append = "YEAR({$field['dbAlias']}),";
462 if (in_array(strtolower($this->_params
['group_bys_freq'][$fieldName]),
467 $this->_groupBy
[] = "$append {$this->_params['group_bys_freq'][$fieldName]}({$field['dbAlias']})";
471 $this->_groupBy
[] = $field['dbAlias'];
478 if (!empty($this->_statFields
) &&
479 (($append && count($this->_groupBy
) <= 1) ||
(!$append)) &&
482 $this->_rollup
= " WITH ROLLUP";
484 $this->_groupBy
= "GROUP BY " . implode(', ', $this->_groupBy
) .
485 " {$this->_rollup} ";
488 $this->_groupBy
= "GROUP BY {$this->_aliases['civicrm_contact']}.id";
493 * Store having clauses as an array.
495 public function storeWhereHavingClauseArray() {
496 parent
::storeWhereHavingClauseArray();
497 if (empty($this->_params
['fields']['soft_amount']) &&
498 !empty($this->_havingClauses
)
500 foreach ($this->_havingClauses
as $key => $havingClause) {
501 if (stristr($havingClause, 'soft_soft')) {
502 unset($this->_havingClauses
[$key]);
515 public function statistics(&$rows) {
516 $statistics = parent
::statistics($rows);
518 $softCredit = CRM_Utils_Array
::value('soft_amount', $this->_params
['fields']);
519 $onlySoftCredit = $softCredit && !CRM_Utils_Array
::value('total_amount', $this->_params
['fields']);
520 $group = "\nGROUP BY {$this->_aliases['civicrm_contribution']}.currency";
522 $this->from('contribution');
523 $this->customDataFrom();
525 COUNT({$this->_aliases['civicrm_contribution']}.total_amount ) as civicrm_contribution_total_amount_count,
526 SUM({$this->_aliases['civicrm_contribution']}.total_amount ) as civicrm_contribution_total_amount_sum,
527 ROUND(AVG({$this->_aliases['civicrm_contribution']}.total_amount), 2) as civicrm_contribution_total_amount_avg,
528 {$this->_aliases['civicrm_contribution']}.currency as currency
529 {$this->_from} {$this->_where} {$group} {$this->_having}";
534 COUNT({$this->_aliases['civicrm_contribution_soft']}.amount ) as civicrm_contribution_soft_soft_amount_count,
535 SUM({$this->_aliases['civicrm_contribution_soft']}.amount ) as civicrm_contribution_soft_soft_amount_sum,
536 ROUND(AVG({$this->_aliases['civicrm_contribution_soft']}.amount), 2) as civicrm_contribution_soft_soft_amount_avg,
537 {$this->_aliases['civicrm_contribution']}.currency as currency
538 {$this->_from} {$this->_where} {$group} {$this->_having}";
541 $contriDAO = CRM_Core_DAO
::executeQuery($contriSQL);
543 $totalAmount = $average = $softTotalAmount = $softAverage = array();
544 $count = $softCount = 0;
545 while ($contriDAO->fetch()) {
547 = CRM_Utils_Money
::format($contriDAO->civicrm_contribution_total_amount_sum
, $contriDAO->currency
) .
548 " (" . $contriDAO->civicrm_contribution_total_amount_count
. ")";
549 $average[] = CRM_Utils_Money
::format($contriDAO->civicrm_contribution_total_amount_avg
, $contriDAO->currency
);
550 $count +
= $contriDAO->civicrm_contribution_total_amount_count
;
554 $softDAO = CRM_Core_DAO
::executeQuery($softSQL);
555 while ($softDAO->fetch()) {
557 = CRM_Utils_Money
::format($softDAO->civicrm_contribution_soft_soft_amount_sum
, $softDAO->currency
) .
558 " (" . $softDAO->civicrm_contribution_soft_soft_amount_count
. ")";
559 $softAverage[] = CRM_Utils_Money
::format($softDAO->civicrm_contribution_soft_soft_amount_avg
, $softDAO->currency
);
560 $softCount +
= $softDAO->civicrm_contribution_soft_soft_amount_count
;
564 if (!$onlySoftCredit) {
565 $statistics['counts']['amount'] = array(
566 'title' => ts('Total Amount'),
567 'value' => implode(', ', $totalAmount),
568 'type' => CRM_Utils_Type
::T_STRING
,
570 $statistics['counts']['count'] = array(
571 'title' => ts('Total Contributions'),
574 $statistics['counts']['avg'] = array(
575 'title' => ts('Average'),
576 'value' => implode(', ', $average),
577 'type' => CRM_Utils_Type
::T_STRING
,
581 $statistics['counts']['soft_amount'] = array(
582 'title' => ts('Total Soft Credit Amount'),
583 'value' => implode(', ', $softTotalAmount),
584 'type' => CRM_Utils_Type
::T_STRING
,
586 $statistics['counts']['soft_count'] = array(
587 'title' => ts('Total Soft Credits'),
588 'value' => $softCount,
590 $statistics['counts']['soft_avg'] = array(
591 'title' => ts('Average Soft Credit'),
592 'value' => implode(', ', $softAverage),
593 'type' => CRM_Utils_Type
::T_STRING
,
600 * Post process function.
602 public function postProcess() {
603 $this->buildACLClause($this->_aliases
['civicrm_contact']);
604 parent
::postProcess();
608 * Build table rows for output.
613 public function buildRows($sql, &$rows) {
614 $dao = CRM_Core_DAO
::executeQuery($sql);
615 if (!is_array($rows)) {
619 // use this method to modify $this->_columnHeaders
620 $this->modifyColumnHeaders();
621 $contriRows = array();
622 $unselectedSectionColumns = $this->unselectedSectionColumns();
624 //CRM-16338 if both soft-credit and contribution are enabled then process the contribution's
625 //total amount's average, count and sum separately and add it to the respective result list
626 $softCredit = (!empty($this->_params
['fields']['soft_amount']) && !empty($this->_params
['fields']['total_amount'])) ?
TRUE : FALSE;
628 $this->from('contribution');
629 $contriSQL = "{$this->_select} {$this->_from} {$this->_where} {$this->_groupBy} {$this->_having} {$this->_orderBy} {$this->_limit}";
630 $contriDAO = CRM_Core_DAO
::executeQuery($contriSQL);
631 $contriFields = array(
632 'civicrm_contribution_total_amount_sum',
633 'civicrm_contribution_total_amount_avg',
634 'civicrm_contribution_total_amount_count');
635 $contriRows = array();
636 while ($contriDAO->fetch()) {
637 $contriRow = array();
638 foreach ($contriFields as $column) {
639 $contriRow[$column] = $contriDAO->$column;
641 $contriRows[] = $contriRow;
646 while ($dao->fetch()) {
648 foreach ($this->_columnHeaders
as $key => $value) {
649 if ($softCredit && array_key_exists($key, $contriRows[$count])) {
650 $row[$key] = $contriRows[$count][$key];
652 elseif (property_exists($dao, $key)) {
653 $row[$key] = $dao->$key;
657 // section headers not selected for display need to be added to row
658 foreach ($unselectedSectionColumns as $key => $values) {
659 if (property_exists($dao, $key)) {
660 $row[$key] = $dao->$key;
675 public function buildChart(&$rows) {
676 $graphRows = array();
678 if (!empty($this->_params
['charts'])) {
679 if (!empty($this->_params
['group_bys']['receive_date'])) {
681 $contrib = !empty($this->_params
['fields']['total_amount']) ?
TRUE : FALSE;
682 $softContrib = !empty($this->_params
['fields']['soft_amount']) ?
TRUE : FALSE;
684 foreach ($rows as $key => $row) {
685 if ($row['civicrm_contribution_receive_date_subtotal']) {
686 $graphRows['receive_date'][] = $row['civicrm_contribution_receive_date_start'];
687 $graphRows[$this->_interval
][] = $row['civicrm_contribution_receive_date_interval'];
688 if ($softContrib && $contrib) {
689 // both contri & soft contri stats are present
690 $graphRows['multiValue'][0][] = $row['civicrm_contribution_total_amount_sum'];
691 $graphRows['multiValue'][1][] = $row['civicrm_contribution_soft_soft_amount_sum'];
693 elseif ($softContrib) {
694 // only soft contributions
695 $graphRows['multiValue'][0][] = $row['civicrm_contribution_soft_soft_amount_sum'];
698 // only contributions
699 $graphRows['multiValue'][0][] = $row['civicrm_contribution_total_amount_sum'];
704 if ($softContrib && $contrib) {
705 $graphRows['barKeys'][0] = ts('Contributions');
706 $graphRows['barKeys'][1] = ts('Soft Credits');
707 $graphRows['legend'] = ts('Contributions and Soft Credits');
709 elseif ($softContrib) {
710 $graphRows['legend'] = ts('Soft Credits');
714 $config = CRM_Core_Config
::Singleton();
715 $graphRows['xname'] = $this->_interval
;
716 $graphRows['yname'] = "Amount ({$config->defaultCurrency})";
717 CRM_Utils_OpenFlashChart
::chart($graphRows, $this->_params
['charts'], $this->_interval
);
718 $this->assign('chartType', $this->_params
['charts']);
724 * Alter display of rows.
726 * Iterate through the rows retrieved via SQL and make changes for display purposes,
727 * such as rendering contacts as links.
730 * Rows generated by SQL, with an array for each row.
732 public function alterDisplay(&$rows) {
734 $contributionStatus = CRM_Contribute_PseudoConstant
::contributionStatus();
736 foreach ($rows as $rowNum => $row) {
737 // make count columns point to detail report
738 if (!empty($this->_params
['group_bys']['receive_date']) &&
739 !empty($row['civicrm_contribution_receive_date_start']) &&
740 CRM_Utils_Array
::value('civicrm_contribution_receive_date_start', $row) &&
741 !empty($row['civicrm_contribution_receive_date_subtotal'])
744 $dateStart = CRM_Utils_Date
::customFormat($row['civicrm_contribution_receive_date_start'], '%Y%m%d');
745 $endDate = new DateTime($dateStart);
748 list($dateEnd['Y'], $dateEnd['M'], $dateEnd['d']) = explode(':', $endDate->format('Y:m:d'));
750 switch (strtolower($this->_params
['group_bys_freq']['receive_date'])) {
752 $dateEnd = date("Ymd", mktime(0, 0, 0, $dateEnd['M'] +
1,
753 $dateEnd['d'] - 1, $dateEnd['Y']
758 $dateEnd = date("Ymd", mktime(0, 0, 0, $dateEnd['M'],
759 $dateEnd['d'] - 1, $dateEnd['Y'] +
1
764 $dateEnd = date("Ymd", mktime(0, 0, 0, $dateEnd['M'],
765 $dateEnd['d'] +
6, $dateEnd['Y']
770 $dateEnd = date("Ymd", mktime(0, 0, 0, $dateEnd['M'] +
3,
771 $dateEnd['d'] - 1, $dateEnd['Y']
775 $url = CRM_Report_Utils_Report
::getNextUrl('contribute/detail',
776 "reset=1&force=1&receive_date_from={$dateStart}&receive_date_to={$dateEnd}",
779 $this->_drilldownReport
781 $rows[$rowNum]['civicrm_contribution_receive_date_start_link'] = $url;
782 $rows[$rowNum]['civicrm_contribution_receive_date_start_hover'] = ts('List all contribution(s) for this date unit.');
786 // make subtotals look nicer
787 if (array_key_exists('civicrm_contribution_receive_date_subtotal', $row) &&
788 !$row['civicrm_contribution_receive_date_subtotal']
790 $this->fixSubTotalDisplay($rows[$rowNum], $this->_statFields
);
794 // convert display name to links
795 if (array_key_exists('civicrm_contact_sort_name', $row) &&
796 array_key_exists('civicrm_contact_id', $row)
798 $url = CRM_Report_Utils_Report
::getNextUrl('contribute/detail',
799 'reset=1&force=1&id_op=eq&id_value=' . $row['civicrm_contact_id'],
800 $this->_absoluteUrl
, $this->_id
, $this->_drilldownReport
802 $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url;
803 $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts("Lists detailed contribution(s) for this record.");
807 // convert contribution status id to status name
808 if ($value = CRM_Utils_Array
::value('civicrm_contribution_contribution_status_id', $row)) {
809 $rows[$rowNum]['civicrm_contribution_contribution_status_id'] = $contributionStatus[$value];
813 // If using campaigns, convert campaign_id to campaign title
814 if (array_key_exists('civicrm_contribution_campaign_id', $row)) {
815 if ($value = $row['civicrm_contribution_campaign_id']) {
816 $rows[$rowNum]['civicrm_contribution_campaign_id'] = $this->activeCampaigns
[$value];
821 $entryFound = $this->alterDisplayAddressFields($row, $rows, $rowNum, 'contribute/detail', 'List all contribution(s) for this ') ?
TRUE : $entryFound;
822 $entryFound = $this->alterDisplayContactFields($row, $rows, $rowNum, 'contribute/detail', 'List all contribution(s) for this ') ?
TRUE : $entryFound;
824 // skip looking further in rows, if first row itself doesn't
825 // have the column we need