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
8 changes: 4 additions & 4 deletions EstateReportingAPI.BusinessLogic/ReportingManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ public async Task<Result<MerchantKpi>> GetMerchantsTransactionKpis(MerchantQueri
using ResolvedDbContext<EstateManagementContext>? resolvedContext = this.Resolver.Resolve(EstateManagementDatabaseName, request.EstateId.ToString());
await using EstateManagementContext context = resolvedContext.Context;

var merchantsQuery = context.Merchants.Select(m => new { m.Name, m.LastSaleDate, m.LastSaleDateTime });
var merchantsQuery = context.MerchantBalanceProjectionState.Select(m => new { m.MerchantName, m.LastSale });
var merchantsQueryResult = await ExecuteQuerySafeToList(merchantsQuery, cancellationToken, "Error retrieving merchants for KPI's");
if (merchantsQueryResult.IsFailed)
return ResultHelpers.CreateFailure(merchantsQueryResult);
Expand All @@ -578,11 +578,11 @@ public async Task<Result<MerchantKpi>> GetMerchantsTransactionKpis(MerchantQueri

DateTime now = DateTime.Now;

Int32 merchantsWithSaleInLastHour = (from m in merchants where m.LastSaleDateTime >= now.AddHours(-1) && m.LastSaleDateTime <= now select m).Count();
Int32 merchantsWithSaleInLastHour = (from m in merchants where m.LastSale >= now.AddHours(-1) && m.LastSale <= now 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 merchantsWithNoSaleToday = (from m in merchants where m.LastSale >= now.AddDays(-7) && m.LastSale <= now.AddDays(-1) select m).Count();

Int32 merchantsWithNoSaleInLast7Days = (from m in merchants where m.LastSaleDate <= now.Date.AddDays(-7) select m).Count();
Int32 merchantsWithNoSaleInLast7Days = (from m in merchants where m.LastSale <= now.AddDays(-7) select m).Count();

MerchantKpi response = new() { MerchantsWithSaleInLastHour = merchantsWithSaleInLastHour, MerchantsWithNoSaleToday = merchantsWithNoSaleToday, MerchantsWithNoSaleInLast7Days = merchantsWithNoSaleInLast7Days };

Expand Down
7 changes: 4 additions & 3 deletions EstateReportingAPI.IntegrationTests/DatabaseHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,8 @@ public async Task<Guid> AddMerchant(String estateName,
EstateId = estate.EstateId,
MerchantId = Guid.NewGuid(),
Name = merchantName,
LastSaleDate = lastSaleDateTime.Date,
LastSaleDateTime = lastSaleDateTime
//LastSaleDate = lastSaleDateTime.Date,
//LastSaleDateTime = lastSaleDateTime
};

await this.Context.Merchants.AddAsync(merchant);
Expand Down Expand Up @@ -452,7 +452,8 @@ await this.Context.MerchantContracts.AddAsync(new MerchantContract {
MerchantBalanceProjectionState state = new MerchantBalanceProjectionState {
Balance = balance,
MerchantId = savedMerchant.MerchantId,
MerchantName = savedMerchant.Name
MerchantName = savedMerchant.Name,
LastSale = lastSaleDateTime,
};
await this.Context.MerchantBalanceProjectionState.AddAsync(state);

Expand Down
Loading