From: Vladimir Fomichev Date: Mon, 8 Dec 2025 08:39:22 +0000 (+0300) Subject: Корректировка дневного отчета X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=516e6a39723e53b031a8e95c48ba78390966c2fa;p=erp24_rep%2Fyii-erp24%2F.git Корректировка дневного отчета --- 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); // Сохраняем данные сотрудников для этого магазина