Added more Inbound VAT considerations

This commit is contained in:
Falkvinge
2017-04-29 22:52:27 +02:00
parent bc271cea14
commit 35fa251168
5 changed files with 76 additions and 18 deletions
+10 -2
View File
@@ -6,7 +6,7 @@ namespace Swarmops.Basic.Types.Financial
public class BasicInboundInvoice : IHasIdentity
{
public BasicInboundInvoice (int inboundInvoiceId, int organizationId, DateTime createdDateTime,
DateTime dueDate, Int64 amountCents, int budgetId, string supplier, string
DateTime dueDate, Int64 amountCents, Int64 vatCents, int budgetId, string supplier, string
payToAccount, string ocr, string invoiceReference, bool attested, bool open,
DateTime closedDateTime, int closedByPersonId)
{
@@ -15,6 +15,7 @@ namespace Swarmops.Basic.Types.Financial
this.CreatedDateTime = createdDateTime;
this.DueDate = dueDate;
this.AmountCents = amountCents;
this.VatCents = vatCents;
this.BudgetId = budgetId;
this.Supplier = supplier;
this.PayToAccount = payToAccount;
@@ -28,7 +29,7 @@ namespace Swarmops.Basic.Types.Financial
public BasicInboundInvoice (BasicInboundInvoice original)
: this (original.InboundInvoiceId, original.OrganizationId, original.CreatedDateTime,
original.DueDate, original.AmountCents, original.BudgetId,
original.DueDate, original.AmountCents, original.VatCents, original.BudgetId,
original.Supplier, original.PayToAccount, original.Ocr, original.InvoiceReference,
original.Attested, original.Open, original.ClosedDateTime, original.ClosedByPersonId)
{
@@ -48,7 +49,14 @@ namespace Swarmops.Basic.Types.Financial
public int ClosedByPersonId { get; protected set; }
public int OrganizationId { get; protected set; }
public string Supplier { get; protected set; }
/// <summary>
/// Total amount, INCLUDING any possible VAT
/// </summary>
public Int64 AmountCents { get; protected set; }
/// <summary>
/// The VAT part of the AmountCents, or zero if no VAT applied
/// </summary>
public Int64 VatCents { get; protected set; }
#region IHasIdentity Members
+9
View File
@@ -1326,6 +1326,15 @@ namespace Swarmops.Database
// TODO: Return BasicFinancialValidation object
public void CreateFinancialValidation(FinancialValidationType validationType,
FinancialDependencyType dependencyType, int foreignId,
DateTime validatedDateTime, int personId, Int64 amountCents)
{
CreateFinancialValidation(validationType, dependencyType,
foreignId, validatedDateTime, personId, amountCents/100.0);
}
public void CreateFinancialValidation (FinancialValidationType validationType,
FinancialDependencyType dependencyType, int foreignId,
+25 -6
View File
@@ -16,7 +16,8 @@ namespace Swarmops.Database
private const string inboundInvoiceFieldSequence =
" InboundInvoiceId,OrganizationId,CreatedDateTime,CreatedByPersonId,DueDate," +
"AmountCents,BudgetId,Attested,Open,Supplier," +
"PayToAccount,Ocr,InvoiceReference,ClosedDateTime,ClosedByPersonId " +
"PayToAccount,Ocr,InvoiceReference,ClosedDateTime,ClosedByPersonId, " +
"VatCents " +
"FROM InboundInvoices ";
private BasicInboundInvoice ReadInboundInvoiceFromDataReader (DbDataReader reader)
@@ -36,9 +37,10 @@ namespace Swarmops.Database
string invoiceReference = reader.GetString (12);
DateTime closedDateTime = reader.GetDateTime (13);
int closedByPersonId = reader.GetInt32 (14);
Int64 vatCents = reader.GetInt64(15);
return new BasicInboundInvoice (inboundInvoiceId, organizationId, createdDateTime, dueDate,
amountCents, budgetId, supplier, payToAccount, ocr, invoiceReference,
amountCents, vatCents, budgetId, supplier, payToAccount, ocr, invoiceReference,
attested, open, closedDateTime, closedByPersonId);
}
@@ -208,17 +210,34 @@ namespace Swarmops.Database
}
public void SetInboundInvoiceAmount (int inboundInvoiceId, Int64 amountCents)
public void SetInboundInvoiceAmount(int inboundInvoiceId, Int64 amountCents)
{
using (DbConnection connection = GetMySqlDbConnection())
{
connection.Open();
DbCommand command = GetDbCommand ("SetInboundInvoiceAmountPrecise", connection);
DbCommand command = GetDbCommand("SetInboundInvoiceAmountPrecise", connection);
command.CommandType = CommandType.StoredProcedure;
AddParameterWithName (command, "inboundInvoiceId", inboundInvoiceId);
AddParameterWithName (command, "amountCents", amountCents);
AddParameterWithName(command, "inboundInvoiceId", inboundInvoiceId);
AddParameterWithName(command, "amountCents", amountCents);
command.ExecuteNonQuery();
}
}
public void SetInboundInvoiceVatCents(int inboundInvoiceId, Int64 amountCents)
{
using (DbConnection connection = GetMySqlDbConnection())
{
connection.Open();
DbCommand command = GetDbCommand("SetInboundInvoiceVatCents", connection);
command.CommandType = CommandType.StoredProcedure;
AddParameterWithName(command, "inboundInvoiceId", inboundInvoiceId);
AddParameterWithName(command, "vatCents", amountCents);
command.ExecuteNonQuery();
}
+31 -9
View File
@@ -131,7 +131,7 @@ namespace Swarmops.Logic.Financial
SwarmDb.GetDatabaseForWriting().SetInboundInvoiceAttested (Identity, true);
SwarmDb.GetDatabaseForWriting().CreateFinancialValidation (FinancialValidationType.Attestation,
FinancialDependencyType.InboundInvoice, Identity,
DateTime.UtcNow, attester.Identity, (double) Amount);
DateTime.UtcNow, attester.Identity, BudgetAmountCents);
base.Attested = true;
}
@@ -140,7 +140,7 @@ namespace Swarmops.Logic.Financial
SwarmDb.GetDatabaseForWriting().SetInboundInvoiceAttested (Identity, false);
SwarmDb.GetDatabaseForWriting().CreateFinancialValidation (FinancialValidationType.Deattestation,
FinancialDependencyType.InboundInvoice, Identity,
DateTime.UtcNow, deattester.Identity, (double) Amount);
DateTime.UtcNow, deattester.Identity, BudgetAmountCents);
base.Attested = false;
}
@@ -169,7 +169,7 @@ namespace Swarmops.Logic.Financial
}
public static InboundInvoice Create (Organization organization, DateTime dueDate, Int64 amountCents,
Int64 amountVatCents, FinancialAccount budget, string supplier, string description, string payToAccount, string ocr,
Int64 vatCents, FinancialAccount budget, string supplier, string description, string payToAccount, string ocr,
string invoiceReference, Person creatingPerson)
{
InboundInvoice newInvoice = FromIdentity (SwarmDb.GetDatabaseForWriting().
@@ -179,6 +179,11 @@ namespace Swarmops.Logic.Financial
newInvoice.Description = description; // Not in original schema; not cause for schema update
if (vatCents > 0)
{
newInvoice.VatCents = vatCents;
}
// Create a corresponding financial transaction with rows
FinancialTransaction transaction =
@@ -186,11 +191,11 @@ namespace Swarmops.Logic.Financial
"Invoice #" + newInvoice.Identity + " from " + supplier);
transaction.AddRow (organization.FinancialAccounts.DebtsInboundInvoices, -amountCents, creatingPerson);
if (amountVatCents > 0)
if (vatCents > 0)
{
transaction.AddRow(organization.FinancialAccounts.AssetsVatInboundUnreported, amountVatCents,
transaction.AddRow(organization.FinancialAccounts.AssetsVatInboundUnreported, vatCents,
creatingPerson);
transaction.AddRow(budget, amountCents - amountVatCents, creatingPerson);
transaction.AddRow(budget, amountCents - vatCents, creatingPerson);
}
else
{
@@ -204,7 +209,7 @@ namespace Swarmops.Logic.Financial
// Create notification (slightly misplaced logic, but this is failsafest place)
OutboundComm.CreateNotificationAttestationNeeded (budget, creatingPerson, supplier, amountCents/100.0,
OutboundComm.CreateNotificationAttestationNeeded (budget, creatingPerson, supplier, (amountCents-vatCents)/100.0,
description, NotificationResource.InboundInvoice_Created);
// Slightly misplaced logic, but failsafer here
SwarmopsLogEntry.Create (creatingPerson,
@@ -214,11 +219,18 @@ namespace Swarmops.Logic.Financial
// Clear a cache
FinancialAccount.ClearAttestationAdjustmentsCache(organization);
return newInvoice;
}
/// <summary>
/// The amount that charges the budget (invoice total minus inbound VAT)
/// </summary>
public Int64 BudgetAmountCents
{
get { return this.AmountCents - this.VatCents; }
}
public static InboundInvoice FromBasic (BasicInboundInvoice basic)
{
return new InboundInvoice (basic);
@@ -246,6 +258,16 @@ namespace Swarmops.Logic.Financial
}
public new Int64 VatCents
{
get { return base.VatCents; }
internal set
{
base.VatCents = value;
SwarmDb.GetDatabaseForWriting().SetInboundInvoiceVatCents(this.Identity, value);
}
}
private void UpdateTransaction (Person updatingPerson)
{
Dictionary<int, Int64> nominalTransaction = new Dictionary<int, Int64>();
@@ -190,7 +190,7 @@ public partial class Pages_v5_Finance_Json_AttestableCosts : DataV5Base
invoice.Budget.OwnerPersonId == Person.NobodyId)
{
AttestableItem item = new AttestableItem ("I" + invoice.Identity.ToString (CultureInfo.InvariantCulture),
invoice.Supplier, invoice.AmountCents, invoice.Budget, invoice.InvoiceReference,
invoice.Supplier, invoice.BudgetAmountCents, invoice.Budget, invoice.InvoiceReference,
"Financial_InvoiceInbound", hasDox, invoice);
if (invoice.Attested)