]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
[ERP-187] исправлен баг в подсчёте числа рабочих дней + при смене должности норма...
authorAlexander Smirnov <fredeom@mail.ru>
Tue, 1 Oct 2024 12:35:09 +0000 (15:35 +0300)
committerAlexander Smirnov <fredeom@mail.ru>
Tue, 1 Oct 2024 12:35:09 +0000 (15:35 +0300)
erp24/helpers/HtmlHelper.php
erp24/services/MotivationService.php

index 0d68bcb2758139801498d917a094ea43b2620987..b5f8b591b16743dc692a6efd3216f961250da61c 100755 (executable)
@@ -165,6 +165,9 @@ class HtmlHelper
 
     public static function getWorkDays($m, $y): int
     {
+        if ($m < 10) {
+            $m = '0' . $m;
+        }
         $firstDay = date($y . "-" . $m . '-01');
         $lastDay = date($y . "-" . $m . '-t', strtotime($firstDay));
         $cntWorkDays = 0;
index 1c63ef67051c1e8a4b562af79d8c605090df3ce1..8fb5fbb6aa9cbeda8704238b8bd4d55910b46ea9 100644 (file)
@@ -772,12 +772,16 @@ class MotivationService
             $result = 0;
             foreach ($adminIds as $admin_id) {
                 $timetableFactModel = TimetableFactModel::find()->select(['COUNT(*) as total', 'admin_group_id', 'admin_id'])->where(['store_id' => $store_id, 'admin_id' => $admin_id])
-                    ->andWhere(['between', 'date', $monthStart, $monthEnd])->groupBy(['admin_group_id', 'admin_id'])->asArray()->one();
-                $admin = Admin::findOne($timetableFactModel['admin_id']);
+                    ->andWhere(['between', 'date', $monthStart, $monthEnd])->groupBy(['admin_group_id', 'admin_id'])->asArray()->all();
+                $total = array_sum(ArrayHelper::getColumn($timetableFactModel, 'total'));
+
+                $admin = Admin::findOne($timetableFactModel[0]['admin_id'] ?? -1);
                 $work_rate = $admin && $admin->work_rate > 1 ? $admin->work_rate : 1;
-                $norma = $timetableFactModel['admin_group_id'] == AdminGroup::GROUP_ADMINISTRATORS && $work_rate == 1 ?
-                    HtmlHelper::getWorkDays($month, $year) : 15;
-                $result += $norma == 0 ? 0 : $timetableFactModel['total'] / $norma;
+                $norma = count($timetableFactModel) == 1 &&
+                         ($timetableFactModel[0]['admin_group_id'] ?? -1) == AdminGroup::GROUP_ADMINISTRATORS &&
+                         $work_rate == 1 ? HtmlHelper::getWorkDays($month, $year) : 15;
+
+                $result += $norma == 0 ? 0 : $total / $norma;
             }
             self::saveOrUpdateMotivationValue($motivation->id, 'fact', MotivationCostsItem::CODE_EMPLOYEES_QUANTITY, 'float', $result);
         }