]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Фильтр показывает только доступные значения
authorAlexander Smirnov <fredeom@mail.ru>
Thu, 25 Jul 2024 12:51:32 +0000 (15:51 +0300)
committerAlexander Smirnov <fredeom@mail.ru>
Thu, 25 Jul 2024 12:51:32 +0000 (15:51 +0300)
erp24/actions/motivation/IndexAction.php

index c3f3794b534c53c54645df929476787100d17e94..15aad57e6b0d7261ef9baafb7d4acc4b68cb432f 100644 (file)
@@ -10,6 +10,7 @@ use yii\base\DynamicModel;
 use yii\helpers\ArrayHelper;
 use yii\web\UploadedFile;
 use yii_app\records\CityStore;
+use yii_app\records\Motivation;
 use yii_app\records\MotivationCostsItem;
 use yii_app\services\MotivationService;
 
@@ -39,8 +40,15 @@ class IndexAction extends Action
 
         $stores = ArrayHelper::map(CityStore::find()->all(), 'id', 'name');
 
-        $years = [2023, 2024, 2025, 2026];
-        $months = ['Январь',' Февраль', 'Март', 'Апрель', 'Май', 'Июнь', 'Июль', 'Август', 'Сентябрь', 'Октябрь', 'Ноябрь', 'Декабрь'];
+        $motivations = Motivation::find()->all();
+        $possibleYears = ArrayHelper::getColumn($motivations, 'year');
+        $years = array_filter(range(2023, 20100), function ($k) use ($possibleYears) {
+            return in_array($k, $possibleYears);
+        });
+        $possibleMonth = ArrayHelper::getColumn($motivations, 'month');
+        $months = array_filter(['Январь',' Февраль', 'Март', 'Апрель', 'Май', 'Июнь', 'Июль', 'Август', 'Сентябрь', 'Октябрь', 'Ноябрь', 'Декабрь'], function ($k, $v) use ($possibleMonth) {
+            return in_array($v + 1, $possibleMonth);
+        }, ARRAY_FILTER_USE_BOTH);
 
         return $this->controller->render('index',
             compact('model', 'stores', 'years', 'months'));