$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']
]);
$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);
// получаем данные из таблицы
- $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;
// Формируем заголовок для 5-й недели
- if ($model->month == 1) { // Февраль
+ if ($model->month == 2) { // Февраль
if ($daysInMonth == 29) {
$week5Header = 'Неделя 5<br>(29)';
}
}
}
- // Подготавливаем данные для 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')
);
}
/** @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]);
<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">
<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' => [