Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions EstateReportingAPI.BusinessLogic/ReportingManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -572,11 +572,13 @@ public async Task<Result<MerchantKpi>> 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 };

Expand Down Expand Up @@ -1524,4 +1526,3 @@ private sealed class ProductPerformanceItemData {

#endregion
}

22 changes: 12 additions & 10 deletions EstateReportingAPI.IntegrationTests/MerchantEndpointTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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", "[email protected]", "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", "[email protected]", "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", "[email protected]", "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", "[email protected]", "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", "[email protected]", "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", "[email protected]", "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", "[email protected]", "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", "[email protected]", "123456"), devices: ["123456"]);

Expand All @@ -192,4 +194,4 @@ protected override async Task ClearStandingData() {
protected override async Task SetupStandingData() {

}
}
}
20 changes: 10 additions & 10 deletions EstateReportingAPI.IntegrationTests/TransactionsEndpointTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ public async Task TransactionsEndpoint_TodaysSales_SalesReturned() {
List<Transaction>? todaysTransactions = new List<Transaction>();
List<Transaction> comparisonDateTransactions = new List<Transaction>();

DateTime todaysDateTime = DateTime.Now;
DateTime comparisonDate = DateTime.Now.AddDays(-1).AddHours(-1);
DateTime todaysDateTime = DateTime.Now.Date;
DateTime comparisonDate = todaysDateTime.AddDays(-1);

Dictionary<string, int> transactionCounts = new() { { "Test Merchant 1", 15 }, { "Test Merchant 2", 18 }, { "Test Merchant 3", 9 }, { "Test Merchant 4", 0 } };

Expand All @@ -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);
}
}
Expand Down Expand Up @@ -162,8 +162,8 @@ public async Task TransactionsEndpoint_TodaysSales_OperatorFilter_SalesReturned(
List<Transaction>? todaysTransactions = new List<Transaction>();
List<Transaction> comparisonDateTransactions = new List<Transaction>();

DateTime todaysDateTime = DateTime.Now;
DateTime comparisonDate = DateTime.Now.AddDays(-1).AddHours(-1);
DateTime todaysDateTime = DateTime.Now.Date;
DateTime comparisonDate = todaysDateTime.AddDays(-1);

Dictionary<string, int> transactionCounts = new() { { "Test Merchant 1", 15 }, { "Test Merchant 2", 18 }, { "Test Merchant 3", 9 }, { "Test Merchant 4", 0 } };

Expand All @@ -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);
}
}
Expand Down Expand Up @@ -220,8 +220,8 @@ public async Task TransactionsEndpoint_TodaysSales_MerchantFilter_SalesReturned(
List<Transaction>? todaysTransactions = new List<Transaction>();
List<Transaction> comparisonDateTransactions = new List<Transaction>();

DateTime todaysDateTime = DateTime.Now;
DateTime comparisonDate = DateTime.Now.AddDays(-1).AddHours(-1);
DateTime todaysDateTime = DateTime.Now.Date;
DateTime comparisonDate = todaysDateTime.AddDays(-1);

Dictionary<string, int> transactionCounts = new() { { "Test Merchant 1", 15 }, { "Test Merchant 2", 18 }, { "Test Merchant 3", 9 }, { "Test Merchant 4", 0 } };

Expand All @@ -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);
}
}
Expand Down Expand Up @@ -1213,4 +1213,4 @@ public async Task SettlementEndpoints_TodaysSettlement_SettlementReturned()
todaysSettlement.TodaysPendingSettlementCount.ShouldBe(overallTodaysPendingSettlementTransactionCount);
todaysSettlement.TodaysPendingSettlementValue.ShouldBe(todayOverallTotals.Sum(c => c.pendingSettlementFees));
}
}
}
Loading