From b7ca9f16d4739f9c9836388f73545d762625f695 Mon Sep 17 00:00:00 2001 From: Vladimir Fomichev Date: Tue, 26 Aug 2025 14:06:25 +0300 Subject: [PATCH] =?utf8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20=D0=B8=20?= =?utf8?q?=D0=B7=D0=B0=D0=B3=D1=80=D1=83=D0=B7=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- erp24/api2/controllers/DataController.php | 13 ++++++++----- .../AnalystsBusinessOperationsController.php | 2 +- ..._create_analysts_business_operations_table.php | 2 +- ...d_analysts_business_operations_types_table.php | 15 ++++++--------- erp24/records/AnalystsBusinessOperations.php | 11 ++++++++--- erp24/records/AnalystsBusinessOperationsTypes.php | 8 ++++---- .../views/analysts-business-operations/index.php | 7 +++++++ 7 files changed, 35 insertions(+), 23 deletions(-) diff --git a/erp24/api2/controllers/DataController.php b/erp24/api2/controllers/DataController.php index 7a0a4c3e..7a28cfb5 100644 --- a/erp24/api2/controllers/DataController.php +++ b/erp24/api2/controllers/DataController.php @@ -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( diff --git a/erp24/controllers/AnalystsBusinessOperationsController.php b/erp24/controllers/AnalystsBusinessOperationsController.php index 8b27fe5e..61c0ba39 100644 --- a/erp24/controllers/AnalystsBusinessOperationsController.php +++ b/erp24/controllers/AnalystsBusinessOperationsController.php @@ -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 diff --git a/erp24/migrations/m250825_141743_create_analysts_business_operations_table.php b/erp24/migrations/m250825_141743_create_analysts_business_operations_table.php index 9c6ead1f..a30f8a9b 100644 --- a/erp24/migrations/m250825_141743_create_analysts_business_operations_table.php +++ b/erp24/migrations/m250825_141743_create_analysts_business_operations_table.php @@ -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'); } 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 index 807070d3..7304a7c2 100644 --- a/erp24/migrations/m250826_061451_add_analysts_business_operations_types_table.php +++ b/erp24/migrations/m250826_061451_add_analysts_business_operations_types_table.php @@ -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); } } diff --git a/erp24/records/AnalystsBusinessOperations.php b/erp24/records/AnalystsBusinessOperations.php index bf6193bf..d8689144 100644 --- a/erp24/records/AnalystsBusinessOperations.php +++ b/erp24/records/AnalystsBusinessOperations.php @@ -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']); + } + } diff --git a/erp24/records/AnalystsBusinessOperationsTypes.php b/erp24/records/AnalystsBusinessOperationsTypes.php index d22ee85d..0745a64f 100644 --- a/erp24/records/AnalystsBusinessOperationsTypes.php +++ b/erp24/records/AnalystsBusinessOperationsTypes.php @@ -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']); } } diff --git a/erp24/views/analysts-business-operations/index.php b/erp24/views/analysts-business-operations/index.php index 0f8008b0..696032f7 100644 --- a/erp24/views/analysts-business-operations/index.php +++ b/erp24/views/analysts-business-operations/index.php @@ -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', -- 2.39.5