diff --git a/Basic/Types/Financial/BasicExpenseClaim.cs b/Basic/Types/Financial/BasicExpenseClaim.cs index 5746f239..63388b75 100644 --- a/Basic/Types/Financial/BasicExpenseClaim.cs +++ b/Basic/Types/Financial/BasicExpenseClaim.cs @@ -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; } diff --git a/Database/Configuration.cs b/Database/Configuration.cs index 16c9a3e2..4dbea8b6 100644 --- a/Database/Configuration.cs +++ b/Database/Configuration.cs @@ -14,7 +14,7 @@ namespace Swarmops.Database /// public static int DbVersionExpected { - get { return 35; } + get { return 36; } } diff --git a/Database/Database-Expenses.cs b/Database/Database-Expenses.cs index 79e62b3e..224ce63b 100644 --- a/Database/Database-Expenses.cs +++ b/Database/Database-Expenses.cs @@ -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(); } } diff --git a/Database/Schemata/revisions.txt b/Database/Schemata/revisions.txt index 57dc656d..5584c8a8 100644 --- a/Database/Schemata/revisions.txt +++ b/Database/Schemata/revisions.txt @@ -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] \ No newline at end of file diff --git a/Database/Schemata/upgrade-0036.sql b/Database/Schemata/upgrade-0036.sql new file mode 100644 index 00000000..150c5af0 --- /dev/null +++ b/Database/Schemata/upgrade-0036.sql @@ -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 diff --git a/Logic/Financial/ExpenseClaim.cs b/Logic/Financial/ExpenseClaim.cs index 8001b3a7..36575768 100644 --- a/Logic/Financial/ExpenseClaim.cs +++ b/Logic/Financial/ExpenseClaim.cs @@ -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 diff --git a/Logic/Structure/Organization.cs b/Logic/Structure/Organization.cs index f3d5e896..f49ef793 100644 --- a/Logic/Structure/Organization.cs +++ b/Logic/Structure/Organization.cs @@ -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); + } + } } } \ No newline at end of file diff --git a/Logic/Support/LogEntries/ExpenseClaimFiledLogEntry.cs b/Logic/Support/LogEntries/ExpenseClaimFiledLogEntry.cs index 1493c0f6..7042db26 100644 --- a/Logic/Support/LogEntries/ExpenseClaimFiledLogEntry.cs +++ b/Logic/Support/LogEntries/ExpenseClaimFiledLogEntry.cs @@ -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; diff --git a/Logic/Support/LogEntries/FinancialActionBase.cs b/Logic/Support/LogEntries/FinancialActionBase.cs index c44269f7..08e89a22 100644 --- a/Logic/Support/LogEntries/FinancialActionBase.cs +++ b/Logic/Support/LogEntries/FinancialActionBase.cs @@ -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; } diff --git a/Site/App_GlobalResources/Pages.Financial.designer.cs b/Site/App_GlobalResources/Pages.Financial.designer.cs index 6ae70d26..bb545337 100644 --- a/Site/App_GlobalResources/Pages.Financial.designer.cs +++ b/Site/App_GlobalResources/Pages.Financial.designer.cs @@ -933,6 +933,15 @@ namespace Resources.Pages { } } + /// + /// Looks up a localized string similar to VAT of the total ({0}). + /// + internal static string FileExpenseClaim_Vat { + get { + return ResourceManager.GetString("FileExpenseClaim_Vat", resourceCulture); + } + } + /// /// Looks up a localized string similar to Account (OCR). /// diff --git a/Site/App_GlobalResources/Pages.Financial.resx b/Site/App_GlobalResources/Pages.Financial.resx index 87a5bbd5..4e175edd 100644 --- a/Site/App_GlobalResources/Pages.Financial.resx +++ b/Site/App_GlobalResources/Pages.Financial.resx @@ -614,4 +614,7 @@ VAT part of total ({0}) + + VAT of the total ({0}) + \ No newline at end of file diff --git a/Site/Pages/v5/Financial/FileExpenseClaim.aspx b/Site/Pages/v5/Financial/FileExpenseClaim.aspx index 613770c5..bb029535 100644 --- a/Site/Pages/v5/Financial/FileExpenseClaim.aspx +++ b/Site/Pages/v5/Financial/FileExpenseClaim.aspx @@ -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" %> @@ -9,6 +9,10 @@ $(document).ready(function () { + if (vatEnable) { + $('.enableVatField').show(); + } + $('#DropTags<%# Eval("TagSetId") %>').combotree({ animate: true, @@ -100,7 +104,13 @@ return true; } + var vatEnable = <%= this.CurrentOrganization.VatEnabled? "true" : "false" %>; + + + @@ -108,7 +118,8 @@

- + +
"> 
@@ -129,6 +140,7 @@

+


<%# Eval("TagSetLocalizedName") %>
diff --git a/Site/Pages/v5/Financial/FileExpenseClaim.aspx.cs b/Site/Pages/v5/Financial/FileExpenseClaim.aspx.cs index 49d62a1c..34ffa8e1 100644 --- a/Site/Pages/v5/Financial/FileExpenseClaim.aspx.cs +++ b/Site/Pages/v5/Financial/FileExpenseClaim.aspx.cs @@ -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) { diff --git a/Site/Pages/v5/Financial/FileExpenseClaim.aspx.designer.cs b/Site/Pages/v5/Financial/FileExpenseClaim.aspx.designer.cs index 385e875c..6dfc1187 100644 --- a/Site/Pages/v5/Financial/FileExpenseClaim.aspx.designer.cs +++ b/Site/Pages/v5/Financial/FileExpenseClaim.aspx.designer.cs @@ -57,6 +57,15 @@ namespace Swarmops.Frontend.Pages.v5.Financial { /// protected global::Swarmops.Frontend.Controls.Financial.CurrencyTextBox CurrencyAmount; + /// + /// CurrencyVat control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::Swarmops.Frontend.Controls.Financial.CurrencyTextBox CurrencyVat; + /// /// TextPurpose control. /// @@ -138,6 +147,15 @@ namespace Swarmops.Frontend.Pages.v5.Financial { /// protected global::System.Web.UI.WebControls.Label LabelAmount; + /// + /// LabelVat control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.Label LabelVat; + /// /// LabelPurpose control. ///