From c5670e9ec0ed4b200a00594b186e6d94390b6456 Mon Sep 17 00:00:00 2001 From: atif-shaikh Date: Mon, 10 Nov 2014 17:51:39 +0530 Subject: [PATCH] CRM-14550 Fix - Future date selection in reports https://issues.civicrm.org/jira/browse/CRM-14550 --- CRM/Core/Form/Date.php | 67 ++++++++++++++------- CRM/Utils/Date.php | 129 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 175 insertions(+), 21 deletions(-) diff --git a/CRM/Core/Form/Date.php b/CRM/Core/Form/Date.php index 35506218f0..8ec898fe4e 100644 --- a/CRM/Core/Form/Date.php +++ b/CRM/Core/Form/Date.php @@ -136,52 +136,77 @@ Class CRM_Core_Form_Date { array( '' => ts('- any -'), 0 => ts('Choose Date Range'), - 'this.year' => ts('This Year'), - 'this.fiscal_year' => ts('This Fiscal Year'), - 'this.quarter' => ts('This Quarter'), - 'this.month' => ts('This Month'), - 'this.week' => ts('This Week'), - 'this.day' => ts('This Day'), - 'previous.year' => ts('Previous Year'), - 'previous.fiscal_year' => ts('Previous Fiscal Year'), - 'previous.quarter' => ts('Previous Quarter'), - 'previous.month' => ts('Previous Month'), - 'previous.week' => ts('Previous Week'), - 'previous.day' => ts('Previous Day'), - 'previous_before.year' => ts('Prior to Previous Year'), - 'previous_before.quarter' => ts('Prior to Previous Quarter'), - 'previous_before.month' => ts('Prior to Previous Month'), - 'previous_before.week' => ts('Prior to Previous Week'), - 'previous_before.day' => ts('Prior to Previous Day'), 'previous_2.year' => ts('Previous 2 Years'), 'previous_2.quarter' => ts('Previous 2 Quarters'), 'previous_2.month' => ts('Previous 2 Months'), 'previous_2.week' => ts('Previous 2 Weeks'), 'previous_2.day' => ts('Previous 2 Days'), + + 'previous_before.year' => ts('Prior to Previous Year'), + 'previous_before.quarter' => ts('Prior to Previous Quarter'), + 'previous_before.month' => ts('Prior to Previous Month'), + 'previous_before.week' => ts('Prior to Previous Week'), + 'previous_before.day' => ts('Prior to Previous Day'), + + 'previous.year' => ts('Previous Year'), + 'previous.fiscal_year' => ts('Previous Fiscal Year'), + 'previous.quarter' => ts('Previous Quarter'), + 'previous.month' => ts('Previous Month'), + 'previous.week' => ts('Previous Week'), + 'earlier.year' => ts('To End of Previous Year'), 'earlier.quarter' => ts('To End of Previous Quarter'), 'earlier.month' => ts('To End of Previous Month'), 'earlier.week' => ts('To End of Previous Week'), 'earlier.day' => ts('To End of Previous Day'), + + 'greater_previous.year' => ts('From End of Previous Year'), + 'greater_previous.quarter' => ts('From End of Previous Quarter'), + 'greater_previous.month' => ts('From End of Previous Month'), + 'greater_previous.week' => ts('From End of Previous Week'), + 'greater.year' => ts('From Start of Current Year'), 'greater.quarter' => ts('From Start of Current Quarter'), 'greater.month' => ts('From Start of Current Month'), 'greater.week' => ts('From Start of Current Week'), 'greater.day' => ts('From Start of Current Day'), - 'greater_previous.year' => ts('From End of Previous Year'), - 'greater_previous.quarter' => ts('From End of Previous Quarter'), - 'greater_previous.month' => ts('From End of Previous Month'), - 'greater_previous.week' => ts('From End of Previous Week'), + 'current.year' => ts('Current Year to-date'), 'current.quarter' => ts('Current Quarter to-date'), 'current.month' => ts('Current Month to-date'), 'current.week' => ts('Current Week to-date'), + 'ending_3.year' => ts('Last 3 Years'), 'ending_2.year' => ts('Last 2 Years'), 'ending.year' => ts('Last 12 Months'), 'ending.quarter' => ts('Last 3 Months'), 'ending.month' => ts('Last Month'), 'ending.week' => ts('Last 7 days'), + 'previous.day' => ts('Yesterday'), + + 'this.year' => ts('This Year'), + 'this.fiscal_year' => ts('This Fiscal Year'), + 'this.quarter' => ts('This Quarter'), + 'this.month' => ts('This Month'), + 'this.week' => ts('This Week'), + 'this.day' => ts('Today'), + + 'starting.day' => ts('Tomorrow'), + 'starting.week' => ts('Upcoming 7 days'), + 'starting.month' => ts('Upcoming Month'), + 'starting.year' => ts('Upcoming 12 Months'), + + 'less.year' => ts('To End of Current Year'), + 'less.quarter' => ts('To End of Current Quarter'), + 'less.month' => ts('To End of Current Month'), + 'less.week' => ts('To End of Current Week'), + + 'next.week' => ts('Next Week'), + 'next.month' => ts('Next Month'), + 'next.quarter' => ts('Next Quarter'), + 'next.fiscal_year' => ts('Next Fiscal Year'), + 'next.year' => ts('Next Year'), + ); if (is_array($operators)) { diff --git a/CRM/Utils/Date.php b/CRM/Utils/Date.php index 883f72bb28..55cbbe9340 100644 --- a/CRM/Utils/Date.php +++ b/CRM/Utils/Date.php @@ -1047,6 +1047,29 @@ class CRM_Utils_Date { $from = self::intervalAdd('year', -3, $to); $from = self::intervalAdd('second', 1, $from); break; + + case 'less': + $to['d'] = 31; + $to['M'] = 12; + $to['Y'] = $now['year']; + unset($from); + break; + + case 'next': + $from['M'] = $from['d'] = 1; + $to['d'] = 31; + $to['M'] = 12; + $to['Y'] = $from['Y'] = $now['year'] + 1; + break; + + case 'starting': + $from['d'] = $now['mday']; + $from['M'] = $now['mon']; + $from['Y'] = $now['year']; + $to['d'] = $now['mday'] - 1; + $to['M'] = $now['mon']; + $to['Y'] = $now['year'] + 1; + break; } break; @@ -1070,7 +1093,15 @@ class CRM_Utils_Date { $from['Y'] = $fYear - 1; $fiscalYear = mktime(0, 0, 0, $from['M'], $form['d'], $from['Y'] + 1); $fiscalEnd = explode('-', date("Y-m-d", $fiscalYear)); + $to['d'] = $fiscalEnd['2']; + $to['M'] = $fiscalEnd['1']; + $to['Y'] = $fiscalEnd['0']; + break; + case 'next': + $from['Y'] = $fYear + 1; + $fiscalYear = mktime(0, 0, 0, $from['M'], $from['d'], $from['Y'] + 1); + $fiscalEnd = explode('-', date("Y-m-d", $fiscalYear)); $to['d'] = $fiscalEnd['2']; $to['M'] = $fiscalEnd['1']; $to['Y'] = $fiscalEnd['0']; @@ -1214,6 +1245,35 @@ class CRM_Utils_Date { $to['H'] = 23; $to['i'] = $to['s'] = 59; break; + + case 'less': + $quarter = ceil($now['mon'] / 3); + $to['M'] = 3 * $quarter; + $to['Y'] = $now['year']; + $to['d'] = date('t', mktime(0, 0, 0, $to['M'], 1, $now['year'])); + unset($from); + break; + + case 'next': + $difference = -1; + $subtractYear = 0; + $quarter = ceil($now['mon'] / 3); + $quarter = $quarter - $difference; + //CRM-14550 QA Fix + if($quarter > 4) { + $now['year'] = $now['year'] + 1; + $quarter = 1; + } + if ($quarter <= 0) { + $subtractYear = 1; + $quarter += 4; + } + $from['d'] = 1; + $from['M'] = (3 * $quarter) - 2; + $to['M'] = 3 * $quarter; + $to['Y'] = $from['Y'] = $now['year'] - $subtractYear; + $to['d'] = date('t', mktime(0, 0, 0, $to['M'], 1, $to['Y'])); + break; } break; @@ -1332,6 +1392,37 @@ class CRM_Utils_Date { $to['H'] = 23; $to['i'] = $to['s'] = 59; break; + + case 'less': + //CRM-14550 QA Fix + $to['Y'] = $now['year']; + $to['M'] = $now['mon']; + $to['d'] = date('t', mktime(0, 0, 0, $now['mon'], 1, $now['year'])); + unset($from); + break; + + case 'next': + $from['d'] = 1; + if ($now['mon'] == 12) { + $from['M'] = $to['M'] = 1; + $from['Y'] = $to['Y'] = $now['year'] + 1; + } + else { + $from['M'] = $to['M'] = $now['mon'] + 1; + $from['Y'] = $to['Y'] = $now['year']; + } + $to['d'] = date('t', mktime(0, 0, 0, $to['M'], 1, $to['Y'])); + break; + + case 'starting': + $from['d'] = $now['mday']; + $from['M'] = $now['mon']; + $from['Y'] = $now['year']; + $from['H'] = 00; + $from['i'] = $to['s'] = 00; + $to = self::intervalAdd('month', +1, $from); + $to = self::intervalAdd('second',-1, $to); + break; } break; @@ -1414,6 +1505,33 @@ class CRM_Utils_Date { $to['H'] = 23; $to['i'] = $to['s'] = 59; break; + + case 'less': + $to['d'] = $now['mday']; + $to['M'] = $now['mon']; + $to['Y'] = $now['year']; + //CRM-14550 QA Fix + $to = self::intervalAdd('day', -1 * ($now['wday']) + 6, $to); + unset($from); + break; + + case 'next': + $from['d'] = $now['mday']; + $from['M'] = $now['mon']; + $from['Y'] = $now['year']; + $from = self::intervalAdd('day', -1 * ($now['wday']) + 7, $from); + $to = self::intervalAdd('day', +6, $from); + break; + + case 'starting': + $from['d'] = $now['mday']; + $from['M'] = $now['mon']; + $from['Y'] = $now['year']; + $from['H'] = 00; + $from['i'] = $to['s'] = 00; + $to = self::intervalAdd('day', +7, $from); + $to = self::intervalAdd('second', -1, $to); + break; } break; @@ -1466,6 +1584,17 @@ class CRM_Utils_Date { $from['Y'] = $now['year']; unset($to); break; + + case 'starting': + $to['d'] = $now['mday']; + $to['M'] = $now['mon']; + $to['Y'] = $now['year']; + $to = self::intervalAdd('day', +1, $to); + $from['d'] = $to['d']; + $from['M'] = $to['M']; + $from['Y'] = $to['Y']; + break; + } break; } -- 2.25.1