From d10dea4c6b3bacb36a78fd4d1dfad10585be27cb Mon Sep 17 00:00:00 2001 From: Rick Falkvinge Date: Fri, 22 Sep 2017 17:15:55 +0200 Subject: [PATCH] Invoice inbound list work --- Logic/Financial/InboundInvoice.cs | 1 + Logic/Financial/Payout.cs | 13 ++ Site/Images/Icons/transparency-16px.png | Bin 0 -> 170 bytes .../Financial/Json-ListInvoicesInbound.aspx | 1 + .../Json-ListInvoicesInbound.aspx.cs | 167 ++++++++++++++++++ .../Json-ListInvoicesInbound.aspx.designer.cs | 13 ++ .../v5/Financial/ListInvoicesInbound.aspx | 2 +- Site/Site.csproj | 9 + 8 files changed, 205 insertions(+), 1 deletion(-) create mode 100644 Site/Images/Icons/transparency-16px.png create mode 100644 Site/Pages/v5/Financial/Json-ListInvoicesInbound.aspx create mode 100644 Site/Pages/v5/Financial/Json-ListInvoicesInbound.aspx.cs create mode 100644 Site/Pages/v5/Financial/Json-ListInvoicesInbound.aspx.designer.cs diff --git a/Logic/Financial/InboundInvoice.cs b/Logic/Financial/InboundInvoice.cs index 50103d8a..0a89baab 100644 --- a/Logic/Financial/InboundInvoice.cs +++ b/Logic/Financial/InboundInvoice.cs @@ -268,6 +268,7 @@ namespace Swarmops.Logic.Financial } } + private void UpdateTransaction (Person updatingPerson) { Dictionary nominalTransaction = new Dictionary(); diff --git a/Logic/Financial/Payout.cs b/Logic/Financial/Payout.cs index f84f0f8f..ff6b5809 100644 --- a/Logic/Financial/Payout.cs +++ b/Logic/Financial/Payout.cs @@ -4,6 +4,7 @@ using System.Globalization; using Swarmops.Basic.Types; using Swarmops.Basic.Types.Financial; using Swarmops.Common.Enums; +using Swarmops.Common.Interfaces; using Swarmops.Database; using Swarmops.Logic.Communications; using Swarmops.Logic.Communications.Payload; @@ -43,6 +44,18 @@ namespace Swarmops.Logic.Financial // return payout; } + public static Payout FromDependency(IHasIdentity dependency) + { + int payoutId = SwarmDb.GetDatabaseForReading().GetPayoutIdFromDependency(dependency); + if (payoutId == 0) + { + throw new ArgumentException("Supplied item does not have an associated payout"); + } + + return Payout.FromIdentity(payoutId); + } + + public static Payout Empty { get { return new Payout (new BasicPayout (0, 0, string.Empty, string.Empty, string.Empty, 0, DateTime.UtcNow, true, DateTime.UtcNow, 0)); } diff --git a/Site/Images/Icons/transparency-16px.png b/Site/Images/Icons/transparency-16px.png new file mode 100644 index 0000000000000000000000000000000000000000..533854edb18057212a631a118b8b5a00f6e4139d GIT binary patch literal 170 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Y)RhkE)4%caKYZ?lYt_f1s;*b z3=G`DAk4@xYmNj^kiEpy*OmPqhX}ti=kY^V_<%x^C9V-A&iT2ysd*&~&PAz-C8;S2 z<(VZJ3hti10pX2&;y^`0o-U3d7N?UFBv= diff --git a/Site/Pages/v5/Financial/Json-ListInvoicesInbound.aspx.cs b/Site/Pages/v5/Financial/Json-ListInvoicesInbound.aspx.cs new file mode 100644 index 00000000..4182b140 --- /dev/null +++ b/Site/Pages/v5/Financial/Json-ListInvoicesInbound.aspx.cs @@ -0,0 +1,167 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text; +using Swarmops.Common.Enums; +using Swarmops.Common.Interfaces; +using Swarmops.Frontend; +using Swarmops.Logic.Financial; +using Swarmops.Logic.Support; +using Swarmops.Logic.Swarm; + +public partial class Pages_v5_Finance_Json_ListInvoicesInbound : DataV5Base +{ + private Dictionary _attestationRights; + private InboundInvoices _invoices; + + protected void Page_Load (object sender, EventArgs e) + { + // Get invoices and attestation rights + + this._attestationRights = GetAttestationRights(); + this._invoices = InboundInvoices.ForOrganization(this.CurrentOrganization); + + // Format as JSON and return + + Response.ContentType = "application/json"; + string json = FormatAsJson(); + Response.Output.WriteLine (json); + Response.End(); + } + + private string FormatAsJson() + { + // Fields: item, dueDate, sender, budget, amount, progress, docs, action + + StringBuilder result = new StringBuilder (16384); + + string hasDoxString = + ""; + + result.Append ("{\"rows\":["); + + foreach (InboundInvoice invoice in _invoices) + { + result.Append("{"); + result.AppendFormat( + "\"item\":\"{0}\",\"dueDate\":\"{1}\",\"sender\":\"{2}\",\"budget\":\"{3}\",\"amount\":\"{4}\",\"progress\":\"{5}\"," + + "\"dox\":\"" + (invoice.Documents.Count > 0 ? hasDoxString : " ") + "\"," + + "\"actions\":\"" + + //"" + + //"" + + //"" + + //"" + + //"" + + "\"", + "#" + invoice.Identity.ToString("N0"), + JsonSanitize(invoice.DueDate.ToString("MMM-dd")), + JsonSanitize(invoice.Supplier), + JsonSanitize(invoice.Budget.Name), + JsonSanitize((invoice.AmountCents/100.0).ToString("N2")), + GetProgressTicks(invoice)); + result.Append("},"); + } + + if (_invoices.Count > 1) + { + result.Remove(result.Length - 1, 1); // remove last comma + } + + result.Append ("]}"); + + return result.ToString(); + } + + private string _emptyTick = ""; + private string _greenTick = ""; + private string _redCross = ""; + private string _filler = ""; + + + private string GetProgressTicks(InboundInvoice invoice) + { + StringBuilder ticks = new StringBuilder(512); + + // The first tick is whether the invoice was even received yet, in anticipation of Purchase Orders + // For now, it is always filled + + ticks.Append(_greenTick); + + // The second tick is whether the invoice has been attested + + if (invoice.Attested) + { + ticks.Append(_greenTick); + + // Is it also paid? + + if (invoice.PaidOut) + { + ticks.Append(_greenTick); + + // Is the payout closed, that is, registered closed with the bank? + + if (Payout.FromDependency(invoice).Open) + { + ticks.Append(_emptyTick); + } + else + { + ticks.Append(_greenTick); + } + } + else + { + // attested but not paid yet + + ticks.Append(_emptyTick + _emptyTick); + } + } + else // not attested + { + // Is the invoice closed? If so, it was denied entirely + + if (invoice.Open) + { + ticks.Append(_emptyTick + _emptyTick + _emptyTick); + } + else + { + // Closed, and therefore it was denied attestation + ticks.Append(_redCross + _filler + _filler); + } + } + + return ticks.ToString(); + } + + + private Dictionary GetAttestationRights() + { + // Right now, this function is quite primitive. At some point in the future, it needs to take into + // account that a budget may have several attesters. Right now, it just loops over all accounts and + // checks the owner. + + Dictionary result = new Dictionary(); + FinancialAccounts accounts = FinancialAccounts.ForOrganization (CurrentOrganization); + + foreach (FinancialAccount account in accounts) + { + if (account.OwnerPersonId == CurrentUser.Identity) + { + if (account.AccountType == FinancialAccountType.Cost) + { + result[account.Identity] = account.GetBudgetCentsRemaining(); + } + else + { + result[account.Identity] = 1; // any value + } + } + } + + return result; + } + + +} \ No newline at end of file diff --git a/Site/Pages/v5/Financial/Json-ListInvoicesInbound.aspx.designer.cs b/Site/Pages/v5/Financial/Json-ListInvoicesInbound.aspx.designer.cs new file mode 100644 index 00000000..78ecfa2c --- /dev/null +++ b/Site/Pages/v5/Financial/Json-ListInvoicesInbound.aspx.designer.cs @@ -0,0 +1,13 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + + + +public partial class Pages_v5_Finance_Json_InvoicesInbound { +} diff --git a/Site/Pages/v5/Financial/ListInvoicesInbound.aspx b/Site/Pages/v5/Financial/ListInvoicesInbound.aspx index ee559a6c..3bc0bc2c 100644 --- a/Site/Pages/v5/Financial/ListInvoicesInbound.aspx +++ b/Site/Pages/v5/Financial/ListInvoicesInbound.aspx @@ -187,7 +187,7 @@ - + diff --git a/Site/Site.csproj b/Site/Site.csproj index 23b45ccd..a80add98 100644 --- a/Site/Site.csproj +++ b/Site/Site.csproj @@ -194,6 +194,13 @@ SendMassMessage.aspx + + Json-ListInvoicesInbound.aspx + ASPXCodeBehind + + + Json-ListInvoicesInbound.aspx + ListInvoicesInbound.aspx ASPXCodeBehind @@ -895,6 +902,7 @@ + @@ -1041,6 +1049,7 @@ +