From 384030cadfe72d0c3bad91f80f5d7ca7f7446714 Mon Sep 17 00:00:00 2001 From: Rick Falkvinge Date: Tue, 29 Jan 2019 11:28:24 +0100 Subject: [PATCH] Work on Payment History --- ...son-MasterPersonEditPaymentHistory.aspx.cs | 87 +++++++++++++++++-- Site/Master-v5.master | 4 +- 2 files changed, 83 insertions(+), 8 deletions(-) diff --git a/Site/Automation/Json-MasterPersonEditPaymentHistory.aspx.cs b/Site/Automation/Json-MasterPersonEditPaymentHistory.aspx.cs index c1e1c060..797a208b 100644 --- a/Site/Automation/Json-MasterPersonEditPaymentHistory.aspx.cs +++ b/Site/Automation/Json-MasterPersonEditPaymentHistory.aspx.cs @@ -1,9 +1,12 @@ 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.Logic.Financial; using Swarmops.Logic.Swarm; namespace Swarmops.Frontend.Automation @@ -25,17 +28,89 @@ namespace Swarmops.Frontend.Automation this._person = Person.FromIdentity(personId); - /* + List list = new List(); - THIS ENTIRE STUFF IS TODO + list.AddRange(GetAmountsOwed()); + list.AddRange(GetAmountsPaid()); Response.ContentType = "application/json"; + Response.Output.WriteLine("{\"rows\": " + JsonWriteItems(list) + ", \"footer\": [" + + JsonWriteFooter(list) + "]}"); - Response.Output.WriteLine("{\"rows\": " + RecurseReport(report.ReportLines) + ", \"footer\": [" + - WriteFooter() + "]}"); + Response.End(); - - Response.End();*/ } + + + public List GetAmountsOwed() + { + List items = new List(); + + // Expense claims + + ExpenseClaims expenses = ExpenseClaims.FromClaimingPersonAndOrganization(_person, + _authenticationData.CurrentOrganization); + + foreach (ExpenseClaim claim in expenses) + { + PaymentHistoryLineItem newItem = new PaymentHistoryLineItem(); + newItem.Id = "E" + claim.Identity.ToString(CultureInfo.InvariantCulture); + newItem.Name = Resources.Global.Financial_ExpenseClaim + " #" + claim.Identity.ToString("N0"); + newItem.Description = claim.Description; + newItem.OwedToPerson = claim.AmountCents; + + items.Add(newItem); + } + + return items; + } + + public List GetAmountsPaid() + { + return null; + } + + public string JsonWriteItems(List items) + { + StringBuilder result = new StringBuilder(16384); + result.Append("["); + + foreach (PaymentHistoryLineItem item in items) + { + result.Append("{"); + result.AppendFormat( + "\"id\":\"{0}\",\"name\":\"{1}\",\"description\":\"{2}\",\"owedToPerson\":\"{3:N2}\"", + JsonSanitize(item.Id), + JsonSanitize(item.Name), + JsonSanitize(item.Description), + item.OwedToPerson/100.0 + ); + + result.Append("},"); + } + + result.Remove(result.Length - 1, 1); // remove last comma + result.Append("]"); + + return result.ToString(); + } + +public string JsonWriteFooter(List items) + { + return string.Empty; + } + + public class PaymentHistoryLineItem + { + public string Id { get; set; } + public string Name { get; set; } + public string Description { get; set; } + public Int64 OwedToPerson { get; set; } + public Int64 PaidToPerson { get; set; } + + public DateTime OpenedDate { get; set; } + public DateTime ClosedDate { get; set; } + } + } } \ No newline at end of file diff --git a/Site/Master-v5.master b/Site/Master-v5.master index 8363b31e..feafc1db 100644 --- a/Site/Master-v5.master +++ b/Site/Master-v5.master @@ -387,8 +387,8 @@ - - + +