From e7e28cc360cbc8a998d1b5b6ce8f2b744206138b Mon Sep 17 00:00:00 2001 From: Rick Falkvinge Date: Thu, 2 Apr 2015 13:59:26 +0200 Subject: [PATCH] Added two properties to Organization --- Common/Enums/ObjectOptionalDataType.cs | 11 +++++- Logic/Structure/Organization.cs | 51 ++++++++++++++++---------- 2 files changed, 41 insertions(+), 21 deletions(-) diff --git a/Common/Enums/ObjectOptionalDataType.cs b/Common/Enums/ObjectOptionalDataType.cs index 16855eda..390c8a1b 100644 --- a/Common/Enums/ObjectOptionalDataType.cs +++ b/Common/Enums/ObjectOptionalDataType.cs @@ -309,7 +309,16 @@ namespace Swarmops.Common.Enums /// /// The datetime UTC when the account was set under lockdown (or empty/null if it is not). /// - AccountUnderLockdownSince + AccountUnderLockdownSince, + /// + /// True if all participants can access global financial reports (balance sheet, P&L). + /// + OrgParticipantFinancialsEnabled, + + /// + /// Early Hack - the mail address used for a PayPal account (before properties like this one are rolled into up into automation classes) + /// + OrgPaypalAccountMailAddress } } \ No newline at end of file diff --git a/Logic/Structure/Organization.cs b/Logic/Structure/Organization.cs index cda59e69..82329af0 100644 --- a/Logic/Structure/Organization.cs +++ b/Logic/Structure/Organization.cs @@ -54,9 +54,9 @@ namespace Swarmops.Logic.Structure return new Organization (basic); } - public static Organization FromOpenLedgersDomain(string domain) + protected static Organization FromOptionalDataString (ObjectOptionalDataType dataType, string data) { - int[] organizationIds = SwarmDb.GetDatabaseForReading().GetObjectsByOptionalData(ObjectType.Organization, ObjectOptionalDataType.OrgOpenLedgersDomain, domain); + int[] organizationIds = SwarmDb.GetDatabaseForReading().GetObjectsByOptionalData(ObjectType.Organization, dataType, data.Trim()); if (organizationIds.Length < 1) { @@ -68,28 +68,27 @@ namespace Swarmops.Logic.Structure } else { - throw new InvalidOperationException("Invalid state: multiple organizations with same open-ledgers domain"); + throw new InvalidOperationException("Invalid state: multiple organizations with same " + dataType.ToString()); } } + public static Organization FromOpenLedgersDomain(string domain) + { + return FromOptionalDataString (ObjectOptionalDataType.OrgOpenLedgersDomain, domain); + } + public static Organization FromVanityDomain(string domain) { - int[] organizationIds = SwarmDb.GetDatabaseForReading().GetObjectsByOptionalData(ObjectType.Organization, ObjectOptionalDataType.OrgVanityDomain, domain); - - if (organizationIds.Length < 1) - { - return null; - } - else if (organizationIds.Length == 1) - { - return Organization.FromIdentity(organizationIds[0]); - } - else - { - throw new InvalidOperationException("Invalid state: multiple organizations with same vanity domain"); - } + return FromOptionalDataString (ObjectOptionalDataType.OrgVanityDomain, domain); } + + static public Organization FromPaypalAccountMailAddress(string address) + { + return FromOptionalDataString (ObjectOptionalDataType.OrgPaypalAccountMailAddress, address); + } + + #endregion private ObjectOptionalData _optionalData; @@ -298,6 +297,21 @@ namespace Swarmops.Logic.Structure get { return OptionalData.GetOptionalDataBool (ObjectOptionalDataType.OrgEconomyEnabled); } } + public bool ParticipantFinancialsEnabled + { + get { return OptionalData.GetOptionalDataBool (ObjectOptionalDataType.OrgParticipantFinancialsEnabled); } + set { OptionalData.SetOptionalDataBool (ObjectOptionalDataType.OrgParticipantFinancialsEnabled, value); } + } + + /// + /// This is a TEMPORARY property that will be deprecated once proper automation properties are in place. + /// + public string PaypalAccountMailAddress + { + get { return OptionalData.GetOptionalDataString (ObjectOptionalDataType.OrgPaypalAccountMailAddress); } + set { OptionalData.SetOptionalDataString (ObjectOptionalDataType.OrgPaypalAccountMailAddress, value); } + } + public int FirstFiscalYear { get @@ -433,9 +447,6 @@ namespace Swarmops.Logic.Structure // First, set hardwired accounts - - // TODO: Set names according to org default culture - FinancialAccounts[OrganizationFinancialAccountType.AssetsBankAccountMain] = FinancialAccount.Create (this, "[LOC]Asset_BankAccount", FinancialAccountType.Asset, null); FinancialAccounts[OrganizationFinancialAccountType.AssetsOutboundInvoices] =