diff --git a/admin-dev/themes/default/template/helpers/calendar/calendar.tpl b/admin-dev/themes/default/template/helpers/calendar/calendar.tpl
index ceaaebbfb..7bd22ef9c 100644
--- a/admin-dev/themes/default/template/helpers/calendar/calendar.tpl
+++ b/admin-dev/themes/default/template/helpers/calendar/calendar.tpl
@@ -51,21 +51,11 @@
{l s='Compare to'}
-
-
+
@@ -251,6 +241,7 @@
datepickerEnd.setStartCompare($("#date-start-compare").val());
datepickerEnd.setEndCompare($("#date-end-compare").val());
$('#form-date-body-compare').show();
+ $('#compare-options').prop('disabled', false);
$('#date-start-compare').focus();
} else {
datepickerStart.setStartCompare(null);
@@ -258,10 +249,21 @@
datepickerEnd.setStartCompare(null);
datepickerEnd.setEndCompare(null);
$('#form-date-body-compare').hide();
+ $('#compare-options').prop('disabled', true);
$('#date-start').focus();
}
})
+ $('#compare-options').change(function() {
+ if (this.value == 1)
+ setPreviousPeriod();
+
+ if (this.value == 2)
+ setPreviousYear();
+
+ $('#date-start-compare').focus();
+ });
+
{/literal}
});
\ No newline at end of file
diff --git a/classes/Employee.php b/classes/Employee.php
index 74cf28dc2..22101b92d 100644
--- a/classes/Employee.php
+++ b/classes/Employee.php
@@ -54,6 +54,7 @@ class EmployeeCore extends ObjectModel
public $stats_compare_from;
public $stats_compare_to;
+ public $stats_compare_option = 1;
/** @var string Display back office background in the specified color */
public $bo_color;
@@ -84,23 +85,24 @@ class EmployeeCore extends ObjectModel
'table' => 'employee',
'primary' => 'id_employee',
'fields' => array(
- 'lastname' => array('type' => self::TYPE_STRING, 'validate' => 'isName', 'required' => true, 'size' => 32),
- 'firstname' => array('type' => self::TYPE_STRING, 'validate' => 'isName', 'required' => true, 'size' => 32),
- 'email' => array('type' => self::TYPE_STRING, 'validate' => 'isEmail', 'required' => true, 'size' => 128),
- 'id_lang' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt', 'required' => true),
- 'passwd' => array('type' => self::TYPE_STRING, 'validate' => 'isPasswdAdmin', 'required' => true, 'size' => 32),
- 'last_passwd_gen' => array('type' => self::TYPE_STRING),
- 'active' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
- 'id_profile' => array('type' => self::TYPE_INT, 'validate' => 'isInt', 'required' => true),
- 'bo_color' => array('type' => self::TYPE_STRING, 'validate' => 'isColor', 'size' => 32),
- 'default_tab' => array('type' => self::TYPE_INT, 'validate' => 'isInt'),
- 'bo_theme' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'size' => 32),
- 'bo_width' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
- 'bo_menu' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
- 'stats_date_from' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
- 'stats_date_to' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
- 'stats_compare_from' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
- 'stats_compare_to' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
+ 'lastname' => array('type' => self::TYPE_STRING, 'validate' => 'isName', 'required' => true, 'size' => 32),
+ 'firstname' => array('type' => self::TYPE_STRING, 'validate' => 'isName', 'required' => true, 'size' => 32),
+ 'email' => array('type' => self::TYPE_STRING, 'validate' => 'isEmail', 'required' => true, 'size' => 128),
+ 'id_lang' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt', 'required' => true),
+ 'passwd' => array('type' => self::TYPE_STRING, 'validate' => 'isPasswdAdmin', 'required' => true, 'size' => 32),
+ 'last_passwd_gen' => array('type' => self::TYPE_STRING),
+ 'active' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
+ 'id_profile' => array('type' => self::TYPE_INT, 'validate' => 'isInt', 'required' => true),
+ 'bo_color' => array('type' => self::TYPE_STRING, 'validate' => 'isColor', 'size' => 32),
+ 'default_tab' => array('type' => self::TYPE_INT, 'validate' => 'isInt'),
+ 'bo_theme' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'size' => 32),
+ 'bo_width' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
+ 'bo_menu' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
+ 'stats_date_from' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
+ 'stats_date_to' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
+ 'stats_compare_from' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
+ 'stats_compare_to' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
+ 'stats_compare_option' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
),
);
diff --git a/classes/helper/HelperCalendar.php b/classes/helper/HelperCalendar.php
index 3d6919b3d..560d4c520 100644
--- a/classes/helper/HelperCalendar.php
+++ b/classes/helper/HelperCalendar.php
@@ -32,6 +32,7 @@ class HelperCalendarCore extends Helper
private $_compare_actions;
private $_compare_date_from;
private $_compare_date_to;
+ private $_compare_date_option;
private $_date_format;
private $_date_from;
private $_date_to;
@@ -84,7 +85,7 @@ class HelperCalendarCore extends Helper
$value = date('Y-m-d', strtotime("-31 days"));
if (!is_string($value))
- throw new PrestaShopException('Date must be string');
+ throw new PrestaShopException('Date must be a string');
$this->_compare_date_from = $value;
return $this;
@@ -104,7 +105,7 @@ class HelperCalendarCore extends Helper
$value = date('Y-m-d');
if (!is_string($value))
- throw new PrestaShopException('Date must be string');
+ throw new PrestaShopException('Date must be a string');
$this->_compare_date_to = $value;
return $this;
@@ -118,10 +119,24 @@ class HelperCalendarCore extends Helper
return $this->_compare_date_to;
}
+ public function setCompareOption($value)
+ {
+ $this->_compare_date_option = (int)$value;
+ return $this;
+ }
+
+ public function getCompareOption()
+ {
+ if (!isset($this->_compare_date_option))
+ $this->_compare_date_option = self::DEFAULT_COMPARE_OPTION;
+
+ return $this->_compare_date_option;
+ }
+
public function setDateFormat($value)
{
if (!is_string($value))
- throw new PrestaShopException('Date format must be string');
+ throw new PrestaShopException('Date format must be a string');
$this->_date_format = $value;
return $this;
@@ -141,7 +156,7 @@ class HelperCalendarCore extends Helper
$value = date('Y-m-d', strtotime("-31 days"));
if (!is_string($value))
- throw new PrestaShopException('Date must be string');
+ throw new PrestaShopException('Date must be a string');
$this->_date_from = $value;
return $this;
@@ -161,7 +176,7 @@ class HelperCalendarCore extends Helper
$value = date('Y-m-d');
if (!is_string($value))
- throw new PrestaShopException('Date must be string');
+ throw new PrestaShopException('Date must be a string');
$this->_date_to = $value;
return $this;
@@ -232,6 +247,7 @@ class HelperCalendarCore extends Helper
'compare_date_to' => $this->getCompareDateTo(),
'actions' => $this->getActions(),
'compare_actions' => $this->getCompareActions(),
+ 'compare_option' => $this->getCompareOption(),
'is_rtl' => $this->isRTL()
));
diff --git a/controllers/admin/AdminDashboardController.php b/controllers/admin/AdminDashboardController.php
index 3fc3f2a76..0376cf11a 100644
--- a/controllers/admin/AdminDashboardController.php
+++ b/controllers/admin/AdminDashboardController.php
@@ -156,6 +156,7 @@ class AdminDashboardControllerCore extends AdminController
$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));
+ $calendar_helper->setCompareOption(Tools::getValue('compare_date_option', $this->context->employee->stats_compare_option));
$this->tpl_view_vars = array(
'hookDashboardZoneOne' => Hook::exec('dashboardZoneOne'),
@@ -180,6 +181,7 @@ class AdminDashboardControllerCore extends AdminController
$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');
$this->context->employee->update();
}
diff --git a/install-dev/data/db_structure.sql b/install-dev/data/db_structure.sql
index 494604e32..2908ca542 100644
--- a/install-dev/data/db_structure.sql
+++ b/install-dev/data/db_structure.sql
@@ -722,6 +722,7 @@ CREATE TABLE `PREFIX_employee` (
`stats_date_to` date default NULL,
`stats_compare_from` date default NULL,
`stats_compare_to` date default NULL,
+ `stats_compare_option` int(1) unsigned NOT NULL DEFAULT 1,
`bo_color` varchar(32) default NULL,
`bo_theme` varchar(32) default NULL,
`default_tab` int(10) unsigned NOT NULL DEFAULT 0,
diff --git a/install-dev/upgrade/sql/1.6.0.1.sql b/install-dev/upgrade/sql/1.6.0.1.sql
index 2ccaf580f..d6b40b1d7 100644
--- a/install-dev/upgrade/sql/1.6.0.1.sql
+++ b/install-dev/upgrade/sql/1.6.0.1.sql
@@ -69,4 +69,6 @@ ALTER TABLE `PREFIX_employee` ADD `stats_compare_from` DATE NULL DEFAULT NULL
INSERT INTO `PREFIX_hook` (`id_hook` , `name` , `title` , `description` , `position` , `live_edit`)
VALUES (NULL , 'displayHomeTab', 'Home Page Tabs', 'This hook displays new elements on the homepage tabs', '1', '1'),
-(NULL , 'displayHomeTabContent', 'Home Page Tabs Content', 'This hook displays new elements on the homepage tabs content', '1', '1');
\ No newline at end of file
+(NULL , 'displayHomeTabContent', 'Home Page Tabs Content', 'This hook displays new elements on the homepage tabs content', '1', '1');
+
+ALTER TABLE `PREFIX_employee` ADD `stats_compare_option` INT( 1 ) NOT NULL DEFAULT '1' AFTER `stats_compare_to`;
\ No newline at end of file