diff --git a/Logic/Structure/Organization.cs b/Logic/Structure/Organization.cs
index a4c957b7..1bc4888e 100644
--- a/Logic/Structure/Organization.cs
+++ b/Logic/Structure/Organization.cs
@@ -849,5 +849,13 @@ namespace Swarmops.Logic.Structure
get { return "bg 451-0061 "; } // TODO: Per organization, of course
}
+ public DateTime GetEndOfFiscalYear (int year)
+ {
+ // Returns the last millisecond of the fiscal year. For now, this is limited to calendar years; the function
+ // is placed here for future flexibility.
+
+ return new DateTime(year, 12, 31, 23, 59, 59, 999);
+ }
+
}
}
\ No newline at end of file
diff --git a/Site5/App_Code/DataV5Base.cs b/Site5/App_Code/DataV5Base.cs
index 4f403547..3b1f963c 100644
--- a/Site5/App_Code/DataV5Base.cs
+++ b/Site5/App_Code/DataV5Base.cs
@@ -174,6 +174,41 @@ public class DataV5Base : System.Web.UI.Page
}
}
+
+ protected static AuthenticationData GetAuthenticationDataAndCulture()
+ {
+ // This function is called from static page methods in AJAX calls to get
+ // the current set of authentication data. Static page methods cannot access
+ // the instance data of PageV5Base.
+
+ AuthenticationData result = new AuthenticationData();
+
+ // Find various credentials
+
+ string identity = HttpContext.Current.User.Identity.Name;
+ string[] identityTokens = identity.Split(',');
+
+ string userIdentityString = identityTokens[0];
+ string organizationIdentityString = identityTokens[1];
+
+ int currentUserId = Convert.ToInt32(userIdentityString);
+ int currentOrganizationId = Convert.ToInt32(organizationIdentityString);
+
+ result.CurrentUser = Person.FromIdentity(currentUserId);
+ result.CurrentOrganization = Organization.FromIdentity(currentOrganizationId);
+
+ string userCultureString = result.CurrentUser.PreferredCulture;
+
+ if (!string.IsNullOrEmpty(userCultureString))
+ {
+ CultureInfo userCulture = new CultureInfo(userCultureString); // may throw on invalid database data
+ Thread.CurrentThread.CurrentCulture = userCulture;
+ Thread.CurrentThread.CurrentUICulture = userCulture;
+ }
+
+ return result;
+ }
+
+
}
-
diff --git a/Site5/App_GlobalResources/Global.resx b/Site5/App_GlobalResources/Global.resx
index f958233a..ad5540c5 100644
--- a/Site5/App_GlobalResources/Global.resx
+++ b/Site5/App_GlobalResources/Global.resx
@@ -312,4 +312,10 @@
Outbound Invoices
+
+ N/A
+
+
+ Not Applicable
+
\ No newline at end of file
diff --git a/Site5/Pages/v5/Financial/Json-PayableCosts.aspx.cs b/Site5/Pages/v5/Financial/Json-PayableCosts.aspx.cs
index 7c286987..9e10a173 100644
--- a/Site5/Pages/v5/Financial/Json-PayableCosts.aspx.cs
+++ b/Site5/Pages/v5/Financial/Json-PayableCosts.aspx.cs
@@ -40,7 +40,7 @@ namespace Swarmops.Frontend.Pages.Financial
StringBuilder result = new StringBuilder(16384);
string hasDoxString =
- "
";
+ "
";
result.Append("{\"rows\":[");
diff --git a/Site5/Pages/v5/Ledgers/Json-BalanceSheetData.aspx.cs b/Site5/Pages/v5/Ledgers/Json-BalanceSheetData.aspx.cs
index 40b592e0..5a688d4d 100644
--- a/Site5/Pages/v5/Ledgers/Json-BalanceSheetData.aspx.cs
+++ b/Site5/Pages/v5/Ledgers/Json-BalanceSheetData.aspx.cs
@@ -12,38 +12,13 @@ using Swarmops.Logic.Swarm;
using Swarmops.Logic.Security;
using Swarmops.Logic.Structure;
-public partial class Pages_v5_Ledgers_Json_BalanceSheetData : System.Web.UI.Page
+public partial class Pages_v5_Ledgers_Json_BalanceSheetData : DataV5Base
{
protected void Page_Load(object sender, EventArgs e)
{
- // Current authentication
+ // Get auth data
- string identity = HttpContext.Current.User.Identity.Name;
- string[] identityTokens = identity.Split(',');
-
- string userIdentityString = identityTokens[0];
- string organizationIdentityString = identityTokens[1];
-
- int currentUserId = Convert.ToInt32(userIdentityString);
- int currentOrganizationId = Convert.ToInt32(organizationIdentityString);
-
- Person currentUser = Person.FromIdentity(currentUserId);
- Authority authority = currentUser.GetAuthority();
- Organization currentOrganization = Organization.FromIdentity(currentOrganizationId);
-
- // Get culture
-
- string cultureString = "en-US";
- HttpCookie cookie = Request.Cookies["PreferredCulture"];
-
- if (cookie != null)
- {
- cultureString = cookie.Value;
- }
-
- _renderCulture = new CultureInfo(cultureString);
- Thread.CurrentThread.CurrentCulture = _renderCulture;
- Thread.CurrentThread.CurrentUICulture = _renderCulture;
+ _authenticationData = GetAuthenticationDataAndCulture();
// Get current year
@@ -56,7 +31,7 @@ public partial class Pages_v5_Ledgers_Json_BalanceSheetData : System.Web.UI.Page
_year = Int32.Parse(yearParameter); // will throw if non-numeric - don't matter for app
}
- YearlyReport report = YearlyReport.Create(currentOrganization, _year, FinancialAccountType.Balance);
+ YearlyReport report = YearlyReport.Create(_authenticationData.CurrentOrganization, _year, FinancialAccountType.Balance);
LocalizeRoot(report.ReportLines);
Response.ContentType = "application/json";
@@ -66,6 +41,7 @@ public partial class Pages_v5_Ledgers_Json_BalanceSheetData : System.Web.UI.Page
Response.End();
}
+ private AuthenticationData _authenticationData;
private void LocalizeRoot(List lines)
diff --git a/Site5/Pages/v5/Ledgers/Json-OutstandingAccounts.aspx b/Site5/Pages/v5/Ledgers/Json-OutstandingAccounts.aspx
new file mode 100644
index 00000000..9bf92e2d
--- /dev/null
+++ b/Site5/Pages/v5/Ledgers/Json-OutstandingAccounts.aspx
@@ -0,0 +1 @@
+<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Json-OutstandingAccounts.aspx.cs" Inherits="Swarmops.Frontend.Pages.v5.Ledgers.Json_OutstandingAccounts" %>
diff --git a/Site5/Pages/v5/Ledgers/Json-OutstandingAccounts.aspx.cs b/Site5/Pages/v5/Ledgers/Json-OutstandingAccounts.aspx.cs
new file mode 100644
index 00000000..50754618
--- /dev/null
+++ b/Site5/Pages/v5/Ledgers/Json-OutstandingAccounts.aspx.cs
@@ -0,0 +1,145 @@
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.Linq;
+using System.Text;
+using System.Web;
+using System.Web.UI;
+using System.Web.UI.WebControls;
+using Swarmops.Logic.Financial;
+using Swarmops.Logic.Security;
+
+namespace Swarmops.Frontend.Pages.v5.Ledgers
+{
+ public partial class Json_OutstandingAccounts : DataV5Base
+ {
+ protected void Page_Load(object sender, EventArgs e)
+ {
+ this.PageAccessRequired = new Access(AccessAspect.Financials, AccessType.Read);
+ _authenticationData = GetAuthenticationDataAndCulture();
+
+ OutstandingAccountType accountType = OutstandingAccountType.Expenses;
+ DateTime targetDateTime = DateTime.Today.AddDays(1);
+ bool renderPresentTime = true;
+ FinancialAccount balanceAccount = null;
+ Int64 balanceAmountCents;
+
+ if (Request.QueryString ["Year"] != null)
+ {
+ targetDateTime = _authenticationData.CurrentOrganization.GetEndOfFiscalYear (Int32.Parse((string) Request.QueryString["Year"], CultureInfo.InvariantCulture));
+ renderPresentTime = false;
+ }
+
+ // Assume claims
+ balanceAccount = _authenticationData.CurrentOrganization.FinancialAccounts.DebtsExpenseClaims;
+
+ ExpenseClaims claims = null;
+ if (renderPresentTime)
+ {
+ claims = ExpenseClaims.ForOrganization(_authenticationData.CurrentOrganization);
+ balanceAmountCents = balanceAccount.GetDeltaCents(DateTime.MinValue, DateTime.MaxValue); // get ALL transactions
+ }
+ else
+ {
+ // TODO
+ claims = new ExpenseClaims();
+ balanceAmountCents = balanceAccount.GetDeltaCents(DateTime.MinValue, targetDateTime);
+ }
+
+
+ OutstandingAccounts outstandingAccounts = new OutstandingAccounts();
+ foreach (ExpenseClaim claim in claims)
+ {
+ outstandingAccounts.Add((OutstandingAccount) claim);
+ }
+
+
+ Response.ContentType = "application/json";
+ Response.Output.WriteLine (FormatJson(outstandingAccounts, balanceAmountCents));
+ Response.End();
+ }
+
+ private string FormatJson (OutstandingAccounts outstandingAccounts, Int64 balanceExpectedCents)
+ {
+ StringBuilder result = new StringBuilder(16384);
+
+ result.Append("{\"rows\":[");
+
+ Int64 centsTotal = 0;
+
+ foreach (OutstandingAccount account in outstandingAccounts)
+ {
+ result.Append("{");
+ result.AppendFormat(
+ "\"id\":\"{0}\"," +
+ "\"created\":\"{1}\"," +
+ "\"expected\":\"{2}\"," +
+ "\"recipient\":\"{3}\"," +
+ "\"description\":\"{4}\"," +
+ "\"amount\":\"{5:N2}\"",
+ account.Identity,
+ account.CreatedDateTime.ToShortDateString(),
+ (account.ExpectedClosed.Year <= 1950 ? Resources.Global.Global_NA : account.ExpectedClosed.ToShortDateString()),
+ account.Recipient,
+ account.Description,
+ account.AmountCents / 100.0);
+ result.Append("},");
+ centsTotal += account.AmountCents;
+ }
+
+ if (outstandingAccounts.Count > 0)
+ {
+ result.Remove(result.Length - 1, 1); // remove last comma
+ }
+
+ result.AppendFormat("],\"footer\":[\"id\":\"{0}\",\"amount\":\"{2:N2}\"]",
+ "Total", balanceExpectedCents, centsTotal/100.0);
+
+ result.Append("}"); // on separate line to suppress warning
+
+ return result.ToString();
+ }
+
+ private AuthenticationData _authenticationData;
+
+ private enum OutstandingAccountType
+ {
+ Unknown = 0,
+ Expenses,
+ InboundInvoices,
+ OutboundInvoices,
+ CashAdvances
+ }
+
+
+ protected class OutstandingAccount
+ {
+ public Int64 AmountCents { get; set; }
+ public string Description { get; set; }
+ public int Identity { get; set; }
+ public string Recipient { get; set; }
+ public DateTime CreatedDateTime { get; set; }
+ public DateTime ExpectedClosed { get; set; }
+
+ public static explicit operator OutstandingAccount(ExpenseClaim claim)
+ {
+ OutstandingAccount result = new OutstandingAccount
+ {
+ AmountCents = claim.AmountCents,
+ Description = claim.Description,
+ Identity = claim.Identity,
+ Recipient = claim.ClaimerCanonical,
+ CreatedDateTime = claim.CreatedDateTime,
+ ExpectedClosed = DateTime.MinValue
+ };
+
+ return result;
+ }
+ }
+
+ protected class OutstandingAccounts: List
+ {
+ // empty class declaration - just want the name
+ }
+ }
+}
\ No newline at end of file
diff --git a/Site5/Pages/v5/Ledgers/ViewOutstandingAccounts.aspx b/Site5/Pages/v5/Ledgers/ViewOutstandingAccounts.aspx
index 65c3ec03..7bb2cbd7 100644
--- a/Site5/Pages/v5/Ledgers/ViewOutstandingAccounts.aspx
+++ b/Site5/Pages/v5/Ledgers/ViewOutstandingAccounts.aspx
@@ -1,6 +1,12 @@
<%@ Page Title="" Language="C#" MasterPageFile="~/Master-v5.master" AutoEventWireup="true" CodeFile="ViewOutstandingAccounts.aspx.cs" Inherits="Swarmops.Frontend.Pages.v5.Ledgers.ViewOutstandingAccounts" %>
+
+

@@ -10,13 +16,13 @@
idField="itemId">
- |
- |
- |
- |
- |
+ |
+ |
+ |
+ |
+ |
|
- |
+ |