From 516e6a39723e53b031a8e95c48ba78390966c2fa Mon Sep 17 00:00:00 2001 From: Vladimir Fomichev Date: Mon, 8 Dec 2025 11:39:22 +0300 Subject: [PATCH] =?utf8?q?=D0=9A=D0=BE=D1=80=D1=80=D0=B5=D0=BA=D1=82=D0=B8?= =?utf8?q?=D1=80=D0=BE=D0=B2=D0=BA=D0=B0=20=D0=B4=D0=BD=D0=B5=D0=B2=D0=BD?= =?utf8?q?=D0=BE=D0=B3=D0=BE=20=D0=BE=D1=82=D1=87=D0=B5=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- erp24/api3/core/services/ReportService.php | 48 ++++++---------------- 1 file changed, 13 insertions(+), 35 deletions(-) diff --git a/erp24/api3/core/services/ReportService.php b/erp24/api3/core/services/ReportService.php index e810a628..58208ef5 100644 --- a/erp24/api3/core/services/ReportService.php +++ b/erp24/api3/core/services/ReportService.php @@ -1411,7 +1411,7 @@ class ReportService * за каждый день указанного периода. * * ВАЖНО: При расчете количества сотрудников на смене учитывается тип смены: - * - shift_type = 1 (дневная): учитываются только сотрудники с shift_id = 1 + * - shift_type = 1 (дневная): учитываются только сотрудники с shift_id = 1,5,8 * - shift_type = 2 (ночная): учитываются только сотрудники с shift_id = 2 * - shift_type = 0 (обе смены): учитываются уникальные комбинации (admin_id, shift_id). * Если сотрудник работает и в дневную, и в ночную смену, он учитывается дважды. @@ -1451,6 +1451,8 @@ class ReportService $cityStoreNames = ArrayHelper::map(CityStore::find()->where(['visible' => '1'])->all(), 'id', 'name'); + $shiftIds = $data->shift_type == 0 ? [1, 2, 5, 8] : ($data->shift_type == 1 ? [1, 5, 8] : [2]); + $eitStores = ExportImportTable::find()->where(['export_val' => $data->stores]) ->select(['entity_id', 'export_val']) ->where(['export_id' => 1, 'entity' => 'city_store']) @@ -1469,7 +1471,8 @@ class ReportService ->where(['store_id' => $data->stores]) ->andWhere(['>=', 'date', date("Y-m-01", strtotime($data->date))]) ->andWhere(['<=', 'date', date("Y-m-d", strtotime($data->date))]) - ->andWhere(['>', 'work_time', 0]); + ->andWhere(['>', 'work_time', 0]) + ->andWhere(['shift_id' => $shiftIds]); // Для типа смены 0 (обе смены) считаем каждую смену отдельно if ($data->shift_type == 0) { @@ -1484,13 +1487,6 @@ class ReportService // Для карт нужны уникальные admin_id $adminIdsInPeriod = array_unique(ArrayHelper::getColumn($allAdminsInPeriod, 'admin_id')); } else { - // Для конкретной смены используем фильтр и distinct - if ($data->shift_type == 1) { - $allAdminsInPeriodQuery->andWhere(['shift_id' => Shift::DAY]); - } elseif ($data->shift_type == 2) { - $allAdminsInPeriodQuery->andWhere(['shift_id' => Shift::NIGHT]); - } - $allAdminsInPeriod = $allAdminsInPeriodQuery ->select(['admin_id']) //->distinct() @@ -1514,32 +1510,14 @@ class ReportService $employeesQuery = TimetableFactModel::find() ->where(['store_id' => $store_id]) ->andWhere(['date' => $day]) - ->andWhere(['>', 'work_time', 0]); - - // Фильтрация по типу смены - if ($data->shift_type == 1) { - // Дневная смена - $employeesQuery->andWhere(['shift_id' => \yii_app\records\Shift::DAY]); - } elseif ($data->shift_type == 2) { - // Ночная смена - $employeesQuery->andWhere(['shift_id' => \yii_app\records\Shift::NIGHT]); - } - // Для shift_type == 0 не фильтруем по shift_id - - // Для shift_type == 0 считаем каждую смену отдельно - if ($data->shift_type == 0) { - $employees = $employeesQuery - ->select(['admin_id', 'shift_id']) - ->asArray() - ->all(); - } else { - - $employees = $employeesQuery - ->select(['admin_id']) - ->asArray() - ->all(); - } - + ->andWhere(['>', 'work_time', 0]) + ->andWhere(['shift_id' => $shiftIds]); + + // Единая выборка admin_id + shift_id + $employees = $employeesQuery + ->select(['admin_id', 'shift_id']) + ->asArray() + ->all(); $employeeCount[$store_id] = count($employees); // Сохраняем данные сотрудников для этого магазина -- 2.39.5