CRM-14106 - Regex targeting inline conditonal statements
[civicrm-core.git] / CRM / Report / Form / Contribute / Summary.php
index 7d01d875d9f47a75879b122c9690a208ef2beaca..d15b69fae78b597c0785891209f09529dd3a89fd 100644 (file)
@@ -231,6 +231,13 @@ class CRM_Report_Form_Contribute_Summary extends CRM_Report_Form {
           '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,
@@ -508,11 +515,23 @@ class CRM_Report_Form_Contribute_Summary extends CRM_Report_Form {
     }
   }
 
+  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
 COUNT({$this->_aliases['civicrm_contribution']}.total_amount )        as civicrm_contribution_total_amount_count,
@@ -590,8 +609,8 @@ ROUND(AVG({$this->_aliases['civicrm_contribution_soft']}.amount), 2) as civicrm_
     if (CRM_Utils_Array::value('charts', $this->_params)) {
       if (CRM_Utils_Array::value('receive_date', $this->_params['group_bys'])) {
 
-        $contrib = CRM_Utils_Array::value('total_amount', $this->_params['fields']) ? TRUE : FALSE;
-        $softContrib = CRM_Utils_Array::value('soft_amount', $this->_params['fields']) ? TRUE : FALSE;
+        $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']) {