Inspect Ledgers functional

This commit is contained in:
Rick Falkvinge
2014-10-25 13:32:22 +02:00
parent d934c1266e
commit fb7f738dac
6 changed files with 356 additions and 3 deletions
+36
View File
@@ -748,4 +748,40 @@
<data name="Title_Person_Ship" xml:space="preserve">
<value>Personhood</value>
</data>
<data name="Global_AllYear" xml:space="preserve">
<value>All</value>
</data>
<data name="Global_Description" xml:space="preserve">
<value>Description</value>
<comment>As a general header of any description field</comment>
</data>
<data name="Global_Q1" xml:space="preserve">
<value>Q1</value>
<comment>First quarter of the year</comment>
</data>
<data name="Global_Q2" xml:space="preserve">
<value>Q2</value>
<comment>Second quarter of the year</comment>
</data>
<data name="Global_Q3" xml:space="preserve">
<value>Q3</value>
<comment>Third quarter of the year</comment>
</data>
<data name="Global_Q4" xml:space="preserve">
<value>Q4</value>
<comment>Fourth quarter of the year</comment>
</data>
<data name="Global_Timestamp" xml:space="preserve">
<value>Timestamp</value>
</data>
<data name="Ledgers_Balance" xml:space="preserve">
<value>Balance</value>
<comment>As in 'account balance', not as in staying upright</comment>
</data>
<data name="Ledgers_Credit" xml:space="preserve">
<value>Credit</value>
</data>
<data name="Ledgers_Debit" xml:space="preserve">
<value>Debit</value>
</data>
</root>
@@ -506,4 +506,37 @@
<data name="InspectLedgers_PageTitle" xml:space="preserve">
<value>Inspect Ledgers</value>
</data>
<data name="InspectLedgers_FlaggingNotAvailable" xml:space="preserve">
<value>Flagging a transaction for closer inspection is not yet implemented. It is scheduled for one of the early Swarmops Red sprints, some time late 2005Q1.</value>
</data>
<data name="InspectLedgers_InboundBalance" xml:space="preserve">
<value>Inbound Balance</value>
</data>
<data name="InspectLedgers_InboundBalanceZero" xml:space="preserve">
<value>No Previous Balance</value>
</data>
<data name="InspectLedgers_Info" xml:space="preserve">
<value>This is the raw underlying Venetian bookkeeping ledgers for the organization's finances. You can study them here in detail for auditing purposes. &lt;span id="SpanInfoProfitLossAccount" style="display:none"&gt;&lt;strong&gt;You're currently watching a P&amp;L account, so signs are reversed - income is negative and expenses positive&lt;/strong&gt; due to how Venetian double bookkeeping works.&lt;/span&gt;</value>
</data>
<data name="InspectLedgers_InspectNotAvailable" xml:space="preserve">
<value>Inspecting a single transaction is not yet implemented. It is scheduled for one of the early Swarmops Red sprints, late 2005Q1.</value>
</data>
<data name="InspectLedgers_OutboundBalance" xml:space="preserve">
<value>Outbound Balance</value>
</data>
<data name="InspectLedgers_OutboundBalanceZero" xml:space="preserve">
<value>Ending Balance</value>
</data>
<data name="InspectLedgers_OutboundBalanceZeroToDate" xml:space="preserve">
<value>Ending Balance (to date)</value>
<comment>Displayed if the end-balance date isn't reached yet</comment>
</data>
<data name="InspectLedgers_PleaseSelectAccount" xml:space="preserve">
<value>(Please select an account.)</value>
<comment>Displayed initially and when no valid account selected</comment>
</data>
<data name="InspectLedgers_TransactionId" xml:space="preserve">
<value>Tx#</value>
<comment>Keep VERY short.</comment>
</data>
</root>
+92 -1
View File
@@ -6,13 +6,104 @@
<Swarmops5:ExternalScripts ID="ExternalScripts1" Package="easyui" Control="tree" runat="server" />
<Swarmops5:ExternalScripts ID="ExternalScripts2" Package="easyui" Control="datagrid" runat="server" />
<link rel="stylesheet" type="text/css" href="/Style/v5-easyui-elements.css" />
<script type="text/javascript">
$(document).ready(function () {
$('#gridLedgers').datagrid(
{
onLoadSuccess: function () {
$('div.datagrid').css('opacity', 1);
$('#imageLoadIndicator').hide();
$('span.loadingHeader').hide();
// Merge inbound, outbound balances
var rowCount = $('#gridLedgers').datagrid('getRows').length;
if (rowCount > 0) {
$('#gridLedgers').datagrid('mergeCells', {
index: 0,
field: 'description',
colspan: 3
});
$('#gridLedgers').datagrid('mergeCells', {
index: rowCount-1,
field: 'description',
colspan: 3
});
//$('#gridOutstandingAccounts').dataGrid('mergeCells', {index: rowCount, field:'id', colspan: 5});
// Footer cells could not be merged in datagrid :(
}
}
});
$('#<%=DropYears.ClientID %>').change(function () {
reloadData();
});
$('#<%=DropMonths.ClientID %>').change(function () {
reloadData();
});
$('div.datagrid').css('opacity', 0.4);
});
var accountId = 0;
function onAccountSelected(newAccountId) {
accountId = newAccountId;
reloadData();
}
function reloadData()
{
var selectedYear = $('#<%=DropYears.ClientID %>').val();
var selectedMonth = $('#<%=DropMonths.ClientID %>').val();
$('#gridLedgers').datagrid({ url: 'Json-InspectLedgerData.aspx?Year=' + selectedYear + "&Month=" + selectedMonth + "&AccountId=" + accountId});
$('#imageLoadIndicator').show();
$('div.datagrid').css('opacity', 0.4);
$('#gridOutstandingAccounts').datagrid('reload');
}
</script>
<style type="text/css">
.datagrid-row-selected,.datagrid-row-over{
background:transparent;
}
table.datagrid-ftable {
font-weight: 500;
}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="PlaceHolderMain" Runat="Server">
<h2>Inspect <Swarmops5:ComboBudgets ID="DropBudgets" ListType="All" runat="server" /> for <asp:DropDownList runat="server" ID="DropYears"/> <asp:DropDownList runat="server" ID="DropMonths"/></h2>
<h2><asp:Label ID="LabelHeaderInspect" runat="server" /> <Swarmops5:ComboBudgets ID="DropBudgets" OnClientSelect="onAccountSelected" ListType="All" runat="server" /> <asp:Label ID="LabelHeaderInspectFor" runat="server" /> <asp:DropDownList runat="server" ID="DropYears"/> <asp:DropDownList runat="server" ID="DropMonths"/></h2>
<table id="gridLedgers" class="easyui-datagrid" style="width:680px;height:500px"
data-options="rownumbers:false,singleSelect:false,nowrap:false,fitColumns:true,fit:false,showFooter:false,loading:false,selectOnCheck:true,checkOnSelect:true,url:'Json-InspectLedgerData.aspx'"
idField="id">
<thead>
<tr>
<th data-options="field:'id',width:50"><asp:Label ID="LabelGridHeaderId" runat="server" Text="ID#"/></th>
<th data-options="field:'datetime',width:90,sortable:true"><asp:Label ID="LabelGridHeaderDateTime" runat="server" Text="XYZ DateTime" /></th>
<th data-options="field:'description',width:270"><asp:Label ID="LabelGridHeaderDescription" runat="server" Text="XYZ Description" /></th>
<th data-options="field:'deltaPos',width:70,align:'right'"><asp:Label ID="LabelGridHeaderDeltaPositive" runat="server" Text="XYZ Debit" /></th>
<th data-options="field:'deltaNeg',width:70,align:'right'"><asp:Label ID="LabelGridHeaderDeltaNegative" runat="server" Text="XYZ Credit" /></th>
<th data-options="field:'balance',width:80,align:'right'"><asp:Label ID="LabelGridHeaderBalance" runat="server" Text="XYZ Balance" /></th>
<th data-options="field:'action',width:43,align:'center'"><asp:Label ID="LabelGridHeaderAction" runat="server" Text="XYZAct" /></th>
</tr>
</thead>
</table>
</asp:Content>
+17 -2
View File
@@ -21,7 +21,8 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers
this.PageAccessRequired = new Access(this.CurrentOrganization, AccessAspect.Bookkeeping, AccessType.Read);
this.DbVersionRequired = 0; // base schema is fine
this.PageTitle = "Inspect Ledgers"; // TODO localize
this.PageTitle = Resources.Pages.Ledgers.InspectLedgers_PageTitle;
this.InfoBoxLiteral = Resources.Pages.Ledgers.InspectLedgers_Info;
this.PageIcon = "iconshock-ledger-inspect";
if (!Page.IsPostBack)
@@ -41,6 +42,12 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers
this.DropMonths.Items.Add(new ListItem(new DateTime(2014, monthNumber, 1).ToString("MMM"), monthNumber.ToString(CultureInfo.InvariantCulture))); // will autolocalize
}
this.DropMonths.Items.Add(new ListItem(Resources.Global.Global_Q1, "21")); // quarters and all-year are coded as fake month numbers
this.DropMonths.Items.Add(new ListItem(Resources.Global.Global_Q2, "22"));
this.DropMonths.Items.Add(new ListItem(Resources.Global.Global_Q3, "23"));
this.DropMonths.Items.Add(new ListItem(Resources.Global.Global_Q4, "24"));
this.DropMonths.Items.Add(new ListItem(Resources.Global.Global_AllYear, "31"));
this.DropYears.SelectedIndex = 0;
this.DropMonths.SelectedValue = today.Month.ToString(CultureInfo.InvariantCulture);
}
@@ -50,7 +57,15 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers
private void Localize()
{
this.LabelHeaderInspect.Text = Resources.Pages.Ledgers.InspectLedgers_Header_Inspect;
this.LabelHeaderInspectFor.Text = Resources.Pages.Ledgers.InspectLedgers_Header_For;
this.LabelGridHeaderAction.Text = Resources.Global.Global_Action;
this.LabelGridHeaderBalance.Text = Resources.Global.Ledgers_Balance;
this.LabelGridHeaderDateTime.Text = Resources.Global.Global_Timestamp;
this.LabelGridHeaderDeltaNegative.Text = Resources.Global.Ledgers_Credit;
this.LabelGridHeaderDeltaPositive.Text = Resources.Global.Ledgers_Debit;
this.LabelGridHeaderDescription.Text = Resources.Global.Global_Description;
this.LabelGridHeaderId.Text = Resources.Pages.Ledgers.InspectLedgers_TransactionId;
}
}
}
@@ -0,0 +1 @@
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Json-InspectLedgerData.aspx.cs" Inherits="Swarmops.Frontend.Pages.v5.Ledgers.Json_InspectLedgerData" %>
@@ -0,0 +1,177 @@
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.Basic.Enums;
using Swarmops.Logic.Financial;
using Swarmops.Logic.Security;
namespace Swarmops.Frontend.Pages.v5.Ledgers
{
public partial class Json_InspectLedgerData : DataV5Base
{
protected void Page_Load(object sender, EventArgs e)
{
Response.ContentType = "application/json";
string accountIdString = Request.QueryString["AccountId"];
string yearString = Request.QueryString["Year"];
string monthString = Request.QueryString["Month"];
string emptyResponse = "[{\"id\":\"-\",\"description\":\"" + JsonSanitize(Resources.Pages.Ledgers.InspectLedgers_PleaseSelectAccount) + "\"}]";
if (string.IsNullOrEmpty(accountIdString) || string.IsNullOrEmpty(yearString) ||
string.IsNullOrEmpty(monthString) || accountIdString == "undefined")
{
Response.Output.WriteLine(emptyResponse);
Response.End();
}
int accountId = Int32.Parse(accountIdString);
int year = Int32.Parse(yearString);
int month = Int32.Parse(monthString);
DateTime dawnOfMankind = new DateTime(1901,1,1); // no org will ever import bookkeeping from before this date
if (accountId <= 0)
{
Response.Output.WriteLine(emptyResponse);
Response.End();
}
FinancialAccount account = FinancialAccount.FromIdentity(accountId);
if (account.OrganizationId != CurrentOrganization.Identity)
{
throw new UnauthorizedAccessException("All the nopes in the world");
}
if (!CurrentUser.HasAccess(new Access(CurrentOrganization, AccessAspect.Bookkeeping, AccessType.Read)))
{
throw new UnauthorizedAccessException("Access denied because security tokens say so");
}
DateTime periodStart, periodEnd;
DateTime balanceStart = dawnOfMankind;
bool zeroStart = false;
bool zeroEnd = false;
if (month > 0 && month <= 12)
{
periodStart = new DateTime(year, month, 1);
periodEnd = periodStart.AddMonths(1);
if (account.AccountType == FinancialAccountType.Income ||
account.AccountType == FinancialAccountType.Cost)
{
balanceStart = new DateTime(year, 1, 1);
if (month == 1)
{
zeroStart = true;
}
if (month == 12)
{
zeroEnd = true;
}
}
}
else if (month > 20 && month < 25) // quarters 1..4 are coded as months 21..24
{
periodStart = new DateTime(year, (month - 21) * 3 + 1, 1);
periodEnd = periodStart.AddMonths(3);
if (account.AccountType == FinancialAccountType.Income ||
account.AccountType == FinancialAccountType.Cost)
{
balanceStart = new DateTime(year, 1, 1);
if (month == 21)
{
zeroStart = true;
}
if (month == 24)
{
zeroEnd = true;
}
}
}
else if (month == 31) // "whole year" is coded as month 31
{
periodStart = new DateTime(year, 1, 1);
periodEnd = new DateTime(year + 1, 1, 1);
if (account.AccountType == FinancialAccountType.Income ||
account.AccountType == FinancialAccountType.Cost)
{
zeroStart = true;
zeroEnd = true;
}
}
else
{
throw new ArgumentException("Invalid month supplied: " + month.ToString(CultureInfo.InvariantCulture));
}
FinancialAccountRows rows = account.GetRows(periodStart, periodEnd);
StringBuilder result = new StringBuilder(16384);
Int64 runningBalance = 0L;
string startString = Resources.Pages.Ledgers.InspectLedgers_InboundBalanceZero;
string endString = Resources.Pages.Ledgers.InspectLedgers_OutboundBalanceZero;
if (!zeroStart)
{
runningBalance = account.GetDeltaCents(dawnOfMankind, periodStart);
startString = Resources.Pages.Ledgers.InspectLedgers_InboundBalance;
}
if (!zeroEnd)
{
endString = Resources.Pages.Ledgers.InspectLedgers_OutboundBalance;
}
else if (periodEnd > DateTime.Now)
{
// account is zeroed at end of this period, but we're not yet at end of period, so add a "to date" disclaimer
endString = Resources.Pages.Ledgers.InspectLedgers_OutboundBalanceZeroToDate;
}
result.Append("{" +
String.Format("\"description\":\"{0}\",\"balance\":\"{1:N0}\"", JsonSanitize(startString), runningBalance / 100.0) + "},");
foreach (FinancialAccountRow row in rows)
{
string creditString = string.Empty;
string debitString = string.Empty;
if (row.AmountCents < 0)
{
creditString = String.Format("{0:N0}", row.AmountCents/100.0);
}
else if (row.AmountCents > 0)
{
debitString = String.Format("{0:N0}", row.AmountCents/100.0);
}
runningBalance += row.AmountCents;
result.Append("{" + String.Format(
"\"id\":\"{0}\",\"datetime\":\"{1:MMM-dd HH:mm}\",\"description\":\"{2}\"," +
"\"deltaPos\":\"{3}\",\"deltaNeg\":\"{4}\",\"balance\":\"{5:N0}\"",
row.FinancialTransactionId,
row.TransactionDateTime,
JsonSanitize(row.Description),
debitString,
creditString,
runningBalance / 100.0) + "},");
}
result.Append("{" +
String.Format("\"description\":\"{0}\",\"balance\":\"{1:N0}\"", JsonSanitize(endString), runningBalance / 100.0) + "},");
Response.Output.WriteLine("[" + result.ToString().TrimEnd(',') + "]");
Response.End();
}
}
}