]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Обработка в DataController
authorVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Tue, 26 Aug 2025 09:41:19 +0000 (12:41 +0300)
committerVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Tue, 26 Aug 2025 09:41:19 +0000 (12:41 +0300)
erp24/api2/controllers/DataController.php
erp24/commands/MarketplaceController.php
erp24/controllers/AnalystsBusinessOperationsTypesController.php [new file with mode: 0644]
erp24/migrations/m250825_141743_create_analysts_business_operations_table.php
erp24/migrations/m250826_061451_add_analysts_business_operations_types_table.php [new file with mode: 0644]
erp24/records/AnalystsBusinessOperationsTypes.php [new file with mode: 0644]
erp24/views/analysts-business-operations-types/_form.php [new file with mode: 0644]
erp24/views/analysts-business-operations-types/create.php [new file with mode: 0644]
erp24/views/analysts-business-operations-types/index.php [new file with mode: 0644]
erp24/views/analysts-business-operations-types/update.php [new file with mode: 0644]
erp24/views/analysts-business-operations-types/view.php [new file with mode: 0644]

index 7d487a2bfcec8fcf0a2f7b986d99757b222ee155..7a0a4c3e52311622668b3aaa5a0f85b78bd82f3b 100644 (file)
@@ -12,6 +12,7 @@ use yii_app\helpers\SalaryHelper;
 use yii_app\records\Admin;
 use yii_app\records\AdminGroup;
 use yii_app\records\AnalystsBusinessOperations;
+use yii_app\records\AnalystsBusinessOperationsTypes;
 use yii_app\records\ApiCron;
 use yii_app\records\Assemblies;
 use yii_app\records\Balances;
@@ -2556,12 +2557,28 @@ class DataController extends BaseController
                 $existingOperations = AnalystsBusinessOperations::find()
                     ->select(['id'])
                     ->column();
+                $existingTypes = AnalystsBusinessOperationsTypes::find()
+                    ->indexBy('code')
+                    ->asArray()
+                    ->all();
                 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 (!in_array($newOperation->type, array_column($existingTypes, 'code'))) {
+                            $newType = new AnalystsBusinessOperationsTypes();
+                            $newType->code = $operation['type'];
+                            if ($newType->save()) {
+                                $newOperation->type_id = $newType->id;
+                            } else {
+                               Yii::error('Ошибка сохранение типа ' . json_encode($newType->getErrors(), JSON_UNESCAPED_UNICODE), __METHOD__ );
+                            }
+                        } else {
+                            $newOperation->type_id = $existingTypes[$operation['type']]['id'];
+                        }
+
                         if (!$newOperation->save()) {
                             LogService::apiErrorLog(
                                 json_encode(
@@ -2570,6 +2587,7 @@ class DataController extends BaseController
                                 )
                             );
                         }
+
                     }
 
                 }
index 1777a3bb460e17b9c741d57f11efb7719df78bb2..2573b6adfb46a252891f3d536260a7ae8e6e5bfb 100644 (file)
@@ -49,8 +49,11 @@ class MarketplaceController extends Controller
 
         $config = Configuration::getDefaultConfiguration()->setApiKey('Api-Key', Yii::$app->params['YANDEX_MARKET_API_KEY']);
 
-        $products = Products1c::find()->alias('p')->leftJoin('products_class pc', 'p.parent_id = pc.category_id')
-            ->where(['pc.tip' => [ProductsClass::MARKETPLACE, ProductsClass::MARKETPLACE_ADDITIONAL]])->all();
+        $products = Products1c::find()
+            ->alias('p')
+            ->leftJoin('products_class pc', 'p.parent_id = pc.category_id')
+            ->where(['pc.tip' => [ProductsClass::MARKETPLACE, ProductsClass::MARKETPLACE_ADDITIONAL]])
+            ->all();
         $matrixErp = MatrixErp::find()->where(['guid' => ArrayHelper::getColumn($products, 'id')])->all();
         $matrixErpByGuid = [];
         $hiddenOfferings = [];
