* за каждый день указанного периода.
*
* ВАЖНО: При расчете количества сотрудников на смене учитывается тип смены:
- * - 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).
* Если сотрудник работает и в дневную, и в ночную смену, он учитывается дважды.
$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'])
->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) {
// Для карт нужны уникальные 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()
$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);
// Сохраняем данные сотрудников для этого магазина