From 2d790bce091171780d64e0ff80d0b543c5e83683 Mon Sep 17 00:00:00 2001 From: Alexander Smirnov Date: Wed, 15 May 2024 19:23:24 +0300 Subject: [PATCH] fix report show(-weeks) using date_first_sale --- erp24/api3/core/services/ReportService.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/erp24/api3/core/services/ReportService.php b/erp24/api3/core/services/ReportService.php index f40acf4d..42ce22f3 100644 --- a/erp24/api3/core/services/ReportService.php +++ b/erp24/api3/core/services/ReportService.php @@ -146,8 +146,8 @@ class ReportService $sales = Sales::find()->alias('s')->select(["COUNT(*) as cnt", "sum(CASE WHEN operation='Продажа' THEN s.summ ELSE (CASE WHEN operation='Возврат' THEN -s.summ ELSE 0 END) END) as total", "sum(CASE WHEN s.phone is null THEN 0 ELSE 1 END) as bonusUserCount", - "sum(CASE WHEN (s.phone IS NOT NULL) AND ((u.sale_cnt IS NULL) OR u.sale_cnt < 2) THEN 1 ELSE 0 END) as newBonusUserCount", - "sum(CASE WHEN (s.phone IS NOT NULL) AND u.sale_cnt > 1 THEN 1 ELSE 0 END) as repeatBonusUserCount", + "sum(CASE WHEN (s.phone IS NOT NULL) AND ((u.date_first_sale IS NOT NULL) AND (u.date_first_sale = s.date)) THEN 1 ELSE 0 END) as newBonusUserCount", + "sum(CASE WHEN (s.phone IS NOT NULL) AND ((u.date_first_sale IS NULL) OR (u.date_first_sale < s.date)) THEN 1 ELSE 0 END) as repeatBonusUserCount", "s.store_id", "s.admin_id"]) ->leftJoin('users u', 'u.phone = s.phone::varchar(20) AND u.phone IN (\'' @@ -593,8 +593,8 @@ class ReportService $sales = Sales::find()->alias('s')->select(["COUNT(*) as cnt", "sum(CASE WHEN operation='Продажа' THEN s.summ ELSE (CASE WHEN operation='Возврат' THEN -s.summ ELSE 0 END) END) as total", "sum(CASE WHEN s.phone is null THEN 0 ELSE 1 END) as bonusUserCount", - "sum(CASE WHEN (s.phone IS NOT NULL) AND ((u.sale_cnt IS NULL) OR u.sale_cnt < 2) THEN 1 ELSE 0 END) as newBonusUserCount", - "sum(CASE WHEN (s.phone IS NOT NULL) AND u.sale_cnt > 1 THEN 1 ELSE 0 END) as repeatBonusUserCount", + "sum(CASE WHEN (s.phone IS NOT NULL) AND ((u.date_first_sale IS NOT NULL) AND (u.date_first_sale = s.date)) THEN 1 ELSE 0 END) as newBonusUserCount", + "sum(CASE WHEN (s.phone IS NOT NULL) AND ((u.date_first_sale IS NULL) OR (u.date_first_sale < s.date)) THEN 1 ELSE 0 END) as repeatBonusUserCount", 'store_id_1c', ]) ->leftJoin('users u', 'u.phone = s.phone::varchar(20) AND u.phone IN (\'' -- 2.39.5