From d9f8c8d3b1b2ceab9709ad4656cc64cbf3fde4ca Mon Sep 17 00:00:00 2001 From: Umar Bolatov Date: Wed, 5 Oct 2022 20:59:05 -0700 Subject: [PATCH] Always show overpaid amount if invoice is overpaid (#4192) close #4146 --- .../Controllers/UIInvoiceController.UI.cs | 18 ++++++++++++++++-- .../InvoicingModels/InvoiceDetailsModel.cs | 1 + .../ListInvoicesPaymentsPartial.cshtml | 5 ++--- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/BTCPayServer/Controllers/UIInvoiceController.UI.cs b/BTCPayServer/Controllers/UIInvoiceController.UI.cs index 21788bbf9..053a46b51 100644 --- a/BTCPayServer/Controllers/UIInvoiceController.UI.cs +++ b/BTCPayServer/Controllers/UIInvoiceController.UI.cs @@ -147,6 +147,7 @@ namespace BTCPayServer.Controllers var details = InvoicePopulatePayments(invoice); model.CryptoPayments = details.CryptoPayments; model.Payments = details.Payments; + model.Overpaid = details.Overpaid; return View(model); } @@ -467,15 +468,25 @@ namespace BTCPayServer.Controllers private InvoiceDetailsModel InvoicePopulatePayments(InvoiceEntity invoice) { - return new InvoiceDetailsModel + + var overpaid = false; + var model = new InvoiceDetailsModel { Archived = invoice.Archived, Payments = invoice.GetPayments(false), + Overpaid = true, CryptoPayments = invoice.GetPaymentMethods().Select( data => { var accounting = data.Calculate(); var paymentMethodId = data.GetId(); + var overpaidAmount = accounting.OverpaidHelper.ToDecimal(MoneyUnit.BTC); + + if (overpaidAmount > 0) + { + overpaid = true; + } + return new InvoiceDetailsModel.CryptoPayment { PaymentMethodId = paymentMethodId, @@ -486,13 +497,16 @@ namespace BTCPayServer.Controllers accounting.CryptoPaid.ToDecimal(MoneyUnit.BTC), paymentMethodId.CryptoCode), Overpaid = _CurrencyNameTable.DisplayFormatCurrency( - accounting.OverpaidHelper.ToDecimal(MoneyUnit.BTC), paymentMethodId.CryptoCode), + overpaidAmount, paymentMethodId.CryptoCode), Address = data.GetPaymentMethodDetails().GetPaymentDestination(), Rate = ExchangeRate(data), PaymentMethodRaw = data }; }).ToList() }; + model.Overpaid = overpaid; + + return model; } [HttpPost("invoices/{invoiceId}/archive")] diff --git a/BTCPayServer/Models/InvoicingModels/InvoiceDetailsModel.cs b/BTCPayServer/Models/InvoicingModels/InvoiceDetailsModel.cs index a198f1cba..a382b5fd9 100644 --- a/BTCPayServer/Models/InvoicingModels/InvoiceDetailsModel.cs +++ b/BTCPayServer/Models/InvoicingModels/InvoiceDetailsModel.cs @@ -134,5 +134,6 @@ namespace BTCPayServer.Models.InvoicingModels public bool CanMarkStatus => CanMarkSettled || CanMarkInvalid; public List Refunds { get; set; } public bool ShowReceipt { get; set; } + public bool Overpaid { get; set; } = false; } } diff --git a/BTCPayServer/Views/UIInvoice/ListInvoicesPaymentsPartial.cshtml b/BTCPayServer/Views/UIInvoice/ListInvoicesPaymentsPartial.cshtml index d979bcd2f..39c334c51 100644 --- a/BTCPayServer/Views/UIInvoice/ListInvoicesPaymentsPartial.cshtml +++ b/BTCPayServer/Views/UIInvoice/ListInvoicesPaymentsPartial.cshtml @@ -1,4 +1,3 @@ -@using BTCPayServer.Client.Models @model (InvoiceDetailsModel Invoice, bool ShowAddress) @{ var invoice = Model.Invoice; } @@ -14,7 +13,7 @@ Rate Paid Due - @if (invoice.StatusException == InvoiceExceptionStatus.PaidOver) + @if (invoice.Overpaid) { Overpaid } @@ -34,7 +33,7 @@ @payment.Rate @payment.Paid @payment.Due - @if (invoice.StatusException == InvoiceExceptionStatus.PaidOver) + @if (invoice.Overpaid) { @payment.Overpaid }