From: Alexander Smirnov Date: Wed, 21 Aug 2024 10:34:07 +0000 (+0300) Subject: [ERP-142] Расчёт количества сотрудников X-Git-Tag: 1.4~27^2~2 X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=d6e1d0dde594b3be8bad024da55c17dec61279cb;p=erp24_rep%2Fyii-erp24%2F.git [ERP-142] Расчёт количества сотрудников --- 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); + } + } + /** * Получение записей по фактическому количеству смен в магазине за указанный период. *