SqlReports

+

4/22/2021 2:07:17 PM

Details

diff --git a/RevenueComparationByCategoriesTotalByCompany.sql b/RevenueComparationByCategoriesTotalByCompany.sql
index d8a39a9..7957aa8 100644
--- a/RevenueComparationByCategoriesTotalByCompany.sql
+++ b/RevenueComparationByCategoriesTotalByCompany.sql
@@ -70,17 +70,20 @@ begin
 	where pt.ID = @PeriodID  
 		
 	
-	declare @TerminalsList table (TerminalID nvarchar(256), ShopID int)
+	declare @TerminalsList table (TerminalID nvarchar(256), ShopID int, CatalogId int)
 
 	insert into @TerminalsList
 		select
 			t.Id as TerminalID,
-			t.ShopID as ShopID
+			t.ShopID as ShopID,
+			c.ProductCatalogId as CatalogId
 
 		from dbo.Terminals t with (nolock)
 			inner join dbo.Shops s with (nolock) on 
 					s.Id = t.ShopId
 				and (s.CompanyId = @CompanyID or @CompanyID = 0)
+			
+			left join dbo.Companies c with (nolock) on c.Id = s.CompanyId
 
 
 	declare @SalesTotals table (ProductId nvarchar(28), CategoryID int, LastPeriodSumm decimal(15, 2), ActualPeriodSumm decimal(15, 2), SalesLastPeriodCount int, SalesActualPeriodCount int)
@@ -145,7 +148,8 @@ begin
 				and sl.SessionId = ss.SessionId
 
 			inner join dbo.Products p with (nolock) on
-					p.Id = sl.ProductId
+					p.Code = sl.ProductId
+				and p.CatalogId = tl.CatalogId
 				and (p.CategoryId = @CategoryID or @CategoryID = 0)
 		group by 
 			sl.ProductId, 
@@ -213,7 +217,8 @@ begin
 				and	prc.Type in (0, 1)
 			
 			inner join dbo.Products p with (nolock) on
-					p.Id = prc.ProductId		
+					p.Code = prc.ProductId
+				and p.CatalogId = tl.CatalogId
 
 		group by 
 			prc.ProductId,