CRM-19325 - enable search for contributions that are not in any batch.
authorJohan Vervloet <johanv@johanv.org>
Thu, 8 Sep 2016 10:24:45 +0000 (12:24 +0200)
committerdeb.monish <monish.deb@webaccessglobal.com>
Thu, 8 Dec 2016 12:10:31 +0000 (17:40 +0530)
CRM/Contact/BAO/Query.php
CRM/Contribute/BAO/Query.php
CRM/Contribute/Form/Search.php

index 2f76936e54916ebf629710cd4deca2c4cd4c50fa..d605ca5bb8d95b2be35a009ce2b0b07098224fd5 100644 (file)
@@ -1744,6 +1744,12 @@ class CRM_Contact_BAO_Query {
     ) {
       $result = array($id, 'IN', $values, 0, $wildcard);
     }
+    // Hack for CRM-19325. This is ugly because it creates a dependency
+    // to the form, that returns the string 'NULL' if the user wants
+    // contributions that are not contained in any batch.
+    else if ($id == 'contribution_batch_id' && $values == 'NULL') {
+      $result = array($id, 'IS', 'NULL', 0, 0);
+    }
     else {
       $result = array($id, '=', $values, 0, $wildcard);
     }
index 85f1f32cdbb1ed0fe915b6b20a38e70166b2874b..d8c601f4df9b308822661c9b2b202aea222d2d0b 100644 (file)
@@ -568,6 +568,9 @@ class CRM_Contribute_BAO_Query extends CRM_Core_BAO_Query {
 
       case 'contribution_batch_id':
         $batches = CRM_Contribute_PseudoConstant::batch();
+        // The key 'NULL' indicates that the user is looking for contributions
+        // that are not contained in a batch, see CRM-19325.
+        $batches['NULL'] = ts('(none)');
         $query->_where[$grouping][] = " civicrm_entity_batch.batch_id $op $value";
         $query->_qill[$grouping][] = ts('Batch Name %1 %2', array(1 => $op, 2 => $batches[$value]));
         $query->_tables['civicrm_contribution'] = $query->_whereTables['civicrm_contribution'] = 1;
@@ -1123,7 +1126,11 @@ class CRM_Contribute_BAO_Query extends CRM_Core_BAO_Query {
     if (!empty($batches)) {
       $form->add('select', 'contribution_batch_id',
         ts('Batch Name'),
-        array('' => ts('- any -')) + $batches,
+        array(
+          '' => ts('- any -'),
+          // CRM-19325
+          'NULL' => ts('None'),
+        ) + $batches,
         FALSE, array('class' => 'crm-select2')
       );
     }
index a2b8b89861cb0d3ba79e2fa92b8f07768274af47..016ef856ff52bfbbee9a185703baf44cfc9d6e96 100644 (file)
@@ -337,6 +337,7 @@ class CRM_Contribute_Form_Search extends CRM_Core_Form_Search {
       );
     }
 
+    // Why is this called twice? (see line 317)
     $this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues);
     $selector = new CRM_Contribute_Selector_Search($this->_queryParams,
       $this->_action,