]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Копактный сбор данных о себестоимости
authorAleksey Filippov <Aleksey.Filippov@erp-flowers.ru>
Thu, 2 Oct 2025 21:04:16 +0000 (00:04 +0300)
committerAleksey Filippov <Aleksey.Filippov@erp-flowers.ru>
Thu, 2 Oct 2025 21:04:16 +0000 (00:04 +0300)
.gitignore
erp24/.gitignore
erp24/api2/controllers/DataController.php
erp24/commands/SelfCostController.php [new file with mode: 0644]
erp24/migrations/m250925_231312_craete_table_self_cost_product_dynamic.php [new file with mode: 0644]
erp24/records/SelfCostProductDynamic.php [new file with mode: 0644]

index 67bdd40f66c746e01a50b90d36fdc9c776e7d3fe..45b2c8061e75b78420536a75f64a4d30bb6c3b13 100644 (file)
@@ -14,3 +14,4 @@ erp24/package-lock.json
 /pgsql_last.sql
 /pgsql_last.sql.gz
 erp24/api2/users_auth_call_log2.txt
+/.history/
index 85c59d7006c424d42d40c758ab3370a9f88c1142..eca74311bf24eb5450ec95d845462ddef560d168 100644 (file)
@@ -9,6 +9,9 @@ nbproject
 .project
 .settings
 
+#
+.history
+
 # windows thumbnail cache
 Thumbs.db
 
index 055469fae273680152fd5cdd24f6842c11e941c8..742f5dfca3279393b88b127b024abc5c1132f1f6 100644 (file)
@@ -66,6 +66,7 @@ use yii_app\services\InfoLogService;
 use yii_app\services\LogService;
 use yii_app\services\MarketplaceService;
 use yii_app\services\TelegramService;
+use yii_app\services\SelfCostProductDinamicService;
 
 class DataController extends BaseController
 {
@@ -1152,6 +1153,7 @@ class DataController extends BaseController
 
                 if (!empty($values)) {
                     $this->setSelfCostUpdate($values);
+                    SelfCostProductDinamicService::UpdateResult($values);
                 }
             }
 
