[ 'class' => AccessControl::class, 'rules' => [ [ 'allow' => true, 'roles' => ['@'], 'matchCallback' => function ($rule, $action) { return $this->getUserModule() ->getAuthorizationChecker() ->isGrantedAsAdministrator($this->getUserCurrent()); } ] ], ], ]; } public function actionTurnover() { $data = []; $dataLabels = []; $dateStart = date('Y-m-d', time() - 60 * 60 * 24 * 365); $dateEnd = date('Y-m-d', time() + 60 * 60 * 24 * 31); $start = new DateTime($dateStart); $interval = new DateInterval('P1M'); $end = new DateTime($dateEnd); $period = new DatePeriod($start, $interval, $end); foreach ($period as $date) { $month = date('m/Y', $date->getTimestamp()); $dataLabels[] = $month; $res = Yii::$app->db->createCommand("SELECT SUM(product_order.price * product_order.quantity) AS total FROM `order`, product_order, distribution WHERE `order`.id_distribution = distribution.id AND `order`.id = product_order.id_order AND distribution.date >= :date_start AND distribution.date <= :date_end ") ->bindValue(':date_start', date('Y-m-', $date->getTimestamp()) . '01') ->bindValue(':date_end', date('Y-m-', $date->getTimestamp()) . '31') ->queryOne(); if ($res['total']) { $data[$month] = $res['total']; } else { $data[$month] = 0; } } $dataNoIndex = []; foreach ($data as $key => $val) { $dataNoIndex[] = round($val, 2); } return $this->render('turnover', [ 'dataLabels' => $dataLabels, 'data' => $dataNoIndex, ]); } public function actionCustomerOrders() { $orderModule = $this->getOrderModule(); $data = []; $dataLabels = []; $dateStart = date('Y-m-d', time() - 60 * 60 * 24 * 30); $dateEnd = date('Y-m-d', time() + 60 * 60 * 24); $start = new DateTime($dateStart); $interval = new DateInterval('P1D'); $end = new DateTime($dateEnd); $period = new DatePeriod($start, $interval, $end); foreach ($period as $date) { $dateFormat = date('d/m/Y', $date->getTimestamp()); $dataLabels[] = $dateFormat; $data[] = $orderModule->countGlobalOrdersByDateAndOrigin($date); } return $this->render('customer_orders', [ 'dataLabels' => $dataLabels, 'data' => $data, ]); } public function actionMatomo() { return $this->render('matomo'); } } ?>