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
12 changes: 7 additions & 5 deletions EstateReportingAPI.BusinessLogic/ReportingManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2139,15 +2139,16 @@ private async Task<Result<List<MerchantDailyPerformanceGroupProjection>>> LoadMe
from t in context.Transactions
join m in context.Merchants on t.MerchantId equals m.MerchantId
join cp in context.ContractProducts on new { t.ContractProductId, t.ContractId } equals new { cp.ContractProductId, cp.ContractId }
join op in context.Operators on t.OperatorId equals op.OperatorId
join op in context.Operators on t.OperatorId equals op.OperatorId into opJoin
from op in opJoin.DefaultIfEmpty()
where t.TransactionType == "Sale"
&& t.TransactionDate >= startDate
&& t.TransactionDate <= endDate
&& m.MerchantReportingId == request.Request.MerchantReportingId
group t by new
{
cp.ContractProductReportingId,
op.Name,
OperatorName = op == null ? string.Empty : op.Name,
Comment thread
StuartFerguson marked this conversation as resolved.
Resolved
cp.ProductName,
t.IsAuthorised
}
Expand All @@ -2156,7 +2157,7 @@ into g
{
ContractProductReportingId = g.Key.ContractProductReportingId,
ProductName = g.Key.ProductName,
OperatorName = g.Key.Name,
OperatorName = g.Key.OperatorName,
IsAuthorised = g.Key.IsAuthorised,
SalesCount = g.Count(),
SalesValue = g.Sum(x => x.TransactionAmount)
Expand All @@ -2174,7 +2175,8 @@ private async Task<Result<List<MerchantDailyPerformanceRecentSaleProjection>>> L
(from t in context.Transactions
join m in context.Merchants on t.MerchantId equals m.MerchantId
join cp in context.ContractProducts on new { t.ContractProductId, t.ContractId } equals new { cp.ContractProductId, cp.ContractId }
join op in context.Operators on t.OperatorId equals op.OperatorId
join op in context.Operators on t.OperatorId equals op.OperatorId into opJoin
from op in opJoin.DefaultIfEmpty()
where t.TransactionType == "Sale"
&& t.TransactionDate >= startDate
&& t.TransactionDate <= endDate
Expand All @@ -2184,7 +2186,7 @@ orderby t.TransactionDateTime descending
{
Reference = t.TransactionNumber,
Product = cp.ProductName,
Operator = op.Name,
Operator = op == null ? string.Empty : op.Name,
Status = t.IsAuthorised ? "Successful" : "Failed",
Amount = t.TransactionAmount,
TransactionDateTime = t.TransactionDateTime
Expand Down
55 changes: 55 additions & 0 deletions EstateReportingAPI.IntegrationTests/TransactionsEndpointTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1401,6 +1401,61 @@ public async Task TransactionsEndpoint_MerchantDailyPerformanceSummary_ReturnsMe
}
}

[Fact]
public async Task TransactionsEndpoint_MerchantDailyPerformanceSummary_PreservesTransactionsWithoutOperatorRows()
{
TransactionProcessor.Database.Entities.Merchant merchant = this.merchantsList.Single(m => m.Name == "Test Merchant 1");
var contract = this.contractList.Single(c => c.contractName == "Safaricom Contract");
var product = this.contractProducts.Single(cp => cp.Key == contract.contractId).Value.Single(p => p.productName == "50 KES Topup");
DateTime transactionDate = DateTime.Now.Date;

List<Transaction> transactions = [
await this.helper.BuildTransactionX(
transactionDate.AddHours(9),
merchant.MerchantId,
contract.operatorId,
contract.contractId,
product.productId,
"0000",
product.productValue,
2001),
await this.helper.BuildTransactionX(
transactionDate.AddHours(10),
merchant.MerchantId,
Guid.NewGuid(),
contract.contractId,
product.productId,
"0000",
product.productValue,
2002)
];

await this.helper.AddTransactionsX(transactions);

MerchantDailyPerformanceSummaryRequest request = new()
{
MerchantReportingId = merchant.MerchantReportingId,
StartDate = transactionDate,
EndDate = transactionDate
};

var result = await this.CreateAndSendHttpRequestMessage<MerchantDailyPerformanceSummaryResponse>(
$"{this.BaseRoute}/merchantdailyperformancesummary",
StringSerialiser.Serialise(request),
CancellationToken.None);

result.IsSuccess.ShouldBeTrue();

MerchantDailyPerformanceSummaryResponse response = result.Data;
response.ShouldNotBeNull();
response.Metrics.ShouldNotBeNull();
response.DrillDownTransactions.ShouldNotBeNull();

response.Metrics.Single(m => m.Title == "Total Sales Count").Value.ShouldBe(2);
response.Metrics.Single(m => m.Title == "Total Sales Value").Value.ShouldBe(transactions.Sum(t => t.TransactionAmount));
response.DrillDownTransactions.Count.ShouldBe(2);
}

[Fact]
public async Task TransactionsEndpoint_MerchantDailyPerformanceSummary_NoSales_ReturnsStableMetricCategories()
{
Expand Down
Loading