diff --git a/CRM/Extendedreport/Form/Report/Campaign/CampaignProgressReport.php b/CRM/Extendedreport/Form/Report/Campaign/CampaignProgressReport.php index 42c0ab81..649cb83f 100644 --- a/CRM/Extendedreport/Form/Report/Campaign/CampaignProgressReport.php +++ b/CRM/Extendedreport/Form/Report/Campaign/CampaignProgressReport.php @@ -57,6 +57,14 @@ public function __construct() { '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, + ) + ), ), ); @@ -103,6 +111,7 @@ function from() { * Join on a progress summary. */ protected function joinProgressTable() { + $until = CRM_Utils_Array::value('effective_date_value', $this->_params); $this->_from .= " LEFT JOIN ( @@ -120,18 +129,27 @@ protected function joinProgressTable() { GROUP BY pledge_id ) as pp ON pp.pledge_id = p.id - WHERE p.is_test = 0 - UNION + WHERE p.is_test = 0"; + if ($until) { + $this->_from .= ' AND p.create_date <="' . CRM_Utils_Type::validate(CRM_Utils_Date::processDate($until), 'Integer') . '"'; + } + + $this->_from .= " UNION SELECT CONCAT('c', c.id) as id, contact_id, campaign_id, financial_type_id, COALESCE(total_amount, 0) as total_amount, c.currency, COALESCE(total_amount, 0) as paid_amount, 0 as balance_amount, 0 as is_pledge - FROM civicrm_contribution c LEFT JOIN civicrm_pledge_payment pp ON pp.contribution_id = c.id + FROM civicrm_contribution c + LEFT JOIN civicrm_pledge_payment pp ON pp.contribution_id = c.id WHERE c.contribution_status_id = 1 - AND pp.id IS NULL - ) as progress ON progress.campaign_id = campaign.id + AND pp.id IS NULL "; + if ($until) { + $this->_from .= ' AND c.receive_date <= "' . CRM_Utils_Type::validate(CRM_Utils_Date::processDate($until), 'Integer') . '"'; + } + + $this->_from .= ") as progress ON progress.campaign_id = campaign.id "; } @@ -213,4 +231,23 @@ function alterDisplay(&$rows) { $this->assign('grandStat', $this->rollupRow); } + + /** + * Note: $fieldName param allows inheriting class to build operationPairs + * specific to a field. + * + * @param string $type + * @param null $fieldName + * + * @return array + */ + function getOperationPair($type = "string", $fieldName = NULL) { + if ($type == self::OP_SINGLEDATE) { + return array( + 'to' => ts('Until Date'), + ); + } + return parent::getOperationPair($type, $fieldName); + } + }