diff --git a/erp24/commands/SelfCostController.php b/erp24/commands/SelfCostController.php
new file mode 100644 (file)
index 0000000..f57e53d
--- /dev/null
@@ -0,0 +1,76 @@
+<?php
+/**
+ * @link https://www.yiiframework.com/
+ * @copyright Copyright (c) 2008 Yii Software LLC
+ * @license https://www.yiiframework.com/license/
+ */
+
+namespace yii_app\commands;
+
+use yii\console\Controller;
+use yii\console\ExitCode;
+use yii_app\records\SelfCostProduct;
+use yii_app\services\SelfCostProductDinamicService;
+
+
+class SelfCostController extends Controller
+{
+
+    public function actionTransferData()
+    {
+        echo "Start " . __LINE__ . " " . time() . "\n";
+        // echo " Line " . __LINE__ . "\n";
+
+        // сбор гуидов
+        $selfCostProductGuid = SelfCostProduct::find()
+            ->select(["DISTINCT(product_guid) as product_guid"])
+            ->asArray()
+            ->all();
+
+        var_dump(count($selfCostProductGuid));
+        echo " Line " . __LINE__ . "\n";
+
+        $arrayCount = $rowsCount = count($selfCostProductGuid);
+        // $rowsCount = 2;
+        // echo('<br>');
+        while ($rowsCount > 0) {
+
+            $shiftRow = array_shift($selfCostProductGuid);
+            // echo($shiftRow["product_guid"].'<br>');
+            // echo($rowsCount.'<br>');
+            $selfCostProductGuidStore = SelfCostProduct::find()
+                ->select(['product_guid','store_id'])
+                ->where(['product_guid' => (string)$shiftRow["product_guid"]])
+                ->groupBy(['product_guid','store_id'])
+                ->asArray()
+                ->all();
+
+            foreach ($selfCostProductGuidStore as $rowGuidStore) {
+
+                $selfCostProduct = SelfCostProduct::find()
+                    ->where(['product_guid' => (string)$rowGuidStore['product_guid']])
+                    ->andWhere(['store_id' => $rowGuidStore['store_id']])
+                    ->select(['product_guid','store_id','price', "string_agg(date::character varying, ', '  order by date ASC) as dates"])
+                    ->groupBy(['product_guid','store_id','price'])
+                    ->asArray()
+                    ->all();
+                // var_dump($selfCostProduct);
+                $resultRow = SelfCostProductDinamicService::PrepareResult($selfCostProduct);
+                // print_r($resultRow);
+                SelfCostProductDinamicService::SaveResult($resultRow);
+                // echo " Line " . __LINE__ . "\n";
+
+
+
+            }
+
+
+
+
+            $rowsCount--;
+        } 
+        
+        echo "\nStop " . time() . "\n";
+        return ExitCode::OK;
+    }
+}
diff --git a/erp24/migrations/m250925_231312_craete_table_self_cost_product_dynamic.php b/erp24/migrations/m250925_231312_craete_table_self_cost_product_dynamic.php
new file mode 100644 (file)
index 0000000..8d4df58
--- /dev/null
@@ -0,0 +1,36 @@
+<?php
+
+use yii\db\Migration;
+
+/**
+ * Class m250925_231312_craete_table_self_cost_product_dynamic
+ */
+class m250925_231312_craete_table_self_cost_product_dynamic extends Migration
+{
+    const TABLE_NAME = 'erp24.self_cost_product_dynamic';
+
+    /**
+     * {@inheritdoc}
+     */
+    public function safeUp()
+    {
+        $this->createTable(self::TABLE_NAME, [
+            'id' => $this->bigPrimaryKey(),
+            'store_id' => $this->integer()->notNull(),
+            'product_guid' => $this->string()->notNull()->comment('product guid'),
+            'price' => $this->float()->notNull()->comment('price'),
+            'date_from' => $this->date()->notNull()->comment('Дата начала'),
+            'date_to' => $this->date()->defaultValue('2100-01-01')->notNull()->comment('Дата окончания'),
+            'created_at' => $this->dateTime()->notNull()->defaultExpression('NOW()')->comment('Дата создания записи'),
+            'updated_at' => $this->datetime()->null()->comment('Дата внесения записи'),
+        ]);
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function safeDown()
+    {
+        $this->dropTable(self::TABLE_NAME);
+    }
+}
diff --git a/erp24/records/SelfCostProductDynamic.php b/erp24/records/SelfCostProductDynamic.php
new file mode 100644 (file)
index 0000000..dfd292e
--- /dev/null
@@ -0,0 +1,77 @@
+<?php
+
+namespace yii_app\records;
+
+use Yii;
+use yii\behaviors\TimestampBehavior;
+use yii\db\Expression;
+
+/**
+ * This is the model class for table "self_cost_product_dynamic".
+ *
+ * @property int $id
+ * @property int $store_id
+ * @property string $product_guid product guid
+ * @property float $price price
+ * @property string $date_from Дата начала
+ * @property string $date_to Дата окончания
+ * @property string $created_at Дата создания записи
+ * @property string|null $updated_at Дата внесения записи
+ */
+class SelfCostProductDynamic extends \yii\db\ActiveRecord
+{
+    /**
+     * {@inheritdoc}
+     */
+    public function behaviors()
+    {
+        return [
+            'timestamp' => [
+                'class' => TimestampBehavior::class,
+                'createdAtAttribute' => 'created_at',
+                'updatedAtAttribute' => 'updated_at',
+                'value' => new Expression('NOW()'),
+            ],
+        ];
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public static function tableName()
+    {
+        return 'self_cost_product_dynamic';
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function rules()
+    {
+        return [
+            [['store_id', 'product_guid', 'price', 'date_from'], 'required'],
+            [['store_id'], 'default', 'value' => null],
+            [['store_id'], 'integer'],
+            [['price'], 'number'],
+            [['date_from', 'date_to', 'created_at', 'updated_at'], 'safe'],
+            [['product_guid'], 'string', 'max' => 255],
+        ];
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function attributeLabels()
+    {
+        return [
+            'id' => 'ID',
+            'store_id' => 'Store ID',
+            'product_guid' => 'Product Guid',
+            'price' => 'Price',
+            'date_from' => 'Date From',
+            'date_to' => 'Date To',
+            'created_at' => 'Created At',
+            'updated_at' => 'Updated At',
+        ];
+    }
+}
\ No newline at end of file