Work on VAT reports

This commit is contained in:
Rick Falkvinge
2017-10-09 16:48:05 +02:00
parent cf83c24135
commit 9cf57ba3bf
8 changed files with 371 additions and 19 deletions
+24 -13
View File
@@ -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));
}
}
}
}
}
+8 -3
View File
@@ -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));
}
}
}
+9
View File
@@ -150,6 +150,11 @@
<DesignTime>True</DesignTime>
<DependentUpon>Logic.Financial.Payout.resx</DependentUpon>
</Compile>
<Compile Include="Resources\Logic.Financial.VatReport.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Logic.Financial.VatReport.resx</DependentUpon>
</Compile>
<Compile Include="Resources\Logic.Structure.Country.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
@@ -597,6 +602,10 @@
<EmbeddedResource Include="Resources\Logic.Financial.Payout.ru-RU.resx" />
<EmbeddedResource Include="Resources\Logic.Financial.Payout.sv-SE.resx" />
<EmbeddedResource Include="Resources\Logic.Financial.Payout.zh-CN.resx" />
<EmbeddedResource Include="Resources\Logic.Financial.VatReport.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Logic.Financial.VatReport.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Include="Resources\Logic.Structure.Country.af-ZA.resx" />
<EmbeddedResource Include="Resources\Logic.Structure.Country.ar-SA.resx" />
<EmbeddedResource Include="Resources\Logic.Structure.Country.da-DK.resx" />
+90
View File
@@ -0,0 +1,90 @@
//------------------------------------------------------------------------------
// <auto-generated>
// 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.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Swarmops.Logic.Resources {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// 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() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[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;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// Looks up a localized string similar to VAT report {0}.
/// </summary>
internal static string Description_FullYear {
get {
return ResourceManager.GetString("Description_FullYear", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to VAT report for {0:yyyy} {0:MMM}-{1:MMM}.
/// </summary>
internal static string Description_Months {
get {
return ResourceManager.GetString("Description_Months", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to VAT report for {0:MMMM} {0:yyyy}.
/// </summary>
internal static string Description_SingleMonth {
get {
return ResourceManager.GetString("Description_SingleMonth", resourceCulture);
}
}
}
}
@@ -0,0 +1,129 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="Description_FullYear" xml:space="preserve">
<value>VAT report {0}</value>
</data>
<data name="Description_Months" xml:space="preserve">
<value>VAT report for {0:yyyy} {0:MMM}-{1:MMM}</value>
</data>
<data name="Description_SingleMonth" xml:space="preserve">
<value>VAT report for {0:MMMM} {0:yyyy}</value>
</data>
</root>
+43 -1
View File
@@ -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 @@
</div>
</div>
</div>
<div id="divVatReport">
<p><input type="radio" id="RadioVatReport" name="TxOptions" value="VatReport" /><label for="RadioVatReport">&nbsp;<asp:Label runat="server" ID="LabelRadioVatReport" Text="Match to an open VAT report? XYZ" /></label></p>
<div id="radioOptionVatReport" class="radioOption">
<div class="entryFields">
<Swarmops5:DropDown ID="DropOpenVatReports" runat="server" />&#8203;<br/>
<input type="button" value='#VatReport#' class="buttonAccentColor" onclick="onMatchOpenVatReports(); return false;" id="buttonExecuteVatReport"/>
</div>
<div class="entryLabels">
<asp:Label runat="server" ID="LabelDescrribeVatReport" Text="Match to open VAT report XYZ" />
</div>
</div>
</div>
<div id="radioOptionPayment2" class="radioOption"></div>
<div id="radioOptionPaymentForeign" class="radioOption"></div>
<div id="divHiddenTodoFutureSprint" style="display:none">
@@ -62,7 +62,7 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers
public string DifferingAmount { get; set; }
public DropdownOptions OpenPayoutData { get; set; }
public DropdownOptions OpenOutboundInvoiceData { get; set; }
public DropdownOptions OpenVatReports { get; set; }
public DropdownOption[] OpenVatReportData { get; set; }
}
[Serializable]
@@ -112,7 +112,6 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers
if (transaction.Rows.AmountCentsTotal > 0)
{
result.OpenOutboundInvoiceData = GetOpenOutboundInvoiceData(transaction);
result.OpenVatReports = null; // TODO
}
else
{
@@ -121,6 +120,8 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers
result.OpenPayoutData = GetOpenPayoutData(transaction);
}
result.OpenVatReportData = GetOpenVatReportData(transaction);
return result;
}
@@ -256,6 +257,34 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers
return false;
}
private static DropdownOption[] GetOpenVatReportData(FinancialTransaction transaction)
{
VatReports vatReports = VatReports.ForOrganization(transaction.Organization);
List<DropdownOption> matches = new List<DropdownOption>();
Int64 txDiffCents = transaction.Rows.AmountCentsTotal; // is zero on a healthy tx
foreach (VatReport report in vatReports)
{
Int64 vatDiffCents = report.VatInboundCents - report.VatOutboundCents; // produces positive value for surplus; same as tx on match
if (vatDiffCents == txDiffCents)
{
matches.Add(new DropdownOption
{
id = report.Identity.ToString(CultureInfo.InvariantCulture),
@group = Resources.Pages.Ledgers.BalanceTransactions_ExactMatches,
text = report.Description
});
}
}
return matches.ToArray();
}
[WebMethod]
public static void BalanceTransactionManually(int transactionId, int accountId)
{
@@ -421,6 +450,16 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers
}
[WebMethod]
public static string GetTransactionDisplayIdentity(int transactionId)
{
FinancialTransaction tx = FinancialTransaction.FromIdentity(transactionId);
return tx.OrganizationSequenceId.ToString("N0");
}
// ---- Localized resources ----
@@ -210,6 +210,33 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers {
/// </remarks>
protected global::System.Web.UI.WebControls.Label LabelDescribeOutboundInvoice;
/// <summary>
/// LabelRadioVatReport control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Label LabelRadioVatReport;
/// <summary>
/// DropOpenVatReports control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::Swarmops.Frontend.Controls.Base.DropDown DropOpenVatReports;
/// <summary>
/// LabelDescrribeVatReport control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Label LabelDescrribeVatReport;
/// <summary>
/// LabelRadioExistingPayment control.
/// </summary>