Quite a bit of work on View Outstanding Accounts.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -312,4 +312,10 @@
|
||||
<data name="Financial_OutboundInvoicesLong" xml:space="preserve">
|
||||
<value>Outbound Invoices</value>
|
||||
</data>
|
||||
<data name="Global_NA" xml:space="preserve">
|
||||
<value>N/A</value>
|
||||
</data>
|
||||
<data name="Global_NALong" xml:space="preserve">
|
||||
<value>Not Applicable</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -40,7 +40,7 @@ namespace Swarmops.Frontend.Pages.Financial
|
||||
StringBuilder result = new StringBuilder(16384);
|
||||
|
||||
string hasDoxString =
|
||||
"<img src=\\\"/Images/Icons/iconshock-glass-16px.png\\\" onmouseover=\\\"this.src='/Images/Icons/iconshock-glass-16px-hot.png';\\\" onmouseout=\\\"this.src='/Images/Icons/iconshock-glass-16px.png';\\\" onclick=\\\"alert('foo');\\\" style=\\\"cursor:pointer\\\" />";
|
||||
"<img src=\\\"/Images/PageIcons/iconshock-battery-drill-16px.png\\\" onmouseover=\\\"this.src='/Images/PageIcons/iconshock-battery-drill-16px.png';\\\" onmouseout=\\\"this.src='/Images/PageIcons/iconshock-battery-drill-16px.png';\\\" onclick=\\\"alert('Under construction');\\\" style=\\\"cursor:pointer\\\" />";
|
||||
|
||||
result.Append("{\"rows\":[");
|
||||
|
||||
|
||||
@@ -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<YearlyReportLine> lines)
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Json-OutstandingAccounts.aspx.cs" Inherits="Swarmops.Frontend.Pages.v5.Ledgers.Json_OutstandingAccounts" %>
|
||||
@@ -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<OutstandingAccount>
|
||||
{
|
||||
// empty class declaration - just want the name
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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" %>
|
||||
|
||||
<asp:Content ID="Content1" ContentPlaceHolderID="PlaceHolderHead" Runat="Server">
|
||||
|
||||
<style type="text/css">
|
||||
.datagrid-row-selected,.datagrid-row-over{
|
||||
background:transparent;
|
||||
}
|
||||
</style>
|
||||
</asp:Content>
|
||||
<asp:Content ID="Content2" ContentPlaceHolderID="PlaceHolderMain" Runat="Server">
|
||||
<h2><asp:Label runat="server" ID="ViewOutstandingAccountsHeader" Text="XYZ View Outstanding" /> <asp:DropDownList runat="server" ID="DropAccounts"/> <asp:DropDownList runat="server" ID="DropYears"/> <img alt="Loading" src="/Images/Abstract/ajaxloader-blackcircle.gif" ID="imageLoadIndicator" /></h2>
|
||||
@@ -10,13 +16,13 @@
|
||||
idField="itemId">
|
||||
<thead>
|
||||
<tr>
|
||||
<th data-options="field:'ID',width:70"><asp:Label ID="LabelGridHeaderDue" runat="server" Text="ID"/></th>
|
||||
<th data-options="field:'created',width:70,sortable:true"><asp:Label ID="LabelGridHeaderRecipient" runat="server" Text="XYZ Created" /></th>
|
||||
<th data-options="field:'due',width:70"><asp:Label ID="LabelGridHeaderBank" runat="server" Text="XYZ Due" /></th>
|
||||
<th data-options="field:'personorg',width:140,sortable:true"><asp:Label ID="LabelGridHeaderAccount" runat="server" Text="XYZ Person / Organization" /></th>
|
||||
<th data-options="field:'reference',width:180,sortable:true,order:'asc'"><asp:Label ID="LabelGridHeaderDescription" runat="server" Text="XYZ Description" /></th>
|
||||
<th data-options="field:'id',width:70"><asp:Label ID="LabelGridHeaderId" runat="server" Text="ID"/></th>
|
||||
<th data-options="field:'created',width:70,sortable:true"><asp:Label ID="LabelGridHeaderCreated" runat="server" Text="XYZ Created" /></th>
|
||||
<th data-options="field:'expected',width:70"><asp:Label ID="LabelGridHeaderBank" runat="server" Text="XYZ Due" /></th>
|
||||
<th data-options="field:'recipient',width:140,sortable:true"><asp:Label ID="LabelGridHeaderAccount" runat="server" Text="XYZ Person / Organization" /></th>
|
||||
<th data-options="field:'description',width:180,sortable:true,order:'asc'"><asp:Label ID="LabelGridHeaderDescription" runat="server" Text="XYZ Description" /></th>
|
||||
<th data-options="field:'amount',width:100,align:'right'"><asp:Label ID="LabelGridHeaderAmount" runat="server" Text="XYZ Amount" /></th>
|
||||
<th data-options="field:'action',width:43,align:'center'"><asp:Label ID="LabelGridHeaderPaid" runat="server" Text="XYZPaid" /></th>
|
||||
<th data-options="field:'action',width:43,align:'center'"><asp:Label ID="LabelGridHeaderAction" runat="server" Text="XYZAct" /></th>
|
||||
</tr>
|
||||
</thead>
|
||||
</table>
|
||||
|
||||
Reference in New Issue
Block a user