diff --git a/admin-dev/themes/default/template/helpers/calendar/calendar.tpl b/admin-dev/themes/default/template/helpers/calendar/calendar.tpl
index 0f0b375c8..b0591142d 100644
--- a/admin-dev/themes/default/template/helpers/calendar/calendar.tpl
+++ b/admin-dev/themes/default/template/helpers/calendar/calendar.tpl
@@ -49,17 +49,17 @@
+
@@ -152,10 +152,12 @@
function setPreviousPeriod() {
startDate = parseDate($("#date-start").val(), parseFormat('{$date_format}'));
+ startDate = startDate.setDate(startDate.getDate()-1);
endDate = parseDate($("#date-end").val(), parseFormat('{$date_format}'));
- diff = endDate.getTime() - startDate.getTime();
- startDateCompare = startDate.getTime()-diff;
- $("#date-end-compare").val($("#date-start").val());
+ endDate = endDate.setDate(endDate.getDate()-1);
+ diff = endDate - startDate;
+ startDateCompare = startDate-diff;
+ $("#date-end-compare").val(formatDate(new Date(startDate), parseFormat('{$date_format}')));
$("#date-start-compare").val(formatDate(new Date(startDateCompare), parseFormat('{$date_format}')));
}
@@ -238,6 +240,9 @@
$('#datepicker-compare').click(function() {
if ($(this).attr("checked")) {
+ if ($("#date-start-compare").val().replace(/^\s+|\s+$/g, '').length == 0)
+ $('#compare-options').trigger('change');
+
datepickerStart.setStartCompare($("#date-start-compare").val());
datepickerStart.setEndCompare($("#date-end-compare").val());
datepickerEnd.setStartCompare($("#date-start-compare").val());
@@ -266,6 +271,18 @@
$('#date-start-compare').focus();
});
+ if ($('#datepicker-compare').attr("checked"))
+ {
+ if ($("#date-start-compare").val().replace(/^\s+|\s+$/g, '').length == 0)
+ $('#compare-options').trigger('change');
+
+ datepickerStart.setStartCompare($("#date-start-compare").val());
+ datepickerStart.setEndCompare($("#date-end-compare").val());
+ datepickerEnd.setStartCompare($("#date-start-compare").val());
+ datepickerEnd.setEndCompare($("#date-end-compare").val());
+ datepickerStart.setCompare(true);
+ datepickerEnd.setCompare(true);
+ }
{/literal}
});
\ No newline at end of file
diff --git a/classes/Employee.php b/classes/Employee.php
index 22101b92d..b09e4449c 100644
--- a/classes/Employee.php
+++ b/classes/Employee.php
@@ -135,16 +135,16 @@ class EmployeeCore extends ObjectModel
public function getFields()
{
if (empty($this->stats_date_from))
- $this->stats_date_from = date('Y-m-d 00:00:00');
+ $this->stats_date_from = date('Y-m-d 00:00:00', strtotime("-1 month"));
- if (empty($this->stats_compare_from))
- $this->stats_compare_from = date('Y-m-d 00:00:00');
+ if (empty($this->stats_compare_from) || $this->stats_compare_from == '0000-00-00')
+ $this->stats_compare_from = null;
if (empty($this->stats_date_to))
$this->stats_date_to = date('Y-m-d 23:59:59');
- if (empty($this->stats_compare_to))
- $this->stats_compare_to = date('Y-m-d 00:00:00');
+ if (empty($this->stats_compare_to) || $this->stats_compare_to == '0000-00-00')
+ $this->stats_compare_to = null;
return parent::getFields();
}
diff --git a/classes/helper/HelperCalendar.php b/classes/helper/HelperCalendar.php
index 560d4c520..cce35608e 100644
--- a/classes/helper/HelperCalendar.php
+++ b/classes/helper/HelperCalendar.php
@@ -26,7 +26,8 @@
class HelperCalendarCore extends Helper
{
- const DEFAULT_DATE_FORMAT = 'Y-m-d';
+ const DEFAULT_DATE_FORMAT = 'Y-m-d';
+ const DEFAULT_COMPARE_OPTION = 1;
private $_actions;
private $_compare_actions;
@@ -81,41 +82,23 @@ class HelperCalendarCore extends Helper
public function setCompareDateFrom($value)
{
- if (!isset($value) || $value == '')
- $value = date('Y-m-d', strtotime("-31 days"));
-
- if (!is_string($value))
- throw new PrestaShopException('Date must be a string');
-
$this->_compare_date_from = $value;
return $this;
}
public function getCompareDateFrom()
{
- if (!isset($this->_compare_date_from))
- $this->_compare_date_from = date('Y-m-d', strtotime("-31 days"));
-
return $this->_compare_date_from;
}
public function setCompareDateTo($value)
{
- if (!isset($value) || $value == '')
- $value = date('Y-m-d');
-
- if (!is_string($value))
- throw new PrestaShopException('Date must be a string');
-
$this->_compare_date_to = $value;
return $this;
}
public function getCompareDateTo()
{
- if (!isset($this->_compare_date_to))
- $this->_compare_date_to = date('Y-m-d');
-
return $this->_compare_date_to;
}
diff --git a/controllers/admin/AdminDashboardController.php b/controllers/admin/AdminDashboardController.php
index 0376cf11a..db72a5ddc 100644
--- a/controllers/admin/AdminDashboardController.php
+++ b/controllers/admin/AdminDashboardController.php
@@ -152,10 +152,21 @@ class AdminDashboardControllerCore extends AdminController
);
$calendar_helper = new HelperCalendar();
+
$calendar_helper->setDateFrom(Tools::getValue('date_from', $this->context->employee->stats_date_from));
$calendar_helper->setDateTo(Tools::getValue('date_to', $this->context->employee->stats_date_to));
- $calendar_helper->setCompareDateFrom(Tools::getValue('compare_date_from', $this->context->employee->stats_compare_from));
- $calendar_helper->setCompareDateTo(Tools::getValue('compare_date_to', $this->context->employee->stats_compare_to));
+
+ $stats_compare_from = $this->context->employee->stats_compare_from;
+ $stats_compare_to = $this->context->employee->stats_compare_to;
+
+ if (is_null($stats_compare_from) || $stats_compare_from == '0000-00-00')
+ $stats_compare_from = null;
+
+ if (is_null($stats_compare_to) || $stats_compare_to == '0000-00-00')
+ $stats_compare_to = null;
+
+ $calendar_helper->setCompareDateFrom($stats_compare_from);
+ $calendar_helper->setCompareDateTo($stats_compare_to);
$calendar_helper->setCompareOption(Tools::getValue('compare_date_option', $this->context->employee->stats_compare_option));
$this->tpl_view_vars = array(
@@ -179,9 +190,20 @@ class AdminDashboardControllerCore extends AdminController
{
$this->context->employee->stats_date_from = Tools::getValue('date_from');
$this->context->employee->stats_date_to = Tools::getValue('date_to');
- $this->context->employee->stats_compare_from = Tools::getValue('compare_date_from');
- $this->context->employee->stats_compare_to = Tools::getValue('compare_date_to');
- $this->context->employee->stats_compare_option = Tools::getValue('compare_date_option');
+
+ if (Tools::getValue('datepicker_compare'))
+ {
+ $this->context->employee->stats_compare_from = Tools::getValue('compare_date_from');
+ $this->context->employee->stats_compare_to = Tools::getValue('compare_date_to');
+ $this->context->employee->stats_compare_option = Tools::getValue('compare_date_option');
+ }
+ else
+ {
+ $this->context->employee->stats_compare_from = null;
+ $this->context->employee->stats_compare_to = null;
+ $this->context->employee->stats_compare_option = HelperCalendar::DEFAULT_COMPARE_OPTION;
+ }
+
$this->context->employee->update();
}
diff --git a/install-dev/models/install.php b/install-dev/models/install.php
index a71de5a07..189189485 100644
--- a/install-dev/models/install.php
+++ b/install-dev/models/install.php
@@ -464,10 +464,6 @@ class InstallModelInstall extends InstallAbstractModel
$employee->bo_theme = 'default';
$employee->default_tab = 1;
$employee->active = true;
- $employee->stats_date_from = date('Y').'-01-01';
- $employee->stats_date_to = date('Y').'-12-31';
- $employee->stats_compare_from = date('Y').'-01-01';
- $employee->stats_compare_to = date('Y').'-12-31';
$employee->id_profile = 1;
$employee->id_lang = Configuration::get('PS_LANG_DEFAULT');
$employee->bo_menu = 1;