diff --git a/erp24/controllers/AnalystsBusinessOperationsTypesController.php b/erp24/controllers/AnalystsBusinessOperationsTypesController.php
new file mode 100644 (file)
index 0000000..e4c4d34
--- /dev/null
@@ -0,0 +1,144 @@
+<?php
+
+namespace app\controllers;
+
+use yii_app\records\AnalystsBusinessOperationsTypes;
+use yii\data\ActiveDataProvider;
+use yii\web\Controller;
+use yii\web\NotFoundHttpException;
+use yii\filters\VerbFilter;
+
+/**
+ * AnalystsBusinessOperationsTypesController implements the CRUD actions for AnalystsBusinessOperationsTypes model.
+ */
+class AnalystsBusinessOperationsTypesController extends Controller
+{
+    /**
+     * @inheritDoc
+     */
+    public function behaviors()
+    {
+        return array_merge(
+            parent::behaviors(),
+            [
+                'verbs' => [
+                    'class' => VerbFilter::className(),
+                    'actions' => [
+                        'delete' => ['POST'],
+                    ],
+                ],
+            ]
+        );
+    }
+
+    /**
+     * Lists all AnalystsBusinessOperationsTypes models.
+     *
+     * @return string
+     */
+    public function actionIndex()
+    {
+        $dataProvider = new ActiveDataProvider([
+            'query' => AnalystsBusinessOperationsTypes::find(),
+            /*
+            'pagination' => [
+                'pageSize' => 50
+            ],
+            'sort' => [
+                'defaultOrder' => [
+                    'id' => SORT_DESC,
+                ]
+            ],
+            */
+        ]);
+
+        return $this->render('index', [
+            'dataProvider' => $dataProvider,
+        ]);
+    }
+
+    /**
+     * Displays a single AnalystsBusinessOperationsTypes model.
+     * @param int $id 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 AnalystsBusinessOperationsTypes model.
+     * If creation is successful, the browser will be redirected to the 'view' page.
+     * @return string|\yii\web\Response
+     */
+    public function actionCreate()
+    {
+        $model = new AnalystsBusinessOperationsTypes();
+
+        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 AnalystsBusinessOperationsTypes model.
+     * If update is successful, the browser will be redirected to the 'view' page.
+     * @param int $id 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 AnalystsBusinessOperationsTypes model.
+     * If deletion is successful, the browser will be redirected to the 'index' page.
+     * @param int $id 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 AnalystsBusinessOperationsTypes model based on its primary key value.
+     * If the model is not found, a 404 HTTP exception will be thrown.
+     * @param int $id ID
+     * @return AnalystsBusinessOperationsTypes the loaded model
+     * @throws NotFoundHttpException if the model cannot be found
+     */
+    protected function findModel($id)
+    {
+        if (($model = AnalystsBusinessOperationsTypes::findOne(['id' => $id])) !== null) {
+            return $model;
+        }
+
+        throw new NotFoundHttpException('The requested page does not exist.');
+    }
+}
index 2d97f8d6bbc4255f1130f1d7baa7106b3af18827..9c6ead1f01bbf399d1534dd581a8cec00f65090e 100644 (file)
@@ -20,7 +20,7 @@ class m250825_141743_create_analysts_business_operations_table extends Migration
                 'id' => $this->string()->notNull()->unique()->comment('GUID аналитики'),
                 'name' => $this->string()->notNull()->comment('Название аналитики'),
                 'type' => $this->integer()->notNull()->comment('Вид использования хозяйственной операции'),
-                'type_id' => $this->string()->null()->comment('ID Вида'),
+                'type_id' => $this->integer()->null()->comment('ID Вида'),
                 'created_at' => $this->dateTime()->notNull()->comment('Дата создания'),
             ]);
             $this->addPrimaryKey('pk_analytics_id', self::TABLE_NAME, 'id');
