From 4660638446caa1862d1524cfb2900850cb167902 Mon Sep 17 00:00:00 2001 From: Rick Falkvinge Date: Tue, 3 Oct 2017 20:26:03 +0200 Subject: [PATCH] Invoice matching is coming together --- .../Pages.Ledgers.designer.cs | 56 ++++++++++++++++++- Site/App_GlobalResources/Pages.Ledgers.resx | 22 +++++++- .../Pages/v5/Ledgers/BalanceTransactions.aspx | 10 ++-- .../v5/Ledgers/BalanceTransactions.aspx.cs | 48 ++++++++++++++-- .../BalanceTransactions.aspx.designer.cs | 17 ++++-- 5 files changed, 138 insertions(+), 15 deletions(-) diff --git a/Site/App_GlobalResources/Pages.Ledgers.designer.cs b/Site/App_GlobalResources/Pages.Ledgers.designer.cs index 3ded7cb7..d75b9cac 100644 --- a/Site/App_GlobalResources/Pages.Ledgers.designer.cs +++ b/Site/App_GlobalResources/Pages.Ledgers.designer.cs @@ -511,7 +511,7 @@ namespace Resources.Pages { } /// - /// Looks up a localized string similar to Matching Amount, Off In Time. + /// Looks up a localized string similar to Matching Amount But On Unexpected Date/Time. /// internal static string BalanceTransactions_ExactMatchesFarAway { get { @@ -591,6 +591,15 @@ namespace Resources.Pages { } } + /// + /// Looks up a localized string similar to Match invoice. + /// + internal static string BalanceTransactions_ModalDialog_ButtonOutboundInvoice { + get { + return ResourceManager.GetString("BalanceTransactions_ModalDialog_ButtonOutboundInvoice", resourceCulture); + } + } + /// /// Looks up a localized string similar to Match. /// @@ -645,6 +654,24 @@ namespace Resources.Pages { } } + /// + /// Looks up a localized string similar to Match this to an open outbound invoice?. + /// + internal static string BalanceTransactions_ModalDialog_RadioOutboundInvoice { + get { + return ResourceManager.GetString("BalanceTransactions_ModalDialog_RadioOutboundInvoice", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Match this to an open outbound invoice in a nonstandard currency (5% forex tolerance)?. + /// + internal static string BalanceTransactions_ModalDialog_RadioOutboundInvoiceForeign { + get { + return ResourceManager.GetString("BalanceTransactions_ModalDialog_RadioOutboundInvoiceForeign", resourceCulture); + } + } + /// /// Looks up a localized string similar to Match the transaction difference to an open, unmatched payout?. /// @@ -672,6 +699,15 @@ namespace Resources.Pages { } } + /// + /// Looks up a localized string similar to Most Probable Match. + /// + internal static string BalanceTransactions_MostProbableMatch { + get { + return ResourceManager.GetString("BalanceTransactions_MostProbableMatch", resourceCulture); + } + } + /// /// Looks up a localized string similar to (No open payouts). /// @@ -699,6 +735,15 @@ namespace Resources.Pages { } } + /// + /// Looks up a localized string similar to Outbound Invoice #{0:N0} for {1}, due {2}: {3}. + /// + internal static string BalanceTransactions_OutboundInvoiceMatch { + get { + return ResourceManager.GetString("BalanceTransactions_OutboundInvoiceMatch", resourceCulture); + } + } + /// /// Looks up a localized string similar to Balance & Match Transactions. /// @@ -735,6 +780,15 @@ namespace Resources.Pages { } } + /// + /// Looks up a localized string similar to VAT Report for {1:yyyy-MMM} surplus. + /// + internal static string BalanceTransactions_VatReportMatch { + get { + return ResourceManager.GetString("BalanceTransactions_VatReportMatch", resourceCulture); + } + } + /// /// Looks up a localized string similar to Bitcoin Address. /// diff --git a/Site/App_GlobalResources/Pages.Ledgers.resx b/Site/App_GlobalResources/Pages.Ledgers.resx index ab78b92c..a5dc810b 100644 --- a/Site/App_GlobalResources/Pages.Ledgers.resx +++ b/Site/App_GlobalResources/Pages.Ledgers.resx @@ -681,7 +681,7 @@ Header in selection list. Capitalize as customary for culture. - Matching Amount, Off In Time + Matching Amount But On Unexpected Date/Time Header in selection list. Capitalize as customary for culture. @@ -836,4 +836,24 @@ Add new transaction Option in sidebar + + Match invoice + + + Match this to an open outbound invoice? + + + Match this to an open outbound invoice in a nonstandard currency (5% forex tolerance)? + + + Most Probable Match + This is the header of a match where the transaction description somehow matches the invoice reference. + + + Outbound Invoice #{0:N0} for {1}, due {2}: {3} + Argument {0} is the invoice identity, {1} the customer name, {2} the due date and {3} the invoice-currencied amount (which can be different from the org's presentation currency) + + + VAT Report for {1:yyyy-MMM} surplus + \ No newline at end of file diff --git a/Site/Pages/v5/Ledgers/BalanceTransactions.aspx b/Site/Pages/v5/Ledgers/BalanceTransactions.aspx index 94d9a10e..fd749d01 100644 --- a/Site/Pages/v5/Ledgers/BalanceTransactions.aspx +++ b/Site/Pages/v5/Ledgers/BalanceTransactions.aspx @@ -29,6 +29,7 @@ $('#buttonExecuteBalance').val(buttonBalanceValue); $('#buttonExecutePayout').val(buttonPayoutValue); $('#buttonExecutePayoutForeign').val(buttonPayoutForeignValue); + $('#buttonExecuteOutboundInvoice').val(buttonOutboundInvoiceValue); }); var transactionId = 0; @@ -148,6 +149,7 @@ var buttonBalanceValue = SwarmopsJS.unescape(''); var buttonPayoutValue = SwarmopsJS.unescape(''); var buttonPayoutForeignValue = SwarmopsJS.unescape(''); + var buttonOutboundInvoiceValue = SwarmopsJS.unescape(''); @@ -232,14 +234,14 @@
-

