]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Правки и загрузка
authorVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Tue, 26 Aug 2025 11:06:25 +0000 (14:06 +0300)
committerVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Tue, 26 Aug 2025 11:06:25 +0000 (14:06 +0300)
erp24/api2/controllers/DataController.php
erp24/controllers/AnalystsBusinessOperationsController.php
erp24/migrations/m250825_141743_create_analysts_business_operations_table.php
erp24/migrations/m250826_061451_add_analysts_business_operations_types_table.php
erp24/records/AnalystsBusinessOperations.php
erp24/records/AnalystsBusinessOperationsTypes.php
erp24/views/analysts-business-operations/index.php

index 7a0a4c3e52311622668b3aaa5a0f85b78bd82f3b..7a28cfb5135b0bab28bb22a0d9cd4f30b1a9c0cb 100644 (file)
@@ -68,8 +68,8 @@ class DataController extends BaseController
 
     const OUT_DIR =
 //        __DIR__ . "/../json";
-         //   "/www/api2/json";
-        "/var/www/erp24/api2/json";
+            "/www/api2/json";
+        //"/var/www/erp24/api2/json";
 
 //          "/var/www/www-root/data/www/api.bazacvetov24.ru/data/json";
     private static function getPathJson()
@@ -2566,19 +2566,22 @@ class DataController extends BaseController
                         $newOperation = new AnalystsBusinessOperations();
                         $newOperation->id = $operation['guid'];
                         $newOperation->name = $operation['name'];
-                        $newOperation->type = $operation['type'];
+                        $newOperation->type = (int)$operation['type'];
                         if (!in_array($newOperation->type, array_column($existingTypes, 'code'))) {
                             $newType = new AnalystsBusinessOperationsTypes();
-                            $newType->code = $operation['type'];
+                            $newType->code = (int)$operation['type'];
+                            $newType->name = null;
+                            $newType->created_at = date('Y-m-d H:i:s');
                             if ($newType->save()) {
                                 $newOperation->type_id = $newType->id;
                             } else {
+                                $newOperation->type_id = null;
                                Yii::error('Ошибка сохранение типа ' . json_encode($newType->getErrors(), JSON_UNESCAPED_UNICODE), __METHOD__ );
                             }
                         } else {
                             $newOperation->type_id = $existingTypes[$operation['type']]['id'];
                         }
