diff --git a/EstateReportingAPI.BusinessLogic/ReportingManager.cs b/EstateReportingAPI.BusinessLogic/ReportingManager.cs index cbb39ae..0a38f7e 100644 --- a/EstateReportingAPI.BusinessLogic/ReportingManager.cs +++ b/EstateReportingAPI.BusinessLogic/ReportingManager.cs @@ -572,11 +572,13 @@ public async Task> GetMerchantsTransactionKpis(MerchantQueri var merchants = merchantsQueryResult.Data; - Int32 merchantsWithSaleInLastHour = (from m in merchants where m.LastSaleDate == DateTime.Now.Date && m.LastSaleDateTime >= DateTime.Now.AddHours(-1) select m).Count(); + DateTime now = DateTime.Now; - Int32 merchantsWithNoSaleToday = (from m in merchants where m.LastSaleDate >= DateTime.Now.Date.AddDays(-7) && m.LastSaleDate <= DateTime.Now.Date.AddDays(-1) select m).Count(); + Int32 merchantsWithSaleInLastHour = (from m in merchants where m.LastSaleDateTime >= now.AddHours(-1) && m.LastSaleDateTime <= now select m).Count(); - Int32 merchantsWithNoSaleInLast7Days = (from m in merchants where m.LastSaleDate <= DateTime.Now.Date.AddDays(-7) select m).Count(); + Int32 merchantsWithNoSaleToday = (from m in merchants where m.LastSaleDate >= now.Date.AddDays(-7) && m.LastSaleDate <= now.Date.AddDays(-1) select m).Count(); + + Int32 merchantsWithNoSaleInLast7Days = (from m in merchants where m.LastSaleDate <= now.Date.AddDays(-7) select m).Count(); MerchantKpi response = new() { MerchantsWithSaleInLastHour = merchantsWithSaleInLastHour, MerchantsWithNoSaleToday = merchantsWithNoSaleToday, MerchantsWithNoSaleInLast7Days = merchantsWithNoSaleInLast7Days }; @@ -1524,4 +1526,3 @@ private sealed class ProductPerformanceItemData { #endregion } - diff --git a/EstateReportingAPI.IntegrationTests/MerchantEndpointTests.cs b/EstateReportingAPI.IntegrationTests/MerchantEndpointTests.cs index d3cf2ac..3740153 100644 --- a/EstateReportingAPI.IntegrationTests/MerchantEndpointTests.cs +++ b/EstateReportingAPI.IntegrationTests/MerchantEndpointTests.cs @@ -148,30 +148,32 @@ public async Task MerchantEndpoint_GetMerchantDevices_MerchantDevicesReturned() [Fact] public async Task MerchantEndpoint_GetMerchantKpis_MerchantKpisReturned() { - await this.helper.AddEstate("Test Estate", "Ref1"); + DateTime now = DateTime.Now; - await this.helper.AddMerchant("Test Estate", $"Test Merchant 1",100, DateTime.Now, DateTime.Now, + await this.helper.AddEstate("Test Estate", "Ref1"); + + await this.helper.AddMerchant("Test Estate", $"Test Merchant 1",100, now, now, ("Address Line 1", $"Test Town", $"TE57 1NG", $"Region"), ("Contact 1", "1@2.com", "123456"), devices: ["123456"]); - await this.helper.AddMerchant("Test Estate", $"Test Merchant 2", 200, DateTime.Now, DateTime.Now.AddMinutes(-10), + await this.helper.AddMerchant("Test Estate", $"Test Merchant 2", 200, now, now.AddMinutes(-10), ("Address Line 1", $"Test Town", $"TE57 1NG", $"Region"), ("Contact 1", "1@2.com", "123456"), devices: ["123456"]); - await this.helper.AddMerchant("Test Estate", $"Test Merchant 3",300, DateTime.Now, DateTime.Now.AddHours(-2), + await this.helper.AddMerchant("Test Estate", $"Test Merchant 3",300, now, now.AddHours(-2), ("Address Line 1", $"Test Town", $"TE57 1NG", $"Region"), ("Contact 1", "1@2.com", "123456"), devices: ["123456"]); - await this.helper.AddMerchant("Test Estate", $"Test Merchant 4",400, DateTime.Now, DateTime.Now.AddHours(-3), + await this.helper.AddMerchant("Test Estate", $"Test Merchant 4",400, now, now.AddHours(-3), ("Address Line 1", $"Test Town", $"TE57 1NG", $"Region"), ("Contact 1", "1@2.com", "123456"), devices: ["123456"]); - await this.helper.AddMerchant("Test Estate", $"Test Merchant 5",500, DateTime.Now, DateTime.Now.AddDays(-2), + await this.helper.AddMerchant("Test Estate", $"Test Merchant 5",500, now, now.AddDays(-2), ("Address Line 1", $"Test Town", $"TE57 1NG", $"Region"), ("Contact 1", "1@2.com", "123456"), devices: ["123456"]); - await this.helper.AddMerchant("Test Estate", $"Test Merchant 6",600, DateTime.Now, DateTime.Now.AddDays(-1), + await this.helper.AddMerchant("Test Estate", $"Test Merchant 6",600, now, now.AddDays(-1), ("Address Line 1", $"Test Town", $"TE57 1NG", $"Region"), ("Contact 1", "1@2.com", "123456"), devices: ["123456"]); - await this.helper.AddMerchant("Test Estate", $"Test Merchant 7",700, DateTime.Now, DateTime.Now.AddDays(-3), + await this.helper.AddMerchant("Test Estate", $"Test Merchant 7",700, now, now.AddDays(-3), ("Address Line 1", $"Test Town", $"TE57 1NG", $"Region"), ("Contact 1", "1@2.com", "123456"), devices: ["123456"]); - await this.helper.AddMerchant("Test Estate", $"Test Merchant 8",800, DateTime.Now, DateTime.Now.AddDays(-10), + await this.helper.AddMerchant("Test Estate", $"Test Merchant 8",800, now, now.AddDays(-10), ("Address Line 1", $"Test Town", $"TE57 1NG", $"Region"), ("Contact 1", "1@2.com", "123456"), devices: ["123456"]); @@ -192,4 +194,4 @@ protected override async Task ClearStandingData() { protected override async Task SetupStandingData() { } -} \ No newline at end of file +} diff --git a/EstateReportingAPI.IntegrationTests/TransactionsEndpointTests.cs b/EstateReportingAPI.IntegrationTests/TransactionsEndpointTests.cs index 329583d..b52eb45 100644 --- a/EstateReportingAPI.IntegrationTests/TransactionsEndpointTests.cs +++ b/EstateReportingAPI.IntegrationTests/TransactionsEndpointTests.cs @@ -104,8 +104,8 @@ public async Task TransactionsEndpoint_TodaysSales_SalesReturned() { List? todaysTransactions = new List(); List comparisonDateTransactions = new List(); - DateTime todaysDateTime = DateTime.Now; - DateTime comparisonDate = DateTime.Now.AddDays(-1).AddHours(-1); + DateTime todaysDateTime = DateTime.Now.Date; + DateTime comparisonDate = todaysDateTime.AddDays(-1); Dictionary transactionCounts = new() { { "Test Merchant 1", 15 }, { "Test Merchant 2", 18 }, { "Test Merchant 3", 9 }, { "Test Merchant 4", 0 } }; @@ -115,7 +115,7 @@ public async Task TransactionsEndpoint_TodaysSales_SalesReturned() { foreach ((Guid productId, String productName, Decimal? productValue, Int32 contractProductReportingId) product in productList) { var transactionCount = transactionCounts.Single(m => m.Key == merchant.Name).Value; for (int i = 0; i < transactionCount; i++) { - Transaction transaction = await this.helper.BuildTransactionX(todaysDateTime.AddHours(-1), merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", product.productValue); + Transaction transaction = await this.helper.BuildTransactionX(todaysDateTime, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", product.productValue); todaysTransactions.Add(transaction); } } @@ -162,8 +162,8 @@ public async Task TransactionsEndpoint_TodaysSales_OperatorFilter_SalesReturned( List? todaysTransactions = new List(); List comparisonDateTransactions = new List(); - DateTime todaysDateTime = DateTime.Now; - DateTime comparisonDate = DateTime.Now.AddDays(-1).AddHours(-1); + DateTime todaysDateTime = DateTime.Now.Date; + DateTime comparisonDate = todaysDateTime.AddDays(-1); Dictionary transactionCounts = new() { { "Test Merchant 1", 15 }, { "Test Merchant 2", 18 }, { "Test Merchant 3", 9 }, { "Test Merchant 4", 0 } }; @@ -173,7 +173,7 @@ public async Task TransactionsEndpoint_TodaysSales_OperatorFilter_SalesReturned( foreach ((Guid productId, String productName, Decimal? productValue, Int32 contractProductReportingId) product in productList) { var transactionCount = transactionCounts.Single(m => m.Key == merchant.Name).Value; for (int i = 0; i < transactionCount; i++) { - Transaction transaction = await this.helper.BuildTransactionX(todaysDateTime.AddHours(-1), merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", product.productValue); + Transaction transaction = await this.helper.BuildTransactionX(todaysDateTime, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", product.productValue); todaysTransactions.Add(transaction); } } @@ -220,8 +220,8 @@ public async Task TransactionsEndpoint_TodaysSales_MerchantFilter_SalesReturned( List? todaysTransactions = new List(); List comparisonDateTransactions = new List(); - DateTime todaysDateTime = DateTime.Now; - DateTime comparisonDate = DateTime.Now.AddDays(-1).AddHours(-1); + DateTime todaysDateTime = DateTime.Now.Date; + DateTime comparisonDate = todaysDateTime.AddDays(-1); Dictionary transactionCounts = new() { { "Test Merchant 1", 15 }, { "Test Merchant 2", 18 }, { "Test Merchant 3", 9 }, { "Test Merchant 4", 0 } }; @@ -231,7 +231,7 @@ public async Task TransactionsEndpoint_TodaysSales_MerchantFilter_SalesReturned( foreach ((Guid productId, String productName, Decimal? productValue, Int32 contractProductReportingId) product in productList) { var transactionCount = transactionCounts.Single(m => m.Key == merchant.Name).Value; for (int i = 0; i < transactionCount; i++) { - Transaction transaction = await this.helper.BuildTransactionX(todaysDateTime.AddHours(-1), merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", product.productValue); + Transaction transaction = await this.helper.BuildTransactionX(todaysDateTime, merchant.MerchantId, contract.operatorId, contract.contractId, product.productId, "0000", product.productValue); todaysTransactions.Add(transaction); } } @@ -1213,4 +1213,4 @@ public async Task SettlementEndpoints_TodaysSettlement_SettlementReturned() todaysSettlement.TodaysPendingSettlementCount.ShouldBe(overallTodaysPendingSettlementTransactionCount); todaysSettlement.TodaysPendingSettlementValue.ShouldBe(todayOverallTotals.Sum(c => c.pendingSettlementFees)); } -} \ No newline at end of file +}