X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FReport%2FForm%2FMember%2FContributionDetail.php;h=85f39a1ff500f351d44a81b285c286988b47d6e9;hb=d1641c514cc7490923db5111f24c7f98da6fa91e;hp=c2d2fe243f32ab142be68e529c4094eb1970ca09;hpb=ec9a1e0b013e3c7a99a099247eb138a362bc307e;p=civicrm-core.git diff --git a/CRM/Report/Form/Member/ContributionDetail.php b/CRM/Report/Form/Member/ContributionDetail.php index c2d2fe243f..85f39a1ff5 100644 --- a/CRM/Report/Form/Member/ContributionDetail.php +++ b/CRM/Report/Form/Member/ContributionDetail.php @@ -3,7 +3,7 @@ +--------------------------------------------------------------------+ | CiviCRM version 4.7 | +--------------------------------------------------------------------+ - | Copyright CiviCRM LLC (c) 2004-2015 | + | Copyright CiviCRM LLC (c) 2004-2016 | +--------------------------------------------------------------------+ | This file is a part of CiviCRM. | | | @@ -28,7 +28,7 @@ /** * * @package CRM - * @copyright CiviCRM LLC (c) 2004-2015 + * @copyright CiviCRM LLC (c) 2004-2016 * $Id$ * */ @@ -38,7 +38,6 @@ class CRM_Report_Form_Member_ContributionDetail extends CRM_Report_Form { protected $_emailField = FALSE; protected $_summary = NULL; - protected $_allBatches = NULL; protected $_customGroupExtends = array( 'Contribution', @@ -195,6 +194,7 @@ class CRM_Report_Form_Member_ContributionDetail extends CRM_Report_Form { 'receive_date' => array('operatorType' => CRM_Report_Form::OP_DATE), 'financial_type_id' => array( 'title' => ts('Financial Type'), + 'type' => CRM_Utils_Type::T_INT, 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Contribute_PseudoConstant::financialType(), ), @@ -207,6 +207,7 @@ class CRM_Report_Form_Member_ContributionDetail extends CRM_Report_Form { ), 'payment_instrument_id' => array( 'title' => ts('Payment Type'), + 'type' => CRM_Utils_Type::T_INT, 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Contribute_PseudoConstant::paymentInstrument(), ), @@ -229,6 +230,25 @@ class CRM_Report_Form_Member_ContributionDetail extends CRM_Report_Form { ), ), ), + 'civicrm_batch' => array( + 'dao' => 'CRM_Batch_DAO_EntityBatch', + 'grouping' => 'contri-fields', + 'fields' => array( + 'batch_id' => array( + 'name' => 'id', + 'title' => ts('Batch Name'), + ), + ), + 'filters' => array( + 'bid' => array( + 'title' => ts('Batch Name'), + 'operatorType' => CRM_Report_Form::OP_MULTISELECT, + 'options' => CRM_Batch_BAO_Batch::getBatches(), + 'type' => CRM_Utils_Type::T_INT, + 'dbAlias' => 'batch_civireport.batch_id', + ), + ), + ), 'civicrm_contribution_product' => array( 'dao' => 'CRM_Contribute_DAO_ContributionProduct', 'fields' => array( @@ -252,6 +272,7 @@ class CRM_Report_Form_Member_ContributionDetail extends CRM_Report_Form { 'filters' => array( 'ordinality' => array( 'title' => ts('Contribution Ordinality'), + 'type' => CRM_Utils_Type::T_INT, 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => array( 0 => 'First by Contributor', @@ -343,29 +364,6 @@ class CRM_Report_Form_Member_ContributionDetail extends CRM_Report_Form { $this->_groupFilter = TRUE; $this->_tagFilter = TRUE; - // Don't show Batch display column and filter unless batches are being used - $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', - 'title' => ts('Batch Name'), - ); - $this->_columns['civicrm_batch']['filters']['bid'] = array( - 'name' => 'id', - 'title' => ts('Batch Name'), - 'type' => CRM_Utils_Type::T_INT, - 'operatorType' => CRM_Report_Form::OP_MULTISELECT, - 'options' => $this->_allBatches, - ); - $this->_columns['civicrm_entity_batch']['dao'] = 'CRM_Batch_DAO_EntityBatch'; - $this->_columns['civicrm_entity_batch']['fields']['entity_batch_id'] = array( - 'name' => 'batch_id', - 'default' => TRUE, - 'no_display' => TRUE, - ); - } - if ($campaignEnabled && !empty($this->activeCampaigns)) { $this->_columns['civicrm_contribution']['fields']['campaign_id'] = array( 'title' => ts('Campaign'), @@ -375,6 +373,7 @@ class CRM_Report_Form_Member_ContributionDetail extends CRM_Report_Form { 'title' => ts('Campaign'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => $this->activeCampaigns, + 'type' => CRM_Utils_Type::T_INT, ); $this->_columns['civicrm_contribution']['order_bys']['campaign_id'] = array('title' => ts('Campaign')); } @@ -448,6 +447,7 @@ class CRM_Report_Form_Member_ContributionDetail extends CRM_Report_Form { } } + $this->_selectClauses = $select; $this->_select = 'SELECT ' . implode(', ', $select) . ' '; } @@ -501,18 +501,16 @@ class CRM_Report_Form_Member_ContributionDetail extends CRM_Report_Form { {$this->_aliases['civicrm_phone']}.is_primary = 1)"; } //for contribution batches - if ($this->_allBatches && - (!empty($this->_params['fields']['batch_id']) || - !empty($this->_params['bid_value'])) + if (!empty($this->_params['fields']['batch_id']) || + !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 = 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"; + 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')"; } if ($this->_addressField OR @@ -542,7 +540,7 @@ class CRM_Report_Form_Member_ContributionDetail extends CRM_Report_Form { CRM_Core_DAO::executeQuery($dropTempTable); $sql = 'CREATE TEMPORARY TABLE civireport_membership_contribution_detail - (contribution_id int, INDEX USING HASH(contribution_id), contact_id int, INDEX USING HASH(contact_id), + (contribution_id int, INDEX USING HASH(contribution_id), contact_id int, INDEX USING HASH(contact_id), membership_id int, INDEX USING HASH(membership_id), payment_id int, INDEX USING HASH(payment_id)) ENGINE=MEMORY'; CRM_Core_DAO::executeQuery($sql); @@ -587,11 +585,17 @@ class CRM_Report_Form_Member_ContributionDetail extends CRM_Report_Form { } $sql = "{$this->_select} {$this->_from} {$this->_where} {$this->_groupBy} {$this->_having} {$this->_orderBy} {$this->_limit}"; + $this->addToDeveloperTab($sql); return $sql; } public function groupBy() { - $this->_groupBy = " GROUP BY {$this->_aliases['civicrm_contact']}.id, {$this->_aliases['civicrm_contribution']}.id "; + $groupBy = array( + "{$this->_aliases['civicrm_contact']}.id", + "{$this->_aliases['civicrm_contribution']}.id", + ); + $this->_groupBy = " GROUP BY " . implode(', ', $groupBy); + $this->_groupBy .= CRM_Contact_BAO_Query::getGroupByFromSelectColumns($this->_selectClauses, $groupBy); } public function orderBy() { @@ -658,6 +662,7 @@ class CRM_Report_Form_Member_ContributionDetail extends CRM_Report_Form { $contributionTypes = CRM_Contribute_PseudoConstant::financialType(); $contributionStatus = CRM_Contribute_PseudoConstant::contributionStatus(); $paymentInstruments = CRM_Contribute_PseudoConstant::paymentInstrument(); + $batches = CRM_Batch_BAO_Batch::getBatches(); //altering the csv display adding additional fields if ($this->_outputMode == 'csv') { @@ -740,10 +745,8 @@ class CRM_Report_Form_Member_ContributionDetail extends CRM_Report_Form { $entryFound = TRUE; } - if (array_key_exists('civicrm_batch_batch_id', $row)) { - if ($value = $row['civicrm_batch_batch_id']) { - $rows[$rowNum]['civicrm_batch_batch_id'] = CRM_Core_DAO::getFieldValue('CRM_Batch_DAO_Batch', $value, 'title'); - } + if (!empty($row['civicrm_batch_batch_id'])) { + $rows[$rowNum]['civicrm_batch_batch_id'] = CRM_Utils_Array::value($row['civicrm_batch_batch_id'], $batches); $entryFound = TRUE; }