From 9cf57ba3bfaf19a663b3af64b7c64a3d814c5437 Mon Sep 17 00:00:00 2001 From: Rick Falkvinge Date: Mon, 9 Oct 2017 16:48:05 +0200 Subject: [PATCH] Work on VAT reports --- Logic/Financial/VatReport.cs | 37 +++-- Logic/Financial/VatReports.cs | 11 +- Logic/Logic.csproj | 9 ++ .../Logic.Financial.VatReport.Designer.cs | 90 ++++++++++++ .../Resources/Logic.Financial.VatReport.resx | 129 ++++++++++++++++++ .../Pages/v5/Ledgers/BalanceTransactions.aspx | 44 +++++- .../v5/Ledgers/BalanceTransactions.aspx.cs | 43 +++++- .../BalanceTransactions.aspx.designer.cs | 27 ++++ 8 files changed, 371 insertions(+), 19 deletions(-) create mode 100644 Logic/Resources/Logic.Financial.VatReport.Designer.cs create mode 100644 Logic/Resources/Logic.Financial.VatReport.resx diff --git a/Logic/Financial/VatReport.cs b/Logic/Financial/VatReport.cs index d0be05f0..f1b186a9 100644 --- a/Logic/Financial/VatReport.cs +++ b/Logic/Financial/VatReport.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; using Swarmops.Basic.Types.Financial; @@ -71,18 +72,6 @@ namespace Swarmops.Logic.Financial newReport.Release(); - string transactionComment = String.Format("VAT Report {0}", year); - - if (monthCount != 12) - { - transactionComment += String.Format(" {0:MMM}", new DateTime(year, startMonth, 16)); - } - - if (monthCount != 1) - { - transactionComment += String.Format("-{0:MMM}", new DateTime(year, startMonth+monthCount-1, 16)); - } - // Create financial TX that moves this VAT from unreported to reported Int64 differenceCents = newReport.VatInboundCents - newReport.VatOutboundCents; @@ -92,7 +81,8 @@ namespace Swarmops.Logic.Financial // if there's anything to report FinancialTransaction vatReportTransaction = FinancialTransaction.Create(organization, endDate.AddDays(4).AddHours(9), - transactionComment); + newReport.Description); + if (newReport.VatInboundCents > 0) { vatReportTransaction.AddRow(organization.FinancialAccounts.AssetsVatInboundUnreported, @@ -229,6 +219,27 @@ namespace Swarmops.Logic.Financial return rows; } + + public string Description + { + get + { + switch (MonthCount) + { + case 1: + return String.Format(Resources.Logic_Financial_VatReport.Description_SingleMonth, + new DateTime(YearMonthStart/100, YearMonthStart%100, 2)); + case 12: + return String.Format(Resources.Logic_Financial_VatReport.Description_FullYear, + YearMonthStart/100); + default: + DateTime start = new DateTime(YearMonthStart/100, YearMonthStart%100, 2); + + return String.Format(Resources.Logic_Financial_VatReport.Description_Months, + start, start.AddMonths(MonthCount - 1)); + } + } + } } } diff --git a/Logic/Financial/VatReports.cs b/Logic/Financial/VatReports.cs index bc63199c..3bad815f 100644 --- a/Logic/Financial/VatReports.cs +++ b/Logic/Financial/VatReports.cs @@ -28,7 +28,7 @@ namespace Swarmops.Logic.Financial // Get the list of previous VAT reports - VatReports reports = VatReports.ForOrganization(organization); + VatReports reports = VatReports.ForOrganization(organization, true); if (reports.Count == 0) { @@ -63,9 +63,14 @@ namespace Swarmops.Logic.Financial return a.YearMonthStart - b.YearMonthStart; } - public static VatReports ForOrganization(Organization organization) + public static VatReports ForOrganization(Organization organization, bool includeClosed = false) { - return FromArray(SwarmDb.GetDatabaseForReading().GetVatReports(organization)); + if (includeClosed) + { + return FromArray(SwarmDb.GetDatabaseForReading().GetVatReports(organization)); + } + + return FromArray(SwarmDb.GetDatabaseForReading().GetVatReports(organization, DatabaseCondition.OpenTrue)); } } } diff --git a/Logic/Logic.csproj b/Logic/Logic.csproj index 49177135..8e489ff0 100644 --- a/Logic/Logic.csproj +++ b/Logic/Logic.csproj @@ -150,6 +150,11 @@ True Logic.Financial.Payout.resx + + True + True + Logic.Financial.VatReport.resx + True True @@ -597,6 +602,10 @@ + + ResXFileCodeGenerator + Logic.Financial.VatReport.Designer.cs + diff --git a/Logic/Resources/Logic.Financial.VatReport.Designer.cs b/Logic/Resources/Logic.Financial.VatReport.Designer.cs new file mode 100644 index 00000000..3f675068 --- /dev/null +++ b/Logic/Resources/Logic.Financial.VatReport.Designer.cs @@ -0,0 +1,90 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Swarmops.Logic.Resources { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Logic_Financial_VatReport { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Logic_Financial_VatReport() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Swarmops.Logic.Resources.Logic.Financial.VatReport", typeof(Logic_Financial_VatReport).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to VAT report {0}. + /// + internal static string Description_FullYear { + get { + return ResourceManager.GetString("Description_FullYear", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to VAT report for {0:yyyy} {0:MMM}-{1:MMM}. + /// + internal static string Description_Months { + get { + return ResourceManager.GetString("Description_Months", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to VAT report for {0:MMMM} {0:yyyy}. + /// + internal static string Description_SingleMonth { + get { + return ResourceManager.GetString("Description_SingleMonth", resourceCulture); + } + } + } +} diff --git a/Logic/Resources/Logic.Financial.VatReport.resx b/Logic/Resources/Logic.Financial.VatReport.resx new file mode 100644 index 00000000..ba89f587 --- /dev/null +++ b/Logic/Resources/Logic.Financial.VatReport.resx @@ -0,0 +1,129 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + VAT report {0} + + + VAT report for {0:yyyy} {0:MMM}-{1:MMM} + + + VAT report for {0:MMMM} {0:yyyy} + + \ No newline at end of file diff --git a/Site/Pages/v5/Ledgers/BalanceTransactions.aspx b/Site/Pages/v5/Ledgers/BalanceTransactions.aspx index 30aeeb05..c78b0d5e 100644 --- a/Site/Pages/v5/Ledgers/BalanceTransactions.aspx +++ b/Site/Pages/v5/Ledgers/BalanceTransactions.aspx @@ -37,7 +37,12 @@ function onFixTransaction(newTransactionId) { transactionId = newTransactionId; $('span#spanModalTransactionId').text("<%=Resources.Global.Global_LoadingPlaceholder%>"); - SwarmopsJS.formatInteger(transactionId, function (result) { $('span#spanModalTransactionId').text(result); }); + SwarmopsJS.ajaxCall( + '/Pages/v5/Ledgers/BalanceTransactions.aspx/GetTransactionDisplayIdentity', + { transactionId: transactionId }, + function(result) { + $('span#spanModalTransactionId').text(result); + }); $('input:radio[name="TxOptions"]').prop('checked', false); $('div.radioOption').hide(); <%= this.DialogTx.ClientID %>_open(); @@ -96,6 +101,16 @@ } + if (data.OpenVatReportData != null && data.OpenVatReportData.length > 0) { + $('#divVatReport').show(); + <%=this.DropOpenVatReports.ClientID%>_loadData(data.OpenVatReportData); + <%=this.DropOpenVatReports.ClientID%>_text("<%=Resources.Global.Global_SelectOne%>"); + } else { + $('#divVatReport').hide(); + <%=this.DropOpenVatReports.ClientID%>_loadData({}); + <%=this.DropOpenVatReports.ClientID%>_text("<%=Resources.Global.Global_NoMatch%>"); + } + }); } @@ -161,6 +176,21 @@ } } + + function onMatchVatReport() { + var vatReportId = <%=this.DropOpenVatReports.ClientID%>_val(); + + if (vatReportId > 0) { + <%= this.DialogTx.ClientID %>_close(); + SwarmopsJS.ajaxCall( + "/Pages/v5/Ledgers/BalanceTransactions.aspx/MatchTransactionOpenVatReport", + { transactionId: transactionId, vatReportId: vatReportId }, + function () { + $('#gridTransactions').datagrid('reload'); + }); + + } } + var buttonBalanceValue = SwarmopsJS.unescape('<%=this.Localized_ButtonBalance%>'); var buttonPayoutValue = SwarmopsJS.unescape('<%=this.Localized_ButtonPayout%>'); var buttonPayoutForeignValue = SwarmopsJS.unescape('<%=this.Localized_ButtonPayoutForeign%>'); @@ -260,6 +290,18 @@ +
+

+
+
+ ​
+ +
+ +
+