From 1f8a4703d2e8fef265f7f0ad3963e5d68451065e Mon Sep 17 00:00:00 2001 From: Rick Falkvinge Date: Tue, 26 Sep 2017 13:07:16 +0200 Subject: [PATCH] Enabled nonpresentation currency for outbound invoices --- Logic/Financial/InboundInvoice.cs | 2 +- Logic/Financial/OutboundInvoice.cs | 46 +++++++++++++++++++ .../v5/Financial/CreateInboundInvoice.aspx.cs | 1 - .../Financial/CreateOutboundInvoice.aspx.cs | 12 ++++- .../Json-ListInvoicesInbound.aspx.cs | 2 +- 5 files changed, 58 insertions(+), 5 deletions(-) diff --git a/Logic/Financial/InboundInvoice.cs b/Logic/Financial/InboundInvoice.cs index 90dcc572..f72854a0 100644 --- a/Logic/Financial/InboundInvoice.cs +++ b/Logic/Financial/InboundInvoice.cs @@ -301,7 +301,7 @@ namespace Swarmops.Logic.Financial } } - public string DisplayAmount + public string DisplayNativeAmount { get { diff --git a/Logic/Financial/OutboundInvoice.cs b/Logic/Financial/OutboundInvoice.cs index c3daaaf2..f771cf44 100644 --- a/Logic/Financial/OutboundInvoice.cs +++ b/Logic/Financial/OutboundInvoice.cs @@ -338,5 +338,51 @@ namespace Swarmops.Logic.Financial return credit; } + + + public string DisplayNativeAmount + { + get + { + if (HasNativeCurrency) + { + Money money = NativeCurrencyAmount; + return money.Currency.DisplayCode + " " + (money.Cents / 100.0).ToString("N2"); + } + else + { + return (AmountCents / 100.0).ToString("N2"); + } + } + } + + public bool HasNativeCurrency + { + get + { + return + ObjectOptionalData.ForObject(this) + .GetOptionalDataString(ObjectOptionalDataType.NativeCurrencyCode) + .Length > 0; + } + } + + public Money NativeCurrencyAmount + { + get + { + ObjectOptionalData optionalData = ObjectOptionalData.ForObject(this); + + return new Money(optionalData.GetOptionalDataInt64(ObjectOptionalDataType.NativeCurrencyAmountCents), Currency.FromCode(optionalData.GetOptionalDataString(ObjectOptionalDataType.NativeCurrencyCode))); + } + set + { + ObjectOptionalData optionalData = ObjectOptionalData.ForObject(this); + + optionalData.SetOptionalDataInt64(ObjectOptionalDataType.NativeCurrencyAmountCents, value.Cents); + optionalData.SetOptionalDataString(ObjectOptionalDataType.NativeCurrencyCode, value.Currency.Code); + } + } + } } \ No newline at end of file diff --git a/Site/Pages/v5/Financial/CreateInboundInvoice.aspx.cs b/Site/Pages/v5/Financial/CreateInboundInvoice.aspx.cs index 8ca2b9e4..ebbd757e 100644 --- a/Site/Pages/v5/Financial/CreateInboundInvoice.aspx.cs +++ b/Site/Pages/v5/Financial/CreateInboundInvoice.aspx.cs @@ -192,7 +192,6 @@ namespace Swarmops.Frontend.Pages.v5.Financial invoice.NativeCurrencyAmount = currencyEntered; } - // Display success message this._invoiceId = invoice.Identity; // a property returns the localized string diff --git a/Site/Pages/v5/Financial/CreateOutboundInvoice.aspx.cs b/Site/Pages/v5/Financial/CreateOutboundInvoice.aspx.cs index 1a56fd3c..329a951c 100644 --- a/Site/Pages/v5/Financial/CreateOutboundInvoice.aspx.cs +++ b/Site/Pages/v5/Financial/CreateOutboundInvoice.aspx.cs @@ -164,9 +164,17 @@ namespace Swarmops.Frontend.Pages.v5.Financial invoice.AddItem(this.TextPurpose.Text, amountCents); - // TODO: VAT + // TODO: VAT -- needs to be PER ITEM, and dbfields must update for this, quite a large work item, do not short circuit hack this - documents.SetForeignObjectForAll (invoice); + documents.SetForeignObjectForAll(invoice); + + // If invoice is denominated in a non-presentation currency, record the native values for proper payment + + if (this.CurrencyAmount.NonPresentationCurrencyUsed) + { + Money currencyEntered = this.CurrencyAmount.NonPresentationCurrencyAmount; + invoice.NativeCurrencyAmount = currencyEntered; + } // Display success message diff --git a/Site/Pages/v5/Financial/Json-ListInvoicesInbound.aspx.cs b/Site/Pages/v5/Financial/Json-ListInvoicesInbound.aspx.cs index f7133066..5eaf61cf 100644 --- a/Site/Pages/v5/Financial/Json-ListInvoicesInbound.aspx.cs +++ b/Site/Pages/v5/Financial/Json-ListInvoicesInbound.aspx.cs @@ -31,7 +31,7 @@ public partial class Pages_v5_Finance_Json_ListInvoicesInbound : DataV5Base Response.End(); } - private static int SortInvoicesByDueDate(InboundInvoice a, InboundInvoice b) + private static int SortInvoicesByDueDateReverse(InboundInvoice a, InboundInvoice b) { return DateTime.Compare(b.DueDate, a.DueDate); }