public function index()
{
$this->template->setTitle($this->lang->line('text_title'));
$this->template->setHeading($this->lang->line('text_heading'));
$this->template->setButton($this->lang->line('button_check_updates'), array('class' => 'btn btn-default', 'href' => site_url('updates')));
$this->template->setStyleTag(assets_url('js/daterange/daterangepicker-bs3.css'), 'daterangepicker-css', '100400');
$this->template->setScriptTag(assets_url('js/daterange/moment.min.js'), 'daterange-moment-js', '1000451');
$this->template->setScriptTag(assets_url('js/daterange/daterangepicker.js'), 'daterangepicker-js', '1000452');
$this->template->setStyleTag(assets_url('js/morris/morris.css'), 'chart-css', '100500');
$this->template->setScriptTag(assets_url('js/morris/raphael-min.js'), 'raphael-min-js', '1000453');
$this->template->setScriptTag(assets_url('js/morris/morris.min.js'), 'morris-min-js', '1000454');
$data['total_menus'] = $this->Dashboard_model->getTotalMenus();
$data['current_month'] = mdate('%Y-%m', time());
$data['months'] = array();
$pastMonth = date('Y-m-d', strtotime(date('Y-m-01') . ' -3 months'));
$futureMonth = date('Y-m-d', strtotime(date('Y-m-01') . ' +3 months'));
for ($i = $pastMonth; $i <= $futureMonth; $i = date('Y-m-d', strtotime($i . ' +1 months'))) {
$data['months'][mdate('%Y-%m', strtotime($i))] = mdate('%F', strtotime($i));
}
$data['default_location_id'] = $this->config->item('default_location_id');
$data['locations'] = array();
$results = $this->Locations_model->getLocations();
foreach ($results as $result) {
$data['locations'][] = array('location_id' => $result['location_id'], 'location_name' => $result['location_name']);
}
$filter = array();
$filter['page'] = '1';
$filter['limit'] = '5';
$data['activities'] = array();
$this->load->model('Activities_model');
$results = $this->Activities_model->getList($filter);
foreach ($results as $result) {
$data['activities'][] = array('activity_id' => $result['activity_id'], 'icon' => 'fa fa-tasks', 'message' => $result['message'], 'time' => mdate('%h:%i %A', strtotime($result['date_added'])), 'time_elapsed' => time_elapsed($result['date_added']), 'state' => $result['status'] === '1' ? 'read' : 'unread');
}
$data['top_customers'] = array();
$filter['limit'] = 6;
$results = $this->Dashboard_model->getTopCustomers($filter);
foreach ($results as $result) {
$data['top_customers'][] = array('first_name' => $result['first_name'], 'last_name' => $result['last_name'], 'total_orders' => $result['total_orders'], 'total_sale' => $this->currency->format($result['total_sale']));
}
$filter = array();
$filter['page'] = '1';
$filter['limit'] = 10;
$filter['sort_by'] = 'orders.date_added';
$filter['order_by'] = 'DESC';
$data['order_by_active'] = 'DESC';
if ($this->user->isStrictLocation()) {
$filter['filter_location'] = $this->user->getLocationId();
}
$data['orders'] = array();
$this->load->model('Orders_model');
$results = $this->Orders_model->getList($filter);
foreach ($results as $result) {
$current_date = mdate('%d-%m-%Y', time());
$date_added = mdate('%d-%m-%Y', strtotime($result['date_added']));
if ($current_date === $date_added) {
$date_added = $this->lang->line('text_today');
} else {
$date_added = mdate('%d %M %y', strtotime($date_added));
}
$data['orders'][] = array('order_id' => $result['order_id'], 'location_name' => $result['location_name'], 'first_name' => $result['first_name'], 'last_name' => $result['last_name'], 'order_status' => $result['status_name'], 'status_color' => $result['status_color'], 'order_time' => mdate('%H:%i', strtotime($result['order_time'])), 'order_type' => $result['order_type'] === '1' ? $this->lang->line('text_delivery') : $this->lang->line('text_collection'), 'date_added' => $date_added, 'edit' => site_url('orders/edit?id=' . $result['order_id']));
}
$data['news_feed'] = $this->Dashboard_model->getNewsFeed();
// Get four items from the feed
if ($this->config->item('auto_update_currency_rates') === '1') {
$this->load->model('Currencies_model');
if ($this->Currencies_model->updateRates()) {
$this->alert->set('success_now', $this->lang->line('alert_rates_updated'));
}
}
if (!$this->Updates_model->lastVersionCheck()) {
$this->alert->set('success_now', sprintf($this->lang->line('text_last_version_check'), site_url('updates')));
}
$this->template->render('dashboard', $data);
}