]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Исправление фильтров origin/feature_smirnov_erp-89_motivation_rbac_and_filters
authorAlexander Smirnov <fredeom@mail.ru>
Tue, 6 Aug 2024 12:45:35 +0000 (15:45 +0300)
committerAlexander Smirnov <fredeom@mail.ru>
Tue, 6 Aug 2024 12:45:35 +0000 (15:45 +0300)
erp24/actions/motivation/IndexAction.php
erp24/views/motivation/index.php

index b60157ac6578765cb2edf84f37d88e805b580b6e..f745fa062253454a944aac23ccc3b4ceb772d390 100644 (file)
@@ -44,7 +44,7 @@ class IndexAction extends Action
         $model = DynamicModel::validateData([
             'store_id' => $currentUser->store_id, // Устанавливаем store_id текущего пользователя
             'year' => $currentDate->format('Y'), // Текущий год
-            'month' => $currentDate->format('n') - 1 // Текущий месяц (0-11)
+            'month' => $currentDate->format('n') // Текущий месяц (1-12)
         ], [
             [['store_id', 'year', 'month'], 'safe']
         ]);
@@ -63,9 +63,10 @@ class IndexAction extends Action
         $years = array_filter(range(2023, 20100), function ($k) use ($possibleYears) {
             return in_array($k, $possibleYears);
         });
+        $years = array_combine($years, $years);
         $possibleMonth = ArrayHelper::getColumn($motivations, 'month');
-        $months = array_filter(['Январь', ' Февраль', 'Март', 'Апрель', 'Май', 'Июнь', 'Июль', 'Август', 'Сентябрь', 'Октябрь', 'Ноябрь', 'Декабрь'], function ($k, $v) use ($possibleMonth) {
-            return in_array($v + 1, $possibleMonth);
+        $months = array_filter([1 => 'Январь', 2 => 'Февраль', 3 => 'Март', 4 => 'Апрель', 5 => 'Май', 6 => 'Июнь', 7 => 'Июль', 8 => 'Август', 9 => 'Сентябрь', 10 => 'Октябрь', 11 => 'Ноябрь', 12 => 'Декабрь'], function ($k, $v) use ($possibleMonth) {
+            return in_array($v, $possibleMonth);
         }, ARRAY_FILTER_USE_BOTH);
 
 
@@ -100,10 +101,10 @@ class IndexAction extends Action
 
 
             // получаем данные из таблицы
-            $motivationDataTableSort = $motivationService->getMotivationDataTableSort($model->store_id, $model->year, $model->month + 1);
+            $motivationDataTableSort = $motivationService->getMotivationDataTableSort($model->store_id, $model->year, $model->month);
 
             // Получаем количество дней в месяце
-            $daysInMonth = cal_days_in_month(CAL_GREGORIAN, $model->month + 1, $model->year);
+            $daysInMonth = cal_days_in_month(CAL_GREGORIAN, $model->month, $model->year);
 
             // Определяем, сколько дней в последней неделе
             $daysInLastWeek = $daysInMonth - 28;
@@ -153,7 +154,7 @@ class IndexAction extends Action
 
 
             // Формируем заголовок для 5-й недели
-            if ($model->month == 1) { // Февраль
+            if ($model->month == 2) { // Февраль
                 if ($daysInMonth == 29) {
                     $week5Header = 'Неделя 5<br>(29)';
                 }
@@ -162,15 +163,13 @@ class IndexAction extends Action
             }
         }
 
-        // Подготавливаем данные для Select2 виджета
-        $yearsForSelect = array_combine($years, $years);
-
 
 
 
         return $this->controller->render(
             'index',
-            compact('model', 'stores', 'yearsForSelect', 'months', 'motivationDataTableSort', 'showTable', 'daysInMonth', 'daysInLastWeek', 'week5Header')
+            compact('model', 'stores', 'years', 'months', 'motivationDataTableSort', 'showTable',
+                'daysInMonth', 'daysInLastWeek', 'week5Header')
         );
     }
 
index a6bdb8b4566598a242170a5c86b14ed47d89f050..38386efcadefcf479a0a223c760884edfa182d43 100644 (file)
@@ -10,7 +10,11 @@ use yii_app\records\MotivationCostsItem;
 /** @var $stores array */
 /** @var $years array */
 /** @var $months array */
-/** @var $daysInMonth integer */
+/** @var $motivationDataTableSort array */
+/** @var $showTable bool */
+/** @var $daysInMonth int */
+/** @var $daysInLastWeek int */
+/** @var $week5Header string */
 
 
 $this->registerJsFile('/js/motivation/index.js', ['position' => \yii\web\View::POS_END]);
@@ -19,7 +23,7 @@ $this->registerJsFile('/js/motivation/index.js', ['position' => \yii\web\View::P
 
 <div class="motivationIndex m-5">
 
-    <?php $form = ActiveForm::begin(['method' => 'GET']) ?>
+    <?php $form = ActiveForm::begin(['method' => 'GET', 'action' => '/motivation/index']) ?>
 
     <div class="row">
         <div class="col-4 d-flex justify-content-between align-items-center gap-4">
@@ -40,7 +44,7 @@ $this->registerJsFile('/js/motivation/index.js', ['position' => \yii\web\View::P
                 <div class="mb-3">Год:</div>
                 <div style="display: inline-block">
                     <?= $form->field($model, 'year')->widget(Select2::class, [
-                        'data' => $yearsForSelect,
+                        'data' => $years,
                         'language' => 'ru',
                         'options' => ['placeholder' => 'Год...'],
                         'pluginOptions' => [