Lots of finishing work on financial basics

This commit is contained in:
Rick Falkvinge
2014-04-25 11:10:13 +00:00
parent 08e23dcb22
commit 0d7212bcab
12 changed files with 197 additions and 16 deletions
+7 -3
View File
@@ -7,7 +7,8 @@ namespace Swarmops.Basic.Enums
Person,
FinancialAccount,
Organization,
OutboundInvoice
OutboundInvoice,
InboundInvoice
}
public enum ObjectOptionalDataType
@@ -204,8 +205,11 @@ namespace Swarmops.Basic.Enums
/// <summary>
/// Temporary mechanism for the Swarmops Red release: a coarse access list (read-only access)
/// </summary>
OrgTemporaryAccessListRead
OrgTemporaryAccessListRead,
/// <summary>
/// Free-text description of an inbound invoice (what's it for?)
/// </summary>
InboundInvoiceDescription
}
}
@@ -1,7 +1,7 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.1008
// Runtime Version:4.0.30319.1022
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
@@ -111,7 +111,7 @@ namespace Swarmops.Logic.App_GlobalResources {
}
/// <summary>
/// Looks up a localized string similar to [OrganizationName] Cash Advance Requested: [CurrencyCode] [BudgetAmountFloat] - Attestation Needed.
/// Looks up a localized string similar to (ACTION ITEM) [OrganizationName] Cash Advance Requested: [CurrencyCode] [BudgetAmountFloat] - Attestation Needed.
/// </summary>
internal static string CashAdvance_Requested_Subject {
get {
@@ -149,7 +149,7 @@ namespace Swarmops.Logic.App_GlobalResources {
}
/// <summary>
/// Looks up a localized string similar to [OrganizationName] Expense Claim Created: [CurrencyCode] [BudgetAmountFloat] - Attestation Needed.
/// Looks up a localized string similar to (ACTION ITEM) [OrganizationName] Expense Claim Created: [CurrencyCode] [BudgetAmountFloat] - Attestation Needed.
/// </summary>
internal static string ExpenseClaim_Created_Subject {
get {
@@ -235,6 +235,46 @@ namespace Swarmops.Logic.App_GlobalResources {
}
}
/// <summary>
/// Looks up a localized string similar to An invoice from [Supplier], concerning [Description], has been filed against your budget of [BudgetName] for the amount of [CurrencyCode] [BudgetAmountFloat]. You must attest this invoice before it proceeds to payout.
///
///Please log on to Swarmops at [SystemUrl] to attest or deny..
/// </summary>
internal static string InboundInvoice_Created_Body {
get {
return ResourceManager.GetString("InboundInvoice_Created_Body", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to (ACTION ITEM) [OrganizationName] Invoice Filed: [CurrencyCode] [BudgetAmountFloat] - Attestation Needed.
/// </summary>
internal static string InboundInvoice_Created_Subject {
get {
return ResourceManager.GetString("InboundInvoice_Created_Subject", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Receipts have been filed that need validation for their financial processes to continue.
///
///Please log on to Swarmops at [SystemUrl] to confirm or reject them..
/// </summary>
internal static string Receipts_Filed_Body {
get {
return ResourceManager.GetString("Receipts_Filed_Body", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to (ACTION ITEM) [OrganizationName] Receipts Filed - Validation Needed.
/// </summary>
internal static string Receipts_Filed_Subject {
get {
return ResourceManager.GetString("Receipts_Filed_Subject", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to An unhandled exception was thrown in Swarmops:
///
@@ -138,7 +138,7 @@ Please log on to Swarmops at [SystemUrl] to attest or deny.</value>
<comment>This is sent to the budget owner(s) only.</comment>
</data>
<data name="CashAdvance_Requested_Subject" xml:space="preserve">
<value>[OrganizationName] Cash Advance Requested: [CurrencyCode] [BudgetAmountFloat] - Attestation Needed</value>
<value>(ACTION ITEM) [OrganizationName] Cash Advance Requested: [CurrencyCode] [BudgetAmountFloat] - Attestation Needed</value>
</data>
<data name="ExpenseClaim_Attested_Body" xml:space="preserve">
<value>Your expense claim with [OrganizationName] for [CurrencyCode] [BudgetAmountFloat], concerning [RequestPurpose], has been attested by the budget owner. It will be paid out to you when the receipts are confirmed valid.</value>
@@ -154,7 +154,8 @@ Please log on to Swarmops at [SystemUrl] to attest or deny.</value>
<comment>This is sent to the budget owner(s)only.</comment>
</data>
<data name="ExpenseClaim_Created_Subject" xml:space="preserve">
<value>[OrganizationName] Expense Claim Created: [CurrencyCode] [BudgetAmountFloat] - Attestation Needed</value>
<value>(ACTION ITEM) [OrganizationName] Expense Claim Created: [CurrencyCode] [BudgetAmountFloat] - Attestation Needed</value>
<comment>ACTION ITEM should be translated.</comment>
</data>
<data name="ExpenseClaim_Deattested_Body" xml:space="preserve">
<value>Your expense claim with [OrganizationName] for [CurrencyCode] [BudgetAmountFloat], concerning [RequestPurpose], has been DE-attested by the budget owner. This usually indicates some sort of problem with your expense claim.
@@ -189,6 +190,22 @@ The claim will be paid out to you when the amount has also been attested by the
<data name="ExpenseClaim_Validated_Subject" xml:space="preserve">
<value>[OrganizationName] Expense Claim Receipts Validated: [CurrencyCode] [BudgetAmountFloat]</value>
</data>
<data name="InboundInvoice_Created_Body" xml:space="preserve">
<value>An invoice from [Supplier], concerning [Description], has been filed against your budget of [BudgetName] for the amount of [CurrencyCode] [BudgetAmountFloat]. You must attest this invoice before it proceeds to payout.
Please log on to Swarmops at [SystemUrl] to attest or deny.</value>
</data>
<data name="InboundInvoice_Created_Subject" xml:space="preserve">
<value>(ACTION ITEM) [OrganizationName] Invoice Filed: [CurrencyCode] [BudgetAmountFloat] - Attestation Needed</value>
</data>
<data name="Receipts_Filed_Body" xml:space="preserve">
<value>Receipts have been filed that need validation for their financial processes to continue.
Please log on to Swarmops at [SystemUrl] to confirm or reject them.</value>
</data>
<data name="Receipts_Filed_Subject" xml:space="preserve">
<value>(ACTION ITEM) [OrganizationName] Receipts Filed - Validation Needed</value>
</data>
<data name="System_Exception_Body" xml:space="preserve">
<value>An unhandled exception was thrown in Swarmops:
+29 -1
View File
@@ -95,13 +95,15 @@ namespace Swarmops.Logic.Communications
}
public static OutboundComm CreateNotificationForAttest(FinancialAccount budget, Person concernedPerson, double amountRequested, string purpose, NotificationResource notification)
public static OutboundComm CreateNotificationAttestationNeeded(FinancialAccount budget, Person concernedPerson, string supplier, double amountRequested, string purpose, NotificationResource notification)
{
NotificationPayload payload = new NotificationPayload(notification.ToString());
payload.Strings[NotificationString.CurrencyCode] = budget.Organization.Currency.Code;
payload.Strings[NotificationString.OrganizationName] = budget.Organization.Name;
payload.Strings[NotificationString.BudgetAmountFloat] = amountRequested.ToString(CultureInfo.InvariantCulture);
payload.Strings[NotificationString.RequestPurpose] = purpose;
payload.Strings[NotificationString.Description] = purpose;
payload.Strings[NotificationString.Supplier] = supplier;
payload.Strings[NotificationString.BudgetName] = budget.Name;
payload.Strings[NotificationString.ConcernedPersonName] = concernedPerson.Canonical;
@@ -126,6 +128,32 @@ namespace Swarmops.Logic.Communications
}
public static OutboundComm CreateNotificationFinancialValidationNeeded (Organization organization, double amountRequested, NotificationResource notification)
{
NotificationPayload payload = new NotificationPayload(notification.ToString());
payload.Strings[NotificationString.CurrencyCode] = organization.Currency.Code;
payload.Strings[NotificationString.OrganizationName] = organization.Name;
payload.Strings[NotificationString.BudgetAmountFloat] = amountRequested.ToString(CultureInfo.InvariantCulture);
OutboundComm comm = OutboundComm.Create(null, null, organization, CommResolverClass.Unknown, null,
CommTransmitterClass.CommsTransmitterMail,
new PayloadEnvelope(payload).ToXml(),
OutboundCommPriority.Low);
People validators = organization.ValidatingPeople;
foreach (Person validator in validators)
{
comm.AddRecipient(validator);
}
comm.Resolved = true;
return comm;
}
public static OutboundComm CreateNotificationOfFinancialValidation(FinancialAccount budget, Person concernedPerson, double amountRequested, string purpose, NotificationResource notification)
{
NotificationPayload payload = new NotificationPayload(notification.ToString());
@@ -103,7 +103,9 @@ namespace Swarmops.Logic.Communications.Transmission
ExpenseClaim_Denied,
ExpenseClaim_Adjusted,
ExpenseClaim_Rebudgeted,
Payout_Settled
Payout_Settled,
InboundInvoice_Created,
Receipts_Filed
}
// ReSharper restore InconsistentNaming
@@ -123,7 +125,9 @@ namespace Swarmops.Logic.Communications.Transmission
EmbeddedPreformattedText,
RequestPurpose,
HostName,
SwarmopsVersion
SwarmopsVersion,
Supplier,
Description
}
[Serializable]
+1 -1
View File
@@ -47,7 +47,7 @@ namespace Swarmops.Logic.Financial
budget.Identity, amountCents,
description));
OutboundComm.CreateNotificationForAttest(budget, forPerson, (double) amountCents/100.0, description, NotificationResource.CashAdvance_Requested); // Slightly misplaced logic, but failsafer here
OutboundComm.CreateNotificationAttestationNeeded(budget, forPerson, string.Empty, (double) amountCents/100.0, description, NotificationResource.CashAdvance_Requested); // Slightly misplaced logic, but failsafer here
SwarmopsLogEntry.Create(forPerson,
new CashAdvanceRequestedLogEntry(createdByPerson, forPerson, (double) amountCents/100.0, budget, description),
newAdvance);
+4 -2
View File
@@ -64,9 +64,11 @@ namespace Swarmops.Logic.Financial
transaction.Dependency = newClaim;
// Create notification
// Create notifications
OutboundComm.CreateNotificationForAttest(budget, claimer, (double)amountCents / 100.0, description, NotificationResource.ExpenseClaim_Created); // Slightly misplaced logic, but failsafer here
OutboundComm.CreateNotificationAttestationNeeded(budget, claimer, string.Empty, (double)amountCents / 100.0, description, NotificationResource.ExpenseClaim_Created); // Slightly misplaced logic, but failsafer here
OutboundComm.CreateNotificationFinancialValidationNeeded(organization, (double) amountCents/100.0,
NotificationResource.Receipts_Filed);
SwarmopsLogEntry.Create(claimer,
new ExpenseClaimFiledLogEntry(claimer /*filing person*/, claimer /*beneficiary*/, (double) amountCents/100.0, budget, description), newClaim);
+28 -1
View File
@@ -4,6 +4,9 @@ using System.Text;
using Swarmops.Basic.Enums;
using Swarmops.Basic.Types;
using Swarmops.Database;
using Swarmops.Logic.Communications;
using Swarmops.Logic.Communications.Transmission;
using Swarmops.Logic.Support.LogEntries;
using Swarmops.Logic.Swarm;
using Swarmops.Logic.Structure;
using Swarmops.Logic.Support;
@@ -13,7 +16,7 @@ namespace Swarmops.Logic.Financial
public class InboundInvoice: BasicInboundInvoice, IAttestable
{
public static InboundInvoice Create (Organization organization, DateTime dueDate, Int64 amountCents,
FinancialAccount budget, string supplier, string payToAccount, string ocr,
FinancialAccount budget, string supplier, string description, string payToAccount, string ocr,
string invoiceReference, Person creatingPerson)
{
InboundInvoice newInvoice = FromIdentity(SwarmDb.GetDatabaseForWriting().
@@ -21,6 +24,8 @@ namespace Swarmops.Logic.Financial
supplier, payToAccount, ocr,
invoiceReference, amountCents, creatingPerson.Identity));
newInvoice.Description = description; // Not in original schema; not cause for schema update
// Create a corresponding financial transaction with rows
FinancialTransaction transaction =
@@ -33,6 +38,13 @@ namespace Swarmops.Logic.Financial
// Make the transaction dependent on the inbound invoice
transaction.Dependency = newInvoice;
// Create notification (slightly misplaced logic, but this is failsafest place)
OutboundComm.CreateNotificationAttestationNeeded(budget, creatingPerson, supplier, (double)amountCents / 100.0, description, NotificationResource.InboundInvoice_Created); // Slightly misplaced logic, but failsafer here
SwarmopsLogEntry.Create(creatingPerson,
new InboundInvoiceCreatedLogEntry(creatingPerson, supplier, description, (double)amountCents / 100.0, budget), newInvoice);
return newInvoice;
}
@@ -176,6 +188,21 @@ namespace Swarmops.Logic.Financial
}
public string Description
{
get
{
return
ObjectOptionalData.ForObject(this).GetOptionalDataString(
ObjectOptionalDataType.InboundInvoiceDescription);
}
set
{
ObjectOptionalData.ForObject(this).SetOptionalDataString(ObjectOptionalDataType.InboundInvoiceDescription, value);
}
}
#region IAttestable Members
+1
View File
@@ -218,6 +218,7 @@
<Compile Include="Support\Imagery.cs" />
<Compile Include="Support\IXmlPayload.cs" />
<Compile Include="Support\LogEntries\CashAdvanceRequestedLogEntry.cs" />
<Compile Include="Support\LogEntries\InboundInvoiceCreatedLogEntry.cs" />
<Compile Include="Support\LogEntries\ExpenseClaimFiledLogEntry.cs" />
<Compile Include="Support\LogEntries\FinancialActionBase.cs" />
<Compile Include="Support\LogEntries\LogEntryBase.cs" />
+22
View File
@@ -862,5 +862,27 @@ namespace Swarmops.Logic.Structure
return new DateTime(year, 12, 31, 23, 59, 59, 999);
}
public People ValidatingPeople
{
get
{
People result = new People();
// HACK: this gets the TEMPORARY list
string peopleIdstring = Parameters.TemporaryAccessListWrite;
string[] peopleIds = peopleIdstring.Split(' ');
foreach (string peopleId in peopleIds)
{
result.Add(Person.FromIdentity(Int32.Parse(peopleId)));
}
return result;
}
}
}
}
@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Swarmops.Logic.Financial;
using Swarmops.Logic.Swarm;
namespace Swarmops.Logic.Support.LogEntries
{
[Serializable]
public class InboundInvoiceCreatedLogEntry: FinancialActionBase
{
public InboundInvoiceCreatedLogEntry()
{
// empty ctor needed for serialize
}
public InboundInvoiceCreatedLogEntry(Person creatingPerson, string supplier, string description, double amount, FinancialAccount budget)
{
this.Amount = amount;
this.Currency = budget.Organization.Currency.Code;
this.DateTime = DateTime.UtcNow;
this.Description = description;
this.OrganizationId = budget.OrganizationId;
this.FinancialAccountId = budget.Identity;
this.FinancialAccountName = budget.Name; // redundancy in case of future name changes
this.OwnerPersonId = budget.OwnerPersonId;
this.OwnerPersonName = budget.OwnerPersonId != 0 ? budget.Owner.Name : string.Empty;
this.ActingPersonId = creatingPerson.Identity; // do not save name for data retention reasons
this.BeneficiaryPersonId = 0;
this.Supplier = supplier;
}
public string Supplier { get; set; }
}
}
@@ -164,7 +164,7 @@ namespace Swarmops.Frontend.Pages.v5.Financial
}
InboundInvoice invoice = InboundInvoice.Create(CurrentOrganization, dueDate, amountCents, budget,
this.TextSupplier.Text, this.TextAccount.Text, string.Empty,
this.TextSupplier.Text, this.TextPurpose.Text, this.TextAccount.Text, string.Empty,
this.TextReference.Text, CurrentUser);
foreach (int tagSetId in _tagSetIds)