]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Изменение прав
authorVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Tue, 26 Aug 2025 12:14:56 +0000 (15:14 +0300)
committerVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Tue, 26 Aug 2025 12:14:56 +0000 (15:14 +0300)
erp24/api2/controllers/DataController.php
erp24/controllers/AnalystsBusinessOperationsController.php
erp24/controllers/AnalystsBusinessOperationsTypesController.php
erp24/views/analysts-business-operations-types/index.php
erp24/views/analysts-business-operations/index.php

index 1dddb361ed7da36830a9fa7cfd3bf97a35ca1cdb..50034b8fec8f61a8c305855f9ae2ea21187d3002 100644 (file)
@@ -2555,19 +2555,20 @@ class DataController extends BaseController
 
             if (!empty($result['analysts_business_operations'])) {
                 $existingOperations = AnalystsBusinessOperations::find()
-                    ->select(['id'])
-                    ->column();
+                    ->indexBy('id')
+                    ->asArray()
+                    ->all();
                 $existingTypes = AnalystsBusinessOperationsTypes::find()
                     ->indexBy('code')
                     ->asArray()
                     ->all();
                 foreach ($result["analysts_business_operations"] as $operation) {
-                    if (!in_array($operation['guid'], $existingOperations)) {
+                    if (!in_array($operation['guid'], array_keys($existingOperations))) {
                         $newOperation = new AnalystsBusinessOperations();
                         $newOperation->id = $operation['guid'];
                         $newOperation->name = $operation['name'];
                         $newOperation->type = (int)$operation['type'];
-                        if (!in_array($newOperation->type, array_column($existingTypes, 'code'))) {
+                        if (!in_array((int)$operation['type'], array_column($existingTypes, 'code'))) {
                             $newType = new AnalystsBusinessOperationsTypes();
                             $newType->code = (int)$operation['type'];
                             $newType->name = null;
@@ -2577,6 +2578,12 @@ class DataController extends BaseController
                             } else {
                                 $newOperation->type_id = null;
                                Yii::error('Ошибка сохранение типа ' . json_encode($newType->getErrors(), JSON_UNESCAPED_UNICODE), __METHOD__ );
+                                LogService::apiErrorLog(
+                                    json_encode(
+                                        ["error_id" => 44.1, "error" => $operation->getErrors()],
+                                        JSON_UNESCAPED_UNICODE
+                                    )
+                                );
                             }
                         } else {
                             $newOperation->type_id = $existingTypes[$operation['type']]['id'];
@@ -2585,12 +2592,45 @@ class DataController extends BaseController
                         if (!$newOperation->save()) {
                             LogService::apiErrorLog(
                                 json_encode(
-                                    ["error_id" => 44, "error" => $newOperation->getErrors()],
+                                    ["error_id" => 44.2, "error" => $newOperation->getErrors()],
                                     JSON_UNESCAPED_UNICODE
                                 )
                             );
                         }
 
+                    } else {
+                        if ($existingOperations[$operation['guid']]['type'] !== (int)$operation['type']) {
+                            $operation = AnalystsBusinessOperations::findOne($operation['guid']);
+                            if (!in_array((int)$operation['type'], array_column($existingTypes, 'code'))) {
+                                $newType = new AnalystsBusinessOperationsTypes();
+                                $newType->code = (int)$operation['type'];
+                                $newType->name = null;
+                                $newType->created_at = date('Y-m-d H:i:s');
+                                if ($newType->save()) {
+                                    $operation->type = (int)$operation['type'];
+                                    $operation->type_id = $newType->id;
+                                } else {
+                                    Yii::error('Ошибка сохранение типа ' . json_encode($newType->getErrors(), JSON_UNESCAPED_UNICODE), __METHOD__ );
+                                    LogService::apiErrorLog(
+                                        json_encode(
+                                            ["error_id" => 44.3, "error" => $operation->getErrors()],
+                                            JSON_UNESCAPED_UNICODE
+                                        )
+                                    );
+                                }
+                            } else {
+                                $operation->type = (int)$operation['type'];
+                                $operation->type_id = AnalystsBusinessOperationsTypes::find()->where(['code' => (int)$operation['type']])->one()->id;
+                                if (!$operation->save()) {
+                                    LogService::apiErrorLog(
+                                        json_encode(
+                                            ["error_id" => 44.4, "error" => $operation->getErrors()],
+                                            JSON_UNESCAPED_UNICODE
+                                        )
+                                    );
+                                }
+                            }
+                        }
                     }
 
                 }
index 61c0ba39ed1178bdc72d104561314ec6ec54c810..709f7cfe4010e356929e277113a74b598fabfdca 100644 (file)
@@ -2,6 +2,9 @@
 
 namespace app\controllers;
 
+use yii\web\ForbiddenHttpException;
+use yii_app\records\Admin;
+use yii_app\records\AdminGroup;
 use yii_app\records\AnalystsBusinessOperations;
 use yii\data\ActiveDataProvider;
 use yii\web\Controller;
@@ -101,6 +104,9 @@ class AnalystsBusinessOperationsController extends Controller
      */
     public function actionUpdate($id)
     {
+        if (!$this->canEdit()) {
+            throw new ForbiddenHttpException('Недостаточно прав.');
+        }
         $model = $this->findModel($id);
 
         if ($this->request->isPost && $model->load($this->request->post()) && $model->save()) {
@@ -121,6 +127,9 @@ class AnalystsBusinessOperationsController extends Controller
      */
     public function actionDelete($id)
     {
+        if (!$this->canEdit()) {
+            throw new ForbiddenHttpException('Недостаточно прав.');
+        }
         $this->findModel($id)->delete();
 
         return $this->redirect(['index']);
@@ -141,4 +150,10 @@ class AnalystsBusinessOperationsController extends Controller
 
         throw new NotFoundHttpException('The requested page does not exist.');
     }
+
+    private function canEdit(): bool
+    {
+        $admin = Admin::findOne(['id' => \Yii::$app->user->id]);
+        return $admin && (int)$admin->group_id === AdminGroup::GROUP_IT;
+    }
 }
index e4c4d344d5c745e67dfb2a4f299fae083f248e16..9d41a221fbf953f6be193e77d8d4b4cf3b80b5eb 100644 (file)
@@ -2,6 +2,9 @@
 
 namespace app\controllers;
 
+use yii\web\ForbiddenHttpException;
+use yii_app\records\Admin;
+use yii_app\records\AdminGroup;
 use yii_app\records\AnalystsBusinessOperationsTypes;
 use yii\data\ActiveDataProvider;
 use yii\web\Controller;
@@ -101,6 +104,9 @@ class AnalystsBusinessOperationsTypesController extends Controller
      */
     public function actionUpdate($id)
     {
+        if (!$this->canEdit()) {
+            throw new ForbiddenHttpException('Недостаточно прав.');
+        }
         $model = $this->findModel($id);
 
         if ($this->request->isPost && $model->load($this->request->post()) && $model->save()) {
@@ -121,6 +127,9 @@ class AnalystsBusinessOperationsTypesController extends Controller
      */
     public function actionDelete($id)
     {
+        if (!$this->canEdit()) {
+            throw new ForbiddenHttpException('Недостаточно прав.');
+        }
         $this->findModel($id)->delete();
 
         return $this->redirect(['index']);
@@ -141,4 +150,10 @@ class AnalystsBusinessOperationsTypesController extends Controller
 
         throw new NotFoundHttpException('The requested page does not exist.');
     }
+
+    private function canEdit(): bool
+    {
+        $admin = Admin::findOne(['id' => \Yii::$app->user->id]);
+        return $admin && (int)$admin->group_id === AdminGroup::GROUP_IT;
+    }
 }
index eeec3b09c74d1c228e36798584017157939c61fe..30d14411276a4422e239fdd9f01a7cec57d66db2 100644 (file)
@@ -1,5 +1,8 @@
 <?php
 
+use yii_app\records\Admin;
+use yii_app\records\AdminGroup;
+use yii_app\records\AnalystsBusinessOperations;
 use yii_app\records\AnalystsBusinessOperationsTypes;
 use yii\helpers\Html;
 use yii\helpers\Url;
@@ -11,15 +14,13 @@ use yii\grid\GridView;
 
 $this->title = 'Типы бизнес операций из 1С';
 $this->params['breadcrumbs'][] = $this->title;
+$admin = Admin::findOne(['id' => Yii::$app->user->id]);
+$isIt  = $admin && (int)$admin->group_id === AdminGroup::GROUP_IT;
 ?>
 <div class="analysts-business-operations-types-index p-4">
 
     <h1><?= Html::encode($this->title) ?></h1>
 
-    <p>
-        <?= Html::a('Создать тип', ['create'], ['class' => 'btn btn-success']) ?>
-    </p>
-
 
     <?= GridView::widget([
         'dataProvider' => $dataProvider,
@@ -32,9 +33,19 @@ $this->params['breadcrumbs'][] = $this->title;
             'created_at',
             [
                 'class' => ActionColumn::class,
-                'urlCreator' => function ($action, AnalystsBusinessOperationsTypes $model, $key, $index, $column) {
-                    return Url::toRoute([$action, 'id' => $model->id]);
-                 }
+                'template' => '{view} {update} {delete}',
+                'visibleButtons' => [
+                    'update' => function ($model, $key, $index) use ($isIt) {
+                        return $isIt;
+                    },
+                    'delete' => function ($model, $key, $index) use ($isIt) {
+                        return $isIt;
+                    },
+
+                ],
+                'urlCreator' => function ($action, AnalystsBusinessOperationsTypes $model) {
+                    return Url::to([$action, 'id' => $model->id]);
+                },
             ],
         ],
     ]); ?>
index 696032f707ed4d08bd2994f1cc835967e172c3a4..7f3854523f548a89c446de23361d9bb7c09751d7 100644 (file)
@@ -1,5 +1,7 @@
 <?php
 
+use yii_app\records\Admin;
+use yii_app\records\AdminGroup;
 use yii_app\records\AnalystsBusinessOperations;
 use yii\helpers\Html;
 use yii\helpers\Url;
@@ -11,6 +13,8 @@ use yii\grid\GridView;
 
 $this->title = 'Аналитика хозяйственных операций';
 $this->params['breadcrumbs'][] = $this->title;
+$admin = Admin::findOne(['id' => Yii::$app->user->id]);
+$isIt  = $admin && (int)$admin->group_id === AdminGroup::GROUP_IT;
 ?>
 <div class="analysts-business-operations-index p-4">
 
@@ -35,10 +39,19 @@ $this->params['breadcrumbs'][] = $this->title;
             'type_id',
             'created_at',
             [
-                'class' => ActionColumn::class,
-                'urlCreator' => function ($action, AnalystsBusinessOperations $model, $key, $index, $column) {
-                    return Url::toRoute([$action, 'id' => $model->id]);
-                 }
+                'class' => \yii\grid\ActionColumn::class,
+                'template' => '{view} {update} {delete}',
+                'visibleButtons' => [
+                    'update' => function ($model, $key, $index) use ($isIt) {
+                        return $isIt;
+                    },
+                    'delete' => function ($model, $key, $index) use ($isIt) {
+                        return $isIt;
+                    },
+                ],
+                'urlCreator' => function ($action, AnalystsBusinessOperations $model) {
+                    return Url::to([$action, 'id' => $model->id]);
+                },
             ],
         ],
     ]); ?>