From: Dave Greenberg Date: Mon, 21 Oct 2013 23:00:09 +0000 (-0700) Subject: Incorporate query fix for contribution detail reports to filter by Batch + fixing... X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=acb4ca2f7a338e9c00be72c89766977081862030;p=civicrm-core.git Incorporate query fix for contribution detail reports to filter by Batch + fixing the getBatches BAO to remove unneeded filtering on batch type and batch status. Now we only exclude batches that are still in Data Entry status. --- diff --git a/CRM/Batch/BAO/Batch.php b/CRM/Batch/BAO/Batch.php index c7ea9fd99f..f085826c6b 100644 --- a/CRM/Batch/BAO/Batch.php +++ b/CRM/Batch/BAO/Batch.php @@ -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); diff --git a/CRM/Report/Form/Contribute/Detail.php b/CRM/Report/Form/Contribute/Detail.php index b4c7cd1a46..b3c68d9e00 100644 --- a/CRM/Report/Form/Contribute/Detail.php +++ b/CRM/Report/Form/Contribute/Detail.php @@ -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"; } diff --git a/CRM/Report/Form/Member/ContributionDetail.php b/CRM/Report/Form/Member/ContributionDetail.php index ac0482e0ec..442c6f856c 100644 --- a/CRM/Report/Form/Member/ContributionDetail.php +++ b/CRM/Report/Form/Member/ContributionDetail.php @@ -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"; }