[ 'class' => AccessControl::className(), 'rules' => [ [ 'actions' => ['login', 'error'], 'allow' => true, ], [ 'actions' => ['logout', 'index'], 'allow' => true, 'roles' => ['@'], 'matchCallback' => function ($rule, $action) { return User::hasAccessBackend(); } ], [ 'actions' => ['change-producer', 'bug-subscription-payment'], 'allow' => true, 'roles' => ['@'], 'matchCallback' => function ($rule, $action) { return User::getCurrentStatus() == User::STATUS_ADMIN; } ], ], ], 'verbs' => [ 'class' => VerbFilter::className(), 'actions' => [ ], ], ]; } /** * @inheritdoc */ public function actions() { return [ 'error' => [ 'class' => 'yii\web\ErrorAction', ], ]; } public function actionBugSubscriptionPayment($fix = 0) { $producerArray = Producer::find()->where(['active' => 1])->all(); //print_r($producerArray); //die(); foreach ($producerArray as $producer) { $orderArray = Order::searchAll([ 'distribution.id_producer' => $producer->id, 'origin' => Order::ORIGIN_AUTO, 'auto_payment' => 0, ], [ 'conditions' => 'date_delete IS NULL AND point_sale.credit_functioning = \'mandatory\' AND subscription.auto_payment = 1 AND order.date > \'2022-12-01\'', 'join_with' => ['pointSale', 'subscription', 'distribution'], ]); /*$orderArray = Order::searchAll([ 'distribution.id_producer' => $producer->id, 'origin' => Order::ORIGIN_AUTO, 'auto_payment' => 0, ], [ 'conditions' => 'date_delete IS NULL AND point_sale.credit_functioning = \'optional\' AND subscription.auto_payment = 1 AND order.date > \'2022-12-01\'', 'join_with' => ['pointSale', 'subscription', 'distribution'], ]);*/ $count = 0; if($orderArray) { foreach($orderArray as $order) { $amountRemaining = $order->getAmount(Order::AMOUNT_REMAINING); if($amountRemaining >= 0.01) { $count ++; } } } if($count) { echo '

' . $producer->name . '

'; echo '

' . $count . ' commandes.

'; echo ''; } } die(); } /** * Affiche le tableau de bord du backend avec les dernières commandes * réalisée, les dernières inscriptions, la liste des clients ayant un crédit * négatif etc. * * @return mixed */ public function actionIndex() { // commandes $optionDashboardNumberDistributions = Producer::getConfig('option_dashboard_number_distributions'); $dashboardNumberDistributions = $optionDashboardNumberDistributions ? $optionDashboardNumberDistributions : 3; $optionDashboardDateStart = Producer::getConfig('option_dashboard_date_start'); $optionDashboardDateEnd = Producer::getConfig('option_dashboard_date_end'); $queryDistributions = Distribution::find()->with('order'); if ($optionDashboardDateStart || $optionDashboardDateEnd) { if ($optionDashboardDateStart) { $queryDistributions->andWhere(['>=', 'distribution.date', $optionDashboardDateStart]); } if ($optionDashboardDateEnd) { $queryDistributions->andWhere(['<=', 'distribution.date', $optionDashboardDateEnd]); } } else { $queryDistributions->andWhere(['>=', 'distribution.date', date('Y-m-d')]); } $distributionsArray = $queryDistributions->andWhere([ 'distribution.id_producer' => GlobalParam::getCurrentProducerId(), 'distribution.active' => 1 ]) ->orderBy('date ASC') ->limit($dashboardNumberDistributions) ->all(); // dernières commandes $paramsOrders = []; if ($optionDashboardDateStart || $optionDashboardDateEnd) { $conditionsOrders = ''; if ($optionDashboardDateStart) { $conditionsOrders .= 'distribution.date >= :date_start'; $paramsOrders[':date_start'] = $optionDashboardDateStart; } if ($optionDashboardDateEnd) { if ($optionDashboardDateStart) { $conditionsOrders .= ' AND '; } $conditionsOrders .= 'distribution.date <= :date_end'; $paramsOrders[':date_end'] = $optionDashboardDateEnd; } } else { $conditionsOrders = 'distribution.date >= :date_start'; $paramsOrders[':date_start'] = date('Y-m-d 00:00:00'); } $ordersArray = Order::searchAll([], [ 'orderby' => 'date DESC', 'conditions' => $conditionsOrders . ' AND (origin = \'' . Order::ORIGIN_USER . '\' OR origin = \'' . Order::ORIGIN_ADMIN . '\' OR (origin = \'' . Order::ORIGIN_AUTO . '\' AND (date_update IS NOT NULL OR date_delete IS NOT NULL)))', 'params' => $paramsOrders, ]); // clients $usersArray = User::findBy() ->orderBy('created_at DESC') ->limit(5) ->all(); $usersNegativeCredit = User::findBy(['id_producer' => GlobalParam::getCurrentProducerId()]) ->andWhere('user_producer.credit < 0') ->all(); // paramètres $producer = GlobalParam::getCurrentProducer(); $productsCount = Product::searchCount(); $pointsSaleCount = PointSale::searchCount(); return $this->render('index', [ 'distributionsArray' => $distributionsArray, 'ordersArray' => $ordersArray, 'usersArray' => $usersArray, 'usersNegativeCredit' => $usersNegativeCredit, 'producer' => $producer, 'productsCount' => $productsCount, 'pointsSaleCount' => $pointsSaleCount ]); } /** * Affiche la page de connexion. * * @return mixed */ public function actionLogin() { if (!\Yii::$app->user->isGuest) { return $this->goHome(); } $model = new LoginForm(); if ($model->load(Yii::$app->request->post()) && $model->login()) { return $this->goBack(); } else { return $this->render('login', [ 'model' => $model, ]); } } /** * Déconnecte l'utilisateur et le redirige à la page d'accueil. * * @return mixed */ public function actionLogout() { Yii::$app->user->logout(); return $this->goHome(); } /** * Change le producteur courant de l'utilisateur connecté. * Permet de passer d'un producteur à un autre en tant qu'administrateur. * * @param integer $id */ public function actionChangeProducer($id) { Yii::$app->user->identity->id_producer = $id; Yii::$app->user->identity->save(); $this->redirect(['site/index']); } }