]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
[ERP-142] Расчёт количества сотрудников
authorAlexander Smirnov <fredeom@mail.ru>
Wed, 21 Aug 2024 10:34:07 +0000 (13:34 +0300)
committerAlexander Smirnov <fredeom@mail.ru>
Wed, 21 Aug 2024 10:34:07 +0000 (13:34 +0300)
erp24/actions/motivation/IndexAction.php
erp24/services/MotivationService.php

index 65c516374ee655a096e96a5cf30c8e9f5e3711b5..d6018407f21f66c4a37bfcc0f9fc8561508fef46 100644 (file)
@@ -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;
index d2eecf565e8a07445e52ccf3b9cd45ce5c19291f..77c925060a7257cd2ab08eb5559743ff22050442 100644 (file)
@@ -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);
+        }
+    }
+
     /**
      * Получение записей по фактическому количеству смен в магазине за указанный период.
      *