-
+                        $newOperation->created_at = date('Y-m-d H:i:s');
                         if (!$newOperation->save()) {
                             LogService::apiErrorLog(
                                 json_encode(
index 8b27fe5e9dd90b59306cef1229d90b1e390f4da8..61c0ba39ed1178bdc72d104561314ec6ec54c810 100644 (file)
@@ -39,7 +39,7 @@ class AnalystsBusinessOperationsController extends Controller
     public function actionIndex()
     {
         $dataProvider = new ActiveDataProvider([
-            'query' => AnalystsBusinessOperations::find(),
+            'query' => AnalystsBusinessOperations::find()->with('typeRel'),
             /*
             'pagination' => [
                 'pageSize' => 50
index 9c6ead1f01bbf399d1534dd581a8cec00f65090e..a30f8a9bb505115afffcea1dc765a5196897dec2 100644 (file)
@@ -21,7 +21,7 @@ class m250825_141743_create_analysts_business_operations_table extends Migration
                 'name' => $this->string()->notNull()->comment('Название аналитики'),
                 'type' => $this->integer()->notNull()->comment('Вид использования хозяйственной операции'),
                 'type_id' => $this->integer()->null()->comment('ID Вида'),
-                'created_at' => $this->dateTime()->notNull()->comment('Дата создания'),
+                'created_at' => $this->dateTime()->notNull()->defaultExpression('NOW()'),
             ]);
             $this->addPrimaryKey('pk_analytics_id', self::TABLE_NAME, 'id');
         }
index 807070d3e1e0b663859833c245c2e1a50af150b6..7304a7c2f4c91599e7483cfff3e3ab4b9afe1515 100644 (file)
@@ -16,16 +16,14 @@ class m250826_061451_add_analysts_business_operations_types_table extends Migrat
             $this->createTable(self::TABLE_NAME, [
                 'id' => $this->primaryKey()->comment('ID типа операции'),
                 'code' => $this->integer()->notNull()->unique()->comment('Код типа (0,1,2...)'),
-                'name' => $this->string()->notNull()->comment('Название типа операции'),
+                'name' => $this->string()->null()->comment('Название типа операции'),
                 'created_at' => $this->dateTime()->notNull()->defaultExpression('NOW()'),
             ]);
-            $this->addForeignKey(
-                'fk_operations_type',
-                'analysts_business_operations',
-                'type_id',
-                'analysts_business_operations_types',
-                'id'
-            );
+            $this->batchInsert(self::TABLE_NAME, ['code', 'name'], [
+                [0, 'Оприходование'],
+                [1, 'Списание'],
+                [2, 'Пересорт'],
+            ]);
 
         }
     }
@@ -37,7 +35,6 @@ class m250826_061451_add_analysts_business_operations_types_table extends Migrat
     {
         $tableSchema = $this->db->getTableSchema(self::TABLE_NAME);
         if (isset($tableSchema)) {
-            $this->dropForeignKey('fk_operations_type', self::TABLE_NAME);
             $this->dropTable(self::TABLE_NAME);
         }
     }
index bf6193bff27cedd40b2f3bb00611c2d7e56fc6af..d8689144d9c1ad61d46d6822c9aef49b14f8f7dc 100644 (file)
@@ -10,7 +10,7 @@ use Yii;
  * @property string $id GUID аналитики
  * @property string $name Название аналитики
  * @property int $type Вид использования хозяйственной операции
- * @property string|null $type_id ID Вида
+ * @property int|null $type_id ID Вида
  * @property string $created_at Дата создания
  */
 class AnalystsBusinessOperations extends \yii\db\ActiveRecord
@@ -34,9 +34,9 @@ class AnalystsBusinessOperations extends \yii\db\ActiveRecord
             [['type_id'], 'default', 'value' => null],
             [['id', 'name', 'type', 'created_at'], 'required'],
             [['type'], 'default', 'value' => null],
-            [['type'], 'integer'],
+            [['type', 'type_id'], 'integer'],
             [['created_at'], 'safe'],
-            [['id', 'name', 'type_id'], 'string', 'max' => 255],
+            [['id', 'name'], 'string', 'max' => 255],
             [['id'], 'unique'],
         ];
     }
@@ -55,4 +55,9 @@ class AnalystsBusinessOperations extends \yii\db\ActiveRecord
         ];
     }
 
+    public function getTypeRel()
+    {
+        return $this->hasOne(AnalystsBusinessOperationsTypes::class, ['id' => 'type_id']);
+    }
+
 }
index d22ee85d9e098f724d1e1700a7327d6da2116dbd..0745a64f5310747f1b72cdc4b5254249996a5d23 100644 (file)
@@ -9,7 +9,7 @@ use Yii;
  *
  * @property int $id ID типа операции
  * @property int $code Код типа (0,1,2...)
- * @property string $name Название типа операции
+ * @property string|null $name Название типа операции
  * @property string $created_at
  *
  * @property AnalystsBusinessOperations[] $analystsBusinessOperations
@@ -33,7 +33,7 @@ class AnalystsBusinessOperationsTypes extends \yii\db\ActiveRecord
     {
         return [
             [['code'], 'required'],
-            [['code'], 'default', 'value' => null],
+            [['name'], 'default', 'value' => null],
             [['code'], 'integer'],
             [['created_at'], 'safe'],
             [['name'], 'string', 'max' => 255],
@@ -59,9 +59,9 @@ class AnalystsBusinessOperationsTypes extends \yii\db\ActiveRecord
      *
      * @return \yii\db\ActiveQuery
      */
-    public function getAnalystsBusinessOperations()
+    public function getTypeRel()
     {
-        return $this->hasMany(AnalystsBusinessOperations::class, ['type_id' => 'id']);
+        return $this->hasOne(AnalystsBusinessOperationsTypes::class, ['id' => 'type_id']);
     }
 
 }
index 0f8008b065f8fd410163d49f02a3d111ae69c1a0..696032f707ed4d08bd2994f1cc835967e172c3a4 100644 (file)
@@ -24,6 +24,13 @@ $this->params['breadcrumbs'][] = $this->title;
 
             'id',
             'name',
+            [
+                'attribute' => 'type_id',
+                'label' => 'Тип (из справочника)',
+                'value' => function ($model) {
+                    return $model->typeRel->name ?? '—';
+                },
+            ],
             'type',
             'type_id',
             'created_at',