CRM-16189 IIDA-58 Added Batch Title to columns, grouping and filter
authorEdsel <edsel.lopez@jmaconsulting.biz>
Thu, 9 Feb 2017 13:12:15 +0000 (18:42 +0530)
committerEdsel <edsel.lopez@jmaconsulting.biz>
Wed, 15 Feb 2017 06:38:06 +0000 (12:08 +0530)
----------------------------------------
* CRM-16189: Improve support for Accrual Method bookkeeping
  https://issues.civicrm.org/jira/browse/CRM-16189

CRM-16189-44 Changes to filters, group bys

CRM-16189 IIDA-58 Prevented loading all batches for report

----------------------------------------
* CRM-16189: Improve support for Accrual Method bookkeeping
  https://issues.civicrm.org/jira/browse/CRM-16189

CRM/Report/Form/Contribute/Summary.php

index 684032ad1f72cd62c50be9ef47f840434e35b067..9b59afb436717bb07cc3295e7f8be4ef7b3e0ef0 100644 (file)
@@ -229,6 +229,12 @@ class CRM_Report_Form_Contribute_Summary extends CRM_Report_Form {
       'civicrm_batch' => array(
         'dao' => 'CRM_Batch_DAO_EntityBatch',
         'grouping' => 'contri-fields',
+        'fields' => array(
+          'batch_id' => array(
+            'name' => 'batch_id',
+            'title' => ts('Batch Title'),
+          ),
+        ),
         'filters' => array(
           'batch_id' => array(
             'title' => ts('Batch Title'),
@@ -237,6 +243,9 @@ class CRM_Report_Form_Contribute_Summary extends CRM_Report_Form {
             'type' => CRM_Utils_Type::T_INT,
           ),
         ),
+        'group_bys' => array(
+          'batch_id' => array('title' => ts('Batch ID')),
+        ),
       ),
       'civicrm_contribution_soft' => array(
         'dao' => 'CRM_Contribute_DAO_ContributionSoft',
@@ -495,14 +504,15 @@ class CRM_Report_Form_Contribute_Summary extends CRM_Report_Form {
                         {$this->_aliases['civicrm_phone']}.is_primary = 1)";
 
     $this->addAddressFromClause();
-    if (!empty($this->_params['batch_id_value'])) {
+    //for contribution batches
+    if ($this->isTableSelected('civicrm_batch')) {
       $this->_from .= "
-                 LEFT JOIN civicrm_entity_financial_trxn eft
-                        ON eft.entity_id = {$this->_aliases['civicrm_contribution']}.id AND
-                           eft.entity_table = 'civicrm_contribution'
-                 LEFT JOIN civicrm_entity_batch {$this->_aliases['civicrm_batch']}
-                        ON {$this->_aliases['civicrm_batch']}.entity_id = eft.financial_trxn_id AND
-                           {$this->_aliases['civicrm_batch']}.entity_table = 'civicrm_financial_trxn'\n";
+        LEFT JOIN civicrm_entity_financial_trxn eft
+          ON eft.entity_id = {$this->_aliases['civicrm_contribution']}.id AND
+            eft.entity_table = 'civicrm_contribution'
+        LEFT JOIN civicrm_entity_batch {$this->_aliases['civicrm_batch']}
+          ON ({$this->_aliases['civicrm_batch']}.entity_id = eft.financial_trxn_id
+          AND {$this->_aliases['civicrm_batch']}.entity_table = 'civicrm_financial_trxn')";
     }
   }
 
@@ -936,6 +946,12 @@ ROUND(AVG({$this->_aliases['civicrm_contribution_soft']}.amount), 2) as civicrm_
         $entryFound = TRUE;
       }
 
+      // convert batch id to batch title
+      if (!empty($row['civicrm_batch_batch_id'])) {
+        $rows[$rowNum]['civicrm_batch_batch_id'] = CRM_Core_DAO::getFieldValue('CRM_Batch_BAO_Batch', $row['civicrm_batch_batch_id'], 'title');
+        $entryFound = TRUE;
+      }
+
       $entryFound = $this->alterDisplayAddressFields($row, $rows, $rowNum, 'contribute/detail', 'List all contribution(s) for this ') ? TRUE : $entryFound;
       $entryFound = $this->alterDisplayContactFields($row, $rows, $rowNum, 'contribute/detail', 'List all contribution(s) for this ') ? TRUE : $entryFound;