Cash advance requests should now send notifications

This commit is contained in:
Rick Falkvinge
2013-09-07 08:29:18 +00:00
parent cec50f0de9
commit b351b39ffa
5 changed files with 83 additions and 6 deletions
+30 -1
View File
@@ -1,11 +1,13 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using Swarmops.Basic.Enums;
using Swarmops.Basic.Types.Communications;
using Swarmops.Database;
using Swarmops.Logic.Communications.Transmission;
using Swarmops.Logic.Financial;
using Swarmops.Logic.Structure;
using Swarmops.Logic.Swarm;
@@ -92,8 +94,35 @@ namespace Swarmops.Logic.Communications
return comm;
}
// public static OutboundComm CreateNotification (FinancialAccount budget, string notificationResource)
public static OutboundComm CreateNotificationForAttest (FinancialAccount budget, Person concernedPerson, 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.RequestReason] = purpose;
payload.Strings[NotificationString.BudgetName] = budget.Name;
OutboundComm comm = OutboundComm.Create(null, null, budget.Organization, CommResolverClass.Unknown, null,
CommTransmitterClass.CommsTransmitterMail,
new PayloadEnvelope(payload).ToXml(),
OutboundCommPriority.Low);
if (budget.OwnerPersonId == 0)
{
comm.AddRecipient(Person.FromIdentity(1)); // Add admin - not good, should be org admins // HACK // TODO
}
else
{
comm.AddRecipient(budget.Owner);
}
comm.Resolved = true;
return comm;
}
public new bool Resolved
{
@@ -1,7 +1,7 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.296
// Runtime Version:4.0.30319.1008
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
@@ -61,6 +61,26 @@ namespace Swarmops.Logic.Communications.Transmission.App_LocalResources {
}
}
/// <summary>
/// Looks up a localized string similar to [ConcernedPersonName] has requested a cash advance of [CurrencyCode] [BudgetAmountFloat] for the purpose of [RequestReason]. This money is part of your budget, [BudgetName].
///
///Please log on to Swarmops at [SystemUrl] to attest or deny..
/// </summary>
internal static string CashAdvance_Requested_Body {
get {
return ResourceManager.GetString("CashAdvance_Requested_Body", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to [OrganizationName] Cash Advance Requested.
/// </summary>
internal static string CashAdvance_Requested_Subject {
get {
return ResourceManager.GetString("CashAdvance_Requested_Subject", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to An unhandled exception was thrown in Swarmops:
///
@@ -117,6 +117,14 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="CashAdvance_Requested_Body" xml:space="preserve">
<value>[ConcernedPersonName] has requested a cash advance of [CurrencyCode] [BudgetAmountFloat] for the purpose of [RequestReason]. This money is part of your budget, [BudgetName].
Please log on to Swarmops at [SystemUrl] to attest or deny.</value>
</data>
<data name="CashAdvance_Requested_Subject" xml:space="preserve">
<value>[OrganizationName] Cash Advance Requested</value>
</data>
<data name="System_Exception_Body" xml:space="preserve">
<value>An unhandled exception was thrown in Swarmops:
@@ -51,7 +51,18 @@ namespace Swarmops.Logic.Communications.Transmission
{
// TODO: Replace all, of course
return input.Replace("[HostName]", System.Net.Dns.GetHostName());
input = input.Replace("[HostName]", System.Net.Dns.GetHostName());
// Loop through supplied strings and replace them in the resource. Not very efficient but who cares
foreach (NotificationString notificationString in Strings.Keys)
{
// TODO: Check if string ends in Float, and if so, parse and culturize it
input = input.Replace("[" + notificationString + "]", Strings[notificationString]);
}
return input;
}
#region Implementation of ICommsRenderer
@@ -77,7 +88,9 @@ namespace Swarmops.Logic.Communications.Transmission
{
Unknown = 0,
System_Startup,
System_Exception
System_Exception,
CashAdvance_Requested,
CashAdvance_Attested
}
// ReSharper restore InconsistentNaming
@@ -93,7 +106,9 @@ namespace Swarmops.Logic.Communications.Transmission
DateTimeExpiry,
BudgetName,
BudgetAmountFloat,
CurrencyCode,
EmbeddedPreformattedText,
RequestReason,
HostName,
SwarmopsVersion
}
+7 -2
View File
@@ -5,6 +5,8 @@ using System.Text;
using Swarmops.Basic.Enums;
using Swarmops.Basic.Types.Financial;
using Swarmops.Database;
using Swarmops.Logic.Communications;
using Swarmops.Logic.Communications.Transmission;
using Swarmops.Logic.Swarm;
using Swarmops.Logic.Structure;
@@ -37,12 +39,15 @@ namespace Swarmops.Logic.Financial
public static CashAdvance Create(Organization organization, Person forPerson, Person createdByPerson, Int64 amountCents, FinancialAccount budget, string description)
{
return
FromIdentityAggressive(SwarmDb.GetDatabaseForWriting().CreateCashAdvance(forPerson.Identity,
CashAdvance newAdvance = FromIdentityAggressive(SwarmDb.GetDatabaseForWriting().CreateCashAdvance(forPerson.Identity,
createdByPerson.Identity,
organization.Identity,
budget.Identity, amountCents,
description));
OutboundComm.CreateNotificationForAttest(budget, forPerson, (double) amountCents/100.0, description, NotificationResource.CashAdvance_Requested); // Slightly misplaced logic, but failsafer here
return newAdvance;
}
#endregion