From c9da44779701f4e518b57dd12a95e16948c3d950 Mon Sep 17 00:00:00 2001 From: Vladimir Fomichev Date: Fri, 14 Nov 2025 18:08:39 +0300 Subject: [PATCH] =?utf8?q?=D0=94=D0=BE=D0=BA=D1=83=D0=BC=D0=B5=D0=BD=D1=82?= =?utf8?q?=D0=B0=D1=86=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- erp24/actions/grade/AdminUpdateAction.php | 20 +++++++++++++- erp24/actions/grade/UpdateAction.php | 31 +++++++++++++++++++--- erp24/api3/core/services/ReportService.php | 20 +++++++++----- erp24/views/grade/admin-update.php | 2 +- erp24/views/grade/update.php | 6 +++++ erp24/views/store-staffing/index.php | 5 ++-- 6 files changed, 70 insertions(+), 14 deletions(-) diff --git a/erp24/actions/grade/AdminUpdateAction.php b/erp24/actions/grade/AdminUpdateAction.php index 968766fa..4aca3a8d 100644 --- a/erp24/actions/grade/AdminUpdateAction.php +++ b/erp24/actions/grade/AdminUpdateAction.php @@ -212,7 +212,25 @@ class AdminUpdateAction extends Action $companies = ArrayHelper::map(Companies::find()->all(), 'id', 'name'); + // Извлекаем смену из group_name, если она там есть + $shift = ''; + if ($model->employee_position_id && !empty($model->group_name)) { + $position = EmployeePosition::findOne($model->employee_position_id); + if ($position) { + $positionName = $position->name; + // Проверяем, что group_name начинается с названия должности и заканчивается на " день" или " ночь" + if (mb_strpos($model->group_name, $positionName) === 0) { + $remaining = mb_substr($model->group_name, mb_strlen($positionName)); + if ($remaining === ' день') { + $shift = 'день'; + } elseif ($remaining === ' ночь') { + $shift = 'ночь'; + } + } + } + } + return $this->controller->render('admin-update', compact('model', 'adminGroups', 'admins', - 'cityStores', 'adminHistoryCategories', 'companies', 'positions')); + 'cityStores', 'adminHistoryCategories', 'companies', 'positions', 'shift')); } } diff --git a/erp24/actions/grade/UpdateAction.php b/erp24/actions/grade/UpdateAction.php index 0b4ff8bc..2b35edef 100755 --- a/erp24/actions/grade/UpdateAction.php +++ b/erp24/actions/grade/UpdateAction.php @@ -21,17 +21,23 @@ class UpdateAction extends Action $positions = EmployeePosition::find()->orderBy('posit')->all(); - $modelPosition = DynamicModel::validateData(['position_id' => null, 'action' => 'updatePosition'], [['position_id', 'integer'], ['action', 'string']]); + $modelPosition = DynamicModel::validateData(['position_id' => null, 'shift' => '', 'action' => 'updatePosition'], + [['position_id', 'integer'], ['shift', 'string'], ['action', 'string']]); if ($modelPosition->load(Yii::$app->request->post()) && $modelPosition->action == 'updatePosition') { // Гибридный подход: обновляем основное поле (источник истины) $admin->employee_position_id = $modelPosition->position_id; - // Синхронизируем group_name с выбранной должностью (как в AdminUpdateAction) + // Синхронизируем group_name с выбранной должностью и сменой (как в AdminUpdateAction) if ($modelPosition->position_id) { $position = EmployeePosition::findOne($modelPosition->position_id); if ($position) { - $admin->group_name = $position->name; + $groupName = $position->name; + // Если выбрана смена, добавляем её к названию + if (!empty($modelPosition->shift)) { + $groupName .= ' ' . $modelPosition->shift; + } + $admin->group_name = $groupName; } } @@ -47,6 +53,25 @@ class UpdateAction extends Action // Показываем текущий грейд из основного поля (источник истины) $modelPosition->position_id = $admin->employee_position_id; $modelPosition->action = 'updatePosition'; + + // Извлекаем смену из group_name, если она там есть + $shift = ''; + if ($admin->employee_position_id && !empty($admin->group_name)) { + $position = EmployeePosition::findOne($admin->employee_position_id); + if ($position) { + $positionName = $position->name; + // Проверяем, что group_name начинается с названия должности и заканчивается на " день" или " ночь" + if (mb_strpos($admin->group_name, $positionName) === 0) { + $remaining = mb_substr($admin->group_name, mb_strlen($positionName)); + if ($remaining === ' день') { + $shift = 'день'; + } elseif ($remaining === ' ночь') { + $shift = 'ночь'; + } + } + } + } + $modelPosition->shift = $shift; $modelPosition->validate(); } diff --git a/erp24/api3/core/services/ReportService.php b/erp24/api3/core/services/ReportService.php index fbf95dfa..a0d36648 100644 --- a/erp24/api3/core/services/ReportService.php +++ b/erp24/api3/core/services/ReportService.php @@ -334,11 +334,12 @@ class ReportService // Получаем все уникальные admin_id сотрудников за период $allAdminsInPeriod = Timetable::find()->alias('t') ->select(['admin_id']) - ->distinct() ->where(['t.store_id' => $data->stores]) ->andWhere(['>=', 'date', date("Y-m-01", strtotime($data->date_start))]) ->andWhere(['<=', 'date', $data->date_end]) ->andWhere(['tabel' => 0, 'slot_type_id' => Timetable::TIMESLOT_WORK]) + ->andWhere(['IS', 't.deleted_at', null]) + ->groupBy(['admin_id']) ->asArray()->all(); $adminIdsInPeriod = ArrayHelper::getColumn($allAdminsInPeriod, 'admin_id'); @@ -358,6 +359,7 @@ class ReportService ->andWhere(['>=', 'date', date("Y-m-01", strtotime($currentDate))]) ->andWhere(['<=', 'date', $currentDate]) ->andWhere(['shift_id' => $shift_id, 'tabel' => 0, 'slot_type_id' => Timetable::TIMESLOT_WORK]) + ->andWhere(['IS', 't.deleted_at', null]) ->asArray()->all(); $timetables = Timetable::find()->alias('t')->select(['admin_id', 'a.name as adminName', 't.store_id', 't.shift_id']) @@ -365,6 +367,7 @@ class ReportService ->where(['t.store_id' => $data->stores]) ->andWhere(['date' => $currentDate, 'tabel' => 0]) ->andWhere(['shift_id' => $shift_id, 'slot_type_id' => Timetable::TIMESLOT_WORK]) + ->andWhere(['IS', 't.deleted_at', null]) ->asArray()->all(); $adminIdsMonth = ArrayHelper::getColumn($timetablesMonth, 'admin_id'); @@ -552,17 +555,20 @@ class ReportService $adminNames = []; foreach ($timetables as $timetable) { - $adminNames[$timetable['store_id']][] = [ + $storeId = $timetable['store_id']; + + if (!isset($adminNames[$storeId])) { + $adminNames[$storeId] = []; + } + + // Добавляем все записи из timetable (фильтрация по deleted_at уже применена в запросе) + // Один администратор может работать в несколько смен в один день + $adminNames[$storeId][] = [ 'id' => $timetable['admin_id'], 'name' => $timetable['adminName'], 'shift_id' => $timetable['shift_id'], ]; } - - // Преобразуем индексированный массив обратно в обычный для совместимости с остальным кодом - foreach ($adminNames as $storeId => $admins) { - $adminNames[$storeId] = array_values($admins); - } $storeVisitorsQuantityTotal = 0; $storeSaleQuantityTotal = 0; diff --git a/erp24/views/grade/admin-update.php b/erp24/views/grade/admin-update.php index 9161c6fd..f974f6bc 100644 --- a/erp24/views/grade/admin-update.php +++ b/erp24/views/grade/admin-update.php @@ -77,7 +77,7 @@ use yii_app\services\FileService; ArrayHelper::map($positions, 'id', 'name'), ['prompt' => 'Выберите должность'] )->label(false)) ?> - 'Не выбрана', 'день' => 'День', 'ночь' => 'Ночь' diff --git a/erp24/views/grade/update.php b/erp24/views/grade/update.php index 3f1b020b..3db96872 100755 --- a/erp24/views/grade/update.php +++ b/erp24/views/grade/update.php @@ -74,7 +74,13 @@ use dosamigos\datetimepicker\DateTimePicker; ['' => '-- Выберите грейд --'] + ArrayHelper::map($positions, 'id', 'name'), ['class' => 'form-control'] )->label(false); ?> + field($modelPosition, 'shift')->dropDownList([ + '' => 'Не выбрана', + 'день' => 'День', + 'ночь' => 'Ночь' + ], ['class' => 'form-control'])->label('Смена') ?> +
'btn btn-primary'])?>
diff --git a/erp24/views/store-staffing/index.php b/erp24/views/store-staffing/index.php index 0d1388c3..baed117b 100644 --- a/erp24/views/store-staffing/index.php +++ b/erp24/views/store-staffing/index.php @@ -111,10 +111,11 @@ $this->params['breadcrumbs'][] = $this->title; } foreach ($storeSkills as $storeId => $data) { - $avgScore = $data['totalCount'] > 0 ? round($data['totalWeighted'] / $data['totalCount'], 1) : 0; + $avgScore = $data['totalCount'] > 0 ? round($data['totalWeighted'] / $data['totalCount'], 2) : 0; + $avgScoreFormatted = number_format($avgScore, 2, ',', ' '); echo ''; echo '' . Html::a($data['storeName'], ['logs', 'store_id' => $storeId]) . ''; - echo '' . $avgScore . ''; + echo '' . $avgScoreFormatted . ''; echo ''; } ?> -- 2.39.5