Incorporate query fix for contribution detail reports to filter by Batch + fixing...
authorDave Greenberg <dave@civicrm.org>
Mon, 21 Oct 2013 23:00:09 +0000 (16:00 -0700)
committerDave Greenberg <dave@civicrm.org>
Mon, 21 Oct 2013 23:00:09 +0000 (16:00 -0700)
CRM/Batch/BAO/Batch.php
CRM/Report/Form/Contribute/Detail.php
CRM/Report/Form/Member/ContributionDetail.php

index c7ea9fd99fbc6ce61d3ed8bff25932dbeb986f4c..f085826c6b84eab25af7f97dfdb6e4d5f3b28951 100644 (file)
@@ -470,14 +470,16 @@ class CRM_Batch_BAO_Batch extends CRM_Batch_DAO_Batch {
   /**
    * function to get batch list
    *
-   * @return array array of batches
+   * @return array array of all batches
+   * excluding batches with data entry in progress (status_id = 3)
    */
   static function getBatches() {
-    $query = 'SELECT id, title
+    $dataEntryStatusId = CRM_Core_OptionGroup::getValue('batch_status','Data Entry');
+    $query = "SELECT id, title
       FROM civicrm_batch
-      WHERE type_id IN (1,2)
-      AND status_id = 2
-      ORDER BY id DESC';
+      WHERE item_count >= 1
+      AND status_id != {$dataEntryStatusId}
+      ORDER BY id DESC";
 
     $batches = array();
     $dao = CRM_Core_DAO::executeQuery($query);
index b4c7cd1a46dc46288be7c6a7295d24a816715e4f..b3c68d9e009a6c5e62028f28e8828ecd6af72b13 100644 (file)
@@ -41,6 +41,7 @@ class CRM_Report_Form_Contribute_Detail extends CRM_Report_Form {
   protected $_nameFieldHonor = FALSE;
 
   protected $_summary = NULL;
+  protected $_allBatches = NULL;
 
   protected $_customGroupExtends = array(
     'Contribution');
@@ -341,8 +342,8 @@ class CRM_Report_Form_Contribute_Detail extends CRM_Report_Form {
     $this->_tagFilter = TRUE;
 
     // Don't show Batch display column and filter unless batches are being used
-    $this->_closedBatches = CRM_Batch_BAO_Batch::getBatches();
-    if (!empty($this->_closedBatches)) {
+    $this->_allBatches = CRM_Batch_BAO_Batch::getBatches();
+    if (!empty($this->_allBatches)) {
       $this->_columns['civicrm_batch']['dao'] = 'CRM_Batch_DAO_Batch';
       $this->_columns['civicrm_batch']['fields']['batch_id'] = array(
         'name' => 'id',
@@ -353,7 +354,7 @@ class CRM_Report_Form_Contribute_Detail extends CRM_Report_Form {
         'title' => ts('Batch Name'),
         'type' => CRM_Utils_Type::T_INT,
         'operatorType' => CRM_Report_Form::OP_MULTISELECT,
-        'options' => $this->_closedBatches,
+        'options' => $this->_allBatches,
       );
       $this->_columns['civicrm_entity_batch']['dao'] = 'CRM_Batch_DAO_EntityBatch';
       $this->_columns['civicrm_entity_batch']['fields']['entity_batch_id'] = array(
@@ -485,11 +486,14 @@ class CRM_Report_Form_Contribute_Detail extends CRM_Report_Form {
                            {$this->_aliases['civicrm_contribution']}.id = {$this->_aliases['civicrm_note']}.entity_id )";
     }
     //for contribution batches
-    if ($this->_closedBatches && CRM_Utils_Array::value('batch_id', $this->_params['fields'])) {
+    if ($this->_allBatches &&
+      (CRM_Utils_Array::value('batch_id', $this->_params['fields']) || !empty($this->_params['bid_value']))) {
       $this->_from .= "
+                LEFT JOIN civicrm_entity_financial_trxn tx ON (tx.entity_id = {$this->_aliases['civicrm_contribution']}.id AND
+                   tx.entity_table = 'civicrm_contribution')
                  LEFT JOIN  civicrm_entity_batch {$this->_aliases['civicrm_entity_batch']}
-                        ON ({$this->_aliases['civicrm_entity_batch']}.entity_id = {$this->_aliases['civicrm_contribution']}.id AND
-                        {$this->_aliases['civicrm_entity_batch']}.entity_table = 'civicrm_contribution')
+                        ON ({$this->_aliases['civicrm_entity_batch']}.entity_id = tx.financial_trxn_id AND
+                        {$this->_aliases['civicrm_entity_batch']}.entity_table = 'civicrm_financial_trxn')
                  LEFT JOIN civicrm_batch {$this->_aliases['civicrm_batch']}
                         ON {$this->_aliases['civicrm_batch']}.id = {$this->_aliases['civicrm_entity_batch']}.batch_id";
     }
index ac0482e0ecf72548dafefb20a30629036f26cf3c..442c6f856c8a9b3b0767934a970d65f3608b8035 100644 (file)
@@ -42,6 +42,7 @@ class CRM_Report_Form_Member_ContributionDetail extends CRM_Report_Form {
   protected $_nameFieldHonor = FALSE;
 
   protected $_summary = NULL;
+  protected $_allBatches = NULL;
 
   protected $_customGroupExtends = array(
     'Contribution', 'Membership');
@@ -420,8 +421,8 @@ class CRM_Report_Form_Member_ContributionDetail extends CRM_Report_Form {
     $this->_tagFilter = TRUE;
 
     // Don't show Batch display column and filter unless batches are being used
-    $this->_closedBatches = CRM_Batch_BAO_Batch::getBatches();
-    if (!empty($this->_closedBatches)) {
+    $this->_allBatches = CRM_Batch_BAO_Batch::getBatches();
+    if (!empty($this->_allBatches)) {
       $this->_columns['civicrm_batch']['dao'] = 'CRM_Batch_DAO_Batch';
       $this->_columns['civicrm_batch']['fields']['batch_id'] = array(
         'name' => 'id',
@@ -432,7 +433,7 @@ class CRM_Report_Form_Member_ContributionDetail extends CRM_Report_Form {
         'title' => ts('Batch Name'),
         'type' => CRM_Utils_Type::T_INT,
         'operatorType' => CRM_Report_Form::OP_MULTISELECT,
-        'options' => $this->_closedBatches,
+        'options' => $this->_allBatches,
       );
       $this->_columns['civicrm_entity_batch']['dao'] = 'CRM_Batch_DAO_EntityBatch';
       $this->_columns['civicrm_entity_batch']['fields']['entity_batch_id'] = array(
@@ -575,12 +576,14 @@ class CRM_Report_Form_Member_ContributionDetail extends CRM_Report_Form {
                          {$this->_aliases['civicrm_phone']}.is_primary = 1)";
     }
     //for contribution batches
-    if ($this->_closedBatches &&
+    if ($this->_allBatches &&
       (CRM_Utils_Array::value('batch_id', $this->_params['fields']) || !empty($this->_params['bid_value']))) {
       $this->_from .= "
+                LEFT JOIN civicrm_entity_financial_trxn tx ON (tx.entity_id = {$this->_aliases['civicrm_contribution']}.id AND
+                   tx.entity_table = 'civicrm_contribution')
                  LEFT JOIN  civicrm_entity_batch {$this->_aliases['civicrm_entity_batch']}
-                        ON ({$this->_aliases['civicrm_entity_batch']}.entity_id = {$this->_aliases['civicrm_contribution']}.id AND
-                        {$this->_aliases['civicrm_entity_batch']}.entity_table = 'civicrm_contribution')
+                        ON ({$this->_aliases['civicrm_entity_batch']}.entity_id = tx.financial_trxn_id AND
+                        {$this->_aliases['civicrm_entity_batch']}.entity_table = 'civicrm_financial_trxn')
                  LEFT JOIN civicrm_batch {$this->_aliases['civicrm_batch']}
                         ON {$this->_aliases['civicrm_batch']}.id = {$this->_aliases['civicrm_entity_batch']}.batch_id";
     }