protected void Page_Load(object sender, EventArgs e) { Response.ContentType = "application/json"; FinancialTransactions unbalancedTransactions = FinancialTransactions.GetUnbalanced(CurrentOrganization); List <string> rows = new List <string>(); if ( CurrentAuthority.HasAccess(new Access(CurrentOrganization, AccessAspect.BookkeepingDetails, AccessType.Read))) { if (unbalancedTransactions.Count == 0) { if (rows.Count == 0) { // If there are no transactions in this time period, say so Response.Output.WriteLine("[{\"description\":\"" + JsonSanitize(Resources.Pages.Ledgers.BalanceTransactions_NoUnbalancedTransactions) + "\"}]"); Response.End(); return; } } foreach (FinancialTransaction transaction in unbalancedTransactions) { string accountName = string.Empty; FinancialTransactionRows txRows = transaction.Rows; if (txRows.Count > 1) { accountName = Resources.Global.Global_Several_Display; } else { // one transaction row (we know there's not zero rows, because the transaction is unbalanced, which requires at least one nonzero row) accountName = txRows[0].AccountName; } string row = String.Format( "\"id\":\"{0:N0}\",\"description\":\"{1}\",\"accountName\":\"{2}\",\"delta\":\"{3:+#,#.00;−#,#.00}\",\"dateTime\":\"{4:yyyy-MMM-dd HH:mm}\"", transaction.OrganizationSequenceId, JsonSanitize(transaction.Description), JsonSanitize(accountName), txRows.AmountCentsTotal / 100.0, transaction.DateTime); row += String.Format( ",\"action\":\"<img src='/Images/Icons/iconshock-wrench-128x96px-centered.png' height='16' width='24' class='LocalIconFix' txId='{0}' />\"", transaction.Identity); rows.Add("{" + row + "}"); } } Response.Output.WriteLine("[" + String.Join(",", rows) + "]"); Response.End(); }
protected void Page_Load(object sender, EventArgs e) { Response.ContentType = "application/json"; string transactionIdString = Request.QueryString["TxId"]; string emptyResponse = "[{\"id\":\"-\",\"accountName\":\"" + JsonSanitize(Resources.Pages.Ledgers.InspectLedgers_EmptyTransaction) + "\"}]"; if (string.IsNullOrEmpty(transactionIdString) || transactionIdString == "undefined") { Response.Output.WriteLine(emptyResponse); Response.End(); } int transactionId = Int32.Parse(transactionIdString); DateTime dawnOfMankind = new DateTime(1901, 1, 1); // no org will ever import bookkeeping from before this date if (transactionId <= 0) { Response.Output.WriteLine(emptyResponse); Response.End(); } FinancialTransaction transaction = FinancialTransaction.FromIdentity(transactionId); if (transaction.OrganizationId != CurrentOrganization.Identity) { throw new UnauthorizedAccessException("All the nopes in the world"); } if (!CurrentAuthority.HasAccess(new Access(CurrentOrganization, AccessAspect.Bookkeeping, AccessType.Read))) { throw new UnauthorizedAccessException("Access denied because security tokens say so"); } FinancialTransactionRows rows = transaction.Rows; StringBuilder result = new StringBuilder(16384); foreach (FinancialTransactionRow row in rows) { string creditString = string.Empty; string debitString = string.Empty; 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); } result.Append("{" + String.Format( "\"id\":\"{0}\",\"dateTime\":\"{1:yyyy-MMM-dd HH:mm}\",\"accountName\":\"{2}\"," + "\"deltaPos\":\"{3}\",\"deltaNeg\":\"{4}\",\"initials\":\"{5}\"", row.FinancialTransactionId, row.CreatedDateTime, JsonSanitize(row.AccountName), debitString, creditString, row.CreatedByPerson != null? row.CreatedByPerson.Initials: Resources.Global.Global_System) + "},"); } Int64 amountCentsTotal = transaction.Rows.AmountCentsTotal; if (amountCentsTotal != 0) { // If the transaction is unbalanced, make a huge deal about it result.Append("{\"accountName\":\"<img src='/Images/Icons/iconshock-warning-24px.png' height='16px' width='16px' class='elementFloatFar' />" + JsonSanitize(Resources.Pages.Ledgers.InspectLedgers_UnbalancedTransaction) + "\","); if (amountCentsTotal < 0) { result.AppendFormat("\"deltaPos\":\"<span class='spanAnnoyingBlink'>{0:N2}</span>\"", -amountCentsTotal / 100.0); } else if (amountCentsTotal > 0) { result.AppendFormat("\"deltaNeg\":\"<span class='spanAnnoyingBlink'>{0:N2}</span>\"", -amountCentsTotal / 100.0); } result.Append("},"); // the comma isn't really necessary here but will be stripped later and is kept for cut&paste consistency of this code block } Response.Output.WriteLine("[" + result.ToString().TrimEnd(',') + "]"); Response.End(); }
protected void GridTransactions_ItemCreated(object sender, GridItemEventArgs e) { if (e.Item is GridDataItem) { // This is actually quite ineffective as Rows does plenty of lookups. A cache would // speed this up, but otoh, it's a very rare call. /* * int transactionIdentity = (int) e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["Identity"]; * FinancialTransaction transaction = FinancialTransaction.FromIdentity (transactionIdentity); * FinancialTransactionRows rows = transaction.Rows;*/ FinancialTransaction transaction = (FinancialTransaction)e.Item.DataItem; if (transaction == null) { return; } FinancialTransactionRows rows = transaction.Rows; HyperLink editLink = (HyperLink)e.Item.FindControl("ManageLink"); editLink.Attributes["href"] = "#"; editLink.Attributes["onclick"] = String.Format("return ShowTransactionForm('{0}','{1}');", transaction.Identity, e.Item.ItemIndex); Label labelAccount = (Label)e.Item.FindControl("LabelAccount"); if (rows.Count > 1) { labelAccount.Text = "[Several]"; } else { labelAccount.Text = rows[0].Account.Name; } Int64 amountCentsTotal = rows.AmountCentsTotal; Label labelBalance = (Label)e.Item.FindControl("LabelBalance"); labelBalance.Text = (amountCentsTotal / 100.0).ToString("N2", new System.Globalization.CultureInfo("sv-SE")); Label labelProblems = (Label)e.Item.FindControl("LabelProblems"); List <string> problems = new List <string>(); if (amountCentsTotal != 0.0) { problems.Add("Unbalanced"); unbalancedCentsTotal += amountCentsTotal; unbalancedCount++; } if (rows.BalanceCentsDelta < 0 && transaction.Documents.Count == 0) { problems.Add("Undocumented"); undocumentedCount++; } labelProblems.Text = String.Join(", ", problems.ToArray()); } if (e.Item is GridFooterItem) { Label labelBalance = (Label)e.Item.FindControl("LabelBalanceAccumulated"); labelBalance.Text = "Total Diff: " + (unbalancedCentsTotal / 100.0).ToString("N2", new System.Globalization.CultureInfo("sv-SE")); Label labelProblemTotals = (Label)e.Item.FindControl("LabelProblemTotals"); labelProblemTotals.Text = String.Format("Unbal {0}, Undoc {1}", unbalancedCount, undocumentedCount); } }