Fix formatting of currencies in Invoice detail page

This commit is contained in:
nicolas.dorier 2019-01-30 19:18:44 +09:00
parent d05bb6c60e
commit 1a98bfba36
4 changed files with 18 additions and 13 deletions

View file

@ -65,6 +65,7 @@ namespace BTCPayServer.Controllers
OrderId = invoice.OrderId, OrderId = invoice.OrderId,
BuyerInformation = invoice.BuyerInformation, BuyerInformation = invoice.BuyerInformation,
Fiat = _CurrencyNameTable.DisplayFormatCurrency(dto.Price, dto.Currency), Fiat = _CurrencyNameTable.DisplayFormatCurrency(dto.Price, dto.Currency),
TaxIncluded = _CurrencyNameTable.DisplayFormatCurrency(invoice.ProductInformation.TaxIncluded, dto.Currency),
NotificationEmail = invoice.NotificationEmail, NotificationEmail = invoice.NotificationEmail,
NotificationUrl = invoice.NotificationURL, NotificationUrl = invoice.NotificationURL,
RedirectUrl = invoice.RedirectURL, RedirectUrl = invoice.RedirectURL,
@ -81,9 +82,9 @@ namespace BTCPayServer.Controllers
var paymentMethodId = data.GetId(); var paymentMethodId = data.GetId();
var cryptoPayment = new InvoiceDetailsModel.CryptoPayment(); var cryptoPayment = new InvoiceDetailsModel.CryptoPayment();
cryptoPayment.PaymentMethod = ToString(paymentMethodId); cryptoPayment.PaymentMethod = ToString(paymentMethodId);
cryptoPayment.Due = $"{accounting.Due} {paymentMethodId.CryptoCode}"; cryptoPayment.Due = _CurrencyNameTable.DisplayFormatCurrency(accounting.Due.ToDecimal(MoneyUnit.BTC), paymentMethodId.CryptoCode);
cryptoPayment.Paid = $"{accounting.CryptoPaid} {paymentMethodId.CryptoCode}"; cryptoPayment.Paid = _CurrencyNameTable.DisplayFormatCurrency(accounting.CryptoPaid.ToDecimal(MoneyUnit.BTC), paymentMethodId.CryptoCode);
cryptoPayment.Overpaid = $"{accounting.OverpaidHelper} {paymentMethodId.CryptoCode}"; cryptoPayment.Overpaid = _CurrencyNameTable.DisplayFormatCurrency(accounting.OverpaidHelper.ToDecimal(MoneyUnit.BTC), paymentMethodId.CryptoCode);
var onchainMethod = data.GetPaymentMethodDetails() as Payments.Bitcoin.BitcoinLikeOnChainPaymentMethod; var onchainMethod = data.GetPaymentMethodDetails() as Payments.Bitcoin.BitcoinLikeOnChainPaymentMethod;
if (onchainMethod != null) if (onchainMethod != null)

View file

@ -105,6 +105,7 @@ namespace BTCPayServer.Models.InvoicingModels
get; get;
set; set;
} }
public string TaxIncluded { get; set; }
public BuyerInformation BuyerInformation public BuyerInformation BuyerInformation
{ {
get; get;

View file

@ -121,15 +121,18 @@ namespace BTCPayServer.Services.Rates
var provider = GetNumberFormatInfo(currency, true); var provider = GetNumberFormatInfo(currency, true);
var currencyData = GetCurrencyData(currency, true); var currencyData = GetCurrencyData(currency, true);
var divisibility = currencyData.Divisibility; var divisibility = currencyData.Divisibility;
while (true) if (value != 0m)
{ {
var rounded = decimal.Round(value, divisibility, MidpointRounding.AwayFromZero); while (true)
if ((Math.Abs(rounded - value) / value) < 0.001m)
{ {
value = rounded; var rounded = decimal.Round(value, divisibility, MidpointRounding.AwayFromZero);
break; if ((Math.Abs(rounded - value) / value) < 0.001m)
{
value = rounded;
break;
}
divisibility++;
} }
divisibility++;
} }
if (divisibility != provider.CurrencyDecimalDigits) if (divisibility != provider.CurrencyDecimalDigits)
{ {

View file

@ -155,11 +155,11 @@
</tr> </tr>
<tr> <tr>
<th>Price</th> <th>Price</th>
<td>@Model.ProductInformation.Price @Model.ProductInformation.Currency</td> <td>@Model.Fiat</td>
</tr> </tr>
<tr> <tr>
<th>Tax included</th> <th>Tax included</th>
<td>@Model.ProductInformation.TaxIncluded @Model.ProductInformation.Currency</td> <td>@Model.TaxIncluded</td>
</tr> </tr>
</table> </table>
} }
@ -182,11 +182,11 @@
</tr> </tr>
<tr> <tr>
<th>Price</th> <th>Price</th>
<td>@Model.ProductInformation.Price @Model.ProductInformation.Currency</td> <td>@Model.Fiat</td>
</tr> </tr>
<tr> <tr>
<th>Tax included</th> <th>Tax included</th>
<td>@Model.ProductInformation.TaxIncluded @Model.ProductInformation.Currency</td> <td>@Model.TaxIncluded</td>
</tr> </tr>
</table> </table>
</div> </div>