Always show overpaid amount if invoice is overpaid (#4192)

close #4146
This commit is contained in:
Umar Bolatov 2022-10-05 20:59:05 -07:00 committed by GitHub
parent 8155841a1d
commit d9f8c8d3b1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 5 deletions

View file

@ -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")]

View file

@ -134,5 +134,6 @@ namespace BTCPayServer.Models.InvoicingModels
public bool CanMarkStatus => CanMarkSettled || CanMarkInvalid;
public List<RefundData> Refunds { get; set; }
public bool ShowReceipt { get; set; }
public bool Overpaid { get; set; } = false;
}
}

View file

@ -1,4 +1,3 @@
@using BTCPayServer.Client.Models
@model (InvoiceDetailsModel Invoice, bool ShowAddress)
@{ var invoice = Model.Invoice; }
@ -14,7 +13,7 @@
<th class="text-end">Rate</th>
<th class="text-end">Paid</th>
<th class="text-end">Due</th>
@if (invoice.StatusException == InvoiceExceptionStatus.PaidOver)
@if (invoice.Overpaid)
{
<th class="text-end">Overpaid</th>
}
@ -34,7 +33,7 @@
<td class="text-end">@payment.Rate</td>
<td class="text-end">@payment.Paid</td>
<td class="text-end">@payment.Due</td>
@if (invoice.StatusException == InvoiceExceptionStatus.PaidOver)
@if (invoice.Overpaid)
{
<td class="text-end">@payment.Overpaid</td>
}