]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Вывод матрицы
authorVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Fri, 20 Jun 2025 15:05:49 +0000 (18:05 +0300)
committerVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Fri, 20 Jun 2025 15:05:49 +0000 (18:05 +0300)
erp24/controllers/CategoryPlanController.php

index 5195c97a2bcf1c2ab112bb33d19c6e8512fc867c..6e133592398fba933e6d08aae2d160f2a7264fbb 100644 (file)
@@ -64,8 +64,7 @@ class CategoryPlanController extends Controller {
             "COUNT(*) as cnt",
             "SUM(CASE WHEN operation='Продажа' THEN s.summ ELSE (CASE WHEN operation='Возврат' THEN -s.summ ELSE 0 END) END) as total",
             "s.store_id",
-            //"p1c.type as type",
-            "p1cn.category as type",
+            "(CASE WHEN p1c.type = 'Матрица' THEN 'Матрица' ELSE p1cn.category END) as type",
             "TO_CHAR(s.date, 'YYYY-MM') as month"
         ])
             ->leftJoin('sales_products sp', 's.id = sp.check_id')
@@ -75,8 +74,17 @@ class CategoryPlanController extends Controller {
             ->andWhere(['order_id' => ['', '0']])
             ->andWhere(['not in', 'p1cn.category', ['', 'букет', 'сборка', 'сервис']])
             ->andWhere(['s.store_id' => $model->store_id])
-            ->groupBy(['s.store_id', "TO_CHAR(s.date, 'YYYY-MM')", "p1cn.category"])
-            ->orderBy(['month' => SORT_ASC, 'p1cn.category' => SORT_ASC])
+            ->groupBy([
+                's.store_id',
+                "TO_CHAR(s.date, 'YYYY-MM')",
+                new \yii\db\Expression("
+                    CASE 
+                        WHEN p1c.type = 'Матрица' THEN 'Матрица'
+                        ELSE p1cn.category
+                    END
+                ")
+            ])
+            ->orderBy(['month' => SORT_ASC, 'type' => SORT_ASC])
             ->asArray()
             ->all();
 
@@ -101,8 +109,7 @@ class CategoryPlanController extends Controller {
             "COUNT(*) as cnt",
             "SUM(CASE WHEN operation='Продажа' THEN s.summ ELSE (CASE WHEN operation='Возврат' THEN -s.summ ELSE 0 END) END) as total",
             "s.store_id",
-            //"p1c.type as type",
-            "p1cn.category as type",
+            "(CASE WHEN p1c.type = 'Матрица' THEN 'Матрица' ELSE p1cn.category END) as type",
             "TO_CHAR(s.date, 'YYYY-MM') as month"
         ])
             ->leftJoin('sales_products sp', 's.id = sp.check_id')
@@ -112,8 +119,17 @@ class CategoryPlanController extends Controller {
             ->andWhere(['not in', 'order_id', ['', '0']])
             ->andWhere(['s.store_id' => $model->store_id])
             ->andWhere(['not in', 'p1cn.category', ['', 'букет', 'сборка', 'сервис']])
-            ->groupBy(['s.store_id', "TO_CHAR(s.date, 'YYYY-MM')", "p1cn.category"])
-            ->orderBy(['month' => SORT_ASC, 'p1cn.category' => SORT_ASC])
+            ->groupBy([
+                's.store_id',
+                "TO_CHAR(s.date, 'YYYY-MM')",
+                new \yii\db\Expression("
+                    CASE 
+                        WHEN p1c.type = 'Матрица' THEN 'Матрица'
+                        ELSE p1cn.category
+                    END
+                ")
+            ])
+            ->orderBy(['month' => SORT_ASC, 'type' => SORT_ASC])
             ->asArray()
             ->all();
 
@@ -127,8 +143,7 @@ class CategoryPlanController extends Controller {
         $store_id = $eit->export_val ?? '';
         $writeOffs = WriteOffs::find()->alias('wo')->select([
             'sum(wo.summ) as total',
-            //"p1c.type as p1ctype",
-            "p1cn.category as p1ctype",
+            "(CASE WHEN p1c.type = 'Матрица' THEN 'Матрица' ELSE p1cn.category END) as p1ctype",
             "TO_CHAR(wo.date, 'YYYY-MM') as month"
         ])
             ->leftJoin('write_offs_products wop', 'wop.write_offs_id = wo.id')
@@ -138,7 +153,15 @@ class CategoryPlanController extends Controller {
             ->andWhere(['wo.type' => WriteOffsErp::WRITE_OFFS_TYPE_BRAK])
             ->andWhere(['not in', 'p1cn.category', ['', 'букет', 'сборка', 'сервис']])
             ->andWhere(['wo.store_id' => $store_id])
-            ->groupBy(["month", 'p1cn.category'])
+            ->groupBy([
+                "month",
+                new \yii\db\Expression("
+                    CASE 
+                        WHEN p1c.type = 'Матрица' THEN 'Матрица'
+                        ELSE p1cn.category
+                    END
+                ")
+            ])
             ->asArray()->all();
 
         $tableWriteOffs = [];