From 2f7350aa548c1661015c063860759d374e49d157 Mon Sep 17 00:00:00 2001 From: Alexander Smirnov Date: Tue, 1 Oct 2024 15:35:09 +0300 Subject: [PATCH] =?utf8?q?[ERP-187]=20=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?utf8?q?=D0=BB=D0=B5=D0=BD=20=D0=B1=D0=B0=D0=B3=20=D0=B2=20=D0=BF=D0=BE?= =?utf8?q?=D0=B4=D1=81=D1=87=D1=91=D1=82=D0=B5=20=D1=87=D0=B8=D1=81=D0=BB?= =?utf8?q?=D0=B0=20=D1=80=D0=B0=D0=B1=D0=BE=D1=87=D0=B8=D1=85=20=D0=B4?= =?utf8?q?=D0=BD=D0=B5=D0=B9=20+=20=D0=BF=D1=80=D0=B8=20=D1=81=D0=BC=D0=B5?= =?utf8?q?=D0=BD=D0=B5=20=D0=B4=D0=BE=D0=BB=D0=B6=D0=BD=D0=BE=D1=81=D1=82?= =?utf8?q?=D0=B8=20=D0=BD=D0=BE=D1=80=D0=BC=D0=B0=20=D0=B0=D0=B2=D1=82?= =?utf8?q?=D0=BE=D0=BC=D0=B0=D1=82=D0=BE=D0=BC=2015?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- erp24/helpers/HtmlHelper.php | 3 +++ erp24/services/MotivationService.php | 14 +++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/erp24/helpers/HtmlHelper.php b/erp24/helpers/HtmlHelper.php index 0d68bcb2..b5f8b591 100755 --- a/erp24/helpers/HtmlHelper.php +++ b/erp24/helpers/HtmlHelper.php @@ -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; diff --git a/erp24/services/MotivationService.php b/erp24/services/MotivationService.php index 1c63ef67..8fb5fbb6 100644 --- a/erp24/services/MotivationService.php +++ b/erp24/services/MotivationService.php @@ -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); } -- 2.39.5