diff --git a/Logic/Communications/OutboundComm.cs b/Logic/Communications/OutboundComm.cs index 52267693..1e072770 100644 --- a/Logic/Communications/OutboundComm.cs +++ b/Logic/Communications/OutboundComm.cs @@ -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 { diff --git a/Logic/Communications/Transmission/App_LocalResources/NotificationPayload.Designer.cs b/Logic/Communications/Transmission/App_LocalResources/NotificationPayload.Designer.cs index 0bcdb22f..d9a12537 100644 --- a/Logic/Communications/Transmission/App_LocalResources/NotificationPayload.Designer.cs +++ b/Logic/Communications/Transmission/App_LocalResources/NotificationPayload.Designer.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // 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 { } } + /// + /// 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.. + /// + internal static string CashAdvance_Requested_Body { + get { + return ResourceManager.GetString("CashAdvance_Requested_Body", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to [OrganizationName] Cash Advance Requested. + /// + internal static string CashAdvance_Requested_Subject { + get { + return ResourceManager.GetString("CashAdvance_Requested_Subject", resourceCulture); + } + } + /// /// Looks up a localized string similar to An unhandled exception was thrown in Swarmops: /// diff --git a/Logic/Communications/Transmission/App_LocalResources/NotificationPayload.resx b/Logic/Communications/Transmission/App_LocalResources/NotificationPayload.resx index 0c429f01..55c63abb 100644 --- a/Logic/Communications/Transmission/App_LocalResources/NotificationPayload.resx +++ b/Logic/Communications/Transmission/App_LocalResources/NotificationPayload.resx @@ -117,6 +117,14 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + [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. + + + [OrganizationName] Cash Advance Requested + An unhandled exception was thrown in Swarmops: diff --git a/Logic/Communications/Transmission/NotificationPayload.cs b/Logic/Communications/Transmission/NotificationPayload.cs index a0e2bc52..03d28c3e 100644 --- a/Logic/Communications/Transmission/NotificationPayload.cs +++ b/Logic/Communications/Transmission/NotificationPayload.cs @@ -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 } diff --git a/Logic/Financial/CashAdvance.cs b/Logic/Financial/CashAdvance.cs index e2e80bcb..ceea8340 100644 --- a/Logic/Financial/CashAdvance.cs +++ b/Logic/Financial/CashAdvance.cs @@ -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