From f8b7c53874747085d9b3c30c391270bca62c2f7c Mon Sep 17 00:00:00 2001 From: Vladimir Fomichev Date: Tue, 26 Aug 2025 15:14:56 +0300 Subject: [PATCH] =?utf8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=B8?= =?utf8?q?=D0=B5=20=D0=BF=D1=80=D0=B0=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- erp24/api2/controllers/DataController.php | 50 +++++++++++++++++-- .../AnalystsBusinessOperationsController.php | 15 ++++++ ...lystsBusinessOperationsTypesController.php | 15 ++++++ .../index.php | 25 +++++++--- .../analysts-business-operations/index.php | 21 ++++++-- 5 files changed, 110 insertions(+), 16 deletions(-) diff --git a/erp24/api2/controllers/DataController.php b/erp24/api2/controllers/DataController.php index 1dddb361..50034b8f 100644 --- a/erp24/api2/controllers/DataController.php +++ b/erp24/api2/controllers/DataController.php @@ -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 + ) + ); + } + } + } } } diff --git a/erp24/controllers/AnalystsBusinessOperationsController.php b/erp24/controllers/AnalystsBusinessOperationsController.php index 61c0ba39..709f7cfe 100644 --- a/erp24/controllers/AnalystsBusinessOperationsController.php +++ b/erp24/controllers/AnalystsBusinessOperationsController.php @@ -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; + } } diff --git a/erp24/controllers/AnalystsBusinessOperationsTypesController.php b/erp24/controllers/AnalystsBusinessOperationsTypesController.php index e4c4d344..9d41a221 100644 --- a/erp24/controllers/AnalystsBusinessOperationsTypesController.php +++ b/erp24/controllers/AnalystsBusinessOperationsTypesController.php @@ -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; + } } diff --git a/erp24/views/analysts-business-operations-types/index.php b/erp24/views/analysts-business-operations-types/index.php index eeec3b09..30d14411 100644 --- a/erp24/views/analysts-business-operations-types/index.php +++ b/erp24/views/analysts-business-operations-types/index.php @@ -1,5 +1,8 @@ title = 'Типы бизнес операций из 1С'; $this->params['breadcrumbs'][] = $this->title; +$admin = Admin::findOne(['id' => Yii::$app->user->id]); +$isIt = $admin && (int)$admin->group_id === AdminGroup::GROUP_IT; ?>

title) ?>

-

- 'btn btn-success']) ?> -

- $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]); + }, ], ], ]); ?> diff --git a/erp24/views/analysts-business-operations/index.php b/erp24/views/analysts-business-operations/index.php index 696032f7..7f385452 100644 --- a/erp24/views/analysts-business-operations/index.php +++ b/erp24/views/analysts-business-operations/index.php @@ -1,5 +1,7 @@ title = 'Аналитика хозяйственных операций'; $this->params['breadcrumbs'][] = $this->title; +$admin = Admin::findOne(['id' => Yii::$app->user->id]); +$isIt = $admin && (int)$admin->group_id === AdminGroup::GROUP_IT; ?>
@@ -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]); + }, ], ], ]); ?> -- 2.39.5