]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Группировка по категориям
authorVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Fri, 20 Jun 2025 14:23:29 +0000 (17:23 +0300)
committerVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Fri, 20 Jun 2025 14:23:29 +0000 (17:23 +0300)
erp24/controllers/CategoryPlanController.php

index 8f329bc648d7ede7ad65bf8500a2dfe7f6ad7d41..2cc797a350c6d27fa303863f013ddcce3679aed9 100644 (file)
@@ -64,16 +64,19 @@ 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",
+            //"p1c.type as type",
+            "p1cn.category as type",
             "TO_CHAR(s.date, 'YYYY-MM') as month"
         ])
             ->leftJoin('sales_products sp', 's.id = sp.check_id')
             ->leftJoin('products_1c p1c', 'p1c.id = sp.product_id')
+            ->leftJoin('products_1c_nomenclature p1cn', 'p1cn.id = sp.product_id')
             ->where(['between', 's.date', $date_start, $date_end])
             ->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')", "type"])
-            ->orderBy(['month' => SORT_ASC, 'type' => SORT_ASC])
+            ->groupBy(['s.store_id', "TO_CHAR(s.date, 'YYYY-MM')", "p1cn.category"])
+            ->orderBy(['month' => SORT_ASC, 'p1cn.category' => SORT_ASC])
             ->asArray()
             ->all();
 
@@ -98,16 +101,19 @@ 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",
+            //"p1c.type as type",
+            "p1cn.category as type",
             "TO_CHAR(s.date, 'YYYY-MM') as month"
         ])
             ->leftJoin('sales_products sp', 's.id = sp.check_id')
             ->leftJoin('products_1c p1c', 'p1c.id = sp.product_id')
+            ->leftJoin('products_1c_nomenclature p1cn', 'p1cn.id = sp.product_id')
             ->where(['between', 's.date', $date_start, $date_end])
             ->andWhere(['not in', 'order_id', ['', '0']])
             ->andWhere(['s.store_id' => $model->store_id])
-            ->groupBy(['s.store_id', "TO_CHAR(s.date, 'YYYY-MM')", "type"])
-            ->orderBy(['month' => SORT_ASC, 'type' => SORT_ASC])
+            ->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])
             ->asArray()
             ->all();
 
@@ -121,15 +127,18 @@ class CategoryPlanController extends Controller {
         $store_id = $eit->export_val ?? '';
         $writeOffs = WriteOffs::find()->alias('wo')->select([
             'sum(wo.summ) as total',
-            "p1c.type as p1ctype",
+            //"p1c.type as p1ctype",
+            "p1cn.category as p1ctype",
             "TO_CHAR(wo.date, 'YYYY-MM') as month"
         ])
             ->leftJoin('write_offs_products wop', 'wop.write_offs_id = wo.id')
             ->leftJoin('products_1c p1c', 'p1c.id = wop.product_id')
+            ->leftJoin('products_1c_nomenclature p1cn', 'p1cn.id = wop.product_id')
             ->where(['between', 'wo.date', $date_start, $date_end])
             ->andWhere(['wo.type' => WriteOffsErp::WRITE_OFFS_TYPE_BRAK])
+            ->andWhere(['not in', 'p1cn.category', ['',  'сервис']])
             ->andWhere(['wo.store_id' => $store_id])
-            ->groupBy(["month", 'p1ctype'])
+            ->groupBy(["month", 'p1cn.category'])
             ->asArray()->all();
 
         $tableWriteOffs = [];