// Date Range picker improvements
This commit is contained in:
@@ -49,17 +49,17 @@
|
||||
<div class='form-date-heading'>
|
||||
<span class="checkbox-title">
|
||||
<label >
|
||||
<input type='checkbox' id="datepicker-compare">
|
||||
<input type='checkbox' id="datepicker-compare" name="datepicker_compare"{if isset($compare_date_from) && isset($compare_date_to)} checked="checked"{/if}>
|
||||
{l s='Compare to'}
|
||||
</label>
|
||||
</span>
|
||||
<select id="compare-options" name="compare_date_option" disabled="disabled">
|
||||
<select id="compare-options" name="compare_date_option"{if is_null($compare_date_from) || is_null($compare_date_to)} disabled="disabled"{/if}>
|
||||
<option value="1"{if $compare_option == 1}selected="selected"{/if} label="{l s='Previous period'}">{l s='Previous period'}</option>
|
||||
<option value="2"{if $compare_option == 2}selected="selected"{/if} label="{l s='Previous Year'}">{l s='Previous Year'}</option>
|
||||
<option value="3"{if $compare_option == 3}selected="selected"{/if} label="{l s='Custom'}">{l s='Custom'}</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-date-body" id="form-date-body-compare" style="display: none;">
|
||||
<div class="form-date-body" id="form-date-body-compare"{if is_null($compare_date_from) || is_null($compare_date_to)} style="display: none;"{/if}>
|
||||
<label>{l s='From'}</label>
|
||||
<input id="date-start-compare" class="date-input form-control" type="text" placeholder="Start" name="compare_date_from" value="{$compare_date_from}" />
|
||||
<label>{l s='to'}</label>
|
||||
@@ -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}
|
||||
});
|
||||
</script>
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user