From c4f0bf3fc693ff569a25e585c8755538db901bb3 Mon Sep 17 00:00:00 2001 From: Vangelis Pantazis Date: Thu, 24 Oct 2019 12:36:14 +0100 Subject: [PATCH] Rework on the relative and absolute dates --- .../Search/Custom/ContributionAggregate.php | 31 ++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/CRM/Contact/Form/Search/Custom/ContributionAggregate.php b/CRM/Contact/Form/Search/Custom/ContributionAggregate.php index 5437e0d2a0..38f0ec55f7 100644 --- a/CRM/Contact/Form/Search/Custom/ContributionAggregate.php +++ b/CRM/Contact/Form/Search/Custom/ContributionAggregate.php @@ -226,20 +226,29 @@ civicrm_contact AS contact_a {$this->_aclFrom} ); } - foreach (CRM_Contact_BAO_Query::convertFormValues($dateParams) as $values) { - list($name, $op, $value) = $values; - if (strstr($name, '_low')) { - if (strlen($value) == 10) { - $value .= ' 00:00:00'; - } - $clauses[] = "contrib.receive_date >= '{$value}'"; + if ($dateParams['receive_date_relative']) { + list($relativeFrom, $relativeTo) = CRM_Utils_Date::getFromTo($dateParams['receive_date_relative'], $dateParams['receive_date_low'], $dateParams['receive_date_high']); + } + else { + if (strlen($dateParams['receive_date_low']) == 10) { + $relativeFrom = $dateParams['receive_date_low'] . ' 00:00:00'; } else { - if (strlen($value) == 10) { - $value .= ' 23:59:59'; - } - $clauses[] = "contrib.receive_date <= '{$value}'"; + $relativeFrom = $dateParams['receive_date_low']; + } + if (strlen($dateParams['receive_date_high']) == 10) { + $relativeTo = $dateParams['receive_date_high'] . ' 23:59:59'; } + else { + $relativeTo = $dateParams['receive_date_high']; + } + } + + if ($relativeFrom) { + $clauses[] = "contrib.receive_date >= '{$relativeFrom}'"; + } + if ($relativeTo) { + $clauses[] = "contrib.receive_date <= '{$relativeTo}'"; } if ($includeContactIDs) { -- 2.25.1