// Adding compare dates to date range picker
This commit is contained in:
@@ -29,9 +29,19 @@
|
||||
</div>
|
||||
<div class='form-date-body form-group'>
|
||||
<label>{l s='From'}</label>
|
||||
<input class='date-input form-control' id='date-start' placeholder='Start' type='text'>
|
||||
<input class='date-input form-control' id='date-start' placeholder='Start' type='text' name="date_from" value="{$date_from}" />
|
||||
<label>{l s='to'}</label>
|
||||
<input class='date-input form-control' id='date-end' placeholder='End' type='text'>
|
||||
<input class='date-input form-control' id='date-end' placeholder='End' type='text' name="date_to" value="{$date_to}" />
|
||||
</div>
|
||||
<hr/>
|
||||
<div class='form-date-heading'>
|
||||
<div>{l s='Compare to'}</div>
|
||||
</div>
|
||||
<div class="form-date-body form-group">
|
||||
<label>{l s='From'}</label>
|
||||
<input id="compare-date-start" class="date-input form-control" type="text" placeholder="Start" name="compare_date_from" value="{$compare_date_from}" />
|
||||
<label>{l s='to'}</label>
|
||||
<input id="compare-date-end" class="date-input form-control" type="text" placeholder="End" name="compare_date_to" value="{$compare_date_to}" />
|
||||
</div>
|
||||
<hr/>
|
||||
<div class='form-group'>
|
||||
@@ -40,7 +50,7 @@
|
||||
{l s='Cancel'}
|
||||
</button>
|
||||
|
||||
<button class='btn btn-default' type='submit'>
|
||||
<button class='btn btn-default' type='submit' name="submitDateRange">
|
||||
<i class='icon-ok text-success'></i>
|
||||
{l s='Apply'}
|
||||
</button>
|
||||
|
||||
@@ -52,6 +52,9 @@ class EmployeeCore extends ObjectModel
|
||||
public $stats_date_from;
|
||||
public $stats_date_to;
|
||||
|
||||
public $stats_compare_from;
|
||||
public $stats_compare_to;
|
||||
|
||||
/** @var string Display back office background in the specified color */
|
||||
public $bo_color;
|
||||
|
||||
@@ -96,6 +99,8 @@ class EmployeeCore extends ObjectModel
|
||||
'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'),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -105,6 +110,8 @@ class EmployeeCore extends ObjectModel
|
||||
'last_passwd_gen' => array('setter' => null),
|
||||
'stats_date_from' => array('setter' => null),
|
||||
'stats_date_to' => array('setter' => null),
|
||||
'stats_compare_from' => array('setter' => null),
|
||||
'stats_compare_to' => array('setter' => null),
|
||||
'passwd' => array('setter' => 'setWsPasswd'),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -29,9 +29,11 @@ class HelperCalendarCore extends Helper
|
||||
const DEFAULT_DATE_FORMAT = 'dd-mm-yyyy';
|
||||
|
||||
private $_actions;
|
||||
private $_compare_date_from;
|
||||
private $_compare_date_to;
|
||||
private $_date_format;
|
||||
private $_from_date;
|
||||
private $_to_date;
|
||||
private $_date_from;
|
||||
private $_date_to;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
@@ -57,6 +59,40 @@ class HelperCalendarCore extends Helper
|
||||
return $this->_actions;
|
||||
}
|
||||
|
||||
public function setCompareDateFrom($value)
|
||||
{
|
||||
if (!is_string($value))
|
||||
throw new PrestaShopException('Date format must be string');
|
||||
|
||||
$this->_compare_date_from = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCompareDateFrom()
|
||||
{
|
||||
if (!isset($this->_compare_date_from))
|
||||
$this->_compare_date_from = date('d-m-Y', strtotime("-31 days"));
|
||||
|
||||
return $this->_compare_date_from;
|
||||
}
|
||||
|
||||
public function setCompareDateTo($value)
|
||||
{
|
||||
if (!is_string($value))
|
||||
throw new PrestaShopException('Date format must be string');
|
||||
|
||||
$this->_compare_date_to = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCompareDateTo()
|
||||
{
|
||||
if (!isset($this->_compare_date_to))
|
||||
$this->_compare_date_to = date('d-m-Y');
|
||||
|
||||
return $this->_compare_date_to;
|
||||
}
|
||||
|
||||
public function setDateFormat($value)
|
||||
{
|
||||
if (!is_string($value))
|
||||
@@ -74,38 +110,38 @@ class HelperCalendarCore extends Helper
|
||||
return $this->_date_format;
|
||||
}
|
||||
|
||||
public function setFromDate($value)
|
||||
public function setDateFrom($value)
|
||||
{
|
||||
if (!is_string($value))
|
||||
throw new PrestaShopException('Date format must be string');
|
||||
|
||||
$this->_from_date = $value;
|
||||
$this->_date_from = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getFromDate()
|
||||
public function getDateFrom()
|
||||
{
|
||||
if (!isset($this->_from_date))
|
||||
$this->_from_date = date('d-m-Y', strtotime("-31 days"));
|
||||
if (!isset($this->_date_from))
|
||||
$this->_date_from = date('d-m-Y', strtotime("-31 days"));
|
||||
|
||||
return $this->_from_date;
|
||||
return $this->_date_from;
|
||||
}
|
||||
|
||||
public function setToDate($value)
|
||||
public function setDateTo($value)
|
||||
{
|
||||
if (!is_string($value))
|
||||
throw new PrestaShopException('Date format must be string');
|
||||
|
||||
$this->_to_date = $value;
|
||||
$this->_date_to = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getToDate()
|
||||
public function getDateTo()
|
||||
{
|
||||
if (!isset($this->_to_date))
|
||||
$this->_to_date = date('d-m-Y');
|
||||
if (!isset($this->_date_to))
|
||||
$this->_date_to = date('d-m-Y');
|
||||
|
||||
return $this->_to_date;
|
||||
return $this->_date_to;
|
||||
}
|
||||
|
||||
public function addAction($action)
|
||||
@@ -142,10 +178,12 @@ class HelperCalendarCore extends Helper
|
||||
|
||||
$this->tpl = $this->createTemplate($this->base_tpl);
|
||||
$this->tpl->assign(array(
|
||||
'date_format' => $this->getDateFormat(),
|
||||
'from_date' => $this->getFromDate(),
|
||||
'to_date' => $this->getToDate(),
|
||||
'actions' => $this->getActions()
|
||||
'date_format' => $this->getDateFormat(),
|
||||
'date_from' => $this->getDateFrom(),
|
||||
'date_to' => $this->getDateTo(),
|
||||
'compare_date_from' => $this->getCompareDateFrom(),
|
||||
'compare_date_to' => $this->getCompareDateTo(),
|
||||
'actions' => $this->getActions()
|
||||
));
|
||||
|
||||
$html .= parent::generate();
|
||||
|
||||
@@ -152,7 +152,11 @@ 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));
|
||||
|
||||
$this->tpl_view_vars = array(
|
||||
'hookDashboardZoneOne' => Hook::exec('dashboardZoneOne'),
|
||||
'hookDashboardZoneTwo' => Hook::exec('dashboardZoneTwo'),
|
||||
@@ -167,6 +171,20 @@ class AdminDashboardControllerCore extends AdminController
|
||||
);
|
||||
return parent::renderView();
|
||||
}
|
||||
|
||||
public function postProcess()
|
||||
{
|
||||
if (Tools::isSubmit('submitDateRange'))
|
||||
{
|
||||
$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->update();
|
||||
}
|
||||
|
||||
parent::postProcess();
|
||||
}
|
||||
|
||||
protected function getWarningDomainName()
|
||||
{
|
||||
|
||||
@@ -63,4 +63,6 @@ INSERT INTO `PREFIX_hook_module` (`id_module`, `id_shop`, `id_hook`, `position`)
|
||||
SELECT m.id_module, s.id_shop, h.id_hook, 2 FROM `PREFIX_module` m, `PREFIX_shop` s, `PREFIX_hook` h WHERE m.name IN ('dashproducts') AND h.name IN ('dashboardZoneTwo')
|
||||
);
|
||||
|
||||
/* PHP:update_order_messages(); */;
|
||||
/* PHP:update_order_messages(); */;
|
||||
|
||||
ALTER TABLE `PREFIX_employee` ADD `stats_compare_from` DATE NULL DEFAULT NULL AFTER `stats_date_to` , ADD `stats_compare_to` DATE NULL DEFAULT NULL AFTER `stats_compare_from`
|
||||
Reference in New Issue
Block a user