From 7e321d401663bc851cec3503a520f062cd84fc1e Mon Sep 17 00:00:00 2001
From: Kukks
Date: Sat, 5 Jan 2019 09:49:06 +0100
Subject: [PATCH] expand list invoices search
---
.../Controllers/InvoiceController.API.cs | 10 +++++-----
.../Controllers/InvoiceController.UI.cs | 4 +++-
.../Crowdfund/CrowdfundHubStreamer.cs | 4 +---
.../Services/Invoices/InvoiceRepository.cs | 19 ++++++++++++-------
.../Views/Invoice/ListInvoices.cshtml | 2 ++
5 files changed, 23 insertions(+), 16 deletions(-)
diff --git a/BTCPayServer/Controllers/InvoiceController.API.cs b/BTCPayServer/Controllers/InvoiceController.API.cs
index 58c637a9d..b44e51469 100644
--- a/BTCPayServer/Controllers/InvoiceController.API.cs
+++ b/BTCPayServer/Controllers/InvoiceController.API.cs
@@ -66,17 +66,17 @@ namespace BTCPayServer.Controllers
{
if (dateEnd != null)
dateEnd = dateEnd.Value + TimeSpan.FromDays(1); //Should include the end day
-
+
var query = new InvoiceQuery()
{
Count = limit,
Skip = offset,
EndDate = dateEnd,
StartDate = dateStart,
- OrderId = orderId,
- ItemCode = itemCode,
- Status = status == null ? null : new[] { status },
- StoreId = new[] { this.HttpContext.GetStoreData().Id }
+ OrderId = orderId == null ? null : new[] {orderId},
+ ItemCode = itemCode == null ? null : new[] {itemCode},
+ Status = status == null ? null : new[] {status},
+ StoreId = new[] {this.HttpContext.GetStoreData().Id}
};
var entities = (await _InvoiceRepository.GetInvoices(query))
diff --git a/BTCPayServer/Controllers/InvoiceController.UI.cs b/BTCPayServer/Controllers/InvoiceController.UI.cs
index 69d1ef708..c50fc36f5 100644
--- a/BTCPayServer/Controllers/InvoiceController.UI.cs
+++ b/BTCPayServer/Controllers/InvoiceController.UI.cs
@@ -473,7 +473,9 @@ namespace BTCPayServer.Controllers
: r,
Status = filterString.Filters.ContainsKey("status") ? filterString.Filters["status"].ToArray() : null,
ExceptionStatus = filterString.Filters.ContainsKey("exceptionstatus") ? filterString.Filters["exceptionstatus"].ToArray() : null,
- StoreId = filterString.Filters.ContainsKey("storeid") ? filterString.Filters["storeid"].ToArray() : null
+ StoreId = filterString.Filters.ContainsKey("storeid") ? filterString.Filters["storeid"].ToArray() : null,
+ ItemCode = filterString.Filters.ContainsKey("itemcode") ? filterString.Filters["itemcode"].ToArray() : null,
+ OrderId = filterString.Filters.ContainsKey("orderid") ? filterString.Filters["orderid"].ToArray() : null
});
return list;
diff --git a/BTCPayServer/Crowdfund/CrowdfundHubStreamer.cs b/BTCPayServer/Crowdfund/CrowdfundHubStreamer.cs
index e68b556a7..abf0fa627 100644
--- a/BTCPayServer/Crowdfund/CrowdfundHubStreamer.cs
+++ b/BTCPayServer/Crowdfund/CrowdfundHubStreamer.cs
@@ -272,7 +272,7 @@ namespace BTCPayServer.Hubs
{
return await _InvoiceRepository.GetInvoices(new InvoiceQuery()
{
- OrderId = appId == null? null :$"{CrowdfundInvoiceOrderIdPrefix}{appId}",
+ OrderId = appId == null? null : new []{$"{CrowdfundInvoiceOrderIdPrefix}{appId}"},
Status = new string[]{
InvoiceState.ToString(InvoiceStatus.New),
InvoiceState.ToString(InvoiceStatus.Paid),
@@ -281,7 +281,5 @@ namespace BTCPayServer.Hubs
StartDate = startDate
});
}
-
-
}
}
diff --git a/BTCPayServer/Services/Invoices/InvoiceRepository.cs b/BTCPayServer/Services/Invoices/InvoiceRepository.cs
index 47d4210ff..df9ca1b61 100644
--- a/BTCPayServer/Services/Invoices/InvoiceRepository.cs
+++ b/BTCPayServer/Services/Invoices/InvoiceRepository.cs
@@ -451,11 +451,16 @@ retry:
if (queryObject.EndDate != null)
query = query.Where(i => i.Created <= queryObject.EndDate.Value);
- if (queryObject.ItemCode != null)
- query = query.Where(i => i.ItemCode == queryObject.ItemCode);
-
- if (queryObject.OrderId != null)
- query = query.Where(i => i.OrderId == queryObject.OrderId);
+ if (queryObject.OrderId != null && queryObject.OrderId.Length > 0)
+ {
+ var statusSet = queryObject.OrderId.ToHashSet();
+ query = query.Where(i => statusSet.Contains(i.OrderId));
+ }
+ if (queryObject.ItemCode != null && queryObject.ItemCode.Length > 0)
+ {
+ var statusSet = queryObject.ItemCode.ToHashSet();
+ query = query.Where(i => statusSet.Contains(i.ItemCode));
+ }
if (queryObject.Status != null && queryObject.Status.Length > 0)
{
@@ -666,12 +671,12 @@ retry:
get; set;
}
- public string OrderId
+ public string[] OrderId
{
get; set;
}
- public string ItemCode
+ public string[] ItemCode
{
get; set;
}
diff --git a/BTCPayServer/Views/Invoice/ListInvoices.cshtml b/BTCPayServer/Views/Invoice/ListInvoices.cshtml
index a415e5706..c3a877d1b 100644
--- a/BTCPayServer/Views/Invoice/ListInvoices.cshtml
+++ b/BTCPayServer/Views/Invoice/ListInvoices.cshtml
@@ -29,6 +29,8 @@
storeid:id
for filtering a specific store
+ orderid:id
for filtering a specific order
+ itemcode:code
for filtering a specific type of item purchased through the pos or crowdfund apps
status:(expired|invalid|complete|confirmed|paid|new)
for filtering a specific status
exceptionstatus:(paidover|paidlate|paidpartial)
for filtering a specific exception state
unusual:(true|false)
for filtering invoices which might requires merchant attention (those invalid or with an exceptionstatus)