+--------------------------------------------------------------------+
| CiviCRM version 4.6 |
+--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2014 |
+ | Copyright CiviCRM LLC (c) 2004-2015 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
/**
*
* @package CRM
- * @copyright CiviCRM LLC (c) 2004-2014
+ * @copyright CiviCRM LLC (c) 2004-2015
* $Id$
*
*/
protected $_summary = NULL;
protected $_customGroupExtends = array(
+ 'Contact',
+ 'Individual',
+ 'Contribution',
'Membership',
);
- /**
- */
/**
*/
public function __construct() {
+ $this->_autoIncludeIndexedFieldsAsOrderBys = 1;
$this->_columns = array(
'civicrm_contact' => array(
'dao' => 'CRM_Contact_DAO_Contact',
'required' => TRUE,
'no_repeat' => TRUE,
),
+ 'first_name' => array(
+ 'title' => ts('First Name'),
+ ),
+ 'middle_name' => array(
+ 'title' => ts('Middle Name'),
+ ),
+ 'last_name' => array(
+ 'title' => ts('Last Name'),
+ ),
'id' => array(
'no_display' => TRUE,
'required' => TRUE,
),
+ 'gender_id' => array(
+ 'title' => ts('Gender'),
+ ),
+ 'birth_date' => array(
+ 'title' => ts('Birth Date'),
+ ),
+ 'age' => array(
+ 'title' => ts('Age'),
+ 'dbAlias' => 'TIMESTAMPDIFF(YEAR, contact_civireport.birth_date, CURDATE())',
+ ),
+ 'contact_type' => array(
+ 'title' => ts('Contact Type'),
+ ),
+ 'contact_sub_type' => array(
+ 'title' => ts('Contact Subtype'),
+ ),
+ ),
+ 'grouping' => 'contact-fields',
+ 'order_bys' => array(
+ 'sort_name' => array(
+ 'title' => ts('Last Name, First Name'),
+ 'default' => '1',
+ 'default_weight' => '0',
+ 'default_order' => 'ASC',
+ ),
+ 'first_name' => array(
+ 'name' => 'first_name',
+ 'title' => ts('First Name'),
+ ),
+ 'gender_id' => array(
+ 'name' => 'gender_id',
+ 'title' => ts('Gender'),
+ ),
+ 'birth_date' => array(
+ 'name' => 'birth_date',
+ 'title' => ts('Birth Date'),
+ ),
'contact_type' => array(
'title' => ts('Contact Type'),
),
'title' => ts('Contact ID'),
'no_display' => TRUE,
),
- ),
- 'order_bys' => array(
- 'sort_name' => array(
- 'title' => ts('Last Name, First Name'),
+ 'gender_id' => array(
+ 'title' => ts('Gender'),
+ 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
+ 'options' => CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id'),
+ ),
+ 'birth_date' => array(
+ 'title' => ts('Birth Date'),
+ 'operatorType' => CRM_Report_Form::OP_DATE,
+ ),
+ 'contact_type' => array(
+ 'title' => ts('Contact Type'),
+ ),
+ 'contact_sub_type' => array(
+ 'title' => ts('Contact Subtype'),
),
),
- 'grouping' => 'contact-fields',
),
'civicrm_membership' => array(
'dao' => 'CRM_Member_DAO_Membership',
parent::postProcess();
}
+ public function groupBy() {
+ $this->_groupBy = " GROUP BY {$this->_aliases['civicrm_entity_financial_trxn']}.id, {$this->_aliases['civicrm_line_item']}.id ";
+ }
+
/**
* @param $rows
*
*/
public function statistics(&$rows) {
$statistics = parent::statistics($rows);
-
- $select = " SELECT COUNT({$this->_aliases['civicrm_financial_trxn']}.id ) as count,
- {$this->_aliases['civicrm_contribution']}.currency,
- SUM(CASE
- WHEN {$this->_aliases['civicrm_entity_financial_trxn']}_item.entity_id IS NOT NULL
- THEN {$this->_aliases['civicrm_entity_financial_trxn']}_item.amount
- ELSE {$this->_aliases['civicrm_entity_financial_trxn']}.amount
- END) as amount
+ $tempTableName = CRM_Core_DAO::createTempTableName('civicrm_contribution');
+ $select = "SELECT {$this->_aliases['civicrm_contribution']}.id, {$this->_aliases['civicrm_entity_financial_trxn']}.id as trxnID, {$this->_aliases['civicrm_contribution']}.currency,
+ CASE
+ WHEN {$this->_aliases['civicrm_entity_financial_trxn']}_item.entity_id IS NOT NULL
+ THEN {$this->_aliases['civicrm_entity_financial_trxn']}_item.amount
+ ELSE {$this->_aliases['civicrm_entity_financial_trxn']}.amount
+ END as amount
";
- $sql = "{$select} {$this->_from} {$this->_where}
- GROUP BY {$this->_aliases['civicrm_contribution']}.currency
-";
+ $tempQuery = "CREATE TEMPORARY TABLE {$tempTableName} CHARACTER SET utf8 COLLATE utf8_unicode_ci AS
+ {$select} {$this->_from} {$this->_where} {$this->_groupBy} ";
+ CRM_Core_DAO::executeQuery($tempQuery);
+ $sql = "SELECT COUNT(trxnID) as count, SUM(amount) as amount, currency
+ FROM {$tempTableName}
+ GROUP BY currency";
$dao = CRM_Core_DAO::executeQuery($sql);
+ $amount = $avg = array();
while ($dao->fetch()) {
$amount[] = CRM_Utils_Money::format($dao->amount, $dao->currency);
$avg[] = CRM_Utils_Money::format(round(($dao->amount /
if ($value = CRM_Utils_Array::value('civicrm_entity_financial_trxn_amount', $row)) {
$rows[$rowNum]['civicrm_entity_financial_trxn_amount'] = CRM_Utils_Money::format($rows[$rowNum]['civicrm_entity_financial_trxn_amount'], $rows[$rowNum]['civicrm_financial_trxn_currency']);
}
+
+ //handle gender
+ if (array_key_exists('civicrm_contact_gender_id', $row)) {
+ if ($value = $row['civicrm_contact_gender_id']) {
+ $gender = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id');
+ $rows[$rowNum]['civicrm_contact_gender_id'] = $gender[$value];
+ }
+ $entryFound = TRUE;
+ }
+
+ // display birthday in the configured custom format
+ if (array_key_exists('civicrm_contact_birth_date', $row)) {
+ $birthDate = $row['civicrm_contact_birth_date'];
+ if ($birthDate) {
+ $rows[$rowNum]['civicrm_contact_birth_date'] = CRM_Utils_Date::customFormat($birthDate, '%Y%m%d');
+ }
+ $entryFound = TRUE;
+ }
+
}
}