Commit fad0ab9c authored by bgm's avatar bgm Committed by Aegir user

Update nz.co.fuzion.extendedreport to v3.5

parent 617c38bb
......@@ -9,22 +9,6 @@ class CRM_Extendedreport_Form_Report_ActivityEditable extends CRM_Extendedreport
* @var array
*/
protected $_customGroupExtends = array('Activity');
/**
* @var bool
*/
protected $_addressField = FALSE;
/**
* @var bool
*/
protected $_emailField = FALSE;
/**
* @var null
*/
protected $_summary = NULL;
/**
* @var bool
*/
protected $_exposeContactID = FALSE;
/**
* @var bool
*/
......@@ -42,8 +26,8 @@ class CRM_Extendedreport_Form_Report_ActivityEditable extends CRM_Extendedreport
* Class constructor.
*/
public function __construct() {
$this->_columns = $this->getColumns('Activity')
+ $this->getColumns('Contact', array('prefix' => 'target_',));
$this->_columns = $this->getColumns('Activity', array('fields_defaults' => array('activity_type_id', 'details', 'subject')))
+ $this->getColumns('Contact', array('prefix' => 'target_'));
$this->_columns['civicrm_activity']['fields']['id'] = array(
'title' => 'id',
'required' => TRUE,
......
......@@ -59,15 +59,15 @@ class CRM_Extendedreport_Form_Report_ActivityExtended extends CRM_Extendedreport
'prefix' => 'target_',
'group_by' => TRUE,
'prefix_label' => 'Target Contact ::',
'filters' => FALSE,
'filters' => TRUE,
)
) + $this->getColumns(
'Contact', array(
'prefix' => 'assignee_',
'prefix_label' => 'Assignee Contact ::',
'filters' => FALSE,
'filters' => TRUE,
)
) + $this->getColumns('Activity');
) + $this->getColumns('Activity', array('group_by' => TRUE));
parent::__construct();
}
......@@ -96,16 +96,19 @@ class CRM_Extendedreport_Form_Report_ActivityExtended extends CRM_Extendedreport
LEFT JOIN civicrm_email civicrm_email_source
ON {$this->_aliases['civicrm_activity']}.source_contact_id = civicrm_email_source.contact_id
AND civicrm_email_source.is_primary = 1
AND civicrm_email_source.is_deleted = 0
LEFT JOIN civicrm_email civicrm_email_target
ON {$this->_aliases['civicrm_activity_target']}.target_contact_id = civicrm_email_target.contact_id
AND civicrm_email_target.is_primary = 1
AND civicrm_email_target.is_deleted = 0
LEFT JOIN civicrm_email civicrm_email_assignee
ON {$this->_aliases['civicrm_activity_assignment']}.assignee_contact_id = civicrm_email_assignee.contact_id
AND civicrm_email_assignee.is_primary = 1 ";
AND civicrm_email_assignee.is_primary = 1
AND civicrm_email_assignee.is_deleted = 0
";
}
$this->addAddressFromClause();
$this->selectableCustomDataFrom();
}
......
......@@ -13,6 +13,7 @@ class CRM_Extendedreport_Form_Report_ActivityPivot extends CRM_Extendedreport_Fo
protected $_rollup = 'WITH ROLLUP';
public $_drilldownReport = array();
protected $_potentialCriteria = array();
protected $_noFields = TRUE;
/**
* Class constructor.
......
......@@ -12,9 +12,9 @@ class CRM_Extendedreport_Form_Report_Campaign_CampaignProgressReport extends CRM
protected $_summary = NULL;
protected $_totalPaid = FALSE;
protected $_customGroupExtends = array(
'Pledge',
'Campaign',
);
public $_drilldownReport = array('pledge/details' => 'Pledge Details');
protected $_baseTable = 'civicrm_campaign';
protected $_customGroupGroupBy = TRUE;
/**
......@@ -30,6 +30,7 @@ class CRM_Extendedreport_Form_Report_Campaign_CampaignProgressReport extends CRM
'financial_type_id' => array(
'title' => ts('Financial type'),
'alter_display' => 'alterFinancialType',
'statistics' => array('GROUP_CONCAT'),
),
'total_amount' => array(
'title' => ts('Raised'),
......@@ -51,6 +52,7 @@ class CRM_Extendedreport_Form_Report_Campaign_CampaignProgressReport extends CRM
'type' => CRM_Utils_Type::T_BOOLEAN,
'options' => array(0 => ts('Payment'), 1 => ts('Pledge')),
'alter_display' => 'alterIsPledge',
'statistics' => array('GROUP_CONCAT'),
),
'still_to_raise' => array(
'title' => ts('Balance to raise'),
......@@ -64,6 +66,29 @@ class CRM_Extendedreport_Form_Report_Campaign_CampaignProgressReport extends CRM
'operatorType' => self::OP_SINGLEDATE,
'pseudofield' => TRUE,
),
'financial_type_id' => array(
'title' => ts('Financial type'),
'alter_display' => 'alterFinancialType',
'type' => CRM_Utils_Type::T_INT,
'operatorType' => self::OP_MULTISELECT,
'options' => $this->_getOptions('Contribution', 'financial_type_id'),
),
),
'group_bys' => array(
'financial_type_id' => array(
'title' => ts('Financial type'),
'alter_display' => 'alterFinancialType',
'type' => CRM_Utils_Type::T_INT,
'operatorType' => self::OP_MULTISELECT,
'options' => $this->_getOptions('Contribution', 'financial_type_id'),
),
'is_pledge' => array(
'title' => ts('Type'),
'type' => CRM_Utils_Type::T_BOOLEAN,
'options' => array(0 => ts('Payment'), 1 => ts('Pledge')),
'alter_display' => 'alterIsPledge',
'statistics' => array('GROUP_CONCAT'),
),
),
),
);
......@@ -78,33 +103,13 @@ class CRM_Extendedreport_Form_Report_Campaign_CampaignProgressReport extends CRM
FROM civicrm_campaign {$this->_aliases['civicrm_campaign']}";
$this->joinProgressTable();
if (!$this->isTableSelected('civicrm_contact')) {
$this->_aliases['civicrm_contact'] = 'civicrm_contact';
}
$this->_aliases['civicrm_contact'] = 'civicrm_contact';
$this->_from .= "
LEFT JOIN civicrm_contact {$this->_aliases['civicrm_contact']}
ON ({$this->_aliases['civicrm_contact']}.id =
progress.contact_id )
{$this->_aclFrom} ";
// include address field if address column is to be included
if ($this->isTableSelected('civicrm_address')) {
$this->_from .= "
LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']}
ON ({$this->_aliases['civicrm_contact']}.id =
{$this->_aliases['civicrm_address']}.contact_id) AND
{$this->_aliases['civicrm_address']}.is_primary = 1\n";
}
// include email field if email column is to be included
if ($this->isTableSelected('civicrm_email')) {
$this->_from .= "
LEFT JOIN civicrm_email {$this->_aliases['civicrm_email']}
ON ({$this->_aliases['civicrm_contact']}.id =
{$this->_aliases['civicrm_email']}.contact_id) AND
{$this->_aliases['civicrm_email']}.is_primary = 1\n";
}
LEFT JOIN civicrm_contact {$this->_aliases['civicrm_contact']}
ON ({$this->_aliases['civicrm_contact']}.id = progress.contact_id )
{$this->_aclFrom}
";
}
/**
......@@ -150,12 +155,11 @@ LEFT JOIN
LEFT JOIN civicrm_pledge_payment pp ON pp.contribution_id = c.id
WHERE c.contribution_status_id = 1
AND pp.id IS NULL ";
if ($until) {
$this->_from .= ' AND c.receive_date <= "' . CRM_Utils_Type::validate(CRM_Utils_Date::processDate($until, 235959), 'Integer') . '"';
}
$this->_from .= ") as progress ON progress.campaign_id = campaign.id
if ($until) {
$this->_from .= ' AND c.receive_date <= "' . CRM_Utils_Type::validate(CRM_Utils_Date::processDate($until, 235959), 'Integer') . '"';
}
$this->_from .= ") as progress ON progress.campaign_id = {$this->_aliases['civicrm_campaign']}.id
";
}
......@@ -172,12 +176,13 @@ LEFT JOIN
function selectClause(&$tableName, $tableKey, &$fieldName, &$field) {
if ($fieldName == 'still_to_raise') {
$alias = "{$tableName}_{$fieldName}";
$this->_columnHeaders["{$tableName}_{$fieldName}"]['title'] = CRM_Utils_Array::value('title', $field);
$this->_columnHeaders["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array::value('type', $field);
$this->_columnHeaders["{$tableName}_{$fieldName}"]['dbAlias'] = CRM_Utils_Array::value('dbAlias', $field);
$this->_columnHeaders[$alias]['title'] = CRM_Utils_Array::value('title', $field);
$this->_columnHeaders[$alias]['type'] = CRM_Utils_Array::value('type', $field);
$this->_columnHeaders[$alias]['dbAlias'] = CRM_Utils_Array::value('dbAlias', $field);
$this->_selectAliases[] = $alias;
return " COALESCE(campaign.goal_revenue - SUM(COALESCE(progress.total_amount, 0)), 0) as $alias ";
return " COALESCE(campaign.goal_revenue, 0) - SUM(COALESCE(progress.total_amount, 0)) as $alias ";
}
return parent::selectClause($tableName, $tableKey, $fieldName, $field);
}
/**
......@@ -195,7 +200,7 @@ LEFT JOIN
* @return string
*/
function alterIsPledge($value) {
return $value ? ts('Pledge') : ts('Payment');
return str_replace(array(0, 1), array(ts('Payment without pledge'),ts('Pledge')), $value);
}
/**
......@@ -203,7 +208,7 @@ LEFT JOIN
*/
function alterDisplay(&$rows) {
parent::alterDisplay($rows);
$this->unsetUnreliableColumnsIfNotCampaignGrouped();
if (isset($this->_columnHeaders['progress_still_to_raise'])) {
$move = $this->_columnHeaders['progress_still_to_raise'];
unset($this->_columnHeaders['progress_still_to_raise']);
......@@ -231,11 +236,22 @@ LEFT JOIN
}
}
$this->rollupRow['civicrm_campaign_campaign_goal_revenue'] = $grandTotalRaised;
$this->rollupRow['progress_still_to_raise'] = $grandTotalLeft;
$this->rollupRow['civicrm_campaign_campaign_goal_revenue'] = $runningTotalRaised;
$this->rollupRow['progress_still_to_raise'] = $runningTotalLeft;
$this->assign('grandStat', $this->rollupRow);
}
/**
* Do we have a group by array that does not include campaign/
*/
protected function groupByCampaignTypeNotCampaign() {
if (!empty($this->_groupByArray)) {
if (!in_array('campaign.id', $this->_groupByArray)) {
return TRUE;
}
}
return FALSE;
}
/**
* Note: $fieldName param allows inheriting class to build operationPairs
......@@ -255,4 +271,17 @@ LEFT JOIN
return parent::getOperationPair($type, $fieldName);
}
protected function unsetUnreliableColumnsIfNotCampaignGrouped() {
if ($this->groupByCampaignTypeNotCampaign()) {
if (isset($this->_columnHeaders['progress_still_to_raise'])) {
unset($this->_columnHeaders['progress_still_to_raise']);
CRM_Core_Session::setStatus(ts('Currently campaign revenue cannot be calculated against the goal if grouping does not include campaign'));
}
if (isset($this->_columnHeaders['civicrm_campaign_campaign_goal_revenue'])) {
unset($this->_columnHeaders['civicrm_campaign_campaign_goal_revenue']);
CRM_Core_Session::setStatus(ts('Currently campaign revenue cannot be calculated against the goal if grouping does not include campaign'));
}
}
}
}
......@@ -14,6 +14,7 @@ class CRM_Extendedreport_Form_Report_Case_ActivityPivot extends CRM_Extendedrepo
public $_drilldownReport = array();
protected $_potentialCriteria = array();
protected $isPivot = TRUE;
protected $_noFields = TRUE;
/**
* Class constructor.
......
......@@ -15,6 +15,7 @@ class CRM_Extendedreport_Form_Report_Case_CasePivot extends CRM_Extendedreport_F
public $_drilldownReport = array();
protected $_potentialCriteria = array();
protected $isPivot = TRUE;
protected $_noFields = TRUE;
/**
* Class constructor.
......
......@@ -14,6 +14,7 @@ class CRM_Extendedreport_Form_Report_Case_CaseWithActivityPivot extends CRM_Exte
protected $_aggregatesAddPercentage = TRUE;
public $_drilldownReport = array();
protected $isPivot = TRUE;
protected $_noFields = TRUE;
/**
* PreConstrain means the query gets run twice - the first time for generating temp tables
* which go in the from the second time around
......
<?php
// This file declares a managed database record of type "ReportTemplate".
// The record will be automatically inserted, updated, or deleted from the
// database as appropriate. For more details, see "hook_civicrm_managed" at:
// http://wiki.civicrm.org/confluence/display/CRMDOC42/Hook+Reference
return array (
0 =>
array (
'name' => 'Address History Report',
'entity' => 'ReportTemplate',
'is_require_logging' => TRUE,
'params' =>
array (
'version' => 3,
'label' => 'Address History',
'description' => 'ContactAddress History',
'class_name' => 'CRM_Extendedreport_Form_Report_Contact_AddressHistory',
'report_url' => 'contact/addresshistory',
'component' => '',
),
),
);
<?php
/**
* Class CRM_Extendedreport_Form_Report_Contact_AddressHistory
*/
class CRM_Extendedreport_Form_Report_Contact_AddressHistory extends CRM_Extendedreport_Form_Report_ExtendedReport {
protected $_baseTable = 'log_civicrm_address';
protected $isSupportsContactTab = TRUE;
/**
* Contact ID being filtered for.
*
* @var int
*/
protected $contactID;
/**
* Contact ID being filtered for.
*
* @var int
*/
protected $activityTypeID;
/**
* Contacts merged into tracked contacts.
*
* @var array
*/
protected $mergedContacts = array();
public function __construct() {
$this->_columns = $this->getColumns('Address', array(
'fields' => TRUE,
'order_by' => FALSE,
//'fields_defaults' => array('address_name', 'street_address', 'supplemental_address_1', 'supplemental_address_2', 'city', 'state_province_id', 'country_id', 'postal_code', 'county_id'),
'fields_defaults' => array('display_address'),
)
);
$this->_columns['log_civicrm_address'] = $this->_columns['civicrm_address'];
unset($this->_columns['civicrm_address']);
$logMetaData = array(
'id' => array(
'name' => 'id',
'title' => ts('Address ID'),
'type' => CRM_Utils_Type::T_INT,
'is_fields' => TRUE,
'no_display' => TRUE,
),
'contact_id' => array(
'name' => 'contact_id',
'title' => ts('Contact ID'),
'type' => CRM_Utils_Type::T_INT,
'is_fields' => TRUE,
'is_filters' => TRUE,
),
'log_date' => array(
'name' => 'log_date',
'title' => ts('Change Date'),
'type' => CRM_Utils_Type::T_TIMESTAMP,
'is_fields' => TRUE,
'default' => 1,
),
'log_conn_id' => array(
'name' => 'log_conn_id',
'title' => ts('Connection'),
'type' => CRM_Utils_Type::T_STRING,
'is_fields' => TRUE,
'default' => 1,
),
'log_user_id' => array(
'name' => 'log_user_id',
'title' => ts('Changed By'),
'type' => CRM_Utils_Type::T_INT,
'is_fields' => TRUE,
'default' => 1,
),
'log_action' => array(
'name' => 'log_action',
'title' => ts('Change action'),
'type' => CRM_Utils_Type::T_STRING,
'is_fields' => TRUE,
'default' => 1,
),
);
$this->_columns['log_civicrm_address']['metadata'] += $logMetaData;
$this->_columns['log_civicrm_address']['fields'] += $logMetaData;
$this->_columns['log_civicrm_address']['filters']['contact_id'] = $logMetaData['contact_id'];
$activityTypes = civicrm_api3('Activity', 'getoptions', array('field' => 'activity_type_id'));
$this->activityTypeID = array_search('Contact Deleted by Merge', $activityTypes['values']);
parent::__construct();
}
/**
public function alterDisplay(&$rows) {
parent::alterDisplay($rows);
// Process rows in reverse order.
$oldestUnprocessedRowIndex = (count($rows) - 1);
while ($oldestUnprocessedRowIndex > -1) {
$row = &$rows[$oldestUnprocessedRowIndex];
$oldestUnprocessedRowIndex--;
}
return $rows;
}*/
/**
* Build order by clause.
*/
public function orderBy() {
parent::orderBy();
$this->_orderBy = "ORDER BY address.log_date DESC";
}
/**
* Generate where clause.
*
* This can be overridden in reports for special treatment of a field
*
* @param array $field Field specifications
* @param string $op Query operator (not an exact match to sql)
* @param mixed $value
* @param float $min
* @param float $max
*
* @return null|string
*/
public function whereClause(&$field, $op, $value, $min, $max) {
if ($field['name'] === 'contact_id' && $value) {
$this->contactID = (int) $value;
$mergedContactIDs = $this->getContactsMergedIntoThisOne($this->contactID);
$clause = parent::whereClause($field, 'in', array_merge(array($this->contactID), $mergedContactIDs), $min, $max);
return $clause;
}
}
/**
* @param int $contactID
* @return int
*/
protected function getContactsMergedIntoThisOne($contactID) {
// @todo get api joins working properly.
$result = civicrm_api3('Activity', 'get', array(
'assignee_contact_id' => $contactID,
'return' => 'id',
'activity_type_id' => $this->activityTypeID,
'api.ActivityContact.get' => array('record_type_id' => 'Activity Targets', 'return' => 'contact_id')
));
if ($result['count']) {
foreach ($result['values'] as $resultRow) {
if (!empty($resultRow['api.ActivityContact.get'])) {
foreach ($resultRow['api.ActivityContact.get']['values'] as $deletedContact) {
if (!in_array($deletedContact['contact_id'], $this->mergedContacts)) {
$this->mergedContacts[] = $deletedContact['contact_id'];
$this->getContactsMergedIntoThisOne($deletedContact['contact_id']);
}
}
}
}
}
return $this->mergedContacts;
}
}
......@@ -10,6 +10,8 @@ class CRM_Extendedreport_Form_Report_Contact_Extendedcontact extends CRM_Extende
protected $_baseTable = 'civicrm_contact';
protected $skipACL = TRUE;
protected $_customGroupAggregates = TRUE;
protected $isPivot = TRUE;
protected $_noFields = TRUE;
/**
......@@ -22,6 +24,9 @@ class CRM_Extendedreport_Form_Report_Contact_Extendedcontact extends CRM_Extende
)
);
$this->_columns['civicrm_contact']['fields']['id']['required'] = TRUE;
$this->_aggregateColumnHeaderFields = array(
'civicrm_contact_civireport:gender_id' => 'Gender',
);
parent::__construct();
}
}
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.5 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2014 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2014
* $Id$
*/
class CRM_Extendedreport_Form_Report_Contribute_BookkeepingExtended extends CRM_Extendedreport_Form_Report_ExtendedReport {
/**
* Class constructor.
*/
public function __construct() {
$this->_columns = $this->getColumns('Contact')
+ $this->getColumns('Address')
+ $this->getColumns('Phone', array('subquery' => FALSE,))
+ $this->getColumns('Email')
+ $this->getColumns('Membership')
+ $this->getColumns('FinancialAccount', array(
'prefix' => 'credit_',
'group_by' => TRUE,
'prefix_label' => ts('Credit '),
'filters' => TRUE,
))
+ $this->getColumns('FinancialAccount', array(
'prefix' => 'debit_',
'group_by' => TRUE,
'prefix_label' => ts('Debit '),
'filters' => FALSE,
))
+ $this->getColumns('LineItem')
+ $this->getColumns('Contribution', array(
'field_defaults' => array('receive_date', 'id'),
'filters_defaults' => array('contribution_status_id' => array('IN' => array(1)),
)))
+ array(
'civicrm_financial_trxn' => array(
'dao' => 'CRM_Financial_DAO_FinancialTrxn',
'fields' => array(
'check_number' => array(
'title' => ts('Cheque #'),
'default' => TRUE,
),
'payment_instrument_id' => array(
'title' => ts('Payment Instrument'),
'default' => TRUE,
'alter_display' => 'alterPaymentType',
),
'currency' => array(
'required' => TRUE,
'no_display' => TRUE,
),
'trxn_date' => array(
'title' => ts('Transaction Date'),
'default' => TRUE,
'type' => CRM_Utils_Type::T_DATE,
),
'trxn_id' => array(
'title' => ts('Trans #'),
'default' => TRUE,
),
),
'filters' => array(
'payment_instrument_id' => array(
'title' => ts('Payment Instrument'),
'operatorType' => CRM_Report_Form::OP_MULTISELECT,
'options' => CRM_Contribute_PseudoConstant::paymentInstrument(),
'type' => CRM_Utils_Type::T_INT,
),
'currency' => array(
'title' => 'Currency',
'operatorType' => CRM_Report_Form::OP_MULTISELECT,
'options' => CRM_Core_OptionGroup::values('currencies_enabled'),
'default' => NULL,
'type' => CRM_Utils_Type::T_STRING,
),
'trxn_date' => array(
'title' => ts('Transaction Date'),
'operatorType' => CRM_Report_Form::OP_DATE,
'type' => CRM_Utils_Type::T_DATE,
),
),
'order_bys' => array(
'payment_instrument_id' => array('title' => ts('Payment Instrument')),
),
),
) + array(
'civicrm_entity_financial_trxn' => array(
'dao' => 'CRM_Financial_DAO_EntityFinancialTrxn',
'fields' => array(
'amount' => array(
'title' => ts('Amount'),
'default' => TRUE,
'type' => CRM_Utils_Type::T_STRING,
'statistics' => array('sum'),
),
),
'filters' => array(
'amount' => array(