]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
получение работников на смене - грейды
authorVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Mon, 23 Mar 2026 06:45:39 +0000 (09:45 +0300)
committerVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Mon, 23 Mar 2026 06:45:39 +0000 (09:45 +0300)
erp24/api2/controllers/DataTestController.php

index b4f4ff90ad48f50bac16c8ba5c6772309c010cc4..9d6f8267e89bf0e48619f740f0a3eea79224b450 100644 (file)
@@ -7,6 +7,7 @@ use Exception;
 use Yii;
 use yii\helpers\Json;
 use yii_app\records\ApiCronTest;
+use yii_app\records\AdminGradeHistory;
 use yii_app\records\ExportImportTable;
 use yii_app\records\TimetableFact;
 
@@ -401,14 +402,38 @@ class DataTestController extends BaseController {
 
             $adminIds = array_unique(array_column($rows, 'admin_id'));
 
-            // Ð\9fолÑ\83Ñ\87аем Ð¸Ð¼ÐµÐ½Ð° Ñ\81оÑ\82Ñ\80Ñ\83дников
+            // Ð\9fолÑ\83Ñ\87аем Ð´Ð°Ð½Ð½Ñ\8bе Ñ\81оÑ\82Ñ\80Ñ\83дников (имÑ\8f, Ð´Ð¾Ð»Ð¶Ð½Ð¾Ñ\81Ñ\82Ñ\8c)
             $admins = \yii_app\records\Admin::find()
-                ->select(['id', 'name_full'])
+                ->select(['id', 'name_full', 'employee_position_id'])
                 ->where(['id' => $adminIds])
                 ->indexBy('id')
                 ->asArray()
                 ->all();
 
+            // Получаем названия должностей
+            $positionIds = array_filter(array_column($admins, 'employee_position_id'));
+            $positions = [];
+            if (!empty($positionIds)) {
+                $positions = \yii_app\records\EmployeePosition::find()
+                    ->select(['id', 'name'])
+                    ->where(['id' => $positionIds])
+                    ->indexBy('id')
+                    ->asArray()
+                    ->all();
+            }
+
+            // Получаем текущий грейд (активная запись: closed_at = '2100-01-01 00:00:00')
+            $gradeRows = AdminGradeHistory::find()
+                ->alias('agh')
+                ->select(['agh.admin_id', 'g.id AS grade_id', 'g.name AS grade_name'])
+                ->innerJoin('grade g', 'g.id = agh.grade_id')
+                ->where(['agh.admin_id' => $adminIds])
+                ->andWhere(['agh.closed_at' => '2100-01-01 00:00:00'])
+                ->asArray()
+                ->all();
+
+            $grades = array_column($gradeRows, null, 'admin_id');
+
             // Получаем seller_id (GUID из 1С) для каждого сотрудника
             $exportRows = ExportImportTable::find()
                 ->select(['entity_id', 'export_val'])
@@ -424,10 +449,18 @@ class DataTestController extends BaseController {
 
             $result = [];
             foreach ($adminIds as $adminId) {
+                $admin      = $admins[$adminId] ?? [];
+                $positionId = $admin['employee_position_id'] ?? null;
+                $grade      = $grades[$adminId] ?? null;
+
                 $result[] = [
-                    'admin_id'  => $adminId,
-                    'name'      => $admins[$adminId]['name_full'] ?? null,
-                    'seller_id' => $sellerIds[$adminId] ?? null,
+                    'admin_id'             => $adminId,
+                    'name'                 => $admin['name_full'] ?? null,
+                    'seller_id'            => $sellerIds[$adminId] ?? null,
+                    'employee_position_id' => $positionId,
+                    'position_name'        => $positionId ? ($positions[$positionId]['name'] ?? null) : null,
+                    'grade_id'             => $grade['grade_id'] ?? null,
+                    'grade_name'           => $grade['grade_name'] ?? null,
                 ];
             }