-
+

+
​
- +
diff --git a/Site/Pages/v5/Ledgers/BalanceTransactions.aspx.cs b/Site/Pages/v5/Ledgers/BalanceTransactions.aspx.cs index 55af4a82..304cfc4b 100644 --- a/Site/Pages/v5/Ledgers/BalanceTransactions.aspx.cs +++ b/Site/Pages/v5/Ledgers/BalanceTransactions.aspx.cs @@ -44,13 +44,16 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers this.LabelDescribePayout.Text = Resources.Pages.Ledgers.BalanceTransactions_ModalDialog_DescribePayout; this.LabelDescribePayoutForeign.Text = Resources.Pages.Ledgers.BalanceTransactions_ModalDialog_DescribePayoutForeign; + this.LabelDescribeOutboundInvoice.Text = this.LabelRadioPayout.Text = Resources.Pages.Ledgers.BalanceTransactions_ModalDialog_RadioPayout; this.LabelRadioPayoutForeign.Text = String.Format(Resources.Pages.Ledgers.BalanceTransactions_ModalDialog_RadioPayoutForeign, 5); + this.LabelRadioOutboundInvoice.Text = this.LiteralButtonBalance.Text = JavascriptEscape(Resources.Pages.Ledgers.BalanceTransactions_ModalDialog_ButtonBalance); this.LiteralButtonPayout.Text = JavascriptEscape(Resources.Pages.Ledgers.BalanceTransactions_ModalDialog_ButtonPayout); this.LiteralButtonPayoutForeign.Text = JavascriptEscape(Resources.Pages.Ledgers.BalanceTransactions_ModalDialog_ButtonPayout); + this.LiteralButtonOutboundInvoice.Text = JavascriptEscape(Resources.Pages.Ledgers.BalanceTransactions_ModalDialog_ButtonOutboundInvoice); } @@ -189,16 +192,24 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers if (invoice.AmountCents > matchAmount * 95 / 100 && invoice.AmountCents < matchAmount * 105 / 100) { - string description = String.Format(Resources.Pages.Ledgers.BalanceTransactions_PayoutMatch, invoice.Identity, - invoice.DueDate, invoice.CustomerName, invoice.Organization.Currency.DisplayCode, invoice.AmountCents / 100.0, - invoice.DisplayNativeAmount); + string description = String.Format(Resources.Pages.Ledgers.BalanceTransactions_OutboundInvoiceMatch, invoice.Identity, + invoice.CustomerName, invoice.DueDate, invoice.DisplayNativeAmount); + + if (invoice.HasNativeCurrency) + { + description += " (" + transaction.Organization.Currency.DisplayCode + " " + + (invoice.AmountCents/100.0).ToString("N2") + ")"; + } + + bool invoiceIdMatch = DescriptionContainsInvoiceReference(invoice.Reference, invoice.TheirReference, transaction.Description); + if (invoice.AmountCents == matchAmount) { listExact.Add(new DropdownOption { id = invoice.Identity.ToString(CultureInfo.InvariantCulture), - @group = Resources.Pages.Ledgers.BalanceTransactions_ExactMatches, + @group = invoiceIdMatch? Resources.Pages.Ledgers.BalanceTransactions_MostProbableMatch : Resources.Pages.Ledgers.BalanceTransactions_ExactMatches, text = description }); } @@ -207,7 +218,7 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers listTolerant.Add(new DropdownOption { id = invoice.Identity.ToString(CultureInfo.InvariantCulture), - @group = Resources.Pages.Ledgers.BalanceTransactions_FivePercentMatches, + @group = invoiceIdMatch ? Resources.Pages.Ledgers.BalanceTransactions_MostProbableMatch : Resources.Pages.Ledgers.BalanceTransactions_FivePercentMatches, text = description }); } @@ -220,6 +231,33 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers return result; } + private static bool DescriptionContainsInvoiceReference(string ourReference, string theirReference, string description) + { + // Remove some noise + + ourReference = ourReference.Replace("-", "").Replace(".", "").Replace("/", ""); + theirReference = theirReference.Replace("-", "").Replace(".", "").Replace("/", ""); + description = description.Replace("-", "").Replace(".", "").Replace("/", ""); + + // For every word in the description, check if it's the invoice reference. If so, return true + + string[] descriptionWords = description.Split(' '); + + foreach (string descriptionWord in descriptionWords) + { + if (descriptionWord == ourReference) + { + return true; + } + if (descriptionWord == theirReference) + { + return true; + } + } + + return false; + } + [WebMethod] public static void BalanceTransactionManually(int transactionId, int accountId) { diff --git a/Site/Pages/v5/Ledgers/BalanceTransactions.aspx.designer.cs b/Site/Pages/v5/Ledgers/BalanceTransactions.aspx.designer.cs index 6a84ed87..a4f94c88 100644 --- a/Site/Pages/v5/Ledgers/BalanceTransactions.aspx.designer.cs +++ b/Site/Pages/v5/Ledgers/BalanceTransactions.aspx.designer.cs @@ -39,6 +39,15 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers { /// protected global::System.Web.UI.WebControls.Literal LiteralButtonPayoutForeign; + /// + /// LiteralButtonOutboundInvoice control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.Literal LiteralButtonOutboundInvoice; + /// /// LabelHeaderUnbalancedTransactions control. /// @@ -211,13 +220,13 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers { protected global::System.Web.UI.WebControls.Label LabelDescribePayoutForeign; /// - /// LabelRadioPaymentDirect control. + /// LabelRadioOutboundInvoice control. /// /// /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// - protected global::System.Web.UI.WebControls.Label LabelRadioPaymentDirect; + protected global::System.Web.UI.WebControls.Label LabelRadioOutboundInvoice; /// /// DropOpenOutboundInvoices control. @@ -229,13 +238,13 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers { protected global::Swarmops.Frontend.Controls.Base.DropDown DropOpenOutboundInvoices; /// - /// Label2 control. + /// LabelDescribeOutboundInvoice control. /// /// /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// - protected global::System.Web.UI.WebControls.Label Label2; + protected global::System.Web.UI.WebControls.Label LabelDescribeOutboundInvoice; /// /// LabelRadioExistingPayment control.