From: Alexander Smirnov Date: Mon, 14 Apr 2025 11:39:56 +0000 (+0300) Subject: [ERP-399] matrix_erp_property_dynamic X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=9fcca48f47046f8449a006f8ccf7b42d353b7bf7;p=erp24_rep%2Fyii-erp24%2F.git [ERP-399] matrix_erp_property_dynamic --- diff --git a/erp24/commands/MatrixErpController.php b/erp24/commands/MatrixErpController.php new file mode 100644 index 00000000..f88523bc --- /dev/null +++ b/erp24/commands/MatrixErpController.php @@ -0,0 +1,75 @@ +all(); + $existingMapGuidGroupNames = []; + foreach ($existings as $existing) { + /* @var $existing MatrixErp */ + $existingMapGuidGroupNames[$existing->guid][] = $existing->group_name; + }; + + $products = MarketplaceService::getMarketplaceProducts(); + + foreach ($products as $product) { + /* @var $product Products1c */ + if (in_array($product->id, array_keys($existingMapGuidGroupNames)) + && (in_array('marketplace', $existingMapGuidGroupNames[$product->id]))) { + $matrixErp = MatrixErp::findOne(['guid' => $product->id]); + if ($matrixErp->components != $product->components) { + $matrixErpPropertyDynamic1 = MatrixErpPropertyDynamic::findOne(['product_id' => $matrixErp->guid, 'category' => 1]); + /* @var MatrixErpPropertyDynamic $matrixErpPropertyDynamic1 */ + if ($matrixErpPropertyDynamic1) { + $matrixErpPropertyDynamic1->date_end = date("Y-m-d H:i:s"); + $matrixErpPropertyDynamic1->save(); + if ($matrixErpPropertyDynamic1->getErrors()) { + var_dump($matrixErpPropertyDynamic1->getErrors()); + } + } + $matrixErpPropertyDynamic2 = new MatrixErpPropertyDynamic; + $matrixErpPropertyDynamic2->product_id = $matrixErp->guid; + $matrixErpPropertyDynamic2->value = $product->components; + $matrixErpPropertyDynamic2->category = 1; + $matrixErpPropertyDynamic2->date_from = date("Y-m-d H:i:s"); + $matrixErpPropertyDynamic2->date_end = '2100-01-01 00:00:00'; + $matrixErpPropertyDynamic2->save(); + if ($matrixErpPropertyDynamic2->getErrors()) { + var_dump($matrixErpPropertyDynamic2->getErrors()); + } + } + if ($matrixErp->articule != $product->articule) { + $matrixErpPropertyDynamic1 = MatrixErpPropertyDynamic::findOne(['product_id' => $matrixErp->guid, 'category' => 2]); + /* @var MatrixErpPropertyDynamic $matrixErpPropertyDynamic1 */ + if ($matrixErpPropertyDynamic1) { + $matrixErpPropertyDynamic1->date_end = date("Y-m-d H:i:s"); + $matrixErpPropertyDynamic1->save(); + if ($matrixErpPropertyDynamic1->getErrors()) { + var_dump($matrixErpPropertyDynamic1->getErrors()); + } + } + $matrixErpPropertyDynamic2 = new MatrixErpPropertyDynamic; + $matrixErpPropertyDynamic2->product_id = $matrixErp->guid; + $matrixErpPropertyDynamic2->value = $product->articule; + $matrixErpPropertyDynamic2->category = 2; + $matrixErpPropertyDynamic2->date_from = date("Y-m-d H:i:s"); + $matrixErpPropertyDynamic2->date_end = '2100-01-01 00:00:00'; + $matrixErpPropertyDynamic2->save(); + if ($matrixErpPropertyDynamic2->getErrors()) { + var_dump($matrixErpPropertyDynamic2->getErrors()); + } + } + } + } + } +} \ No newline at end of file diff --git a/erp24/migrations/m250414_094332_create_table_matrix_erp_property_dynamic.php b/erp24/migrations/m250414_094332_create_table_matrix_erp_property_dynamic.php new file mode 100755 index 00000000..58a94add --- /dev/null +++ b/erp24/migrations/m250414_094332_create_table_matrix_erp_property_dynamic.php @@ -0,0 +1,42 @@ +db->getTableSchema(self::TABLE_NAME); + + if (!isset($tableSchema)) { + $this->createTable(self::TABLE_NAME, [ + 'id' => $this->primaryKey(), + 'product_id' => $this->string(36)->notNull()->comment('GUID товара из таблицы products_1c'), + 'value' => $this->text()->null()->comment('значение components при category = 1, articule при category = 2'), + 'category' => $this->integer()->notNull()->comment('1 - value = components, 2 - value = articule'), + 'date_from' => $this->dateTime()->notNull()->comment('Дата и время начала активности'), + 'date_end' => $this->dateTime()->null()->comment('Дата и время окончания активности'), + 'active' => $this->tinyInteger()->notNull()->defaultValue(1)->comment('Активность записи'), + ]); + } + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + $tableSchema = $this->db->getTableSchema(self::TABLE_NAME); + + if (isset($tableSchema)) { + $this->dropTable(self::TABLE_NAME); + } + } +} diff --git a/erp24/records/MatrixErpPropertyDynamic.php b/erp24/records/MatrixErpPropertyDynamic.php new file mode 100644 index 00000000..f5b660ec --- /dev/null +++ b/erp24/records/MatrixErpPropertyDynamic.php @@ -0,0 +1,58 @@ + null], + [['category', 'active'], 'integer'], + [['date_from', 'date_end'], 'safe'], + [['product_id'], 'string', 'max' => 36], + ]; + } + + /** + * {@inheritdoc} + */ + public function attributeLabels() + { + return [ + 'id' => 'ID', + 'product_id' => 'Product ID', + 'value' => 'Value', + 'category' => 'Category', + 'date_from' => 'Date From', + 'date_end' => 'Date End', + 'active' => 'Active', + ]; + } +}