From 246b5b63b70da2c5b88a5adff59ecbdd31bf6e7e Mon Sep 17 00:00:00 2001 From: Saurabh Batra Date: Fri, 4 Mar 2016 00:23:37 +0530 Subject: [PATCH] CRM-17602 - https://issues.civicrm.org/jira/browse/CRM-17602 --- CRM/Contribute/BAO/Query.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/CRM/Contribute/BAO/Query.php b/CRM/Contribute/BAO/Query.php index 1b6d4cac2b..2bc9dcb0d3 100644 --- a/CRM/Contribute/BAO/Query.php +++ b/CRM/Contribute/BAO/Query.php @@ -1019,6 +1019,7 @@ class CRM_Contribute_BAO_Query { $form->addElement('text', 'contribution_source', ts('Contribution Source'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Contribution', 'source')); CRM_Core_Form_Date::buildDateRange($form, 'contribution_date', 1, '_low', '_high', ts('From:'), FALSE); + $form->addFormRule(array('CRM_Contribute_BAO_Query', 'formRule'), $form); $form->add('text', 'contribution_amount_low', ts('From'), array('size' => 8, 'maxlength' => 8)); $form->addRule('contribution_amount_low', ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money::format('9.99', ' '))), 'money'); @@ -1197,4 +1198,30 @@ class CRM_Contribute_BAO_Query { return TRUE; } + /** + * Check if the values in the date range are in correct chronological order. + * + * @param array $fields + * @param array $files + * @param CRM_Core_Form $form + * + * @return bool|array + */ + public static function formRule($fields, $files, $form) { + $errors = array(); + + if (empty($fields['contribution_date_high']) || empty($fields['contribution_date_low'])) { + return TRUE; + } + $lowDate = strtotime($fields['contribution_date_low']); + $highDate = strtotime($fields['contribution_date_high']); + + if ($lowDate > $highDate) { + $errors['contribution_date'] = ts('Please check your Contribution Date Range.'); + // remove this after errors starts working. + echo ts('Please check your Contribution Date Range.'); + } + return empty($errors) ? TRUE : $errors; + } + } -- 2.25.1