diff --git a/FrontSocket/FrontendLoop.cs b/FrontSocket/FrontendLoop.cs index 0186b6c5..9829bab7 100644 --- a/FrontSocket/FrontendLoop.cs +++ b/FrontSocket/FrontendLoop.cs @@ -308,26 +308,18 @@ namespace Swarmops.Frontend.Socket public static void RecalculateOrganizationProfitLoss(Organization organization) { - Int64 annualProfitLossCents = GetOrganizationProfitLossCents(organization); + Int64 annualProfitLossCents = organization.GetProfitLossCents(); JObject json = new JObject(); json["MessageType"] = "AnnualProfitLossCents"; - json["ProfitLossCents"] = annualProfitLossCents.ToString(); + json["ProfitLossCents"] = annualProfitLossCents.ToString(CultureInfo.InvariantCulture); json["OrganizationId"] = organization.Identity; BroadcastToOrganization(organization, json); } - public static Int64 GetOrganizationProfitLossCents(Organization organization) - { - FinancialAccounts allPLAccounts = FinancialAccounts.ForOrganization(organization, - FinancialAccountType.Result); - DateTime thisYearStart = new DateTime(DateTime.UtcNow.Year, 1, 1); - DateTime thisYearEnd = new DateTime(thisYearStart.Year + 1, 1, 1); - return -allPLAccounts.GetDeltaCents(thisYearStart, thisYearEnd); // negative because of accounting of P&L accounts - } public static void BroadcastToOrganization(Organization organization, JObject message) diff --git a/FrontSocket/FrontendServices.cs b/FrontSocket/FrontendServices.cs index dab240ef..09919187 100644 --- a/FrontSocket/FrontendServices.cs +++ b/FrontSocket/FrontendServices.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -68,9 +69,8 @@ namespace Swarmops.Frontend.Socket JObject json = new JObject(); json ["MessageType"] = json["messageType"] = "AnnualProfitLossCents"; - json["ProfitLossCents"] = FrontendLoop.GetOrganizationProfitLossCents(this._authority.Organization).ToString(); + json["ProfitLossCents"] = this._authority.Organization.GetProfitLossCents().ToString(CultureInfo.InvariantCulture); json["OrganizationId"] = this._authority.Organization.Identity; - json["Instant"] = "1"; // instant update, no odometer rolling for init this.Send(json.ToString()); } diff --git a/Logic/Structure/Organization.cs b/Logic/Structure/Organization.cs index f49ef793..cb18d881 100644 --- a/Logic/Structure/Organization.cs +++ b/Logic/Structure/Organization.cs @@ -1005,6 +1005,21 @@ namespace Swarmops.Logic.Structure } + public Int64 GetProfitLossCents (int year = 0) + { + if (year == 0) + { + year = DateTime.UtcNow.Year; + } + + FinancialAccounts allPLAccounts = Swarmops.Logic.Financial.FinancialAccounts.ForOrganization(this, + FinancialAccountType.Result); + DateTime thisYearStart = new DateTime(year, 1, 1); + DateTime thisYearEnd = new DateTime(year + 1, 1, 1); + + return -allPLAccounts.GetDeltaCents(thisYearStart, thisYearEnd); // negative because of accounting of P&L accounts + } + public string VanityDomain { get { return OptionalData.GetOptionalDataString(ObjectOptionalDataType.OrgVanityDomain); } diff --git a/Site/Master-v5.master b/Site/Master-v5.master index ce92e809..6ce93946 100644 --- a/Site/Master-v5.master +++ b/Site/Master-v5.master @@ -227,7 +227,7 @@