]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Добавление операций
authorVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Mon, 25 Aug 2025 15:12:09 +0000 (18:12 +0300)
committerVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Mon, 25 Aug 2025 15:12:09 +0000 (18:12 +0300)
erp24/api2/controllers/DataController.php
erp24/controllers/AnalystsBusinessOperationsController.php [new file with mode: 0644]
erp24/controllers/CronController.php
erp24/migrations/m250825_141743_create_analysts_business_operations_table.php [new file with mode: 0644]
erp24/records/AnalystsBusinessOperations.php [new file with mode: 0644]
erp24/views/analysts-business-operations/_form.php [new file with mode: 0644]
erp24/views/analysts-business-operations/create.php [new file with mode: 0644]
erp24/views/analysts-business-operations/index.php [new file with mode: 0644]
erp24/views/analysts-business-operations/update.php [new file with mode: 0644]
erp24/views/analysts-business-operations/view.php [new file with mode: 0644]

index 7d87c66fad606bdc7fca872b981a9a18fd23dff0..7d487a2bfcec8fcf0a2f7b986d99757b222ee155 100644 (file)
@@ -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 (file)
index 0000000..8b27fe5
--- /dev/null
@@ -0,0 +1,144 @@
+<?php
+
+namespace app\controllers;
+
+use yii_app\records\AnalystsBusinessOperations;
+use yii\data\ActiveDataProvider;
+use yii\web\Controller;
+use yii\web\NotFoundHttpException;
+use yii\filters\VerbFilter;
+
+/**
+ * AnalystsBusinessOperationsController implements the CRUD actions for AnalystsBusinessOperations model.
+ */
+class AnalystsBusinessOperationsController extends Controller
+{
+    /**
+     * @inheritDoc
+     */
+    public function behaviors()
+    {
+        return array_merge(
+            parent::behaviors(),
+            [
+                'verbs' => [
+                    '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.');
+    }
+}
index d04fe80ec1cc7ed52a90103aa140377bbe88d846..8dfea03f7329e19a26ad4e2c2dcf9d0cae005b4e 100644 (file)
@@ -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 (file)
index 0000000..2d97f8d
--- /dev/null
@@ -0,0 +1,41 @@
+<?php
+
+use yii\db\Migration;
+
+/**
+ * Handles the creation of table `{{%analysts_business_operations}}`.
+ */
+class m250825_141743_create_analysts_business_operations_table extends Migration
+{
+    const TABLE_NAME = 'erp24.analysts_business_operations';
+    /**
+     * {@inheritdoc}
+     */
+    public function safeUp()
+    {
+        $tableSchema = $this->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 (file)
index 0000000..bf6193b
--- /dev/null
@@ -0,0 +1,58 @@
+<?php
+
+namespace yii_app\records;
+
+use Yii;
+
+/**
+ * This is the model class for table "analysts_business_operations".
+ *
+ * @property string $id GUID аналитики
+ * @property string $name Название аналитики
+ * @property int $type Вид использования хозяйственной операции
+ * @property string|null $type_id ID Вида
+ * @property string $created_at Дата создания
+ */
+class AnalystsBusinessOperations extends \yii\db\ActiveRecord
+{
+
+
+    /**
+     * {@inheritdoc}
+     */
+    public static function tableName()
+    {
+        return 'analysts_business_operations';
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function rules()
+    {
+        return [
+            [['type_id'], 'default', 'value' => 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 (file)
index 0000000..fdcf053
--- /dev/null
@@ -0,0 +1,31 @@
+<?php
+
+use yii\helpers\Html;
+use yii\widgets\ActiveForm;
+
+/** @var yii\web\View $this */
+/** @var yii_app\records\AnalystsBusinessOperations $model */
+/** @var yii\widgets\ActiveForm $form */
+?>
+
+<div class="analysts-business-operations-form">
+
+    <?php $form = ActiveForm::begin(); ?>
+
+    <?= $form->field($model, 'id')->textInput(['maxlength' => true]) ?>
+
+    <?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>
+
+    <?= $form->field($model, 'type')->textInput() ?>
+
+    <?= $form->field($model, 'type_id')->textInput(['maxlength' => true]) ?>
+
+    <?= $form->field($model, 'created_at')->textInput() ?>
+
+    <div class="form-group">
+        <?= Html::submitButton('Save', ['class' => 'btn btn-success']) ?>
+    </div>
+
+    <?php ActiveForm::end(); ?>
+
+</div>
diff --git a/erp24/views/analysts-business-operations/create.php b/erp24/views/analysts-business-operations/create.php
new file mode 100644 (file)
index 0000000..edc4415
--- /dev/null
@@ -0,0 +1,20 @@
+<?php
+
+use yii\helpers\Html;
+
+/** @var yii\web\View $this */
+/** @var yii_app\records\AnalystsBusinessOperations $model */
+
+$this->title = 'Create Analysts Business Operations';
+$this->params['breadcrumbs'][] = ['label' => 'Analysts Business Operations', 'url' => ['index']];
+$this->params['breadcrumbs'][] = $this->title;
+?>
+<div class="analysts-business-operations-create">
+
+    <h1><?= Html::encode($this->title) ?></h1>
+
+    <?= $this->render('_form', [
+        'model' => $model,
+    ]) ?>
+
+</div>
diff --git a/erp24/views/analysts-business-operations/index.php b/erp24/views/analysts-business-operations/index.php
new file mode 100644 (file)
index 0000000..0f8008b
--- /dev/null
@@ -0,0 +1,40 @@
+<?php
+
+use yii_app\records\AnalystsBusinessOperations;
+use yii\helpers\Html;
+use yii\helpers\Url;
+use yii\grid\ActionColumn;
+use yii\grid\GridView;
+
+/** @var yii\web\View $this */
+/** @var yii\data\ActiveDataProvider $dataProvider */
+
+$this->title = 'Аналитика хозяйственных операций';
+$this->params['breadcrumbs'][] = $this->title;
+?>
+<div class="analysts-business-operations-index p-4">
+
+    <h1><?= Html::encode($this->title) ?></h1>
+
+
+    <?= GridView::widget([
+        'dataProvider' => $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]);
+                 }
+            ],
+        ],
+    ]); ?>
+
+
+</div>
diff --git a/erp24/views/analysts-business-operations/update.php b/erp24/views/analysts-business-operations/update.php
new file mode 100644 (file)
index 0000000..5ccc402
--- /dev/null
@@ -0,0 +1,21 @@
+<?php
+
+use yii\helpers\Html;
+
+/** @var yii\web\View $this */
+/** @var yii_app\records\AnalystsBusinessOperations $model */
+
+$this->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';
+?>
+<div class="analysts-business-operations-update p-4">
+
+    <h1><?= Html::encode($this->title) ?></h1>
+
+    <?= $this->render('_form', [
+        'model' => $model,
+    ]) ?>
+
+</div>
diff --git a/erp24/views/analysts-business-operations/view.php b/erp24/views/analysts-business-operations/view.php
new file mode 100644 (file)
index 0000000..b32a733
--- /dev/null
@@ -0,0 +1,40 @@
+<?php
+
+use yii\helpers\Html;
+use yii\widgets\DetailView;
+
+/** @var yii\web\View $this */
+/** @var yii_app\records\AnalystsBusinessOperations $model */
+
+$this->title = $model->name;
+$this->params['breadcrumbs'][] = ['label' => 'Analysts Business Operations', 'url' => ['index']];
+$this->params['breadcrumbs'][] = $this->title;
+\yii\web\YiiAsset::register($this);
+?>
+<div class="analysts-business-operations-view p-4">
+
+    <h1><?= Html::encode($this->title) ?></h1>
+
+    <p>
+        <?= Html::a('Изменить', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
+        <?= Html::a('Удалить', ['delete', 'id' => $model->id], [
+            'class' => 'btn btn-danger',
+            'data' => [
+                'confirm' => 'Вы уверены, что хотите удалить запись?',
+                'method' => 'post',
+            ],
+        ]) ?>
+    </p>
+
+    <?= DetailView::widget([
+        'model' => $model,
+        'attributes' => [
+            'id',
+            'name',
+            'type',
+            'type_id',
+            'created_at',
+        ],
+    ]) ?>
+
+</div>