From 97ec9e39142b2e1e83536596c2284a94d589a0d7 Mon Sep 17 00:00:00 2001 From: Rick Falkvinge Date: Sun, 3 Mar 2019 16:36:53 +0100 Subject: [PATCH] Some work on auditing hotwallet --- Site/App_GlobalResources/Menu5.designer.cs | 9 + Site/App_GlobalResources/Menu5.resx | 4 + Site/Controls/v5/Base/MainMenu.ascx.cs | 2 +- Site/MainMenu-v5.xml | 4 +- Site/Pages/v5/Ledgers/InspectLedgers.aspx | 20 ++ .../Ledgers/InspectLedgers.aspx.designer.cs | 90 ++++++ .../v5/Ledgers/Json-LedgerNativeData.aspx | 1 + .../v5/Ledgers/Json-LedgerNativeData.aspx.cs | 271 ++++++++++++++++++ .../Json-LedgerNativeData.aspx.designer.cs | 15 + Site/Site.csproj | 8 + 10 files changed, 421 insertions(+), 3 deletions(-) create mode 100644 Site/Pages/v5/Ledgers/Json-LedgerNativeData.aspx create mode 100644 Site/Pages/v5/Ledgers/Json-LedgerNativeData.aspx.cs create mode 100644 Site/Pages/v5/Ledgers/Json-LedgerNativeData.aspx.designer.cs diff --git a/Site/App_GlobalResources/Menu5.designer.cs b/Site/App_GlobalResources/Menu5.designer.cs index 8178a9e9..70e5c9bc 100644 --- a/Site/App_GlobalResources/Menu5.designer.cs +++ b/Site/App_GlobalResources/Menu5.designer.cs @@ -492,6 +492,15 @@ namespace Resources { } } + /// + /// Looks up a localized string similar to Request Reimbursement. + /// + internal static string Menu5_Financial_RequestReimbursement { + get { + return ResourceManager.GetString("Menu5_Financial_RequestReimbursement", resourceCulture); + } + } + /// /// Looks up a localized string similar to My Salary. /// diff --git a/Site/App_GlobalResources/Menu5.resx b/Site/App_GlobalResources/Menu5.resx index 6f916872..67f3db87 100644 --- a/Site/App_GlobalResources/Menu5.resx +++ b/Site/App_GlobalResources/Menu5.resx @@ -485,4 +485,8 @@ Reports This is financial analysis reports. "Analysis" would also work as translation. + + Request Reimbursement + This is the same as "file an expense claim", but "requesting reimbursement" is better English + \ No newline at end of file diff --git a/Site/Controls/v5/Base/MainMenu.ascx.cs b/Site/Controls/v5/Base/MainMenu.ascx.cs index 37d768ca..1c650bdc 100644 --- a/Site/Controls/v5/Base/MainMenu.ascx.cs +++ b/Site/Controls/v5/Base/MainMenu.ascx.cs @@ -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) { diff --git a/Site/MainMenu-v5.xml b/Site/MainMenu-v5.xml index 1143e04a..5d5f5df9 100644 --- a/Site/MainMenu-v5.xml +++ b/Site/MainMenu-v5.xml @@ -146,10 +146,10 @@ - Financial_ClaimExpense + Financial_RequestReimbursement 1 - iconshock-moneyback + iconshock-visa /Pages/v5/Financial/FileExpenseClaim.aspx Link diff --git a/Site/Pages/v5/Ledgers/InspectLedgers.aspx b/Site/Pages/v5/Ledgers/InspectLedgers.aspx index b1ae30eb..330d2a2c 100644 --- a/Site/Pages/v5/Ledgers/InspectLedgers.aspx +++ b/Site/Pages/v5/Ledgers/InspectLedgers.aspx @@ -432,6 +432,26 @@ +
+

+ + + + + + + + + + + + + +
+ +
diff --git a/Site/Pages/v5/Ledgers/InspectLedgers.aspx.designer.cs b/Site/Pages/v5/Ledgers/InspectLedgers.aspx.designer.cs index e49a224a..e52af7c6 100644 --- a/Site/Pages/v5/Ledgers/InspectLedgers.aspx.designer.cs +++ b/Site/Pages/v5/Ledgers/InspectLedgers.aspx.designer.cs @@ -291,6 +291,96 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers { /// protected global::System.Web.UI.WebControls.Label LabelGridHeaderAction; + /// + /// LabelHeaderHotwallet control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.Label LabelHeaderHotwallet; + + /// + /// DropHotwalletYears control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.DropDownList DropHotwalletYears; + + /// + /// DropHotwalletMonths control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.DropDownList DropHotwalletMonths; + + /// + /// Label1 control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.Label Label1; + + /// + /// Label2 control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.Label Label2; + + /// + /// Label3 control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.Label Label3; + + /// + /// Label4 control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.Label Label4; + + /// + /// Label5 control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.Label Label5; + + /// + /// Label6 control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.Label Label6; + + /// + /// Label7 control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.Label Label7; + /// /// DialogEditTx control. /// diff --git a/Site/Pages/v5/Ledgers/Json-LedgerNativeData.aspx b/Site/Pages/v5/Ledgers/Json-LedgerNativeData.aspx new file mode 100644 index 00000000..38685c6e --- /dev/null +++ b/Site/Pages/v5/Ledgers/Json-LedgerNativeData.aspx @@ -0,0 +1 @@ +<%@ Page Language="C#" AutoEventWireup="true" Inherits="Swarmops.Frontend.Pages.v5.Ledgers.Json_LedgerNativeData" Codebehind="Json-LedgerNativeData.aspx.cs" %> \ No newline at end of file diff --git a/Site/Pages/v5/Ledgers/Json-LedgerNativeData.aspx.cs b/Site/Pages/v5/Ledgers/Json-LedgerNativeData.aspx.cs new file mode 100644 index 00000000..5524fd46 --- /dev/null +++ b/Site/Pages/v5/Ledgers/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 runningBalanceLookup = new Dictionary(); + Dictionary accountLookup = new Dictionary(); + + 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 = + "" + + ""; + + string actionHtml = string.Empty; + + Documents documents = Documents.ForObject(transaction.Dependency ?? transaction); + + if (documents.Count > 0) + { + foreach (Document doc in documents) + { + actionHtml += String.Format("", + 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")) + "" + actionHtml + ""; + } + + result.Append("{" + String.Format( + "\"id\":\"{0:N0}\",\"idDisplay\":\"{0:N0}\",\"datetime\":\"{1:MMM-dd HH:mm}\",\"txDescription\":\"{2}\",\"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 ( + " ", + 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(); + } + } +} \ No newline at end of file diff --git a/Site/Pages/v5/Ledgers/Json-LedgerNativeData.aspx.designer.cs b/Site/Pages/v5/Ledgers/Json-LedgerNativeData.aspx.designer.cs new file mode 100644 index 00000000..afcca1d5 --- /dev/null +++ b/Site/Pages/v5/Ledgers/Json-LedgerNativeData.aspx.designer.cs @@ -0,0 +1,15 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Swarmops.Frontend.Pages.v5.Ledgers { + + + public partial class Json_LedgerNativeData { + } +} diff --git a/Site/Site.csproj b/Site/Site.csproj index 580f1127..d9e439f4 100644 --- a/Site/Site.csproj +++ b/Site/Site.csproj @@ -1760,6 +1760,13 @@ Json-AccountChartData.aspx + + Json-LedgerNativeData.aspx + ASPXCodeBehind + + + Json-LedgerNativeData.aspx + Json-GeneralLedgerData.aspx ASPXCodeBehind @@ -2460,6 +2467,7 @@ +