From 0a89ff9be91625094c0f0c9b2a5c0f5f8bfb71e6 Mon Sep 17 00:00:00 2001 From: Vladimir Fomichev Date: Mon, 25 Aug 2025 18:12:09 +0300 Subject: [PATCH] =?utf8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD?= =?utf8?q?=D0=B8=D0=B5=20=D0=BE=D0=BF=D0=B5=D1=80=D0=B0=D1=86=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- erp24/api2/controllers/DataController.php | 26 +++- .../AnalystsBusinessOperationsController.php | 144 ++++++++++++++++++ erp24/controllers/CronController.php | 1 + ...ate_analysts_business_operations_table.php | 41 +++++ erp24/records/AnalystsBusinessOperations.php | 58 +++++++ .../analysts-business-operations/_form.php | 31 ++++ .../analysts-business-operations/create.php | 20 +++ .../analysts-business-operations/index.php | 40 +++++ .../analysts-business-operations/update.php | 21 +++ .../analysts-business-operations/view.php | 40 +++++ 10 files changed, 421 insertions(+), 1 deletion(-) create mode 100644 erp24/controllers/AnalystsBusinessOperationsController.php create mode 100644 erp24/migrations/m250825_141743_create_analysts_business_operations_table.php create mode 100644 erp24/records/AnalystsBusinessOperations.php create mode 100644 erp24/views/analysts-business-operations/_form.php create mode 100644 erp24/views/analysts-business-operations/create.php create mode 100644 erp24/views/analysts-business-operations/index.php create mode 100644 erp24/views/analysts-business-operations/update.php create mode 100644 erp24/views/analysts-business-operations/view.php diff --git a/erp24/api2/controllers/DataController.php b/erp24/api2/controllers/DataController.php index 7d87c66f..7d487a2b 100644 --- a/erp24/api2/controllers/DataController.php +++ b/erp24/api2/controllers/DataController.php @@ -11,6 +11,7 @@ use yii_app\helpers\ClientHelper; use yii_app\helpers\SalaryHelper; use yii_app\records\Admin; use yii_app\records\AdminGroup; +use yii_app\records\AnalystsBusinessOperations; use yii_app\records\ApiCron; use yii_app\records\Assemblies; use yii_app\records\Balances; @@ -2550,13 +2551,36 @@ class DataController extends BaseController } } + + if (!empty($result['analysts_business_operations'])) { + $existingOperations = AnalystsBusinessOperations::find() + ->select(['id']) + ->column(); + foreach ($result["analysts_business_operations"] as $operation) { + if (!in_array($operation['guid'], $existingOperations)) { + $newOperation = new AnalystsBusinessOperations(); + $newOperation->id = $operation['guid']; + $newOperation->name = $operation['name']; + $newOperation->type = $operation['type']; + if (!$newOperation->save()) { + LogService::apiErrorLog( + json_encode( + ["error_id" => 44, "error" => $newOperation->getErrors()], + JSON_UNESCAPED_UNICODE + ) + ); + } + } + + } + } $mess['line'][] = __LINE__; } catch (Exception $e) { LogService::apiDataLogs(1, json_encode($mess, JSON_UNESCAPED_UNICODE), $requestIdText); file_put_contents(self::OUT_DIR . '/log_error.txt', PHP_EOL . date("d.m.Y H:i:s", time()) . $e->getMessage() . " " . $e->getLine(), FILE_APPEND); Yii::error('Ошибка upload - блок catch '. json_encode($e->getMessage() . " " . $e->getLine(), JSON_UNESCAPED_UNICODE)); LogService::apiErrorLog(json_encode([ - "error_id" => 44, + "error_id" => 45, "error" => "Ошибка загрузки " . $e->getMessage() . " " . $e->getLine(), ], JSON_UNESCAPED_UNICODE)); } finally { diff --git a/erp24/controllers/AnalystsBusinessOperationsController.php b/erp24/controllers/AnalystsBusinessOperationsController.php new file mode 100644 index 00000000..8b27fe5e --- /dev/null +++ b/erp24/controllers/AnalystsBusinessOperationsController.php @@ -0,0 +1,144 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['POST'], + ], + ], + ] + ); + } + + /** + * Lists all AnalystsBusinessOperations models. + * + * @return string + */ + public function actionIndex() + { + $dataProvider = new ActiveDataProvider([ + 'query' => AnalystsBusinessOperations::find(), + /* + 'pagination' => [ + 'pageSize' => 50 + ], + 'sort' => [ + 'defaultOrder' => [ + 'id' => SORT_DESC, + ] + ], + */ + ]); + + return $this->render('index', [ + 'dataProvider' => $dataProvider, + ]); + } + + /** + * Displays a single AnalystsBusinessOperations model. + * @param string $id + * @return string + * @throws NotFoundHttpException if the model cannot be found + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new AnalystsBusinessOperations model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return string|\yii\web\Response + */ + public function actionCreate() + { + $model = new AnalystsBusinessOperations(); + + if ($this->request->isPost) { + if ($model->load($this->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id]); + } + } else { + $model->loadDefaultValues(); + } + + return $this->render('create', [ + 'model' => $model, + ]); + } + + /** + * Updates an existing AnalystsBusinessOperations model. + * If update is successful, the browser will be redirected to the 'view' page. + * @param string $id + * @return string|\yii\web\Response + * @throws NotFoundHttpException if the model cannot be found + */ + public function actionUpdate($id) + { + $model = $this->findModel($id); + + if ($this->request->isPost && $model->load($this->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id]); + } + + return $this->render('update', [ + 'model' => $model, + ]); + } + + /** + * Deletes an existing AnalystsBusinessOperations model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * @param string $id + * @return \yii\web\Response + * @throws NotFoundHttpException if the model cannot be found + */ + public function actionDelete($id) + { + $this->findModel($id)->delete(); + + return $this->redirect(['index']); + } + + /** + * Finds the AnalystsBusinessOperations model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param string $id + * @return AnalystsBusinessOperations the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = AnalystsBusinessOperations::findOne(['id' => $id])) !== null) { + return $model; + } + + throw new NotFoundHttpException('The requested page does not exist.'); + } +} diff --git a/erp24/controllers/CronController.php b/erp24/controllers/CronController.php index d04fe80e..8dfea03f 100644 --- a/erp24/controllers/CronController.php +++ b/erp24/controllers/CronController.php @@ -24,6 +24,7 @@ class CronController extends Controller "employee" => ["name" => "Физ лица в 1с - продавцы"], "prices" => ["name" => "Типы цен", "array" => ["type_price" => "Розничная цена"]], "checks_dell" => ["name" => "Удаление чеков"], + "analysts_business_operations" => ["name" => "Аналитика хозяйственных операций"], "checks" => [ "name" => "Чеки-продажи", "array" => [ diff --git a/erp24/migrations/m250825_141743_create_analysts_business_operations_table.php b/erp24/migrations/m250825_141743_create_analysts_business_operations_table.php new file mode 100644 index 00000000..2d97f8d6 --- /dev/null +++ b/erp24/migrations/m250825_141743_create_analysts_business_operations_table.php @@ -0,0 +1,41 @@ +db->getTableSchema(self::TABLE_NAME); + + if (!isset($tableSchema)) { + $this->createTable(self::TABLE_NAME, [ + 'id' => $this->string()->notNull()->unique()->comment('GUID аналитики'), + 'name' => $this->string()->notNull()->comment('Название аналитики'), + 'type' => $this->integer()->notNull()->comment('Вид использования хозяйственной операции'), + 'type_id' => $this->string()->null()->comment('ID Вида'), + 'created_at' => $this->dateTime()->notNull()->comment('Дата создания'), + ]); + $this->addPrimaryKey('pk_analytics_id', self::TABLE_NAME, 'id'); + } + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + $tableSchema = $this->db->getTableSchema(self::TABLE_NAME); + if (isset($tableSchema)) { + $this->dropPrimaryKey('pk_analytics_id', self::TABLE_NAME); + $this->dropTable(self::TABLE_NAME); + } + } +} diff --git a/erp24/records/AnalystsBusinessOperations.php b/erp24/records/AnalystsBusinessOperations.php new file mode 100644 index 00000000..bf6193bf --- /dev/null +++ b/erp24/records/AnalystsBusinessOperations.php @@ -0,0 +1,58 @@ + null], + [['id', 'name', 'type', 'created_at'], 'required'], + [['type'], 'default', 'value' => null], + [['type'], 'integer'], + [['created_at'], 'safe'], + [['id', 'name', 'type_id'], 'string', 'max' => 255], + [['id'], 'unique'], + ]; + } + + /** + * {@inheritdoc} + */ + public function attributeLabels() + { + return [ + 'guid' => 'GUID аналитики', + 'name' => 'Название аналитики', + 'type' => 'Вид использования хозяйственной операции', + 'type_id' => 'ID Вида', + 'created_at' => 'Дата создания', + ]; + } + +} diff --git a/erp24/views/analysts-business-operations/_form.php b/erp24/views/analysts-business-operations/_form.php new file mode 100644 index 00000000..fdcf0533 --- /dev/null +++ b/erp24/views/analysts-business-operations/_form.php @@ -0,0 +1,31 @@ + + +
+ + + + field($model, 'id')->textInput(['maxlength' => true]) ?> + + field($model, 'name')->textInput(['maxlength' => true]) ?> + + field($model, 'type')->textInput() ?> + + field($model, 'type_id')->textInput(['maxlength' => true]) ?> + + field($model, 'created_at')->textInput() ?> + +
+ 'btn btn-success']) ?> +
+ + + +
diff --git a/erp24/views/analysts-business-operations/create.php b/erp24/views/analysts-business-operations/create.php new file mode 100644 index 00000000..edc44153 --- /dev/null +++ b/erp24/views/analysts-business-operations/create.php @@ -0,0 +1,20 @@ +title = 'Create Analysts Business Operations'; +$this->params['breadcrumbs'][] = ['label' => 'Analysts Business Operations', 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/erp24/views/analysts-business-operations/index.php b/erp24/views/analysts-business-operations/index.php new file mode 100644 index 00000000..0f8008b0 --- /dev/null +++ b/erp24/views/analysts-business-operations/index.php @@ -0,0 +1,40 @@ +title = 'Аналитика хозяйственных операций'; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ + + $dataProvider, + 'columns' => [ + ['class' => 'yii\grid\SerialColumn'], + + 'id', + 'name', + 'type', + 'type_id', + 'created_at', + [ + 'class' => ActionColumn::class, + 'urlCreator' => function ($action, AnalystsBusinessOperations $model, $key, $index, $column) { + return Url::toRoute([$action, 'id' => $model->id]); + } + ], + ], + ]); ?> + + +
diff --git a/erp24/views/analysts-business-operations/update.php b/erp24/views/analysts-business-operations/update.php new file mode 100644 index 00000000..5ccc4023 --- /dev/null +++ b/erp24/views/analysts-business-operations/update.php @@ -0,0 +1,21 @@ +title = 'Изменить аналитику: ' . $model->name; +$this->params['breadcrumbs'][] = ['label' => 'Analysts Business Operations', 'url' => ['index']]; +$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id]]; +$this->params['breadcrumbs'][] = 'Update'; +?> +
+ +

title) ?>

+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/erp24/views/analysts-business-operations/view.php b/erp24/views/analysts-business-operations/view.php new file mode 100644 index 00000000..b32a733c --- /dev/null +++ b/erp24/views/analysts-business-operations/view.php @@ -0,0 +1,40 @@ +title = $model->name; +$this->params['breadcrumbs'][] = ['label' => 'Analysts Business Operations', 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +\yii\web\YiiAsset::register($this); +?> +
+ +

title) ?>

+ +

+ $model->id], ['class' => 'btn btn-primary']) ?> + $model->id], [ + 'class' => 'btn btn-danger', + 'data' => [ + 'confirm' => 'Вы уверены, что хотите удалить запись?', + 'method' => 'post', + ], + ]) ?> +

+ + $model, + 'attributes' => [ + 'id', + 'name', + 'type', + 'type_id', + 'created_at', + ], + ]) ?> + +
-- 2.39.5