Some work on auditing hotwallet

This commit is contained in:
Rick Falkvinge
2019-03-03 16:36:53 +01:00
parent 2ffe21935b
commit 97ec9e3914
10 changed files with 421 additions and 3 deletions
+9
View File
@@ -492,6 +492,15 @@ namespace Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Request Reimbursement.
/// </summary>
internal static string Menu5_Financial_RequestReimbursement {
get {
return ResourceManager.GetString("Menu5_Financial_RequestReimbursement", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to My Salary.
/// </summary>
+4
View File
@@ -485,4 +485,8 @@
<value>Reports</value>
<comment>This is financial analysis reports. "Analysis" would also work as translation.</comment>
</data>
<data name="Menu5_Financial_RequestReimbursement" xml:space="preserve">
<value>Request Reimbursement</value>
<comment>This is the same as "file an expense claim", but "requesting reimbursement" is better English</comment>
</data>
</root>
+1 -1
View File
@@ -125,7 +125,7 @@ namespace Swarmops.Controls.Base
}
else if (menuItem.ImageUrl != null)
{
string[] iconSizePreferences = { "40", "96", "128", "20", "16" };
string[] iconSizePreferences = { "96", "128", "40", "20", "16" };
foreach (string testSize in iconSizePreferences)
{
+2 -2
View File
@@ -146,10 +146,10 @@
<Children>
<MainMenuItem>
<ResourceKey>Financial_ClaimExpense</ResourceKey>
<ResourceKey>Financial_RequestReimbursement</ResourceKey>
<UserLevel>1</UserLevel>
<Permissions />
<ImageUrl>iconshock-moneyback</ImageUrl>
<ImageUrl>iconshock-visa</ImageUrl>
<NavigateUrl>/Pages/v5/Financial/FileExpenseClaim.aspx</NavigateUrl>
<Type>Link</Type>
<Children />
+20
View File
@@ -432,6 +432,26 @@
</thead>
</table>
</div>
<div class="tab" title="<img src='/Images/Icons/iconshock-cashregister-96px.png' height='64' width='64' />">
<h2><asp:Label ID="LabelHeaderHotwallet" runat="server" /> <asp:DropDownList runat="server" ID="DropHotwalletYears"/> <asp:DropDownList runat="server" ID="DropHotwalletMonths"/></h2>
<table id="gridHotwallet" 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:70,align:'right'"><asp:Label ID="Label1" runat="server" Text="ID#"/></th>
<th data-options="field:'datetime',width:90,sortable:true"><asp:Label ID="Label2" runat="server" Text="XYZ DateTime" /></th>
<th data-options="field:'description',width:250"><asp:Label ID="Label3" runat="server" Text="XYZ Description" /></th>
<th data-options="field:'deltaPres',width:70,align:'right'"><asp:Label ID="Label4" runat="server" Text="XYZ Debit" /></th>
<th data-options="field:'deltaBitcoin',width:70,align:'right'"><asp:Label ID="Label5" runat="server" Text="XYZ Credit" /></th>
<th data-options="field:'balanceBitcoin',width:80,align:'right'"><asp:Label ID="Label6" runat="server" Text="XYZ Balance" /></th>
<th data-options="field:'action',width:43,align:'center'"><asp:Label ID="Label7" runat="server" Text="XYZAct" /></th>
</tr>
</thead>
</table>
</div>
</div>
+90
View File
@@ -291,6 +291,96 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers {
/// </remarks>
protected global::System.Web.UI.WebControls.Label LabelGridHeaderAction;
/// <summary>
/// LabelHeaderHotwallet control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Label LabelHeaderHotwallet;
/// <summary>
/// DropHotwalletYears control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.DropDownList DropHotwalletYears;
/// <summary>
/// DropHotwalletMonths control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.DropDownList DropHotwalletMonths;
/// <summary>
/// Label1 control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Label Label1;
/// <summary>
/// Label2 control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Label Label2;
/// <summary>
/// Label3 control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Label Label3;
/// <summary>
/// Label4 control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Label Label4;
/// <summary>
/// Label5 control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Label Label5;
/// <summary>
/// Label6 control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Label Label6;
/// <summary>
/// Label7 control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Label Label7;
/// <summary>
/// DialogEditTx control.
/// </summary>
@@ -0,0 +1 @@
<%@ Page Language="C#" AutoEventWireup="true" Inherits="Swarmops.Frontend.Pages.v5.Ledgers.Json_LedgerNativeData" Codebehind="Json-LedgerNativeData.aspx.cs" %>
@@ -0,0 +1,271 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using Swarmops.Common;
using Swarmops.Common.Enums;
using Swarmops.Common.Interfaces;
using Swarmops.Logic.Financial;
using Swarmops.Logic.Security;
using Swarmops.Logic.Support;
namespace Swarmops.Frontend.Pages.v5.Ledgers
{
public partial class Json_LedgerNativeData : DataV5Base
{
protected void Page_Load (object sender, EventArgs e)
{
Response.ContentType = "application/json";
string yearString = Request.QueryString["Year"];
string monthString = Request.QueryString["Month"];
int year = Int32.Parse (yearString);
int month = Int32.Parse (monthString);
if (!CurrentAuthority.HasAccess (new Access (CurrentOrganization, AccessAspect.Bookkeeping, AccessType.Read)))
{
throw new UnauthorizedAccessException ("Access denied because security tokens say so");
}
DateTime periodStart, periodEnd;
bool zeroStart = false;
bool zeroEnd = false;
bool displayDescription = CurrentAuthority.HasAccess (new Access (CurrentOrganization, AccessAspect.BookkeepingDetails, AccessType.Read));
// HACK HACK HACK
if (CurrentOrganization.Identity == 8 && CurrentOrganization.Name.StartsWith("Rick Falkvinge"))
{
// TODO
displayDescription = true; // FIX THIS WITH A DAMN SETTING, YOU MORON, DON'T HARDCODE IT
}
bool canSeeAudit = CurrentAuthority.HasAccess(new Access(CurrentOrganization, AccessAspect.Auditing, AccessType.Read));
if (month > 0 && month <= 12)
{
periodStart = new DateTime (year, month, 1);
periodEnd = periodStart.AddMonths (1);
}
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);
}
else if (month == 31) // "whole year" is coded as month 31
{
periodStart = new DateTime (year, 1, 1);
periodEnd = new DateTime (year + 1, 1, 1);
}
else
{
throw new ArgumentException ("Invalid month supplied: " + month.ToString (CultureInfo.InvariantCulture));
}
DateTime profitLossStart = new DateTime(periodStart.Year, 1, 1);
DateTime balanceStart = Constants.DateTimeLow;
FinancialAccounts accounts = FinancialAccounts.ForOrganization(CurrentOrganization);
FinancialAccountRows rows = accounts.GetRows (periodStart, periodEnd);
StringBuilder result = new StringBuilder (16384);
Dictionary<int, Int64> runningBalanceLookup = new Dictionary<int, long>();
Dictionary<int, FinancialAccount> accountLookup = new Dictionary<int, FinancialAccount>();
foreach (FinancialAccount accountLoop in accounts)
{
accountLookup[accountLoop.Identity] = accountLoop;
}
int currentTransactionId = 0;
int rowCount = 0;
foreach (FinancialAccountRow row in rows)
{
string creditString = string.Empty;
string debitString = string.Empty;
FinancialAccount account = accountLookup[row.FinancialAccountId];
if (!runningBalanceLookup.ContainsKey(row.FinancialAccountId))
{
if (account.AccountType == FinancialAccountType.Asset || account.AccountType == FinancialAccountType.Debt)
{
runningBalanceLookup[account.Identity] = account.GetDeltaCents(balanceStart, periodStart);
}
else
{
runningBalanceLookup[account.Identity] = account.GetDeltaCents(profitLossStart, periodStart);
}
}
if (row.FinancialTransactionId != currentTransactionId)
{
// We're starting a new transaction here
// If it's not the first one, close the previous one first
if (currentTransactionId != 0)
{
result.Append("]},");
}
FinancialTransaction transaction = row.Transaction;
string description = transaction.Description;
string hasDoxString =
"<img src='/Images/Icons/iconshock-search-256px.png' onmouseover=\"this.src='/Images/Icons/iconshock-search-hot-256px.png';\" onmouseout=\"this.src='/Images/Icons/iconshock-search-256px.png';\" data-txid='{0}' class='LocalViewDox' style='cursor:pointer' height='20' width='20' />" +
"<img src='/Images/Icons/iconshock-download-240px.png' onmouseover=\"this.src='/Images/Icons/iconshock-download-hot-240px.png';\" onmouseout=\"this.src='/Images/Icons/iconshock-download-240px.png';\" data-docid='{1}' data-docname=\"{2}\" class='LocalDownloadDox' style='cursor:pointer' height='18' width='18' />";
string actionHtml = string.Empty;
Documents documents = Documents.ForObject(transaction.Dependency ?? transaction);
if (documents.Count > 0)
{
foreach (Document doc in documents)
{
actionHtml += String.Format("<a href='/Pages/v5/Support/StreamUpload.aspx?DocId={0}&hq=1' data-caption=\"{1}\" class='FancyBox_Gallery' data-fancybox='{2}'></a>",
doc.Identity, doc.ClientFileName.Replace("\"", "'"), transaction.Identity);
}
actionHtml = String.Format(hasDoxString, row.FinancialTransactionId.ToString(CultureInfo.InvariantCulture), documents[0].Identity, CurrentOrganization.Name + " - " + Resources.Global.Financial_GeneralLedger + " " + transaction.DateTime.ToShortDateString() + " - " + Resources.Global.Financial_TransactionIdShort + transaction.OrganizationSequenceId.ToString("N0")) + "<span class='hiddenDocLinks'>" + actionHtml + "</span>";
}
result.Append("{" + String.Format(
"\"id\":\"{0:N0}\",\"idDisplay\":\"<span class='weight-more-emphasis'>{0:N0}</span>\",\"datetime\":\"<span class='weight-more-emphasis'>{1:MMM-dd HH:mm}</span>\",\"txDescription\":\"<span class='weight-more-emphasis tx-description'>{2}</span>\",\"action\":\"{3}\"," +
"\"state\":\"open\",\"children\":[",
row.Transaction.OrganizationSequenceId,
row.TransactionDateTime,
JsonSanitize(description),
JsonSanitize(actionHtml)));
if (transaction.Dependency != null)
{
IHasIdentity dependency = transaction.Dependency;
string info = string.Empty;
Documents docs = null;
if (dependency is VatReport)
{
VatReport report = (VatReport) dependency;
if (report.OpenTransactionId == transaction.Identity)
{
info = String.Format(Resources.Pages.Ledgers.InspectLedgers_TxInfo_OpenVatReport,
report.DescriptionShort);
}
else if (report.CloseTransactionId == transaction.Identity)
{
info = String.Format(Resources.Pages.Ledgers.InspectLedgers_TxInfo_CloseVatReport,
report.DescriptionShort);
}
}
// TODO: Continue here with adding Info row under transactions where it's helpful
// TODO: Remember that the Info row needs cell merging, colspan=5 or =6
}
/*
result.Append("{" + String.Format(
"\"id\":\"{0:N0}\",\"datetime\":\"{1:MMM-dd HH:mm}\",\"description\":\"{2}\"," +
"\"action\":\"{6}\",\"state\":\"open\",\"children\":[",
row.Transaction.OrganizationSequenceId,
row.TransactionDateTime,
JsonSanitize(description),
debitString,
creditString,
runningBalanceLookup[row.FinancialAccountId]/100.0,
JsonSanitize(actionHtml)));
*/
currentTransactionId = row.FinancialTransactionId;
rowCount = 1;
}
else
{
// still same transaction
result.Append(",");
rowCount++;
}
if (row.AmountCents < 0)
{
creditString = String.Format ("{0:N2}", row.AmountCents/100.0);
}
else if (row.AmountCents > 0)
{
debitString = String.Format ("{0:N2}", row.AmountCents/100.0);
}
runningBalanceLookup[row.FinancialAccountId] += row.AmountCents;
/*
if (canSeeAudit)
{
actionHtml +=
String.Format (
"&nbsp;<img src=\"/Images/Icons/iconshock-flag-white-16px.png\" class=\"LocalIconFlag\" txId=\"{0}\" />",
row.FinancialTransactionId.ToString (CultureInfo.InvariantCulture));
}*/
//result.Append("{\"description\":\"child\"}");
string accountClass;
switch (accountLookup[row.FinancialAccountId].AccountType)
{
case FinancialAccountType.Asset:
accountClass = Resources.Global.Financial_Asset;
break;
case FinancialAccountType.Debt:
accountClass = Resources.Global.Financial_Debt;
break;
case FinancialAccountType.Income:
accountClass = Resources.Global.Financial_Income;
break;
case FinancialAccountType.Cost:
accountClass = Resources.Global.Financial_Cost;
break;
default:
throw new NotImplementedException();
}
string accountName = account.Name;
if (account.ParentIdentity != 0)
{
if (!accountLookup.ContainsKey(account.ParentIdentity))
{
accountLookup[account.ParentIdentity] = account.Parent;
}
accountName = accountLookup[account.ParentIdentity].Name + " » " + accountName;
}
result.Append ("{" + String.Format (
"\"id\":\"{0:N0}-{6:N0}\",\"idDisplay\":\"{0:N0}:{6:N0}\",\"datetime\":\"{1}\",\"txDescription\":\"{2}\"," +
"\"deltaPos\":\"{3}\",\"deltaNeg\":\"{4}\",\"balance\":\"{5:N2}\"",
row.Transaction.OrganizationSequenceId,
JsonSanitize (accountClass),
JsonSanitize (accountName),
debitString,
creditString,
runningBalanceLookup[row.FinancialAccountId]/100.0,
rowCount) + "}");
}
if (rows.Count == 0)
{
// If there are no transactions in this time period, say so
result.Append ("{\"description\":\"" +
JsonSanitize (Resources.Pages.Ledgers.InspectLedgers_NoTransactions) + "\"},");
}
Response.Output.WriteLine ("[" + result.ToString().TrimEnd (',') + "]}]");
Response.End();
}
}
}
@@ -0,0 +1,15 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Swarmops.Frontend.Pages.v5.Ledgers {
public partial class Json_LedgerNativeData {
}
}
+8
View File
@@ -1760,6 +1760,13 @@
<Compile Include="Pages\v5\Ledgers\Json-AccountChartData.aspx.designer.cs">
<DependentUpon>Json-AccountChartData.aspx</DependentUpon>
</Compile>
<Compile Include="Pages\v5\Ledgers\Json-LedgerNativeData.aspx.cs">
<DependentUpon>Json-LedgerNativeData.aspx</DependentUpon>
<SubType>ASPXCodeBehind</SubType>
</Compile>
<Compile Include="Pages\v5\Ledgers\Json-LedgerNativeData.aspx.designer.cs">
<DependentUpon>Json-LedgerNativeData.aspx</DependentUpon>
</Compile>
<Compile Include="Pages\v5\Ledgers\Json-GeneralLedgerData.aspx.cs">
<DependentUpon>Json-GeneralLedgerData.aspx</DependentUpon>
<SubType>ASPXCodeBehind</SubType>
@@ -2460,6 +2467,7 @@
<Content Include="Pages\v5\Ledgers\EndOfMonth.aspx" />
<Content Include="Pages\v5\Ledgers\InspectLedgers.aspx" />
<Content Include="Pages\v5\Ledgers\Json-AccountChartData.aspx" />
<Content Include="Pages\v5\Ledgers\Json-LedgerNativeData.aspx" />
<Content Include="Pages\v5\Ledgers\Json-GeneralLedgerData.aspx" />
<Content Include="Pages\v5\Ledgers\Json-VatReportData.aspx" />
<Content Include="Pages\v5\Ledgers\Json-BalanceSheetDataSimplified.aspx" />