Enabled VAT in expense claims

This commit is contained in:
Falkvinge
2017-05-04 19:37:51 +02:00
parent 5fd29bc668
commit dd97e7ac51
14 changed files with 156 additions and 43 deletions
+4 -2
View File
@@ -14,7 +14,7 @@ namespace Swarmops.Basic.Types.Financial
public BasicExpenseClaim (int expenseClaimId, int claimingPersonId, DateTime createdDateTime,
bool open, bool attested, bool documented, bool claimed, int organizationId,
int geographyId, int budgetId, DateTime expenseDate,
string description, double preApprovedAmount, Int64 amountCents, bool repaid, bool keepSeparate)
string description, double preApprovedAmount, Int64 amountCents, Int64 vatCents, bool repaid, bool keepSeparate)
{
this.ExpenseClaimId = expenseClaimId;
this.ClaimingPersonId = claimingPersonId;
@@ -30,6 +30,7 @@ namespace Swarmops.Basic.Types.Financial
this.Description = description;
this.PreApprovedAmount = preApprovedAmount;
this.AmountCents = amountCents;
this.VatCents = vatCents;
this.Repaid = repaid;
this.KeepSeparate = keepSeparate;
}
@@ -42,7 +43,7 @@ namespace Swarmops.Basic.Types.Financial
original.Open, original.Attested, original.Validated, original.Claimed,
original.OrganizationId, original.GeographyId, original.BudgetId,
original.ExpenseDate, original.Description,
original.PreApprovedAmount, original.AmountCents, original.Repaid, original.KeepSeparate)
original.PreApprovedAmount, original.AmountCents, original.VatCents, original.Repaid, original.KeepSeparate)
{
}
@@ -51,6 +52,7 @@ namespace Swarmops.Basic.Types.Financial
public DateTime ExpenseDate { get; protected set; }
public string Description { get; protected set; }
public Int64 AmountCents { get; protected set; }
public Int64 VatCents { get; protected set; }
public double PreApprovedAmount { get; private set; }
public int ClaimingPersonId { get; private set; }
public int BudgetId { get; protected set; }
+1 -1
View File
@@ -14,7 +14,7 @@ namespace Swarmops.Database
/// </summary>
public static int DbVersionExpected
{
get { return 35; }
get { return 36; }
}
+37 -30
View File
@@ -10,6 +10,13 @@ namespace Swarmops.Database
{
public partial class SwarmDb
{
private string expenseClaimFieldSequence =
" ExpenseClaimId,ClaimingPersonId,CreatedDateTime,Open,Attested," +
" Validated,Claimed,OrganizationId,GeographyId,BudgetId," +
" ExpenseDate,Description,PreApprovedAmount,AmountCents,Repaid,KeepSeparate, " +
" VatCents " +
" FROM ExpenseClaims";
public BasicExpenseClaim GetExpenseClaim (int expenseClaimId)
{
using (DbConnection connection = GetMySqlDbConnection())
@@ -17,10 +24,7 @@ namespace Swarmops.Database
connection.Open();
DbCommand command = GetDbCommand (
"SELECT ExpenseClaimId,ClaimingPersonId,CreatedDateTime,Open,Attested," +
"Validated,Claimed,OrganizationId,GeographyId,BudgetId," +
"ExpenseDate,Description,PreApprovedAmount,AmountCents,Repaid,KeepSeparate " +
"FROM ExpenseClaims WHERE ExpenseClaimId=" + expenseClaimId,
"SELECT " + this.expenseClaimFieldSequence + " WHERE ExpenseClaimId=" + expenseClaimId,
connection);
using (DbDataReader reader = command.ExecuteReader())
@@ -44,10 +48,7 @@ namespace Swarmops.Database
connection.Open();
DbCommand command =
GetDbCommand ("SELECT ExpenseClaimId,ClaimingPersonId,CreatedDateTime,Open,Attested," +
"Validated,Claimed,OrganizationId,GeographyId,BudgetId," +
"ExpenseDate,Description,PreApprovedAmount,AmountCents,Repaid,KeepSeparate " +
"FROM ExpenseClaims " + ConstructWhereClause ("ExpenseClaims", conditions),
GetDbCommand ("SELECT " + this.expenseClaimFieldSequence + ConstructWhereClause ("ExpenseClaims", conditions),
connection);
using (DbDataReader reader = command.ExecuteReader())
@@ -71,10 +72,7 @@ namespace Swarmops.Database
connection.Open();
DbCommand command =
GetDbCommand ("SELECT ExpenseClaimId,ClaimingPersonId,CreatedDateTime,Open,Attested," +
"Validated,Claimed,OrganizationId,GeographyId,BudgetId," +
"ExpenseDate,Description,PreApprovedAmount,AmountCents,Repaid,KeepSeparate " +
"FROM ExpenseClaims WHERE ClaimingPersonId=" + claimingPersonId,
GetDbCommand ("SELECT " + this.expenseClaimFieldSequence + " WHERE ClaimingPersonId=" + claimingPersonId,
connection);
using (DbDataReader reader = command.ExecuteReader())
@@ -98,10 +96,7 @@ namespace Swarmops.Database
connection.Open();
DbCommand command =
GetDbCommand ("SELECT ExpenseClaimId,ClaimingPersonId,CreatedDateTime,Open,Attested," +
"Validated,Claimed,OrganizationId,GeographyId,BudgetId," +
"ExpenseDate,Description,PreApprovedAmount,AmountCents,Repaid,KeepSeparate " +
"FROM ExpenseClaims WHERE ClaimingPersonId=" + claimingPersonId +
GetDbCommand ("SELECT " + this.expenseClaimFieldSequence + " WHERE ClaimingPersonId=" + claimingPersonId +
" AND OrganizationId=" + organizationId,
connection);
@@ -126,10 +121,7 @@ namespace Swarmops.Database
connection.Open();
DbCommand command =
GetDbCommand ("SELECT ExpenseClaimId,ClaimingPersonId,CreatedDateTime,Open,Attested," +
"Validated,Claimed,OrganizationId,GeographyId,BudgetId," +
"ExpenseDate,Description,PreApprovedAmount,AmountCents,Repaid,KeepSeparate " +
"FROM ExpenseClaims WHERE BudgetId=" + budgetId + " AND BudgetYear=" + budgetYear,
GetDbCommand ("SELECT " + this.expenseClaimFieldSequence + " WHERE BudgetId=" + budgetId + " AND BudgetYear=" + budgetYear,
connection);
using (DbDataReader reader = command.ExecuteReader())
@@ -153,10 +145,7 @@ namespace Swarmops.Database
connection.Open();
DbCommand command =
GetDbCommand ("SELECT ExpenseClaimId,ClaimingPersonId,CreatedDateTime,Open,Attested," +
"Validated,Claimed,OrganizationId,GeographyId,BudgetId," +
"ExpenseDate,Description,PreApprovedAmount,AmountCents,Repaid,KeepSeparate " +
"FROM ExpenseClaims WHERE OrganizationId=" + organizationId,
GetDbCommand ("SELECT " + this.expenseClaimFieldSequence + " WHERE OrganizationId=" + organizationId,
connection);
using (DbDataReader reader = command.ExecuteReader())
@@ -190,11 +179,12 @@ namespace Swarmops.Database
Int64 amountCents = reader.GetInt64 (13);
bool repaid = reader.GetBoolean (14);
bool keepSeparate = reader.GetBoolean (15);
Int64 vatCents = reader.GetInt64(16);
return new BasicExpenseClaim (expenseClaimId, claimingPersonId, createdDateTime,
open, attested, documented, claimed, organizationId, geographyId,
budgetId, expenseDate, description, preApprovedAmount,
amountCents, repaid, keepSeparate);
amountCents, vatCents, repaid, keepSeparate);
}
@@ -241,19 +231,36 @@ namespace Swarmops.Database
}
}
public int SetExpenseClaimDescription (int expenseClaimId, string description)
public int SetExpenseClaimDescription(int expenseClaimId, string description)
{
using (DbConnection connection = GetMySqlDbConnection())
{
connection.Open();
DbCommand command = GetDbCommand ("SetExpenseClaimDescription", connection);
DbCommand command = GetDbCommand("SetExpenseClaimDescription", connection);
command.CommandType = CommandType.StoredProcedure;
AddParameterWithName (command, "expenseClaimId", expenseClaimId);
AddParameterWithName (command, "description", description);
AddParameterWithName(command, "expenseClaimId", expenseClaimId);
AddParameterWithName(command, "description", description);
return Convert.ToInt32 (command.ExecuteScalar());
return Convert.ToInt32(command.ExecuteScalar());
}
}
public void SetExpenseClaimVatCents(int expenseClaimId, Int64 vatCents)
{
using (DbConnection connection = GetMySqlDbConnection())
{
connection.Open();
DbCommand command = GetDbCommand("SetExpenseClaimVatCents", connection);
command.CommandType = CommandType.StoredProcedure;
AddParameterWithName(command, "expenseClaimId", expenseClaimId);
AddParameterWithName(command, "vatCents", vatCents);
command.ExecuteNonQuery();
}
}
+1
View File
@@ -33,3 +33,4 @@
0033 - Added transaction row identity return, necessary for 0032 [RF]
0034 - Fix for SetFinancialTransactionRowNativeCurrency
0035 - Added OrganizationSequenceId on FinancialTransactions, VatCents setter on invoices [RF]
0036 - Added support for VatCents on ExpenseClaims [RF]
+16
View File
@@ -0,0 +1,16 @@
DROP PROCEDURE IF EXISTS `SetExpenseClaimVatCents`
#
CREATE PROCEDURE `SetExpenseClaimVatCents`(
IN expenseClaimId INTEGER,
IN vatCents BIGINT
)
BEGIN
UPDATE ExpenseClaims SET ExpenseClaims.VatCents=vatCents
WHERE ExpenseClaims.ExpenseClaimId=expenseClaimId;
END
+36 -6
View File
@@ -42,12 +42,18 @@ namespace Swarmops.Logic.Financial
}
public static ExpenseClaim Create (Person claimer, Organization organization, FinancialAccount budget,
DateTime expenseDate, string description, Int64 amountCents)
DateTime expenseDate, string description, Int64 amountCents, Int64 vatCents)
{
ExpenseClaim newClaim =
FromIdentityAggressive (SwarmDb.GetDatabaseForWriting()
.CreateExpenseClaim (claimer.Identity, organization.Identity,
budget.Identity, expenseDate, description, amountCents));
if (vatCents > 0)
{
newClaim.VatCents = vatCents;
}
// Create the financial transaction with rows
string transactionDescription = "Expense #" + newClaim.Identity + ": " + description; // TODO: Localize
@@ -62,7 +68,15 @@ namespace Swarmops.Logic.Financial
transactionDescription);
transaction.AddRow (organization.FinancialAccounts.DebtsExpenseClaims, -amountCents, claimer);
transaction.AddRow (budget, amountCents, claimer);
if (vatCents > 0)
{
transaction.AddRow(budget, amountCents - vatCents, claimer);
transaction.AddRow(organization.FinancialAccounts.AssetsVatInboundUnreported, vatCents, claimer);
}
else
{
transaction.AddRow(budget, amountCents, claimer);
}
// Make the transaction dependent on the expense claim
@@ -70,13 +84,13 @@ namespace Swarmops.Logic.Financial
// Create notifications
OutboundComm.CreateNotificationAttestationNeeded (budget, claimer, string.Empty, amountCents/100.0,
OutboundComm.CreateNotificationAttestationNeeded (budget, claimer, string.Empty, newClaim.BudgetAmountCents/100.0,
description, NotificationResource.ExpenseClaim_Created); // Slightly misplaced logic, but failsafer here
OutboundComm.CreateNotificationFinancialValidationNeeded (organization, amountCents/100.0,
OutboundComm.CreateNotificationFinancialValidationNeeded (organization, newClaim.AmountCents/100.0,
NotificationResource.Receipts_Filed);
SwarmopsLogEntry.Create (claimer,
new ExpenseClaimFiledLogEntry (claimer /*filing person*/, claimer /*beneficiary*/, amountCents/100.0,
budget, description), newClaim);
new ExpenseClaimFiledLogEntry (claimer /*filing person*/, claimer /*beneficiary*/, newClaim.BudgetAmountCents/100.0,
vatCents / 100.0, budget, description), newClaim);
// Clear a cache
FinancialAccount.ClearAttestationAdjustmentsCache(organization);
@@ -97,6 +111,22 @@ namespace Swarmops.Logic.Financial
}
public new Int64 VatCents
{
get { return base.VatCents; }
set
{
base.VatCents = value;
SwarmDb.GetDatabaseForWriting().SetExpenseClaimVatCents(this.Identity, value);
}
}
public Int64 BudgetAmountCents
{
get { return this.AmountCents - this.VatCents; }
}
public string ClaimerCanonical
{
get
+9
View File
@@ -1034,5 +1034,14 @@ namespace Swarmops.Logic.Structure
get { return OptionalData.GetOptionalDataString (ObjectOptionalDataType.OrgTaxPaymentOcr); }
set { OptionalData.SetOptionalDataString (ObjectOptionalDataType.OrgTaxPaymentOcr, value); }
}
public bool VatEnabled
{
get
{
return (this.FinancialAccounts.AssetsVatInbound != null &&
this.FinancialAccounts.AssetsVatInbound.Active);
}
}
}
}
@@ -12,10 +12,11 @@ namespace Swarmops.Logic.Support.LogEntries
// empty ctor needed for serialize
}
public ExpenseClaimFiledLogEntry (Person filingPerson, Person beneficiaryPerson, double amount,
public ExpenseClaimFiledLogEntry (Person filingPerson, Person beneficiaryPerson, double amount, double vat,
FinancialAccount budget, string reason)
{
Amount = amount;
Vat = vat;
Currency = budget.Organization.Currency.Code;
DateTime = DateTime.UtcNow;
Description = reason;
@@ -11,6 +11,7 @@ namespace Swarmops.Logic.Support.LogEntries
public int BeneficiaryPersonId { get; set; }
public int OrganizationId { get; set; }
public double Amount { get; set; }
public double Vat { get; set; }
public string Currency { get; set; }
public string Description { get; set; }
public int OwnerPersonId { get; set; }
+9
View File
@@ -933,6 +933,15 @@ namespace Resources.Pages {
}
}
/// <summary>
/// Looks up a localized string similar to VAT of the total ({0}).
/// </summary>
internal static string FileExpenseClaim_Vat {
get {
return ResourceManager.GetString("FileExpenseClaim_Vat", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Account (OCR).
/// </summary>
@@ -614,4 +614,7 @@
<data name="CreateInboundInvoice_AmountVat" xml:space="preserve">
<value>VAT part of total ({0})</value>
</data>
<data name="FileExpenseClaim_Vat" xml:space="preserve">
<value>VAT of the total ({0})</value>
</data>
</root>
+14 -2
View File
@@ -1,7 +1,7 @@
<%@ Page Title="" Language="C#" MasterPageFile="~/Master-v5.master" AutoEventWireup="true" Inherits="Swarmops.Frontend.Pages.v5.Financial.FileExpenseClaim" Codebehind="FileExpenseClaim.aspx.cs" %>
<%@ Register src="~/Controls/v5/Base/FileUpload.ascx" tagname="FileUpload" tagprefix="Swarmops5" %>
<%@ Register TagPrefix="Swarmops5" TagName="ComboBudgets" Src="~/Controls/v5/Financial/ComboBudgets.ascx" %>
<%@ Register TagPrefix="Swarmops5" TagName="CurrencyAmount" Src="~/Controls/v5/Financial/CurrencyTextBox.ascx" %>
<%@ Register TagPrefix="Swarmops5" TagName="Currency" Src="~/Controls/v5/Financial/CurrencyTextBox.ascx" %>
<asp:Content ID="Content4" ContentPlaceHolderID="PlaceHolderHead" Runat="Server">
@@ -9,6 +9,10 @@
$(document).ready(function () {
if (vatEnable) {
$('.enableVatField').show();
}
<asp:Repeater ID="RepeaterTagDropScript" runat="server"><ItemTemplate>
$('#DropTags<%# Eval("TagSetId") %>').combotree({
animate: true,
@@ -100,7 +104,13 @@
return true;
}
var vatEnable = <%= this.CurrentOrganization.VatEnabled? "true" : "false" %>;
</script>
<style type="text/css">
.enableVatField { display: none; }
</style>
</asp:Content>
@@ -108,7 +118,8 @@
<h2><asp:Label runat="server" ID="BoxTitle" /></h2>
<asp:HiddenField ID="HiddenTagSetIdentifiers" runat="server"/>
<div class="entryFields">
<Swarmops5:CurrencyAmount runat="server" ID="CurrencyAmount" />
<Swarmops5:Currency runat="server" ID="CurrencyAmount" />
<span class="enableVatField"><Swarmops5:Currency runat="server" ID="CurrencyVat" /></span>
<div class="stacked-input-control"><asp:TextBox runat="server" ID="TextPurpose" /></div>
<Swarmops5:ComboBudgets ID="ComboBudgets" runat="server" />
<asp:Repeater ID="RepeaterTagDrop" runat="server"><ItemTemplate><span id="SpanDropTags<%# Eval("TagSetId") %>"><select class="easyui-combotree" url="/Automation/Json-TransactionTagsTree.aspx?TagSetId=<%# Eval("TagSetId") %>" name="DropTags<%# Eval("TagSetId") %>" id="DropTags<%# Eval("TagSetId") %>" animate="true" style="width:300px"></select></span>&nbsp;<br/></ItemTemplate></asp:Repeater>
@@ -129,6 +140,7 @@
</div>
<div class="entryLabels">
<asp:Label runat="server" ID="LabelAmount" /><br/>
<span class="enableVatField"><asp:Label runat="server" ID="LabelVat"/><br/></span>
<asp:Label runat="server" ID="LabelPurpose" /><br/>
<asp:Label runat="server" ID="LabelBudget" /><br/>
<asp:Repeater ID="RepeaterTagLabels" runat="server"><ItemTemplate><%# Eval("TagSetLocalizedName") %><br/></ItemTemplate></asp:Repeater>
@@ -109,6 +109,7 @@ namespace Swarmops.Frontend.Pages.v5.Financial
this.TextClearing.Text = CurrentUser.BankClearing;
this.TextAccount.Text = CurrentUser.BankAccount;
this.CurrencyAmount.Cents = 0;
this.CurrencyVat.Cents = 0;
this.CurrencyAmount.Focus();
Localize();
@@ -128,6 +129,8 @@ namespace Swarmops.Frontend.Pages.v5.Financial
this.LabelBankAccount.Text = Resources.Pages.Financial.FileExpenseClaim_BankAccount;
this.LabelHeaderImageFiles.Text = Resources.Pages.Financial.FileExpenseClaim_HeaderReceiptImages;
this.LabelImageFiles.Text = Resources.Pages.Financial.FileExpenseClaim_UploadRecieptImages;
this.LabelVat.Text = string.Format(Resources.Pages.Financial.FileExpenseClaim_Vat,
CurrentOrganization.Currency.DisplayCode);
this.ButtonRequest.Text = Resources.Pages.Financial.FileExpenseClaim_ButtonRequest;
}
@@ -139,6 +142,7 @@ namespace Swarmops.Frontend.Pages.v5.Financial
// People who choose to disable JavaScript and then submit bad input almost deserve to be hurt.
Int64 amountCents = this.CurrencyAmount.Cents;
Int64 vatCents = this.CurrencyVat.Cents;
string description = this.TextPurpose.Text;
@@ -167,7 +171,7 @@ namespace Swarmops.Frontend.Pages.v5.Financial
}
ExpenseClaim claim = ExpenseClaim.Create (CurrentUser, CurrentOrganization, budget, DateTime.UtcNow,
description, amountCents);
description, amountCents, vatCents);
foreach (int tagSetId in this._tagSetIds)
{
@@ -57,6 +57,15 @@ namespace Swarmops.Frontend.Pages.v5.Financial {
/// </remarks>
protected global::Swarmops.Frontend.Controls.Financial.CurrencyTextBox CurrencyAmount;
/// <summary>
/// CurrencyVat control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::Swarmops.Frontend.Controls.Financial.CurrencyTextBox CurrencyVat;
/// <summary>
/// TextPurpose control.
/// </summary>
@@ -138,6 +147,15 @@ namespace Swarmops.Frontend.Pages.v5.Financial {
/// </remarks>
protected global::System.Web.UI.WebControls.Label LabelAmount;
/// <summary>
/// LabelVat 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 LabelVat;
/// <summary>
/// LabelPurpose control.
/// </summary>