From: Alexander Smirnov Date: Thu, 25 Jul 2024 12:51:32 +0000 (+0300) Subject: Фильтр показывает только доступные значения X-Git-Tag: 1.4~45^2~24 X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=8e1bb385290fa2b998b3f193c87af03575f52d55;p=erp24_rep%2Fyii-erp24%2F.git Фильтр показывает только доступные значения --- diff --git a/erp24/actions/motivation/IndexAction.php b/erp24/actions/motivation/IndexAction.php index c3f3794b..15aad57e 100644 --- a/erp24/actions/motivation/IndexAction.php +++ b/erp24/actions/motivation/IndexAction.php @@ -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'));