From d6e1d0dde594b3be8bad024da55c17dec61279cb Mon Sep 17 00:00:00 2001 From: Alexander Smirnov Date: Wed, 21 Aug 2024 13:34:07 +0300 Subject: [PATCH] =?utf8?q?[ERP-142]=20=D0=A0=D0=B0=D1=81=D1=87=D1=91=D1=82?= =?utf8?q?=20=D0=BA=D0=BE=D0=BB=D0=B8=D1=87=D0=B5=D1=81=D1=82=D0=B2=D0=B0?= =?utf8?q?=20=D1=81=D0=BE=D1=82=D1=80=D1=83=D0=B4=D0=BD=D0=B8=D0=BA=D0=BE?= =?utf8?q?=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- erp24/actions/motivation/IndexAction.php | 3 +++ erp24/services/MotivationService.php | 30 ++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/erp24/actions/motivation/IndexAction.php b/erp24/actions/motivation/IndexAction.php index 65c51637..d6018407 100644 --- a/erp24/actions/motivation/IndexAction.php +++ b/erp24/actions/motivation/IndexAction.php @@ -96,6 +96,9 @@ class IndexAction extends Action // Подсчитываем прогноз за месяц MotivationService::calculateMonthForecast($model->store_id, $model->year, $model->month); + // Подсчёт количества сотрудников + MotivationService::calculatePersonalCount($model->store_id, $model->year, $model->month); + $showTable = false; $motivationData = []; $daysInMonth = null; diff --git a/erp24/services/MotivationService.php b/erp24/services/MotivationService.php index d2eecf56..77c92506 100644 --- a/erp24/services/MotivationService.php +++ b/erp24/services/MotivationService.php @@ -634,6 +634,9 @@ class MotivationService $motivation = Motivation::find()->where(['store_id' => $store_id, 'year' => $year, 'month' => $month])->one(); foreach ($items as $code) { + if ($code == 34) { // Количество сотрудников считается в другой задаче + continue; + } if ($motivation) { $motivationValue = MotivationValue::find()->where(['motivation_id' => $motivation->id, 'motivation_group_id' => $motivationValueGroupForecast->id, 'value_id' => $code])->one(); @@ -670,6 +673,33 @@ class MotivationService } } + public static function calculatePersonalCount($store_id, $year, $month) { + $monthStart = date("Y-m-d 00:00:00", strtotime($year . '-' . $month . '-1')); + $monthEnd = date("Y-m-t 23:59:59", strtotime($year . '-' . $month . '-1')); + + $motivation = Motivation::find()->where(['store_id' => $store_id, 'year' => $year, 'month' => $month])->one(); + if ($motivation) { + $timetableFactModels = TimetableFactModel::find()->select(['DISTINCT(admin_id) as admin_id'])->where(['store_id' => $store_id]) + ->andWhere(['between', 'date_shift', $monthStart, $monthEnd])->all(); + $adminIds = ArrayHelper::getColumn($timetableFactModels, 'admin_id'); + + $result = 0; + foreach ($adminIds as $admin_id) { + $timetableFactModel = TimetableFactModel::find()->select(['COUNT(*) as total', 'admin_group_id'])->where(['store_id' => $store_id, 'admin_id' => $admin_id]) + ->andWhere(['between', 'date_shift', $monthStart, $monthEnd])->groupBy(['admin_group_id'])->asArray()->one(); + + $norma = 15; + if ($timetableFactModel['admin_group_id'] != 45) { + $timetablePlan = Timetable::find()->select(['COUNT(*) as total'])->where(['store_id' => $store_id, 'admin_id' => $admin_id, 'tabel' => 0]) + ->andWhere(['between', 'date', $monthStart, $monthEnd])->asArray()->one(); + $norma = $timetablePlan['total']; + } + $result += $norma == 0 ? 0 : $timetableFactModel['total'] / $norma; + } + self::saveOrUpdateMotivationValue($motivation->id, 'fact', 34, 'float', $result); + } + } + /** * Получение записей по фактическому количеству смен в магазине за указанный период. * -- 2.39.5