diff --git a/Site/Pages/v5/Ledgers/InspectLedgers.aspx b/Site/Pages/v5/Ledgers/InspectLedgers.aspx index c4ffd09f..4dea49a3 100644 --- a/Site/Pages/v5/Ledgers/InspectLedgers.aspx +++ b/Site/Pages/v5/Ledgers/InspectLedgers.aspx @@ -71,8 +71,7 @@ var heightBody = $('div#<%=this.DialogEditTx.ClientID%>_divModalCover table.datagrid-btable').height(); - if (heightBody != null) - { + if (heightBody != null) { $('div#<%=this.DialogEditTx.ClientID%>_divModalCover div.datagrid-body').height(heightBody); var heightHeaders = $('div#<%=this.DialogEditTx.ClientID%>_divModalCover div.datagrid-header').height(); @@ -84,6 +83,7 @@ } }); + $('#treeGeneralLedger').treegrid( { onLoadSuccess: function() { @@ -117,7 +117,46 @@ } ); + $('#gridHotwallet').datagrid( + { + onLoadSuccess: function() { + $('div.datagrid').css('opacity', 1); + $('#imageLoadIndicator').hide(); + $('span.loadingHeader').hide(); + + // Merge inbound, outbound balances + + var rowCount = $('#gridHotwallet').datagrid('getRows').length; + if (rowCount > 0) { + $('#gridHotwallet').datagrid('mergeCells', { + index: 0, + field: 'description', + colspan: 3 + }); + $('#gridHotwallet').datagrid('mergeCells', { + index: rowCount - 1, + field: 'description', + colspan: 3 + }); + + } + + // Enable various actions on icon + + $('img.LocalIconFlag').click(function() { + inspectingTransactionId = $(this).attr("data-txid"); + onFlagTransaction("Add Tx Id here"); + }); + + $('img.LocalIconInspect').click(function() { + onInspectTransaction($(this).attr("data-txid")); + }); + + } + }); + reloadGeneralData(); // loads first data - URL is null when first entered + reloadHotwalletData(); $('#<%= DropYears.ClientID %>').change(function() { reloadInspectData(); @@ -135,6 +174,16 @@ reloadGeneralData(); }); + $('#<%=this.DropHotwalletYears.ClientID%>').change(function() + { + reloadHotwalletData(); + }); + + $('#<%=this.DropHotwalletMonths.ClientID%>').change(function() + { + reloadHotwalletData(); + }); + $('#ButtonAddTransactionRow').click(function() { addTransactionRow(); }); @@ -256,6 +305,16 @@ // $('#gridOutstandingAccounts').datagrid('reload'); } + function reloadHotwalletData() { + var selectedYear = $('#<%= DropHotwalletYears.ClientID %>').val(); + var selectedMonth = $('#<%= DropHotwalletMonths.ClientID %>').val(); + + $('#gridHotwallet').datagrid({ url: 'Json-InspectNativeData.aspx?Year=' + selectedYear + "&Month=" + selectedMonth }); + + $('#imageLoadIndicator').show(); + $('div.datagrid').css('opacity', 0.4); + } + function prefillUnbalancedAmount(transactionId) { var jsonData = {}; @@ -436,7 +495,7 @@

diff --git a/Site/Pages/v5/Ledgers/InspectLedgers.aspx.cs b/Site/Pages/v5/Ledgers/InspectLedgers.aspx.cs index 094af198..c802dcef 100644 --- a/Site/Pages/v5/Ledgers/InspectLedgers.aspx.cs +++ b/Site/Pages/v5/Ledgers/InspectLedgers.aspx.cs @@ -119,7 +119,7 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers this.LabelHotwalletHeaderId.Text = Resources.Pages.Ledgers.InspectLedgers_TransactionId; this.LabelHotwalletHeaderPresentationCurrency.Text = CurrentOrganization.Currency.DisplayCode; this.LabelHotwalletHeaderMicrocoin.Text = Currency.BitcoinCash.DisplayCode; - this.LabelHotwalletHeaderBalance.Text = Global.Ledgers_Balance; + this.LabelHotwalletHeaderBalance.Text = Resources.Pages.Ledgers.BitcoinHotwallet_BalanceMicrocoins; this.LabelHotwalletActions.Text = Global.Global_Action; this.LabelFlagNotAvailable.Text = Resources.Pages.Ledgers.InspectLedgers_FlaggingNotAvailable; diff --git a/Site/Pages/v5/Ledgers/Json-LedgerNativeData.aspx.cs b/Site/Pages/v5/Ledgers/Json-LedgerNativeData.aspx.cs index 5524fd46..5384116c 100644 --- a/Site/Pages/v5/Ledgers/Json-LedgerNativeData.aspx.cs +++ b/Site/Pages/v5/Ledgers/Json-LedgerNativeData.aspx.cs @@ -1,38 +1,50 @@ 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) + 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); + string emptyResponse = "[{\"id\":\"-\",\"description\":\"" + + JsonSanitize(Resources.Pages.Ledgers.InspectLedgers_PleaseSelectAccount) + "\"}]"; - if (!CurrentAuthority.HasAccess (new Access (CurrentOrganization, AccessAspect.Bookkeeping, AccessType.Read))) + if (string.IsNullOrEmpty(yearString) || string.IsNullOrEmpty(monthString)) { - throw new UnauthorizedAccessException ("Access denied because security tokens say so"); + Response.Output.WriteLine(emptyResponse); + Response.End(); + } + + int year = Int32.Parse(yearString); + int month = Int32.Parse(monthString); + + FinancialAccount account = CurrentOrganization.FinancialAccounts.AssetsBitcoinHot; + if (account == null || account.OrganizationId != CurrentOrganization.Identity) + { + throw new UnauthorizedAccessException("All the nopes in the world"); + } + + if (!CurrentAuthority.HasAccess(new Access(CurrentOrganization, AccessAspect.Bookkeeping, AccessType.Read)) && CurrentOrganization.HasOpenLedgers) + { + throw new UnauthorizedAccessException("Access denied because security tokens say so"); } DateTime periodStart, periodEnd; + DateTime balanceStart = Constants.DateTimeLow; bool zeroStart = false; bool zeroEnd = false; - bool displayDescription = CurrentAuthority.HasAccess (new Access (CurrentOrganization, AccessAspect.BookkeepingDetails, AccessType.Read)); + bool displayDescription = CurrentAuthority.HasAccess(new Access(CurrentOrganization, AccessAspect.BookkeepingDetails, AccessType.Read)); // HACK HACK HACK if (CurrentOrganization.Identity == 8 && CurrentOrganization.Name.StartsWith("Rick Falkvinge")) @@ -45,226 +57,137 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers if (month > 0 && month <= 12) { - periodStart = new DateTime (year, month, 1); - periodEnd = periodStart.AddMonths (1); + 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); + 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); + 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)); + throw new ArgumentException("Invalid month supplied: " + month.ToString(CultureInfo.InvariantCulture)); } - DateTime profitLossStart = new DateTime(periodStart.Year, 1, 1); - DateTime balanceStart = Constants.DateTimeLow; + FinancialAccountRows rows = account.GetRows(periodStart, periodEnd); - FinancialAccounts accounts = FinancialAccounts.ForOrganization(CurrentOrganization); - FinancialAccountRows rows = accounts.GetRows (periodStart, periodEnd); + StringBuilder result = new StringBuilder(16384); - StringBuilder result = new StringBuilder (16384); + Int64 runningBalance = 0L; + Int64 runningBitcoinBalance = 0; + string startString = Resources.Pages.Ledgers.InspectLedgers_InboundBalanceZero; + string endString = Resources.Pages.Ledgers.InspectLedgers_OutboundBalanceZero; - Dictionary runningBalanceLookup = new Dictionary(); - Dictionary accountLookup = new Dictionary(); - - foreach (FinancialAccount accountLoop in accounts) + if (!zeroStart) { - accountLookup[accountLoop.Identity] = accountLoop; + runningBitcoinBalance = account.GetForeignCurrencyBalanceDeltaCents(balanceStart, periodStart).Cents; + runningBalance = account.GetDeltaCents(balanceStart, 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; } - int currentTransactionId = 0; - int rowCount = 0; + result.Append("{" + + String.Format("\"description\":\"{0}\",\"balanceBitcoin\":\"{1:N2}\"", JsonSanitize(startString), + runningBitcoinBalance / 100.0) + "},"); foreach (FinancialAccountRow row in rows) { - string creditString = string.Empty; - string debitString = string.Empty; + string description = row.Description; - FinancialAccount account = accountLookup[row.FinancialAccountId]; - if (!runningBalanceLookup.ContainsKey(row.FinancialAccountId)) + if (!displayDescription) { - if (account.AccountType == FinancialAccountType.Asset || account.AccountType == FinancialAccountType.Debt) - { - runningBalanceLookup[account.Identity] = account.GetDeltaCents(balanceStart, periodStart); - } - else - { - runningBalanceLookup[account.Identity] = account.GetDeltaCents(profitLossStart, periodStart); - } + description = Resources.Pages.Ledgers.InspectLedgers_TxDetail_DescriptionWithheld; } - if (row.FinancialTransactionId != currentTransactionId) - { - // We're starting a new transaction here + Int64 deltaSatoshis = row.TransactionRow.AmountForeignCents.Cents; + runningBitcoinBalance += deltaSatoshis; - // If it's not the first one, close the previous one first - if (currentTransactionId != 0) - { - result.Append("]},"); - } + string hasDoxString = + ""; - FinancialTransaction transaction = row.Transaction; - string description = transaction.Description; + string actionHtml = String.Format(hasDoxString, row.FinancialTransactionId.ToString(CultureInfo.InvariantCulture)); - 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 ( + 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(); + row.FinancialTransactionId.ToString(CultureInfo.InvariantCulture)); } - 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}\"", + result.Append("{" + String.Format( + "\"id\":\"{0:N0}\",\"datetime\":\"{1:MMM-dd HH:mm}\",\"description\":\"{2}\"," + + "\"deltaPresentation\":\"{3}\",\"deltaBitcoin\":\"{4}\",\"balanceBitcoin\":\"{5:N2}\",\"action\":\"{6}\"", row.Transaction.OrganizationSequenceId, - JsonSanitize (accountClass), - JsonSanitize (accountName), - debitString, - creditString, - runningBalanceLookup[row.FinancialAccountId]/100.0, - rowCount) + "}"); - + row.TransactionDateTime, + JsonSanitize(description), + row.AmountCents != 0? (row.AmountCents / 100.0).ToString("N2") : string.Empty, + deltaSatoshis != 0? (deltaSatoshis / 100.0).ToString("N2"): string.Empty, + runningBitcoinBalance / 100.0, + JsonSanitize(actionHtml)) + "},"); } if (rows.Count == 0) { // If there are no transactions in this time period, say so - result.Append ("{\"description\":\"" + - JsonSanitize (Resources.Pages.Ledgers.InspectLedgers_NoTransactions) + "\"},"); + result.Append("{\"description\":\"" + + JsonSanitize(Resources.Pages.Ledgers.InspectLedgers_NoTransactions) + "\"},"); } - Response.Output.WriteLine ("[" + result.ToString().TrimEnd (',') + "]}]"); + result.Append("{" + + String.Format("\"description\":\"{0}\",\"balance\":\"{1:N2}\"", JsonSanitize(endString), + runningBalance / 100.0) + "},"); + + Response.Output.WriteLine("[" + result.ToString().TrimEnd(',') + "]"); Response.End(); } }