diff --git a/erp24/migrations/m250826_061451_add_analysts_business_operations_types_table.php b/erp24/migrations/m250826_061451_add_analysts_business_operations_types_table.php
new file mode 100644 (file)
index 0000000..807070d
--- /dev/null
@@ -0,0 +1,58 @@
+<?php
+
+use yii\db\Migration;
+
+class m250826_061451_add_analysts_business_operations_types_table extends Migration
+{
+    const TABLE_NAME = 'erp24.analysts_business_operations_types';
+    /**
+     * {@inheritdoc}
+     */
+    public function safeUp()
+    {
+        $tableSchema = $this->db->getTableSchema(self::TABLE_NAME);
+
+        if (!isset($tableSchema)) {
+            $this->createTable(self::TABLE_NAME, [
+                'id' => $this->primaryKey()->comment('ID типа операции'),
+                'code' => $this->integer()->notNull()->unique()->comment('Код типа (0,1,2...)'),
+                'name' => $this->string()->notNull()->comment('Название типа операции'),
+                'created_at' => $this->dateTime()->notNull()->defaultExpression('NOW()'),
+            ]);
+            $this->addForeignKey(
+                'fk_operations_type',
+                'analysts_business_operations',
+                'type_id',
+                'analysts_business_operations_types',
+                'id'
+            );
+
+        }
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function safeDown()
+    {
+        $tableSchema = $this->db->getTableSchema(self::TABLE_NAME);
+        if (isset($tableSchema)) {
+            $this->dropForeignKey('fk_operations_type', self::TABLE_NAME);
+            $this->dropTable(self::TABLE_NAME);
+        }
+    }
+    /*
+    // Use up()/down() to run migration code without a transaction.
+    public function up()
+    {
+
+    }
+
+    public function down()
+    {
+        echo "m250826_061451_add_analysts_business_operations_types_table cannot be reverted.\n";
+
+        return false;
+    }
+    */
+}
diff --git a/erp24/records/AnalystsBusinessOperationsTypes.php b/erp24/records/AnalystsBusinessOperationsTypes.php
new file mode 100644 (file)
index 0000000..d22ee85
--- /dev/null
@@ -0,0 +1,67 @@
+<?php
+
+namespace yii_app\records;
+
+use Yii;
+
+/**
+ * This is the model class for table "analysts_business_operations_types".
+ *
+ * @property int $id ID типа операции
+ * @property int $code Код типа (0,1,2...)
+ * @property string $name Название типа операции
+ * @property string $created_at
+ *
+ * @property AnalystsBusinessOperations[] $analystsBusinessOperations
+ */
+class AnalystsBusinessOperationsTypes extends \yii\db\ActiveRecord
+{
+
+
+    /**
+     * {@inheritdoc}
+     */
+    public static function tableName()
+    {
+        return 'analysts_business_operations_types';
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function rules()
+    {
+        return [
+            [['code'], 'required'],
+            [['code'], 'default', 'value' => null],
+            [['code'], 'integer'],
+            [['created_at'], 'safe'],
+            [['name'], 'string', 'max' => 255],
+            [['code'], 'unique'],
+        ];
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function attributeLabels()
+    {
+        return [
+            'id' => 'ID',
+            'code' => 'Code',
+            'name' => 'Name',
+            'created_at' => 'Created At',
+        ];
+    }
+
+    /**
+     * Gets query for [[AnalystsBusinessOperations]].
+     *
+     * @return \yii\db\ActiveQuery
+     */
+    public function getAnalystsBusinessOperations()
+    {
+        return $this->hasMany(AnalystsBusinessOperations::class, ['type_id' => 'id']);
+    }
+
+}
diff --git a/erp24/views/analysts-business-operations-types/_form.php b/erp24/views/analysts-business-operations-types/_form.php
new file mode 100644 (file)
index 0000000..563dab3
--- /dev/null
@@ -0,0 +1,27 @@
+<?php
+
+use yii\helpers\Html;
+use yii\widgets\ActiveForm;
+
+/** @var yii\web\View $this */
+/** @var yii_app\records\AnalystsBusinessOperationsTypes $model */
+/** @var yii\widgets\ActiveForm $form */
+?>
+
+<div class="analysts-business-operations-types-form">
+
+    <?php $form = ActiveForm::begin(); ?>
+
+    <?= $form->field($model, 'code')->textInput() ?>
+
+    <?= $form->field($model, 'name')->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-types/create.php b/erp24/views/analysts-business-operations-types/create.php
new file mode 100644 (file)
index 0000000..cd09ac6
--- /dev/null
@@ -0,0 +1,20 @@
+<?php
+
+use yii\helpers\Html;
+
+/** @var yii\web\View $this */
+/** @var yii_app\records\AnalystsBusinessOperationsTypes $model */
+
+$this->title = 'Создать тип ';
+$this->params['breadcrumbs'][] = ['label' => 'Analysts Business Operations Types', 'url' => ['index']];
+$this->params['breadcrumbs'][] = $this->title;
+?>
+<div class="analysts-business-operations-types-create p-4">
+
+    <h1><?= Html::encode($this->title) ?></h1>
+
+    <?= $this->render('_form', [
+        'model' => $model,
+    ]) ?>
+
+</div>
diff --git a/erp24/views/analysts-business-operations-types/index.php b/erp24/views/analysts-business-operations-types/index.php
new file mode 100644 (file)
index 0000000..eeec3b0
--- /dev/null
@@ -0,0 +1,43 @@
+<?php
+
+use yii_app\records\AnalystsBusinessOperationsTypes;
+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 = 'Типы бизнес операций из 1С';
+$this->params['breadcrumbs'][] = $this->title;
+?>
+<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,
+        'columns' => [
+            ['class' => 'yii\grid\SerialColumn'],
+
+            'id',
+            'code',
+            'name',
+            'created_at',
+            [
+                'class' => ActionColumn::class,
+                'urlCreator' => function ($action, AnalystsBusinessOperationsTypes $model, $key, $index, $column) {
+                    return Url::toRoute([$action, 'id' => $model->id]);
+                 }
+            ],
+        ],
+    ]); ?>
+
+
+</div>
diff --git a/erp24/views/analysts-business-operations-types/update.php b/erp24/views/analysts-business-operations-types/update.php
new file mode 100644 (file)
index 0000000..99b7931
--- /dev/null
@@ -0,0 +1,21 @@
+<?php
+
+use yii\helpers\Html;
+
+/** @var yii\web\View $this */
+/** @var yii_app\records\AnalystsBusinessOperationsTypes $model */
+
+$this->title = 'Изменить тип: ' . $model->name;
+$this->params['breadcrumbs'][] = ['label' => 'Analysts Business Operations Types', 'url' => ['index']];
+$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id]];
+$this->params['breadcrumbs'][] = 'Update';
+?>
+<div class="analysts-business-operations-types-update p-4">
+
+    <h1><?= Html::encode($this->title) ?></h1>
+
+    <?= $this->render('_form', [
+        'model' => $model,
+    ]) ?>
+
+</div>
diff --git a/erp24/views/analysts-business-operations-types/view.php b/erp24/views/analysts-business-operations-types/view.php
new file mode 100644 (file)
index 0000000..c7e44f0
--- /dev/null
@@ -0,0 +1,39 @@
+<?php
+
+use yii\helpers\Html;
+use yii\widgets\DetailView;
+
+/** @var yii\web\View $this */
+/** @var yii_app\records\AnalystsBusinessOperationsTypes $model */
+
+$this->title = $model->name;
+$this->params['breadcrumbs'][] = ['label' => 'Analysts Business Operations Types', 'url' => ['index']];
+$this->params['breadcrumbs'][] = $this->title;
+\yii\web\YiiAsset::register($this);
+?>
+<div class="analysts-business-operations-types-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',
+            'code',
+            'name',
+            'created_at',
+        ],
+    ]) ?>
+
+</div>