]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
[ERP-310] Применить фильтры после нажатия кнопки применить
authorAlexander Smirnov <fredeom@mail.ru>
Wed, 19 Mar 2025 12:30:14 +0000 (15:30 +0300)
committerAlexander Smirnov <fredeom@mail.ru>
Wed, 19 Mar 2025 12:30:14 +0000 (15:30 +0300)
erp24/controllers/MatrixStatisticsController.php

index 1f365425d9df305c8b36460a971f749e15e8809f..23b91ef4e1e061a4053e2dd477aa5a7a2b3c74fa 100644 (file)
@@ -39,6 +39,25 @@ class MatrixStatisticsController extends Controller {
 
         $model->load(Yii::$app->request->get());
 
+        $stores = ArrayHelper::map($this->getStores([
+            'territorial_manager_id' => $model->territory_manager_id,
+            'kshf_id' => $model->kshf_id,
+            'city_id' => $model->city_id,
+            'region_id' => $model->region_id,
+            'raion_id' => $model->raion_id,
+            'store_type_id' => $model->store_type_id,
+        ]), 'id', 'name');
+
+        $exist = false;
+        foreach ($stores as $storeId => $storeName) {
+            if ($model->store_id == $storeId) {
+                $exist = true;
+                break;
+            }
+        }
+        if (!$exist) {
+            $model->store_id = null;
+        }
         ///////////////////////////////////////////
         $total = 0;
         $matrixTypes = MatrixType::find()->orderBy(['id' => SORT_ASC])->all();
@@ -191,18 +210,12 @@ class MatrixStatisticsController extends Controller {
             $year = date("Y") - $i;
             $years [$year] = $year;
         }
-        $stores = ArrayHelper::map(CityStore::find()->andWhere(['visible' => '1'])->all(), 'id', 'name');
-
 
         return $this->render('index', compact('model', 'years', 'stores', 'total',
             'withoutMatrix', 'withOnlyMatrix', 'saleCountPlan', 'matrixTypes'));
     }
 
-    public function actionGetStores() {
-        Yii::$app->response->format = Response::FORMAT_JSON;
-
-        $data = Yii::$app->request->post();
-
+    public function getStores($data) {
         $territorialManager = $data['territorial_manager_id'] ?? null;
         $bushChefFlorist = $data['kshf_id'] ?? null;
 
@@ -257,6 +270,16 @@ class MatrixStatisticsController extends Controller {
 
         $stores = $query->all();
 
+        return $stores;
+    }
+
+    public function actionGetStores() {
+        Yii::$app->response->format = Response::FORMAT_JSON;
+
+        $data = Yii::$app->request->post();
+
+        $stores = $this->getStores($data);
+
         return ArrayHelper::map($stores, 'id', 'name');
     }
 }