Commit 1c96c086 authored by Mathieu Lutfy's avatar Mathieu Lutfy Committed by Aegir user
Browse files

Update extendedreport

parent cf24b4fe
......@@ -31,6 +31,7 @@ class CRM_Extendedreport_Form_Report_ActivityEditable extends CRM_Extendedreport
$this->_columns['civicrm_activity']['fields']['id'] = array(
'title' => 'id',
'required' => TRUE,
'type' => CRM_Utils_Type::T_INT,
);
parent::__construct();
}
......
......@@ -4,37 +4,25 @@
* Class CRM_Extendedreport_Form_Report_ActivityExtended
*/
class CRM_Extendedreport_Form_Report_ActivityExtended extends CRM_Extendedreport_Form_Report_ExtendedReport {
//todo move def to getActivityColumns
/**
* @var array
*/
protected $_customGroupExtended = array(
'civicrm_activity' => array(
'extends' => array('Activity'),
'title' => 'Activity',
'filters' => TRUE,
),
);
/**
* @var bool
*/
protected $_addressField = FALSE;
protected $_customGroupExtends = ['Activity', 'Contact', 'Individual', 'Household', 'Organization'];
protected $_editableFields = FALSE;
/**
* Can this report be used on a contact tab.
*
* The report must support contact_id in the url for this to work.
*
* @var bool
*/
protected $_emailField = FALSE;
/**
* @var null
*/
protected $_summary = NULL;
protected $isSupportsContactTab = TRUE;
/**
* @var bool
*/
protected $_exposeContactID = FALSE;
/**
* @var bool
*/
protected $_customGroupGroupBy = FALSE;
/**
* @var string
*/
......@@ -42,8 +30,6 @@ class CRM_Extendedreport_Form_Report_ActivityExtended extends CRM_Extendedreport
/**
* Class constructor.
*
* @todo allow filtering on other contacts
*/
public function __construct() {
$this->_columns = $this->getColumns(
......@@ -109,7 +95,6 @@ class CRM_Extendedreport_Form_Report_ActivityExtended extends CRM_Extendedreport
AND civicrm_email_assignee.is_deleted = 0
";
}
$this->selectableCustomDataFrom();
}
/**
......
......@@ -21,81 +21,91 @@ class CRM_Extendedreport_Form_Report_Campaign_CampaignProgressReport extends CRM
* Class constructor.
*/
public function __construct() {
$this->_columns
= $this->getColumns('Campaign') +
array(
'progress' => array(
'alias' => 'progress',
'fields' => array(
'financial_type_id' => array(
'title' => ts('Financial type'),
'alter_display' => 'alterFinancialType',
'statistics' => array('GROUP_CONCAT'),
),
'total_amount' => array(
'title' => ts('Raised'),
'type' => CRM_Utils_Type::T_MONEY,
'statistics' => array('sum' => ts('Total Raised')),
),
'paid_amount' => array(
'title' => ts('Amount received'),
'type' => CRM_Utils_Type::T_MONEY,
'statistics' => array('sum' => ts('Total Received')),
),
'balance_amount' => array(
'title' => ts('Amount outstanding'),
'type' => CRM_Utils_Type::T_MONEY,
'statistics' => array('sum' => ts('Pledges Outstanding')),
),
'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'),
),
'still_to_raise' => array(
'title' => ts('Balance to raise'),
'type' => CRM_Utils_Type::T_MONEY,
),
),
'filters' => array(
'effective_date' => array(
'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME,
'title' => ts('Date range'),
'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'),
),
),
),
);
$progressSpec = [
'financial_type_id' => [
'title' => ts('Financial type'),
'alter_display' => 'alterFinancialType',
'type' => CRM_Utils_Type::T_INT,
'operatorType' => self::OP_MULTISELECT,
'is_fields' => TRUE,
'is_filters' => TRUE,
'is_group_bys' => TRUE,
'is_order_bys' => FALSE,
'is_join_filters' => FALSE,
'options' => $this->_getOptions('Contribution', 'financial_type_id'),
],
'total_amount' => [
'title' => ts('Raised'),
'type' => CRM_Utils_Type::T_MONEY,
'operatorType' => CRM_Report_Form::OP_FLOAT,
'statistics' => array('sum' => ts('Total Raised')),
'is_fields' => TRUE,
'is_filters' => FALSE,
'is_group_bys' => FALSE,
'is_order_bys' => FALSE,
'is_join_filters' => FALSE,
],
'paid_amount' => [
'title' => ts('Amount received'),
'type' => CRM_Utils_Type::T_MONEY,
'operatorType' => CRM_Report_Form::OP_FLOAT,
'statistics' => array('sum' => ts('Total Received')),
'is_fields' => TRUE,
'is_filters' => FALSE,
'is_group_bys' => FALSE,
'is_order_bys' => FALSE,
'is_join_filters' => FALSE,
],
'balance_amount' => [
'title' => ts('Amount outstanding'),
'type' => CRM_Utils_Type::T_MONEY,
'operatorType' => CRM_Report_Form::OP_FLOAT,
'statistics' => array('sum' => ts('Pledges Outstanding')),
'is_fields' => TRUE,
'is_filters' => FALSE,
'is_group_bys' => FALSE,
'is_order_bys' => FALSE,
'is_join_filters' => FALSE,
],
'is_pledge' => [
'title' => ts('Type'),
'type' => CRM_Utils_Type::T_BOOLEAN,
'operatorType' => CRM_Report_Form::OP_SELECT,
'options' => array(0 => ts('Payment'), 1 => ts('Pledge')),
'alter_display' => 'alterIsPledge',
'is_fields' => TRUE,
'is_filters' => FALSE,
'is_group_bys' => TRUE,
'is_order_bys' => FALSE,
'is_join_filters' => FALSE,
],
'still_to_raise' => [
'title' => ts('Balance to raise'),
'type' => CRM_Utils_Type::T_MONEY,
'operatorType' => CRM_Report_Form::OP_FLOAT,
'is_fields' => TRUE,
'is_filters' => FALSE,
'is_group_bys' => FALSE,
'is_order_bys' => FALSE,
'is_join_filters' => FALSE,
],
'effective_date' => [
'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME,
'title' => ts('Date range'),
'operatorType' => self::OP_SINGLEDATE,
'pseudofield' => TRUE,
'is_fields' => FALSE,
'is_filters' => TRUE,
'is_group_bys' => FALSE,
'is_order_bys' => FALSE,
'is_join_filters' => FALSE,
],
];
$this->_columns = $this->getColumns('Campaign') + $this->buildColumns($progressSpec, 'progress');
$this->_groupFilter = TRUE;
$this->_tagFilter = TRUE;
parent::__construct();
CRM_Core_DAO::disableFullGroupByMode();
}
function from() {
......@@ -117,29 +127,33 @@ class CRM_Extendedreport_Form_Report_Campaign_CampaignProgressReport extends CRM
*/
protected function joinProgressTable() {
$until = CRM_Utils_Array::value('effective_date_value', $this->_params);
$untilClause = '';
if ($until) {
$untilClause = ' AND c.receive_date <="' . CRM_Utils_Type::validate(CRM_Utils_Date::processDate($until, 235959), 'Integer') . '"';
}
$this->_from .= " LEFT JOIN
(
SELECT CONCAT('p', p.id) as id, contact_id, campaign_id, financial_type_id,
COALESCE(amount, 0) as total_amount,
COALESCE(amount, 0) - COALESCE(cancelled_amount, 0) as total_amount,
currency,
COALESCE(paid_amount, 0) as paid_amount,
COALESCE(amount - paid_amount, 0) as balance_amount,
COALESCE(amount - paid_amount, 0) - COALESCE(cancelled_amount, 0) as balance_amount,
1 as is_pledge
FROM civicrm_pledge p
LEFT JOIN
(SELECT pledge_id, sum(if(status_id = 1";
if ($until) {
$this->_from .= ' AND c.receive_date <="' . CRM_Utils_Type::validate(CRM_Utils_Date::processDate($until, 235959), 'Integer') . '"';
}
$this->_from .= ", actual_amount, 0)) as paid_amount
(SELECT pledge_id,
sum(if(status_id = 1 $untilClause , actual_amount, 0)) as paid_amount,
sum(if(status_id = 3 $untilClause , scheduled_amount, 0)) as cancelled_amount
FROM civicrm_pledge_payment
LEFT JOIN civicrm_contribution c ON c.id = contribution_id
GROUP BY pledge_id
) as pp
ON pp.pledge_id = p.id
WHERE p.is_test = 0";
WHERE p.is_test = 0
";
if ($until) {
$this->_from .= ' AND p.create_date <="' . CRM_Utils_Type::validate(CRM_Utils_Date::processDate($until, 235959), 'Integer') . '"';
}
......@@ -174,13 +188,13 @@ LEFT JOIN
* @return string
*/
function selectClause(&$tableName, $tableKey, &$fieldName, &$field) {
if ($fieldName == 'still_to_raise') {
if ($fieldName == 'progress_still_to_raise') {
$alias = "{$tableName}_{$fieldName}";
$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, 0) - SUM(COALESCE(progress.total_amount, 0)) as $alias ";
$this->_selectAliases[$alias] = $alias;
return " COALESCE({$this->_aliases['civicrm_campaign']}.goal_revenue, 0) - SUM(COALESCE(progress.total_amount, 0)) as $alias ";
}
return parent::selectClause($tableName, $tableKey, $fieldName, $field);
}
......@@ -215,19 +229,19 @@ LEFT JOIN
$this->_columnHeaders['progress_still_to_raise'] = $move;
}
$runningTotalRaised = $runningTotalLeft = 0;
$grandTotalRaised = $grandTotalLeft = 0;
$runningTotalGoal = $runningTotalLeft = 0;
$grandTotalGoal = $grandTotalLeft = 0;
foreach ($rows as $index => $row) {
if (isset($row['civicrm_campaign_campaign_goal_revenue']) && is_numeric($row['civicrm_campaign_campaign_goal_revenue'])) {
$runningTotalRaised += $row['civicrm_campaign_campaign_goal_revenue'];
$runningTotalGoal += $row['civicrm_campaign_campaign_goal_revenue'];
$runningTotalLeft += $row['progress_still_to_raise'];
}
else {
$rows[$index]['civicrm_campaign_campaign_goal_revenue'] = $runningTotalRaised;
$rows[$index]['civicrm_campaign_campaign_goal_revenue'] = $runningTotalGoal;
$rows[$index]['progress_still_to_raise'] = $runningTotalLeft;
$grandTotalLeft += $runningTotalLeft;
$grandTotalRaised += $runningTotalRaised;
$runningTotalRaised = $runningTotalLeft = 0;
$grandTotalGoal += $runningTotalGoal;
$runningTotalGoal = $runningTotalLeft = 0;
foreach ($rows[$index] as $field => $value) {
if (is_numeric($value)) {
$rows[$index][$field] = '<span class="report-label">' . str_replace('$', '', CRM_Utils_Money::format($value)) . '</span>';
......@@ -236,8 +250,8 @@ LEFT JOIN
}
}
$this->rollupRow['civicrm_campaign_campaign_goal_revenue'] = $runningTotalRaised;
$this->rollupRow['progress_still_to_raise'] = $runningTotalLeft;
$this->rollupRow['civicrm_campaign_campaign_goal_revenue'] = $grandTotalGoal;
$this->rollupRow['progress_still_to_raise'] = $grandTotalLeft;
$this->assign('grandStat', $this->rollupRow);
}
......
......@@ -39,6 +39,19 @@ class CRM_Extendedreport_Form_Report_Case_CasePivot extends CRM_Extendedreport_F
$this->_columns['civicrm_case']['fields']['case_civireport_status_id']['no_display'] = TRUE;
$this->_columns['civicrm_case']['filters']['case_civireport_is_deleted']['default'] = 0;
$this->_columns['civicrm_case']['metadata']['case_civireport_id'] = array_merge(
['is_fields' => FALSE, 'is_filters' => FALSE, 'is_group_bys' => FALSE, 'is_order_bys' => FALSE, 'is_join_filters' => FALSE],
$this->_columns['civicrm_case']['fields']['case_civireport_id']
);
$this->_columns['civicrm_case']['metadata']['case_civireport_status_id'] = array_merge(
['is_fields' => FALSE, 'is_filters' => FALSE, 'is_group_bys' => FALSE, 'is_order_bys' => FALSE, 'is_join_filters' => FALSE],
$this->_columns['civicrm_case']['fields']['case_civireport_status_id']
);
$this->_columns['civicrm_case']['metadata']['case_civireport_is_deleted'] = array_merge(
['is_fields' => FALSE, 'is_filters' => FALSE, 'is_group_bys' => FALSE, 'is_order_bys' => FALSE, 'is_join_filters' => FALSE],
$this->_columns['civicrm_case']['filters']['case_civireport_is_deleted']
);
$this->_aggregateRowFields = array(
'case_civireport:id' => 'Case',
'case_civireport:status_id' => 'Case Status',
......
<?php
/**
* Created by IntelliJ IDEA.
* User: emcnaughton
* Date: 9/1/18
* Time: 1:05 AM
*/
/**
* Trait CRM_Extendedreport_Form_Report_ColumnDefinitionTrait
*
* This trait serves to organise the long getColumns functions into one function.
*
* It is for code organisation & may or may not make the most sense long term.
*/
trait CRM_Extendedreport_Form_Report_ColumnDefinitionTrait {
/*
* Function to get Activity Columns
* @param array $options column options
*/
/**
* @param array $options
*
* @return array
*/
function getActivityColumns($options = array()) {
$defaultOptions = array(
'prefix' => '',
'prefix_label' => '',
'fields' => TRUE,
'group_by' => FALSE,
'order_by' => TRUE,
'filters' => TRUE,
'fields_defaults' => array(),
'filters_defaults' => array(),
'group_bys_defaults' => array(),
'order_by_defaults' => array(),
);
$options = array_merge($defaultOptions, $options);
$defaults = $this->getDefaultsFromOptions($options);
$spec = array(
'id' => array(
'no_display' => TRUE,
'required' => TRUE,
'is_group_bys' => $options['group_by'],
),
'source_record_id' => array(
'no_display' => TRUE,
'required' => FALSE,
),
'activity_type_id' => array(
'title' => ts('Activity Type'),
'alter_display' => 'alterActivityType',
'is_fields' => TRUE,
'is_filters' => TRUE,
'is_order_bys' => TRUE,
'operatorType' => CRM_Report_Form::OP_MULTISELECT,
'options' => CRM_Core_PseudoConstant::activityType(TRUE, TRUE),
'name' => 'activity_type_id',
'type' => CRM_Utils_Type::T_INT,
),
'subject' => array(
'title' => ts('Subject'),
'name' => 'subject',
'is_fields' => TRUE,
'is_filters' => TRUE,
'crm_editable' => array(
'id_table' => 'civicrm_activity',
'id_field' => 'id',
'entity' => 'activity',
),
),
'activity_date_time' => array(
'title' => ts('Activity Date'),
'default' => TRUE,
'name' => 'activity_date_time',
'operatorType' => CRM_Report_Form::OP_DATE,
'type' => CRM_Utils_Type::T_DATE,
'is_fields' => TRUE,
'is_filters' => TRUE,
'is_order_bys' => TRUE,
),
'status_id' => array(
'title' => ts('Activity Status'),
'name' => 'status_id',
'type' => CRM_Utils_Type::T_STRING,
'alter_display' => 'alterPseudoConstant',
'is_fields' => TRUE,
'is_filters' => TRUE,
'is_order_bys' => TRUE,
'operatorType' => CRM_Report_Form::OP_MULTISELECT,
'options' => CRM_Core_PseudoConstant::activityStatus(),
'crm_editable' => array(
'id_table' => 'civicrm_activity',
'id_field' => 'id',
'entity' => 'activity',
'options' => $this->_getOptions('activity', 'activity_status_id'),
),
),
'duration' => array(
'title' => ts('Duration (sum for all contacts)'),
'type' => CRM_Utils_Type::T_INT,
'statistics' => array(
'sum' => ts('Total Duration')
),
'is_fields' => TRUE,
),
'duration_each' => array(
'title' => ts('Duration (for each contact)'),
'name' => 'duration',
'type' => CRM_Utils_Type::T_INT,
'is_fields' => TRUE,
),
'details' => array(
'title' => ts('Activity Details'),
'is_fields' => TRUE,
'is_filters' => TRUE,
'type' => CRM_Utils_Type::T_TEXT,
'crm_editable' => array(
'id_table' => 'civicrm_activity',
'id_field' => 'id',
'entity' => 'activity',
),
),
'result' => array(
'title' => ts('Activity Result'),
'is_fields' => TRUE,
'is_filters' => TRUE,
'type' => CRM_Utils_Type::T_TEXT,
'crm_editable' => array(
'id_table' => 'civicrm_activity',
'id_field' => 'id',
'entity' => 'activity',
),
),
'is_current_revision' => array(
'type' => CRM_Report_Form::OP_INT,
'operatorType' => CRM_Report_Form::OP_SELECT,
'title' => ts("Current Revision"),
'name' => 'is_current_revision',
'options' => array('1' => 'Yes', '0' => 'No',),
'is_filters' => TRUE,
),
'is_deleted' => array(
'type' => CRM_Report_Form::OP_INT,
'operatorType' => CRM_Report_Form::OP_SELECT,
'title' => ts("Is activity deleted"),
'name' => 'is_deleted',
'options' => array('0' => 'No', '1' => 'Yes',),
'is_filters' => TRUE,
),
);
return $this->buildColumns($spec, $options['prefix'] . 'civicrm_activity', 'CRM_Activity_DAO_Activity', NULL, $defaults, $options);
}
/**
* Get columns for Case.
*
* @param $options
*
* @return array
*/
function getCaseColumns($options) {
$config = CRM_Core_Config::singleton();
if (!in_array('CiviCase', $config->enableComponents)) {
return array('civicrm_case' => array('fields' => array(), 'metadata' => array()));
}
$spec = array(
'civicrm_case' => array(
'fields' => array(
'id' => array(
'title' => ts('Case ID'),
'name' => 'id',
'is_fields' => TRUE,
),
'subject' => array(
'title' => ts('Case Subject'),
'default' => TRUE,
'is_fields' => TRUE,
'is_filters' => TRUE,
),
'status_id' => array(
'title' => ts('Case Status'),
'default' => TRUE,
'name' => 'status_id',
'is_fields' => TRUE,
'is_filters' => TRUE,
'operatorType' => CRM_Report_Form::OP_MULTISELECT,
'options' => CRM_Case_BAO_Case::buildOptions('case_status_id'),
'type' => CRM_Utils_Type::T_INT,
),
'case_type_id' => array(
'title' => ts('Case Type'),
'is_fields' => TRUE,