]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Корректировка дневного отчета
authorVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Mon, 8 Dec 2025 08:39:22 +0000 (11:39 +0300)
committerVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Mon, 8 Dec 2025 08:39:22 +0000 (11:39 +0300)
erp24/api3/core/services/ReportService.php

index e810a6287edd242da5d897b555a184a54fd4c4b8..58208ef5f958c1e81cca3b9ee1bef44004e595af 100644 (file)
@@ -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);
 
                 // Сохраняем данные сотрудников для этого магазина